diff options
author | JulienMoumne <julien@piwik.org> | 2010-09-04 17:35:16 +0400 |
---|---|---|
committer | JulienMoumne <julien@piwik.org> | 2010-09-04 17:35:16 +0400 |
commit | 04b65bcb536759fd9c2b8253ab25af76bdf43e06 (patch) | |
tree | 1ac8d27c0c7e0bf39c8e72ae801b374e24bd394a /js/index.php | |
parent | c93e3966e3bbcde674ab5e5eaff4de19d61f7893 (diff) |
fixes #1527 - merged assets are now returned to browser using a custom php proxy script, refs #660 - asset manager updated in two ways: - inclusion directive via proxy, - hash management dropped
git-svn-id: http://dev.piwik.org/svn/trunk@3048 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'js/index.php')
-rw-r--r-- | js/index.php | 81 |
1 files changed, 9 insertions, 72 deletions
diff --git a/js/index.php b/js/index.php index d98424ce71..cdda22c6b4 100644 --- a/js/index.php +++ b/js/index.php @@ -12,80 +12,17 @@ if(!empty($_SERVER['QUERY_STRING'])) { exit; } -$file = '../piwik.js'; - -if (file_exists($file) && function_exists('readfile')) { - // conditional GET - $modifiedSince = ''; - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { - $modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE']; - } - $lastModified = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'; - - // optional compression - $compressed = false; - $encoding = ''; - if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { - $acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING']; - if (extension_loaded('zlib') && function_exists('file_get_contents') && function_exists('file_put_contents')) { - if (preg_match('/(?:^|, ?)(deflate)(?:,|$)/', $acceptEncoding, $matches)) { - $encoding = 'deflate'; - $filegz = '../tmp/piwik.js.deflate'; - } else if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches)) { - $encoding = $matches[1]; - $filegz = '../tmp/piwik.js.gz'; - } - - if (!empty($encoding)) { - // compress-on-demand and use cache - if(!file_exists($filegz) || (filemtime($file) > filemtime($filegz))) { - $data = file_get_contents($file); - - if ($encoding == 'deflate') { - $data = gzcompress($data, 9); - } else if ($encoding == 'gzip' || $encoding == 'x-gzip') { - $data = gzencode($data, 9); - } - - file_put_contents($filegz, $data); - $file = $filegz; - } +/** + * @see core/Piwik.php + */ - $compressed = true; - $file = $filegz; - } - } else { - // manually compressed - $filegz = '../tmp/piwik.js.gz'; - if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches) && file_exists($filegz) && (filemtime($file) < filemtime($filegz))) { - $encoding = $matches[1]; - $compressed = true; - $file = $filegz; - } - } - } +define('PIWIK_INCLUDE_PATH', '..'); +define('PIWIK_DOCUMENT_ROOT', '..'); - // strip any trailing data appended to header - if (false !== ($semicolon = strpos($modifiedSince, ';'))) { - $modifiedSince = substr($modifiedSince, 0, $semicolon); - } +require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php'; - if ($modifiedSince == $lastModified) { - header('HTTP/1.1 304 Not Modified'); - } else { - header('Last-Modified: ' . $lastModified); - header('Content-Length: ' . filesize($file)); - header('Content-Type: application/javascript; charset=UTF-8'); +$file = 'piwik.js'; - if ($compressed) { - header('Content-Encoding: ' . $encoding); - } +Piwik::serveStaticFile($file, "application/javascript; charset=UTF-8"); - if (!readfile($file)) { - header ('HTTP/1.0 505 Internal server error'); - } - } -} else { - header ('HTTP/1.0 404 Not Found'); -} -exit; +exit;
\ No newline at end of file |