1<?php 2/** 3 * Template Functions 4 * 5 * This file provides template specific custom functions that are 6 * not provided by the DokuWiki core. 7 * It is common practice to start each function with an underscore 8 * to make sure it won't interfere with future core functions. 9 */ 10 11// must be run from within DokuWiki 12if (!defined('DOKU_INC')) die(); 13 14/** 15 * Create link/button to discussion page and back 16 * 17 * @author Anika Henke <anika@selfthinker.org> 18 */ 19function _tpl_discussion($discussionPage,$title,$backTitle,$link=0,$wrapper=0) { 20 global $ID; 21 22 $discussPage = str_replace('@ID@',$ID,$discussionPage); 23 $discussPageRaw = str_replace('@ID@','',$discussionPage); 24 $isDiscussPage = strpos($ID,$discussPageRaw)!==false; 25 $backID = str_replace($discussPageRaw,'',$ID); 26 27 if ($wrapper) echo "<$wrapper>"; 28 29 if ($isDiscussPage) { 30 if ($link) 31 tpl_pagelink($backID,$backTitle); 32 else 33 echo html_btn('back2article',$backID,'',array(),'get',0,$backTitle); 34 } else { 35 if ($link) 36 tpl_pagelink($discussPage,$title); 37 else 38 echo html_btn('discussion',$discussPage,'',array(),'get',0,$title); 39 } 40 41 if ($wrapper) echo "</$wrapper>"; 42} 43 44/** 45 * Create link/button to user page 46 * 47 * @author Anika Henke <anika@selfthinker.org> 48 */ 49function _tpl_userpage($userPage,$title,$link=0,$wrapper=0) { 50 if (!$_SERVER['REMOTE_USER']) return; 51 52 global $conf; 53 $userPage = str_replace('@USER@',$_SERVER['REMOTE_USER'],$userPage); 54 55 if ($wrapper) echo "<$wrapper>"; 56 57 if ($link) 58 tpl_pagelink($userPage,$title); 59 else 60 echo html_btn('userpage',$userPage,'',array(),'get',0,$title); 61 62 if ($wrapper) echo "</$wrapper>"; 63} 64 65/** 66 * Create link/button to register page 67 * DW versions > 2011-02-20 can use the core function tpl_action('register') 68 * 69 * @author Anika Henke <anika@selfthinker.org> 70 */ 71function _tpl_register($link=0,$wrapper=0) { 72 global $conf; 73 global $lang; 74 global $ID; 75 $lang_register = !empty($lang['btn_register']) ? $lang['btn_register'] : $lang['register']; 76 77 if ($_SERVER['REMOTE_USER'] || !$conf['useacl'] || !actionOK('register')) return; 78 79 if ($wrapper) echo "<$wrapper>"; 80 81 if ($link) 82 tpl_link(wl($ID,'do=register'),$lang_register,'class="action register" rel="nofollow"'); 83 else 84 echo html_btn('register',$ID,'',array('do'=>'register'),'get',0,$lang_register); 85 86 if ($wrapper) echo "</$wrapper>"; 87} 88 89/** 90 * Wrapper around custom template actions 91 * 92 * @author Anika Henke <anika@selfthinker.org> 93 */ 94function _tpl_action($type,$link=0,$wrapper=0) { 95 switch ($type) { 96 case 'discussion': 97 if (tpl_getConf('discussionPage')) { 98 _tpl_discussion(tpl_getConf('discussionPage'),tpl_getLang('discussion'),tpl_getLang('back_to_article'),$link,$wrapper); 99 } 100 break; 101 case 'userpage': 102 if (tpl_getConf('userPage')) { 103 _tpl_userpage(tpl_getConf('userPage'),tpl_getLang('userpage'),$link,$wrapper); 104 } 105 break; 106 case 'register': 107 _tpl_register($link,$wrapper); 108 break; 109 } 110} 111 112/** 113 * Use favicon.ico from data/media root directory if it exists, otherwise use 114 * the one in the template's image directory. 115 * DW versions > 2010-11-12 can use the core function tpl_getFavicon() 116 * 117 * @author Anika Henke <anika@selfthinker.org> 118 */ 119function _tpl_getFavicon() { 120 if (file_exists(mediaFN('favicon.ico'))) 121 return ml('favicon.ico'); 122 return DOKU_TPL.'images/favicon.ico'; 123} 124 125/** 126 * Include additional html file from conf directory if it exists, otherwise use 127 * file in the template's root directory. 128 * 129 * @author Anika Henke <anika@selfthinker.org> 130 */ 131function _tpl_include($fn) { 132 $confFile = DOKU_CONF.$fn; 133 $tplFile = dirname(__FILE__).'/'.$fn; 134 135 if (file_exists($confFile)) 136 include($confFile); 137 else if (file_exists($tplFile)) 138 include($tplFile); 139} 140