1<?php
2
3/**
4 * Info Indexmenu tag: Tag a page with a sort number.
5 *
6 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author      Samuele Tognini <samuele@samuele.netsons.org>
8 *
9 */
10
11if(!defined('DOKU_INC')) die();
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_indexmenu_tag extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * What kind of syntax are we?
21     */
22    function getType() {
23        return 'substition';
24    }
25
26    /**
27     * Where to sort in?
28     */
29    function getSort() {
30        return 139;
31    }
32
33    /**
34     * Connect pattern to lexer
35     */
36    function connectTo($mode) {
37        $this->Lexer->addSpecialPattern('{{indexmenu_n>.+?}}', $mode, 'plugin_indexmenu_tag');
38    }
39
40    /**
41     * Handle the match
42     */
43    function handle($match, $state, $pos, Doku_Handler $handler) {
44        $match = substr($match, 14, -2);
45        $match = str_replace("\xE2\x80\x8B", "", $match);
46        return array($match);
47    }
48
49    /**
50     * Render output
51     */
52    function render($mode, Doku_Renderer $renderer, $data) {
53        if($mode == 'metadata') {
54            /** @var Doku_Renderer_metadata $renderer */
55            if(is_numeric($data[0])) $renderer->meta['indexmenu_n'] = $data[0];
56        }
57    }
58}