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