summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries/Gallery_View.php
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-06-29 08:24:42 -0700
committerTim Almdal <tnalmdal@shaw.ca>2009-06-29 08:24:42 -0700
commit6ec293dfe70665c528d803b78a2bb295633496ec (patch)
treebe3b7f8d7c2e8ba0e11e3432e2891206272efc1a /modules/gallery/libraries/Gallery_View.php
parent10b4eda6f0cbb44fde9fb3158bd174c82467f2ee (diff)
*Note* work in progress.
Implement the combined css functionality. Local url references and replace with absolute urls instead of relative.
Diffstat (limited to 'modules/gallery/libraries/Gallery_View.php')
-rw-r--r--modules/gallery/libraries/Gallery_View.php47
1 files changed, 44 insertions, 3 deletions
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
index 7000d3de..1c1dec38 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -113,12 +113,53 @@ class Gallery_View_Core extends View {
protected function combine_css() {
$links = array();
$key = "";
+ static $PATTERN = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#";
+
foreach (array_keys($this->css) as $file) {
- $links[] = "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
- url::file($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("alert", "CSS file missing: " . $file);
+ }
+ }
+ $key = md5($key);
+ $cache = Cache::instance();
+ $contents = $cache->get($key);
+ $docroot_length = strlen(DOCROOT);
+
+ if (empty($contents)) {
+ $contents = "";
+ foreach ($links as $link) {
+ $css = file_get_contents($link);
+ if (preg_match_all($PATTERN, $css, $matches, PREG_SET_ORDER)) {
+ $search = $replace = array();
+ foreach ($matches as $match) {
+ $relative = substr(realpath(dirname($link) . "/$match[1]"), $docroot_length);
+ if (!empty($relative)) {
+ $search[] = $match[1];
+ $replace[] = url::abs_file($relative);
+ } else {
+ Kohana::log("alert", sprintf("Missing URL reference '%s' in CSS file '%s' ",
+ $match[1], $link));
+ }
+ }
+ $css = str_replace($search, $replace, $css);
+ }
+ $contents .= $css;
+ }
+ $cache->set($key, $contents, array("css"), 30 * 84600);
+ if (function_exists("gzencode")) {
+ $cache->set("{$key}_gz", gzencode($contents, 9, FORCE_GZIP),
+ array("css", "gzip"), 30 * 84600);
+ }
}
- return implode("\n", $links);
+ return "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
+ url::site("combined/css/$key") . "\" />";
}
} \ No newline at end of file