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.

136 lines
3.7 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. *
  56. * @author Anika Henke <anika@selfthinker.org>
  57. */
  58. function _tpl_register($link=0,$wrapper=0) {
  59. global $conf;
  60. global $lang;
  61. global $ID;
  62. if ($_SERVER['REMOTE_USER'] || !$conf['useacl'] || !actionOK('register')) return;
  63. if ($wrapper) echo "<$wrapper>";
  64. if ($link)
  65. tpl_link(wl($ID,'do=register'),$lang['register'],'class="action register" rel="nofollow"');
  66. else
  67. echo html_btn('register',$ID,'',array('do'=>'register'),'get',0,$lang['register']);
  68. if ($wrapper) echo "</$wrapper>";
  69. }
  70. /**
  71. * Wrapper around custom template actions
  72. *
  73. * @author Anika Henke <anika@selfthinker.org>
  74. */
  75. function _tpl_action($type,$link=0,$wrapper=0) {
  76. switch ($type) {
  77. case 'discussion':
  78. if (tpl_getConf('discussionPage')) {
  79. _tpl_discussion(tpl_getConf('discussionPage'),tpl_getLang('discussion'),tpl_getLang('back_to_article'),$link,$wrapper);
  80. }
  81. break;
  82. case 'userpage':
  83. if (tpl_getConf('userPage')) {
  84. _tpl_userpage(tpl_getConf('userPage'),tpl_getLang('userpage'),$link,$wrapper);
  85. }
  86. break;
  87. case 'register':
  88. _tpl_register($link,$wrapper);
  89. break;
  90. }
  91. }
  92. /**
  93. * Use favicon.ico from data/media root directory if it exists, otherwise use
  94. * the one in the template's image directory.
  95. *
  96. * @author Anika Henke <anika@selfthinker.org>
  97. */
  98. function _tpl_getFavicon() {
  99. if (file_exists(mediaFN('favicon.ico')))
  100. return ml('favicon.ico');
  101. return DOKU_TPL.'images/favicon.ico';
  102. }
  103. /**
  104. * Include additional html file from conf directory if it exists, otherwise use
  105. * file in the template's root directory.
  106. *
  107. * @author Anika Henke <anika@selfthinker.org>
  108. */
  109. function _tpl_include($fn) {
  110. $confFile = DOKU_CONF.$fn;
  111. $tplFile = dirname(__FILE__).'/'.$fn;
  112. if (file_exists($confFile))
  113. include($confFile);
  114. else if (file_exists($tplFile))
  115. include($tplFile);
  116. }