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