forked from LaswitchTech/writr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebar_tree.php
More file actions
82 lines (68 loc) · 2.44 KB
/
Copy pathsidebar_tree.php
File metadata and controls
82 lines (68 loc) · 2.44 KB
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
<?php
/**
* Sidebar Tree Navigation for Writr template
* Adapted from desert3 template's sidebar.php
*
* Displays a namespace tree synchronized with the current page.
*/
if (!defined('DOKU_INC')) die();
require_once(DOKU_INC . 'inc/search.php');
/**
* Render the namespace tree as nested <ul>
*/
function tpl_nstree() {
global $ID, $conf;
$ns = getNS($ID);
$ns = utf8_encodeFN(str_replace(':', '/', $ns));
$data = array();
search($data, $conf['datadir'], 'search_index', array('ns' => $ns));
if (empty($data)) return;
$currentLevel = 1;
echo '<ul class="nstree">' . "\n";
for ($i = 0; $i < count($data); $i++) {
$item = $data[$i];
// ACL check
if ($item['type'] === 'd') {
$perm = auth_quickaclcheck($item['id'] . ':*');
} else {
$perm = auth_quickaclcheck($item['id']);
}
if ($perm < AUTH_READ) continue;
// Link name
$linkName = noNS($item['id']);
if ($conf['useheading'] && $item['type'] === 'f') {
$heading = p_get_first_heading($item['id']);
if ($heading) $linkName = $heading;
}
$linkName = str_replace('_', ' ', $linkName);
// Close deeper levels
if ($currentLevel > $item['level']) {
echo str_repeat("</ul></li>\n", $currentLevel - $item['level']);
$currentLevel = $item['level'];
}
// Render item
if ($item['type'] === 'd') {
$class = $item['open'] ? 'nstree__dir nstree__dir--open' : 'nstree__dir';
echo '<li class="' . $class . '">';
$url = wl($item['id'] . ':' . $conf['start']);
echo '<a href="' . $url . '">' . hsc($linkName) . '</a>';
} else {
$isCurrent = ($item['id'] === $ID);
$class = 'nstree__file' . ($isCurrent ? ' nstree__file--active' : '');
echo '<li class="' . $class . '">';
echo '<a href="' . wl($item['id']) . '">' . hsc($linkName) . '</a>';
}
// Handle nesting
$nextLevel = isset($data[$i + 1]) ? $data[$i + 1]['level'] : 1;
if ($nextLevel > $currentLevel) {
echo '<ul>' . "\n";
} elseif ($nextLevel < $currentLevel) {
echo '</li>' . "\n";
echo str_repeat("</ul></li>\n", $currentLevel - $nextLevel);
} else {
echo '</li>' . "\n";
}
$currentLevel = $nextLevel;
}
echo '</ul>' . "\n";
}