diff options
author | Michael Hamann <michael@content-space.de> | 2012-09-18 21:57:56 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2012-09-18 22:15:50 +0200 |
commit | 14977bd2edded61cecdc10116826eef384777e82 (patch) | |
tree | 1e12b5ccb232980635f72a557300b40c6f6b6b12 | |
parent | bd4e4c94416613145edca00156831fb283024684 (diff) | |
download | rpg-14977bd2edded61cecdc10116826eef384777e82.tar.gz rpg-14977bd2edded61cecdc10116826eef384777e82.tar.bz2 |
Fix CSS cache handling and CSS output
This fixes several problems:
- the CSS cache was only updated when either the CSS files for all media
types or one of the global files was modified
- when only the screen CSS was changed, the screen CSS was regenerated
but then the cache was printed which either caused duplicated screen
CSS output when gzip output was disabled or invalid output with gzip
enabled as first the plain text screen CSS and then the
gzip-compressed cache file was printed
Now first all CSS files are collected, then the cache is checked once
and only after this the CSS content is collected.
-rw-r--r-- | lib/exe/css.php | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 8de3db11b..0ad9dee06 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -64,21 +64,27 @@ function css_out(){ // start output buffering ob_start(); + // Array of needed files and their web locations, the latter ones + // are needed to fix relative paths in the stylesheets + $files = array(); + + $cache_files = getConfigFiles('main'); + $cache_files[] = $tplinc.'style.ini'; + $cache_files[] = __FILE__; + foreach($mediatypes as $mediatype) { - // Array of needed files and their web locations, the latter ones - // are needed to fix relative paths in the stylesheets - $files = array(); + $files[$mediatype] = array(); // load core styles - $files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; + $files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/'; // load jQuery-UI theme if ($mediatype == 'screen') { - $files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; + $files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/'; } // load plugin styles - $files = array_merge($files, css_pluginstyles($mediatype)); + $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype)); // load template styles if (isset($tplstyles[$mediatype])) { - $files = array_merge($files, $tplstyles[$mediatype]); + $files[$mediatype] = array_merge($files[$mediatype], $tplstyles[$mediatype]); } // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { @@ -86,7 +92,7 @@ function css_out(){ } // load user styles if(isset($config_cascade['userstyle'][$mediatype])){ - $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; + $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; } // load rtl styles // note: this adds the rtl styles only to the 'screen' media type @@ -94,20 +100,20 @@ function css_out(){ // please use "[dir=rtl]" in any css file in all, screen or print mode instead if ($mediatype=='screen') { if($lang['direction'] == 'rtl'){ - if (isset($tplstyles['rtl'])) $files = array_merge($files, $tplstyles['rtl']); + if (isset($tplstyles['rtl'])) $files[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']); } } - $cache_files = array_merge(array_keys($files), getConfigFiles('main')); - $cache_files[] = $tplinc.'style.ini'; - $cache_files[] = __FILE__; + $cache_files = array_merge($cache_files, array_keys($files[$mediatype])); + } - // check cache age & handle conditional request - // This may exit if a cache can be used - http_cached($cache->cache, - $cache->useCache(array('files' => $cache_files))); + // check cache age & handle conditional request + // This may exit if a cache can be used + http_cached($cache->cache, + $cache->useCache(array('files' => $cache_files))); - // build the stylesheet + // build the stylesheet + foreach ($mediatypes as $mediatype) { // print the default classes for interwiki links and file downloads if ($mediatype == 'screen') { @@ -117,7 +123,7 @@ function css_out(){ // load files $css_content = ''; - foreach($files as $file => $location){ + foreach($files[$mediatype] as $file => $location){ $css_content .= css_loadfile($file, $location); } switch ($mediatype) { |