1<?php
2/**
3 * Bootstrap Wrapper Plugin: Jumbotron
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_jumbotron extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $pattern_start  = '<(?:JUMBOTRON|jumbotron).*?>(?=.*?</(?:JUMBOTRON|jumbotron)>)';
14    public $pattern_end    = '</(?:JUMBOTRON|jumbotron)>';
15    public $tag_name       = 'jumbotron';
16    public $tag_attributes = array(
17
18        'background' => array(
19            'type'     => 'string',
20            'values'   => null,
21            'required' => false,
22            'default'  => null),
23
24        'color'      => array(
25            'type'     => 'string',
26            'values'   => null,
27            'required' => false,
28            'default'  => null),
29
30    );
31
32    public function render($mode, Doku_Renderer $renderer, $data)
33    {
34
35        if (empty($data)) {
36            return false;
37        }
38
39        if ($mode !== 'xhtml') {
40            return false;
41        }
42
43        /** @var Doku_Renderer_xhtml $renderer */
44        list($state, $match, $pos, $attributes, $is_block) = $data;
45
46        if ($state == DOKU_LEXER_ENTER) {
47            $background = $attributes['background'];
48            $color      = $attributes['color'];
49
50            $styles = array();
51
52            if ($background) {
53                $styles[] = 'background-image:url(' . ml($background) . ')';
54            }
55
56            if ($color) {
57                $styles[] = 'color:' . hsc($color);
58            }
59
60            $markup = '<div class="bs-wrap bs-wrap-jumbotron jumbotron" style="' . implode(';', $styles) . '">';
61
62            $renderer->doc .= $markup;
63            return true;
64        }
65
66        if ($state == DOKU_LEXER_EXIT) {
67            $renderer->doc .= '</div>';
68            return true;
69        }
70
71        return true;
72    }
73}
74