xref: /plugin/include/syntax/header.php (revision c44026dcfe3673d4d32f02d3abee46f69f306946)
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, $indata) {
50        global $ID;
51        list($text, $level) = $indata;
52
53        if ($mode == 'xhtml') {
54	        $hid = $renderer->_headerToLink($text,true);
55
56	        //only add items within configured levels
57	        $renderer->toc_additem($hid, $text, $level);
58
59	        // write the header
60	        $renderer->doc .= DOKU_LF.'<h'.$level.'><a name="'.$hid.'" id="'.$hid.'" href="'.wl($ID).'">';
61	        $renderer->doc .= $renderer->_xmlEntities($text);
62	        $renderer->doc .= "</a></h$level>".DOKU_LF;
63
64	        return true;
65        }
66
67        // unsupported $mode
68        return false;
69    }
70}
71
72// vim:ts=4:sw=4:et:enc=utf-8:
73