1<?php
2/**
3 * DokuWiki Plugin sitemapnavi (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <grosse@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14class syntax_plugin_sitemapnavi extends DokuWiki_Syntax_Plugin
15{
16    /**
17     * @return string Syntax mode type
18     */
19    public function getType()
20    {
21        return 'substition';
22    }
23
24    /**
25     * @return string Paragraph type
26     */
27    public function getPType()
28    {
29        return 'block';
30    }
31
32    /**
33     * @return int Sort order - Low numbers go before high numbers
34     */
35    public function getSort()
36    {
37        return 99;
38    }
39
40    /**
41     * Connect lookup pattern to lexer.
42     *
43     * @param string $mode Parser mode
44     */
45    public function connectTo($mode)
46    {
47        $this->Lexer->addSpecialPattern('{{sitemapnavi}}', $mode, 'plugin_sitemapnavi');
48    }
49
50    /**
51     * Handle matches of the sitemapnavi syntax
52     *
53     * @param string $match The match of the syntax
54     * @param int $state The state of the handler
55     * @param int $pos The position in the document
56     * @param Doku_Handler $handler The handler
57     * @return array Data for the renderer
58     */
59    public function handle($match, $state, $pos, Doku_Handler $handler)
60    {
61        $data = array();
62
63        return $data;
64    }
65
66    /**
67     * Render xhtml output or metadata
68     *
69     * @param string $mode Renderer mode (supported modes: xhtml)
70     * @param Doku_Renderer $renderer The renderer
71     * @param array $data The data from the handler() function
72     * @return bool If rendering was successful.
73     */
74    public function render($mode, Doku_Renderer $renderer, $data)
75    {
76        if ($mode !== 'xhtml') {
77            return false;
78        }
79
80        global $conf, $INFO;
81        $renderer->info['cache'] = false;
82
83        /** @var helper_plugin_sitemapnavi $helper */
84        $helper = $this->loadHelper('sitemapnavi');
85        $listHtml = $helper->getSiteMap(':');
86
87        $divClass = empty($this->getConf('showMedia')) ? 'hide-media-links' : '';
88        $renderer->doc .= '<div id="plugin__sitemapnavi" class="' . $divClass . '">';
89        $renderer->doc .= $listHtml; //html_buildlist($pages, 'idx', [$this, 'listItemCallback'], [$this, 'liCallback']);
90        $renderer->doc .= '</div>';
91
92        return true;
93    }
94}
95
96// vim:ts=4:sw=4:et:
97