1<?php
2/**
3 * DokuWiki Plugin indexeverywhere (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Sascha Zantis <sascha.zantis@gmail.com>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12class syntax_plugin_indexeverywhere_showTheTree extends DokuWiki_Syntax_Plugin {
13    /**
14     * @return string Syntax mode type
15     */
16    public function getType() {
17        return 'container';
18    }
19    /**
20     * @return string Paragraph type
21     */
22    public function getPType() {
23        return 'normal';
24    }
25    /**
26     * @return int Sort order - Low numbers go before high numbers
27     */
28    public function getSort() {
29        return 99;
30    }
31
32    /**
33     * Connect lookup pattern to lexer.
34     *
35     * @param string $mode Parser mode
36     */
37    public function connectTo($mode) {
38        $this->Lexer->addSpecialPattern('~~INDEXEVERYWHERE~~',$mode,'plugin_indexeverywhere_showTheTree');
39    }
40
41    /**
42     * Handle matches of the indexeverywhere syntax
43     *
44     * @param string $match The match of the syntax
45     * @param int    $state The state of the handler
46     * @param int    $pos The position in the document
47     * @param Doku_Handler    $handler The handler
48     * @return array Data for the renderer
49     */
50    public function handle($match, $state, $pos, Doku_Handler &$handler){
51        $data = array();
52        return $data;
53    }
54
55    /**
56     * Render xhtml output or metadata
57     *
58     * @param string         $mode      Renderer mode (supported modes: xhtml)
59     * @param Doku_Renderer  $renderer  The renderer
60     * @param array          $data      The data from the handler() function
61     * @return bool If rendering was successful.
62     */
63    public function render($mode, Doku_Renderer &$renderer, $data) {
64        if($mode != 'xhtml') return false;
65        global $conf;
66        global $ID;
67        $ns = dirname(str_replace(':','/',$ID));
68        if($ns == '.') $ns ='';
69        $ns  = utf8_encodeFN(str_replace(':','/',$ns));
70
71        $index = '<div id="index__tree" class="indexeverywhere">';
72        $data = array();
73        $index .= search($data,$conf['datadir'],'search_index',array('ns' => $ns));
74        $index .= html_buildlist($data,'idx','html_list_index','html_li_index');
75
76        $index .= '</div>';
77        $renderer->doc .=  $index;
78
79        return true;
80    }
81}
82
83// vim:ts=4:sw=4:et:
84