xref: /template/mikio/mikio.php (revision 30b82348bafc9493f03435da3bdd3eeda529d793)
1<?php
2
3/**
4 * DokuWiki Mikio Template
5 *
6 * @link    http://dokuwiki.org/template:mikio
7 * @author  James Collins <james.collins@outlook.com.au>
8 * @license GPLv2 (http://www.gnu.org/licenses/gpl-2.0.html)
9 */
10
11namespace dokuwiki\template\mikio;
12
13if (defined('DOKU_INC') === false) {
14    die();
15}
16
17require_once('icons/icons.php');
18require_once('inc/simple_html_dom.php');
19
20class Template
21{
22    /**
23     * @var string Template directory path from local FS.
24     */
25    public $tplDir  = '';
26
27    /**
28     * @var string Template directory path from web.
29     */
30    public $baseDir = '';
31
32    /**
33     * @var array Array of Javascript files to include in footer.
34     */
35    public $footerScript = [];
36
37    /**
38     * @var boolean Ignore LESS files.
39     */
40    public $lessIgnored = false;
41
42
43    /**
44     * Class constructor
45     */
46    public function __construct()
47    {
48        $this->tplDir  = tpl_incdir();
49        $this->baseDir = tpl_basedir();
50
51        $this->registerHooks();
52    }
53
54
55    /**
56     * Returns the instance of the class
57     *
58     * @return  Template        class instance
59     */
60    public static function getInstance()
61    {
62        static $instance = null;
63
64        if (empty($instance) === true) {
65            $instance = new Template();
66        }
67
68        return $instance;
69    }
70
71
72    /**
73     * Register the themes hooks into Dokuwiki
74     *
75     * @return void
76     */
77    private function registerHooks()
78    {
79        global $EVENT_HANDLER;
80
81        $events_dispatcher = [
82            'TPL_METAHEADER_OUTPUT'     => 'metaheadersHandler'
83        ];
84
85        foreach ($events_dispatcher as $event => $method) {
86            $EVENT_HANDLER->register_hook($event, 'BEFORE', $this, $method);
87        }
88    }
89
90
91    /**
92     * Meta handler hook for DokuWiki
93     *
94     * @param   \Doku_Event $event DokuWiki Event.
95     * @return  void
96     */
97    public function metaHeadersHandler(\Doku_Event $event)
98    {
99        global $MIKIO_ICONS;
100        global $conf;
101
102        $this->includePage('theme', false, true);
103
104        $stylesheets    = [];
105        $scripts        = [];
106
107        if (empty($this->getConf('customTheme')) === false) {
108            if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.less') === true) {
109                $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.less';
110            } else {
111                if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.css') === true) {
112                    $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.css';
113                }
114            }
115            if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/script.js') === true) {
116                $scripts[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/script.js';
117            }
118        }
119
120        if (is_array($MIKIO_ICONS) === true && empty($this->getConf('iconTag', 'icon')) === false) {
121            $icons = [];
122            foreach ($MIKIO_ICONS as $icon) {
123                if (isset($icon['name']) === true && isset($icon['css']) === true && isset($icon['insert']) === true) {
124                    $icons[] = $icon;
125
126                    if (empty($icon['css']) === false) {
127                        if (strpos($icon['css'], '//') === false) {
128                            $stylesheets[] = $this->baseDir . 'icons/' . $icon['css'];
129                        } else {
130                            $stylesheets[] = $icon['css'];
131                        }
132                    }
133                }
134            }
135            $MIKIO_ICONS = $icons;
136        } else {
137            $MIKIO_ICONS = [];
138        }
139
140        $scripts[] = $this->baseDir . 'assets/mikio-typeahead.js';
141        $scripts[] = $this->baseDir . 'assets/mikio.js';
142
143        if ($this->getConf('useLESS') === true) {
144            $stylesheets[] = $this->baseDir . 'assets/mikio.less';
145        } else {
146            $stylesheets[] = $this->baseDir . 'assets/mikio.css';
147        }
148
149
150        $set = [];
151        foreach ($stylesheets as $style) {
152            if (in_array($style, $set) === false) {
153                if (strcasecmp(substr($style, -5), '.less') === 0 && $this->getConf('useLESS') === true) {
154                    $style = $this->baseDir . 'css.php?css=' . str_replace($this->baseDir, '', $style);
155                }
156
157                array_unshift($event->data['link'], [
158                    'type' => 'text/css',
159                    'rel'  => 'stylesheet',
160                    'href' => $style
161                ]);
162            }
163            $set[] = $style;
164        }
165
166        $set = [];
167        foreach ($scripts as $script) {
168            if (in_array($script, $set) === false) {
169                $script_params = [
170                    'type'  => 'text/javascript',
171                    '_data' => '',
172                    'src'   => $script
173                ];
174
175                // equal to or greator than hogfather
176                if ($this->dwVersionNumber() >= 20200729) {
177                    // greator than hogfather - defer always on
178                    if ($this->dwVersionNumber() >= 20200729) {
179                        $script_params += ['defer' => 'defer'];
180                    } else {
181                        // hogfather - defer always on unless $conf['defer_js'] is false
182                        if (array_key_exists('defer_js', $conf) === false || $conf['defer_js'] === true) {
183                            $script_params += ['defer' => 'defer'];
184                        }
185                    }
186                }
187
188                $event->data['script'][] = $script_params;
189            }//end if
190            $set[] = $script;
191        }//end foreach
192    }
193
194
195    /**
196     * Print or return the footer meta data
197     *
198     * @param   boolean $print Print the data to buffer.
199     * @return  string         HTML footer meta data
200     */
201    public function includeFooterMeta(bool $print = true)
202    {
203        $html = '';
204
205        if (count($this->footerScript) > 0) {
206            $html .= '<script type="text/javascript">function mikioFooterRun() {';
207            foreach ($this->footerScript as $script) {
208                $html .= $script . ';';
209            }
210            $html .= '}</script>';
211        }
212
213
214        if ($print === true) {
215            echo $html;
216        }
217        return $html;
218    }
219
220
221    // phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
222
223
224    /**
225     * Retreive and parse theme configuration options
226     *
227     * @param   string $key     The configuration key to retreive.
228     * @param   mixed  $default If key doesn't exist, return this value.
229     * @return  mixed           parsed value of configuration
230     */
231    public function getConf(string $key, $default = false)
232    {
233        $value = tpl_getConf($key, $default);
234
235        $data = [
236            ['keys' => ['navbarDWMenuType'],                'type' => 'choice',
237                'values' => ['both', 'icons', 'text']
238            ],
239            ['keys' => ['navbarDWMenuCombine'],             'type' => 'choice',
240                'values' => ['combine', 'seperate', 'dropdown']
241            ],
242            ['keys' => ['navbarPosLeft', 'navbarPosMiddle', 'navbarPosRight'],
243                'type' => 'choice',
244                'values' => ['none', 'custom', 'search', 'dokuwiki'],
245                'default' => [
246                    'navbarPosLeft' => 'none',
247                    'navbarPosMiddle' => 'search',
248                    'navbarPosRight' => 'dokuwiki'
249                ]
250            ],
251            ['keys' => ['navbarItemShowCreate', 'navbarItemShowShow', 'navbarItemShowRevs', 'navbarItemShowBacklink',
252                'navbarItemShowRecent', 'navbarItemShowMedia', 'navbarItemShowIndex', 'navbarItemShowProfile',
253                'navbarItemShowAdmin'
254            ],
255                'type' => 'choice',
256                'values' => ['always', 'logged in', 'logged out', 'never']
257            ],
258            ['keys' => ['navbarItemShowLogin', 'navbarItemShowLogout'],
259                'type' => 'choice',
260                'values' => ['always', 'never']
261            ],
262            ['keys' => ['searchButton'],                    'type' => 'choice',
263                'values' => ['icon', 'text']
264            ],
265            ['keys' => ['breadcrumbPosition', 'youareherePosition'],
266                'type' => 'choice',
267                'values' => ['top', 'hero', 'page', 'none']
268            ],
269            ['keys' => ['youarehereHome'],                  'type' => 'choice',
270                'values' => ['page title', 'home', 'icon', 'none']
271            ],
272            ['keys' => ['sidebarLeftRow1', 'sidebarLeftRow2', 'sidebarLeftRow3', 'sidebarLeftRow4'],
273                'type' => 'choice',
274                'values' => ['none', 'logged in user', 'search', 'content', 'tags'],
275                'default' => [
276                    'sidebarLeftRow1' => 'logged in user',
277                    'sidebarLeftRow2' => 'search',
278                    'sidebarLeftRow3' => 'content'
279                ]
280            ],
281            ['keys' => ['pageToolsFloating', 'pageToolsFooter'],
282                'type' => 'choice',
283                'values' => ['always', 'none', 'page editors']
284            ],
285            ['keys' => ['pageToolsShowCreate', 'pageToolsShowEdit', 'pageToolsShowRevs', 'pageToolsShowBacklink',
286                'pageToolsShowTop'
287            ],
288                'type' => 'choice',
289                'values' => ['always', 'logged in', 'logged out', 'never']
290            ],
291            ['keys' => ['showNotifications'],               'type' => 'choice',
292                'values' => ['admin', 'always', 'none']
293            ],
294            ['keys' => ['licenseType'],                     'type' => 'choice',
295                'values' => ['badge', 'button', 'none']
296            ],
297            ['keys' => ['navbarUseTitleIcon'],              'type' => 'bool'],
298            ['keys' => ['navbarUseTitleText'],              'type' => 'bool'],
299            ['keys' => ['navbarUseTaglineText'],            'type' => 'bool'],
300            ['keys' => ['navbarShowSub'],                   'type' => 'bool'],
301            ['keys' => ['heroTitle'],                       'type' => 'bool'],
302            ['keys' => ['heroImagePropagation'],            'type' => 'bool'],
303            ['keys' => ['breadcrumbPrefix'],                'type' => 'bool'],
304            ['keys' => ['breadcrumbSep'],                   'type' => 'bool'],
305            ['keys' => ['youareherePrefix'],                'type' => 'bool'],
306            ['keys' => ['youarehereSep'],                   'type' => 'bool'],
307            ['keys' => ['sidebarShowLeft'],                 'type' => 'bool'],
308            ['keys' => ['sidebarShowRight'],                'type' => 'bool'],
309            ['keys' => ['tocFull'],                         'type' => 'bool'],
310            ['keys' => ['footerSearch'],                    'type' => 'bool'],
311            ['keys' => ['licenseImageOnly'],                'type' => 'bool'],
312            ['keys' => ['includePageUseACL'],               'type' => 'bool'],
313            ['keys' => ['includePagePropagate'],            'type' => 'bool'],
314            ['keys' => ['youarehereHideHome'],              'type' => 'bool'],
315            ['keys' => ['tagsConsolidate'],                 'type' => 'bool'],
316            ['keys' => ['footerInPage'],                    'type' => 'bool'],
317            ['keys' => ['sidebarMobileDefaultCollapse'],    'type' => 'bool'],
318            ['keys' => ['sidebarAlwaysShowLeft'],           'type' => 'bool'],
319            ['keys' => ['sidebarAlwaysShowRight'],          'type' => 'bool'],
320            ['keys' => ['searchUseTypeahead'],              'type' => 'bool'],
321            ['keys' => ['showLightDark'],                   'type' => 'bool'],
322            ['keys' => ['youarehereShowLast'],              'type' => 'int'],
323
324            ['keys' => ['iconTag'],                         'type' => 'string'],
325            ['keys' => ['customTheme'],                     'type' => 'string'],
326            ['keys' => ['navbarCustomMenuText'],            'type' => 'string'],
327            ['keys' => ['breadcrumbPrefixText'],            'type' => 'string'],
328            ['keys' => ['breadcrumbSepText'],               'type' => 'string'],
329            ['keys' => ['youareherePrefixText'],            'type' => 'string'],
330            ['keys' => ['youarehereSepText'],               'type' => 'string'],
331            ['keys' => ['footerCustomMenuText'],            'type' => 'string'],
332            ['keys' => ['brandURLGuest'],                   'type' => 'string'],
333            ['keys' => ['brandURLUser'],                    'type' => 'string'],
334
335            ['keys' => ['useLESS'],                         'type' => 'less'],
336        ];
337
338        foreach ($data as $row) {
339            // does not check case....
340            if (in_array($key, $row['keys']) === true) {
341                if (array_key_exists('type', $row) === true) {
342                    switch ($row['type']) {
343                        case 'bool':
344                            return (bool) $value;
345                        case 'int':
346                            return (int) $value;
347                        case 'string':
348                            return $value;
349                        case 'less':
350                            $value = (bool) $value;
351                            $lessAvailable = true;
352
353                            // check for less library
354                            $lesscLib = '../../../vendor/marcusschwarz/lesserphp/lessc.inc.php';
355                            if (file_exists($lesscLib) === false) {
356                                $lesscLib = $_SERVER['DOCUMENT_ROOT'] . '/vendor/marcusschwarz/lesserphp/lessc.inc.php';
357                            }
358                            if (file_exists($lesscLib) === false) {
359                                $lesscLib = '../../../../../app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php';
360                            }
361                            if (file_exists($lesscLib) === false) {
362                                $lesscLib = $_SERVER['DOCUMENT_ROOT'] .
363                                    '/app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php';
364                            }
365                            if (file_exists($lesscLib) === false) {
366                                $lessAvailable = false;
367                            }
368
369                            // check for ctype extensions
370                            if (function_exists('ctype_digit') === false) {
371                                $lessAvailable = false;
372                            }
373
374                            if ($value === true && $lessAvailable === false) {
375                                $this->lessIgnored = true;
376                                $value = false;
377                            }
378
379                            return $value;
380                    }//end switch
381                }//end if
382
383                if (in_array($value, $row['values']) === true) {
384                    return $value;
385                }
386
387                if (array_key_exists('default', $row) === true) {
388                    if (is_array($row['default']) === true) {
389                        if (array_key_exists($key, $row['default']) === true) {
390                            return $row['default'][$key];
391                        }
392                    } else {
393                        return $row['default'];
394                    }
395                }
396
397                return reset($row['values']);
398            }//end if
399        }//end foreach
400
401        return $value;
402    }
403
404
405    // phpcs:enable
406
407
408    /**
409     * Check if a page exist in directory or namespace
410     *
411     * @param   string $page Page/namespace to search.
412     * @return  boolean      if page exists
413     */
414    public function pageExists(string $page)
415    {
416        ob_start();
417        tpl_includeFile($page . '.html');
418        $html = ob_get_contents();
419        ob_end_clean();
420
421        if (empty($html) === false) {
422            return true;
423        }
424
425        $useACL = $this->getConf('includePageUseACL');
426        $propagate = $this->getConf('includePagePropagate');
427
428        if ($propagate === true) {
429            if (page_findnearest($page, $useACL) !== false) {
430                return true;
431            }
432        } elseif ($useACL === true && auth_quickaclcheck($page) !== AUTH_NONE) {
433            return true;
434        }
435
436        return false;
437    }
438
439
440    /**
441     * Print or return page from directory or namespace
442     *
443     * @param   string  $page         Page/namespace to include.
444     * @param   boolean $print        Print content.
445     * @param   boolean $parse        Parse content before printing/returning.
446     * @param   string  $classWrapper Wrap page in a div with class.
447     * @return  string                contents of page found
448     */
449    public function includePage(string $page, bool $print = true, bool $parse = true, string $classWrapper = '')
450    {
451        ob_start();
452        tpl_includeFile($page . '.html');
453        $html = ob_get_contents();
454        ob_end_clean();
455
456        if (empty($html) === true) {
457            $useACL = $this->getConf('includePageUseACL');
458            $propagate = $this->getConf('includePagePropagate');
459            $html = '';
460
461            $html = tpl_include_page($page, false, $propagate, $useACL);
462        }
463
464        if (empty($html) === false && $parse === true) {
465            $html = $this->parseContent($html);
466        }
467
468        if (empty($classWrapper) === false && empty($html) === false) {
469            $html = '<div class="' . $classWrapper . '">' . $html . '</div>';
470        }
471
472        if ($print === true) {
473            echo $html;
474        }
475        return $html;
476    }
477
478
479    /**
480     * Print or return logged in user information
481     *
482     * @param   boolean $print Print content.
483     * @return  string         user information
484     */
485    public function includeLoggedIn(bool $print = true)
486    {
487        $html = '';
488
489        if (empty($_SERVER['REMOTE_USER']) === false) {
490            $html .= '<div class="mikio-user-info">';
491            ob_start();
492            tpl_userinfo();
493            $html .= ob_get_contents();
494            ob_end_clean();
495            $html .= '</div>';
496        }
497
498        if ($print === true) {
499            echo $html;
500        }
501        return $html;
502    }
503
504
505    /**
506     * Print or return DokuWiki Menu
507     *
508     * @param   boolean $print Print content.
509     * @return  string         contents of the menu
510     */
511    public function includeDWMenu(bool $print = true)
512    {
513        global $lang;
514        global $USERINFO;
515
516        $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0);
517        $html = '<ul class="mikio-nav">';
518
519        $pageToolsMenu = [];
520        $siteToolsMenu = [];
521        $userToolsMenu = [];
522
523        $showIcons  = ($this->getConf('navbarDWMenuType') != 'text');
524        $showText   = ($this->getConf('navbarDWMenuType') != 'icons');
525        $isDropDown = ($this->getConf('navbarDWMenuCombine') != 'seperate');
526
527        $items = (new \dokuwiki\Menu\PageMenu())->getItems();
528        foreach ($items as $item) {
529            if ($item->getType() !== 'top') {
530                $itemHtml = '';
531
532                $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType()));
533                if (
534                    $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
535                    (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) ||
536                    (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false))
537                ) {
538                    $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') .
539                        ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">';
540                    if ($showIcons === true) {
541                        $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
542                    }
543                    if ($showText === true || $isDropDown === true) {
544                        $itemHtml .= '<span>' . $item->getLabel() . '</span>';
545                    }
546                    $itemHtml .= '</a>';
547
548                    $pageToolsMenu[] = $itemHtml;
549                }
550            }//end if
551        }//end foreach
552
553        $items = (new \dokuwiki\Menu\SiteMenu())->getItems('action');
554        foreach ($items as $item) {
555            $itemHtml = '';
556
557            $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType()));
558            if (
559                $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
560                (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) ||
561                (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false))
562            ) {
563                $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . ' ' .
564                    $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">';
565                if ($showIcons === true) {
566                    $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
567                }
568                if ($showText === true || $isDropDown === true) {
569                    $itemHtml .= '<span>' . $item->getLabel() . '</span>';
570                }
571                $itemHtml .= '</a>';
572
573                $siteToolsMenu[] = $itemHtml;
574            }
575        }//end foreach
576
577        $items = (new \dokuwiki\Menu\UserMenu())->getItems('action');
578        foreach ($items as $item) {
579            $itemHtml = '';
580
581            $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType()));
582            if (
583                $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
584                (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) ||
585                (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false))
586            ) {
587                $itemHtml .= '<a class="mikio-nav-link' . ($isDropDown === true ? ' mikio-dropdown-item' : '') . ' ' .
588                $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">';
589                if ($showIcons === true) {
590                    $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
591                }
592                if ($showText === true || $isDropDown === true) {
593                    $itemHtml .= '<span>' . $item->getLabel() . '</span>';
594                }
595                $itemHtml .= '</a>';
596
597                $userToolsMenu[] = $itemHtml;
598            }
599        }//end foreach
600
601
602        switch ($this->getConf('navbarDWMenuCombine')) {
603            case 'dropdown':
604                $html .= '<li id="dokuwiki__pagetools" class="mikio-nav-dropdown">';
605                $html .= '<a id="mikio_dropdown_pagetools" class="nav-link dropdown-toggle" href="#" role="button"
606data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
607                ($showIcons === true ? $this->mikioInlineIcon('file') : '') .
608                ($showText === true ? $lang['page_tools'] : '<span class="mikio-small-only">' . $lang['page_tools'] .
609                '</span>') . '</a>';
610                $html .= '<div class="mikio-dropdown closed">';
611
612                foreach ($pageToolsMenu as $item) {
613                    $html .= $item;
614                }
615
616                $html .= '</div>';
617                $html .= '</li>';
618
619                $html .= '<li id="dokuwiki__sitetools" class="mikio-nav-dropdown">';
620                $html .= '<a id="mikio_dropdown_sitetools" class="nav-link dropdown-toggle" href="#" role="button"
621data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
622                    ($showIcons === true ? $this->mikioInlineIcon('gear') : '') .
623                    ($showText === true ? $lang['site_tools'] : '<span class="mikio-small-only">' .
624                    $lang['site_tools'] . '</span>') . '</a>';
625                $html .= '<div class="mikio-dropdown closed">';
626
627                foreach ($siteToolsMenu as $item) {
628                    $html .= $item;
629                }
630
631                $html .= '</div>';
632                $html .= '</li>';
633
634                $html .= '<li id="dokuwiki__usertools" class="mikio-nav-dropdown">';
635                $html .= '<a id="mikio_dropdown_usertools" class="nav-link dropdown-toggle" href="#" role="button"
636data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
637                    ($showIcons === true ? $this->mikioInlineIcon('user') : '') .
638                    ($showText === true ? $lang['user_tools'] : '<span class="mikio-small-only">' .
639                    $lang['user_tools'] . '</span>') . '</a>';
640                $html .= '<div class="mikio-dropdown closed">';
641
642                foreach ($userToolsMenu as $item) {
643                    $html .= $item;
644                }
645
646                $html .= '</div>';
647                $html .= '</li>';
648
649                break;
650
651            case 'combine':
652                $html .= '<li class="mikio-nav-dropdown">';
653                $html .= '<a class="mikio-nav-link" href="#">' .
654                    ($showIcons === true ? $this->mikioInlineIcon('wrench') : '') .
655                    ($showText === true ? tpl_getLang('tools-menu') : '<span class="mikio-small-only">' .
656                    tpl_getLang('tools-menu') . '</span>') . '</a>';
657                $html .= '<div class="mikio-dropdown closed">';
658
659                $html .= '<h6 class="mikio-dropdown-header">' . $lang['page_tools'] . '</h6>';
660                foreach ($pageToolsMenu as $item) {
661                    $html .= $item;
662                }
663
664                $html .= '<div class="mikio-dropdown-divider"></div>';
665                $html .= '<h6 class="mikio-dropdown-header">' . $lang['site_tools'] . '</h6>';
666                foreach ($siteToolsMenu as $item) {
667                    $html .= $item;
668                }
669
670                $html .= '<div class="mikio-dropdown-divider"></div>';
671                $html .= '<h6 class="mikio-dropdown-header">' . $lang['user_tools'] . '</h6>';
672                foreach ($userToolsMenu as $item) {
673                    $html .= $item;
674                }
675
676                $html .= '</div>';
677                $html .= '</li>';
678                break;
679
680            default:    // seperate
681                foreach ($siteToolsMenu as $item) {
682                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
683                }
684
685                foreach ($pageToolsMenu as $item) {
686                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
687                }
688
689                foreach ($userToolsMenu as $item) {
690                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
691                }
692
693                break;
694        }//end switch
695
696        if ($this->getConf('showLightDark') === true) {
697            $html .= '<li class="mikio-theme-mode">
698<a href="#" class="mikio-control mikio-button mikio-theme-mode-button"></a></li>';
699        }
700
701        $html .= '</ul>';
702
703        if ($print === true) {
704            echo $html;
705        }
706        return $html;
707    }
708
709
710    /**
711     * Create a nav element from a string. <uri>|<title>;
712     *
713     * @param string $str String to generate nav.
714     * @return string     nav elements generated
715     */
716    public function stringToNav(string $str)
717    {
718        $html = '';
719
720        if (empty($str) === false) {
721            $items = explode(';', $str);
722            if (count($items) > 0) {
723                $html .= '<ul class="mikio-nav">';
724                foreach ($items as $item) {
725                    $parts = explode('|', $item);
726                    if ($parts > 1) {
727                        $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' .
728                            strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) .
729                            '</a></li>';
730                    }
731                }
732                $html .= '</ul>';
733            }
734        }
735
736        return $html;
737    }
738
739    /**
740     * print or return the main navbar
741     *
742     * @param boolean $print   Print the navbar.
743     * @param boolean $showSub Include the sub navbar.
744     * @return string          generated content
745     */
746    public function includeNavbar(bool $print = true, bool $showSub = false)
747    {
748        global $conf, $USERINFO;
749
750        $homeUrl = wl();
751
752        if (plugin_isdisabled('showpageafterlogin') === false) {
753            $p = &plugin_load('action', 'showpageafterlogin');
754            if (empty($p) === false) {
755                if (is_array($USERINFO) === true && count($USERINFO) > 0) {
756                    $homeUrl = wl($p->getConf('page_after_login'));
757                }
758            }
759        } else {
760            if (is_array($USERINFO) === true && count($USERINFO) > 0) {
761                $url = $this->getConf('brandURLUser');
762                if (strlen($url) > 0) {
763                    $homeUrl = $url;
764                }
765            } else {
766                $url = $this->getConf('brandURLGuest');
767                if (strlen($url) > 0) {
768                    $homeUrl = $url;
769                }
770            }
771        }
772
773        $html = '';
774
775        $html .= '<nav class="mikio-navbar'  . (($this->getConf('stickyNavbar') === true) ? ' mikio-sticky' : '') .
776            '">';
777        $html .= '<div class="mikio-container">';
778        $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '">';
779        if ($this->getConf('navbarUseTitleIcon') === true || $this->getConf('navbarUseTitleText') === true) {
780            // Brand image
781            if ($this->getConf('navbarUseTitleIcon') === true) {
782                $logo = $this->getMediaFile('logo', false);
783                ;
784                if (empty($logo) === false) {
785                    $width = $this->getConf('navbarTitleIconWidth');
786                    $height = $this->getConf('navbarTitleIconHeight');
787                    $styles = '';
788
789                    if (strlen($width) > 0 || strlen($height) > 0) {
790                        if (ctype_digit($width) === true) {
791                            $styles .= 'max-width:' . intval($width) . 'px;';
792                        } elseif (preg_match('/^\d+(px|rem|em|%)$/', $width) === 1) {
793                            $styles .= 'max-width:' . $width . ';';
794                        } elseif (strcasecmp($width, 'none') === 0) {
795                            $styles .= 'max-width:none;';
796                        }
797
798                        if (ctype_digit($height) === true) {
799                            $styles .= 'max-height:' . intval($height) . 'px;';
800                        } elseif (preg_match('/^\d+(px|rem|em|%)$/', $height) === 1) {
801                            $styles .= 'max-height:' . $height . ';';
802                        } elseif (strcasecmp($height, 'none') === 0) {
803                            $styles .= 'max-height:none;';
804                        }
805
806                        if (strlen($styles) > 0) {
807                            $styles = ' style="' . $styles . '"';
808                        }
809                    }//end if
810
811                    $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image"' . $styles . '>';
812                }//end if
813            }//end if
814
815            // Brand title
816            if ($this->getConf('navbarUseTitleText') === true) {
817                $html .= '<div class="mikio-navbar-brand-title">';
818                $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>';
819                if ($this->getConf('navbarUseTaglineText') === true) {
820                    $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>';
821                }
822                $html .= '</div>';
823            }
824        }//end if
825        $html .= '</a>';
826        $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>';
827
828        // Menus
829        $html .= '<div class="mikio-navbar-collapse">';
830
831        $menus = [$this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'),
832            $this->getConf('navbarPosRight', 'none')
833        ];
834        foreach ($menus as $menuType) {
835            switch ($menuType) {
836                case 'custom':
837                    $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', ''));
838                    break;
839                case 'search':
840                    $html .= '<div class="mikio-nav-item">';
841                    $html .= $this->includeSearch(false);
842                    $html .= '</div>';
843                    break;
844                case 'dokuwiki':
845                    $html .= $this->includeDWMenu(false);
846                    break;
847            }
848        }
849
850        $html .= '</div>';
851        $html .= '</div>';
852        $html .= '</nav>';
853
854        // Sub Navbar
855        if ($showSub === true) {
856            $sub = $this->includePage('submenu', false);
857            if (empty($sub) === false) {
858                $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>';
859            }
860        }
861
862        if ($print === true) {
863            echo $html;
864        }
865        return $html;
866    }
867
868
869    /**
870     * Is there a sidebar
871     *
872     * @param   string $prefix Sidebar prefix to use when searching.
873     * @return  boolean        if sidebar exists
874     */
875    public function sidebarExists(string $prefix = '')
876    {
877        global $conf;
878
879        if (strcasecmp($prefix, 'left') === 0) {
880            $prefix = '';
881        }
882
883        return $this->pageExists($conf['sidebar' . $prefix]);
884    }
885
886
887    /**
888     * Print or return the sidebar content
889     *
890     * @param   string  $prefix Sidebar prefix to use when searching.
891     * @param   boolean $print  Print the generated content to the output buffer.
892     * @param   boolean $parse  Parse the content.
893     * @return  string          generated content
894     */
895    public function includeSidebar(string $prefix = '', bool $print = true, bool $parse = true)
896    {
897        global $conf, $ID;
898
899        $html = '';
900        $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix));
901        $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix));
902
903        if (empty($confPrefix) === true) {
904            $confPrefix = 'Left';
905        }
906        if (strcasecmp($prefix, 'Left') === 0) {
907            $prefix = '';
908        }
909
910        empty($sidebarPage = $conf[$prefix . 'sidebar']) === true ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar'];
911
912        if (
913            $this->getConf('sidebarShow' . $confPrefix) === true && page_findnearest($sidebarPage) !== false &&
914            p_get_metadata($ID, 'nosidebar', false) === false
915        ) {
916            $content = $this->includePage($sidebarPage . 'header', false);
917            if (empty($content) === false) {
918                $html .= '<div class="mikio-sidebar-header">' . $content . '</div>';
919            }
920
921            if (empty($prefix) === true) {
922                $rows = [$this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'),
923                    $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4')
924                ];
925
926                foreach ($rows as $row) {
927                    switch ($row) {
928                        case 'search':
929                            $html .= $this->includeSearch(false);
930                            break;
931                        case 'logged in user':
932                            $html .= $this->includeLoggedIn(false);
933                            break;
934                        case 'content':
935                            $content = $this->includePage($sidebarPage, false);
936                            if (empty($content) === false) {
937                                $html .= '<div class="mikio-sidebar-content">' . $content . '</div>';
938                            }
939                            break;
940                        case 'tags':
941                            $html .= '<div class="mikio-tags"></div>';
942                    }
943                }
944            } else {
945                $content = $this->includePage($sidebarPage, false);
946                if (empty($content) === false) {
947                    $html .= '<div class="mikio-sidebar-content">' . $content . '</div>';
948                }
949            }//end if
950
951            $content = $this->includePage($sidebarPage . 'footer', false);
952            if (empty($content) === false) {
953                $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>';
954            }
955        }//end if
956
957        if (empty($html) === true) {
958            if (empty($prefix) === true && $this->getConf('sidebarAlwaysShowLeft') === true) {
959                $html = '&nbsp;';
960            }
961            if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix)) === true) {
962                $html = '&nbsp;';
963            }
964        }
965
966        if (empty($html) === false) {
967            empty($html = '<aside class="mikio-sidebar mikio-sidebar-' . ($prefix) === true ? 'left' : $prefix) .
968                '"><a class="mikio-sidebar-toggle' .
969                ($this->getConf('sidebarMobileDefaultCollapse') === true ? ' closed' : '') . '" href="#">' .
970                tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="mikio-sidebar-collapse">' .
971                $html . '</div></aside>';
972        }
973
974        if ($parse === true) {
975            $html = $this->includeIcons($html);
976        }
977        if ($print === true) {
978            echo $html;
979        }
980        return $html;
981    }
982
983
984    /**
985     * Print or return the page tools content
986     *
987     * @param   boolean $print     Print the generated content to the output buffer.
988     * @param   boolean $includeId Include the dw__pagetools id in the element.
989     * @return  string             generated content
990     */
991    public function includePageTools(bool $print = true, bool $includeId = false)
992    {
993        global $USERINFO;
994
995        $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0);
996        $html = '';
997
998        $html .= '<nav' . ($includeId === true ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">';
999        $html .= '<ul class="tools">';
1000
1001        $items = (new \dokuwiki\Menu\PageMenu())->getItems();
1002        foreach ($items as $item) {
1003            $classes = [];
1004            $classes[] = $item->getType();
1005            $attr = $item->getLinkAttributes();
1006
1007            if (empty($attr['class']) === false) {
1008                $classes = array_merge($classes, explode(' ', $attr['class']));
1009            }
1010
1011            $classes = array_unique($classes);
1012
1013            $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType()));
1014            if (
1015                $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
1016                (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) ||
1017                (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === true))
1018            ) {
1019                $html .= '<li class="' . implode(' ', $classes) . '">';
1020                $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' .
1021                    $item->getTitle() . '"><div class="icon">' . inlineSVG($item->getSvg()) .
1022                    '</div><span class="a11y">' . $item->getLabel() . '</span></a>';
1023                $html .= '</li>';
1024            }
1025        }//end foreach
1026
1027        $html .= '</ul>';
1028        $html .= '</nav>';
1029
1030        if ($print === true) {
1031            echo $html;
1032        }
1033        return $html;
1034    }
1035
1036
1037    /**
1038     * Print or return the search bar
1039     *
1040     * @param   boolean $print Print content.
1041     * @return  string         contents of the search bar
1042     */
1043    public function includeSearch(bool $print = true)
1044    {
1045        global $lang, $ID, $ACT, $QUERY;
1046        $html = '';
1047
1048        $html .= '<form class="mikio-search search" action="' . wl() .
1049            '" accept-charset="utf-8" method="get" role="search">';
1050        $html .= '<input type="hidden" name="do" value="search">';
1051        $html .= '<input type="hidden" name="id" value="' . $ID . '">';
1052        $html .= '<input name="q" ';
1053        if ($this->getConf('searchUseTypeahead') === true) {
1054            $html .= 'class="search_typeahead" ';
1055        }
1056        $html .= 'autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' .
1057            ((strcasecmp($ACT, 'search') === 0) ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />';
1058        $html .= '<button type="submit" title="' .  $lang['btn_search'] . '">';
1059        if (strcasecmp($this->getConf('searchButton'), 'icon') === 0) {
1060            $html .= $this->mikioInlineIcon('search');
1061        } else {
1062            $html .= $lang['btn_search'];
1063        }
1064        $html .= '</button>';
1065        $html .= '</form>';
1066
1067        if ($print === true) {
1068            echo $html;
1069        }
1070        return $html;
1071    }
1072
1073
1074    /**
1075     * Print or return content
1076     *
1077     * @param   boolean $print Print content.
1078     * @return  string         contents
1079     */
1080    public function includeContent(bool $print = true)
1081    {
1082        ob_start();
1083        tpl_content(false);
1084        $html = ob_get_contents();
1085        ob_end_clean();
1086
1087        $html = $this->includeIcons($html);
1088        $html = $this->parseContent($html);
1089
1090        $html .= '<div style="clear:both"></div>';
1091
1092        if ($this->getConf('heroTitle') === false) {
1093            $html = '<div class="mikio-tags"></div>' . $html;
1094        }
1095
1096        $html = '<div class="mikio-article-content">' . $html . '</div>';
1097
1098        if ($print === true) {
1099            echo $html;
1100        }
1101        return $html;
1102    }
1103
1104    /**
1105     * Print or return footer
1106     *
1107     * @param   boolean $print Print footer.
1108     * @return  string         HTML string containing footer
1109     */
1110    public function includeFooter(bool $print = true)
1111    {
1112        global $ACT;
1113
1114        $html = '';
1115
1116        $html .= '<footer class="mikio-footer">';
1117        $html .= '<div class="doc">' . tpl_pageinfo(true) . '</div>';
1118        $html .= $this->includePage('footer', false);
1119
1120        $html .= $this->stringToNav($this->getConf('footerCustomMenuText'));
1121
1122        if ($this->getConf('footerSearch') === true) {
1123            $html .= '<div class="mikio-footer-search">';
1124            $html .= $this->includeSearch(false);
1125            $html .= '</div>';
1126        }
1127
1128        $showPageTools = $this->getConf('pageToolsFooter');
1129        if (
1130            strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, 'always') === 0 ||
1131            $this->userCanEdit() === true && strcasecmp($showPageTools, 'page editors') === 0)
1132        ) {
1133            $html .= $this->includePageTools(false);
1134        }
1135
1136        $meta['licenseType']            = ['multichoice', '_choices' => ['none', 'badge', 'button']];
1137        $meta['licenseImageOnly']       = ['onoff'];
1138
1139        $licenseType = $this->getConf('licenseType');
1140        if ($licenseType !== 'none') {
1141            $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true, true);
1142        }
1143
1144        $html .= '</footer>';
1145
1146        if ($print === true) {
1147            echo $html;
1148        }
1149        return $html;
1150    }
1151
1152
1153    /**
1154     * Print or return breadcrumb trail
1155     *
1156     * @param   boolean $print Print out trail.
1157     * @param   boolean $parse Parse trail before printing.
1158     * @return  string         HTML string containing breadcrumbs
1159     */
1160    public function includeBreadcrumbs(bool $print = true, bool $parse = true)
1161    {
1162        global $conf, $ID, $lang, $ACT;
1163
1164        if (
1165            $this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 &&
1166            strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0
1167        ) {
1168            return '';
1169        }
1170
1171        $html = '<div class="mikio-breadcrumbs">';
1172        $html .= '<div class="mikio-container">';
1173        if (strcasecmp($ACT, 'show') === 0) {
1174            if ($conf['breadcrumbs'] !== 0) {
1175                if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) {
1176                    ob_start();
1177                    tpl_breadcrumbs();
1178                    $html .= ob_get_contents();
1179                    ob_end_clean();
1180                } else {
1181                    $sep = '•';
1182                    $prefix = $lang['breadcrumb'];
1183
1184                    if ($this->getConf('breadcrumbSep') === true) {
1185                        $sep = $this->getConf('breadcrumbSepText');
1186                        $img = $this->getMediaFile('breadcrumb-sep', false);
1187
1188                        if ($img !== false) {
1189                            $sep = '<img src="' . $img . '">';
1190                        }
1191                    }
1192
1193                    if ($this->getConf('breadcrumbPrefix') === true) {
1194                        $prefix = $this->getConf('breadcrumbPrefixText');
1195                        $img = $this->getMediaFile('breadcrumb-prefix', false);
1196
1197                        if ($img !== false) {
1198                            $prefix = '<img src="' . $img . '">';
1199                        }
1200                    }
1201
1202                    $crumbs = breadcrumbs();
1203
1204                    $html .= '<ul>';
1205                    if (empty($prefix) === false) {
1206                        $html .= '<li class="prefix">' . $prefix . '</li>';
1207                    }
1208
1209                    $last = count($crumbs);
1210                    $i    = 0;
1211                    foreach ($crumbs as $id => $name) {
1212                        $i++;
1213                        if ($i !== 1) {
1214                            $html .= '<li class="sep">' . $sep . '</li>';
1215                        }
1216                        $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>';
1217                        $html .= tpl_pagelink($id, null, true);
1218                        $html .= '</li>';
1219                    }
1220
1221                    $html .= '</ul>';
1222                }//end if
1223            }//end if
1224        }//end if
1225
1226        $html .= '</div>';
1227        $html .= '</div>';
1228
1229        if ($parse === true) {
1230            $html = $this->includeIcons($html);
1231        }
1232        if ($print === true) {
1233            echo $html;
1234        }
1235        return $html;
1236    }
1237
1238    /**
1239     * Print or return you are here trail
1240     *
1241     * @param   boolean $print Print out trail.
1242     * @param   boolean $parse Parse trail before printing.
1243     * @return  string         HTML string containing breadcrumbs
1244     */
1245    public function includeYouAreHere(bool $print = true, bool $parse = true)
1246    {
1247        global $conf, $ID, $lang, $ACT;
1248
1249        if (
1250            $this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 &&
1251            strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0
1252        ) {
1253            return '';
1254        }
1255
1256        $html = '<div class="mikio-youarehere">';
1257        $html .= '<div class="mikio-container">';
1258        if (strcasecmp($ACT, 'show') === 0) {
1259            if ($conf['youarehere'] !== 0) {
1260                if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) {
1261                    $html .= '<div class="mikio-bcdw">';
1262                    ob_start();
1263                    tpl_youarehere();
1264                    $html .= ob_get_contents();
1265                    ob_end_clean();
1266                    $html .= '</div>';
1267                } else {
1268                    $sep = ' » ';
1269                    $prefix = $lang['youarehere'];
1270
1271                    if ($this->getConf('youarehereSep') === true) {
1272                        $sep = $this->getConf('youarehereSepText');
1273                        $img = $this->getMediaFile('youarehere-sep', false);
1274
1275                        if ($img !== false) {
1276                            $sep = '<img src="' . $img . '">';
1277                        }
1278                    }
1279
1280                    if ($this->getConf('youareherePrefix') === true) {
1281                        $prefix = $this->getConf('youareherePrefixText');
1282                        $img = $this->getMediaFile('youarehere-prefix', false);
1283
1284                        if ($img !== false) {
1285                            $prefix = '<img src="' . $img . '">';
1286                        }
1287                    }
1288
1289                    $html .= '<ul>';
1290                    if (empty($prefix) === false) {
1291                        $html .= '<li class="prefix">' . $prefix . '</li>';
1292                    }
1293                    $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>';
1294
1295                    $parts = explode(':', $ID);
1296                    $count = count($parts);
1297
1298                    $part = '';
1299                    for ($i = 0; $i < ($count - 1); $i++) {
1300                        $part .= $parts[$i] . ':';
1301                        $page = $part;
1302                        if ($page === $conf['start']) {
1303                            continue;
1304                        }
1305
1306                        $html .= '<li class="sep">' . $sep . '</li>';
1307                        $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>';
1308                    }
1309
1310                    resolve_pageid('', $page, $exists);
1311                    if ((isset($page) === true && $page === $part . $parts[$i]) === false) {
1312                        $page = $part . $parts[$i];
1313                        if ($page !== $conf['start']) {
1314                            $html .= '<li class="sep">' . $sep . '</li>';
1315                            $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>';
1316                        }
1317                    }
1318
1319                    $html .= '</ul>';
1320                }//end if
1321            }//end if
1322
1323            $showLast = $this->getConf('youarehereShowLast');
1324            if ($showLast !== 0) {
1325                preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches);
1326                if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) {
1327                    $count = count($matches[0]);
1328                    $list = '';
1329
1330                    // Show Home
1331                    $list .= $matches[0][0] . $matches[0][1];
1332
1333                    $list .= '<li>...</li>';
1334                    for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) {
1335                        $list .= $matches[0][$i];
1336                    }
1337
1338                    $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html);
1339                }
1340            }
1341
1342            switch ($this->getConf('youarehereHome')) {
1343                case 'none':
1344                    $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2);
1345                    break;
1346                case 'home':
1347                    $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1);
1348                    break;
1349                case 'icon':
1350                    $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' .
1351                        $this->mikioInlineIcon('home') . '$3', $html, 1);
1352                    break;
1353            }
1354        } else {
1355            $html .= '&#8810; ';
1356            if (isset($_GET['page']) === true) {
1357                $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">Back</a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;';
1358            }
1359            $html .= '<a href="' . wl($ID) . '">View Page</a>';
1360        }//end if
1361
1362        $html .= '</div>';
1363        $html .= '</div>';
1364
1365        if ($parse === true) {
1366            $html = $this->includeIcons($html);
1367        }
1368        if ($print === true) {
1369            echo $html;
1370        }
1371        return $html;
1372    }
1373
1374    /**
1375     * Get Page Title
1376     *
1377     * @return string page title
1378     */
1379    public function parsePageTitle()
1380    {
1381        global $ID;
1382
1383        $title = p_get_first_heading($ID);
1384        if (strlen($title) <= 0) {
1385            $title = tpl_pagetitle(null, true);
1386        }
1387        $title = $this->includeIcons($title);
1388
1389        return $title;
1390    }
1391
1392
1393    /**
1394     * Print or return hero block
1395     *
1396     * @param   boolean $print Print content.
1397     * @return  string         contents of hero
1398     */
1399    public function includeHero(bool $print = true)
1400    {
1401        $html = '';
1402
1403        if ($this->getConf('heroTitle') === true) {
1404            $html .= '<div class="mikio-hero">';
1405            $html .= '<div class="mikio-container">';
1406            $html .= '<div class="mikio-hero-text">';
1407            if (strcasecmp($this->getConf('youareherePosition'), 'hero') === 0) {
1408                $html .= $this->includeYouAreHere(false);
1409            }
1410            if (strcasecmp($this->getConf('breadcrumbPosition'), 'hero') === 0) {
1411                $html .= $this->includeBreadcrumbs(false);
1412            }
1413
1414            $html .= '<h1 class="mikio-hero-title">';
1415            $html .= $this->parsePageTitle();    // No idea why this requires a blank space afterwards to work?
1416            $html .= '</h1>';
1417            $html .= '<h2 class="mikio-hero-subtitle"></h2>';
1418            $html .= '</div>';
1419
1420            $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true));
1421            $hero_image_resize_class = '';
1422            if (empty($hero_image) === false) {
1423                $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"';
1424                $hero_image_resize_class = ' mikio-hero-image-resize';
1425            }
1426
1427            $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image .
1428                '><div class="mikio-tags"></div></div>';
1429
1430            $html .= '</div>';
1431            $html .= '</div>';
1432        }//end if
1433
1434        if ($print === true) {
1435            echo $html;
1436        }
1437
1438        return $html;
1439    }
1440
1441
1442    /**
1443     * Print or return out TOC
1444     *
1445     * @param   boolean $print Print TOC.
1446     * @param   boolean $parse Parse icons.
1447     * @return  string         contents of TOC
1448     */
1449    public function includeTOC(bool $print = true, bool $parse = true)
1450    {
1451        $html = '';
1452
1453        $tocHtml = tpl_toc(true);
1454
1455        if (empty($tocHtml) === false) {
1456            $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml);
1457            $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml);
1458
1459            $html .= '<div class="mikio-toc">';
1460            $html .= $tocHtml;
1461            $html .= '</div>';
1462        }
1463
1464        if ($parse === true) {
1465            $html = $this->includeIcons($html);
1466        }
1467
1468        if ($print === true) {
1469            echo $html;
1470        }
1471
1472        return $html;
1473    }
1474
1475
1476    /**
1477     * Parse the string and replace icon elements with included icon libraries
1478     *
1479     * @param   string $str Content to parse.
1480     * @return  string      parsed string
1481     */
1482    public function includeIcons(string $str)
1483    {
1484        global $ACT, $MIKIO_ICONS;
1485
1486        $iconTag = $this->getConf('iconTag', 'icon');
1487        if (empty($iconTag) === true) {
1488            return $str;
1489        }
1490
1491        if (
1492            in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true ||
1493            strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0
1494        ) {
1495            $content = $str;
1496            $preview = null;
1497
1498            if (strcasecmp($ACT, 'preview') === 0) {
1499                $html = new \simple_html_dom();
1500                $html->stripRNAttrValues = false;
1501                $html->load($str, true, false);
1502
1503                $preview = $html->find('div.preview');
1504                if (is_array($preview) === true && count($preview) > 0) {
1505                    $content = $preview[0]->innertext;
1506                }
1507            }
1508
1509            $page_regex = '/(.*)/';
1510            if (stripos($str, '<pre') !== false) {
1511                $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/';
1512            }
1513
1514            $content = preg_replace_callback($page_regex, function ($icons) {
1515                $iconTag = $this->getConf('iconTag', 'icon');
1516
1517                return preg_replace_callback(
1518                    '/&lt;' . $iconTag . ' ([\w\- #]*)&gt;(?=[^>]*(<|$))/',
1519                    function ($matches) {
1520                        global $MIKIO_ICONS;
1521
1522                        $s = $matches[0];
1523
1524                        if (count($MIKIO_ICONS) > 0) {
1525                            $icon = $MIKIO_ICONS[0];
1526
1527                            if (count($matches) > 1) {
1528                                $e = explode(' ', $matches[1]);
1529
1530                                if (count($e) > 1) {
1531                                    foreach ($MIKIO_ICONS as $iconItem) {
1532                                        if (strcasecmp($iconItem['name'], $e[0]) === 0) {
1533                                            $icon = $iconItem;
1534
1535                                            $s = $icon['insert'];
1536                                            for ($i = 1; $i < 9; $i++) {
1537                                                if (count(empty($e) < $i || $e[$i]) === true) {
1538                                                    if (isset($icon['$' . $i]) === true) {
1539                                                        $s = str_replace('$' . $i, $icon['$' . $i], $s);
1540                                                    }
1541                                                } else {
1542                                                    $s = str_replace('$' . $i, $e[$i], $s);
1543                                                }
1544                                            }
1545
1546                                            $dir = '';
1547                                            if (isset($icon['dir']) === true) {
1548                                                $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/';
1549                                            }
1550
1551                                            $s = str_replace('$0', $dir, $s);
1552
1553                                            break;
1554                                        }//end if
1555                                    }//end foreach
1556                                } else {
1557                                    $s = str_replace('$1', $matches[1], $icon['insert']);
1558                                }//end if
1559                            }//end if
1560                        }//end if
1561
1562                        $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count);
1563                        if ($count === 0) {
1564                            $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s);
1565                        }
1566
1567                        return $s;
1568                    },
1569                    $icons[0]
1570                );
1571            }, $content);
1572
1573            if (strcasecmp($ACT, 'preview') === 0) {
1574                if (is_array($preview) === true && count($preview) > 0) {
1575                    $preview[0]->innertext = $content;
1576                }
1577
1578                $str = $html->save();
1579                $html->clear();
1580                unset($html);
1581            } else {
1582                $str = $content;
1583            }
1584        }//end if
1585
1586        return $str;
1587    }
1588
1589    /**
1590     * Parse HTML for theme
1591     *
1592     * @param   string $content HTML content to parse.
1593     * @return  string          Parsed content
1594     */
1595    public function parseContent(string $content)
1596    {
1597        global $INPUT, $ACT;
1598
1599        // Add Mikio Section titles
1600        if (strcasecmp($INPUT->str('page'), 'config') === 0) {
1601            $admin_sections = [
1602                // Section      Insert Before                 Icon
1603                'navbar'        => ['navbarUseTitleIcon',      ''],
1604                'search'        => ['searchButton',            ''],
1605                'hero'          => ['heroTitle',               ''],
1606                'tags'          => ['tagsConsolidate',         ''],
1607                'breadcrumb'    => ['breadcrumbHideHome',      ''],
1608                'youarehere'    => ['youarehereHideHome',      ''],
1609                'sidebar'       => ['sidebarShowLeft',         ''],
1610                'toc'           => ['tocFull',                 ''],
1611                'pagetools'     => ['pageToolsFloating',       ''],
1612                'footer'        => ['footerCustomMenuText',    ''],
1613                'license'       => ['licenseType',             ''],
1614                'acl'           => ['includePageUseACL',       ''],
1615                'sticky'        => ['stickyTopHeader',         ''],
1616            ];
1617
1618            foreach ($admin_sections as $section => $items) {
1619                $search = $items[0];
1620                $icon   = $items[1];
1621
1622                $content = preg_replace(
1623                    '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/',
1624                    '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) .
1625                        tpl_getLang('config_' . $section) .
1626                        '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' .
1627                        $search . '</span>',
1628                    $content
1629                );
1630            }
1631        }//end if
1632
1633        if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) {
1634            $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content);
1635        }
1636
1637        // Page Revisions - Table Fix
1638        if (strpos($content, 'id="page__revisions"') !== false) {
1639            $content = preg_replace(
1640                '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/',
1641                '<span>$1</span>',
1642                $content
1643            );
1644        }
1645
1646        $html = new \simple_html_dom();
1647        $html->stripRNAttrValues = false;
1648        $html->load($content, true, false);
1649
1650        if ($html === false) {
1651            return $content;
1652        }
1653
1654        /* Buttons */
1655        foreach ($html->find('#config__manager button') as $node) {
1656            $c = explode(' ', $node->class);
1657            if (in_array('mikio-button', $c) === false) {
1658                $c[] = 'mikio-button';
1659            }
1660            $node->class = implode(' ', $c);
1661        }
1662
1663
1664        /* Buttons - Primary */
1665        foreach ($html->find('#config__manager [type=submit]') as $node) {
1666            $c = explode(' ', $node->class);
1667            if (in_array('mikio-primary', $c) === false) {
1668                $c[] = 'mikio-primary';
1669            }
1670            $node->class = implode(' ', $c);
1671        }
1672
1673        /* Hide page title if hero is enabled */
1674        if ($this->getConf('heroTitle') === true && $ACT !== 'preview') {
1675            $pageTitle = $this->parsePageTitle();
1676
1677            foreach ($html->find('h1,h2,h3,h4') as $elm) {
1678                if ($elm->innertext === $pageTitle) {
1679                    // $elm->innertext = '';
1680                    $elm->setAttribute('style', 'display:none');
1681
1682                    break;
1683                }
1684            }
1685        }
1686
1687        /* Hero subtitle */
1688        foreach ($html->find('p') as $elm) {
1689            $i = stripos($elm->innertext, '~~hero-subtitle');
1690            if ($i !== false) {
1691                $j = strpos($elm->innertext, '~~', ($i + 2));
1692                if ($j !== false) {
1693                    if ($j > ($i + 16)) {
1694                        $subtitle = substr($elm->innertext, ($i + 16), ($j - $i - 16));
1695                        $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')';
1696
1697                        // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2);
1698                        $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext);
1699                    }
1700
1701                    break;
1702                }
1703            }
1704        }
1705
1706        /* Hero image */
1707        foreach ($html->find('p') as $elm) {
1708            $image = '';
1709            preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches);
1710            if (count($matches) > 0) {
1711                preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches);
1712                if (count($imageTagMatches) > 0) {
1713                    $image = $imageTagMatches[1];
1714                } else {
1715                    preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches);
1716                    if (count($imageTagMatches) > 0) {
1717                        $image = $imageTagMatches[1];
1718                    } else {
1719                        $image = strip_tags($matches[1]);
1720                        if (stripos($image, ':') === false) {
1721                            $image = str_replace(['{', '}'], '', $image);
1722                            $i = stripos($image, '?');
1723                            if ($i !== false) {
1724                                $image = substr($image, 0, $i);
1725                            }
1726
1727                            $image = ml($image, '', true, '', false);
1728                        }
1729                    }
1730                }
1731
1732                $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')';
1733
1734                $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext);
1735            }//end if
1736        }//end foreach
1737
1738        /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color]
1739        [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */
1740        foreach ($html->find('p') as $elm) {
1741            $i = stripos($elm->innertext, '~~hero-colors');
1742            if ($i !== false) {
1743                $j = strpos($elm->innertext, '~~', ($i + 2));
1744                if ($j !== false) {
1745                    if ($j > ($i + 14)) {
1746                        $color = substr($elm->innertext, ($i + 14), ($j - $i - 14));
1747                        $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')';
1748
1749                        $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext);
1750                    }
1751
1752                    break;
1753                }
1754            }
1755        }
1756
1757        /* Hide parts - ~~hide-parts [parts]~~  */
1758        foreach ($html->find('p') as $elm) {
1759            $i = stripos($elm->innertext, '~~hide-parts');
1760            if ($i !== false) {
1761                $j = strpos($elm->innertext, '~~', ($i + 2));
1762                if ($j !== false) {
1763                    if ($j > ($i + 13)) {
1764                        $parts = explode(' ', substr($elm->innertext, ($i + 13), ($j - $i - 13)));
1765                        $script = '';
1766
1767                        foreach ($parts as $part) {
1768                            // $part = trim($part);
1769                            if (strlen($part) > 0) {
1770                                $script .= 'mikio.hidePart(\'' . $part . '\');';
1771                            }
1772                        }
1773
1774                        if (strlen($script) > 0) {
1775                            $this->footerScript['hide-parts'] = $script;
1776                        }
1777
1778                        $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext);
1779                    }
1780
1781                    break;
1782                }//end if
1783            }//end if
1784        }//end foreach
1785
1786
1787        /* Page Tags (tag plugin) */
1788        if ($this->getConf('tagsConsolidate') === true) {
1789            $tags = '';
1790            foreach ($html->find('div.tags a') as $elm) {
1791                $tags .= $elm->outertext;
1792            }
1793
1794            foreach ($html->find('div.tags') as $elm) {
1795                $elm->innertext = '';
1796                $elm->setAttribute('style', 'display:none');
1797            }
1798
1799            if (empty($tags) === false) {
1800                $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')';
1801            }
1802        }
1803
1804        // Configuration Manager
1805        if (strcasecmp($INPUT->str('page'), 'config') === 0) {
1806            // Additional save buttons
1807            foreach ($html->find('#config__manager') as $cm) {
1808                $saveButtons = '';
1809
1810                foreach ($cm->find('p') as $elm) {
1811                    $saveButtons = $elm->outertext;
1812                    $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons);
1813                    $elm->outertext = '';
1814                }
1815
1816                foreach ($cm->find('fieldset') as $elm) {
1817                    $elm->innertext .= $saveButtons;
1818                }
1819            }
1820        }
1821
1822        $content = $html->save();
1823        $html->clear();
1824        unset($html);
1825
1826        return $content;
1827    }
1828
1829
1830    /**
1831     * Get DokuWiki namespace/page/URI as link
1832     *
1833     * @param   string $str String to parse.
1834     * @return  string      parsed URI
1835     */
1836    public function getLink(string $str)
1837    {
1838        $i = strpos($str, '://');
1839        if ($i !== false) {
1840            return $str;
1841        }
1842
1843        return wl($str);
1844    }
1845
1846
1847    /**
1848     * Check if the user can edit current namespace/page
1849     *
1850     * @return  boolean  user can edit
1851     */
1852    public function userCanEdit()
1853    {
1854        global $INFO;
1855        global $ID;
1856
1857        $wiki_file = wikiFN($ID);
1858        if (@file_exists($wiki_file) === false) {
1859            return true;
1860        }
1861        if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) {
1862            return true;
1863        }
1864        // $meta_file = metaFN($ID, '.meta');
1865        if ($INFO['meta']['user'] === false) {
1866            return true;
1867        }
1868        if ($INFO['client'] === $INFO['meta']['user']) {
1869            return true;
1870        }
1871
1872        return false;
1873    }
1874
1875
1876    /**
1877     * Search for and return the uri of a media file
1878     *
1879     * @param string  $image           Image name to search for (without extension).
1880     * @param boolean $searchCurrentNS Search the current namespace.
1881     * @param boolean $propagate       Propagate search through the namespace.
1882     * @return string                  URI of the found media file
1883     */
1884    public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true)
1885    {
1886        global $INFO;
1887
1888        $ext = ['png', 'jpg', 'gif', 'svg'];
1889
1890        if ($searchCurrentNS === true) {
1891            $prefix[] = ':' . $INFO['namespace'] . ':';
1892        }
1893        if ($propagate === true) {
1894            $prefix[] = ':';
1895            $prefix[] = ':wiki:';
1896        }
1897        $theme = $this->getConf('customTheme');
1898        if (empty($theme) === false) {
1899            $prefix[] = 'themes/' . $theme . '/images/';
1900        }
1901        $prefix[] = 'images/';
1902
1903        $search = [];
1904        foreach ($prefix as $pitem) {
1905            foreach ($ext as $eitem) {
1906                $search[] = $pitem . $image . '.' . $eitem;
1907            }
1908        }
1909
1910        $img = '';
1911        $file = '';
1912        $url = '';
1913        $ismedia = false;
1914        $found = false;
1915
1916        foreach ($search as $img) {
1917            if (strcasecmp(substr($img, 0, 1), ':') === 0) {
1918                $file    = mediaFN($img);
1919                $ismedia = true;
1920            } else {
1921                $file    = tpl_incdir() . $img;
1922                $ismedia = false;
1923            }
1924
1925            if (file_exists($file) === true) {
1926                $found = true;
1927                break;
1928            }
1929        }
1930
1931        if ($found === false) {
1932            return false;
1933        }
1934
1935        if ($ismedia === true) {
1936            $url = ml($img, '', true, '', false);
1937        } else {
1938            $url = tpl_basedir() . $img;
1939        }
1940
1941        return $url;
1942    }
1943
1944
1945    /**
1946     * Print or return the page title
1947     *
1948     * @param string $page Page id or empty string for current page.
1949     * @return string      generated content
1950     */
1951    public function getPageTitle(string $page = '')
1952    {
1953        global $ID, $conf;
1954
1955        $html = '';
1956
1957        if (empty($page) === true) {
1958            $page = $ID;
1959        }
1960
1961        $html = p_get_first_heading($page);
1962        $html = strip_tags($html);
1963        $html = preg_replace('/\s+/', ' ', $html);
1964        $html .= ' [' . strip_tags($conf['title']) . ']';
1965        $html = trim($html);
1966
1967        return $html;
1968    }
1969
1970
1971    /**
1972     * Return inline theme icon
1973     *
1974     * @param   string $type Icon to retreive.
1975     * @return  string       HTML icon content
1976     */
1977    public function mikioInlineIcon(string $type)
1978    {
1979        switch ($type) {
1980            case 'wrench':
1981                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792"
1982style="fill:currentColor"><g transform="matrix(1,0,0,-1,53.152542,1217.0847)"><path d="m 384,64 q 0,26 -19,45 -19,19
1983-45,19 -26,0 -45,-19 -19,-19 -19,-45 0,-26 19,-45 19,-19 45,-19 26,0 45,19 19,19 19,45 z m 644,420 -682,-682 q -37,-37
1984-90,-37 -52,0 -91,37 L 59,-90 Q 21,-54 21,0 21,53 59,91 L 740,772 Q 779,674 854.5,598.5 930,523 1028,484 z m 634,435 q
19850,-39 -23,-106 Q 1592,679 1474.5,595.5 1357,512 1216,512 1031,512 899.5,643.5 768,775 768,960 q 0,185 131.5,316.5 131.5,
1986131.5 316.5,131.5 58,0 121.5,-16.5 63.5,-16.5 107.5,-46.5 16,-11 16,-28 0,-17 -16,-28 L 1152,1120 V 896 l 193,-107 q 5,
19873 79,48.5 74,45.5 135.5,81 61.5,35.5 70.5,35.5 15,0 23.5,-10 8.5,-10 8.5,-25 z"/></g></svg>';
1988            case 'file':
1989                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792"
1990style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"><path d="M 128,0 H 1152 V 768
1991H 736 q -40,0 -68,28 -28,28 -28,68 v 416 H 128 V 0 z m 640,896 h 299 L 768,1195 V 896 z M 1280,768 V -32 q 0,-40 -28,
1992-68 -28,-28 -68,-28 H 96 q -40,0 -68,28 -28,28 -28,68 v 1344 q 0,40 28,68 28,28 68,28 h 544 q 40,0 88,-20 48,-20 76,-48
1993l 408,-408 q 28,-28 48,-76 20,-48 20,-88 z" id="path2993" inkscape:connector-curvature="0"
1994xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>';
1995            case 'gear':
1996                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792"
1997style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"><path d="m 1024,640 q 0,106
1998-75,181 -75,75 -181,75 -106,0 -181,-75 -75,-75 -75,-181 0,-106 75,-181 75,-75 181,-75 106,0 181,75 75,75 75,181 z m
1999512,109 V 527 q 0,-12 -8,-23 -8,-11 -20,-13 l -185,-28 q -19,-54 -39,-91 35,-50 107,-138 10,-12 10,-25 0,-13 -9,-23 -27,
2000-37 -99,-108 -72,-71 -94,-71 -12,0 -26,9 l -138,108 q -44,-23 -91,-38 -16,-136 -29,-186 -7,-28 -36,-28 H 657 q -14,0
2001-24.5,8.5 Q 622,-111 621,-98 L 593,86 q -49,16 -90,37 L 362,16 Q 352,7 337,7 323,7 312,18 186,132 147,186 q -7,10 -7,23
20020,12 8,23 15,21 51,66.5 36,45.5 54,70.5 -27,50 -41,99 L 29,495 Q 16,497 8,507.5 0,518 0,531 v 222 q 0,12 8,23 8,11 19,
200313 l 186,28 q 14,46 39,92 -40,57 -107,138 -10,12 -10,24 0,10 9,23 26,36 98.5,107.5 72.5,71.5 94.5,71.5 13,0 26,-10 l
2004138,-107 q 44,23 91,38 16,136 29,186 7,28 36,28 h 222 q 14,0 24.5,-8.5 Q 914,1391 915,1378 l 28,-184 q 49,-16 90,-37 l
2005142,107 q 9,9 24,9 13,0 25,-10 129,-119 165,-170 7,-8 7,-22 0,-12 -8,-23 -15,-21 -51,-66.5 -36,-45.5 -54,-70.5 26,-50
200641,-98 l 183,-28 q 13,-2 21,-12.5 8,-10.5 8,-23.5 z" id="path3029" inkscape:connector-curvature="0" /></g></svg>';
2007            case 'user':
2008                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792"
2009style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 1408,131 Q 1408,11 1335,-58.5
20101262,-128 1141,-128 H 267 Q 146,-128 73,-58.5 0,11 0,131 0,184 3.5,234.5 7,285 17.5,343.5 28,402 44,452 q 16,50 43,97.5
201127,47.5 62,81 35,33.5 85.5,53.5 50.5,20 111.5,20 9,0 42,-21.5 33,-21.5 74.5,-48 41.5,-26.5 108,-48 Q 637,565 704,565 q
201267,0 133.5,21.5 66.5,21.5 108,48 41.5,26.5 74.5,48 33,21.5 42,21.5 61,0 111.5,-20 50.5,-20 85.5,-53.5 35,-33.5 62,-81
201327,-47.5 43,-97.5 16,-50 26.5,-108.5 10.5,-58.5 14,-109 Q 1408,184 1408,131 z m -320,893 Q 1088,865 975.5,752.5 863,640
2014704,640 545,640 432.5,752.5 320,865 320,1024 320,1183 432.5,1295.5 545,1408 704,1408 863,1408 975.5,1295.5 1088,1183
20151088,1024 z"/></g></svg>';
2016            case 'search':
2017                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"
2018aria-hidden="true" style="fill:currentColor"><path d="M27 24.57l-5.647-5.648a8.895 8.895 0 0 0 1.522-4.984C22.875 9.01
201918.867 5 13.938 5 9.01 5 5 9.01 5 13.938c0 4.929 4.01 8.938 8.938 8.938a8.887 8.887 0 0 0 4.984-1.522L24.568 27 27
202024.57zm-13.062-4.445a6.194 6.194 0 0 1-6.188-6.188 6.195 6.195 0 0 1 6.188-6.188 6.195 6.195 0 0 1 6.188 6.188 6.195
20216.195 0 0 1-6.188 6.188z"/></svg>';
2022            case 'home':
2023                return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792"
2024aria-hidden="true" style="fill:currentColor"><g transform="matrix(1,0,0,-1,68.338983,1285.4237)" id="g3015">
2025<path d="M 1408,544 V 64 Q 1408,38 1389,19 1370,0 1344,0 H 960 V 384 H 704 V 0 H 320 q -26,0 -45,19 -19,19 -19,
202645 v 480 q 0,1 0.5,3 0.5,2 0.5,3 l 575,474 575,-474 q 1,-2 1,-6 z m 223,69 -62,-74 q -8,-9 -21,-11 h -3 q -13,
20270 -21,7 L 832,1112 140,535 q -12,-8 -24,-7 -13,2 -21,11 l -62,74 q -8,10 -7,23.5 1,13.5 11,21.5 l 719,
2028599 q 32,26 76,26 44,0 76,-26 l 244,-204 v 195 q 0,14 9,23 9,9 23,9 h 192 q 14,0 23,-9 9,-9 9,-23 V 840 l 219,
2029-182 q 10,-8 11,-21.5 1,-13.5 -7,-23.5 z" id="path3017" inkscape:connector-curvature="0"
2030xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>';
2031        }//end switch
2032
2033        return '';
2034    }
2035
2036    /**
2037     * Finalize theme
2038     *
2039     * @return void
2040     */
2041    public function finalize()
2042    {
2043    }
2044
2045    /**
2046     * Show Messages
2047     *
2048     * @return void
2049     */
2050    public function showMessages()
2051    {
2052        global $ACT;
2053
2054        if ($this->lessIgnored === true) {
2055            msg(
2056                'useLESS is enabled on the Mikio template, however is not supported on this server',
2057                2,
2058                '',
2059                '',
2060                MSG_ADMINS_ONLY
2061            );
2062        }
2063
2064        $show = $this->getConf('showNotifications');
2065        if (
2066            strcasecmp($show, 'always') === 0 ||
2067            (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0)
2068        ) {
2069            global $MSG, $MSG_shown;
2070
2071            if (isset($MSG) === false) {
2072                return;
2073            }
2074
2075            if (isset($MSG_shown) === false) {
2076                $MSG_shown = [];
2077            }
2078
2079            foreach ($MSG as $msg) {
2080                $hash = md5($msg['msg']);
2081                if (isset($MSG_shown[$hash]) === true) {
2082                    continue;
2083                }
2084                // skip double messages
2085
2086                if (info_msg_allowed($msg) === true) {
2087                    echo '<div class="' . $msg['lvl'] . '">';
2088                    echo $msg['msg'];
2089                    echo '</div>';
2090                }
2091
2092                $MSG_shown[$hash] = true;
2093            }
2094
2095            unset($GLOBALS['MSG']);
2096        }//end if
2097    }
2098
2099    /**
2100     * Dokuwiki version
2101     *
2102     * @return  string        the dw version name
2103     */
2104    public function dwVersion()
2105    {
2106        if (function_exists('getVersionData') === true) {
2107            $version_data = getVersionData();
2108            if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) {
2109                $version_items = explode(' ', $version_data['date']);
2110                if (count($version_items) >= 2) {
2111                    return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1]));
2112                }
2113            }
2114        }
2115
2116        return 'unknown';
2117    }
2118
2119    /**
2120     * Dokuwiki version number
2121     *
2122     * @return  string        the dw version date converted to integer
2123     */
2124    public function dwVersionNumber()
2125    {
2126        if (function_exists('getVersionData') === true) {
2127            $version_data = getVersionData();
2128            if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) {
2129                $version_items = explode(' ', $version_data['date']);
2130                if (count($version_items) >= 1) {
2131                    return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0])));
2132                }
2133            }
2134        }
2135
2136        return 0;
2137    }
2138}
2139
2140global $TEMPLATE;
2141$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance();
2142