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