2012-05-26 06:21:31 +00:00
|
|
|
#!/usr/bin/env php
|
2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-08-28 10:56:54 +00:00
|
|
|
error_reporting(6135); // errors and warnings
|
2009-06-13 20:55:19 +00:00
|
|
|
include dirname(__FILE__) . "/adminer/include/version.inc.php";
|
2012-03-08 09:12:06 +00:00
|
|
|
include dirname(__FILE__) . "/externals/JsShrink/jsShrink.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, "\\'");
|
|
|
|
}
|
|
|
|
|
2012-09-07 05:15:03 +00:00
|
|
|
function add_quo_slashes($s) {
|
|
|
|
return addcslashes($s, "\n\r\$\"\\");
|
|
|
|
}
|
|
|
|
|
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);
|
2009-06-21 23:20:32 +00:00
|
|
|
if ($match[3] == ",") { // lang() has parameters
|
2007-07-09 15:28:37 +00:00
|
|
|
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
|
|
|
function lang_ids($match) {
|
|
|
|
global $lang_ids;
|
2009-07-11 19:45:57 +00:00
|
|
|
$lang_id = &$lang_ids[stripslashes($match[1])];
|
2012-05-14 06:54:07 +00:00
|
|
|
if ($lang_id === null) {
|
2009-07-11 19:45:57 +00:00
|
|
|
$lang_id = count($lang_ids) - 1;
|
|
|
|
}
|
2009-09-10 19:05:27 +00:00
|
|
|
return ($_SESSION["lang"] ? $match[0] : "lang($lang_id$match[2]");
|
2008-05-23 14:46:52 +00:00
|
|
|
}
|
|
|
|
|
2007-07-02 05:51:26 +00:00
|
|
|
function put_file($match) {
|
2009-07-11 19:45:57 +00:00
|
|
|
global $project;
|
2009-07-03 06:26:01 +00:00
|
|
|
if (basename($match[2]) == '$LANG.inc.php') {
|
2009-07-11 19:45:57 +00:00
|
|
|
return $match[0]; // processed later
|
2007-07-26 16:47:28 +00:00
|
|
|
}
|
2009-07-03 06:26:01 +00:00
|
|
|
$return = file_get_contents(dirname(__FILE__) . "/$project/$match[2]");
|
2009-09-10 19:05:27 +00:00
|
|
|
if (basename($match[2]) != "lang.inc.php" || !$_SESSION["lang"]) {
|
2009-06-21 23:20:32 +00:00
|
|
|
$tokens = token_get_all($return); // to find out the last token
|
2009-06-01 16:20:06 +00:00
|
|
|
return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
|
2011-07-11 15:32:52 +00:00
|
|
|
} elseif (preg_match('~\\s*(\\$pos = (.+\n).+;)~sU', $return, $match2)) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// single language lang() is used for plural
|
2010-12-30 12:53:39 +00:00
|
|
|
return "function get_lang() {
|
|
|
|
return '$_SESSION[lang]';
|
|
|
|
}
|
|
|
|
|
|
|
|
function lang(\$translation, \$number) {
|
2011-07-11 15:32:52 +00:00
|
|
|
\$pos = $match2[2]\t\t: " . (preg_match("~\\\$LANG == '$_SESSION[lang]'.* \\? (.+)\n~U", $match2[1], $match3) ? $match3[1] : "1") . '
|
|
|
|
);
|
2012-06-05 00:44:04 +00:00
|
|
|
$translation = str_replace("%d", "%s", $translation[$pos]);
|
|
|
|
$number = number_format($number, 0, ".", lang(\',\'));
|
|
|
|
return sprintf($translation, $number);
|
2010-12-30 12:53:39 +00:00
|
|
|
}
|
|
|
|
';
|
2009-06-01 16:20:06 +00:00
|
|
|
} else {
|
|
|
|
echo "lang() not found\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 13:44:32 +00:00
|
|
|
function lzw_compress($string) {
|
|
|
|
// compression
|
|
|
|
$dictionary = array_flip(range("\0", "\xFF"));
|
|
|
|
$word = "";
|
|
|
|
$codes = array();
|
|
|
|
for ($i=0; $i <= strlen($string); $i++) {
|
|
|
|
$x = $string[$i];
|
|
|
|
if (strlen($x) && isset($dictionary[$word . $x])) {
|
|
|
|
$word .= $x;
|
|
|
|
} elseif ($i) {
|
|
|
|
$codes[] = $dictionary[$word];
|
|
|
|
$dictionary[$word . $x] = count($dictionary);
|
|
|
|
$word = $x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// convert codes to binary string
|
|
|
|
$dictionary_count = 256;
|
|
|
|
$bits = 8; // ceil(log($dictionary_count, 2))
|
|
|
|
$return = "";
|
|
|
|
$rest = 0;
|
|
|
|
$rest_length = 0;
|
|
|
|
foreach ($codes as $code) {
|
|
|
|
$rest = ($rest << $bits) + $code;
|
|
|
|
$rest_length += $bits;
|
|
|
|
$dictionary_count++;
|
|
|
|
if ($dictionary_count >> $bits) {
|
|
|
|
$bits++;
|
|
|
|
}
|
|
|
|
while ($rest_length > 7) {
|
|
|
|
$rest_length -= 8;
|
|
|
|
$return .= chr($rest >> $rest_length);
|
|
|
|
$rest &= (1 << $rest_length) - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return . ($rest_length ? chr($rest << (8 - $rest_length)) : "");
|
|
|
|
}
|
|
|
|
|
2009-07-11 19:45:57 +00:00
|
|
|
function put_file_lang($match) {
|
2010-11-15 15:54:08 +00:00
|
|
|
global $lang_ids, $project, $langs;
|
2009-09-10 19:05:27 +00:00
|
|
|
if ($_SESSION["lang"]) {
|
2009-07-11 19:45:57 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-09-03 22:59:05 +00:00
|
|
|
$return = "";
|
2010-11-15 15:54:08 +00:00
|
|
|
foreach ($langs as $lang => $val) {
|
|
|
|
include dirname(__FILE__) . "/adminer/lang/$lang.inc.php"; // assign $translations
|
2009-07-11 19:45:57 +00:00
|
|
|
$translation_ids = array_flip($lang_ids); // default translation
|
|
|
|
foreach ($translations as $key => $val) {
|
2012-05-14 06:54:07 +00:00
|
|
|
if ($val !== null) {
|
2012-09-03 22:59:05 +00:00
|
|
|
$translation_ids[$lang_ids[$key]] = implode("\t", (array) $val);
|
2009-07-11 19:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-07 05:15:03 +00:00
|
|
|
$return .= '
|
|
|
|
case "' . $lang . '": $compressed = "' . add_quo_slashes(lzw_compress(implode("\n", $translation_ids))) . '"; break;';
|
2009-07-11 19:45:57 +00:00
|
|
|
}
|
2012-09-03 22:59:05 +00:00
|
|
|
$translations_version = crc32($return);
|
2012-09-02 13:44:32 +00:00
|
|
|
return '$translations = &$_SESSION["translations"];
|
2012-09-03 22:00:06 +00:00
|
|
|
if ($_SESSION["translations_version"] != ' . $translations_version . ') {
|
|
|
|
$translations = array();
|
|
|
|
$_SESSION["translations_version"] = ' . $translations_version . ';
|
|
|
|
}
|
2012-09-16 13:08:00 +00:00
|
|
|
if (!$translations) {
|
2012-09-03 22:59:05 +00:00
|
|
|
switch ($LANG) {' . $return . '
|
|
|
|
}
|
|
|
|
$translations = array();
|
|
|
|
foreach (explode("\n", lzw_decompress($compressed)) as $val) {
|
|
|
|
$translations[] = (strpos($val, "\t") ? explode("\t", $val) : $val);
|
|
|
|
}
|
2012-09-02 13:44:32 +00:00
|
|
|
}
|
|
|
|
';
|
2009-07-11 19:45:57 +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) {
|
2012-05-16 23:42:45 +00:00
|
|
|
$return .= $chars[$number % strlen($chars)];
|
2009-04-15 11:23:31 +00:00
|
|
|
$number = floor($number / strlen($chars)) - 1;
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2009-07-24 06:13:38 +00:00
|
|
|
// based on http://latrine.dgx.cz/jak-zredukovat-php-skripty
|
2007-09-04 14:01:00 +00:00
|
|
|
function php_shrink($input) {
|
2011-05-12 14:21:40 +00:00
|
|
|
global $VERSION;
|
2009-05-08 05:13:51 +00:00
|
|
|
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
|
2009-10-06 11:49:31 +00:00
|
|
|
$short_variables = array();
|
2009-04-15 11:23:31 +00:00
|
|
|
$shortening = true;
|
2009-04-15 14:31:05 +00:00
|
|
|
$tokens = token_get_all($input);
|
|
|
|
|
2012-05-16 23:42:45 +00:00
|
|
|
// remove unnecessary { }
|
|
|
|
//! change also `while () { if () {;} }` to `while () if () ;` but be careful about `if () { if () { } } else { }
|
|
|
|
$shorten = 0;
|
|
|
|
$opening = -1;
|
|
|
|
foreach ($tokens as $i => $token) {
|
|
|
|
if (in_array($token[0], array(T_IF, T_ELSE, T_ELSEIF, T_WHILE, T_DO, T_FOR, T_FOREACH), true)) {
|
|
|
|
$shorten = ($token[0] == T_FOR ? 4 : 2);
|
|
|
|
$opening = -1;
|
|
|
|
} elseif (in_array($token[0], array(T_SWITCH, T_FUNCTION, T_CLASS, T_CLOSE_TAG), true)) {
|
|
|
|
$shorten = 0;
|
|
|
|
} elseif ($token === ';') {
|
|
|
|
$shorten--;
|
|
|
|
} elseif ($token === '{') {
|
|
|
|
if ($opening < 0) {
|
|
|
|
$opening = $i;
|
|
|
|
} elseif ($shorten > 1) {
|
|
|
|
$shorten = 0;
|
|
|
|
}
|
|
|
|
} elseif ($token === '}' && $opening >= 0 && $shorten == 1) {
|
|
|
|
unset($tokens[$opening]);
|
|
|
|
unset($tokens[$i]);
|
|
|
|
$shorten = 0;
|
|
|
|
$opening = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$tokens = array_values($tokens);
|
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
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
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
arsort($short_variables);
|
2011-08-09 08:22:14 +00:00
|
|
|
$chars = implode(range('a', 'z')) . '_' . implode(range('A', 'Z'));
|
|
|
|
// preserve variable names between versions if possible
|
|
|
|
$short_variables2 = array_splice($short_variables, strlen($chars));
|
|
|
|
ksort($short_variables);
|
|
|
|
ksort($short_variables2);
|
|
|
|
$short_variables += $short_variables2;
|
2009-04-15 14:31:05 +00:00
|
|
|
foreach (array_keys($short_variables) as $number => $key) {
|
2011-08-09 08:22:14 +00:00
|
|
|
$short_variables[$key] = short_identifier($number, $chars); // could use also numbers and \x7f-\xff
|
2009-04-15 14:31:05 +00:00
|
|
|
}
|
2009-04-15 11:23:31 +00:00
|
|
|
|
2012-09-03 22:03:55 +00:00
|
|
|
$set = array_flip(preg_split('//', '!"#$%&\'()*+,-./:;<=>?@[\]^`{|}'));
|
2007-09-04 14:01:00 +00:00
|
|
|
$space = '';
|
|
|
|
$output = '';
|
2009-06-01 21:31:05 +00:00
|
|
|
$in_echo = false;
|
2009-07-11 19:45:57 +00:00
|
|
|
$doc_comment = false; // include only first /**
|
2009-06-01 21:31:05 +00:00
|
|
|
for (reset($tokens); list($i, $token) = each($tokens); ) {
|
2007-09-04 14:01:00 +00:00
|
|
|
if (!is_array($token)) {
|
|
|
|
$token = array(0, $token);
|
|
|
|
}
|
2009-08-26 12:36:59 +00:00
|
|
|
if ($tokens[$i+2][0] === T_CLOSE_TAG && $tokens[$i+3][0] === T_INLINE_HTML && $tokens[$i+4][0] === T_OPEN_TAG
|
2012-09-07 05:15:03 +00:00
|
|
|
&& strlen(add_apo_slashes($tokens[$i+3][1])) < strlen($tokens[$i+3][1]) + 3
|
2009-08-26 12:36:59 +00:00
|
|
|
) {
|
|
|
|
$tokens[$i+2] = array(T_ECHO, 'echo');
|
2012-09-07 05:15:03 +00:00
|
|
|
$tokens[$i+3] = array(T_CONSTANT_ENCAPSED_STRING, "'" . add_apo_slashes($tokens[$i+3][1]) . "'");
|
2009-08-26 12:36:59 +00:00
|
|
|
$tokens[$i+4] = array(0, ';');
|
|
|
|
}
|
2009-07-11 19:45:57 +00:00
|
|
|
if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE || ($token[0] == T_DOC_COMMENT && $doc_comment)) {
|
2007-09-04 14:01:00 +00:00
|
|
|
$space = "\n";
|
|
|
|
} else {
|
2009-07-11 19:45:57 +00:00
|
|
|
if ($token[0] == T_DOC_COMMENT) {
|
|
|
|
$doc_comment = true;
|
2011-05-12 14:21:40 +00:00
|
|
|
$token[1] = substr_replace($token[1], "* @version $VERSION\n", -2, 0);
|
2009-07-11 19:45:57 +00:00
|
|
|
}
|
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) {
|
2009-08-26 14:14:38 +00:00
|
|
|
if ($tokens[$i+1][0] === T_WHITESPACE && $tokens[$i+2][0] === T_ECHO) {
|
2009-06-01 21:31:05 +00:00
|
|
|
next($tokens);
|
2009-07-30 16:29:38 +00:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if ($tokens[$i+1][0] === T_ECHO) {
|
|
|
|
// join two consecutive echos
|
2009-06-01 21:31:05 +00:00
|
|
|
next($tokens);
|
2009-09-23 09:06:38 +00:00
|
|
|
$token[1] = ','; // '.' would conflict with "a".1+2 and would use more memory //! remove ',' and "," but not $var","
|
2009-08-26 12:36:59 +00:00
|
|
|
} else {
|
|
|
|
$in_echo = false;
|
2009-06-01 21:31:05 +00:00
|
|
|
}
|
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-15 11:23:31 +00:00
|
|
|
}
|
2010-04-21 12:01:32 +00:00
|
|
|
if (isset($set[substr($output, -1)]) || isset($set[$token[1][0]])) {
|
2007-09-04 14:01:00 +00:00
|
|
|
$space = '';
|
|
|
|
}
|
|
|
|
$output .= $space . $token[1];
|
|
|
|
$space = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2009-06-26 20:43:41 +00:00
|
|
|
function minify_css($file) {
|
2012-09-07 05:37:24 +00:00
|
|
|
return lzw_compress(preg_replace('~\\s*([:;{},])\\s*~', '\\1', preg_replace('~/\\*.*\\*/~sU', '', $file)));
|
2009-06-26 20:43:41 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 05:23:27 +00:00
|
|
|
function minify_js($file) {
|
2012-09-07 05:49:16 +00:00
|
|
|
$file = str_replace("'../externals/jush/'", "location.protocol + '//www.adminer.org/static/'", $file);
|
2012-09-07 05:23:27 +00:00
|
|
|
if (function_exists('jsShrink')) {
|
|
|
|
$file = jsShrink($file);
|
|
|
|
}
|
2012-09-07 05:37:24 +00:00
|
|
|
return lzw_compress($file);
|
2012-09-07 05:23:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 20:43:41 +00:00
|
|
|
function compile_file($match) {
|
2009-07-13 21:40:43 +00:00
|
|
|
global $project;
|
2012-09-07 05:23:27 +00:00
|
|
|
$file = "";
|
|
|
|
foreach (explode(";", $match[1]) as $filename) {
|
|
|
|
$file .= file_get_contents(dirname(__FILE__) . "/$project/$filename");
|
|
|
|
}
|
2012-09-07 05:37:24 +00:00
|
|
|
if ($match[2]) {
|
|
|
|
$file = call_user_func($match[2], $file);
|
|
|
|
}
|
|
|
|
return '"' . add_quo_slashes($file) . '"';
|
2009-06-26 20:43:41 +00:00
|
|
|
}
|
|
|
|
|
2010-05-07 13:44:22 +00:00
|
|
|
$driver = "";
|
2010-04-21 12:01:32 +00:00
|
|
|
if (file_exists(dirname(__FILE__) . "/adminer/drivers/" . $_SERVER["argv"][1] . ".inc.php")) {
|
2010-05-07 13:44:22 +00:00
|
|
|
$driver = $_SERVER["argv"][1];
|
2010-04-21 12:01:32 +00:00
|
|
|
array_shift($_SERVER["argv"]);
|
|
|
|
}
|
|
|
|
|
2009-09-10 19:05:27 +00:00
|
|
|
unset($_COOKIE["adminer_lang"]);
|
|
|
|
$_SESSION["lang"] = $_SERVER["argv"][1]; // Adminer functions read language from session
|
2010-04-21 12:01:32 +00:00
|
|
|
include dirname(__FILE__) . "/adminer/include/lang.inc.php";
|
2009-09-10 19:05:27 +00:00
|
|
|
if (isset($_SESSION["lang"])) {
|
|
|
|
if (isset($_SERVER["argv"][2]) || !isset($langs[$_SESSION["lang"]])) {
|
2012-02-17 20:10:37 +00:00
|
|
|
echo "Usage: php compile.php [driver] [lang]\nPurpose: Compile adminer[-driver][-lang].php and editor[-driver][-lang].php.\n";
|
2007-07-05 10:46:44 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-09-10 19:05:27 +00:00
|
|
|
include dirname(__FILE__) . "/adminer/lang/$_SESSION[lang].inc.php";
|
2007-07-05 10:46:44 +00:00
|
|
|
}
|
2007-08-04 19:36:01 +00:00
|
|
|
|
2010-04-21 12:01:32 +00:00
|
|
|
// check function definition in drivers
|
|
|
|
$filename = dirname(__FILE__) . "/adminer/drivers/mysql.inc.php";
|
|
|
|
preg_match_all('~\\bfunction ([^(]+)~', file_get_contents($filename), $matches); //! respect context (extension, class)
|
|
|
|
$functions = array_combine($matches[1], $matches[0]);
|
|
|
|
unset($functions["__destruct"], $functions["Min_DB"], $functions["Min_Result"]);
|
2010-05-07 13:44:22 +00:00
|
|
|
foreach (glob(dirname(__FILE__) . "/adminer/drivers/" . ($driver ? $driver : "*") . ".inc.php") as $filename) {
|
2010-04-21 12:01:32 +00:00
|
|
|
if ($filename != "mysql.inc.php") {
|
|
|
|
$file = file_get_contents($filename);
|
|
|
|
foreach ($functions as $val) {
|
|
|
|
if (!strpos($file, "$val(")) {
|
2012-09-16 13:13:48 +00:00
|
|
|
fprintf(STDERR, "Missing $val in $filename\n");
|
2010-04-21 12:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-07 13:44:22 +00:00
|
|
|
include dirname(__FILE__) . "/adminer/include/pdo.inc.php";
|
2011-06-04 02:19:14 +00:00
|
|
|
$features = array("call" => "routine", "dump", "event", "privileges", "procedure" => "routine", "processlist", "routine", "scheme", "sequence", "status", "trigger", "type", "user" => "privileges", "variables", "view");
|
2009-10-06 11:49:31 +00:00
|
|
|
foreach (array("adminer", "editor") as $project) {
|
|
|
|
$lang_ids = array(); // global variable simplifies usage in a callback function
|
|
|
|
$file = file_get_contents(dirname(__FILE__) . "/$project/index.php");
|
2010-05-07 13:44:22 +00:00
|
|
|
if ($driver) {
|
2010-05-05 16:30:55 +00:00
|
|
|
$connection = (object) array("server_info" => 5.1); // MySQL support is version specific
|
2010-05-07 13:44:22 +00:00
|
|
|
$_GET[$driver] = true; // to load the driver
|
|
|
|
include_once dirname(__FILE__) . "/adminer/drivers/$driver.inc.php";
|
2011-06-04 02:19:14 +00:00
|
|
|
foreach ($features as $key => $feature) {
|
2010-04-21 12:01:32 +00:00
|
|
|
if (!support($feature)) {
|
2011-06-04 02:19:14 +00:00
|
|
|
if (!is_int($key)) {
|
|
|
|
$feature = $key;
|
|
|
|
}
|
2010-04-21 12:01:32 +00:00
|
|
|
$file = str_replace("} elseif (isset(\$_GET[\"$feature\"])) {\n\tinclude \"./$feature.inc.php\";\n", "", $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!support("routine")) {
|
|
|
|
$file = str_replace("if (isset(\$_GET[\"callf\"])) {\n\t\$_GET[\"call\"] = \$_GET[\"callf\"];\n}\nif (isset(\$_GET[\"function\"])) {\n\t\$_GET[\"procedure\"] = \$_GET[\"function\"];\n}\n", "", $file);
|
|
|
|
}
|
|
|
|
}
|
2009-10-06 11:49:31 +00:00
|
|
|
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
|
|
|
|
$file = str_replace('include "../adminer/include/coverage.inc.php";', '', $file);
|
2010-05-07 13:44:22 +00:00
|
|
|
if ($driver) {
|
|
|
|
$file = preg_replace('(include "../adminer/drivers/(?!' . preg_quote($driver) . ').*\\s*)', '', $file);
|
2010-04-21 12:01:32 +00:00
|
|
|
}
|
2009-10-06 11:49:31 +00:00
|
|
|
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file); // bootstrap.inc.php
|
2010-05-21 13:42:17 +00:00
|
|
|
if ($driver) {
|
|
|
|
foreach ($features as $feature) {
|
|
|
|
if (!support($feature)) {
|
|
|
|
$file = preg_replace("((\t*)" . preg_quote('if (support("' . $feature . '")') . ".*\n\\1\\})sU", '', $file);
|
|
|
|
}
|
|
|
|
}
|
2010-05-28 09:13:37 +00:00
|
|
|
if (count($drivers) == 1) {
|
2010-06-08 20:55:08 +00:00
|
|
|
$file = str_replace('<?php echo html_select("driver", $drivers, DRIVER); ?>', "<input type='hidden' name='driver' value='" . ($driver == "mysql" ? "server" : $driver) . "'>" . reset($drivers), $file);
|
2010-05-28 09:13:37 +00:00
|
|
|
}
|
2010-05-21 13:42:17 +00:00
|
|
|
}
|
2009-10-06 11:49:31 +00:00
|
|
|
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
|
2012-09-02 13:44:32 +00:00
|
|
|
$file = preg_replace_callback('~\\b(include|require) "([^"]*\\$LANG.inc.php)";~', 'put_file_lang', $file);
|
2012-09-07 05:15:03 +00:00
|
|
|
$file = str_replace("\r", "", $file);
|
2009-10-06 11:49:31 +00:00
|
|
|
if ($_SESSION["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; ?>', $_SESSION["lang"], $file);
|
|
|
|
}
|
|
|
|
$file = str_replace('<script type="text/javascript" src="static/editing.js"></script>' . "\n", "", $file);
|
2012-09-07 05:37:24 +00:00
|
|
|
$file = preg_replace_callback("~compile_file\\('([^']+)'(?:, '([^']*)')?\\)~", 'compile_file', $file); // integrate static files
|
2011-02-09 14:28:45 +00:00
|
|
|
$replace = 'h(preg_replace("~\\\\\\\\?.*~", "", ME)) . "?file=\\1&version=' . $VERSION;
|
2012-04-16 05:18:03 +00:00
|
|
|
$file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
|
2009-10-06 11:49:31 +00:00
|
|
|
$file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
|
|
|
|
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
|
|
|
|
$file = php_shrink($file);
|
2009-07-20 15:46:34 +00:00
|
|
|
|
2010-05-07 13:44:22 +00:00
|
|
|
$filename = $project . (preg_match('~-dev$~', $VERSION) ? "" : "-$VERSION") . ($driver ? "-$driver" : "") . ($_SESSION["lang"] ? "-$_SESSION[lang]" : "") . ".php";
|
2009-10-06 11:49:31 +00:00
|
|
|
fwrite(fopen($filename, "w"), $file); // file_put_contents() since PHP 5
|
2010-04-21 12:01:32 +00:00
|
|
|
echo "$filename created (" . strlen($file) . " B).\n";
|
2009-10-06 11:49:31 +00:00
|
|
|
}
|