diff options
author | emkael <emkael@tlen.pl> | 2015-01-28 11:07:05 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2015-01-28 11:07:05 +0100 |
commit | 6a900ef8a872a82ac44605572b2c9b392efffbf2 (patch) | |
tree | 6894ccf348827f716a03f1ffc81546606f6708ec /http/index.php | |
parent | cab5dcbafb0f82ba742ac014741dfc4208be9fbd (diff) |
* base path configuration
Diffstat (limited to 'http/index.php')
-rw-r--r-- | http/index.php | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/http/index.php b/http/index.php index 42a2731..700951d 100644 --- a/http/index.php +++ b/http/index.php @@ -1,5 +1,6 @@ <?php +define('BASE_PATH', '/'); define('CACHE_PATH', '../cache'); define('CEZAR_URL', 'http://msc.com.pl/cezar/'); @@ -26,7 +27,7 @@ function fetch_with_user_agent_spoof($targetFile, $sourceUrl) { } // parse requested path (after rewrite) -$url = parse_url($_SERVER['REQUEST_URI']); +$url = parse_url(preg_replace('/^' . preg_quote(BASE_PATH) . '/', $_SERVER['REQUEST_URI'])); $path = array_values(array_filter(explode('/', $url['path']))); if ($path) { @@ -34,13 +35,13 @@ if ($path) { $cache = !(count($path) > 1 && $path[1] == 'refresh'); // build Cezar URL for requested path - $path[0] = urldecode($path[0]); + $path[0] = urldecode($path[0]); $searchUrl = new http\Url(CEZAR_URL, ['query' => http_build_query( ['pid_search' => $path[0], 'p' => '21'] )]); - + $mscUrl = $searchUrl->toString(); $content = get_cache_content($path[0], $mscUrl, !$cache); // requested content @@ -49,9 +50,13 @@ if ($path) { // if the comment delimiters are present, we're possibly dealing with the content we want, slice it and wrap it $delimiters = array_keys(preg_grep('/---- page content /', $contentLines)); if ($delimiters) { - $content = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><base href="/" /><style>body {width: 580px; font-family: Tahoma, Geneva, Arial, Helvetica, "sans-serif";}</style></head><body>' - . implode(PHP_EOL, array_slice($contentLines, $delimiters[0]+1, $delimiters[1]-$delimiters[0]-1)) - . '</body></html>'; + $content = '<html><head>' + . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' + . '<base href="' . BASE_PATH . '" />' + . '<style>body {width: 580px; font-family: Tahoma, Geneva, Arial, Helvetica, "sans-serif";}</style>' + . '</head><body>' + . implode(PHP_EOL, array_slice($contentLines, $delimiters[0]+1, $delimiters[1]-$delimiters[0]-1)) + . '</body></html>'; } else { die('Malformed (even more than usually) content :('); |