1<?php
2
3use dokuwiki\Extension\SyntaxPlugin;
4
5/**
6 * DokuWiki Plugin vshare (Syntax Component)
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 * @author  Andreas Gohr <andi@splitbrain.org>
10 */
11class syntax_plugin_vshare_debug extends SyntaxPlugin
12{
13    /** @inheritDoc */
14    public function getType()
15    {
16        return 'substition';
17    }
18
19    /** @inheritDoc */
20    public function getPType()
21    {
22        return 'block';
23    }
24
25    /** @inheritDoc */
26    public function getSort()
27    {
28        return 155;
29    }
30
31    /** @inheritDoc */
32    public function connectTo($mode)
33    {
34        if ($this->getConf('debug')) {
35            $this->Lexer->addSpecialPattern('~~vshare-debug~~', $mode, 'plugin_vshare_debug');
36        }
37    }
38
39    /** @inheritDoc */
40    public function handle($match, $state, $pos, Doku_Handler $handler)
41    {
42        return [];
43    }
44
45    /** @inheritDoc */
46    public function render($mode, Doku_Renderer $renderer, $handlerdata)
47    {
48        if ($mode !== 'xhtml') {
49            return false;
50        }
51
52        $sites = helper_plugin_vshare::loadSites();
53        $syntax = new syntax_plugin_vshare_video();
54        $handler = new \Doku_Handler();
55
56
57        $renderer->header('vshare sites', 1, 0);
58
59        foreach ($sites as $site => $info) {
60            $renderer->header($site, 2, 0);
61
62            if (!empty($info['vid'])) {
63                $data = $syntax->handle("{{ $site>{$info['vid']} }}", DOKU_LEXER_MATCHED, 0, $handler);
64                $syntax->render($mode, $renderer, $data);
65            } else {
66                $renderer->p_open();
67                $renderer->smiley('FIXME');
68                $renderer->cdata(' No sample video ID available');
69                $renderer->p_close();
70            }
71
72            if (!empty($info['web'])) {
73                $renderer->p_open();
74                $renderer->externallink($info['web']);
75                $renderer->p_close();
76            } else {
77                $renderer->p_open();
78                $renderer->smiley('FIXME');
79                $renderer->cdata(' No sample video available');
80                $renderer->p_close();
81            }
82        }
83
84        return true;
85    }
86}
87