1<?php
2
3
4/**
5 * Afficher un dossier
6 * @param $dataList Le contenu du dossier en array
7 */
8function tpl_list_folder($dataList){
9	global $conf;
10	global $ID;
11	global $INFO;
12
13	require_once(DOKU_INC.'inc/auth.php');
14
15	$currentLevel = 1;
16
17	$pathinfo = pathinfo($_SERVER['REQUEST_URI']);
18	$url = $pathinfo['dirname'];
19
20	echo "<ul class=\"explorer\">\n";
21	for($i=0; $i<count($dataList); $i++){
22
23		// Permission
24		if($dataList[$i]["type"] == "d"){
25			$perm = auth_quickaclcheck($dataList[$i]["id"].":*");
26		}else{
27			$perm = auth_quickaclcheck($dataList[$i]["id"]);
28		}
29
30		if($perm > 0){
31
32			// Nom du lien
33			$firstHeading = p_get_first_heading($dataList[$i]["id"]);
34			if($conf['useheading'] && $dataList[$i]["type"] == "f" && !empty($firstHeading)){
35				$linkName = $firstHeading;
36			}else{
37				$linkName = split(":", $dataList[$i]["id"]);
38				$linkName = $linkName[count($linkName) - 1];
39				$linkName = str_replace("_", " ", $linkName);
40			}
41
42			// On vérifie qu'on est dans le bon level
43			if($currentLevel > $dataList[$i]["level"]){
44				echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i]["level"]);
45				$currentLevel = $dataList[$i]["level"];
46			}
47
48			// Affichage
49			if($dataList[$i]["type"] == "d"){
50				// dossier
51				if($dataList[$i]["open"]){
52					echo "<li class=\"folderopen\">";
53				}else{
54					echo "<li class=\"folder\">";
55				}
56
57				if($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl"){
58					$path = wl($dataList[$i]["id"].":".$conf['start'], "do=admin&amp;page=acl");
59				}else{
60					$path = wl($dataList[$i]["id"].":".$conf['start']);
61				}
62				tpl_link($path,$linkName);
63			}else{
64				// fichier
65				echo "<li class=\"file\">";
66				if($dataList[$i]["id"] == $ID){
67					// Page affichée
68					echo "<strong>";
69				}
70				if($_REQUEST["do"] == "admin" && $_REQUEST["page"] == "acl"){
71					$path = wl($dataList[$i]["id"], "do=admin&amp;page=acl");
72				}else{
73					$path = wl($dataList[$i]["id"]);
74				}
75				tpl_link($path,$linkName);
76
77				if($dataList[$i]["id"] == $ID){
78					// Page affichée
79					echo "</strong>";
80				}
81			}
82
83			if($dataList[$i+1]["level"] == $currentLevel){
84				// dossier courant
85				echo "</li>\n";
86			}else if($dataList[$i+1]["level"] > $currentLevel){
87				// Nouveau sous dossier
88				echo "<ul>\n";
89			}else if($dataList[$i+1]["level"] < $currentLevel){
90				// Fin du dossier
91				if(!empty($dataList[$i+1]["level"])){
92					echo str_repeat("</ul></li>\n", $currentLevel - $dataList[$i+1]["level"]);
93				}
94			}
95			$currentLevel = $dataList[$i+1]["level"];
96		}
97	}
98	echo "</ul>\n";
99}
100
101/**
102 * Afficher le plan du site
103 */
104function tpl_sitemap() {
105	global $ID;
106	global $ACT;
107	global $conf;
108
109
110	$folder = getNS($ID);
111
112	require_once(DOKU_INC.'inc/search.php');
113	require_once(DOKU_INC.'inc/html.php');
114
115	$ns  = cleanID($ID);
116	if(empty($ns)){
117		$ns = dirname(str_replace(':','/',$ID));
118		if($ns == '.') $ns ='';
119	}
120	$ns  = utf8_encodeFN(str_replace(':','/',$ns));
121
122	$list = array();
123	search($list,$conf['datadir'],'search_index',array('ns' => $ns));
124
125	tpl_list_folder($list);
126}
127
128/**
129 * Afficher le plan de la page
130 */
131function getToc(){
132	global $ID;
133	$except = array('admin', 'revisions', 'diff');
134	if(in_array($_REQUEST["do"], $except) || auth_quickaclcheck($ID) < 1) return false;
135
136	require_once(DOKU_INC.'inc/parserutils.php');
137
138	$content = p_wiki_xhtml($ID);
139	$pattern = '@<div id="toc__inside">.*?</div>\n</div>@s';
140
141	preg_match($pattern, $content, $matches);
142	return substr($matches[0], 22, -14);
143}
144?>
145