1<?php
2if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../../');
3require_once(DOKU_INC . 'inc/init.php');
4
5$core = new syntax_plugin_mikioplugin_core();
6$renderer = new Doku_Renderer_xhtml();
7
8if (isset($_GET['id'])) {
9    $content = rawWiki($_GET['id']);
10    preg_match_all('/<carousel[^-item].*?>.*?<\/carousel>/s', $content, $matches);
11
12    $carousel_index = 0;
13    if (isset($_GET['carousel'])) {
14        $carousel_index = $_GET['carousel'];
15        if ($carousel_index > count($matches[0])) {
16            die('The page does not have ' . $carousel_index . ' carousels');
17        }
18
19        $carousel_index--;
20    } else {
21        if (count($matches[0]) <= 0) {
22            die('No carousels where found on the page');
23        }
24    }
25
26    preg_match_all('/<[^\/].*?>/s', $matches[0][$carousel_index], $tags);
27    foreach ($tags[0] as $tag) {
28        preg_match_all('/([^\r\n\t\f\v<>= \'"]+)(?:=(["\'])?((?:.(?!\2?\s+(?:\S+)=|\2))+[^>])\2?)?/', $tag, $attributes);
29
30        if (count($attributes) > 0) {
31            $tagName = $attributes[1][0];
32            $tagAttribs = array();
33            $count = count($attributes[1]);
34
35            for ($i = 1; $i < $count; $i++) {
36                $value = $attributes[3][$i];
37                if (strlen($value) == 0) {
38                    $value = true;
39                }
40
41                $tagAttribs[$attributes[1][$i]] = $value;
42            }
43
44            if (strcasecmp($tagName, 'carousel') == 0) {
45                $core->syntaxRender($renderer, $tagName, '', $tagAttribs, MIKIO_LEXER_ENTER);
46            } else if (strcasecmp($tagName, 'carousel-item') == 0) {
47                $core->syntaxRender($renderer, $tagName, '', $tagAttribs, MIKIO_LEXER_SPECIAL);
48            }
49        }
50    }
51
52    $core->syntaxRender($renderer, 'carousel', '', $tagAttribs, MIKIO_LEXER_EXIT);
53
54    echo '<html lang=en><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link type="text/css" rel="stylesheet" href="assets/external.css"/><link type="text/css" rel="stylesheet" href="css.php?css=/assets/variables.less,/assets/styles.less"/></head><body id="dokuwiki__content">';
55    echo $renderer->doc;
56    echo '<script src="../../scripts/jquery/jquery.min.js"></script><script src="script.js"></script>';
57    echo '</body></html>';
58} else {
59    die('No page id was set in the url');
60}
61