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 9if (!defined('DOKU_INC')) 10 define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/'); 11if (!defined('DOKU_PLUGIN')) 12 define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 13require_once (DOKU_PLUGIN . 'syntax.php'); 14 15class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin { 16 17 function getInfo() { 18 return array ( 19 'author' => 'Gina Häußge, Michael Klier', 20 'email' => 'dokuwiki@chimeric.de', 21 'date' => @file_get_contents(DOKU_PLUGIN . 'blog/VERSION'), 22 'name' => 'Include Plugin (footer component)', 23 'desc' => 'Provides a header instruction which renders a permalink to the included page', 24 'url' => 'http://wiki.splitbrain.org/plugin:include', 25 ); 26 } 27 28 function getType() { 29 return 'formatting'; 30 } 31 32 function getSort() { 33 return 300; 34 } 35 36 function handle($match, $state, $pos, &$handler) { 37 // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser 38 } 39 40 /** 41 * Renders a permalink header. 42 * 43 * Code heavily copied from the header renderer from inc/parser/xhtml.php, just 44 * added an href parameter to the anchor tag linking to the wikilink. 45 */ 46 function render($mode, &$renderer, $data) { 47 48 list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data; 49 50 if ($mode == 'xhtml') { 51 $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer); 52 return true; 53 } 54 return false; 55 } 56 57 /** 58 * Returns the meta line below the included page 59 */ 60 function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) { 61 global $conf, $ID; 62 63 if(!$flags['footer']) return ''; 64 65 $meta = p_get_metadata($page); 66 $xhtml = array(); 67 68 // permalink 69 if ($flags['permalink']) { 70 $class = (page_exists($page) ? 'wikilink1' : 'wikilink2'); 71 $url = ($sect) ? wl($page) . '#' . $sect : wl($page); 72 $name = ($sect) ? $sect_title : $page; 73 $title = ($sect) ? $page . '#' . $sect : $page; 74 if (!$title) $title = str_replace('_', ' ', noNS($page)); 75 $link = array( 76 'url' => $url, 77 'title' => $title, 78 'name' => $name, 79 'target' => $conf['target']['wiki'], 80 'class' => $class . ' permalink', 81 'more' => 'rel="bookmark"', 82 ); 83 $xhtml[] = $renderer->_formatLink($link); 84 } 85 86 // date 87 if ($flags['date']) { 88 $date = $meta['date']['created']; 89 if ($date) { 90 $xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">' 91 . strftime($conf['dformat'], $date) 92 . '</abbr>'; 93 } 94 } 95 96 // author 97 if ($flags['user']) { 98 $author = $meta['creator']; 99 if ($author) { 100 $userpage = cleanID($this->getConf('usernamespace').':'.$author); 101 resolve_pageid(getNS($ID), $userpage, $exists); 102 $class = ($exists ? 'wikilink1' : 'wikilink2'); 103 $link = array( 104 'url' => wl($userpage), 105 'title' => $userpage, 106 'name' => hsc($author), 107 'target' => $conf['target']['wiki'], 108 'class' => $class.' url fn', 109 'pre' => '<span class="vcard author">', 110 'suf' => '</span>', 111 ); 112 $xhtml[] = $renderer->_formatLink($link); 113 } 114 } 115 116 // comments - let Discussion Plugin do the work for us 117 if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion =& plugin_load('helper', 'discussion'))) { 118 $disc = $discussion->td($page); 119 if ($disc) $xhtml[] = '<span class="comment">' . $disc . '</span>'; 120 } 121 122 // linkbacks - let Linkback Plugin do the work for us 123 if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback =& plugin_load('helper', 'linkback'))) { 124 $link = $linkback->td($page); 125 if ($link) $xhtml[] = '<span class="linkback">' . $link . '</span>'; 126 } 127 128 $xhtml = implode(DOKU_LF . DOKU_TAB . '· ', $xhtml); 129 130 // tags - let Tag Plugin do the work for us 131 if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag =& plugin_load('helper', 'tag'))) { 132 $tags = '<div class="tags"><span>' . DOKU_LF 133 . DOKU_TAB . $tag->td($page) . DOKU_LF 134 . DOKU_TAB . '</span></div>' . DOKU_LF; 135 $xhtml .= $tags . DOKU_TAB; 136 } 137 138 if (!$xhtml) $xhtml = ' '; 139 $class = 'inclmeta'; 140 $class .= ' level' . $footer_lvl; 141 return '<div class="' . $class . '">' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '</div>' . DOKU_LF; 142 } 143} 144// vim:ts=4:sw=4:et:enc=utf-8: 145