1<?php
2/**
3 * Table of content-function that will
4 * create a hierarchical TOC for the site (by namespace)
5 * and highlight the current page
6 * The startpage if it exists, will always
7 * be shown first in the menu
8 */
9
10function tpl_processStartPage($ns,$context) {
11    // Check if a start page exists and add it first
12    global $conf;
13    $pageExists = false;
14    $startPageName = $conf['start'];
15    if ($ns == "") {
16        $startPageID = $startPageName;
17    } else {
18        $startPageID = $ns . ":" . $startPageName;
19    }
20
21    $startPagePath = $startPageID;
22
23    resolve_pageid($ns, $startPagePath,$pageExists);
24
25    if ($pageExists) {
26        // Check if page is visible
27
28        $perm = auth_quickaclcheck($startPageID);
29        if ($perm > 0) {
30
31            // Determine Page Title from first heading
32            $firstHeading = p_get_first_heading($startPageID);
33
34            if ($conf['useheading'] && !empty($firstHeading)) {
35                $linkName = $firstHeading;
36            } else {
37                $linkName = $startPageName;
38            }
39            // echo "<b>" . $conf['useheading'] ."</b>";
40            tpl_pageLinkCreate($startPageID, '<i class="icon-home"></i>'.$linkName, "tpl_processStartPage:$context");
41        }
42
43    }
44}
45function tpl_pageLinkCreate($fileToLinkID, $linkName, $calledFrom) {
46        global $ID;
47
48        echo "<li";
49        if ($fileToLinkID == $ID) {
50            // highlight current page
51            echo ' class="active"';
52        }
53        echo ">";
54        if ($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl") {
55            $path = wl($fileToLinkID, "do=admin&amp;page=acl");
56        } else {
57            $path = wl($fileToLinkID);
58        }
59        // echo "<em>$fileToLinkID, $linkName, $calledFrom</em>";
60        tpl_link($path,$linkName);
61}
62function tpl_list_folder($dataList, $findAndProcessStartpage) {
63    global $conf;
64    global $ID;
65    global $INFO;
66
67    require_once(DOKU_INC.'inc/auth.php');
68
69    $currentLevel = 1;
70
71    echo "<div class='well well-nav'><ul class=\"nav nav-list\">\n";
72
73    tpl_processStartPage("","tof");
74
75    for($i=0; $i<count($dataList); $i++) {
76
77        // Check if page is visible
78        if ($dataList[$i]["type"] == "d") {
79            $perm = auth_quickaclcheck($dataList[$i]["id"].":*");
80        } else {
81            $perm = auth_quickaclcheck($dataList[$i]["id"]);
82        }
83        // process only visible pages
84        if ($perm > 0) {
85
86            // don't show start page in normal order
87            if (noNS($dataList[$i]["id"]) != $conf['start']) {
88
89                 // FIXME not sure if this is actually needed
90                 // Could we not use noNS($dataList[$i]["id"]) instead???
91                 $pageFileName = split(":", $dataList[$i]["id"]);
92                 $pageFileName = $pageFileName[count($pageFileName) - 1];
93                 $pageFileName = str_replace("_", " ", $pageFileName);
94
95                    // Determine Page Title from first heading
96                    $firstHeading = p_get_first_heading($dataList[$i]["id"]);
97                    if ($conf['useheading'] && $dataList[$i]["type"] == "f" && !empty($firstHeading)) {
98                        $linkName = $firstHeading;
99                    } else {
100                        $linkName = $pageFileName;
101                    }
102
103                    // Adjust the level. If level of page is higher than current level
104                    // close list-item and list
105                    // FIXME: Why is this needed when the same happens down below?
106                    if ($currentLevel > $dataList[$i]["level"]) {
107                        echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i]["level"]);
108                        $currentLevel = $dataList[$i]["level"];
109                    }
110
111                    // if entry is a folder
112                    if ($dataList[$i]["type"] == "d") {
113
114                        if ($dataList[$i]["open"]) {
115                            $folder_status = 'open';
116                        } else {
117                            $folder_status = 'close';
118                        }
119                        echo '<li class="folder-status-' . $folder_status . '">';
120
121                        if ($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl") {
122                            $path = wl($dataList[$i]["id"].":".$conf['start'], "do=admin&amp;page=acl");
123                        } else {
124                            $path = wl($dataList[$i]["id"].":".$conf['start']);
125                        }
126                        // echo "<p>Path: $path, LinkName: $linkName</p>";
127                        tpl_link($path, '<i class="icon-folder-' . $folder_status . '"></i>' . $linkName);
128                    } else {
129                        // entry is a file
130                        // echo "<p>Path: $path, LinkName: $linkName, id: ". $dataList[$i]["id"] . "</p>";
131                        tpl_pageLinkCreate ($dataList[$i]["id"], '<i class="icon-file"></i>' . $linkName, "direkt:tpl_list_folder");
132                    }
133
134                    if ($dataList[$i+1]["level"] == $currentLevel) {
135                        // current folder (just close list-item)
136                        echo "</li>\n";
137                    } else if ($dataList[$i+1]["level"] > $currentLevel) {
138                        // new sub-folder (start new sub-list)
139                        echo '<ul class="nav nav-list">';
140                        // Check if a start page exists and add it first
141
142                        tpl_processStartPage($dataList[$i]["id"],"");
143                    } else if ($dataList[$i+1]["level"] < $currentLevel) {
144                        // end of sub-folder (close open sublists)
145                        if (!empty($dataList[$i+1]["level"])) {
146                            echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i+1]["level"]);
147                        }
148                    }
149                    $currentLevel = $dataList[$i+1]["level"];
150            }
151        }
152    }
153    echo "</ul></div>\n";
154}
155    global $ID;
156    global $ACT;
157    global $conf;
158
159
160    $folder = getNS($ID);
161
162    require_once(DOKU_INC.'inc/search.php');
163    require_once(DOKU_INC.'inc/html.php');
164
165    $ns = cleanID($ID);
166    if (empty($ns)) {
167        $ns = dirname(str_replace(':','/',$ID));
168        if ($ns == '.') $ns ='';
169    }
170    $ns = utf8_encodeFN(str_replace(':','/',$ns));
171
172    $list = array();
173    search($list,$conf['datadir'],'search_index',array('ns' => $ns));
174
175    tpl_list_folder($list,true);
176?>
177