1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * DokuWiki Plugin dbquery (Syntax Component)
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 * @author  Andreas Gohr <dokuwiki@cosmocode.de>
10 */
11class syntax_plugin_dbquery_macro extends SyntaxPlugin
12{
13    /** @inheritDoc */
14    public function getType()
15    {
16        return 'substition';
17    }
18
19    /** @inheritDoc */
20    public function getPType()
21    {
22        return 'normal';
23    }
24
25    /** @inheritDoc */
26    public function getSort()
27    {
28        return 155;
29    }
30
31    /** @inheritDoc */
32    public function connectTo($mode)
33    {
34        $this->Lexer->addSpecialPattern('~~DBQUERY:.*?~~', $mode, 'plugin_dbquery_macro');
35    }
36
37    /** @inheritDoc */
38    public function handle($match, $state, $pos, Doku_Handler $handler)
39    {
40        $macro = strtolower(trim(substr($match, 10, -2)));
41        return [$macro];
42    }
43
44    /** @inheritDoc */
45    public function render($mode, Doku_Renderer $renderer, $data)
46    {
47        [$name, $value] = sexplode('=', $data[0], 2);
48        $name = trim($name);
49        $value = trim($value);
50        if (!$value) $value = true;
51
52        $renderer->info['dbquery'][$name] = $value;
53        return true;
54    }
55}
56