Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 184 lines (175 sloc) 7.74 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
<?php
function add_apo_slashes($s) {
return addcslashes($s, "\\'");
}

function remove_lang($match) {
global $translations;
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
$s = ($translations[$idf] ? $translations[$idf] : $idf);
if ($match[3] == ",") {
return "$match[1]" . (is_array($s) ? "lang(array('" . implode("', '", array_map('add_apo_slashes', $s)) . "')," : "sprintf('" . add_apo_slashes($s) . "',");
}
return ($match[1] && $match[4] ? $s : "$match[1]'" . add_apo_slashes($s) . "'$match[4]");
}

$lang_ids = array();
function lang_ids($match) {
global $lang_ids;
return 'lang(' . $lang_ids[stripslashes($match[1])] . $match[2];
}

function put_file($match) {
global $lang_ids;
if ($match[3] == './lang/$LANG.inc.php') {
if ($_COOKIE["lang"]) {
return "";
}
$return = "";
foreach (glob("lang/*.inc.php") as $filename) {
include $filename;
foreach ($translations as $key => $val) {
if (!isset($lang_ids[$key])) {
$lang_ids[$key] = count($lang_ids);
}
}
}
foreach (glob("lang/*.inc.php") as $filename) {
include $filename;
$translation_ids = array_flip($lang_ids);
foreach ($translations as $key => $val) {
$translation_ids[$lang_ids[$key]] = $val;
}
$return .= 'case "' . basename($filename, '.inc.php') . '": $translations = array(';
foreach ($translation_ids as $val) {
$return .= (is_array($val) ? "array('" . implode("', '", array_map('add_apo_slashes', $val)) . "')" : "'" . add_apo_slashes($val) . "'") . ", ";
}
$return = substr($return, 0, -2) . "); break;\n";
}
return "switch (\$LANG) {\n$return}\n";
}
$return = file_get_contents($match[3]);
if ($match[3] == "./lang.inc.php" && $_COOKIE["lang"] && (preg_match("~case '$_COOKIE[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2))) {
return "$match[1]\nfunction lang(\$ar, \$number) {\n\t$match2[1]\n\treturn sprintf(\$ar[\$pos], \$number);\n}\n$match[4]";
}
$return = preg_replace("~\\?>\n?\$~", '', $return);
if (substr_count($return, "<?php") <= substr_count($return, "?>") && !$match[4]) {
$return .= "<?php\n";
}
$return = preg_replace('~^<\\?php\\s+~', '', $return, 1, $count);
if ($count) {
$return = "\n$return";
} elseif (!$match[1]) {
$return = "?>\n$return";
}
return $return;
}

function short_identifier($number, $chars) {
$return = '';
while ($number >= 0) {
$return .= $chars{$number % strlen($chars)};
$number = floor($number / strlen($chars)) - 1;
}
return $return;
}

// Based on Dgx's PHP shrinker
function php_shrink($input) {
$special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
static $short_variables = array();
$shortening = true;
$special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', 'normalize_enum', '__construct'));
static $short_functions = array();
$tokens = token_get_all($input);

foreach ($tokens as $i => $token) {
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
$short_variables[$token[1]]++;
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !is_callable($token[1]) && !isset($special_functions[$token[1]])) {
$short_functions[$token[1]]++;
}
}
arsort($short_variables);
foreach (array_keys($short_variables) as $number => $key) {
$short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff
}
arsort($short_functions);
foreach (array_keys($short_functions) as $number => $key) {
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
}

$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
$space = '';
$output = '';
foreach ($tokens as $i => $token) {
if (!is_array($token)) {
$token = array(0, $token);
}
if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE) {
$space = "\n";
} else {
if ($token[0] == T_VAR) {
$shortening = false;
} elseif (!$shortening) {
if ($token[1] == ';') {
$shortening = true;
}
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
$token[1] = '$' . $short_variables[$token[1]];
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !is_callable($token[1]) && !isset($special_functions[$token[1]])
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && !in_array($tokens[$i-2][1], array('_result', '$_result'), true)
) {
$token[1] = $short_functions[$token[1]];
} elseif ($token[0] == T_CONSTANT_ENCAPSED_STRING && $tokens[$i-1] === '(' && in_array($tokens[$i-2][1], array('array_map', 'set_exception_handler'), true) && isset($short_functions[substr($token[1], 1, -1)])) {
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
}
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
$space = '';
}
$output .= $space . $token[1];
$space = '';
}
}
return $output;
}

error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) {
$_COOKIE["lang"] = $_SERVER["argv"][1];
include "./lang.inc.php";
if ($_SERVER["argc"] != 2 || !isset($langs[$_COOKIE["lang"]])) {
echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
exit(1);
}
include "./lang/$_COOKIE[lang].inc.php";
}

$filename = "phpMinAdmin" . ($_COOKIE["lang"] ? "-$_COOKIE[lang]" : "") . ".php";
$file = file_get_contents("index.php");
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require) "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
if ($_COOKIE["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("<?php switch_lang(); ?>\n", "", $file);
$file = str_replace('<?php echo $LANG; ?>', $_COOKIE["lang"], $file);
} else {
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
}
$file = preg_replace('~favicon\\.ico|(up|down|plus|minus)\\.gif~', '<?php echo preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=\\0"; ?>', $file);
$file = preg_replace('~default\\.css|arrow\\.gif~', '" . preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=\\0', $file);
$file = str_replace('error_reporting(E_ALL & ~E_NOTICE);', 'error_reporting(E_ALL & ~E_NOTICE);
if (isset($_GET["file"])) {
header("Expires: " . gmdate("D, d M Y H:i:s", filemtime(__FILE__) + 365*24*60*60) . " GMT");
if ($_GET["file"] == "favicon.ico") {
header("Content-Type: image/x-icon");
echo base64_decode("' . base64_encode(file_get_contents("favicon.ico")) . '");
} elseif ($_GET["file"] == "default.css") {
header("Content-Type: text/css");
?>' . preg_replace('~\\s*([:;{},])\\s+~', '\\1', file_get_contents("default.css")) . '<?php
} else {
header("Content-Type: image/gif");
switch ($_GET["file"]) {
case "arrow.gif": echo base64_decode("' . base64_encode(file_get_contents("arrow.gif")) . '"); break;
case "up.gif": echo base64_decode("' . base64_encode(file_get_contents("up.gif")) . '"); break;
case "down.gif": echo base64_decode("' . base64_encode(file_get_contents("down.gif")) . '"); break;
case "plus.gif": echo base64_decode("' . base64_encode(file_get_contents("plus.gif")) . '"); break;
case "minus.gif": echo base64_decode("' . base64_encode(file_get_contents("minus.gif")) . '"); break;
}
}
exit;
}', $file);
$file = php_shrink($file);
fwrite(fopen($filename, "w"), $file);
echo "$filename created.\n";
Something went wrong with that request. Please try again.