1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * BBCode plugin: allows BBCode markup familiar from forum software
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Esther Brunner <esther@kaffeehaus.ch>
10 */
11class syntax_plugin_bbcode_image extends SyntaxPlugin
12{
13    /** @inheritdoc */
14    public function getType()
15    {
16        return 'substition';
17    }
18    /** @inheritdoc */
19    public function getSort()
20    {
21        return 105;
22    }
23    /** @inheritdoc */
24    public function connectTo($mode)
25    {
26        $this->Lexer->addSpecialPattern('\[img.+?\[/img\]', $mode, 'plugin_bbcode_image');
27    }
28
29    /** @inheritdoc */
30    public function handle($match, $state, $pos, Doku_Handler $handler)
31    {
32        $match = trim(substr($match, 5, -6));
33        [$url, $title] = sexplode(']', $match, 2, null);
34
35        // Check whether this is a local or remote image
36        if (preg_match('#^(https?|ftp)#i', $url)) {
37            $call = 'externalmedia';
38        } else {
39            $call = 'internalmedia';
40        }
41
42        $handler->addCall($call, [$url,$title,null,null,null,'cache'], $pos);
43        return true;
44    }
45
46    /** @inheritdoc */
47    public function render($format, Doku_Renderer $renderer, $data)
48    {
49        return true;
50    }
51}
52