1<?php
2
3namespace dokuwiki\plugin\prosemirror\parser;
4
5class RSSNode extends Node
6{
7    protected $parent;
8    protected $data;
9
10    public function __construct($data, Node $parent)
11    {
12        $this->parent = &$parent;
13        $this->data = $data;
14    }
15
16    public function toSyntax()
17    {
18        $attrs = $this->data['attrs'];
19        return self::attrToSyntax($attrs);
20    }
21
22    protected static function attrToSyntax($attrs)
23    {
24        $prefix = '{{rss>';
25        $url = '';
26        if (!empty($attrs['url'])) {
27            $url = $attrs['url'];
28        }
29        $paramString = '';
30
31        if (!empty($attrs['max']) && $attrs['max'] !== 8) {
32            $paramString .= ' ' . $attrs['max'];
33        }
34
35        if (!empty($attrs['reverse'])) {
36            $paramString .= ' reverse';
37        }
38
39        if (!empty($attrs['author'])) {
40            $paramString .= ' author';
41        }
42
43        if (!empty($attrs['date'])) {
44            $paramString .= ' date';
45        }
46
47        if (!empty($attrs['details'])) {
48            $paramString .= ' description';
49        }
50
51        if (!empty($attrs['refresh']) && $attrs['refresh'] !== '4h') {
52            $paramString .= ' ' . $attrs['refresh'];
53        }
54        $postfix = '}}';
55        return $prefix . $url . $paramString . $postfix;
56    }
57
58    public static function renderAttrsToHTML($attrs)
59    {
60        $syntax = self::attrToSyntax($attrs);
61        $ins = p_get_instructions($syntax);
62        return p_render('xhtml', $ins, $info);
63    }
64}
65