fix rewrite map loading
[phorkie.git] / src / stub-phar.php
index 72e367d17e2a0ceb897e6ab2e1dd8a65563b38a3..9b65f2fabdf7c7c15a4f01b44f7e90bfd0d1d506 100644 (file)
@@ -45,10 +45,38 @@ function rewritePath($path)
         return 'www/index.php';
     }
 
         return 'www/index.php';
     }
 
-    if (substr($path, -4) == '.css') {
+    $path = rewriteWithHtaccess($path);
+
+    if (substr($path, -4) == '.css' || substr($path, -3) == '.js') {
         header('Expires: ' . date('r', time() + 86400 * 7));
     }
         header('Expires: ' . date('r', time() + 86400 * 7));
     }
-    return $path;
+    return 'www' . $path;
+}
+
+function rewriteWithHtaccess($path)
+{
+    //remove the leading slash /
+    $cpath = substr($path, 1);
+    $bFoundMatch = false;
+    $map = include('phar://' . __FILE__ . '/src/gen-rewritemap.php');
+    foreach ($map as $pattern => $replace) {
+        if (preg_match($pattern, $cpath, $matches)) {
+            $bFoundMatch = true;
+            break;
+        }
+    }
+    if (!$bFoundMatch) {
+        return $path;
+    }
+    $newcpath = preg_replace($pattern, $replace, $cpath);
+    if (strpos($newcpath, '?') === false) {
+        return '/' . $newcpath;
+    }
+    list($cfile, $getParams) = explode('?', $newcpath, 2);
+    if ($getParams != '') {
+        parse_str($getParams, $_GET);
+    }
+    return '/' . $cfile;
 }
 
 //Phar::interceptFileFuncs();
 }
 
 //Phar::interceptFileFuncs();