Skip to content
Snippets Groups Projects
Commit 124af657 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

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
parent b65e3b9f
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment