From 124af657c8d7563757e72334573c08aec6457680 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Mon, 10 Mar 2008 21:16:30 +0100 Subject: [PATCH] allow dynamic passing of template to use for css.php This patch makes it possible to pass the template name to use to the lib/exe/css.php dispatcher. When passed the $conf['template'] option is ignored by the disaptcher and the given template is used instead. This makes it possible to switch templates dynamically without loosing the CSS dispatcher functionality. This might be useful for things like the multitemplate template or for loading a template based on the user agent. darcs-hash:20080310201630-7ad00-2062fa939b1f868540031ea42a42e948dd82bbb4.gz --- inc/template.php | 6 +++--- lib/exe/css.php | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/inc/template.php b/inc/template.php index 4f4ba9813..cc9d4f9f4 100644 --- a/inc/template.php +++ b/inc/template.php @@ -312,11 +312,11 @@ function tpl_metaheaders($alt=true){ // load stylesheets $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?s=all'); + 'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template']); $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php'); + 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template']); $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?s=print'); + 'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template']); // load javascript $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0; diff --git a/lib/exe/css.php b/lib/exe/css.php index e550ab206..11ae2e828 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -41,15 +41,24 @@ function css_out(){ break; } + $tpl = trim(preg_replace('/[^\w]+/','',$_REQUEST['t'])); + if($tpl){ + $tplinc = DOKU_INC.'lib/tpl/'.$tpl.'/'; + $tpldir = DOKU_BASE.'lib/tpl/'.$tpl.'/'; + }else{ + $tplinc = DOKU_TPLINC; + $tpldir = DOKU_TPL; + } + // The generated script depends on some dynamic options - $cache = getCacheName('styles'.DOKU_BASE.$conf['template'].$style,'.css'); + $cache = getCacheName('styles'.DOKU_BASE.$tplinc.$style,'.css'); // load template styles $tplstyles = array(); - if(@file_exists(DOKU_TPLINC.'style.ini')){ - $ini = parse_ini_file(DOKU_TPLINC.'style.ini',true); + if(@file_exists($tplinc.'style.ini')){ + $ini = parse_ini_file($tplinc.'style.ini',true); foreach($ini['stylesheets'] as $file => $mode){ - $tplstyles[$mode][DOKU_TPLINC.$file] = DOKU_TPL; + $tplstyles[$mode][$tplinc.$file] = $tpldir; } } @@ -80,7 +89,7 @@ function css_out(){ // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); - if(css_cacheok($cache,array_keys($files))){ + if(css_cacheok($cache,array_keys($files),$tplinc)){ http_conditionalRequest(filemtime($cache)); if($conf['allowdebug']) header("X-CacheUsed: $cache"); readfile($cache); @@ -106,7 +115,7 @@ function css_out(){ ob_end_clean(); // apply style replacements - $css = css_applystyle($css); + $css = css_applystyle($css,$tplinc); // compress whitespace and comments if($conf['compress']){ @@ -125,7 +134,7 @@ function css_out(){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function css_cacheok($cache,$files){ +function css_cacheok($cache,$files,$tplinc){ if($_REQUEST['purge']) return false; //support purge request $ctime = @filemtime($cache); @@ -134,7 +143,7 @@ function css_cacheok($cache,$files){ // some additional files to check $files[] = DOKU_CONF.'dokuwiki.php'; $files[] = DOKU_CONF.'local.php'; - $files[] = DOKU_TPLINC.'style.ini'; + $files[] = $tplinc.'style.ini'; $files[] = __FILE__; // now walk the files @@ -152,9 +161,9 @@ function css_cacheok($cache,$files){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function css_applystyle($css){ - if(@file_exists(DOKU_TPLINC.'style.ini')){ - $ini = parse_ini_file(DOKU_TPLINC.'style.ini',true); +function css_applystyle($css,$tplinc){ + if(@file_exists($tplinc.'style.ini')){ + $ini = parse_ini_file($tplinc.'style.ini',true); $css = strtr($css,$ini['replacements']); } return $css; -- GitLab