1<?php
2/**
3 * Bootstrap Wrapper Plugin: Image
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
7 * @copyright  (C) 2015-2020, Giuseppe Di Terlizzi
8 */
9
10class syntax_plugin_bootswrapper_image extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $p_type         = 'block';
14    public $pattern_start  = '<image.*?>(?=.*?</image>)';
15    public $pattern_end    = '</image>';
16    public $tag_name       = 'image';
17    public $tag_attributes = array(
18        'shape' => array(
19            'type'     => 'string',
20            'values'   => array('rounded', 'circle', 'thumbnail', 'responsive'),
21            'required' => false,
22            'default'  => ''),
23    );
24
25    public function render($mode, Doku_Renderer $renderer, $data)
26    {
27
28        if (empty($data)) {
29            return false;
30        }
31
32        if ($mode !== 'xhtml') {
33            return false;
34        }
35
36        /** @var Doku_Renderer_xhtml $renderer */
37        list($state, $match, $pos, $attributes) = $data;
38
39        if ($state == DOKU_LEXER_ENTER) {
40            extract($attributes);
41
42            $html5_data = array();
43
44            if ($shape) {
45                $html5_data[] = 'data-img-shape="' . $shape . '"';
46            }
47
48            $markup = '<span class="bs-wrap bs-wrap-image" ' . implode(' ', $html5_data) . '>';
49
50            $renderer->doc .= $markup;
51            return true;
52        }
53
54        if ($state == DOKU_LEXER_EXIT) {
55            $renderer->doc .= '</span>';
56            return true;
57        }
58
59        return true;
60    }
61}
62