forked from wwu-housing/starterbootstrap
/
tpl_functions.php
375 lines (333 loc) · 11.4 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?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.
*/
// must be run from within DokuWiki
if (!defined('DOKU_INC')) die();
/**
* Print the search form
*
* If the first parameter is given a div with the ID 'qsearch_out' will
* be added which instructs the ajax pagequicksearch to kick in and place
* its output into this div. The second parameter controls the propritary
* attribute autocomplete. If set to false this attribute will be set with an
* value of "off" to instruct the browser to disable it's own built in
* autocompletion feature (MSIE and Firefox)
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param bool $ajax
* @param bool $autocomplete
* @return bool
*/
function _tpl_searchform($ajax = true, $autocomplete = true) {
global $lang;
global $ACT;
global $QUERY;
// don't print the search form if search action has been disabled
if(!actionOK('search')) return false;
print '<form action="'.wl().'" accept-charset="utf-8" class="navbar-form navbar-right" id="dw__search" method="get" role="search">';
print '<input type="hidden" name="do" value="search" />';
print '<div class="form-group">';
print '<input type="text" ';
if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
print ' autocomplete="off" ';
print 'id="qsearch__in" accesskey="f" name="id" class="form-control col-lg-3" title="[F]" placeholder="' . $lang['btn_search'] . '" /> ';
print '</div>';
if($ajax) print '<div id="qsearch__out" class="ajax_qsearch"></div>';
print '</form>';
return true;
}
/* table of contents */
function _tpl_toc($return = false) {
global $TOC;
global $ACT;
global $ID;
global $REV;
global $INFO;
global $conf;
global $INPUT;
$toc = array();
//if(is_array($TOC))
// NOTE:
// This will happen if sidebar has headings in it, so we don't want to use
// a TOC from the global scope. I suspect this could break some plugins.
if(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
// get TOC from metadata, render if neccessary
$meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
if(isset($meta['internal']['toc'])) {
$tocok = $meta['internal']['toc'];
} else {
$tocok = true;
}
$toc = $meta['description']['tableofcontents'];
if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
$toc = array();
}
} elseif($ACT == 'admin') {
// try to load admin plugin TOC FIXME: duplicates code from tpl_admin
$plugin = null;
$class = $INPUT->str('page');
if(!empty($class)) {
$pluginlist = plugin_list('admin');
if(in_array($class, $pluginlist)) {
// attempt to load the plugin
/** @var $plugin DokuWiki_Admin_Plugin */
$plugin =& plugin_load('admin', $class);
}
}
if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) {
$toc = $plugin->getTOC();
$TOC = $toc; // avoid later rebuild
}
}
trigger_event('TPL_TOC_RENDER', $toc, null, false);
$html = bootstrap_html_TOC($toc);
if($return) return $html;
echo $html;
return '';
}
/**
* Return the TOC rendered to XHTML
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function bootstrap_html_TOC($toc){
if(!count($toc)) return '';
global $lang;
$out = '<!-- TOC START -->'.DOKU_LF;
$out .= '<div id="dw_toc" class="hidden-print panel panel-default pull-right col-sm-4 col-md-3 col-xs-12">'.DOKU_LF;
$out .= '<div class="panel-heading hidden-print"><h3 class="panel-title" data-toggle="collapse" data-target="#toc_contents">';
$out .= $lang['toc'];
$out .= ' <b class="caret"></b></h3></div>'.DOKU_LF;
$out .= '<div id="toc_contents" class="hidden-print panel-collapse collapse in"><div class="panel-body">';
$out .= bootstrap_toc_html_buildlist($toc,'','html_list_toc');
$out .= '</div></div>';
$out .= '</div>'.DOKU_LF;
$out .= '<!-- TOC END -->'.DOKU_LF;
return $out;
}
function bootstrap_toc_html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
if (count($data) === 0) {
return '';
}
$start_level = $data[0]['level'];
$level = $start_level;
$ret = '';
$open = 0;
foreach ($data as $item){
if( $item['level'] > $level ){
//open new list
for($i=0; $i<($item['level'] - $level); $i++){
if ($i) $ret .= '<li class="">';
$ret .= "\n<ul class=\"$class\">\n";
$open++;
}
$level = $item['level'];
}elseif( $item['level'] < $level ){
//close last item
$ret .= "</li>\n";
while( $level > $item['level'] && $open > 0 ){
//close higher lists
$ret .= "</ul>\n</li>\n";
$level--;
$open--;
}
} elseif ($ret !== '') {
//close previous item
$ret .= "</li>\n";
}
//print item
$ret .= call_user_func($lifunc,$item);
$ret .= call_user_func($func,$item);
}
//close remaining items and lists
$ret .= "</li>\n";
while($open-- > 0) {
$ret .= "</ul></li>\n";
}
if ($forcewrapper || $start_level < 2) {
// Trigger building a wrapper ul if the first level is
// 0 (we have a root object) or 1 (just the root content)
$ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
}
return $ret;
}
function _tpl_breadcrumbs() {
global $lang;
global $conf;
// check if enabled
if (!$conf['breadcrumbs']) return false;
$crumbs = breadcrumbs();
$last = count($crumbs);
if ($last > 1) {
print '<!-- BREADCRUMBS --><div id="breadcrumbs" class="row hidden-print"><div class="col-lg-12"><ul class="breadcrumb">'.$lang['breadcrumb'].': ';
$i = 0;
foreach ($crumbs as $id => $name) {
$i++;
if ($i == $last - 1) {
print '<li>';
tpl_pagelink(':'.$id, hsc($name), 'title="' . $id . '"');
} else if ($i != $last) {
print '<li>';
tpl_pagelink(':'.$id, hsc($name), 'title="' . $id . '"');
}
print '</li> ';
}
print '</ul></div></div>';
}
return true;
}
function bootstrap_tpl_youarehere() {
global $lang;
global $ID;
global $conf;
// check if enabled
if (!$conf['youarehere']) return false;
$parts = explode(':', $ID);
$count = count($parts);
print '<ul class="breadcrumb hidden-print">' . $lang['youarehere'] . ': ';
// always print the start page
echo '<li class="home">';
tpl_pagelink(':'.$conf['start']);
echo '</li> ';
// print intermediate namespace links
$part = '';
for ($i = 0; $i < $count - 1; $i++) {
$part .= $parts[$i].':';
$page = $part;
if ($page == $conf['start']) continue; // skip startpage
echo '<li>';
tpl_pagelink($page);
echo '</li> ';
}
// print current page, skipping start page, skipping for namespace index
resolve_pageid('', $page, $exists);
if (isset($page) && $page == $part.$parts[$i]) return true;
$page = $part.$parts[$i];
if ($page == $conf['start']) return true;
echo '<li>';
tpl_pagelink($page);
echo '</li> ';
print '</ul>';
return true;
}
function bootstrap_tpl_userinfo() {
global $lang;
global $INFO;
if(isset($_SERVER['REMOTE_USER'])) {
print 'you are:'.hsc($INFO['userinfo']['name']);
return true;
}
return false;
}
/**
* prints the namespace tree in the mediamanger popup
*
* Only allowed in mediamanager.php
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function bootstrap_tpl_mediaTree() {
global $NS;
ptln('<div id="media__tree" class="well well-sm">');
bootstrap_media_nstree($NS);
ptln('</div>');
}
/**
* Build a tree outline of available media namespaces
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function bootstrap_media_nstree($ns){
global $conf;
global $lang;
// currently selected namespace
$ns = cleanID($ns);
if(empty($ns)){
global $ID;
$ns = (string)getNS($ID);
}
$ns_dir = utf8_encodeFN(str_replace(':','/',$ns));
$data = array();
search($data,$conf['mediadir'],'search_index',array('ns' => $ns_dir, 'nofiles' => true));
// wrap a list with the root level around the other namespaces
array_unshift($data, array('level' => 0, 'id' => '', 'open' =>'true', 'label' => '['.$lang['mediaroot'].']'));
// insert the current ns into the hierarchy if it isn't already part of it
$ns_parts = explode(':', $ns);
$tmp_ns = '';
$pos = 0;
foreach ($ns_parts as $level => $part) {
if ($tmp_ns) $tmp_ns .= ':'.$part;
else $tmp_ns = $part;
// find the namespace parts or insert them
while ($data[$pos]['id'] != $tmp_ns) {
if ($pos >= count($data) || ($data[$pos]['level'] <= $level+1 && strnatcmp(utf8_encodeFN($data[$pos]['id']), utf8_encodeFN($tmp_ns)) > 0)) {
array_splice($data, $pos, 0, array(array('level' => $level+1, 'id' => $tmp_ns, 'open' => 'true')));
break;
}
++$pos;
}
}
echo bootstrap_toc_html_buildlist($data,'','bootstrap_media_nstree_item','bootstrap_media_nstree_li');
}
/**
* Userfunction for html_buildlist
*
* Prints a media namespace tree item
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function bootstrap_media_nstree_item($item){
global $INPUT;
$pos = strrpos($item['id'], ':');
$label = substr($item['id'], $pos > 0 ? $pos + 1 : 0);
if(!$item['label']) $item['label'] = $label;
$class = 'level'.$item['level'];
// TODO: only deliver an image if it actually has a subtree...
if($item['open']){
$class .= ' open';
$icon = '<i class="glyphicon glyphicon-minus"></i> ';
$alt = '−';
} else {
$class .= ' closed';
$icon = '<i class="glyphicon glyphicon-plus"></i> ';
$alt = '+';
}
$ret = '<li class="'.$class.'">';
if (!($INPUT->str('do') == 'media'))
$ret .= '<a href="'.DOKU_BASE.'lib/exe/mediamanager.php?ns='.idfilter($item['id']).'" class="idx_dir">';
else $ret .= '<a href="'.media_managerURL(array('ns' => idfilter($item['id'], false), 'tab_files' => 'files')).'>';
$ret .= $icon;
$ret .= $item['label'];
$ret .= '</a>';
return $ret;
}
function bootstrap_media_nstree_li($item){
}
/**
* Get the sidebar html. Get cached sidebar if $cache param is true.
*
* @author Cameron Little <cameron@camlittle.com>
*/
function bootstrap_tpl_get_sidebar($pageid, $cache) {
global $TOC;
$oldtoc = $TOC;
$html = '';
$rev = '';
$file = wikiFN($pageid, $rev);
if ($cache && !$rev) {
if(@file_exists($file)) {
$html = p_cached_output($file,'xhtml',$pageid);
}
} else {
if(@file_exists($file)) {
$html = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$pageid,$rev)),$info); //no caching on old revisions
}
}
return $html;
}