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