From afb2c08218345dc3604024c829a5c408e3f39277 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Aug 2013 14:42:05 +0200 Subject: allow for a style.ini in conf//style.ini This is another go at what pull request #227 tried to do. This removes support for a style.local.ini in the template file in preference of a style.ini in the conf folder --- lib/exe/css.php | 139 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 60 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index 83972d407..ce6a83fea 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -40,43 +40,33 @@ function css_out(){ $type = ''; } + // decide from where to get the template $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); - if($tpl){ - $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/'; - $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/'; - }else{ - $tplinc = tpl_incdir(); - $tpldir = tpl_basedir(); - } - - // used style.ini file - $styleini = css_styleini($tplinc); + if(!$tpl) $tpl = $conf['template']; // The generated script depends on some dynamic options - $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css'); + $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css'); - // load template styles - $tplstyles = array(); - if ($styleini) { - foreach($styleini['stylesheets'] as $file => $mode) { - $tplstyles[$mode][$tplinc.$file] = $tpldir; - } - } + // load styl.ini + $styleini = css_styleini($tpl); + + print_r($styleini); // 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']; } - // Array of needed files and their web locations, the latter ones - // are needed to fix relative paths in the stylesheets - $files = array(); - + // cache influencers + $tplinc = tpl_basedir($tpl); $cache_files = getConfigFiles('main'); $cache_files[] = $tplinc.'style.ini'; - $cache_files[] = $tplinc.'style.local.ini'; + $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini"; $cache_files[] = __FILE__; + // Array of needed files and their web locations, the latter ones + // are needed to fix relative paths in the stylesheets + $files = array(); foreach($mediatypes as $mediatype) { $files[$mediatype] = array(); // load core styles @@ -88,8 +78,8 @@ function css_out(){ // load plugin styles $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype)); // load template styles - if (isset($tplstyles[$mediatype])) { - $files[$mediatype] = array_merge($files[$mediatype], $tplstyles[$mediatype]); + if (isset($styleini['stylesheets'][$mediatype])) { + $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]); } // load user styles if(isset($config_cascade['userstyle'][$mediatype])){ @@ -101,7 +91,7 @@ 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[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']); + if (isset($styleini['stylesheets']['rtl'])) $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets']['rtl']); if (isset($config_cascade['userstyle']['rtl'])) $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE; } } @@ -154,7 +144,7 @@ function css_out(){ ob_end_clean(); // apply style replacements - $css = css_applystyle($css,$tplinc); + $css = css_applystyle($css, $styleini['replacements']); // parse less $css = css_parseless($css); @@ -200,7 +190,6 @@ function css_parseless($css) { // walk upwards to last include $lines = explode("\n", $css); - $count = count($lines); for($i=$lno-1; $i>=0; $i--){ if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){ // we found it, add info to message @@ -238,50 +227,80 @@ function css_parseless($css) { * * @author Andreas Gohr */ -function css_applystyle($css,$tplinc){ - $styleini = css_styleini($tplinc); - - if($styleini){ - // we convert ini replacements to LESS variable names - // and build a list of variable: value; pairs - $less = ''; - foreach($styleini['replacements'] as $key => $value){ - $lkey = trim($key, '_'); - $lkey = '@ini_'.$lkey; - $less .= "$lkey: $value;\n"; - - $styleini['replacements'][$key] = $lkey; - } +function css_applystyle($css, $replacements) { + // we convert ini replacements to LESS variable names + // and build a list of variable: value; pairs + $less = ''; + foreach((array) $replacements as $key => $value) { + $lkey = trim($key, '_'); + $lkey = '@ini_'.$lkey; + $less .= "$lkey: $value;\n"; + + $replacements[$key] = $lkey; + } - // we now replace all old ini replacements with LESS variables - $css = strtr($css, $styleini['replacements']); + // we now replace all old ini replacements with LESS variables + $css = strtr($css, $replacements); - // now prepend the list of LESS variables as the very first thing - $css = $less.$css; - } + // now prepend the list of LESS variables as the very first thing + $css = $less.$css; return $css; } /** - * Get contents of merged style.ini and style.local.ini as an array. + * Load style ini contents + * + * Loads and merges style.ini files from template and config and prepares + * the stylesheet modes * - * @author Anika Henke + * @author Andreas Gohr + * @param string $tpl the used template + * @return array with keys 'stylesheets' and 'replacements' */ -function css_styleini($tplinc) { - $styleini = array(); +function css_styleini($tpl) { + $stylesheets = array(); // mode, file => base + $replacements = array(); // placeholder => value + + // load template's style.ini + $incbase = tpl_incdir($tpl); + $webbase = tpl_basedir($tpl); + $ini = $incbase.'style.ini'; + if(file_exists($ini)){ + $data = parse_ini_file($ini, true); + + // stylesheets + if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ + $stylesheets[$mode][$incbase.$file] = $webbase; + } - foreach (array($tplinc.'style.ini', $tplinc.'style.local.ini') as $ini) { - $tmp = (@file_exists($ini)) ? parse_ini_file($ini, true) : array(); + // replacements + if(is_array($data['replacements'])){ + $replacements = array_merge($replacements, $data['replacements']); + } + } - 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; - } + // load configs's style.ini + $incbase = dirname($ini).'/'; + $webbase = DOKU_BASE; + $ini = DOKU_CONF."/tpl/$tpl/style.ini"; + if(file_exists($ini)){ + $data = parse_ini_file($ini, true); + + // stylesheets + if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ + $stylesheets[$mode][$incbase.$file] = $webbase; + } + + // replacements + if(is_array($data['replacements'])){ + $replacements = array_merge($replacements, $data['replacements']); } } - return $styleini; + + return array( + 'stylesheets' => $stylesheets, + 'replacements' => $replacements + ); } /** -- cgit v1.2.3 From 568ffd7ef769ecacdf91ac7bdf01dbcedaf8643a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Aug 2013 16:25:02 +0200 Subject: Readded style.local.ini and deprecated it --- lib/exe/css.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index ce6a83fea..aa82ba9a2 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -279,6 +279,23 @@ function css_styleini($tpl) { } } + // load template's style.local.ini + // @deprecated 2013-08-03 + $ini = $incbase.'style.local.ini'; + if(file_exists($ini)){ + $data = parse_ini_file($ini, true); + + // stylesheets + if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){ + $stylesheets[$mode][$incbase.$file] = $webbase; + } + + // replacements + if(is_array($data['replacements'])){ + $replacements = array_merge($replacements, $data['replacements']); + } + } + // load configs's style.ini $incbase = dirname($ini).'/'; $webbase = DOKU_BASE; -- cgit v1.2.3 From 90e793b91a348ae2876ed14c8b0d0000192d55e5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Aug 2013 22:52:10 +0200 Subject: removed debug statement --- lib/exe/css.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index aa82ba9a2..299e1ebcf 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -50,8 +50,6 @@ function css_out(){ // load styl.ini $styleini = css_styleini($tpl); - print_r($styleini); - // 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']; -- cgit v1.2.3 From 8c5aad7bcd74959cceb191697de486a5f6e98fd7 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 3 Aug 2013 22:16:08 +0100 Subject: fixed conf style.ini not working due to wrong incbase path --- lib/exe/css.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/exe') diff --git a/lib/exe/css.php b/lib/exe/css.php index aa82ba9a2..48304b2b6 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -297,9 +297,9 @@ function css_styleini($tpl) { } // load configs's style.ini - $incbase = dirname($ini).'/'; $webbase = DOKU_BASE; - $ini = DOKU_CONF."/tpl/$tpl/style.ini"; + $ini = DOKU_CONF."tpl/$tpl/style.ini"; + $incbase = dirname($ini).'/'; if(file_exists($ini)){ $data = parse_ini_file($ini, true); -- cgit v1.2.3