File: Index.php

package info (click to toggle)
dokuwiki 0.0.20220731.a-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,244 kB
  • sloc: php: 187,701; javascript: 5,931; sql: 1,204; sh: 672; xml: 384; perl: 216; makefile: 77
file content (131 lines) | stat: -rw-r--r-- 3,447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php

namespace dokuwiki\Ui;

/**
 * DokuWiki Index Interface
 *
 * @package dokuwiki\Ui
 */
class Index extends Ui
{
    protected $ns;

    /**
     * Index Ui constructor
     *
     * @param string $ns  namespace
    */
    public function __construct($ns = '')
    {
        $this->ns = $ns;
    }


    /**
     * Display page index
     *
     * @author   Andreas Gohr <andi@splitbrain.org>
     *
     * @return void
     */
    public function show()
    {
        // print intro
        print p_locale_xhtml('index');

        print $this->sitemap();
    }

    /**
     * Build html of sitemap, unordered list of pages under the namespace
     *
     * @return string
     */
    public function sitemap()
    {
        global $conf;
        global $ID;

        $ns = cleanID($this->ns);
        if (empty($ns)){
            $ns = getNS($ID);
            if ($ns === false) $ns = '';
        }
        $ns = utf8_encodeFN(str_replace(':', '/', $ns));
        $data = array();
        search($data, $conf['datadir'], 'search_index', array('ns' => $ns));

        return '<div id="index__tree" class="index__tree">'
              . html_buildlist($data, 'idx', [$this,'formatListItem'], [$this,'tagListItem'])
              . '</div>';
    }

    /**
     * Index item formatter
     *
     * User function for html_buildlist()
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     *
     * @param array $item
     * @return string
     */
    public function formatListItem($item)    // RENAMED from html_list_index()
    {
        global $ID, $conf;

        // prevent searchbots needlessly following links
        $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : '';

        $html = '';
        $base = ':'.$item['id'];
        $base = substr($base, strrpos($base,':') +1);
        if ($item['type'] == 'd') {
            // FS#2766, no need for search bots to follow namespace links in the index
            $link = wl($ID, 'idx='. rawurlencode($item['id']));
            $html .= '<a href="'. $link .'" title="'. $item['id'] .'" class="idx_dir"' . $nofollow .'><strong>';
            $html .= $base;
            $html .= '</strong></a>';
        } else {
            // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
            $html .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
        }
        return $html;
    }

    /**
     * Index List item
     *
     * This user function is used in html_buildlist to build the
     * <li> tags for namespaces when displaying the page index
     * it gives different classes to opened or closed "folders"
     *
     * @author Andreas Gohr <andi@splitbrain.org>
     *
     * @param array $item
     * @return string html
     */
    public function tagListItem($item)    // RENAMED from html_li_index()
    {
        global $INFO;
        global $ACT;

        $class = '';
        $id = '';

        if ($item['type'] == 'f') {
            // scroll to the current item
            if (isset($INFO) && $item['id'] == $INFO['id'] && $ACT == 'index') {
                $id = ' id="scroll__here"';
                $class = ' bounce';
            }
            return '<li class="level'.$item['level'].$class.'" '.$id.'>';
        } elseif ($item['open']) {
            return '<li class="open">';
        } else {
            return '<li class="closed">';
        }
    }

}