1<?php
2
3/**
4 * DokuWiki Plugin linklist (Renderer Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author Andreas Gohr <dokuwiki@cosmocode.de>
8 */
9class renderer_plugin_linklist extends Doku_Renderer
10{
11    protected $data = [];
12
13
14    /** @inheritDoc */
15    public function getFormat()
16    {
17        return 'linklist';
18    }
19
20    public function document_start()
21    {
22        $this->data = [
23            'internal' => [],
24            'external' => [],
25            'interwiki' => [],
26        ];
27    }
28
29    public function document_end()
30    {
31        $this->doc = json_encode($this->data);
32    }
33
34
35    public function reset()
36    {
37        $this->document_start();
38    }
39
40    public function internallink($link, $title = null)
41    {
42        $title = helper_plugin_linklist::getTitle($link);
43
44        if (isset($this->data['internal'][$link])) {
45            return; // already added
46        }
47        $this->data['internal'][$link] = [$link, $title];
48    }
49
50    public function externallink($link, $title = null)
51    {
52        if (is_array($title)) $title = null;
53        if (!$title) {
54            $title = helper_plugin_linklist::getUrlTitle($link);
55        }
56
57        if (isset($this->data['external'][$link])) {
58            return; // already added
59        }
60        $this->data['external'][$link] = [$link, $title];
61    }
62
63    public function interwikilink($link, $title, $wikiName, $wikiUri)
64    {
65        if (is_array($title)) $title = null;
66        if (!$title) {
67            $title = $wikiUri;
68        }
69
70        if (isset($this->data['interwiki'][$link])) {
71            return; // already added
72        }
73        $this->data['interwiki'][$link] = [$link, $title, $wikiName, $wikiUri];
74    }
75}
76