mirror of
https://github.com/vrana/adminer.git
synced 2025-08-13 10:04:07 +02:00
Comments
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@729 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
31
compile.php
31
compile.php
@@ -10,13 +10,13 @@ function remove_lang($match) {
|
||||
global $translations;
|
||||
$idf = strtr($match[2], array("\\'" => "'", "\\\\" => "\\"));
|
||||
$s = ($translations[$idf] ? $translations[$idf] : $idf);
|
||||
if ($match[3] == ",") {
|
||||
if ($match[3] == ",") { // lang() has parameters
|
||||
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();
|
||||
$lang_ids = array(); // global variable simplifies usage in a callback function
|
||||
function lang_ids($match) {
|
||||
global $lang_ids;
|
||||
return 'lang(' . $lang_ids[stripslashes($match[1])] . $match[2];
|
||||
@@ -30,6 +30,7 @@ function put_file($match) {
|
||||
}
|
||||
$return = "";
|
||||
foreach (glob(dirname(__FILE__) . "/adminer/lang/*.inc.php") as $filename) {
|
||||
// assign translation numbers
|
||||
include $filename;
|
||||
foreach ($translations as $key => $val) {
|
||||
if (!isset($lang_ids[$key])) {
|
||||
@@ -38,7 +39,7 @@ function put_file($match) {
|
||||
}
|
||||
}
|
||||
foreach (glob(dirname(__FILE__) . "/adminer/lang/*.inc.php") as $filename) {
|
||||
include $filename;
|
||||
include $filename; // reassign $translations
|
||||
$translation_ids = array_flip($lang_ids);
|
||||
foreach ($translations as $key => $val) {
|
||||
$translation_ids[$lang_ids[$key]] = $val;
|
||||
@@ -53,9 +54,10 @@ function put_file($match) {
|
||||
}
|
||||
$return = file_get_contents(dirname(__FILE__) . "/adminer/$match[2]");
|
||||
if ($match[2] != "./include/lang.inc.php" || !$_COOKIE["lang"]) {
|
||||
$tokens = token_get_all($return);
|
||||
$tokens = token_get_all($return); // to find out the last token
|
||||
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)) {
|
||||
// single language lang() is used for plural
|
||||
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";
|
||||
@@ -75,10 +77,10 @@ function short_identifier($number, $chars) {
|
||||
function php_shrink($input) {
|
||||
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
||||
static $short_variables = array();
|
||||
static $short_functions = array();
|
||||
$shortening = true;
|
||||
$special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct'));
|
||||
$defined_functions = array();
|
||||
static $short_functions = array();
|
||||
$tokens = token_get_all($input);
|
||||
|
||||
foreach ($tokens as $i => $token) {
|
||||
@@ -101,9 +103,9 @@ function php_shrink($input) {
|
||||
foreach ($short_functions as $key => $val) {
|
||||
if (isset($defined_functions[$key])) {
|
||||
do {
|
||||
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z')));
|
||||
$short_functions[$key] = short_identifier($number, implode("", range('a', 'z'))); // _ not used to not collide with gettext()
|
||||
$number++;
|
||||
} while (isset($short_functions[$short_functions[$key]]));
|
||||
} while (isset($short_functions[$short_functions[$key]])); // don't overwrite existing functions
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +131,7 @@ function php_shrink($input) {
|
||||
} elseif ($token[1] == ';' && $in_echo) {
|
||||
$in_echo = false;
|
||||
if ($tokens[$i+1][0] === T_WHITESPACE && $tokens[$i+2][0] === T_ECHO) {
|
||||
// join two consecutive echos
|
||||
next($tokens);
|
||||
next($tokens);
|
||||
$token[1] = '.'; //! join ''.'' and "".""
|
||||
@@ -136,10 +139,13 @@ function php_shrink($input) {
|
||||
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
|
||||
$token[1] = '$' . $short_variables[$token[1]];
|
||||
} elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && isset($defined_functions[$token[1]])
|
||||
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result'
|
||||
&& $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result' // don't substitute parent methods - used to link PHP methods only
|
||||
) {
|
||||
$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)) || $token[1] == "'normalize_enum'") && isset($defined_functions[substr($token[1], 1, -1)])) {
|
||||
} 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)])
|
||||
) { // minify callback functions too
|
||||
$token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
|
||||
}
|
||||
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
|
||||
@@ -154,7 +160,7 @@ function php_shrink($input) {
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
if ($_SERVER["argc"] > 1) {
|
||||
$_COOKIE["lang"] = $_SERVER["argv"][1];
|
||||
$_COOKIE["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from cookie
|
||||
include dirname(__FILE__) . "/adminer/include/lang.inc.php";
|
||||
if ($_SERVER["argc"] != 2 || !isset($langs[$_COOKIE["lang"]])) {
|
||||
echo "Usage: php compile.php [lang]\nPurpose: Compile adminer[-lang].php from index.php.\n";
|
||||
@@ -168,6 +174,7 @@ $file = file_get_contents(dirname(__FILE__) . "/adminer/index.php");
|
||||
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
|
||||
$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
|
||||
if ($_COOKIE["lang"]) {
|
||||
// single language version
|
||||
$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);
|
||||
@@ -200,9 +207,9 @@ if (isset($_GET["file"])) {
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}', $file);
|
||||
}', $file); // integrate static files
|
||||
$file = str_replace("../externals/jush/", "http://jush.sourceforge.net/", $file);
|
||||
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
|
||||
$file = php_shrink($file);
|
||||
fwrite(fopen($filename, "w"), $file);
|
||||
fwrite(fopen($filename, "w"), $file); // file_put_contents() since PHP 5
|
||||
echo "$filename created.\n";
|
||||
|
Reference in New Issue
Block a user