You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
6.8 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  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. // must be run from within DokuWiki
  11. if (!defined('DOKU_INC')) die();
  12. /**
  13. * Create link/button to discussion page and back
  14. *
  15. * @author Anika Henke <anika@selfthinker.org>
  16. */
  17. function _tpl_discussion($discussionPage, $title, $backTitle, $link=0, $wrapper=0) {
  18. global $ID;
  19. $discussPage = str_replace('@ID@', $ID, $discussionPage);
  20. $discussPageRaw = str_replace('@ID@', '', $discussionPage);
  21. $isDiscussPage = strpos($ID, $discussPageRaw) !== false;
  22. $backID = str_replace($discussPageRaw, '', $ID);
  23. if ($wrapper) echo "<$wrapper>";
  24. if ($isDiscussPage) {
  25. if ($link)
  26. tpl_pagelink($backID, $backTitle);
  27. else
  28. echo html_btn('back2article', $backID, '', array(), 'get', 0, $backTitle);
  29. } else {
  30. if ($link)
  31. tpl_pagelink($discussPage, $title);
  32. else
  33. echo html_btn('discussion', $discussPage, '', array(), 'get', 0, $title);
  34. }
  35. if ($wrapper) echo "</$wrapper>";
  36. }
  37. /**
  38. * Create link/button to user page
  39. *
  40. * @author Anika Henke <anika@selfthinker.org>
  41. */
  42. function _tpl_userpage($userPage, $title, $link=0, $wrapper=0) {
  43. if (!$_SERVER['REMOTE_USER']) return;
  44. global $conf;
  45. $userPage = str_replace('@USER@', $_SERVER['REMOTE_USER'], $userPage);
  46. if ($wrapper) echo "<$wrapper>";
  47. if ($link)
  48. tpl_pagelink($userPage, $title);
  49. else
  50. echo html_btn('userpage', $userPage, '', array(), 'get', 0, $title);
  51. if ($wrapper) echo "</$wrapper>";
  52. }
  53. /**
  54. * Create link/button to register page
  55. * @deprecated DW versions > 2011-02-20 can use the core function tpl_action('register')
  56. *
  57. * @author Anika Henke <anika@selfthinker.org>
  58. */
  59. function _tpl_register($link=0, $wrapper=0) {
  60. global $conf;
  61. global $lang;
  62. global $ID;
  63. $lang_register = !empty($lang['btn_register']) ? $lang['btn_register'] : $lang['register'];
  64. if ($_SERVER['REMOTE_USER'] || !$conf['useacl'] || !actionOK('register')) return;
  65. if ($wrapper) echo "<$wrapper>";
  66. if ($link)
  67. tpl_link(wl($ID, 'do=register'), $lang_register, 'class="action register" rel="nofollow"');
  68. else
  69. echo html_btn('register', $ID, '', array('do'=>'register'), 'get', 0, $lang_register);
  70. if ($wrapper) echo "</$wrapper>";
  71. }
  72. /**
  73. * Wrapper around custom template actions
  74. *
  75. * @author Anika Henke <anika@selfthinker.org>
  76. */
  77. function _tpl_action($type, $link=0, $wrapper=0) {
  78. switch ($type) {
  79. case 'discussion':
  80. if (tpl_getConf('discussionPage')) {
  81. _tpl_discussion(tpl_getConf('discussionPage'), tpl_getLang('discussion'), tpl_getLang('back_to_article'), $link, $wrapper);
  82. }
  83. break;
  84. case 'userpage':
  85. if (tpl_getConf('userPage')) {
  86. _tpl_userpage(tpl_getConf('userPage'), tpl_getLang('userpage'), $link, $wrapper);
  87. }
  88. break;
  89. case 'register': // deprecated
  90. _tpl_register($link, $wrapper);
  91. break;
  92. }
  93. }
  94. /* deprecated functions for backwards compatibility
  95. ********************************************************************/
  96. /**
  97. * Returns icon from data/media root directory if it exists, otherwise
  98. * the one in the template's image directory.
  99. * @deprecated superseded by core tpl_getFavicon()
  100. *
  101. * @param bool $abs - if to use absolute URL
  102. * @param string $fileName - file name of icon
  103. * @author Anika Henke <anika@selfthinker.org>
  104. */
  105. function _tpl_getFavicon($abs=false, $fileName='favicon.ico') {
  106. if (file_exists(mediaFN($fileName))) {
  107. return ml($fileName, '', true, '', $abs);
  108. }
  109. if($abs) {
  110. return DOKU_URL.substr(DOKU_TPL.'images/'.$fileName, strlen(DOKU_REL));
  111. }
  112. return DOKU_TPL.'images/'.$fileName;
  113. }
  114. /* use core function if available, otherwise the custom one */
  115. if (!function_exists('tpl_getFavicon')) {
  116. function tpl_getFavicon($abs=false, $fileName='favicon.ico') {
  117. _tpl_getFavicon($abs, $fileName);
  118. }
  119. }
  120. /**
  121. * Returns <link> tag for various icon types (favicon|mobile|generic)
  122. * @deprecated superseded by core tpl_favicon()
  123. *
  124. * @param array $types - list of icon types to display (favicon|mobile|generic)
  125. * @author Anika Henke <anika@selfthinker.org>
  126. */
  127. function _tpl_favicon($types=array('favicon')) {
  128. $return = '';
  129. foreach ($types as $type) {
  130. switch($type) {
  131. case 'favicon':
  132. $return .= '<link rel="shortcut icon" href="'.tpl_getFavicon().'" />'.NL;
  133. break;
  134. case 'mobile':
  135. $return .= '<link rel="apple-touch-icon" href="'.tpl_getFavicon(false, 'apple-touch-icon.png').'" />'.NL;
  136. break;
  137. case 'generic':
  138. // ideal world solution, which doesn't work in any browser yet
  139. $return .= '<link rel="icon" href="'.tpl_getFavicon(false, 'icon.svg').'" type="image/svg+xml" />'.NL;
  140. break;
  141. }
  142. }
  143. return $return;
  144. }
  145. /* use core function if available, otherwise the custom one */
  146. if (!function_exists('tpl_favicon')) {
  147. function tpl_favicon($types=array('favicon')) {
  148. _tpl_favicon($types);
  149. }
  150. }
  151. /**
  152. * Include additional html file from conf directory if it exists, otherwise use
  153. * file in the template's root directory.
  154. * @deprecated superseded by core tpl_includeFile()
  155. *
  156. * @author Anika Henke <anika@selfthinker.org>
  157. */
  158. function _tpl_include($fn) {
  159. $confFile = DOKU_CONF.$fn;
  160. $tplFile = dirname(__FILE__).'/'.$fn;
  161. if (file_exists($confFile))
  162. include($confFile);
  163. else if (file_exists($tplFile))
  164. include($tplFile);
  165. }
  166. /* use core function if available, otherwise the custom one */
  167. if (!function_exists('tpl_includeFile')) {
  168. function tpl_includeFile($fn) {
  169. _tpl_include($fn);
  170. }
  171. }
  172. /* if newer settings exist in the core, use them, otherwise fall back to template settings */
  173. if (!isset($conf['tagline'])) {
  174. $conf['tagline'] = tpl_getConf('tagline');
  175. }
  176. if (!isset($conf['sidebar'])) {
  177. $conf['sidebar'] = tpl_getConf('sidebarID');
  178. }
  179. if (!function_exists('tpl_sidebar')) {
  180. function tpl_sidebar() {
  181. /* includes the given wiki page; not exactly the same as in the core */
  182. tpl_include_page($conf['sidebar']);
  183. }
  184. }
  185. /* these $lang strings are now in the core */
  186. if (!isset($lang['user_tools'])) {
  187. $lang['user_tools'] = tpl_getLang('user_tools');
  188. }
  189. if (!isset($lang['site_tools'])) {
  190. $lang['site_tools'] = tpl_getLang('site_tools');
  191. }
  192. if (!isset($lang['page_tools'])) {
  193. $lang['page_tools'] = tpl_getLang('page_tools');
  194. }
  195. if (!isset($lang['skip_to_content'])) {
  196. $lang['skip_to_content'] = tpl_getLang('skip_to_content');
  197. }