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
34            for ($i = 1; $i < count($attributes[1]); $i++) {
35                $value = $attributes[3][$i];
36                if (strlen($value) == 0) {
37                    $value = true;
38                }
39
40                $tagAttribs[$attributes[1][$i]] = $value;
41            }
42
43            if (strcasecmp($tagName, 'carousel') == 0) {
44                $core->syntaxRender($renderer, $tagName, '', $tagAttribs, MIKIO_LEXER_ENTER);
45            } else if (strcasecmp($tagName, 'carousel-item') == 0) {
46                $core->syntaxRender($renderer, $tagName, '', $tagAttribs, MIKIO_LEXER_SPECIAL);
47            }
48        }
49    }
50
51    $core->syntaxRender($renderer, 'carousel', '', $tagAttribs, MIKIO_LEXER_EXIT);
52
53    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">';
54    echo $renderer->doc;
55    echo '<script src="../../scripts/jquery/jquery.min.js"></script><script src="script.js"></script>';
56    echo '</body></html>';
57} else {
58    die('No page id was set in the url');
59}
60