Permalink
Browse files

php_shrink()

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@356 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 21ea4ae commit 794192d9c68fd0825ec15260441fff3ec80e0d6c jakubvrana committed Sep 4, 2007
Showing with 23 additions and 0 deletions.
  1. +23 −0 _compile.php
View
@@ -41,6 +41,28 @@ function put_file($match) {
return $return;
}
+// Dgx's PHP shrinker
+function php_shrink($input) {
+ $set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
+ $space = '';
+ $output = '';
+ foreach (token_get_all($input) as $token) {
+ if (!is_array($token)) {
+ $token = array(0, $token);
+ }
+ if ($token[0] == T_COMMENT || $token[0] == T_WHITESPACE) {
+ $space = "\n";
+ } else {
+ if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
+ $space = '';
+ }
+ $output .= $space . $token[1];
+ $space = '';
+ }
+ }
+ return $output;
+}
+
error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) {
$_COOKIE["lang"] = $_SERVER["argv"][1];
@@ -64,5 +86,6 @@ function put_file($match) {
$file = str_replace("arrow.gif", '" . preg_replace("~\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?gif=arrow', $file);
$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);
$file = str_replace('<link rel="stylesheet" type="text/css" href="default.css" />', "<style type='text/css'>\n" . file_get_contents("default.css") . "</style>", $file);
+$file = php_shrink($file);
fwrite(fopen($filename, "w"), $file);
echo "$filename created.\n";

0 comments on commit 794192d

Please sign in to comment.