1<?php
2/**
3 * BBCode plugin: allows BBCode markup familiar from forum software
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Esther Brunner <esther@kaffeehaus.ch>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_bbcode_image extends DokuWiki_Syntax_Plugin {
18
19    function getType() { return 'substition'; }
20    function getSort() { return 105; }
21    function connectTo($mode) { $this->Lexer->addSpecialPattern('\[img.+?\[/img\]',$mode,'plugin_bbcode_image'); }
22
23    /**
24     * Handle the match
25     */
26    function handle($match, $state, $pos, Doku_Handler $handler) {
27        $match = trim(substr($match, 5, -6));
28        $match = preg_split('/\]/u',$match,2);
29        if ( !isset($match[0]) ) {
30            $url   = $match[1];
31            $title = NULL;
32        } else {
33            $url   = $match[0];
34            $title = $match[1];
35        }
36
37        // Check whether this is a local or remote image
38        if ( preg_match('#^(https?|ftp)#i',$url) ) {
39            $call = 'externalmedia';
40        } else {
41            $call = 'internalmedia';
42        }
43
44        $handler->_addCall($call,array($url,$title,NULL,NULL,NULL,'cache'),$pos);
45        return true;
46    }
47
48    /**
49     * Create output
50     */
51    function render($mode, Doku_Renderer $renderer, $data) {
52        return true;
53    }
54}
55// vim:ts=4:sw=4:et:enc=utf-8:
56