From 11f08ee4399c62cc1d2c36457a214c6db693db06 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 26 Jun 2009 21:42:02 -0700 Subject: Implement the combined javascript controller. --- modules/gallery/controllers/javascript.php | 64 ++++++++++++++++++++++++++++++ modules/gallery/libraries/Theme_View.php | 29 ++++++++++++-- 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 modules/gallery/controllers/javascript.php (limited to 'modules') diff --git a/modules/gallery/controllers/javascript.php b/modules/gallery/controllers/javascript.php new file mode 100644 index 00000000..d3c0ded5 --- /dev/null +++ b/modules/gallery/controllers/javascript.php @@ -0,0 +1,64 @@ +scripts)); + $key = ""; foreach (array_keys($this->scripts) as $file) { - $links[] = html::script($file); + $path = DOCROOT . $file; + if (file_exists($path)) { + $stats = stat($path); + $links[] = $path; + // 7 == size, 9 == mtime, see http://php.net/stat + $key = "{$key}$file $stats[7] $stats[9],"; + } else { + Kohana::log("warn", "Javascript file missing: " . $file); + } + } + + $key = md5($key); + $file = "tmp/CombinedJavascript_$key"; + if (!file_exists(VARPATH . $file)) { + $contents = ''; + foreach ($links as $link) { + $contents .= file_get_contents($link); + } + file_put_contents(VARPATH . $file, $contents); + if (function_exists("gzencode")) { + file_put_contents(VARPATH . "{$file}_gzip", gzencode($contents, 9, FORCE_GZIP)); + } } - return empty($links) ? "" : implode("\n", $links); + + return ""; } /** -- cgit v1.2.3