1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * Encrypted Passwords Plugin: Store encrypted passwords with syntax <decrypt></decrypt>
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 */
10class syntax_plugin_encryptedpasswords extends SyntaxPlugin
11{
12    /** @inheritDoc */
13    public function getType()
14    {
15        return 'substition';
16    }
17
18    /** @inheritDoc */
19    public function getSort()
20    {
21        return 65;
22    }
23
24    /** @inheritDoc */
25    public function connectTo($mode)
26    {
27        $this->Lexer->addSpecialPattern('<decrypt>(?:.*?<\/decrypt>)', $mode, 'plugin_encryptedpasswords');
28    }
29
30    /** @inheritDoc */
31    public function handle($match, $state, $pos, Doku_Handler $handler)
32    {
33        $crypt = substr($match, 9, -10); // remove tags
34        return [$crypt];
35    }
36
37    /** @inheritDoc */
38    public function render($mode, Doku_Renderer $renderer, $data)
39    {
40        if ($mode !== 'xhtml') {
41            return false;
42        }
43
44        $crypt = hsc($data[0]);
45        $renderer->doc .= '<span class="encryptedpasswords crypted" data-crypted="' . $crypt . '">';
46        $renderer->doc .= '<span>••••••••••</span>';
47        $renderer->doc .= inlineSVG(__DIR__ . '/lock.svg');
48        $renderer->doc .= inlineSVG(__DIR__ . '/lock-open.svg');
49        $renderer->doc .= '</span>';
50        return true;
51    }
52}
53