-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_template.php
514 lines (435 loc) · 14.8 KB
/
my_template.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?php
/**
* Overwriting DokuWiki template functions
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sascha Leib <[email protected]>
*/
use dokuwiki\Extension\Event;
use dokuwiki\File\PageResolver;
/**
* Creates the Site logo image link
*
*/
function my_sitelogo() {
global $conf;
// get logo either out of the template images folder or data/media folder
$logoSize = array();
$logo = tpl_getMediaFile(array(':logo.svg', ':wiki:logo.svg', ':logo.png', ':wiki:logo.png', 'images/sitelogo.svg'), false, $logoSize);
tpl_link( my_homelink(),
'<img src="'.$logo.'" ' . (is_array($logoSize) && array_key_exists(3, $logoSize) ? $logoSize[3] : '') . ' alt="' . htmlentities($conf['title']) . '">', 'class="logo"');
}
/**
* get a link to the homepage.
*
* wraps the original wl() function to allow overriding in the options
*
* @author Sascha Leib <[email protected]>
*
* @returns string (link)
*/
function my_homelink() {
global $conf;
$hl = trim(tpl_getConf('homelink'));
if ( $hl !== '' ) {
return $hl;
} else {
return wl(); // default homelink
}
}
/**
* My implementation of the basic userinfo (in the global banner)
*
*
* @author Sascha Leib <[email protected]>
*
* @param string $prefix to be added before each line
*
* @return void
*/
function my_userinfo($prefix = '') {
global $lang;
global $INPUT;
global $INFO;
global $USERINFO;
// is there a user logged in?
$userid = $INPUT->server->str('REMOTE_USER');
// get the user menu items:
$items = (new \dokuwiki\Menu\UserMenu())->getItems();
if (isset($USERINFO['name'])) { // user is loggd in:
// output the button:
echo $prefix . "<button id=\"user-button\" aria-haspopup=\"menu\" aria-controls=\"user-action-menu\">\n";
echo $prefix . "\t<svg class=\"icon\" viewBox=\"0 0 24 24\"><path d=\"M12,4A4,4 0 0,1 16,8A4,4 0 0,1 12,12A4,4 0 0,1 8,8A4,4 0 0,1 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z\" /></svg>\n";
echo $prefix . "\t<span class=\"label\"><span class=\"sr-only\">" . htmlentities($lang['loggedinas']) . ' </span>' . htmlentities($USERINFO['name']) . "</span>\n";
echo $prefix . "</button>\n";
// add the menu:
my_actionlist($prefix, 'user-action-menu', $items, ['admin'], '', true);
} else {
my_actionlist($prefix, 'user-action-buttons', $items, ['admin']);
}
}
/**
* Hierarchical breadcrumbs
*
* Cleanup of the original code to create neater and more accessible HTML
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
* @author Nigel McNie <[email protected]>
* @author Sean Coates <[email protected]>
* @author <[email protected]>
*
* @param string $prefix to be added before each line
*
*/
function my_youarehere($prefix, $position, $return = false) {
global $conf;
global $ID;
global $lang;
// check if enabled
if (!$conf['youarehere']) return false;
// check if right position:
if(tpl_getConf('youareherepos') !== $position) return false;
// prepare output string:
$out = $prefix . '<h2 class="sr-only">' . $lang['youarehere'] . "</h2>\n";
$parts = explode(':', $ID);
$count = count($parts);
/* start the list: */
$out .= $prefix . "<ol class=\"youarehere\">\n";
/* is there a higher-level homepage defined? */
$hl = trim(tpl_getConf('homelink'));
if ( $hl !== '' ) {
$homeIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 5.69L17 10.19V18H15V12H9V18H7V10.19L12 5.69M12 3L2 12H5V20H11V14H13V20H19V12H22" /></svg>';
$out .= $prefix . "\t<li class=\"home hasicon\">" . tpl_link( $hl, $homeIcon . '<span>' . htmlentities(tpl_getLang('homepage')) . '</span>', ' title="' . htmlentities(tpl_getLang('homepage')) . '"', true) . "</li>\n";
}
// always print the startpage
$out .= $prefix . "\t<li" . ( $hl == '' ? ' class="home"' : '' ) . '>' . tpl_pagelink(':' . $conf['start'], null, true) . "</li>\n";
// print intermediate namespace links
$part = '';
for ($i = 0; $i < $count - 1; $i++) {
$part .= $parts[$i] . ':';
$page = $part;
if ($page == $conf['start']) continue; // Skip startpage
// output
$out .= $prefix . "\t<li>" . tpl_pagelink($page, null, true) . "</li>\n";
}
// print current page, skipping start page, skipping for namespace index
if (isset($page)) {
$page = (new PageResolver('root'))->resolveId($page);
if ($page == $part . $parts[$i]) {
$out .= $prefix . "</ol>\n";
if ($return) return $out;
echo $out;
return true;
}
}
$page = $part . $parts[$i];
if ($page == $conf['start']) {
$out .= $prefix . "</ol>\n";
if ($return) return $out;
echo $out;
return true;
}
/* actual page link and end: */
$out .= $prefix . "\t<li>" .tpl_pagelink($page, null, true) . "</li>\n";
$out .= $prefix . "</ol>\n";
if ($return) return $out;
echo $out;
return (bool)$out;
}
/**
* Print the breadcrumbs trace
*
* Cleanup of the original code to create neater and more accessible HTML
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param string $prefix inserted before each line
*
* @return void
*/
function my_breadcrumbs($prefix, $position) {
global $lang;
global $conf;
//check if enabled
if(!$conf['breadcrumbs']) return false;
// check if right position:
if(tpl_getConf('breadcrumbpos', 'none') !== $position) return false;
$crumbs = breadcrumbs(); //setup crumb trace
/* begin listing */
echo $prefix . '<p class="sr-only">' . $lang['breadcrumb'] . "</p>\n";
echo $prefix . "<ol class=\"trace\" reversed>";
$last = count($crumbs);
$i = 0;
foreach($crumbs as $id => $name) {
$i++;
echo '<li' . ($i == $last ? ' class="current"' : '') . '><bdi>' . tpl_link(wl($id), hsc($name), '', true) . '</bdi></li>';
}
echo "</ol>\n";
}
/**
* Inserts a cleaner version of the TOC
*
* This is an update of the original function that renders the TOC directly.
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param string $prefix to be added before each line
*
* @return void
*/
function my_toc($prefix = '') {
global $TOC;
global $ACT;
global $ID;
global $REV;
global $INFO;
global $conf;
global $lang;
$toc = array();
if(is_array($TOC)) {
// if a TOC was prepared in global scope, always use it
$toc = $TOC;
} elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
// get TOC from metadata, render if neccessary
$meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
if(isset($meta['internal']['toc'])) {
$tocok = $meta['internal']['toc'];
} else {
$tocok = true;
}
$toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
$toc = array();
}
} elseif($ACT == 'admin') {
// try to load admin plugin TOC
/** @var $plugin AdminPlugin */
if ($plugin = plugin_getRequestAdminPlugin()) {
$toc = $plugin->getTOC();
$TOC = $toc; // avoid later rebuild
}
}
/* inline icons: */
$iconSvg = "<svg width='100%' height='100%' viewBox='0 0 24 24' version='1.1' xmlns='http://www.w3.org/2000/svg'><rect class='top-bar' x='5' y='6' width='14' height='2'></rect><rect class='middle-bar' x='5' y='11' width='14' height='2'></rect><rect class='bottom-bar' x='5' y='16' width='14' height='2'></rect></svg>";
$tocView = tpl_getConf('showtoc', 'hide');
if (in_array($ACT, array('admin'))) {
$tocView = 'hide';
}
/* Build the hierarchical list of headline links: */
if (count($toc) >= intval($conf['tocminheads'])) {
echo $prefix . "<aside id=\"toc\" class=\"toggle_{$tocView}\">\n";
echo $prefix . "\t<div id=\"toc_header\"><h2>" . htmlentities($lang['toc']) . "</h2><button type=\"button\" id=\"toc-menubutton\" class=\"tg_button\" title=\"" . htmlentities($lang['toc']) . '" aria-haspopup="true" aria-controls="toc-menu"><span class="sr-only">' . htmlentities($lang['toc']) . "</span>" . $iconSvg . "</button></div>\n";
echo $prefix . "\t<div id=\"toc-menu\" class=\"tg_content\" role=\"menu\" aria-labelledby=\"toc-menubutton\">";
$level = 0;
foreach($toc as $it) {
$nl = intval($it['level']);
$cp = ($nl <=> $level);
if ($cp > 0) {
while ($level < $nl) {
echo "\n" . $prefix . str_repeat("\t", $level*2 + 2) . "<ol>\n";
$level++;
}
} else if ($cp < 0) {
while ($level > $nl) {
echo "\n" . $prefix . str_repeat("\t", $level*2) . "</ol>\n" . $prefix . str_repeat("\t", $level*2-1) . "</li>\n";
$level--;
}
} else {
echo "</li>\n";
}
$href = ( array_key_exists('link', $it ) ? $it['link'] : '' ) . ( array_key_exists('hid', $it) && $it['hid'] !== '' ? '#' . $it['hid'] : '' );
echo $prefix . str_repeat("\t", $nl*2 + 1) . '<li role="presentation"><a role="menuitem" href="' . $href . '">' . htmlentities($it['title']) . "</a>";
$level = $nl;
}
for ($i = $level-1; $i > 0; $i--) {
echo "</li>\n" . $prefix . str_repeat("\t", $i*2 + 1) . "</ol>";
}
echo "</li>\n" . $prefix . "\t\t</ol>\n" . $prefix . "\t</div>\n" . $prefix . "</aside>\n";
}
}
/**
* Insert the main headline for the page
*
* provides additional configuration options for this element
*
* @author Sascha Leib <[email protected]>
*
* @param string $prefix inserted before each line
*
* @return void
*/
function my_pagetitle($prefix) {
global $ID;
global $conf;
/* get the header style */
$type = my_headerstyle();
/* build the headline section */
echo $prefix . '<div class="type-' . $type . "\">\n";
switch ($type) {
case 'file':
tpl_includeFile('title.html');
break;
case 'sitename':
echo $prefix . "\t<h2 class=\"title\">" . $conf['title'] . "</h2>\n";
if ($conf['tagline'] && $conf['tagline'] !== '') {
echo $prefix . "\t<p class=\"tagline\">" . $conf['tagline'] . "</p>\n";
}
break;
case 'pagename':
echo $prefix . "\t<h1>" . tpl_pagetitle($ID, true) . "</h1>\n";
break;
default:
echo "<pre>UNKNOWN:" . tpl_getConf('pageheadline') . "</pre>";
break;
}
echo $prefix . "</div>\n";
}
/**
* Print the breadcrumbs trace
*
* Cleanup of the original code to create neater and more accessible HTML
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param string $prefix inserted before each line
*
* @return void
*/
function my_banner_style() {
global $ID;
global $conf;
/* don't run if banner image is disabled */
if (trim(tpl_getConf('bannerimg')) == '') return;
$background = null;
/* list of extensions to look for (in reverse order) */
$exts = array('jpg','jpeg','png','svg');
/* build a list of paths to look at: */
$cpath = '';
$paths = array();
foreach (explode(':', $ID) as $it) {
foreach ($exts as $ext) {
array_push($paths, $cpath . trim(tpl_getConf('bannerimg')) . '.' . $ext);
}
$cpath .= $it . ':';
}
$paths = array_reverse($paths); /* reverse the order */
/* check if an image exists in one of the paths: */
foreach ($paths as $rpath) {
$lpath = mediaFN($rpath);
if (file_exists($lpath)) {
$background = ml($rpath, '', true, '', false);
break;
}
}
/* if not found, use the template banner: */
if (!$background) {
$background = tpl_basedir() . 'images/banner.jpg';
}
/* find the element height */
$height = tpl_getConf('bannersize', 'inherit');
if ($background) {
echo "background-image: url('" . $background . "');min-height: " . $height . ';';
}
}
/**
* Modification of the original tpl_license in the DokuWiki code
*
* @author Andreas Gohr <[email protected]>
* @author Sascha Leib <[email protected]>
*
* @param string $target open link in new tab?
*/
function my_license_button($target) {
global $license;
global $conf;
global $lang;
if(!$conf['license']) return '';
if(!is_array($license[$conf['license']])) return '';
$lic = $license[$conf['license']];
$trg = ($target) ? ' target="'.$target.'"' : '';
$src = 'lib/tpl/nuropa/images/license/'.$conf['license'].'.svg';
echo "\t<a href=\"".$lic['url'].'" rel="license"'.$trg.'><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" width="80" height="15" /></a>';
}
/**
* Wrapper for tpl_classes to add template classes
*
* @author Sascha Leib <[email protected]>
*/
function my_bodyclasses() {
global $conf;
$cls = tpl_classes();
/* enable darkmode? */
if (tpl_getConf('darkmode') === 'auto') {
$cls .= ' darkmode';
}
return $cls;
}
/* private helper function to putput a list of action items: */
function my_actionlist($prefix, $id, $list, $exclude, $type = '', $hidden = false) {
/* build menu */
echo $prefix . '<ul id="' . $id . '" class="' . htmlentities($type) . '"' . ($hidden ? ' style="display:none"' : '') . ">\n";
foreach($list as $it) {
//echo '<!-- ' . print_r($it, true) . ' -->';
$typ = htmlentities($it->getType());
if (!in_array($typ, $exclude)) {
echo $prefix . "\t<li data-type=\"" . $typ . '">'
. my_HtmlLink($it, false, true)
. "</li>\n";
}
}
echo $prefix . "</ul>\n";
};
/* overwrite the asHtmlLink function for my purposes */
function my_HtmlLink($item, $classprefix = 'menuitem ', $svg = true) {
$attr = buildAttributes($item->getLinkAttributes($classprefix));
$html = "<a $attr>";
if ($svg) {
$html .= inlineSVG($item->getSvg());
$html .= '<span>' . hsc($item->getLabel()) . '</span>';
} else {
$html .= hsc($item->getLabel());
}
$html .= "</a>";
return $html;
}
/* helper function to determine the headline style: */
function my_headerstyle() {
global $ID;
global $conf;
/* what kind of headline should be included? */
$type = tpl_getConf('pageheadline');
if ($type == 'siteonhp') {
if ($ID == $conf['start']) {
$type = 'sitename';
} else {
$type = 'pagename';
}
}
return $type;
}
/**
* creates a back to top button
*
* Buids the HTML code to insert the "to top" button
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param string $prefix inserted before each line
*
* @return string html
**/
function my_topbtn($prefix)
{
global $lang;
$iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.41,15.41L12,10.83L16.59,15.41L18,14L12,8L6,14L7.41,15.41Z" style="fill:#166DDF" /></svg>';
$html = $prefix . "<div id=\"to-top-block\">\n"
. "\t<a href=\"#main-content\" title=\"" . $lang['btn_top'] ." [t]\" rel=\"nofollow\" accesskey=\"t\">\n"
. "\t<span class=\"sr-only\">" . $lang['btn_top'] ." </span>\n"
. "\t\t" . $iconSvg . "</a></div>\n";
return $html;
}