-
Notifications
You must be signed in to change notification settings - Fork 4
/
my_template.php
748 lines (631 loc) · 23.9 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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
<?php
/**
* Overwriting DokuWiki template functions
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*/
use dokuwiki\Extension\Event;
use dokuwiki\File\PageResolver;
/**
* Print the specific HTML meta headers
*
* Overrides the original version by modifying the headers and the way it is printed
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @triggers TPL_METAHEADER_OUTPUT
* @param bool $alt Should feeds and alternative format links be added?
* @return bool
*/
function my_metaheaders($alt = true) {
global $ID;
global $REV;
global $INFO;
global $JSINFO;
global $ACT;
global $QUERY;
global $lang;
global $conf;
global $updateVersion;
/** @var Input $INPUT */
global $INPUT;
// prepare the head array
$head = array();
// prepare seed for js and css
$tseed = $updateVersion;
$depends = getConfigFiles('main');
$depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
foreach($depends as $f) $tseed .= @filemtime($f);
$tseed = md5($tseed);
// Open Graph information
$meta = p_get_metadata($ID);
if (is_array($meta) && array_key_exists('title', $meta) && $meta['title'] !== null) {
$head['meta'][] = array('property' => 'og:title', 'content' => tpl_pagetitle($ID, true));
$head['meta'][] = array('property' => 'og:site_name ', 'content' => $conf['title']);
$head['meta'][] = array('property' => 'og:type', 'content' => 'website');
$head['meta'][] = array('property' => 'og:url', 'content' => wl($ID, '', true, '&'));
if (array_key_exists('description', $meta) && is_array($meta['description'])) {
if (array_key_exists('abstract', $meta['description'])) {
$parts = explode("\n", $meta['description']['abstract']);
if (is_array($parts) && array_key_exists(2, $parts)) {
$head['meta'][] = array('property' => 'og:description', 'content' => $parts[2]);
// Bing insists in a non-og description:
$head['meta'][] = array('name' => 'description', 'content' => $parts[2]);
}
}
}
}
// the usual stuff
$head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
if(actionOK('search')) {
$head['link'][] = array(
'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
);
}
$head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
if(actionOK('index')) {
$head['link'][] = array(
'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
'title'=> $lang['btn_index']
);
}
if (actionOK('manifest')) {
$head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
}
$styleUtil = new \dokuwiki\StyleUtils();
$styleIni = $styleUtil->cssStyleini();
$replacements = $styleIni['replacements'];
if (!empty($replacements['__theme_color__'])) {
$head['meta'][] = array(
'name' => 'theme-color',
'content' => $replacements['__theme_color__']
);
}
if($alt) {
if(actionOK('rss')) {
$head['link'][] = array(
'rel' => 'alternate', 'type'=> 'application/rss+xml',
'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
);
$head['link'][] = array(
'rel' => 'alternate', 'type'=> 'application/rss+xml',
'title'=> $lang['currentns'],
'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '')
);
}
if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
$head['link'][] = array(
'rel' => 'edit',
'title'=> $lang['btn_edit'],
'href' => wl($ID, 'do=edit', false, '&')
);
}
if(actionOK('rss') && $ACT == 'search') {
$head['link'][] = array(
'rel' => 'alternate', 'type'=> 'application/rss+xml',
'title'=> $lang['searchresult'],
'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
);
}
if(actionOK('export_xhtml')) {
$head['link'][] = array(
'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
'href'=> exportlink($ID, 'xhtml', '', false, '&')
);
}
if(actionOK('export_raw')) {
$head['link'][] = array(
'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
'href'=> exportlink($ID, 'raw', '', false, '&')
);
}
}
// setup robot tags apropriate for different modes
if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
if($INFO['exists']) {
//delay indexing:
if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
} else {
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
}
$canonicalUrl = wl($ID, '', true, '&');
if ($ID == $conf['start']) {
$canonicalUrl = DOKU_URL;
}
$head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
} else {
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
}
} elseif(defined('DOKU_MEDIADETAIL')) {
$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
} else {
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
}
// set metadata
if($ACT == 'show' || $ACT == 'export_xhtml') {
// keywords (explicit or implicit)
if(!empty($INFO['meta']['subject'])) {
$head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
} else {
$head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
}
}
// load stylesheets
$head['link'][] = array(
'rel' => 'stylesheet',
'href'=> DOKU_BASE . 'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
'defer' => 'defer'
);
$script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';\n\t\t";
if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
$script .= "var SIG=".toolbar_signature().";\n\t\t";
}
if($conf['basedir']) {
$script .= 'var BASEDIR="'.$conf['basedir']."\";\n\t\t";
}
jsinfo();
$script .= 'var JSINFO = ' . json_encode($JSINFO).';';
$head['script'][] = array('_data'=> $script);
// load jquery
$jquery = getCdnUrls();
foreach($jquery as $src) {
$head['script'][] = array(
/* 'charset' => 'utf-8', -- obsolete */
'_data' => '',
'src' => $src,
) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
}
// load our javascript dispatcher
$head['script'][] = array(
/* 'charset'=> 'utf-8', -- obsolete */
'_data'=> '',
'src' => DOKU_BASE . 'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
// trigger event here
Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_my_metaheaders_action', true);
return true;
}
/**
* prints the array build by my_metaheaders
*
* Overrides the original version by adding a tab before each line for neater HTML code
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param array $data
*/
function _my_metaheaders_action($data) {
foreach($data as $tag => $inst) {
foreach($inst as $attr) {
if ( empty($attr) ) { continue; }
echo "\t<", $tag, ' ', buildAttributes($attr);
if(isset($attr['_data']) || $tag == 'script') {
if($tag == 'script' && $attr['_data'])
$attr['_data'] = "/*<![CDATA[*/".
$attr['_data'].
"\n/*!]]>*/";
echo '>', $attr['_data'], '</', $tag, '>';
} else {
echo '/>';
}
echo "\n";
}
}
}
/**
* 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
}
}
/**
* 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 = '') {
global $lang;
global $conf;
//check if enabled
if(!$conf['breadcrumbs']) return false;
$crumbs = breadcrumbs(); //setup crumb trace
/* begin listing */
echo $prefix . "<nav id=\"navBreadCrumbs\">\n";
echo $prefix . "\t<h4>" . $lang['breadcrumb'] . "</h4>\n";
echo $prefix . "\t<ol reversed>\n";
$last = count($crumbs);
$i = 0;
foreach($crumbs as $id => $name) {
$i++;
echo $prefix . "\t\t<li" . ($i == $last ? ' class="current"' : '') . '><bdi>' . tpl_link(wl($id), hsc($name), '', true) . "</bdi></li>\n";
}
echo $prefix . "\t</ol>\n";
echo $prefix . "</nav>\n";
}
/**
* 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 = '') {
global $conf;
global $ID;
global $lang;
// check if enabled
if(!$conf['youarehere']) return false;
$parts = explode(':', $ID);
$count = count($parts);
$isdir = ( $parts[$count-1] == $conf['start']);
$hl = trim(tpl_getConf('homelink'));
echo $prefix . "<nav id=\"navYouAreHere\">\n";
echo $prefix . "\t<h4>" . $lang['youarehere'] . "</h4>\n";
echo $prefix . "\t<ol>\n";
// always print the startpage
if ( $hl !== '' ) {
echo $prefix . "\t\t<li class=\"home\">" . tpl_link( $hl, htmlentities(tpl_getLang('homepage')), ' title="' . htmlentities(tpl_getLang('homepage')) . '"', true) . "</li>\n";
echo $prefix . "\t\t<li>" . tpl_pagelink(':'.$conf['start'], null, true) . "</li>\n";
} else {
echo $prefix . "\t\t<li class=\"home\">" . tpl_pagelink(':'.$conf['start'], null, true) . "</li>\n";
}
// print intermediate namespace links
$page = '';
for($i = 0; $i < $count - 1; $i++) {
$part = $parts[$i];
$page .= $part . ':';
if ($i == $count-2 && $isdir) break; // Skip last if it is an index page
echo $prefix . "\t\t<li>" . tpl_pagelink($page, null, true) . "</li>\n";
}
// chould the current page be included in the listing?
$trail = tpl_getConf('navtrail');
if ($trail !== 'none' && $trail !== '') {
echo $prefix . "\t\t<li class=\"current\">";
if ($trail == 'text') {
echo tpl_pagetitle($page . $parts[$count-1], true);
} else if ($trail == 'link') {
echo tpl_pagelink($page . $parts[$count-1], null, true);
}
echo "</li>\n";
}
echo $prefix . "\t</ol>\n";
echo $prefix . "</nav>\n";
}
/**
* 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;
// add login/logout button:
$items = (new \dokuwiki\Menu\UserMenu())->getItems();
foreach($items as $it) {
$typ = $it->getType();
if ($typ === 'profile') { // special case for user profile:
echo $prefix . '<li class="action profile"><span class="sronly">' . $lang['loggedinas'] .
' </span><a href="' . htmlentities($it->getLink()) . '" title="' . $it->getTitle() . '">' .
userlink() . "</a></li>\n";
} else {
echo $prefix . "<li class=\"action $typ\"><a href=\"" . htmlentities($it->getLink()) .
'" title="' . $it->getTitle() . '">' . ($typ === 'profile'? userlink() : $it->getLabel() ) .
"</a></li>\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
}
}
/* Build the hierarchical list of headline links: */
if (count($toc) >= intval($conf['tocminheads'])) {
echo $prefix . "<aside id=\"toc\" class=\"toggle hide\">\n";
echo $prefix . "\t<button type=\"button\" id=\"toc-menubutton\" class=\"tg_button\" title=\"" . htmlentities($lang['toc']) . '" aria-haspopup="true" aria-controls="toc-menu"><span>' . htmlentities($lang['toc']) . "</span></button>\n" . $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";
}
}
/**
* Print last change date
*
* @author Sascha Leib <[email protected]>
*
* @param string $prefix to be added before each line
*
* @return void
*/
function my_lastchange($prefix = '') {
global $lang;
global $INFO;
global $conf;
$lastmod = $INFO['lastmod'];
if (intval($lastmod) > 0) { // is valid date?
$longDate = htmlentities(dformat($lastmod));
echo $prefix . "<p class=\"docInfo\">\n";
echo $prefix . "\t<bdi>" . $lang['lastmod'] . "</bdi>\n";
echo $prefix . "\t<time datetime=\"" . date('c', $lastmod) . '" title="' . $longDate . '"><span class="print-only">' . $longDate . '</span><span class="noprint">' . datetime_h($lastmod) . "</span></time>\n";
echo $prefix . "</p>\n";
}
/* user name for last change (is this really interesting to the visitor?) */
/* echo $prefix .'<span class="editorname" tabindex="0">' . $lang['by'] . ' <bdi>' . editorinfo($INFO['editor']) . "</bdi></span>\n"; */
}
/**
* Returns a description list of the metatags of the current image
*
* @return string html of description list
*/
function my_img_meta($prefix = '') {
global $lang;
$format = '%Y-%m-%dT%T%z'; /* e.g. 2021-21-05T16:45:12+02:00 */
$tags = tpl_get_img_meta();
foreach($tags as $tag) {
$label = $lang[$tag['langkey']];
if(!$label) $label = $tag['langkey'] . ':';
echo $prefix . '<tr><th>'.$label.'</th><td>';
if ($tag['type'] == 'date') {
echo '<time datetime="' . strftime($format, $tag['value']) . '">' . dformat($tag['value']) . '</time>';
} else {
echo hsc($tag['value']);
}
echo "</td></tr>\n";
}
}
/**
* 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']) . '" />', 'accesskey="h" title="[H]" class="logo"');
}
/**
* Creates the various favicon and similar links:
*
* @param string $color overwrite the theme color.
*
* @return null
*/
function my_favicons($color = null) {
$logoSize = array();
/* Theme color:
if ($color == null) {
// get the style config:
$styleUtil = new \dokuwiki\StyleUtils();
$styleIni = $styleUtil->cssStyleini();
$replacements = $styleIni['replacements'];
$color = $replacements['__theme_color__'];
if ($color== null) { $color = '#2b73b7'; }
}
echo "\t<meta name=\"theme-color\" content=\"" . $color . "\" />\n"; */
// get the favicon:
$link = tpl_getMediaFile(array(':favicon.ico', ':favicon.png', ':favicon.svg', ':wiki:favicon.ico', ':wiki:favicon.png', ':wiki:favicon.svg'), false, $logoSize);
echo "\t<link rel=\"icon\" href=\"" . $link . "\" />\n";
// Apple Touch Icon
$logoSize = array();
$link = tpl_getMediaFile(array(':apple-touch-icon.png', ':wiki:apple-touch-icon.png', 'images/apple-touch-icon.png'), false, $logoSize);
echo "\t<link rel=\"apple-touch-icon\" href=\"" . $link . "\" />\n";
}
/**
* inserts the Cookies banner, if appropriate.
* This is based on Michal Koutny’s "cookielaw" plugin
*
* @param string $prefix to be added before each line
*/
function my_cookiebanner($prefix = '') {
// get the configuration settings:
$msg = tpl_getConf('cookiemsg', '(no message configured)');
$position = tpl_getConf('cookiepos', 'bottom');
$link = tpl_getConf('cookielink', 'about:cookies');
// if the cookie is already set or position is set to hide, do nothing.
if ( isset($_COOKIE['cookielaw']) or $position == 'hide') {
return;
}
// output the HTML code:
echo $prefix . "<div id=\"cookiebanner\" class=\"cb_" . $position . "\">\n";
echo $prefix . "\t<p class=\"cb_info\"><span class=\"cb_icon\"></span>\n";
echo $prefix . "\t\t<span class=\"cb_msg\">". $msg . "</span>\r";
echo $prefix . "\t</p>\n";
echo $prefix . "\t<p class=\"cb_action\">\n";
echo $prefix . "\t\t<button>" . hsc(tpl_getLang('cookie_consent')) . "</button>\n";
echo $prefix . "\t\t";
if ( substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://') {
echo '<a href="' . $link . '" target="_blank">' . hsc(tpl_getLang('cookie_linktext')) . '</a>';
} else {
tpl_pagelink($link, tpl_getLang('cookie_linktext'));
}
echo $prefix . "\n\t</p>\n" . $prefix . "</div>\n";
}
/**
* inserts the Languages menu, if appropriate.
*
* @author Sascha Leib <[email protected]>
* @author Andreas Gohr <[email protected]>
*
* @param string $prefix to be added before each line
* @param string $place the location from where it is called
* @param string $checkage should the age of the translation be checked?
*/
function my_langmenu($prefix, $place, $checkage = true) {
global $INFO;
global $conf;
// the current page language:
$lang = $conf['lang'];
/* get the config option: */
$config = tpl_getConf('langmenu', 'none');
/* only shw the menu if this is called from the right place */
if ($config == $place) {
/* collect the output: */
$out = '';
/* try to load the plugin: */
$trans = plugin_load('helper','translation');
/* plugin available? */
if ($trans) {
if (!$trans->istranslatable($INFO['id'])) return '';
if ($checkage) $trans->checkage();
[, $idpart] = $trans->getTransParts($INFO['id']);
$asMenu = ($place == 'tb'); // display as menu only in toolbar!
$out .= "{$prefix}<div id=\"{$place}Languages\">\n";
// create the header item
if ($asMenu) { // show as menu (toolbar)
// get the language name (in the local language)
$langName = htmlentities($trans->getLocalName($lang));
/* prepare the menu icon (note that the language code and name are embedded! */
$svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><title>{$langName}</title><path d='M20,2H4A2,2 0 0,0 2,4V22L6,18H20A2,2 0 0,0 22,16V4C22,2.89 21.1,2 20,2Z' /><text lengthAdjust='spacingAndGlyphs' x='50%' y='47%' dominant-baseline='middle' text-anchor='middle' style='font-size:50%'>{$lang}</text></svg>";
// prepare the menu button:
$out .= "{$prefix}\t<button id=\"langButton\" aria-haspopup=\"menu\" aria-controls=\"langMenuWrapper\" aria-expanded=\"false\">\n";
$out .= "{$prefix}\t\t{$svg}\n";
$out .= "{$prefix}\t\t<span class=\"sronly\">" . $trans->getLang('translations') . "</span>\n{$prefix}\t</button>\n";
} else { // show as list (sidebar)
// show title (only if the option is configured)
if (isset($trans->opts['title'])) {
// get a localized headline text
$headline = tpl_getLang('languages');
// should a link to the about page be added?
$about = $trans->getConf('about'); /* get the about link */
if ($about !== '') {
/* localized about links? */
if ($trans->getConf('localabout')) {
[, $aboutid] = $trans->getTransParts($about);
[$about, ] = $trans->buildTransID($lang, $aboutid);
$about = cleanID($about);
}
// build the link:
$headline = html_wikilink($about, $headline);
}
/* complete the headline */
$out .= "{$prefix}\t<h3><span>" . $headline . "</span></h3>\n";
}
}
/* build the menu content */
$out .= "{$prefix}\t<div id=\"langMenu" . ( $asMenu ? 'Wrapper" role="menu" style="display: none"' : 'List"') . ">\n"
. "{$prefix}\t\t<ul id=\"lang" . ( $asMenu ? 'Menu" role="group"' : 'List"' ) . ">\n";
// loop over each language and add it to the menu:
foreach ($trans->translations as $t) {
$l = ( $t !== '' ? $t : $lang );
[$trg, $lng] = $trans->buildTransID($t, $idpart);
$trg = cleanID($trg);
$exists = page_exists($trg, '', false);
$filter = tpl_getConf('langfilter', 'all');
/* only show if translation exists? */
if ($exists || $filter === 'all') {
$class = 'wikilink' . ( $exists ? '1' : '2');
$link = wl($trg);
$current = ($lng == $lang);
$out .= "{$prefix}\t\t\t<li" . ( $asMenu ? ' role="presentation"' : '' ). ( $current ? ' class="current"' : '' ) . ">\n";
$out .= "{$prefix}\t\t\t\t<a href=\"{$link}\" lang=\"{$lng}\" hreflang=\"{$lng}\" class=\"{$class}\"" . ( $asMenu ? ' role="menuitem"' : '' ) . '><bdi>'. $trans->getLocalName($lng) . "</bdi></a>\n";
$out .= "{$prefix}\t\t\t</li>\n";
}
}
// close all open elements:
$out .= "{$prefix}\t\t</ul>\n"
. "{$prefix}\t</div>\n"
. "{$prefix}</div>\n";
}
echo $out; // done.
}
}