1<?php
2/**
3 * Overwriting DokuWiki template functions
4 *
5 * @license	GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author	Sascha Leib <sascha@leib.be>
7 * @author	Andreas Gohr <andi@splitbrain.org>
8 */
9
10use dokuwiki\Extension\Event;
11use dokuwiki\File\PageResolver;
12
13/**
14 * Print the specific HTML meta headers
15 *
16 * Overrides the original version by modifying the headers and the way it is printed
17 *
18 * @author Sascha Leib <sascha@leib.be>
19 * @author Andreas Gohr <andi@splitbrain.org>
20 *
21 * @triggers TPL_METAHEADER_OUTPUT
22 * @param	bool $alt Should feeds and alternative format links be added?
23 * @return	bool
24 */
25function my_metaheaders($alt = true) {
26	global $ID;
27	global $REV;
28	global $INFO;
29	global $JSINFO;
30	global $ACT;
31	global $QUERY;
32	global $lang;
33	global $conf;
34	global $updateVersion;
35	/** @var Input $INPUT */
36	global $INPUT;
37
38	// prepare the head array
39	$head = array();
40
41	// prepare seed for js and css
42	$tseed = $updateVersion;
43	$depends = getConfigFiles('main');
44	$depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
45	foreach($depends as $f) $tseed .= @filemtime($f);
46	$tseed = md5($tseed);
47
48	// Open Graph information
49	$meta = p_get_metadata($ID);
50	if (is_array($meta) && array_key_exists('title', $meta) && $meta['title'] !== null) {
51		$head['meta'][] = array('property' => 'og:title', 'content' => tpl_pagetitle($ID, true));
52		$head['meta'][] = array('property' => 'og:site_name ', 'content' => $conf['title']);
53		$head['meta'][] = array('property' => 'og:type', 'content' => 'website');
54		$head['meta'][] = array('property' => 'og:url', 'content' => wl($ID, '', true, '&'));
55
56		if (array_key_exists('description', $meta) && is_array($meta['description'])) {
57			if (array_key_exists('abstract', $meta['description'])) {
58				$parts = explode(NL, $meta['description']['abstract']);
59
60				if (is_array($parts) && array_key_exists(2, $parts)) {
61					$head['meta'][] = array('property' => 'og:description', 'content' => $parts[2]);
62
63					// Bing insists in a non-og description:
64					$head['meta'][] = array('name' => 'description', 'content' => $parts[2]);
65				}
66			}
67		}
68	}
69
70	// the usual stuff
71	$head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
72	if(actionOK('search')) {
73		$head['link'][] = array(
74			'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
75			'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
76		);
77	}
78
79	$head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
80	if(actionOK('index')) {
81		$head['link'][] = array(
82			'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
83			'title'=> $lang['btn_index']
84		);
85	}
86
87	if (actionOK('manifest')) {
88		$head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
89	}
90
91	$styleUtil = new \dokuwiki\StyleUtils();
92	$styleIni = $styleUtil->cssStyleini();
93	$replacements = $styleIni['replacements'];
94	if (!empty($replacements['__theme_color__'])) {
95		$head['meta'][] = array(
96			'name' => 'theme-color',
97			'content' => $replacements['__theme_color__']
98		);
99	}
100
101	if($alt) {
102		if(actionOK('rss')) {
103			$head['link'][] = array(
104				'rel'  => 'alternate', 'type'=> 'application/rss+xml',
105				'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
106			);
107			$head['link'][] = array(
108				'rel'  => 'alternate', 'type'=> 'application/rss+xml',
109				'title'=> $lang['currentns'],
110				'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '')
111			);
112		}
113		if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
114			$head['link'][] = array(
115				'rel'  => 'edit',
116				'title'=> $lang['btn_edit'],
117				'href' => wl($ID, 'do=edit', false, '&')
118			);
119		}
120
121		if(actionOK('rss') && $ACT == 'search') {
122			$head['link'][] = array(
123				'rel'  => 'alternate', 'type'=> 'application/rss+xml',
124				'title'=> $lang['searchresult'],
125				'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
126			);
127		}
128
129		if(actionOK('export_xhtml')) {
130			$head['link'][] = array(
131				'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
132				'href'=> exportlink($ID, 'xhtml', '', false, '&')
133			);
134		}
135
136		if(actionOK('export_raw')) {
137			$head['link'][] = array(
138				'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
139				'href'=> exportlink($ID, 'raw', '', false, '&')
140			);
141		}
142	}
143
144	// setup robot tags apropriate for different modes
145	if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
146		if($INFO['exists']) {
147			//delay indexing:
148			if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
149				$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
150			} else {
151				$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
152			}
153			$canonicalUrl = wl($ID, '', true, '&');
154			if ($ID == $conf['start']) {
155				$canonicalUrl = DOKU_URL;
156			}
157			$head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
158		} else {
159			$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
160		}
161	} elseif(defined('DOKU_MEDIADETAIL')) {
162		$head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
163	} else {
164		$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
165	}
166
167	// set metadata
168	if($ACT == 'show' || $ACT == 'export_xhtml') {
169		// keywords (explicit or implicit)
170		if(!empty($INFO['meta']['subject'])) {
171			$head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
172		} else {
173			$head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
174		}
175	}
176
177	// load stylesheets
178	$head['link'][] = array(
179		'rel' => 'stylesheet',
180		'href'=> DOKU_BASE . 'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
181		'defer' => 'defer'
182	);
183
184	$script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';".DOKU_LF.DOKU_TAB.DOKU_TAB;
185	if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
186		$script .= "var SIG=".toolbar_signature().";".DOKU_LF.DOKU_TAB.DOKU_TAB;
187	}
188
189	if($conf['basedir']) {
190		$script .= 'var BASEDIR="'.$conf['basedir']."\";".DOKU_LF.DOKU_TAB.DOKU_TAB;
191	}
192
193	jsinfo();
194	$script .= 'var JSINFO = ' . json_encode($JSINFO).';';
195	$head['script'][] = array('_data'=> $script);
196
197	// load jquery
198	$jquery = getCdnUrls();
199	foreach($jquery as $src) {
200		$head['script'][] = array(
201			/* 'charset' => 'utf-8', -- obsolete */
202			'_data' => '',
203			'src' => $src,
204		) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
205	}
206
207	// load our javascript dispatcher
208	$head['script'][] = array(
209		/* 'charset'=> 'utf-8', -- obsolete */
210		'_data'=> '',
211		'src' => DOKU_BASE . 'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
212	) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
213
214	// trigger event here
215	Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_my_metaheaders_action', true);
216	return true;
217}
218
219/**
220 * prints the array build by my_metaheaders
221 *
222 * Overrides the original version by adding a tab before each line for neater HTML code
223 *
224 * @author Sascha Leib <sascha@leib.be>
225 * @author Andreas Gohr <andi@splitbrain.org>
226 *
227 * @param array $data
228 */
229function _my_metaheaders_action($data) {
230	foreach($data as $tag => $inst) {
231		foreach($inst as $attr) {
232			if ( empty($attr) ) { continue; }
233			echo DOKU_TAB . '<', $tag, ' ', buildAttributes($attr);
234			if($tag == 'script' && isset($attr['_data'])) {
235				/* $attr['_data'] = "<![CDATA[".NL. DOKU_TAB . DOKU_TAB .
236					$attr['_data'].
237					NL . DOKU_TAB . ' ]]>'; */
238
239				echo '>', $attr['_data'], '</', $tag, '>';
240			} else {
241				echo '>';
242				if ($tag == 'script') {
243					echo '</', $tag, '>';
244				}
245			}
246			echo DOKU_LF;
247		}
248	}
249}
250
251/**
252 * get a link to the homepage.
253 *
254 * wraps the original wl() function to allow overriding in the options
255 *
256 * @author Sascha Leib <sascha@leib.be>
257 *
258 * @returns string (link)
259 */
260function my_homelink() {
261	global $conf;
262
263	$hl = trim(tpl_getConf('homelink'));
264
265	if ( $hl !== '' ) {
266		return $hl;
267	} else {
268		return wl(); // default homelink
269	}
270}
271
272/**
273 * Print the breadcrumbs trace
274 *
275 * Cleanup of the original code to create neater and more accessible HTML
276 *
277 * @author Sascha Leib <sascha@leib.be>
278 * @author Andreas Gohr <andi@splitbrain.org>
279 *
280 * @param string $prefix inserted before each line
281 *
282 * @return void
283 */
284function my_breadcrumbs($prefix = '') {
285	global $lang;
286	global $conf;
287
288	//check if enabled
289	if(!$conf['breadcrumbs']) return false;
290
291	$crumbs = breadcrumbs(); //setup crumb trace
292
293	/* begin listing */
294	echo $prefix . '<nav id="navBreadCrumbs">'.NL;
295	echo $prefix . DOKU_TAB . '<h4>' . $lang['breadcrumb'] . '</h4>'.NL;
296	echo $prefix . DOKU_TAB . '<ol reversed>'.NL;
297
298	$last = count($crumbs);
299	$i	= 0;
300	foreach($crumbs as $id => $name) {
301		$i++;
302		echo $prefix . DOKU_TAB . DOKU_TAB . '<li' . ($i == $last ? ' class="current"' : '') . '><bdi>' . tpl_link(wl($id), hsc($name), '', true) .  '</bdi></li>'.NL;
303	}
304	echo $prefix . DOKU_TAB . '</ol>'.NL;
305	echo $prefix . '</nav>'.NL;
306}
307
308/**
309 * Hierarchical breadcrumbs
310 *
311 * Cleanup of the original code to create neater and more accessible HTML
312 *
313 * @author Sascha Leib <sascha@leib.be>
314 * @author Andreas Gohr <andi@splitbrain.org>
315 * @author Nigel McNie <oracle.shinoda@gmail.com>
316 * @author Sean Coates <sean@caedmon.net>
317 * @author <fredrik@averpil.com>
318 *
319 * @param  string $prefix to be added before each line
320 *
321 */
322function my_youarehere($prefix = '') {
323	global $conf;
324	global $ID;
325	global $lang;
326
327	// check if enabled
328	if(!$conf['youarehere']) return false;
329
330	$parts = explode(':', $ID);
331	$count = count($parts);
332	$isdir = ( $parts[$count-1] == $conf['start']);
333
334	$hl = trim(tpl_getConf('homelink'));
335
336	echo $prefix . '<nav id="navYouAreHere">'.NL;
337	echo $prefix . DOKU_TAB . '<h4>' . $lang['youarehere'] . '</h4>'.NL;
338	echo $prefix . DOKU_TAB . '<ol>'.NL;
339
340	// always print the startpage
341	if ( $hl !== '' ) {
342		echo $prefix . DOKU_TAB . DOKU_TAB . '<li class="home">' . tpl_link( $hl, htmlentities(tpl_getLang('homepage')), ' title="' . htmlentities(tpl_getLang('homepage')) . '"', true) . '</li>'.NL;
343		echo $prefix . DOKU_TAB . DOKU_TAB . '<li>' . tpl_pagelink(':'.$conf['start'], null, true) . '</li>'.NL;
344	} else {
345		echo $prefix . DOKU_TAB . DOKU_TAB . '<li class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</li>'.NL;
346	}
347
348	// print intermediate namespace links
349	$page = '';
350	for($i = 0; $i < $count - 1; $i++) {
351		$part = $parts[$i];
352		$page .= $part . ':';
353
354		if ($i == $count-2 && $isdir)  break; // Skip last if it is an index page
355
356		echo $prefix . DOKU_TAB . DOKU_TAB . '<li>' . tpl_pagelink($page, null, true) . '</li>'.NL;
357	}
358
359	// chould the current page be included in the listing?
360	$trail = tpl_getConf('navtrail');
361
362	if ($trail !== 'none' && $trail !== '') {
363
364		echo $prefix . DOKU_TAB . DOKU_TAB . '<li class="current">';
365		if ($trail == 'text') {
366			echo tpl_pagetitle($page . $parts[$count-1], true);
367		} else if ($trail == 'link') {
368			echo tpl_pagelink($page . $parts[$count-1], null, true);
369		}
370		echo '</li>'.NL;
371	}
372
373	echo $prefix . DOKU_TAB . '</ol>'.NL;
374	echo $prefix . '</nav>'.NL;
375}
376
377/**
378 * My implementation of the basic userinfo (in the global banner)
379 *
380 *
381 * @author Sascha Leib <sascha@leib.be>
382 *
383 * @param  string $prefix to be added before each line
384 *
385 * @return void
386 */
387function my_userinfo($prefix = '') {
388	global $lang;
389	global $INPUT;
390
391	// add login/logout button:
392	$items = (new \dokuwiki\Menu\UserMenu())->getItems();
393	foreach($items as $it) {
394		$typ = $it->getType();
395
396		if ($typ === 'profile') { // special case for user profile:
397
398			echo $prefix . '<li class="action profile"><span class="sronly">' . $lang['loggedinas'] .
399				' </span><a href="' . htmlentities($it->getLink()) . '" title="' . $it->getTitle() . '">' .
400				userlink() . "</a></li>".NL;
401
402		} else {
403
404			echo $prefix . "<li class=\"action $typ\">" . '<a href="' . htmlentities($it->getLink()) .
405				'" title="' . $it->getTitle() . '">' . ($typ === 'profile'? userlink() : $it->getLabel() ) .
406				'</a></li>'.NL;
407		}
408	}
409}
410
411/**
412 *Inserts a cleaner version of the TOC
413 *
414 * This is an update of the original function that renders the TOC directly.
415 *
416 * @author Sascha Leib <sascha@leib.be>
417 * @author Andreas Gohr <andi@splitbrain.org>
418 *
419 * @param  string $prefix to be added before each line
420 *
421 * @return void
422 */
423function my_toc($prefix = '') {
424	global $TOC;
425	global $ACT;
426	global $ID;
427	global $REV;
428	global $INFO;
429	global $conf;
430	global $lang;
431	$toc = array();
432
433	if(is_array($TOC)) {
434		// if a TOC was prepared in global scope, always use it
435		$toc = $TOC;
436	} elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
437		// get TOC from metadata, render if neccessary
438		$meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
439		if(isset($meta['internal']['toc'])) {
440			$tocok = $meta['internal']['toc'];
441		} else {
442			$tocok = true;
443		}
444		$toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
445		if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
446			$toc = array();
447		}
448	} elseif($ACT == 'admin') {
449		// try to load admin plugin TOC
450		/** @var $plugin AdminPlugin */
451		if ($plugin = plugin_getRequestAdminPlugin()) {
452			$toc = $plugin->getTOC();
453			$TOC = $toc; // avoid later rebuild
454		}
455	}
456
457	/* Build the hierarchical list of headline links: */
458	if (count($toc) >= intval($conf['tocminheads'])) {
459		echo $prefix . '<aside id="toc" class="toggle hide">'.NL;
460		echo $prefix . DOKU_TAB . '<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>'.NL;
461		echo $prefix . DOKU_TAB . '<nav id="toc-menu" class="tg_content" role="menu" aria-labelledby="toc-menubutton">';
462		$level = 0;
463		foreach($toc as $it) {
464
465			$nl = intval($it['level']);
466			$cp = ($nl <=> $level);
467
468			if ($cp > 0) {
469				while ($level < $nl) {
470					echo DOKU_LF . $prefix . str_repeat(DOKU_TAB, $level*2 + 2) . '<ol>'.NL;
471					$level++;
472				}
473			} else if ($cp < 0) {
474				while ($level > $nl) {
475					echo DOKU_LF . $prefix . str_repeat(DOKU_TAB, $level*2) . '</ol>'.NL;
476					echo $prefix . str_repeat(DOKU_TAB, $level*2-1) . '</li>'.NL;
477					$level--;
478				}
479			} else {
480				echo '</li>'.NL;
481			}
482
483			$href = ( array_key_exists('link', $it ) ? $it['link'] : '' ) . ( array_key_exists('hid', $it) && $it['hid'] !== '' ? '#' . $it['hid'] : '' );
484
485			echo $prefix . str_repeat(DOKU_TAB, $nl*2 + 1) . '<li role="presentation">' . "<a role=\"menuitem\" href=\"{$href}\">" . htmlentities($it['title']) . '</a>';
486			$level = $nl;
487		}
488
489		for ($i = $level-1; $i > 0; $i--) {
490			echo '</li>'.NL;
491			echo $prefix . str_repeat(DOKU_TAB, $i*2 + 1) . '</ol>';
492		}
493
494		echo '</li>'.NL;
495		echo $prefix . DOKU_TAB . DOKU_TAB . '</ol>'.NL;
496		echo $prefix . DOKU_TAB . '</nav>'.NL;
497		echo $prefix . '</aside>'.NL;
498	}
499}
500
501/**
502 * Print last change date
503 *
504 * @author Sascha Leib <sascha@leib.be>
505 *
506 * @param  string $prefix to be added before each line
507 *
508 * @return void
509 */
510function my_lastchange($prefix = '') {
511
512	global $lang;
513	global $INFO;
514	global $conf;
515	global $_REQUEST;
516
517	$lastmod = $INFO['lastmod'];
518	$doAdmin = (array_key_exists('do', $_REQUEST) && $_REQUEST['do'] == 'admin');
519
520	if (!$doAdmin && intval($lastmod) > 0) { // is valid date?
521
522		$longDate = htmlentities(dformat($lastmod));
523
524		echo $prefix . '<p class="docInfo">'.NL;
525		echo $prefix . DOKU_TAB . '<bdi>' . $lang['lastmod'] . '</bdi>'.NL;
526		echo $prefix . DOKU_TAB . '<time datetime="' . date('c', $lastmod) . '" title="' . $longDate . '"><span class="print-only">' . $longDate . '</span><span class="noprint">' . datetime_h($lastmod) . "</span></time>".NL;
527		echo $prefix . '</p>'.NL;
528	}
529
530	/* user name for last change (is this really interesting to the visitor?) */
531	/* echo $prefix .'<span class="editorname" tabindex="0">' . $lang['by'] . ' <bdi>' . editorinfo($INFO['editor']) . '</bdi></span>'.NL; */
532}
533
534/**
535 * Returns a description list of the metatags of the current image
536 *
537 * @return string html of description list
538 */
539function my_img_meta($prefix = '') {
540	global $lang;
541
542	$format = '%Y-%m-%dT%T%z';	/* e.g. 2021-21-05T16:45:12+02:00 */
543
544	$tags = tpl_get_img_meta();
545
546	foreach($tags as $tag) {
547		$label = $lang[$tag['langkey']];
548		if(!$label) $label = $tag['langkey'] . ':';
549
550		echo $prefix . "<tr><th>{$label}</th><td>";
551		if ($tag['type'] == 'date') {
552			echo '<time datetime="' . strftime($format, $tag['value']) . '">' . dformat($tag['value']) . '</time>';
553		} else {
554			echo hsc($tag['value']);
555		}
556		echo '</td></tr>'.NL;
557	}
558}
559
560/**
561 * Creates the Site logo image link
562 *
563 */
564function my_sitelogo() {
565	global $conf;
566
567	// get logo either out of the template images folder or data/media folder
568	$logoSize = array();
569	$logo = tpl_getMediaFile(array(':logo.svg', ':wiki:logo.svg', ':logo.png', ':wiki:logo.png', 'images/sitelogo.svg'), false, $logoSize);
570	tpl_link( my_homelink(),
571		"<img src=\"{$logo}\" " . (is_array($logoSize) && array_key_exists(3, $logoSize) ? $logoSize[3] : '') . ' alt="' . htmlentities($conf['title']) . '" />', 'accesskey="h" title="[H]" class="logo"');
572}
573
574/**
575 * Creates the various favicon and similar links:
576 *
577 * @param  string $color overwrite the theme color.
578 *
579 * @return null
580 */
581function my_favicons($color = null) {
582
583	$logoSize = array();
584
585	/* Theme color:
586	if ($color == null) {
587
588		// get the style config:
589		$styleUtil = new \dokuwiki\StyleUtils();
590		$styleIni = $styleUtil->cssStyleini();
591		$replacements = $styleIni['replacements'];
592		$color = $replacements['__theme_color__'];
593
594		if ($color== null) { $color = '#2b73b7'; }
595	}
596	echo DOKU_TAB . "<meta name=\"theme-color\" content=\"" . $color . "\" />".NL; */
597
598	// get the favicon:
599	$link = tpl_getMediaFile(array(':favicon.ico', ':favicon.png', ':favicon.svg', ':wiki:favicon.ico', ':wiki:favicon.png', ':wiki:favicon.svg'), false, $logoSize);
600	echo DOKU_TAB . "<link rel=\"icon\" href=\"{$link}\" />".NL;
601
602	// Apple Touch Icon
603	$logoSize = array();
604	$link = tpl_getMediaFile(array(':apple-touch-icon.png', ':wiki:apple-touch-icon.png', 'images/apple-touch-icon.png'), false, $logoSize);
605	echo DOKU_TAB . "<link rel=\"apple-touch-icon\" href=\"{$link}\" />".NL;
606
607}
608
609/**
610 * inserts the Cookies banner, if appropriate.
611 * This is based on Michal Koutny’s "cookielaw" plugin
612 *
613 * @param  string $prefix to be added before each line
614 */
615function my_cookiebanner($prefix = '') {
616
617	// get the configuration settings:
618	$msg = tpl_getConf('cookiemsg', '(no message configured)');
619	$position = tpl_getConf('cookiepos', 'bottom');
620	$link = tpl_getConf('cookielink', 'about:cookies');
621
622	// if the cookie is already set or position is set to hide, do nothing.
623	if ( isset($_COOKIE['cookielaw']) or $position == 'hide') {
624		return;
625	}
626
627	// define the cookie icon:
628	$svg = '<svg width="100%" height="100%" viewBox="0 0 64 64" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"><path d="M17.272,19.443c6.035,-0.582 10.759,-5.673 10.759,-11.858c-0,-1.843 -0.42,-3.588 -1.168,-5.146c1.668,-0.289 3.385,-0.439 5.137,-0.439c16.557,-0 30,13.443 30,30c0,16.557 -13.443,30 -30,30c-16.557,-0 -30,-13.443 -30,-30c0,-0.925 0.042,-1.84 0.124,-2.743c1.061,0.31 2.183,0.476 3.345,0.476c6.025,0 11.011,-4.482 11.803,-10.29Z" style="fill:#d5944b;stroke:#26251d;stroke-width:4px;"/><circle cx="17.927" cy="41.07" r="3.488" style="fill:#443017;"/><circle cx="31.33" cy="30.835" r="3.488" style="fill:#443017;"/><circle cx="32" cy="49.883" r="3.488" style="fill:#443017;"/><circle cx="43.952" cy="41.07" r="3.488" style="fill:#443017;"/><circle cx="49.092" cy="27.347" r="3.488" style="fill:#443017;"/><circle cx="38.306" cy="16.056" r="3.488" style="fill:#443017;"/></svg>';
629
630	// output the HTML code:
631	echo $prefix . "<div id=\"cookiebanner\" class=\"cb_{$position}\">".NL;
632	echo $prefix . DOKU_TAB . '<p class="cb_info">'.NL;
633	echo $prefix . DOKU_TAB . DOKU_TAB . "<span class=\"cb_icon\">{$svg}</span>".NL;
634	echo $prefix . DOKU_TAB . DOKU_TAB . "<span class=\"cb_msg\">{$msg}</span>".NL;
635	echo $prefix . DOKU_TAB . '</p>'.NL;
636	echo $prefix . DOKU_TAB . '<p class="cb_action">'.NL;
637	echo $prefix . DOKU_TAB . DOKU_TAB . '<button>' . hsc(tpl_getLang('cookie_consent')) . '</button>'.NL;
638	echo $prefix . DOKU_TAB . DOKU_TAB;
639	if ( substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://') {
640		echo "<a href=\"{$link}\" target=\"_blank\">" . hsc(tpl_getLang('cookie_linktext')) . '</a>';
641	} else {
642		tpl_pagelink($link, tpl_getLang('cookie_linktext'));
643	}
644	echo $prefix . DOKU_LF . DOKU_TAB.'</p>'.NL;
645	echo $prefix . '</div>'.NL;
646
647}
648
649/**
650 * inserts the Languages menu, if appropriate.
651 *
652 * @author Sascha Leib <sascha@leib.be>
653 * @author Andreas Gohr <andi@splitbrain.org>
654 *
655 * @param  string $prefix to be added before each line
656 * @param  string $place the location from where it is called
657 * @param  string $checkage should the age of the translation be checked?
658 */
659function my_langmenu($prefix, $place, $checkage = true) {
660
661	global $INFO;
662	global $conf;
663
664	// the current page language:
665	$lang = $conf['lang'];
666
667	/* get the config option: */
668	$config = tpl_getConf('langmenu', 'none');
669
670	/* only shw the menu if this is called from the right place */
671	if ($config == $place) {
672
673		/* collect the output: */
674		$out = '';
675
676		/* try to load the plugin: */
677		$trans = plugin_load('helper','translation');
678
679		/* plugin available? */
680		if ($trans) {
681
682			if (!$trans->istranslatable($INFO['id'])) return '';
683			if ($checkage) $trans->checkage();
684
685			[, $idpart] = $trans->getTransParts($INFO['id']);
686
687			$asMenu = ($place == 'tb'); // display as menu only in toolbar!
688
689			$out .= $prefix . "<div id=\"{$place}Languages\">".NL;
690
691			// create the header item
692
693			if ($asMenu) { // show as menu (toolbar)
694
695				// get the language name (in the local language)
696				$langName = htmlentities($trans->getLocalName($lang));
697
698				/* prepare the menu icon (note that the language code and name are embedded! */
699				$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>";
700
701				// prepare the menu button:
702				$out .= $prefix . DOKU_TAB . '<button id="langButton" aria-haspopup="menu" aria-controls="langMenuWrapper" aria-expanded="false">'.NL;
703				$out .= $prefix . DOKU_TAB . DOKU_TAB . $svg . NL;
704				$out .= $prefix . DOKU_TAB . DOKU_TAB . '<span class="sronly">' . $trans->getLang('translations') . '</span>'.NL;
705				$out .= $prefix . DOKU_TAB . '</button>'.NL;
706
707			} else { // show as list (sidebar)
708
709				// show title (only if the option is configured)
710				if (isset($trans->opts['title'])) {
711
712					// get a localized headline text
713					$headline = tpl_getLang('languages');
714
715					// should a link to the about page be added?
716					$about = $trans->getConf('about'); /* get the about link */
717					if ($about !== '') {
718						/* localized about links? */
719						if ($trans->getConf('localabout')) {
720							[, $aboutid] = $trans->getTransParts($about);
721							[$about, ] = $trans->buildTransID($lang, $aboutid);
722							$about = cleanID($about);
723						}
724						// build the link:
725						$headline = html_wikilink($about, $headline);
726					}
727					/* complete the headline */
728					$out .= $prefix . DOKU_TAB . "<h3><span>{$headline}</span></h3>".NL;
729				}
730			}
731
732			/* build the menu content */
733			$out .= $prefix . DOKU_TAB . '<div id="langMenu' . ( $asMenu ? 'Wrapper" role="menu" style="display: none"' : 'List"') . '>'.NL;
734			$out .= $prefix . DOKU_TAB . DOKU_TAB . '<ul id="lang' . ( $asMenu ? 'Menu" role="group"' : 'List"' ) . '>'.NL;
735
736			// loop over each language and add it to the menu:
737			foreach ($trans->translations as $t) {
738				$l = ( $t !== '' ? $t : $lang );
739
740				[$trg, $lng] = $trans->buildTransID($t, $idpart);
741				$trg = cleanID($trg);
742				$exists = page_exists($trg, '', false);
743				$filter = tpl_getConf('langfilter', 'all');
744
745				/* only show if translation exists? */
746				if ($exists || $filter === 'all') {
747					$class = 'wikilink' . ( $exists ? '1' : '2');
748					$link = wl($trg);
749					$current = ($lng == $lang);
750
751					$out .= $prefix . DOKU_TAB . DOKU_TAB . DOKU_TAB .'<li' . ( $asMenu ? ' role="presentation"' : '' ). ( $current ? ' class="current"' : '' ) . '>'.NL;
752					$out .= $prefix . DOKU_TAB . DOKU_TAB . DOKU_TAB . DOKU_TAB . "<a href=\"{$link}\" lang=\"{$lng}\" hreflang=\"{$lng}\" class=\"{$class}\"" . ( $asMenu ? ' role="menuitem"' : '' ) . '><bdi>'. $trans->getLocalName($lng) . '</bdi></a>'.NL;
753					$out .= $prefix . DOKU_TAB . DOKU_TAB . DOKU_TAB . '</li>'.NL;
754				}
755			}
756
757			// close all open elements:
758			$out .= $prefix . DOKU_TAB . DOKU_TAB . '</ul>'.NL
759				 .	$prefix . DOKU_TAB . '</div>'.NL
760				 .	$prefix . '</div>'.NL;
761		}
762		echo $out; // done.
763	}
764}