1<?php
2
3use FYKOS\dokuwiki\Extension\PluginNewsFeed\AbstractStream;
4
5/**
6 * Class syntax_plugin_newsfeed_stream
7 * @author Michal Červeňák <miso@fykos.cz>
8 */
9class syntax_plugin_newsfeed_stream extends AbstractStream {
10
11    public function connectTo($mode): void {
12        $this->Lexer->addSpecialPattern('{{news-stream>.+?}}', $mode, 'plugin_newsfeed_stream');
13    }
14
15    public function handle($match, $state, $pos, Doku_Handler $handler): array {
16        switch ($state) {
17            case DOKU_LEXER_SPECIAL:
18                preg_match_all('/([a-z]+)="([^".]*)"/', substr($match, 14, -2), $matches);
19                $parameters = [];
20                foreach ($matches[1] as $index => $match) {
21                    $parameters[$match] = $matches[2][$index];
22                }
23                return [$state, [$parameters]];
24        }
25        return [$state, null];
26
27    }
28
29    public function render($mode, Doku_Renderer $renderer, $data): bool {
30        if ($mode !== 'xhtml') {
31            return true;
32        }
33        [$state, $match] = $data;
34        switch ($state) {
35            case DOKU_LEXER_SPECIAL:
36                [$param] = $match;
37                $this->renderStream($renderer, $param);
38                return false;
39        }
40        return true;
41    }
42}
43