From 14977bd2edded61cecdc10116826eef384777e82 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 18 Sep 2012 21:57:56 +0200 Subject: 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. --- lib/exe/css.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'lib/exe/css.php') 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) { -- cgit v1.2.3 From dbf794bf86316c93b56454ab5d2c658598cce617 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 18 Sep 2012 22:46:47 +0200 Subject: Set default userstyle only once as screen userstyle --- lib/exe/css.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 0ad9dee06..cee806ef4 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -61,6 +61,11 @@ function css_out(){ } } + // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility + if (isset($config_cascade['userstyle']['default'])) { + $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; + } + // start output buffering ob_start(); @@ -86,10 +91,6 @@ function css_out(){ if (isset($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'])) { - $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; - } // load user styles if(isset($config_cascade['userstyle'][$mediatype])){ $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; -- cgit v1.2.3 From c5c68de9adc23077defdd39f9264286a62fb2e0e Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 18 Sep 2012 22:47:22 +0200 Subject: Load rtl userstyle as it is still supported (did it ever work?) --- lib/exe/css.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index cee806ef4..fb639fc7e 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -102,6 +102,7 @@ function css_out(){ if ($mediatype=='screen') { if($lang['direction'] == 'rtl'){ if (isset($tplstyles['rtl'])) $files[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']); + if (isset($config_cascade['userstyle']['rtl'])) $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE; } } -- cgit v1.2.3 From 3899c2ecc4140de70c555215188bab73b4870e10 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 18 Sep 2012 22:53:59 +0200 Subject: Start output buffering in lib/exe/css.php only when the CSS is generated This prevents buffering of the cache file output. --- lib/exe/css.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index fb639fc7e..8899ff193 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -66,9 +66,6 @@ function css_out(){ $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; } - // 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(); @@ -114,6 +111,9 @@ function css_out(){ http_cached($cache->cache, $cache->useCache(array('files' => $cache_files))); + // start output buffering + ob_start(); + // build the stylesheet foreach ($mediatypes as $mediatype) { -- cgit v1.2.3 From 0e6f9f08b1c948f45d1867346a4502021afa55bc Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 7 Oct 2012 15:30:38 +0100 Subject: added support for local style.ini files --- lib/exe/css.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 8899ff193..dd69c94cf 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -49,14 +49,17 @@ function css_out(){ $tpldir = tpl_basedir(); } + // used style.ini file + $styleini = css_styleini($tplinc); + // The generated script depends on some dynamic options $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); // load template styles $tplstyles = array(); - if(@file_exists($tplinc.'style.ini')){ - $ini = parse_ini_file($tplinc.'style.ini',true); - foreach($ini['stylesheets'] as $file => $mode){ + if ($styleini) { + $ini = parse_ini_file($styleini, true); + foreach($ini['stylesheets'] as $file => $mode) { $tplstyles[$mode][$tplinc.$file] = $tpldir; } } @@ -71,7 +74,8 @@ function css_out(){ $files = array(); $cache_files = getConfigFiles('main'); - $cache_files[] = $tplinc.'style.ini'; + if ($styleini) + $cache_files[] = $styleini; $cache_files[] = __FILE__; foreach($mediatypes as $mediatype) { @@ -173,13 +177,26 @@ function css_out(){ * @author Andreas Gohr */ function css_applystyle($css,$tplinc){ - if(@file_exists($tplinc.'style.ini')){ - $ini = parse_ini_file($tplinc.'style.ini',true); + $styleini = css_styleini($tplinc); + + if($styleini){ + $ini = parse_ini_file($styleini,true); $css = strtr($css,$ini['replacements']); } return $css; } +/** + * If either exist, get the template's style.local.ini or style.ini file. + */ +function css_styleini($tplinc) { + if(@file_exists($tplinc.'style.local.ini')) + return $tplinc.'style.local.ini'; + if(@file_exists($tplinc.'style.ini')) + return $tplinc.'style.ini'; + return ''; +} + /** * Prints classes for interwikilinks * -- cgit v1.2.3 From 0ac69508958a06e566a51fb6a74802401ebe5eb5 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Thu, 11 Oct 2012 13:26:47 +0100 Subject: changed local style.ini to be merged with standard one --- lib/exe/css.php | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index dd69c94cf..ae160558a 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -58,8 +58,7 @@ function css_out(){ // load template styles $tplstyles = array(); if ($styleini) { - $ini = parse_ini_file($styleini, true); - foreach($ini['stylesheets'] as $file => $mode) { + foreach($styleini['stylesheets'] as $file => $mode) { $tplstyles[$mode][$tplinc.$file] = $tpldir; } } @@ -74,8 +73,8 @@ function css_out(){ $files = array(); $cache_files = getConfigFiles('main'); - if ($styleini) - $cache_files[] = $styleini; + $cache_files[] = $tplinc.'style.ini'; + $cache_files[] = $tplinc.'style.local.ini'; $cache_files[] = __FILE__; foreach($mediatypes as $mediatype) { @@ -180,21 +179,31 @@ function css_applystyle($css,$tplinc){ $styleini = css_styleini($tplinc); if($styleini){ - $ini = parse_ini_file($styleini,true); - $css = strtr($css,$ini['replacements']); + $css = strtr($css,$styleini['replacements']); } return $css; } /** - * If either exist, get the template's style.local.ini or style.ini file. + * Get contents of merged style.ini and style.local.ini as an array. + * + * @author Anika Henke */ function css_styleini($tplinc) { - if(@file_exists($tplinc.'style.local.ini')) - return $tplinc.'style.local.ini'; - if(@file_exists($tplinc.'style.ini')) - return $tplinc.'style.ini'; - return ''; + $styleini = array(); + + foreach (array($tplinc.'style.ini', $tplinc.'style.local.ini') as $ini) { + $tmp = (@file_exists($ini)) ? parse_ini_file($ini, true) : array(); + + foreach($tmp as $key => $value) { + if(array_key_exists($key, $styleini) && is_array($value)) { + $styleini[$key] = array_merge($styleini[$key], $tmp[$key]); + } else { + $styleini[$key] = $value; + } + } + } + return $styleini; } /** -- cgit v1.2.3 From cacfb6067895a011e255d9f940a8dac2fa2c1110 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Fri, 12 Oct 2012 23:15:53 +0100 Subject: fixed interwiki and filetype styles being included in all css modes --- lib/exe/css.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index ae160558a..1e662c64a 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -122,8 +122,10 @@ function css_out(){ // print the default classes for interwiki links and file downloads if ($mediatype == 'screen') { + print '@media screen {'; css_interwiki(); css_filetypes(); + print '}'; } // load files -- cgit v1.2.3