1<?php
2/**
3 * DokuWiki plugin PageTitle YouAreHere; Syntax component
4 * Hierarchical breadcrumbs
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Satoshi Sahara <sahara.satoshi@gmail.com>
8 */
9class syntax_plugin_pagetitle_youarehere extends DokuWiki_Syntax_Plugin
10{
11    /** syntax type */
12    public function getType()
13    {
14        return 'substition';
15    }
16
17    /** paragraph type */
18    public function getPType()
19    {
20        return 'block';
21    }
22
23    /**
24     * Connect pattern to lexer
25     */
26    protected $mode, $pattern;
27
28    /** sort number used to determine priority of this mode */
29    public function getSort()
30    {
31        return 990;
32    }
33
34    public function preConnect()
35    {
36        // syntax mode, drop 'syntax_' from class name
37        $this->mode = substr(__CLASS__, 7);
38
39        //syntax patterns
40        $this->pattern[5] = '<!-- ?YOU_ARE_HERE ?-->';
41    }
42
43    public function connectTo($mode)
44    {
45        $this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
46    }
47
48    /**
49     * Handle the match
50     */
51    public function handle($match, $state, $pos, Doku_Handler $handler)
52    {
53        global $ID;
54        return $data = [$state, $match, $ID];
55    }
56
57    /**
58     * Create output
59     */
60    public function render($format, Doku_Renderer $renderer, $data)
61    {
62        global $ID;
63        static $helper;
64
65        list($state, $match, $id) = $data;
66
67        // skip calls that belong to different pages (eg. title of included page)
68        if ($id !== $ID) return false;
69
70        if ($format == 'metadata') {
71            $renderer->meta['plugin']['pagetitle']['youarehere'] =+ 1;
72
73        } elseif ($format == 'xhtml') {
74            // load helper object
75            isset($helper) || $helper = $this->loadHelper($this->getPluginName());
76
77            $renderer->doc .= DOKU_LF.$match.DOKU_LF; // html comment
78            $renderer->doc .= '<div class="youarehere">';
79            $renderer->doc .= $helper->html_youarehere(1); // start_depth = 1
80            $renderer->doc .= '</div>'.DOKU_LF;
81        }
82        return true;
83    }
84
85}
86