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.

121 lines
3.3 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 (empty($_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. * Wrapper around custom template actions
  55. *
  56. * @author Anika Henke <anika@selfthinker.org>
  57. */
  58. function _tpl_action($type, $link=0, $wrapper=0) {
  59. switch ($type) {
  60. case 'discussion':
  61. if (tpl_getConf('discussionPage')) {
  62. _tpl_discussion(tpl_getConf('discussionPage'), tpl_getLang('discussion'), tpl_getLang('back_to_article'), $link, $wrapper);
  63. }
  64. break;
  65. case 'userpage':
  66. if (tpl_getConf('userPage')) {
  67. _tpl_userpage(tpl_getConf('userPage'), tpl_getLang('userpage'), $link, $wrapper);
  68. }
  69. break;
  70. }
  71. }
  72. /**
  73. * Create event for tools menues
  74. *
  75. * @author Anika Henke <anika@selfthinker.org>
  76. */
  77. function _tpl_toolsevent($toolsname, $items, $view='main') {
  78. $data = array(
  79. 'view' => $view,
  80. 'items' => $items
  81. );
  82. $hook = 'TEMPLATE_'.strtoupper($toolsname).'_DISPLAY';
  83. $evt = new Doku_Event($hook, $data);
  84. if($evt->advise_before()){
  85. foreach($evt->data['items'] as $k => $html) echo $html;
  86. }
  87. $evt->advise_after();
  88. }
  89. /**
  90. * copied from core
  91. * @todo: remove when it's available in stable (autumn 2013)
  92. */
  93. if (!function_exists('tpl_classes')) {
  94. function tpl_classes() {
  95. global $ACT, $conf, $ID, $INFO;
  96. $classes = array(
  97. 'dokuwiki',
  98. 'mode_'.$ACT,
  99. 'tpl_'.$conf['template'],
  100. !empty($_SERVER['REMOTE_USER']) ? 'loggedIn' : '',
  101. $INFO['exists'] ? '' : 'notFound',
  102. ($ID == $conf['start']) ? 'home' : '',
  103. );
  104. return join(' ', $classes);
  105. }
  106. }