footer.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Include plugin (footer component)
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Michael Klier <chi@chimeric.de>
  7. */
  8. class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
  9. function getType() {
  10. return 'formatting';
  11. }
  12. function getSort() {
  13. return 300;
  14. }
  15. function handle($match, $state, $pos, Doku_Handler $handler) {
  16. // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
  17. }
  18. /**
  19. * Renders a permalink header.
  20. *
  21. * Code heavily copied from the header renderer from inc/parser/xhtml.php, just
  22. * added an href parameter to the anchor tag linking to the wikilink.
  23. */
  24. function render($mode, Doku_Renderer $renderer, $data) {
  25. list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
  26. if ($mode == 'xhtml') {
  27. $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
  28. return true;
  29. }
  30. return false;
  31. }
  32. /**
  33. * Returns the meta line below the included page
  34. * @param $renderer Doku_Renderer_xhtml The (xhtml) renderer
  35. * @return string The HTML code of the footer
  36. */
  37. function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) {
  38. global $conf, $ID;
  39. if(!$flags['footer']) return '';
  40. $meta = p_get_metadata($page);
  41. $exists = page_exists($page);
  42. $xhtml = array();
  43. // permalink
  44. if ($flags['permalink']) {
  45. $class = ($exists ? 'wikilink1' : 'wikilink2');
  46. $url = ($sect) ? wl($page) . '#' . $sect : wl($page);
  47. $name = ($sect) ? $sect_title : $page;
  48. $title = ($sect) ? $page . '#' . $sect : $page;
  49. if (!$title) $title = str_replace('_', ' ', noNS($page));
  50. $link = array(
  51. 'url' => $url,
  52. 'title' => $title,
  53. 'name' => $name,
  54. 'target' => $conf['target']['wiki'],
  55. 'class' => $class . ' permalink',
  56. 'more' => 'rel="bookmark"',
  57. );
  58. $xhtml[] = $renderer->_formatLink($link);
  59. }
  60. // date
  61. if ($flags['date'] && $exists) {
  62. $date = $meta['date']['created'];
  63. if ($date) {
  64. $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
  65. . strftime($conf['dformat'], $date)
  66. . '</abbr>';
  67. }
  68. }
  69. // modified date
  70. if ($flags['mdate'] && $exists) {
  71. $mdate = $meta['date']['modified'];
  72. if ($mdate) {
  73. $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $mdate).'">'
  74. . strftime($conf['dformat'], $mdate)
  75. . '</abbr>';
  76. }
  77. }
  78. // author
  79. if ($flags['user'] && $exists) {
  80. $author = $meta['user'];
  81. if ($author) {
  82. if (function_exists('userlink')) {
  83. $xhtml[] = '<span class="vcard author">' . userlink($author) . '</span>';
  84. } else { // DokuWiki versions < 2014-05-05 doesn't have userlink support, fall back to not providing a link
  85. $xhtml[] = '<span class="vcard author">' . editorinfo($author) . '</span>';
  86. }
  87. }
  88. }
  89. // comments - let Discussion Plugin do the work for us
  90. if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion = plugin_load('helper', 'discussion'))) {
  91. $disc = $discussion->td($page);
  92. if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>';
  93. }
  94. // linkbacks - let Linkback Plugin do the work for us
  95. if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback = plugin_load('helper', 'linkback'))) {
  96. $link = $linkback->td($page);
  97. if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>';
  98. }
  99. $xhtml = implode(DOKU_LF . DOKU_TAB . '&middot; ', $xhtml);
  100. // tags - let Tag Plugin do the work for us
  101. if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) {
  102. $tags = $tag->td($page);
  103. if($tags) {
  104. $xhtml .= '<div class="tags"><span>' . DOKU_LF
  105. . DOKU_TAB . $tags . DOKU_LF
  106. . DOKU_TAB . '</span></div>' . DOKU_LF;
  107. }
  108. }
  109. if (!$xhtml) $xhtml = '&nbsp;';
  110. $class = 'inclmeta';
  111. $class .= ' level' . $footer_lvl;
  112. return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF;
  113. }
  114. }
  115. // vim:ts=4:sw=4:et: