X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/cb96273d9e57cf57eaab4015b46a4e0b43cc1c55..c4985f69a5d947a08867c9cb4c65d3709f2ad82f:/src/stub-phar.php?ds=sidebyside diff --git a/src/stub-phar.php b/src/stub-phar.php index 72e367d..859152b 100644 --- a/src/stub-phar.php +++ b/src/stub-phar.php @@ -9,7 +9,7 @@ * @author Christian Weiske * @copyright 2014 Christian Weiske * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 - * @link http://phorkie.sf.net/ + * @link https://cweiske.de/phorkie.htm */ if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) { echo "Phar extension not avaiable\n"; @@ -45,10 +45,41 @@ function rewritePath($path) return 'www/index.php'; } - if (substr($path, -4) == '.css') { + $path = rewriteWithHtaccess($path); + + if (substr($path, -4) == '.css' + || substr($path, -3) == '.js' + || substr($path, 0, 9) == '/phorkie/' + ) { 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();