2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2007-07-09 15:28:37 +00:00
|
|
|
function add_apo_slashes($s) {
|
|
|
|
return addcslashes($s, "\\'");
|
|
|
|
}
|
|
|
|
|
2007-07-05 07:34:42 +00:00
|
|
|
function remove_lang($match) {
|
2007-08-04 19:36:01 +00:00
|
|
|
global $translations;
|
2007-07-26 16:47:28 +00:00
|
|
|
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
|
2007-08-04 19:36:01 +00:00
|
|
|
$s = ($translations[$idf] ? $translations[$idf] : $idf);
|
2007-07-09 15:28:37 +00:00
|
|
|
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]");
|
2007-07-05 07:34:42 +00:00
|
|
|
}
|
|
|
|
|
2008-05-23 14:46:52 +00:00
|
|
|
$lang_ids = array();
|
|
|
|
function lang_ids($match) {
|
|
|
|
global $lang_ids;
|
|
|
|
return 'lang(' . $lang_ids[stripslashes($match[1])] . $match[2];
|
|
|
|
}
|
|
|
|
|
2007-07-02 05:51:26 +00:00
|
|
|
function put_file($match) {
|
2008-05-23 14:46:52 +00:00
|
|
|
global $lang_ids;
|
2008-05-23 10:46:32 +00:00
|
|
|
if ($match[3] == './lang/$LANG.inc.php') {
|
2007-08-04 19:36:01 +00:00
|
|
|
if ($_COOKIE["lang"]) {
|
|
|
|
return "";
|
2007-07-09 15:28:37 +00:00
|
|
|
}
|
2007-08-07 15:27:51 +00:00
|
|
|
$return = "";
|
2008-05-23 14:46:52 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2008-05-24 08:27:37 +00:00
|
|
|
}
|
|
|
|
foreach (glob("lang/*.inc.php") as $filename) {
|
|
|
|
include $filename;
|
2008-05-23 14:46:52 +00:00
|
|
|
$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) . "'") . ", ";
|
|
|
|
}
|
2008-05-26 10:29:07 +00:00
|
|
|
$return = substr($return, 0, -2) . "); break;\n";
|
2007-08-04 19:36:01 +00:00
|
|
|
}
|
2007-08-07 15:27:51 +00:00
|
|
|
return "switch (\$LANG) {\n$return}\n";
|
2007-07-26 16:47:28 +00:00
|
|
|
}
|
2008-05-23 10:46:32 +00:00
|
|
|
$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]";
|
2007-07-09 15:28:37 +00:00
|
|
|
}
|
2007-07-05 13:23:39 +00:00
|
|
|
$return = preg_replace("~\\?>\n?\$~", '', $return);
|
2008-05-23 10:46:32 +00:00
|
|
|
if (substr_count($return, "<?php") <= substr_count($return, "?>") && !$match[4]) {
|
2007-07-02 05:51:26 +00:00
|
|
|
$return .= "<?php\n";
|
|
|
|
}
|
|
|
|
$return = preg_replace('~^<\\?php\\s+~', '', $return, 1, $count);
|
2007-07-05 13:23:39 +00:00
|
|
|
if ($count) {
|
|
|
|
$return = "\n$return";
|
|
|
|
} elseif (!$match[1]) {
|
2007-07-02 05:51:26 +00:00
|
|
|
$return = "?>\n$return";
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
function short_identifier($number, $chars) {
|
|
|
|
$return = '';
|
2009-04-15 11:23:31 +00:00
|
|
|
while ($number >= 0) {
|
|
|
|
$return .= $chars{$number % strlen($chars)};
|
|
|
|
$number = floor($number / strlen($chars)) - 1;
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
// Based on Dgx's PHP shrinker
|
2007-09-04 14:01:00 +00:00
|
|
|
function php_shrink($input) {
|
2009-04-15 11:23:31 +00:00
|
|
|
$special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
|
|
|
static $short_variables = array();
|
|
|
|
$shortening = true;
|
2009-04-16 14:17:31 +00:00
|
|
|
$special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', '__construct'));
|
|
|
|
$defined_functions = array();
|
2009-04-15 14:31:05 +00:00
|
|
|
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]]++;
|
2009-04-16 14:17:31 +00:00
|
|
|
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !isset($special_functions[$token[1]])) {
|
2009-04-15 14:31:05 +00:00
|
|
|
$short_functions[$token[1]]++;
|
2009-04-16 14:17:31 +00:00
|
|
|
if ($tokens[$i-2][0] === T_FUNCTION) {
|
|
|
|
$defined_functions[$token[1]] = true;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-16 14:17:31 +00:00
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
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);
|
2009-04-16 14:17:31 +00:00
|
|
|
$number = 0;
|
|
|
|
foreach ($short_functions as $key => $val) {
|
|
|
|
if (isset($defined_functions[$key])) {
|
2009-04-17 13:25:35 +00:00
|
|
|
do {
|
|
|
|
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')) . '_');
|
|
|
|
$number++;
|
|
|
|
} while (isset($short_functions[$short_functions[$key]]));
|
2009-04-16 14:17:31 +00:00
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
}
|
2009-04-15 11:23:31 +00:00
|
|
|
|
2007-09-04 14:01:00 +00:00
|
|
|
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
|
|
|
|
$space = '';
|
|
|
|
$output = '';
|
2009-04-15 14:31:05 +00:00
|
|
|
foreach ($tokens as $i => $token) {
|
2007-09-04 14:01:00 +00:00
|
|
|
if (!is_array($token)) {
|
|
|
|
$token = array(0, $token);
|
|
|
|
}
|
|
|
|
if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE) {
|
|
|
|
$space = "\n";
|
|
|
|
} else {
|
2009-04-15 11:23:31 +00:00
|
|
|
if ($token[0] == T_VAR) {
|
|
|
|
$shortening = false;
|
|
|
|
} elseif (!$shortening) {
|
|
|
|
if ($token[1] == ';') {
|
|
|
|
$shortening = true;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
|
|
|
$token[1] = '$' . $short_variables[$token[1]];
|
2009-04-16 14:17:31 +00:00
|
|
|
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && isset($defined_functions[$token[1]])
|
2009-04-16 14:33:58 +00:00
|
|
|
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result'
|
2009-04-15 14:31:05 +00:00
|
|
|
) {
|
|
|
|
$token[1] = $short_functions[$token[1]];
|
2009-04-16 14:17:31 +00:00
|
|
|
} elseif ($token[0] == T_CONSTANT_ENCAPSED_STRING && (($tokens[$i-1] === '(' && in_array($tokens[$i-2][1], array('array_map', 'set_exception_handler'), true)) || $token[1] == "'normalize_enum'") && isset($defined_functions[substr($token[1], 1, -1)])) {
|
2009-04-15 14:31:05 +00:00
|
|
|
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
|
2009-04-15 11:23:31 +00:00
|
|
|
}
|
2007-09-04 14:01:00 +00:00
|
|
|
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
|
|
|
$space = '';
|
|
|
|
}
|
|
|
|
$output .= $space . $token[1];
|
|
|
|
$space = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2007-07-05 07:34:42 +00:00
|
|
|
error_reporting(E_ALL & ~E_NOTICE);
|
2007-07-05 10:46:44 +00:00
|
|
|
if ($_SERVER["argc"] > 1) {
|
2007-07-13 14:37:23 +00:00
|
|
|
$_COOKIE["lang"] = $_SERVER["argv"][1];
|
2007-07-05 10:46:44 +00:00
|
|
|
include "./lang.inc.php";
|
2007-08-04 19:36:01 +00:00
|
|
|
if ($_SERVER["argc"] != 2 || !isset($langs[$_COOKIE["lang"]])) {
|
2007-07-05 13:32:01 +00:00
|
|
|
echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
|
2007-07-05 10:46:44 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-07-26 16:47:28 +00:00
|
|
|
include "./lang/$_COOKIE[lang].inc.php";
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
2007-08-04 19:36:01 +00:00
|
|
|
|
|
|
|
$filename = "phpMinAdmin" . ($_COOKIE["lang"] ? "-$_COOKIE[lang]" : "") . ".php";
|
2007-07-02 05:51:26 +00:00
|
|
|
$file = file_get_contents("index.php");
|
2008-05-23 10:46:32 +00:00
|
|
|
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require) "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
|
2008-10-02 16:42:55 +00:00
|
|
|
$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
|
2007-07-13 14:37:23 +00:00
|
|
|
if ($_COOKIE["lang"]) {
|
2007-07-10 18:53:35 +00:00
|
|
|
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
|
2007-07-05 10:46:44 +00:00
|
|
|
$file = str_replace("<?php switch_lang(); ?>\n", "", $file);
|
2007-07-17 14:04:29 +00:00
|
|
|
$file = str_replace('<?php echo $LANG; ?>', $_COOKIE["lang"], $file);
|
2008-05-23 14:46:52 +00:00
|
|
|
} else {
|
|
|
|
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
|
2007-07-05 07:34:42 +00:00
|
|
|
}
|
2009-04-03 14:08:58 +00:00
|
|
|
$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);
|
2008-01-21 16:28:48 +00:00
|
|
|
$file = str_replace('error_reporting(E_ALL & ~E_NOTICE);', 'error_reporting(E_ALL & ~E_NOTICE);
|
|
|
|
if (isset($_GET["file"])) {
|
2008-05-23 10:40:38 +00:00
|
|
|
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");
|
2009-04-10 12:01:11 +00:00
|
|
|
?>' . preg_replace('~\\s*([:;{},])\\s+~', '\\1', file_get_contents("default.css")) . '<?php
|
2008-01-21 16:28:48 +00:00
|
|
|
} else {
|
2008-05-23 10:40:38 +00:00
|
|
|
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;
|
2008-01-21 16:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}', $file);
|
2007-09-04 14:01:00 +00:00
|
|
|
$file = php_shrink($file);
|
2007-08-07 15:27:51 +00:00
|
|
|
fwrite(fopen($filename, "w"), $file);
|
2007-07-05 10:46:44 +00:00
|
|
|
echo "$filename created.\n";
|