1<?php
2/*
3 * Display Orphans Plugin
4 * Copyright (c) 2016 Jay Jeckel
5 * Licensed under the MIT license: https://opensource.org/licenses/MIT
6 * Permission is granted to use, copy, modify, and distribute the work.
7 * Full license information available in the project LICENSE file.
8*/
9
10if (!defined('DOKU_INC')) { die(); }
11
12require_once(DOKU_INC . 'inc' . '/' . 'search.php');
13require_once(dirname(__FILE__) . '/'. '_local.php');
14
15class renderer_plugin_displayorphans extends DokuWiki_Plugin
16{
17    function /* void */ table(Doku_Renderer $renderer, /* string */ $type, array $items = null, /* bool */ $showHeader = null, array $showColumns = array(true, true, true, true))
18    {
19        $renderer->table_open(null, null, null, array('plugin__displayorphans_' . $type));
20
21        if ($showHeader)
22        {
23            $this->_head($renderer, array(
24                $showColumns[0] ? $this->getLang('header_index') : null,
25                $showColumns[1] ? $this->getLang('header_id') : null,
26                $showColumns[2] ? $this->getLang('header_title') : null,
27                $showColumns[3] ? $this->getLang('header_backlinks') : null
28                ));
29        }
30
31        $renderer->tabletbody_open();
32
33        if (!empty($items))
34        {
35            foreach ($items as $id => $item)
36            { $this->_row($renderer, $id, $item, ++$rownum, $type, $showColumns); }
37        }
38
39        $renderer->tabletbody_close();
40        $renderer->table_close(null);
41    }
42
43    function /* void */ _head(Doku_Renderer $renderer, array $labels)
44    {
45        if (!empty($labels))
46        {
47            $renderer->tablethead_open();
48            $renderer->tablerow_open();
49            foreach ($labels as $label)
50            {
51                if ($label !== null)
52                {
53                    $renderer->tableheader_open();
54                    $renderer->doc .= $label;
55                    $renderer->tableheader_close();
56                }
57            }
58            $renderer->tablerow_close();
59            $renderer->tablethead_close();
60        }
61    }
62
63    function /* void */ _row(Doku_Renderer $renderer, $id, $item, $rownum, $type, array $showColumns = array(true, true, true, true))
64    {
65        $renderer->tablerow_open();
66
67        // Index of the row.
68        if ($showColumns[0])
69        {
70            $renderer->tablecell_open();
71            $renderer->doc .= $rownum;
72            $renderer->tablecell_close();
73        }
74
75        // Link to page.
76        if ($showColumns[1])
77        {
78            $renderer->tablecell_open();
79            $renderer->internallink(':' . $id, $id);
80            $renderer->tablecell_close();
81        }
82
83        // Title of the page.
84        if ($showColumns[2])
85        {
86            $renderer->tablecell_open();
87            if ($item['exists']) { $renderer->doc .= p_get_first_heading($id); }
88            $renderer->tablecell_close();
89        }
90
91        // Backlinks link for the page.
92        if ($showColumns[3])
93        {
94            $renderer->tablecell_open();
95            if ($item['count'] > 0) { $this->_backlinksLink($renderer, $id, $item['count']); }
96            $renderer->tablecell_close();
97        }
98
99        /*$renderer->tablecell_open();
100        if ($type == PageType::ORPHAN) { $renderer->doc .= p_get_first_heading($id); }
101        else if ($type == PageType::WANTED) { $this->_backlinksLink($renderer, $id, $item['count']); }
102        else { }
103        $renderer->tablecell_close();*/
104
105
106        $renderer->tablerow_close();
107    }
108
109    function /* void */ _backlinksLink(Doku_Renderer &$renderer, $id, $count)
110    {
111        global $conf;
112
113        $text = $this->getLang('text_show_backlinks');
114        $link = array('target' => $conf['target']['wiki'], 'class' => 'wikilink1', 'url' => wl($id, 'do=backlink'), 'name' => $text, 'title' => $text . ' - ' . $id);
115        if ($count !== null) { $renderer->doc .= $count . ' : '; }
116        $renderer->doc .= $count > 0 ? $renderer->_formatLink($link) : $text;
117    }
118}
119
120//Setup VIM: ex: et ts=4 enc=utf-8 :
121?>