Permalink
Browse files

DOKU_TPL* considered harmful

Some plugins want to dynamically switch the template based on users,
namspaces or the phase of the moon. Having fixed paths in a unchangable
constant prevents this.

This changes deprecates the DOKU_TPL* constants in favor of two new
tpl_* functions that return the correct paths based on the $conf
variables which can be changed from the DOKUWIKI_STARTED event.
  • Loading branch information...
splitbrain committed Jan 30, 2012
1 parent 378325f commit c4766956646b53ab644ec6ddbd17d9cba07cf872
Showing with 29 additions and 6 deletions.
  1. +2 −2 inc/init.php
  2. +27 −4 inc/template.php
@@ -118,11 +118,11 @@ function delta_time($start=0) {
// define main script
if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');
// define Template baseURL
// DEPRECATED, use tpl_basedir() instead
if(!defined('DOKU_TPL')) define('DOKU_TPL',
DOKU_BASE.'lib/tpl/'.$conf['template'].'/');
// define real Template directory
// DEPRECATED, use tpl_incdir() instead
if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
DOKU_INC.'lib/tpl/'.$conf['template'].'/');
@@ -23,6 +23,29 @@ function template($tpl){
return DOKU_INC.'lib/tpl/default/'.$tpl;
}
/**
* Convenience function to access template dir from local FS
*
* This replaces the deprecated DOKU_TPLINC constant
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_incdir(){
return DOKU_INC.'lib/tpl/'.$conf['template'].'/';
}
/**
* Convenience function to access template dir from web
*
* This replaces the deprecated DOKU_TPL constant
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tpl_basedir(){
return DOKU_BASE.'lib/tpl/'.$conf['template'].'/';
}
/**
* Print the content
*
@@ -1034,7 +1057,7 @@ function tpl_getConf($id){
*/
function tpl_loadConfig(){
$file = DOKU_TPLINC.'/conf/default.php';
$file = tpl_incdir().'/conf/default.php';
$conf = array();
if (!@file_exists($file)) return false;
@@ -1055,7 +1078,7 @@ function tpl_getLang($id){
static $lang = array();
if (count($lang) === 0){
$path = DOKU_TPLINC.'lang/';
$path = tpl_incdir().'lang/';
$lang = array();
@@ -1476,7 +1499,7 @@ function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
$file = mediaFN($img);
$ismedia = true;
}else{
$file = DOKU_TPLINC.$img;
$file = tpl_incdir().$img;
$ismedia = false;
}
@@ -1492,7 +1515,7 @@ function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
if($ismedia){
$url = ml($img, '', true, '', $abs);
}else{
$url = DOKU_TPL.$img;
$url = tpl_basedir().$img;
if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
}

2 comments on commit c476695

@selfthinker

This comment has been minimized.

Collaborator

selfthinker replied Jan 31, 2012

Can you please document that those two constants are deprecated on http://www.dokuwiki.org/devel:releases#deprecation?

@bug

This comment has been minimized.

Collaborator

bug replied Feb 1, 2012

DOKU_TPL also appears in several files under lib/ dir. Shouldn't those be changed too?

Please sign in to comment.