-
Notifications
You must be signed in to change notification settings - Fork 6
/
sidebar.php
179 lines (148 loc) · 6.43 KB
/
sidebar.php
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* Table of content-function that will
* create a hierarchical TOC for the site (by namespace)
* and highlight the current page
* The startpage if it exists, will always
* be shown first in the menu
*/
function tpl_processStartPage($ns,$context) {
// Check if a start page exists and add it first
global $conf;
$pageExists = false;
$startPageName = $conf['start'];
if ($ns == "") {
$startPageID = $startPageName;
} else {
$startPageID = $ns . ":" . $startPageName;
}
$startPagePath = $startPageID;
resolve_pageid($ns, $startPagePath,$pageExists);
if ($pageExists) {
// Check if page is visible
$perm = auth_quickaclcheck($startPageID);
if ($perm > 0) {
// Determine Page Title from first heading
$firstHeading = p_get_first_heading($startPageID);
if ($conf['useheading'] && !empty($firstHeading)) {
$linkName = $firstHeading;
} else {
$linkName = $startPageName;
}
// echo "<b>" . $conf['useheading'] ."</b>";
tpl_pageLinkCreate($startPageID, '<i class="icon-home"></i>'.$linkName, "tpl_processStartPage:$context");
}
}
}
function tpl_pageLinkCreate($fileToLinkID, $linkName, $calledFrom) {
global $ID;
echo "<li";
if ($fileToLinkID == $ID) {
// highlight current page
echo ' class="active"';
}
echo ">";
if ($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl") {
$path = wl($fileToLinkID, "do=admin&page=acl");
} else {
$path = wl($fileToLinkID);
}
// echo "<em>$fileToLinkID, $linkName, $calledFrom</em>";
tpl_link($path,$linkName);
}
function tpl_list_folder($dataList, $findAndProcessStartpage) {
global $conf;
global $ID;
global $INFO;
require_once(DOKU_INC.'inc/auth.php');
$currentLevel = 1;
$pathinfo = pathinfo($_SERVER['REQUEST_URI']);
$url = $pathinfo['dirname'];
echo "<div class='well well-nav'><ul class=\"nav nav-list\">\n";
tpl_processStartPage("","tof");
for($i=0; $i<count($dataList); $i++) {
// Check if page is visible
if ($dataList[$i]["type"] == "d") {
$perm = auth_quickaclcheck($dataList[$i]["id"].":*");
} else {
$perm = auth_quickaclcheck($dataList[$i]["id"]);
}
// process only visible pages
if ($perm > 0) {
// don't show start page in normal order
if (noNS($dataList[$i]["id"]) != $conf['start']) {
// FIXME not sure if this is actually needed
// Could we not use noNS($dataList[$i]["id"]) instead???
$pageFileName = split(":", $dataList[$i]["id"]);
$pageFileName = $pageFileName[count($pageFileName) - 1];
$pageFileName = str_replace("_", " ", $pageFileName);
// Determine Page Title from first heading
$firstHeading = p_get_first_heading($dataList[$i]["id"]);
if ($conf['useheading'] && $dataList[$i]["type"] == "f" && !empty($firstHeading)) {
$linkName = $firstHeading;
} else {
$linkName = $pageFileName;
}
// Adjust the level. If level of page is higher than current level
// close list-item and list
// FIXME: Why is this needed when the same happens down below?
if ($currentLevel > $dataList[$i]["level"]) {
echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i]["level"]);
$currentLevel = $dataList[$i]["level"];
}
// if entry is a folder
if ($dataList[$i]["type"] == "d") {
if ($dataList[$i]["open"]) {
$folder_status = 'open';
} else {
$folder_status = 'close';
}
echo '<li class="folder-status-' . $folder_status . '">';
if ($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl") {
$path = wl($dataList[$i]["id"].":".$conf['start'], "do=admin&page=acl");
} else {
$path = wl($dataList[$i]["id"].":".$conf['start']);
}
// echo "<p>Path: $path, LinkName: $linkName</p>";
tpl_link($path, '<i class="icon-folder-' . $folder_status . '"></i>' . $linkName);
} else {
// entry is a file
// echo "<p>Path: $path, LinkName: $linkName, id: ". $dataList[$i]["id"] . "</p>";
tpl_pageLinkCreate ($dataList[$i]["id"], '<i class="icon-file"></i>' . $linkName, "direkt:tpl_list_folder");
}
if ($dataList[$i+1]["level"] == $currentLevel) {
// current folder (just close list-item)
echo "</li>\n";
} else if ($dataList[$i+1]["level"] > $currentLevel) {
// new sub-folder (start new sub-list)
echo '<ul class="nav nav-list">';
// Check if a start page exists and add it first
tpl_processStartPage($dataList[$i]["id"],"");
} else if ($dataList[$i+1]["level"] < $currentLevel) {
// end of sub-folder (close open sublists)
if (!empty($dataList[$i+1]["level"])) {
echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i+1]["level"]);
}
}
$currentLevel = $dataList[$i+1]["level"];
}
}
}
echo "</ul></div>\n";
}
global $ID;
global $ACT;
global $conf;
$folder = getNS($ID);
require_once(DOKU_INC.'inc/search.php');
require_once(DOKU_INC.'inc/html.php');
$ns = cleanID($ID);
if (empty($ns)) {
$ns = dirname(str_replace(':','/',$ID));
if ($ns == '.') $ns ='';
}
$ns = utf8_encodeFN(str_replace(':','/',$ns));
$list = array();
search($list,$conf['datadir'],'search_index',array('ns' => $ns));
tpl_list_folder($list,true);
?>