-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpl_functions.php
executable file
·177 lines (162 loc) · 4.04 KB
/
tpl_functions.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
<?php
/**
* Template Functions
*
* This file provides template specific custom functions that are
* not provided by the DokuWiki core.
* It is common practice to start each function with an underscore
* to make sure it won't interfere with future core functions.
*
* @author Andreas Gohr <[email protected]>
* @author Anika Henke <[email protected]>
* @author Klaus Vormweg <[email protected]>
*
*/
// must be run from within DokuWiki
if (!defined('DOKU_INC')) die();
/**
* prints the menu
*
* @param void
* @return void
*/
function _tpl_mainmenu() {
require_once(DOKU_INC.'inc/search.php');
global $conf;
/* options for search() function */
$opts = array(
'depth' => 0,
'listfiles' => true,
'listdirs' => true,
'pagesonly' => true,
'firsthead' => true,
'sneakyacl' => true
);
if(isset($conf['start'])) {
$start = $conf['start'];
} else {
$start = 'start';
}
$data = array();
search($data,$conf['datadir'],'search_universal',$opts);
$i = 0;
$data2 = array();
foreach($data as $item) {
if(strpos($item['id'],'playground') !== false) {
continue;
}
if(isset($conf['sidebar'])) {
if($conf['sidebar']) {
if(strpos($item['id'], $conf['sidebar']) !== false) {
continue;
}
}
}
## unset()!!!
if($item['id'] == $start or preg_match('/:'.$start.'$/',$item['id'])
or preg_match('/(\w+):\1$/',$item['id'])) {
continue;
}
if(array_key_exists($item['id'], $data2)) {
$data2[$item['id']]['type'] = 'd';
$data2[$item['id']]['ns'] = $item['id'];
continue;
}
$data2[$item['id']] = $item;
$i++;
}
usort($data2,"_tpl_sort_index");
echo html_buildlist($data2,'idx','_tpl_list_index','_tpl_html_li_index');
}
/**
* Index item formatter
* Callback function for html_buildlist()
*
* @param array $item
* @return string html
*/
function _tpl_list_index($item) {
global $conf;
$ret = '';
if($item['type'] == 'd') {
if(@file_exists(wikiFN($item['id'].':'.$conf['start']))) {
$ret .= html_wikilink($item['id'].':'.$conf['start'], $item['title']);
} elseif(@file_exists(wikiFN($item['id'].':'.$item['id']))) {
$ret .= html_wikilink($item['id'].':'.$item['id'], $item['title']);
} else {
$ret .= html_wikilink($item['id'].':', $conf['start']);
}
} else {
$ret .= html_wikilink(':'.$item['id'], $item['title']);
}
return $ret;
}
/**
* Index List item
*
* Callback function for html_buildlist to build the
* <li> tags for namespaces when displaying the page index
*
* @param array $item
* @return string html
*/
function _tpl_html_li_index($item) {
global $INFO;
$class = '';
$id = '';
if($item['type'] == "f") {
return '<li class="level'.$item['level'].$class.'" '.$id.'>';
} else {
return '<li class="closed level'.$item['level'].$class.'">';
}
}
/**
* Returns <link> tag for various icon types (favicon|mobile)
*
* @param array $types - list of icon types to display (favicon|mobile)
* @return string
*/
function _tpl_favicon($types = array('favicon','mobile')) {
$return = '';
$typearr = array();
foreach($types as $type) {
switch($type) {
case 'favicon':
$typearr['shortcut icon'] = 'favicon.ico';
case 'mobile':
$typearr['apple-touch-icon'] = 'apple-touch-icon.png';
}
}
foreach($typearr as $type => $fname) {
$look = array(':wiki:'.$fname, ':'.$fname, 'images/'.$fname);
$i = 0;
while($look[$i] and strpos($look[$i],'images') === FALSE) {
if(!auth_quickaclcheck($look[$i])) {
unset($look[$i]);
}
$i++;
}
$return .= '<link rel="'.$type.'" href="'.tpl_getMediaFile($look).'" />'.NL;
}
return $return;
}
/**
* Checks if a media file is readable by the current user
*
* @param string $id
* @return bool
*/
function _tpl_media_isreadable($id) {
$id = cleanID($id);
if(auth_quickaclcheck($id)) {
return true;
} else {
return false;
}
}
/**
* Callback function for usort
*/
function _tpl_sort_index($a, $b) {
return strcmp($a['id'],$b['id']);
}