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

Index::show()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 23
rs 9.552
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
        global $conf;
38
        global $ID;
39
40
        $ns  = cleanID($this->ns);
41
        if (empty($ns)){
42
            $ns = getNS($ID);
43
            if ($ns === false) $ns = '';
44
        }
45
        $ns  = utf8_encodeFN(str_replace(':', '/', $ns));
46
47
        // print intro
48
        print p_locale_xhtml('index');
49
50
        print '<div id="index__tree" class="index__tree">';
51
52
        $data = array();
53
        search($data, $conf['datadir'], 'search_index', array('ns' => $ns));
54
        print $this->buildIndexList($data);
55
56
        print '</div>'.DOKU_LF;
57
    }
58
59
    /**
60
     * Build html of unordered list of index items
61
     *
62
     * @param array $item
0 ignored issues
show
Bug introduced by
There is no parameter named $item. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
     * @return string
64
     */
65
    public function buildIndexList($data)
66
    {
67
        return html_buildlist($data, 'idx', [$this,'formatListItem'], [$this,'tagListItem']);
68
    }
69
70
    /**
71
     * Index item formatter
72
     *
73
     * User function for html_buildlist()
74
     *
75
     * @author Andreas Gohr <[email protected]>
76
     *
77
     * @param array $item
78
     * @return string
79
     */
80
    public function formatListItem($item)    // RENAMED from html_list_index()
81
    {
82
        global $ID, $conf;
83
84
        // prevent searchbots needlessly following links
85
        $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';
86
87
        $html = '';
88
        $base = ':'.$item['id'];
89
        $base = substr($base, strrpos($base,':') +1);
90
        if ($item['type'] == 'd') {
91
            // FS#2766, no need for search bots to follow namespace links in the index
92
            $link = wl($ID, 'idx='. rawurlencode($item['id']));
93
            $html .= '<a href="'. $link .'" title="'. $item['id'] .'" class="idx_dir"' . $nofollow .'><strong>';
94
            $html .= $base;
95
            $html .= '</strong></a>';
96
        } else {
97
            // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
98
            $html .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
99
        }
100
        return $html;
101
    }
102
103
    /**
104
     * Index List item
105
     *
106
     * This user function is used in html_buildlist to build the
107
     * <li> tags for namespaces when displaying the page index
108
     * it gives different classes to opened or closed "folders"
109
     *
110
     * @author Andreas Gohr <[email protected]>
111
     *
112
     * @param array $item
113
     * @return string html
114
     */
115
    public function tagListItem($item)    // RENAMED from html_li_index()
116
    {
117
        global $INFO;
118
        global $ACT;
119
120
        $class = '';
121
        $id = '';
122
123
        if ($item['type'] == 'f') {
124
            // scroll to the current item
125
            if (isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
126
                $id = ' id="scroll__here"';
127
                $class = ' bounce';
128
            }
129
            return '<li class="level'.$item['level'].$class.'" '.$id.'>';
130
        } elseif ($item['open']) {
131
            return '<li class="open">';
132
        } else {
133
            return '<li class="closed">';
134
        }
135
    }
136
137
}
138