diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/controllers/javascript.php | 37 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 11 |
2 files changed, 28 insertions, 20 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); } } diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 167f8a8d..f55cb55a 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -188,18 +188,21 @@ class Theme_View_Core extends View { } $key = md5($key); - $file = "tmp/CombinedJavascript_$key"; - if (!file_exists(VARPATH . $file)) { + $contents = Cache::instance()->get($key); + if (empty($contents)) { $contents = ''; foreach ($links as $link) { $contents .= file_get_contents($link); } - file_put_contents(VARPATH . $file, $contents); + Cache::instance()->set($key, $contents, array("javascript"), 84600); if (function_exists("gzencode")) { - file_put_contents(VARPATH . "{$file}_gzip", gzencode($contents, 9, FORCE_GZIP)); + Cache::instance()->set("{$key}_gz", gzencode($contents, 9, FORCE_GZIP), + array("javascript", "gzip"), 84600); } + Cache::instance()->set("{$key}_modified", time(), array("javascript", "modified"), 84600); } + // Handcraft the script link because html::script will add a .js extenstion return "<script type=\"text/javascript\" src=\"" . url::site("javascript/combined/$key") . "\"></script>"; } |