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