2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-05-29 20:19:13 +00:00
|
|
|
include dirname(__FILE__) . "/include/version.inc.php";
|
2009-05-29 16:57:32 +00:00
|
|
|
include dirname(__FILE__) . "/externals/jsmin-php/jsmin.php";
|
2009-05-29 14:53:42 +00:00
|
|
|
|
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;
|
2009-06-01 16:20:06 +00:00
|
|
|
if ($match[2] == './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 = "";
|
2009-05-29 16:34:55 +00:00
|
|
|
foreach (glob(dirname(__FILE__) . "/lang/*.inc.php") as $filename) {
|
2008-05-23 14:46:52 +00:00
|
|
|
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
|
|
|
}
|
2009-05-29 16:34:55 +00:00
|
|
|
foreach (glob(dirname(__FILE__) . "/lang/*.inc.php") as $filename) {
|
2008-05-24 08:27:37 +00:00
|
|
|
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
|
|
|
}
|
2009-06-01 16:20:06 +00:00
|
|
|
$return = file_get_contents(dirname(__FILE__) . "/$match[2]");
|
|
|
|
if ($match[2] != "./include/lang.inc.php" || !$_COOKIE["lang"]) {
|
|
|
|
$tokens = token_get_all($return);
|
|
|
|
return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
|
|
|
|
} elseif (preg_match('~\\s*(\\$pos = .*)~', $return, $match2)) {
|
|
|
|
return "function lang(\$translation, \$number) {\n\t" . str_replace('$LANG', "'$_COOKIE[lang]'", $match2[1]) . "\n\treturn sprintf(\$translation[\$pos], \$number);\n}\n";
|
|
|
|
} else {
|
|
|
|
echo "lang() not found\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-05-08 08:31:56 +00:00
|
|
|
// based on Dgx's PHP shrinker
|
2007-09-04 14:01:00 +00:00
|
|
|
function php_shrink($input) {
|
2009-05-08 05:13:51 +00:00
|
|
|
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
2009-04-15 11:23:31 +00:00
|
|
|
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 {
|
2009-05-03 21:30:03 +00:00
|
|
|
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')));
|
2009-04-17 13:25:35 +00:00
|
|
|
$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-06-01 21:31:05 +00:00
|
|
|
$in_echo = false;
|
|
|
|
for (reset($tokens); list($i, $token) = each($tokens); ) {
|
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-06-01 21:31:05 +00:00
|
|
|
} elseif ($token[0] == T_ECHO) {
|
|
|
|
$in_echo = true;
|
|
|
|
} elseif ($token[1] == ';' && $in_echo) {
|
|
|
|
$in_echo = false;
|
|
|
|
if ($tokens[$i+1][0] === T_WHITESPACE && $tokens[$i+2][0] === T_ECHO) {
|
|
|
|
next($tokens);
|
|
|
|
next($tokens);
|
|
|
|
$token[1] = '.'; //! join ''.'' and "".""
|
|
|
|
}
|
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];
|
2009-05-29 20:19:13 +00:00
|
|
|
include dirname(__FILE__) . "/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);
|
|
|
|
}
|
2009-05-29 16:34:55 +00:00
|
|
|
include dirname(__FILE__) . "/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";
|
2009-05-29 16:34:55 +00:00
|
|
|
$file = file_get_contents(dirname(__FILE__) . "/index.php");
|
2009-06-01 16:20:06 +00:00
|
|
|
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
|
|
|
|
$file = preg_replace("~<\\?php\\s*\\?>|\\?>\n?<\\?php~", '', $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-05-29 14:53:42 +00:00
|
|
|
$replace = 'preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=\\0&version=' . $VERSION;
|
2009-05-31 19:38:22 +00:00
|
|
|
$file = preg_replace('~default\\.css|functions\\.js|favicon\\.ico|(up|down|plus|cross)\\.gif~', '<?php echo ' . $replace . '"; ?>', $file);
|
2009-05-29 14:53:42 +00:00
|
|
|
$file = preg_replace('~arrow\\.gif~', '" . ' . $replace, $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"])) {
|
2009-05-29 14:53:42 +00:00
|
|
|
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 365*24*60*60) . " GMT");
|
2008-05-23 10:40:38 +00:00
|
|
|
if ($_GET["file"] == "favicon.ico") {
|
|
|
|
header("Content-Type: image/x-icon");
|
2009-05-29 16:34:55 +00:00
|
|
|
echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/favicon.ico")) . '");
|
2008-05-23 10:40:38 +00:00
|
|
|
} elseif ($_GET["file"] == "default.css") {
|
|
|
|
header("Content-Type: text/css");
|
2009-05-29 16:34:55 +00:00
|
|
|
?>' . preg_replace('~\\s*([:;{},])\\s*~', '\\1', file_get_contents(dirname(__FILE__) . "/default.css")) . '<?php
|
2009-05-29 16:14:54 +00:00
|
|
|
} elseif ($_GET["file"] == "functions.js") {
|
|
|
|
header("Content-Type: text/javascript");
|
2009-05-29 16:57:32 +00:00
|
|
|
?>' . JSMin::minify(file_get_contents(dirname(__FILE__) . "/functions.js")) . '<?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"]) {
|
2009-05-29 16:34:55 +00:00
|
|
|
case "arrow.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/arrow.gif")) . '"); break;
|
|
|
|
case "up.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/up.gif")) . '"); break;
|
|
|
|
case "down.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/down.gif")) . '"); break;
|
2009-06-01 16:05:51 +00:00
|
|
|
case "plus.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/plus.gif")) . '"); break;
|
2009-05-31 19:38:22 +00:00
|
|
|
case "cross.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/cross.gif")) . '"); break;
|
2008-01-21 16:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}', $file);
|
2009-05-31 14:12:15 +00:00
|
|
|
$file = str_replace("externals/jush/", "http://jush.sourceforge.net/", $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";
|