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
|
|
|
}
|
|
|
|
|
2007-07-02 05:51:26 +00:00
|
|
|
function put_file($match) {
|
2007-07-26 16:47:28 +00:00
|
|
|
if ($match[4] == './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 = "";
|
2007-08-04 19:36:01 +00:00
|
|
|
foreach (glob("./lang/*.inc.php") as $filename) {
|
|
|
|
$return .= "case '" . basename($filename, '.inc.php') . "': " . substr(file_get_contents($filename), 6) . "break;\n";
|
|
|
|
}
|
2007-08-07 15:27:51 +00:00
|
|
|
return "switch (\$LANG) {\n$return}\n";
|
2007-07-26 16:47:28 +00:00
|
|
|
}
|
|
|
|
$return = file_get_contents($match[4]);
|
|
|
|
if ($match[4] == "./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[5]";
|
2007-07-09 15:28:37 +00:00
|
|
|
}
|
2007-07-05 13:23:39 +00:00
|
|
|
$return = preg_replace("~\\?>\n?\$~", '', $return);
|
|
|
|
if (substr_count($return, "<?php") <= substr_count($return, "?>") && !$match[5]) {
|
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;
|
|
|
|
}
|
|
|
|
|
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");
|
2007-07-05 13:23:39 +00:00
|
|
|
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $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);
|
2007-07-05 07:34:42 +00:00
|
|
|
}
|
2007-07-26 16:47:28 +00:00
|
|
|
$file = str_replace("favicon.ico", '<?php echo preg_replace("~\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?favicon="; ?>', $file);
|
|
|
|
$file = str_replace("arrow.gif", '" . preg_replace("~\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file);
|
2007-07-27 11:53:04 +00:00
|
|
|
$file = str_replace('error_reporting(E_ALL & ~E_NOTICE);', "error_reporting(E_ALL & ~E_NOTICE);\nif (isset(\$_GET['favicon'])) {\n\theader('Content-Type: image/x-icon');\n\techo base64_decode('" . base64_encode(file_get_contents("favicon.ico")) . "');\n\texit;\n} elseif (isset(\$_GET['gif'])) {\n\theader('Content-Type: image/gif');\n\techo base64_decode('" . base64_encode(file_get_contents("arrow.gif")) . "');\n\texit;\n}", $file);
|
2007-07-11 12:07:17 +00:00
|
|
|
$file = str_replace('<link rel="stylesheet" type="text/css" href="default.css" />', "<style type='text/css'>\n" . file_get_contents("default.css") . "</style>", $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";
|