1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * DokuWiki Plugin acknowledge (Syntax Component)
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 * @author  Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de>
10 */
11class syntax_plugin_acknowledge_assign extends SyntaxPlugin
12{
13    /** @inheritDoc */
14    public function getType()
15    {
16        return 'substition';
17    }
18
19    /** @inheritDoc */
20    public function getPType()
21    {
22        return 'block';
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('~~ACK:.*?~~', $mode, 'plugin_acknowledge_assign');
35    }
36
37
38    /** @inheritDoc */
39    public function handle($match, $state, $pos, Doku_Handler $handler)
40    {
41        $match = substr($match, 6, -2);
42        return ['assignees' => $match];
43    }
44
45    /** @inheritDoc */
46    public function render($mode, Doku_Renderer $renderer, $data)
47    {
48        global $ID;
49
50        if ($mode === 'metadata') {
51            /** @var helper_plugin_acknowledge $helper */
52            $helper = plugin_load('helper', 'acknowledge');
53            $helper->setPageAssignees($ID, $data['assignees']);
54            return true;
55        }
56
57        if ($mode !== 'xhtml') {
58            return false;
59        }
60
61        // a canvas to render the output to
62        $renderer->doc .= '<div class="plugin-acknowledge-banner">…</div>';
63        return true;
64    }
65}
66