1<?php
2/**
3 * Bootstrap Wrapper Plugin: Carousel
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_carousel extends syntax_plugin_bootswrapper_bootstrap
11{
12
13    public $p_type         = 'block';
14    public $pattern_start  = '<carousel.*?>(?=.*?</carousel>)';
15    public $pattern_end    = '</carousel>';
16    public $tag_name       = 'carousel';
17    public $tag_attributes = array(
18
19        'interval' => array(
20            'type'     => 'integer',
21            'values'   => null,
22            'required' => false,
23            'default'  => 5000),
24
25        'pause'    => array(
26            'type'     => 'string',
27            'values'   => null,
28            'required' => false,
29            'default'  => 'hover'),
30
31        'wrap'     => array(
32            'type'     => 'boolean',
33            'values'   => null,
34            'required' => false,
35            'default'  => true),
36
37        'keyboard' => array(
38            'type'     => 'boolean',
39            'values'   => null,
40            'required' => false,
41            'default'  => true),
42
43    );
44
45    public function render($mode, Doku_Renderer $renderer, $data)
46    {
47
48        if (empty($data)) {
49            return false;
50        }
51
52        if ($mode !== 'xhtml') {
53            return false;
54        }
55
56        /** @var Doku_Renderer_xhtml $renderer */
57        list($state, $match, $pos, $attributes) = $data;
58
59        if ($state == DOKU_LEXER_ENTER) {
60            $html5_attributes = array();
61
62            foreach ($attributes as $attribute => $value) {
63                $html5_attributes[] = 'data-' . $attribute . '="' . $value . '"';
64            }
65
66            $markup = '<div class="bs-wrap bs-wrap-carousel carousel slide" data-ride="carousel" ' . implode(' ', $html5_attributes) . '><ol class="carousel-indicators"></ol><div class="carousel-inner" role="listbox">';
67
68            $renderer->doc .= $markup;
69            return true;
70        }
71
72        if ($state == DOKU_LEXER_EXIT) {
73            $renderer->doc .= '</div>
74  <a class="left carousel-control" href="#" role="button" data-slide="prev">
75    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
76    <span class="sr-only">Previous</span>
77  </a>
78  <a class="right carousel-control" href="#" role="button" data-slide="next">
79    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
80    <span class="sr-only">Next</span>
81  </a></div>';
82            return true;
83        }
84
85        return true;
86    }
87}
88