Remove code generation

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@760 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-06-26 20:43:41 +00:00
parent 9e0ce84a79
commit 9ee9cf08e1
2 changed files with 37 additions and 26 deletions

View file

@ -7,6 +7,32 @@
*/
error_reporting(E_ALL & ~E_NOTICE);
// used only in compiled file
if (isset($_GET["file"])) {
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 365*24*60*60) . " GMT");
if ($_GET["file"] == "favicon.ico") {
header("Content-Type: image/x-icon");
echo base64_decode("compile_file('favicon.ico', 'base64_encode')");
} elseif ($_GET["file"] == "default.css") {
header("Content-Type: text/css");
?>compile_file('default.css', 'minify_css')<?php
} elseif ($_GET["file"] == "functions.js") {
header("Content-Type: text/javascript");
?>compile_file('functions.js', 'JSMin::minify')<?php
} else {
header("Content-Type: image/gif");
switch ($_GET["file"]) {
case "plus.gif": echo base64_decode("compile_file('plus.gif', 'base64_encode')"); break;
case "cross.gif": echo base64_decode("compile_file('cross.gif', 'base64_encode')"); break;
case "up.gif": echo base64_decode("compile_file('up.gif', 'base64_encode')"); break;
case "down.gif": echo base64_decode("compile_file('down.gif', 'base64_encode')"); break;
case "arrow.gif": echo base64_decode("compile_file('arrow.gif', 'base64_encode')"); break;
}
}
exit;
}
if (!ini_get("session.auto_start")) {
// use specific session name to get own namespace
session_name("adminer_sid");

View file

@ -158,6 +158,14 @@ function php_shrink($input) {
return $output;
}
function minify_css($file) {
return preg_replace('~\\s*([:;{},])\\s*~', '\\1', $file);
}
function compile_file($match) {
return call_user_func($match[2], file_get_contents(dirname(__FILE__) . "/adminer/$match[1]"));
}
error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) {
$_COOKIE["adminer_lang"] = $_SERVER["argv"][1]; // Adminer functions read language from cookie
@ -182,33 +190,10 @@ if ($_COOKIE["adminer_lang"]) {
} else {
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
}
$file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\)~", 'compile_file', $file); // integrate static files
$replace = 'htmlspecialchars(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\0&amp;version=' . $VERSION;
$file = preg_replace('~default\\.css|functions\\.js|favicon\\.ico~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~(plus|cross|up|down|arrow)\\.gif~', '" . ' . $replace, $file);
$file = str_replace('error_reporting(E_ALL & ~E_NOTICE);', 'error_reporting(E_ALL & ~E_NOTICE);
if (isset($_GET["file"])) {
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 365*24*60*60) . " GMT");
if ($_GET["file"] == "favicon.ico") {
header("Content-Type: image/x-icon");
echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/favicon.ico")) . '");
} elseif ($_GET["file"] == "default.css") {
header("Content-Type: text/css");
?>' . preg_replace('~\\s*([:;{},])\\s*~', '\\1', file_get_contents(dirname(__FILE__) . "/adminer/default.css")) . '<?php
} elseif ($_GET["file"] == "functions.js") {
header("Content-Type: text/javascript");
?>' . JSMin::minify(file_get_contents(dirname(__FILE__) . "/adminer/functions.js")) . '<?php
} else {
header("Content-Type: image/gif");
switch ($_GET["file"]) {
case "arrow.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/arrow.gif")) . '"); break;
case "up.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/up.gif")) . '"); break;
case "down.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/down.gif")) . '"); break;
case "plus.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/plus.gif")) . '"); break;
case "cross.gif": echo base64_decode("' . base64_encode(file_get_contents(dirname(__FILE__) . "/adminer/cross.gif")) . '"); break;
}
}
exit;
}', $file); // integrate static files
$file = preg_replace('~(?<!== ")(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~(?<!case ")(plus|cross|up|down|arrow)\\.gif~', '" . ' . $replace, $file);
$file = str_replace("../externals/jush/", "http://jush.sourceforge.net/", $file);
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
$file = php_shrink($file);