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-07-09 15:28:37 +00:00
|
|
|
$s = lang(strtr($match[2], array("\\'" => "'", "\\\\" => "\\")), false);
|
|
|
|
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) {
|
|
|
|
$return = file_get_contents($match[4]);
|
2007-07-09 15:28:37 +00:00
|
|
|
if ($match[4] == "./lang.inc.php") {
|
|
|
|
if (!$_SESSION["lang"]) {
|
2007-07-10 13:51:06 +00:00
|
|
|
$return = str_replace("\tif (\$number === false) { // used in _compile.php\n\t\treturn (\$translation ? \$translation : \$idf);\n\t}\n", "", $return);
|
2007-07-09 15:32:18 +00:00
|
|
|
} elseif (preg_match("~case '$_SESSION[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2)) {
|
|
|
|
return "$match[1]\nfunction lang(\$ar, \$number) {\n\t$match2[1]\n\treturn \$ar[\$pos];\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-09 15:32:18 +00:00
|
|
|
$_SESSION["lang"] = $_SERVER["argv"][1];
|
2007-07-05 10:46:44 +00:00
|
|
|
include "./lang.inc.php";
|
|
|
|
if ($_SERVER["argc"] != 2 || !in_array($_SERVER["argv"][1], 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$filename = "phpMinAdmin.php";
|
2007-07-02 05:51:26 +00:00
|
|
|
$file = file_get_contents("index.php");
|
2007-07-05 10:46:44 +00:00
|
|
|
if ($_SESSION["lang"]) {
|
|
|
|
$filename = "phpMinAdmin-$_SESSION[lang].php";
|
2007-07-05 07:34:42 +00:00
|
|
|
}
|
2007-07-05 13:23:39 +00:00
|
|
|
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
|
2007-07-05 10:46:44 +00:00
|
|
|
if ($_SESSION["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-09 06:12:22 +00:00
|
|
|
$file = str_replace("<?php echo get_lang(); ?>", $_SESSION["lang"], $file);
|
2007-07-05 07:34:42 +00:00
|
|
|
}
|
2007-07-05 10:46:44 +00:00
|
|
|
file_put_contents($filename, $file);
|
|
|
|
echo "$filename created.\n";
|