Failed Conditions
Pull Request — master (#3198)
by
unknown
02:54
created

Index::html_list_index()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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