Failed Conditions
Push — master ( 96da53...0afbc1 )
by Andreas
06:02 queued 03:20
created

Index::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Ui;
4
5
use dokuwiki\Extension\Event;
6
use dokuwiki\Form\Form;
7
8
/**
9
 * DokuWiki Index Interface
10
 *
11
 * @package dokuwiki\Ui
12
 */
13
class Index extends Ui
14
{
15
    protected $ns;
16
17
    /** 
18
     * Index Ui constructor
19
     *
20
     * @param string $ns  namespace
21
    */
22
    public function __construct($ns = '')
23
    {
24
        $this->ns = $ns;
25
    }
26
27
28
    /**
29
     * Display page index
30
     *
31
     * @author   Andreas Gohr <[email protected]>
32
     *
33
     * @return void
34
     */
35
    public function show()
36
    {
37
        // print intro
38
        print p_locale_xhtml('index');
39
40
        print $this->sitemap();
41
    }
42
43
    /**
44
     * Build html of sitemap, unordered list of pages under the namespace
45
     *
46
     * @return string
47
     */
48
    public function sitemap()
49
    {
50
        global $conf;
51
        global $ID;
52
53
        $ns = cleanID($this->ns);
54
        if (empty($ns)){
55
            $ns = getNS($ID);
56
            if ($ns === false) $ns = '';
57
        }
58
        $ns = utf8_encodeFN(str_replace(':', '/', $ns));
59
        $data = array();
60
        search($data, $conf['datadir'], 'search_index', array('ns' => $ns));
61
62
        $html = '<div id="index__tree" class="index__tree">'
63
              . html_buildlist($data, 'idx', [$this,'formatListItem'], [$this,'tagListItem'])
64
              . '</div>';
65
        return $html;
66
    }
67
68
    /**
69
     * Index item formatter
70
     *
71
     * User function for html_buildlist()
72
     *
73
     * @author Andreas Gohr <[email protected]>
74
     *
75
     * @param array $item
76
     * @return string
77
     */
78
    public function formatListItem($item)    // RENAMED from html_list_index()
79
    {
80
        global $ID, $conf;
81
82
        // prevent searchbots needlessly following links
83
        $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
84
85
        $html = '';
86
        $base = ':'.$item['id'];
87
        $base = substr($base, strrpos($base,':') +1);
88
        if ($item['type'] == 'd') {
89
            // FS#2766, no need for search bots to follow namespace links in the index
90
            $link = wl($ID, 'idx='. rawurlencode($item['id']));
91
            $html .= '<a href="'. $link .'" title="'. $item['id'] .'" class="idx_dir"' . $nofollow .'><strong>';
92
            $html .= $base;
93
            $html .= '</strong></a>';
94
        } else {
95
            // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
96
            $html .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
97
        }
98
        return $html;
99
    }
100
101
    /**
102
     * Index List item
103
     *
104
     * This user function is used in html_buildlist to build the
105
     * <li> tags for namespaces when displaying the page index
106
     * it gives different classes to opened or closed "folders"
107
     *
108
     * @author Andreas Gohr <[email protected]>
109
     *
110
     * @param array $item
111
     * @return string html
112
     */
113
    public function tagListItem($item)    // RENAMED from html_li_index()
114
    {
115
        global $INFO;
116
        global $ACT;
117
118
        $class = '';
119
        $id = '';
120
121
        if ($item['type'] == 'f') {
122
            // scroll to the current item
123
            if (isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
124
                $id = ' id="scroll__here"';
125
                $class = ' bounce';
126
            }
127
            return '<li class="level'.$item['level'].$class.'" '.$id.'>';
128
        } elseif ($item['open']) {
129
            return '<li class="open">';
130
        } else {
131
            return '<li class="closed">';
132
        }
133
    }
134
135
}
136