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_header 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 50; 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 list($headline, $lvl, $page, $sect, $flags) = $data; 51 $hid = $renderer->_headerToLink($headline); 52 if ($mode == 'xhtml') { 53 $renderer->toc_additem($hid, $headline, $lvl); 54 $url = ($sect) ? wl($page) . '#' . $sect : wl($page); 55 $renderer->doc .= DOKU_LF.'<h' . $lvl; 56 if($flags['taglogos']) { 57 $tag = $this->_get_firsttag($page); 58 if($tag) { 59 $renderer->doc .= ' class="include_firsttag__' . $tag . '"'; 60 } 61 } 62 $headline = $renderer->_xmlEntities($headline); 63 $renderer->doc .= '><a name="' . $hid . '" id="' . $hid . '" href="' . $url . '" title="' . $headline . '">'; 64 $renderer->doc .= $headline; 65 $renderer->doc .= '</a></h' . $lvl . '>' . DOKU_LF; 66 return true; 67 } elseif($mode == 'metadata') { 68 $renderer->toc_additem($hid, $headline, $lvl); 69 return true; 70 } 71 return false; 72 } 73 74 /** 75 * Optionally add a CSS class for the first tag 76 * 77 * @author Michael Klier <chi@chimeric.de> 78 */ 79 function _get_firsttag($page) { 80 if(plugin_isdisabled('tag') || (!$taghelper =& plugin_load('helper', 'tag'))) { 81 return false; 82 } 83 $subject = p_get_metadata($page, 'subject'); 84 if (is_array($subject)) { 85 $tag = $subject[0]; 86 } else { 87 list($tag, $rest) = explode(' ', $subject, 2); 88 } 89 if($tag) { 90 return $tag; 91 } else { 92 return false; 93 } 94 } 95} 96// vim:ts=4:sw=4:et:enc=utf-8: 97