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