diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-06-28 15:30:13 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-06-28 15:30:13 -0700 |
commit | bf26ca727e615e61a8f61a2bbf1a83572cfa5c20 (patch) | |
tree | 91d82e6b5fa26bea3f9180b4d89b93c1e0520853 /modules/gallery/controllers/javascript.php | |
parent | 7a3310e91b50f37b09a1c9d10173409244015653 (diff) |
Change the combined javascript to use the new caching functionality and respect the HTTP_IF_MODIFIED_SINCE header request.
Diffstat (limited to 'modules/gallery/controllers/javascript.php')
-rw-r--r-- | modules/gallery/controllers/javascript.php | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/modules/gallery/controllers/javascript.php b/modules/gallery/controllers/javascript.php index d3c0ded5..bc231e0a 100644 --- a/modules/gallery/controllers/javascript.php +++ b/modules/gallery/controllers/javascript.php @@ -20,30 +20,35 @@ class Javascript_Controller extends Controller { public function combined($key) { if (preg_match('/[^0-9a-f]/', $key)) { - /* The key can't contain non-hex, so just terminate early */ + // The key can't contain non-hex, so just terminate early Kohana::show_404(); } // We don't need to save the session for this request Session::abort_save(); - Kohana::log("error", Kohana::debug($_SERVER)); // Dump out the javascript file - $ext = strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ? "_gzip" : ""; - $file = VARPATH . "tmp/CombinedJavascript_$key{$ext}"; + $cache = Cache::instance(); - if (!file_exists($file)) { - Kohana::show_404(); + $modified = $cache->get("{$key}_modified"); + if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && !empty($modified)) { + header('HTTP/1.0 304 Not Modified'); + return; } - $stats = stat($file); - if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && - $stats[9] <= $_SERVER["HTTP_IF_MODIFIED_SINCE"]) { - header("HTTP/1.0 304 Not Modified"); - return; + $content = ""; + if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ) { + $content = $cache->get("{$key}_gz"); + } + + if (empty($content)) { + $content = $cache->get($key); + } + + if (empty($content)) { + Kohana::show_404(); } - Kohana::log("error", Kohana::debug($_SERVER)); if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) { header("Content-Encoding: gzip"); header("Cache-Control: private, x-gzip-ok=\"public\""); @@ -52,13 +57,13 @@ class Javascript_Controller extends Controller { header("Content-Type: text/javascript; charset=UTF-8"); header("Expires: " . gmdate(21474383647)); - header("Last-Modified: " . gmdate($stats[9])); + header("Last-Modified: " . $modified); Kohana::close_buffers(false); - $fd = fopen($file, "rb"); - fpassthru($fd); - fclose($fd); + $handle = fopen("php://output", "wb"); + fwrite($handle, $content); + fclose($handle); } } |