summaryrefslogtreecommitdiff
path: root/inc/template.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/template.php')
-rw-r--r--inc/template.php101
1 files changed, 81 insertions, 20 deletions
diff --git a/inc/template.php b/inc/template.php
index b338d2ce9..d007f47ef 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -23,6 +23,31 @@ 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(){
+ global $conf;
+ 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(){
+ global $conf;
+ return DOKU_BASE.'lib/tpl/'.$conf['template'].'/';
+}
+
/**
* Print the content
*
@@ -555,7 +580,7 @@ function tpl_get_action($type) {
$accesskey = 'v';
}
}else{
- $params = '';
+ $params = array();
$type = 'show';
$accesskey = 'v';
}
@@ -572,7 +597,7 @@ function tpl_get_action($type) {
break;
case 'top':
$accesskey = 'x';
- $params = '';
+ $params = array();
$id = '#dokuwiki__top';
break;
case 'back':
@@ -581,7 +606,7 @@ function tpl_get_action($type) {
return false;
}
$id = $parent;
- $params = '';
+ $params = array();
$accesskey = 'b';
break;
case 'login':
@@ -969,7 +994,7 @@ function tpl_img($maxwidth=0,$maxheight=0,$link=true,$params=null){
/**
* Default action for TPL_IMG_DISPLAY
*/
-function _tpl_img_action($data, $param=NULL) {
+function _tpl_img_action($data, $param=null) {
global $lang;
$p = buildAttributes($data['params']);
@@ -987,8 +1012,6 @@ function _tpl_img_action($data, $param=NULL) {
*/
function tpl_indexerWebBug(){
global $ID;
- global $INFO;
- if(!$INFO['exists']) return false;
$p = array();
$p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
@@ -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();
@@ -1207,7 +1230,7 @@ function tpl_mediaFileDetails($image, $rev){
list($ext,$mime,$dl) = mimetype($image,false);
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$class = 'select mediafile mf_'.$class;
- $tabTitle = '<strong class="'.$class.'">'.$image.'</strong>';
+ $tabTitle = '<strong class="'.$class.'"><a href="'.ml($image).'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
if ($opened_tab === 'view' && $rev) {
printf($lang['media_viewold'], $tabTitle, dformat($rev));
} else {
@@ -1325,31 +1348,33 @@ function tpl_actiondropdown($empty='',$button='&gt;'){
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $img - print image? (|button|badge)
* @param bool $return - when true don't print, but return HTML
+ * @param bool $wrap - wrap in div with class="license"?
*/
-function tpl_license($img='badge',$imgonly=false,$return=false){
+function tpl_license($img='badge',$imgonly=false,$return=false,$wrap=true){
global $license;
global $conf;
global $lang;
if(!$conf['license']) return '';
if(!is_array($license[$conf['license']])) return '';
$lic = $license[$conf['license']];
+ $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
- $out = '<div class="license">';
+ $out = '';
+ if($wrap) $out .= '<div class="license">';
if($img){
$src = license_img($img);
if($src){
- $out .= '<a href="'.$lic['url'].'" rel="license"';
- if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
- $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
+ $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
+ $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
+ if(!$imgonly) $out .= ' ';
}
}
if(!$imgonly) {
- $out .= $lang['license'];
- $out .= ' <a href="'.$lic['url'].'" rel="license" class="urlextern"';
- if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
+ $out .= $lang['license'].' ';
+ $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
$out .= '>'.$lic['name'].'</a>';
}
- $out .= '</div>';
+ if($wrap) $out .= '</div>';
if($return) return $out;
echo $out;
@@ -1476,7 +1501,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 +1517,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));
}
@@ -1500,6 +1525,42 @@ function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
}
/**
+ * PHP include a file
+ *
+ * either from the conf directory if it exists, otherwise use
+ * file in the template's root directory.
+ *
+ * The function honours config cascade settings and looks for the given
+ * file next to the ´main´ config files, in the order protected, local,
+ * default.
+ *
+ * Note: no escaping or sanity checking is done here. Never pass user input
+ * to this function!
+ *
+ * @author Anika Henke <anika@selfthinker.org>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function tpl_includeFile($file){
+ global $config_cascade;
+ foreach (array('protected','local','default') as $config_group) {
+ if (empty($config_cascade['main'][$config_group])) continue;
+ foreach ($config_cascade['main'][$config_group] as $conf_file) {
+ $dir = dirname($conf_file);
+ if(file_exists("$dir/$file")){
+ include("$dir/$file");
+ return;
+ }
+ }
+ }
+
+ // still here? try the template dir
+ $file = tpl_incdir().$file;
+ if(file_exists($file)){
+ include($file);
+ }
+}
+
+/**
* Returns icon from data/media root directory if it exists, otherwise
* the one in the template's image directory.
*