]> git.joonet.de Git - adminer.git/commitdiff
Remove code generation
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 26 Jun 2009 20:43:41 +0000 (20:43 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 26 Jun 2009 20:43:41 +0000 (20:43 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@760 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/index.php
compile.php

index 04f28c8d2102265028e98e875a48bc2e030a14ce..5e5a37e21872d805ffd505b3ce184ae6518ce7a5 100644 (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");
index 36624937e58f9038432e26ff53da0fce37bbb794..5ded8a8c414dc5c471f803c38dec01322b5246aa 100644 (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);