xref: /dokuwiki/inc/Ui/Index.php (revision f9ee77d64c08a142995bc3ff066bc126947b4402)
1<?php
2
3namespace dokuwiki\Ui;
4
5use dokuwiki\Extension\Event;
6use dokuwiki\Form\Form;
7
8/**
9 * DokuWiki Index Insterface
10 *
11 * @package dokuwiki\Ui
12 */
13class Index extends Ui
14{
15    /**
16     * Display page index
17     *
18     * @author   Andreas Gohr <andi@splitbrain.org>
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,'formatListItem'], [$this,'taglListItem']);
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 <andi@splitbrain.org>
53     *
54     * @param array $item
55     * @return string
56     */
57    public function formatListItem($item)    // RENAMED from html_list_index()
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 <andi@splitbrain.org>
88     *
89     * @param array $item
90     * @return string html
91     */
92    public function taglListItem($item)    // RENAMED from html_li_index()
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