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.
 
 
 
 
 

143 lines
4.0 KiB

  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, $return=0) {
  18. global $ID;
  19. $output = '';
  20. $discussPage = str_replace('@ID@', $ID, $discussionPage);
  21. $discussPageRaw = str_replace('@ID@', '', $discussionPage);
  22. $isDiscussPage = strpos($ID, $discussPageRaw) !== false;
  23. $backID = ':'.str_replace($discussPageRaw, '', $ID);
  24. if ($wrapper) $output .= "<$wrapper>";
  25. if ($isDiscussPage) {
  26. if ($link) {
  27. ob_start();
  28. tpl_pagelink($backID, $backTitle);
  29. $output .= ob_get_contents();
  30. ob_end_clean();
  31. } else {
  32. $output .= html_btn('back2article', $backID, '', array(), 'get', 0, $backTitle);
  33. }
  34. } else {
  35. if ($link) {
  36. ob_start();
  37. tpl_pagelink($discussPage, $title);
  38. $output .= ob_get_contents();
  39. ob_end_clean();
  40. } else {
  41. $output .= html_btn('discussion', $discussPage, '', array(), 'get', 0, $title);
  42. }
  43. }
  44. if ($wrapper) $output .= "</$wrapper>";
  45. if ($return) return $output;
  46. echo $output;
  47. }
  48. /**
  49. * Create link/button to user page
  50. *
  51. * @author Anika Henke <anika@selfthinker.org>
  52. */
  53. function _tpl_userpage($userPage, $title, $link=0, $wrapper=0, $return=0) {
  54. if (empty($_SERVER['REMOTE_USER'])) return;
  55. global $conf;
  56. $output = '';
  57. $userPage = str_replace('@USER@', $_SERVER['REMOTE_USER'], $userPage);
  58. if ($wrapper) $output .= "<$wrapper>";
  59. if ($link) {
  60. ob_start();
  61. tpl_pagelink($userPage, $title);
  62. $output .= ob_get_contents();
  63. ob_end_clean();
  64. } else {
  65. $output .= html_btn('userpage', $userPage, '', array(), 'get', 0, $title);
  66. }
  67. if ($wrapper) $output .= "</$wrapper>";
  68. if ($return) return $output;
  69. echo $output;
  70. }
  71. /**
  72. * Wrapper around custom template actions
  73. *
  74. * @author Anika Henke <anika@selfthinker.org>
  75. */
  76. function _tpl_action($type, $link=0, $wrapper=0, $return=0) {
  77. switch ($type) {
  78. case 'discussion':
  79. if (tpl_getConf('discussionPage')) {
  80. $output = _tpl_discussion(tpl_getConf('discussionPage'), tpl_getLang('discussion'), tpl_getLang('back_to_article'), $link, $wrapper, 1);
  81. if ($return) return $output;
  82. echo $output;
  83. }
  84. break;
  85. case 'userpage':
  86. if (tpl_getConf('userPage')) {
  87. $output = _tpl_userpage(tpl_getConf('userPage'), tpl_getLang('userpage'), $link, $wrapper, 1);
  88. if ($return) return $output;
  89. echo $output;
  90. }
  91. break;
  92. }
  93. }
  94. /**
  95. * copied to core (available since Detritus)
  96. */
  97. if (!function_exists('tpl_toolsevent')) {
  98. function tpl_toolsevent($toolsname, $items, $view='main') {
  99. $data = array(
  100. 'view' => $view,
  101. 'items' => $items
  102. );
  103. $hook = 'TEMPLATE_'.strtoupper($toolsname).'_DISPLAY';
  104. $evt = new Doku_Event($hook, $data);
  105. if($evt->advise_before()){
  106. foreach($evt->data['items'] as $k => $html) echo $html;
  107. }
  108. $evt->advise_after();
  109. }
  110. }
  111. /**
  112. * copied from core (available since Binky)
  113. */
  114. if (!function_exists('tpl_classes')) {
  115. function tpl_classes() {
  116. global $ACT, $conf, $ID, $INFO;
  117. $classes = array(
  118. 'dokuwiki',
  119. 'mode_'.$ACT,
  120. 'tpl_'.$conf['template'],
  121. !empty($_SERVER['REMOTE_USER']) ? 'loggedIn' : '',
  122. $INFO['exists'] ? '' : 'notFound',
  123. ($ID == $conf['start']) ? 'home' : '',
  124. );
  125. return join(' ', $classes);
  126. }
  127. }