xref: /template/mikio/mikio.php (revision 667fe6ce109a355f94ea32272f9f8746487b65f6)
1<?php
2/** @noinspection DuplicatedCode */
3/** @noinspection SpellCheckingInspection */
4
5/**
6 * DokuWiki Mikio Template
7 *
8 * @link    http://dokuwiki.org/template:mikio
9 * @author  James Collins <james.collins@outlook.com.au>
10 * @license GPLv2 (http://www.gnu.org/licenses/gpl-2.0.html)
11 */
12
13namespace dokuwiki\template\mikio;
14
15use Doku_Event;
16use dokuwiki\Menu\PageMenu;
17use dokuwiki\Menu\SiteMenu;
18use dokuwiki\Menu\UserMenu;
19use ParensParser;
20use simple_html_dom;
21use DOMDocument;
22use DOMNode;
23
24if (defined('DOKU_INC') === false) {
25    die();
26}
27
28require_once('icons/icons.php');
29require_once('inc/simple_html_dom.php');
30require_once('inc/parens-parser.php');
31
32class mikio
33{
34    /**
35     * @var string Template directory path from local FS.
36     */
37    public $tplDir  = '';
38
39    /**
40     * @var string Template directory path from web.
41     */
42    public $baseDir = '';
43
44    /**
45     * @var array Array of Javascript files to include in footer.
46     */
47    public $footerScript = [];
48
49    /**
50     * @var string Notifications from included pages.
51     */
52    private $includedPageNotifications = '';
53
54
55    /**
56     * Class constructor
57     */
58    public function __construct()
59    {
60        $this->tplDir  = tpl_incdir();
61        $this->baseDir = tpl_basedir();
62
63        $this->registerHooks();
64    }
65
66    /**
67     * Returns the instance of the class
68     *
69     * @return  mikio        class instance
70     */
71    public static function getInstance(): mikio
72    {
73        static $instance = null;
74
75        if ($instance === null) {
76            $instance = new mikio();
77        }
78
79        return $instance;
80    }
81
82
83    /**
84     * Register the themes hooks into Dokuwiki
85     *
86     * @return void
87     */
88    private function registerHooks()
89    {
90        global $EVENT_HANDLER;
91
92        $events_dispatcher = [
93            'TPL_METAHEADER_OUTPUT'     => 'metaheadersHandler'
94        ];
95
96        foreach ($events_dispatcher as $event => $method) {
97            $EVENT_HANDLER->register_hook($event, 'BEFORE', $this, $method);
98        }
99    }
100
101
102    /**
103     * Meta handler hook for DokuWiki
104     *
105     * @param   Doku_Event $event DokuWiki Event.
106     * @return  void
107     * @noinspection PhpUnused
108     */
109    public function metaHeadersHandler(Doku_Event $event)
110    {
111        global $MIKIO_ICONS;
112        global $conf;
113
114        global $MIKIO_TEMPLATE;
115        $MIKIO_TEMPLATE = '123';
116
117        $this->includePage('theme', false);
118
119        $stylesheets    = [];
120        $scripts        = [];
121
122        if (empty($this->getConf('customTheme')) === false) {
123            if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.less') === true) {
124                $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.less';
125            } else {
126                if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.css') === true) {
127                    $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.css';
128                }
129            }
130            if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/script.js') === true) {
131                $scripts[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/script.js';
132            }
133        }
134
135        if (is_array($MIKIO_ICONS) === true && empty($this->getConf('iconTag', 'icon')) === false) {
136            $icons = [];
137            foreach ($MIKIO_ICONS as $icon) {
138                if (isset($icon['name']) === true && isset($icon['css']) === true && isset($icon['insert']) === true) {
139                    $icons[] = $icon;
140
141                    if (empty($icon['css']) === false) {
142                        if (strpos($icon['css'], '//') === false) {
143                            $stylesheets[] = $this->baseDir . 'icons/' . $icon['css'];
144                        } else {
145                            $stylesheets[] = $icon['css'];
146                        }
147                    }
148                }
149            }
150            $MIKIO_ICONS = $icons;
151        } else {
152            $MIKIO_ICONS = [];
153        }
154
155        $scripts[] = $this->baseDir . 'assets/mikio-typeahead.js';
156        $scripts[] = $this->baseDir . 'assets/mikio.js';
157
158        if ($this->getConf('useLESS') === true) {
159            $stylesheets[] = $this->baseDir . 'assets/mikio.less';
160        } else {
161            $stylesheets[] = $this->baseDir . 'assets/mikio.css';
162        }
163
164        /* MikioPlugin Support */
165        if (plugin_load('action', 'mikioplugin') !== null) {
166            if ($this->getConf('useLESS') === true) {
167                $stylesheets[] = $this->baseDir . 'assets/mikioplugin.less';
168            } else {
169                $stylesheets[] = $this->baseDir . 'assets/mikioplugin.css';
170            }
171        }
172
173        $set = [];
174        foreach ($stylesheets as $style) {
175            if (in_array($style, $set) === false) {
176                if (strcasecmp(substr($style, -5), '.less') === 0 && $this->getConf('useLESS') === true) {
177                    $style = $this->baseDir . 'css.php?css=' . str_replace($this->baseDir, '', $style);
178                }
179
180                array_unshift($event->data['link'], [
181                    'type' => 'text/css',
182                    'rel'  => 'stylesheet',
183                    'href' => $style
184                ]);
185            }
186            $set[] = $style;
187        }
188
189        $set = [];
190        foreach ($scripts as $script) {
191            if (in_array($script, $set) === false) {
192                $script_params = [
193                    'type'  => 'text/javascript',
194                    '_data' => '',
195                    'src'   => $script
196                ];
197
198                // equal to or greator than hogfather
199                if ($this->dwVersionNumber() >= 20200729 || $this->dwVersionNumber() == 0) {
200                    // greator than hogfather - defer always on
201                    if ($this->dwVersionNumber() >= 20200729 || $this->dwVersionNumber() == 0) {
202                        $script_params += ['defer' => 'defer'];
203                    } else {
204                        // hogfather - defer always on unless $conf['defer_js'] is false
205                        if (array_key_exists('defer_js', $conf) === false || $conf['defer_js'] === true) {
206                            $script_params += ['defer' => 'defer'];
207                        }
208                    }
209                }
210
211                $event->data['script'][] = $script_params;
212            }//end if
213            $set[] = $script;
214        }//end foreach
215    }
216
217
218    /**
219     * Print or return the footer metadata
220     *
221     * @param   boolean $print Print the data to buffer.
222     * @return  string         HTML footer meta data
223     */
224    public function includeFooterMeta(bool $print = true): string
225    {
226        $html = '';
227
228        if (count($this->footerScript) > 0) {
229            $html .= '<script type="text/javascript">function mikioFooterRun() {';
230            foreach ($this->footerScript as $script) {
231                $html .= $script . ';';
232            }
233            $html .= '}</script>';
234        }
235
236
237        if ($print === true) {
238            echo $html;
239        }
240        return $html;
241    }
242
243
244    // phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
245
246
247    /**
248     * Retreive and parse theme configuration options
249     *
250     * @param   string $key     The configuration key to retreive.
251     * @param   mixed  $default If key doesn't exist, return this value.
252     * @return  mixed           parsed value of configuration
253     */
254    public function getConf(string $key, $default = false)
255    {
256        $value = tpl_getConf($key, $default);
257
258        $data = [
259            ['keys' => ['navbarDWMenuType'],
260                'type' => 'choice',
261                'values' => [tpl_getLang('value_both'), tpl_getLang('value_icons'), tpl_getLang('value_text')]
262            ],
263            ['keys' => ['navbarDWMenuCombine'],
264                'type' => 'choice',
265                'values' => [tpl_getLang('value_combine'), tpl_getLang('value_separate'), tpl_getLang('value_dropdown')]
266            ],
267            ['keys' => ['navbarPosLeft', 'navbarPosMiddle', 'navbarPosRight'],
268                'type' => 'choice',
269                'values' => [tpl_getLang('value_none'), tpl_getLang('value_custom'), tpl_getLang('value_search'), tpl_getLang('value_dokuwiki')],
270                'default' => [
271                    'navbarPosLeft' => tpl_getLang('value_none'),
272                    'navbarPosMiddle' => tpl_getLang('value_search'),
273                    'navbarPosRight' => tpl_getLang('value_dokuwiki')
274                ]
275            ],
276            ['keys' => ['navbarItemShowCreate', 'navbarItemShowShow', 'navbarItemShowRevs', 'navbarItemShowBacklink',
277                'navbarItemShowRecent', 'navbarItemShowMedia', 'navbarItemShowIndex', 'navbarItemShowProfile',
278                'navbarItemShowAdmin'
279            ],
280                'type' => 'choice',
281                'values' => [tpl_getLang('value_always'), tpl_getLang('value_logged_in'), tpl_getLang('value_logged_out'), tpl_getLang('value_never')]
282            ],
283            ['keys' => ['navbarItemShowLogin', 'navbarItemShowLogout'],
284                'type' => 'choice',
285                'values' => [tpl_getLang('value_always'), tpl_getLang('value_never')]
286            ],
287            ['keys' => ['searchButton'],                    'type' => 'choice',
288                'values' => [tpl_getLang('value_icon'), tpl_getLang('value_text')]
289            ],
290            ['keys' => ['breadcrumbPosition', 'youareherePosition'],
291                'type' => 'choice',
292                'values' => [tpl_getLang('value_top'), tpl_getLang('value_hero'), tpl_getLang('value_page'), tpl_getLang('value_none')]
293            ],
294            ['keys' => ['youarehereHome'],                  'type' => 'choice',
295                'values' => [tpl_getLang('value_page_title'), tpl_getLang('value_home'), tpl_getLang('value_icon'), tpl_getLang('value_none')]
296            ],
297            ['keys' => ['sidebarLeftRow1', 'sidebarLeftRow2', 'sidebarLeftRow3', 'sidebarLeftRow4'],
298                'type' => 'choice',
299                'values' => [tpl_getLang('value_none'), tpl_getLang('value_logged in user'), tpl_getLang('value_search'), tpl_getLang('value_content'), tpl_getLang('value_tags')],
300                'default' => [
301                    'sidebarLeftRow1' => tpl_getLang('value_logged in user'),
302                    'sidebarLeftRow2' => tpl_getLang('value_search'),
303                    'sidebarLeftRow3' => tpl_getLang('value_content')
304                ]
305            ],
306            ['keys' => ['pageToolsFloating', 'pageToolsFooter'],
307                'type' => 'choice',
308                'values' => [tpl_getLang('value_always'), tpl_getLang('value_none'), tpl_getLang('value_page_editors')]
309            ],
310            ['keys' => ['pageToolsShowCreate', 'pageToolsShowEdit', 'pageToolsShowRevs', 'pageToolsShowBacklink',
311                'pageToolsShowTop'
312            ],
313                'type' => 'choice',
314                'values' => [tpl_getLang('value_always'), tpl_getLang('value_logged_in'), tpl_getLang('value_logged_out'), tpl_getLang('value_never')]
315            ],
316            ['keys' => ['showNotifications'],               'type' => 'choice',
317                'values' => [tpl_getLang('value_admin'), tpl_getLang('value_always'), tpl_getLang('value_none'), '', tpl_getLang('value_never')]
318            ],
319            ['keys' => ['licenseType'],                     'type' => 'choice',
320                'values' => [tpl_getLang('value_badge'), tpl_getLang('value_button'), tpl_getLang('value_none')]
321            ],
322            ['keys' => ['navbarUseTitleIcon'],              'type' => 'bool'],
323            ['keys' => ['navbarUseTitleText'],              'type' => 'bool'],
324            ['keys' => ['navbarUseTaglineText'],            'type' => 'bool'],
325            ['keys' => ['navbarShowSub'],                   'type' => 'bool'],
326            ['keys' => ['heroTitle'],                       'type' => 'bool'],
327            ['keys' => ['heroImagePropagation'],            'type' => 'bool'],
328            ['keys' => ['breadcrumbPrefix'],                'type' => 'bool'],
329            ['keys' => ['breadcrumbSep'],                   'type' => 'bool'],
330            ['keys' => ['youareherePrefix'],                'type' => 'bool'],
331            ['keys' => ['youarehereSep'],                   'type' => 'bool'],
332            ['keys' => ['sidebarShowLeft'],                 'type' => 'bool'],
333            ['keys' => ['sidebarShowRight'],                'type' => 'bool'],
334            ['keys' => ['tocFull'],                         'type' => 'bool'],
335            ['keys' => ['footerSearch'],                    'type' => 'bool'],
336            ['keys' => ['licenseImageOnly'],                'type' => 'bool'],
337            ['keys' => ['includePageUseACL'],               'type' => 'bool'],
338            ['keys' => ['includePagePropagate'],            'type' => 'bool'],
339            ['keys' => ['youarehereHideHome'],              'type' => 'bool'],
340            ['keys' => ['tagsConsolidate'],                 'type' => 'bool'],
341            ['keys' => ['tagsShowHero'],                    'type' => 'bool'],
342            ['keys' => ['footerInPage'],                    'type' => 'bool'],
343            ['keys' => ['sidebarMobileDefaultCollapse'],    'type' => 'bool'],
344            ['keys' => ['sidebarAlwaysShowLeft'],           'type' => 'bool'],
345            ['keys' => ['sidebarAlwaysShowRight'],          'type' => 'bool'],
346            ['keys' => ['searchUseTypeahead'],              'type' => 'bool'],
347            ['keys' => ['showLightDark'],                   'type' => 'bool'],
348            ['keys' => ['autoLightDark'],                   'type' => 'bool'],
349            ['keys' => ['youarehereShowLast'],              'type' => 'int'],
350
351            ['keys' => ['iconTag'],                         'type' => 'string'],
352            ['keys' => ['customTheme'],                     'type' => 'string'],
353            ['keys' => ['navbarCustomMenuText'],            'type' => 'string'],
354            ['keys' => ['breadcrumbPrefixText'],            'type' => 'string'],
355            ['keys' => ['breadcrumbSepText'],               'type' => 'string'],
356            ['keys' => ['youareherePrefixText'],            'type' => 'string'],
357            ['keys' => ['youarehereSepText'],               'type' => 'string'],
358            ['keys' => ['footerPageInfoText'],              'type' => 'string'],
359            ['keys' => ['footerCustomMenuText'],            'type' => 'string'],
360            ['keys' => ['brandURLGuest'],                   'type' => 'string'],
361            ['keys' => ['brandURLUser'],                    'type' => 'string'],
362
363            ['keys' => ['useLESS'],                         'type' => 'bool'],
364
365            ['keys' => ['stickyTopHeader'],                  'type' => 'bool'],
366            ['keys' => ['stickyNavbar'],                     'type' => 'bool'],
367            ['keys' => ['stickyHeader'],                     'type' => 'bool'],
368            ['keys' => ['stickyLeftSidebar'],                'type' => 'bool'],
369        ];
370
371        foreach ($data as $row) {
372            // does not check case....
373            if (in_array($key, $row['keys']) === true) {
374                if (array_key_exists('type', $row) === true) {
375                    switch ($row['type']) {
376                        case 'bool':
377                            return (bool) $value;
378                        case 'int':
379                            return (int) $value;
380                        case 'string':
381                            return $value;
382                    }//end switch
383                }//end if
384
385                if (in_array($value, $row['values']) === true) {
386                    return $value;
387                }
388
389                if (array_key_exists('default', $row) === true) {
390                    if (is_array($row['default']) === true) {
391                        if (array_key_exists($key, $row['default']) === true) {
392                            return $row['default'][$key];
393                        }
394                    } else {
395                        return $row['default'];
396                    }
397                }
398
399                return reset($row['values']);
400            }//end if
401        }//end foreach
402
403        return $value;
404    }
405
406
407    // phpcs:enable
408
409
410    /**
411     * Check if a page exist in directory or namespace
412     *
413     * @param   string $page Page/namespace to search.
414     * @return  boolean      if page exists
415     */
416    public function pageExists(string $page): bool
417    {
418        ob_start();
419        tpl_includeFile($page . '.html');
420        $html = ob_get_clean();
421
422        if (empty($html) === false) {
423            return true;
424        }
425
426        $useACL = $this->getConf('includePageUseACL');
427        $propagate = $this->getConf('includePagePropagate');
428
429        if ($propagate === true) {
430            if (page_findnearest($page, $useACL) !== false) {
431                return true;
432            }
433        } elseif ($useACL === true && auth_quickaclcheck($page) !== AUTH_NONE) {
434            return true;
435        }
436
437        return false;
438    }
439
440
441    /**
442     * Print or return page from directory or namespace
443     *
444     * @param   string  $page         Page/namespace to include.
445     * @param   boolean $print        Print content.
446     * @param   boolean $parse        Parse content before printing/returning.
447     * @param   string  $classWrapper Wrap page in a div with class.
448     * @return  string                contents of page found
449     */
450    public function includePage(string $page, bool $print = true, bool $parse = true, string $classWrapper = ''): string
451    {
452        ob_start();
453        tpl_includeFile($page . '.html');
454        $html = ob_get_clean();
455
456        if (empty($html) === true) {
457            $useACL = $this->getConf('includePageUseACL');
458            $propagate = $this->getConf('includePagePropagate');
459
460            ob_start();
461            $html = tpl_include_page($page, false, $propagate, $useACL);
462            $this->includedPageNotifications .= ob_get_clean();
463        }
464
465        if (empty($html) === false && $parse === true) {
466            $html = $this->parseContent($html);
467        }
468
469        if (empty($classWrapper) === false && empty($html) === false) {
470            $html = '<div class="' . $classWrapper . '">' . $html . '</div>';
471        }
472
473        if ($print === true) {
474            echo $html;
475        }
476        return $html;
477    }
478
479
480    /**
481     * Print or return logged-in user information
482     *
483     * @param   boolean $print Print content.
484     * @return  string         user information
485     */
486    public function includeLoggedIn(bool $print = true): string
487    {
488        $html = '';
489
490        if (empty($_SERVER['REMOTE_USER']) === false) {
491            $html .= '<div class="mikio-user-info">';
492            ob_start();
493            tpl_userinfo();
494            $html .= ob_get_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): string
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') != tpl_getLang('value_text'));
524        $showText   = ($this->getConf('navbarDWMenuType') != tpl_getLang('value_icons'));
525        $isDropDown = ($this->getConf('navbarDWMenuCombine') != tpl_getLang('value_separate'));
526
527        $items = (new 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, tpl_getLang('value_always')) === 0 ||
535                    (strcasecmp($showItem, tpl_getLang('value_logged_in')) === 0 && $loggedIn === true) ||
536                    (strcasecmp($showItem, tpl_getLang('value_logged_out')) === 0 && $loggedIn === false))
537                ) {
538                    $title = isset($attr['title']) && $attr['title'] !== 0 ? $attr['title'] : $item->getTitle();
539
540                    $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') .
541                        ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $title . '"' . (isset($attr['accesskey']) && $attr['accesskey'] !== '' ? ' accesskey="' . $attr['accesskey'] . '"' : '') . '>';
542                    if ($showIcons === true) {
543                        $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
544                    }
545                    if ($showText === true || $isDropDown === true) {
546                        $itemHtml .= '<span>' . $item->getLabel() . '</span>';
547                    }
548                    $itemHtml .= '</a>';
549
550                    $pageToolsMenu[] = $itemHtml;
551                }
552            }//end if
553        }//end foreach
554
555        $items = (new SiteMenu())->getItems();
556        foreach ($items as $item) {
557            $itemHtml = '';
558
559            $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType()));
560            if (
561                $showItem !== false && (strcasecmp($showItem, tpl_getLang('value_always')) === 0 ||
562                (strcasecmp($showItem, tpl_getLang('value_logged_in')) === 0 && $loggedIn === true) ||
563                (strcasecmp($showItem, tpl_getLang('value_logged_out')) === 0 && $loggedIn === false))
564            ) {
565                $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . ' ' .
566                    $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">';
567                if ($showIcons === true) {
568                    $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
569                }
570                if ($showText === true || $isDropDown === true) {
571                    $itemHtml .= '<span>' . $item->getLabel() . '</span>';
572                }
573                $itemHtml .= '</a>';
574
575                $siteToolsMenu[] = $itemHtml;
576            }
577        }//end foreach
578
579        $items = (new UserMenu())->getItems();
580        foreach ($items as $item) {
581            $itemHtml = '';
582
583            $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType()));
584            if (
585                $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
586                (strcasecmp($showItem, tpl_getLang('value_logged_in')) === 0 && $loggedIn === true) ||
587                (strcasecmp($showItem, tpl_getLang('value_logged_out')) === 0 && $loggedIn === false))
588            ) {
589                $itemHtml .= '<a class="mikio-nav-link' . ($isDropDown === true ? ' mikio-dropdown-item' : '') . ' ' .
590                $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">';
591                if ($showIcons === true) {
592                    $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>';
593                }
594                if ($showText === true || $isDropDown === true) {
595                    $itemHtml .= '<span>' . $item->getLabel() . '</span>';
596                }
597                $itemHtml .= '</a>';
598
599                $userToolsMenu[] = $itemHtml;
600            }
601        }//end foreach
602
603        $value_dropdown = tpl_getLang('value_dropdown');
604        $value_combine = tpl_getLang('value_combine');
605//        $value_separate = tpl_getLang('value_separate');
606
607        switch ($this->getConf('navbarDWMenuCombine')) {
608            case $value_dropdown:
609                $html .= '<li id="dokuwiki__pagetools" class="mikio-nav-dropdown">';
610                $html .= '<a id="mikio_dropdown_pagetools" class="nav-link dropdown-toggle" href="#" role="button"
611data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
612                ($showIcons === true ? $this->mikioInlineIcon('file') : '') .
613                ($showText === true ? $lang['page_tools'] : '<span class="mikio-small-only">' . $lang['page_tools'] .
614                '</span>') . '</a>';
615
616                $html .= '<div class="mikio-dropdown closed">' . implode('', $pageToolsMenu);
617
618                $html .= '</div>';
619                $html .= '</li>';
620
621                $html .= '<li id="dokuwiki__sitetools" class="mikio-nav-dropdown">';
622                $html .= '<a id="mikio_dropdown_sitetools" class="nav-link dropdown-toggle" href="#" role="button"
623data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
624                    ($showIcons === true ? $this->mikioInlineIcon('gear') : '') .
625                    ($showText === true ? $lang['site_tools'] : '<span class="mikio-small-only">' .
626                    $lang['site_tools'] . '</span>') . '</a>';
627
628                $html .= '<div class="mikio-dropdown closed">' . implode('', $siteToolsMenu);
629
630                $html .= '</div>';
631                $html .= '</li>';
632
633                $html .= '<li id="dokuwiki__usertools" class="mikio-nav-dropdown">';
634                $html .= '<a id="mikio_dropdown_usertools" class="nav-link dropdown-toggle" href="#" role="button"
635data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
636                    ($showIcons === true ? $this->mikioInlineIcon('user') : '') .
637                    ($showText === true ? $lang['user_tools'] : '<span class="mikio-small-only">' .
638                    $lang['user_tools'] . '</span>') . '</a>';
639
640                $html .= '<div class="mikio-dropdown closed">' . implode('', $userToolsMenu);
641
642                $html .= '</div>';
643                $html .= '</li>';
644
645                break;
646
647            case $value_combine:
648                $html .= '<li class="mikio-nav-dropdown">';
649                $html .= '<a class="mikio-nav-link" href="#">' .
650                    ($showIcons === true ? $this->mikioInlineIcon('wrench') : '') .
651                    ($showText === true ? tpl_getLang('tools-menu') : '<span class="mikio-small-only">' .
652                    tpl_getLang('tools-menu') . '</span>') . '</a>';
653                $html .= '<div class="mikio-dropdown closed">';
654
655                $html .= '<h6 class="mikio-dropdown-header">' . $lang['page_tools'] . '</h6>';
656                foreach ($pageToolsMenu as $item) {
657                    $html .= $item;
658                }
659
660                $html .= '<div class="mikio-dropdown-divider"></div>';
661                $html .= '<h6 class="mikio-dropdown-header">' . $lang['site_tools'] . '</h6>';
662                foreach ($siteToolsMenu as $item) {
663                    $html .= $item;
664                }
665
666                $html .= '<div class="mikio-dropdown-divider"></div>';
667                $html .= '<h6 class="mikio-dropdown-header">' . $lang['user_tools'] . '</h6>';
668                foreach ($userToolsMenu as $item) {
669                    $html .= $item;
670                }
671
672                $html .= '</div>';
673                $html .= '</li>';
674                break;
675
676            default:    // separate
677                foreach ($siteToolsMenu as $item) {
678                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
679                }
680
681                foreach ($pageToolsMenu as $item) {
682                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
683                }
684
685                foreach ($userToolsMenu as $item) {
686                    $html .= '<li class="mikio-nav-item">' . $item . '</li>';
687                }
688
689                break;
690        }//end switch
691
692        $vswitch = plugin_load('syntax', 'versionswitch');
693        if ($vswitch && method_exists($vswitch, 'versionSelector')) {
694            $versionData = $vswitch->versionSelector();
695            $links = [];
696            $currentLinkText = "NA";
697
698            // Regex to find all 'a' tags
699            $pattern = '/<a\s+[^>]*href="([^"]+)"[^>]*>.*?<\/a>/i';
700            preg_match_all($pattern, $versionData, $matches);
701
702            // Loop through matches to build the links array
703            foreach ($matches[0] as $match) {
704                $links[] = $match;
705            }
706
707            // Regex to find the 'a' tag within 'curid' class span
708            $currentPattern = '/<li[^>]*class="[^"]*current[^"]*"[^>]*>\s*<a\s+[^>]*href="([^"]+)"[^>]*>([^<]+)<\/a>/i';
709            preg_match($currentPattern, $versionData, $currentMatch);
710
711            if (!empty($currentMatch)) {
712                $currentLinkText = $currentMatch[2]; // This will capture the text inside the <a> tag
713            }
714
715            $html .= '<li id="mikio__versionswitch" class="mikio-nav-dropdown">';
716            $html .= '<a id="mikio_dropdown_translate" class="nav-link dropdown-toggle" href="#" role="button"
717data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . $currentLinkText . '</a>';
718            $html .= '<div class="mikio-dropdown closed">';
719
720            foreach($links as $link) {
721                $classPattern = '/class="[^"]*"/i';
722                $html .= preg_replace($classPattern, 'class="mikio-nav-link mikio-dropdown-item"', $link);
723            }
724
725            $html .= '</div>';
726            $html .= '</li>';
727        }
728
729        $translation = plugin_load('helper', 'translation');
730        if ($translation !== null && method_exists($translation, 'showTranslations')) {
731            $html .= '<li id="mikio__translate" class="mikio-nav-dropdown">';
732            $html .= '<a id="mikio_dropdown_translate" class="nav-link dropdown-toggle" href="#" role="button"
733data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' .
734                $this->mikioInlineIcon('language') .
735                 '</a>';
736            $html .= '<div class="mikio-dropdown closed">';
737
738                $html .= $translation->showTranslations();
739
740            $html .= '</div>';
741            $html .= '</li>';
742        }
743
744        if ($this->getConf('showLightDark') === true) {
745            $autoLightDark = $this->getConf('autoLightDark');
746            $html .= '<li class="mikio-darklight">
747<a href="#" class="mikio-control mikio-button mikio-darklight-button">' .
748            ($autoLightDark === true ? $this->mikioInlineIcon('sunmoon', 'mikio-darklight-auto') : '') .
749            $this->mikioInlineIcon('sun', 'mikio-darklight-light') .
750            $this->mikioInlineIcon('moon', 'mikio-darklight-dark') .
751            '</a></li>';
752        }
753
754        $html .= '</ul>';
755
756        if ($print === true) {
757            echo $html;
758        }
759        return $html;
760    }
761
762
763    /**
764     * Create a nav element from a string. <uri>|<title>;
765     *
766     * @param string $str String to generate nav.
767     * @return string     nav elements generated
768     */
769    public function stringToNav(string $str): string
770    {
771        $html = '';
772
773        if (empty($str) === false) {
774            $items = explode(';', $str);
775            if (count($items) > 0) {
776                $html .= '<ul class="mikio-nav">';
777                foreach ($items as $item) {
778                    $parts = explode('|', $item);
779                    if ($parts > 1) {
780                        $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' .
781                            strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) .
782                            '</a></li>';
783                    }
784                }
785                $html .= '</ul>';
786            }
787        }
788
789        return $html;
790    }
791
792    /**
793     * print or return the main navbar
794     *
795     * @param boolean $print   Print the navbar.
796     * @param boolean $showSub Include the sub navbar.
797     * @return string          generated content
798     */
799    public function includeNavbar(bool $print = true, bool $showSub = false): string
800    {
801        global $conf, $USERINFO;
802
803        $homeUrl = wl();
804
805        if (plugin_isdisabled('showpageafterlogin') === false) {
806            $p = plugin_load('action', 'showpageafterlogin');
807            if (empty($p) === false) {
808                if (is_array($USERINFO) === true && count($USERINFO) > 0) {
809                    $homeUrl = wl($p->getConf('page_after_login'));
810                }
811            }
812        } else {
813            if (is_array($USERINFO) === true && count($USERINFO) > 0) {
814                $url = $this->getConf('brandURLUser');
815            } else {
816                $url = $this->getConf('brandURLGuest');
817            }
818            if (strlen($url) > 0) {
819                $homeUrl = $url;
820            }
821        }
822
823        $html = '<nav class="mikio-navbar' . (($this->getConf('stickyNavbar') === true) ? ' mikio-sticky' : '') .
824            '">';
825        $html .= '<div class="mikio-container">';
826        $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '" accesskey="h" title="Home [h]">';
827        if ($this->getConf('navbarUseTitleIcon') === true || $this->getConf('navbarUseTitleText') === true) {
828            // Brand image
829            if ($this->getConf('navbarUseTitleIcon') === true) {
830                $logo = $this->getMediaFile('logo', false);
831                if (empty($logo) === false) {
832                    $width = $this->getConf('navbarTitleIconWidth');
833                    $height = $this->getConf('navbarTitleIconHeight');
834                    $styles = '';
835
836                    if (strlen($width) > 0 || strlen($height) > 0) {
837                        if (ctype_digit($width) === true) {
838                            $styles .= 'max-width:' . intval($width) . 'px;';
839                        } elseif (preg_match('/^\d+(px|rem|em|%)$/', $width) === 1) {
840                            $styles .= 'max-width:' . $width . ';';
841                        } elseif (strcasecmp($width, 'none') === 0) {
842                            $styles .= 'max-width:none;';
843                        }
844
845                        if (ctype_digit($height) === true) {
846                            $styles .= 'max-height:' . intval($height) . 'px;';
847                        } elseif (preg_match('/^\d+(px|rem|em|%)$/', $height) === 1) {
848                            $styles .= 'max-height:' . $height . ';';
849                        } elseif (strcasecmp($height, 'none') === 0) {
850                            $styles .= 'max-height:none;';
851                        }
852
853                        if (strlen($styles) > 0) {
854                            $styles = ' style="' . $styles . '"';
855                        }
856                    }//end if
857
858                    $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image"' . $styles . '>';
859                }//end if
860            }//end if
861
862            // Brand title
863            if ($this->getConf('navbarUseTitleText') === true) {
864                $html .= '<div class="mikio-navbar-brand-title">';
865                $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>';
866                if ($this->getConf('navbarUseTaglineText') === true) {
867                    $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>';
868                }
869                $html .= '</div>';
870            }
871        }//end if
872        $html .= '</a>';
873        $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>';
874
875        // Menus
876        $html .= '<div class="mikio-navbar-collapse">';
877
878        $menus = [$this->getConf('navbarPosLeft', tpl_getLang('value_none')), $this->getConf('navbarPosMiddle', tpl_getLang('value_none')),
879            $this->getConf('navbarPosRight', tpl_getLang('value_none'))
880        ];
881
882        $value_custom = tpl_getLang('value_custom');
883        $value_search = tpl_getLang('value_search');
884        $value_dokuwiki = tpl_getLang('value_dokuwiki');
885
886        foreach ($menus as $menuType) {
887            switch ($menuType) {
888                case $value_custom:
889                    $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', ''));
890                    break;
891                case $value_search:
892                    $html .= '<div class="mikio-nav-item">';
893                    $html .= $this->includeSearch(false);
894                    $html .= '</div>';
895                    break;
896                case $value_dokuwiki:
897                    $html .= $this->includeDWMenu(false);
898                    break;
899            }
900        }
901
902        $html .= '</div>';
903        $html .= '</div>';
904        $html .= '</nav>';
905
906        // Sub Navbar
907        if ($showSub === true) {
908            $sub = $this->includePage('submenu', false);
909            if (empty($sub) === false) {
910                $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>';
911            }
912        }
913
914        if ($print === true) {
915            echo $html;
916        }
917        return $html;
918    }
919
920
921    /**
922     * Is there a sidebar
923     *
924     * @param   string $prefix Sidebar prefix to use when searching.
925     * @return  boolean        if sidebar exists
926     */
927    public function sidebarExists(string $prefix = ''): bool
928    {
929        global $conf;
930
931        if (strcasecmp($prefix, 'left') === 0) {
932            $prefix = '';
933        }
934
935        return $this->pageExists($conf['sidebar' . $prefix]);
936    }
937
938
939    /**
940     * Print or return the sidebar content
941     *
942     * @param   string  $prefix Sidebar prefix to use when searching.
943     * @param   boolean $print  Print the generated content to the output buffer.
944     * @param   boolean $parse  Parse the content.
945     * @return  string          generated content
946     */
947    public function includeSidebar(string $prefix = '', bool $print = true, bool $parse = true): string
948    {
949        global $conf, $ID;
950
951        $html = '';
952        $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix));
953        $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix));
954
955        if (empty($confPrefix) === true) {
956            $confPrefix = 'Left';
957        }
958        if (strcasecmp($prefix, 'left') === 0) {
959            $prefix = '';
960        }
961
962        $sidebarPage = empty($conf[$prefix . 'sidebar']) === true ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar'];
963
964        if (
965            $this->getConf('sidebarShow' . $confPrefix) === true && page_findnearest($sidebarPage) !== false &&
966            p_get_metadata($ID, 'nosidebar', false) === null
967        ) {
968            $content = $this->includePage($sidebarPage . 'header', false);
969            if (empty($content) === false) {
970                $html .= '<div class="mikio-sidebar-header">' . $content . '</div>';
971            }
972
973            if (empty($prefix) === true) {
974                $rows = [$this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'),
975                    $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4')
976                ];
977
978                $value_search = tpl_getLang('value_search');
979                $value_logged_in_user = tpl_getLang('value_logged_in_user');
980                $value_content = tpl_getLang('value_content');
981                $value_tags = tpl_getLang('value_tags');
982
983                foreach ($rows as $row) {
984                    switch ($row) {
985                        case $value_search:
986                            $html .= $this->includeSearch(false);
987                            break;
988                        case $value_logged_in_user:
989                            $html .= $this->includeLoggedIn(false);
990                            break;
991                        case $value_content:
992                            $content = $this->includePage($sidebarPage, false);
993                            if (empty($content) === false) {
994                                $html .= '<div class="mikio-sidebar-content">' . $content . '</div>';
995                            }
996                            break;
997                        case $value_tags:
998                            $html .= '<div class="mikio-tags"></div>';
999                    }
1000                }
1001            } else {
1002                $content = $this->includePage($sidebarPage, false);
1003                if (empty($content) === false) {
1004                    $html .= '<div class="mikio-sidebar-content">' . $content . '</div>';
1005                }
1006            }//end if
1007
1008            $content = $this->includePage($sidebarPage . 'footer', false);
1009            if (empty($content) === false) {
1010                $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>';
1011            }
1012        }//end if
1013
1014        if (empty($html) === true) {
1015            if (empty($prefix) === true && $this->getConf('sidebarAlwaysShowLeft') === true) {
1016                $html = '&nbsp;';
1017            }
1018            if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix)) === true) {
1019                $html = '&nbsp;';
1020            }
1021        }
1022
1023        if (empty($html) === false) {
1024            $sidebarClasses = [
1025                'mikio-sidebar',
1026                'mikio-sidebar-' . (empty($prefix) === true ? 'left' : $prefix)
1027            ];
1028
1029            $collapseClasses = ['mikio-sidebar-collapse'];
1030
1031            if(empty($prefix) === true && $this->getConf('stickyLeftSidebar') === true) {
1032                $collapseClasses[] = 'mikio-sidebar-sticky';
1033            }
1034
1035            $html = '<aside class="' . implode(' ', $sidebarClasses) . '"><a class="mikio-sidebar-toggle' .
1036                ($this->getConf('sidebarMobileDefaultCollapse') === true ? ' closed' : '') . '" href="#">' .
1037                tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="' . implode(' ', $collapseClasses) . '">' .
1038                $html . '</div></aside>';
1039        }
1040
1041        if ($parse === true) {
1042            $html = $this->includeIcons($html);
1043        }
1044        if ($print === true) {
1045            echo $html;
1046        }
1047
1048        return $html;
1049    }
1050
1051
1052    /**
1053     * Print or return the page tools content
1054     *
1055     * @param   boolean $print     Print the generated content to the output buffer.
1056     * @param   boolean $includeId Include the dw__pagetools id in the element.
1057     * @return  string             generated content
1058     */
1059    public function includePageTools(bool $print = true, bool $includeId = false): string
1060    {
1061        global $USERINFO;
1062
1063        $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0);
1064
1065        $html = '<nav' . ($includeId === true ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">';
1066        $html .= '<ul class="tools">';
1067
1068        $items = (new PageMenu())->getItems();
1069        foreach ($items as $item) {
1070            $classes = [];
1071            $classes[] = $item->getType();
1072            $attr = $item->getLinkAttributes();
1073
1074            if (empty($attr['class']) === false) {
1075                $classes = array_merge($classes, explode(' ', $attr['class']));
1076            }
1077
1078            $classes = array_unique($classes);
1079            $title = isset($attr['title']) && $attr['title'] !== 0 ? $attr['title'] : $item->getTitle();
1080
1081            $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType()), tpl_getLang('value_always'));
1082            if (
1083                $showItem !== false && (strcasecmp($showItem, 'always') === 0 ||
1084                (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) ||
1085                (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === true))
1086            ) {
1087                $html .= '<li class="' . implode(' ', $classes) . '">';
1088                $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' .
1089                    $title . '"' . (isset($attr['accesskey']) && $attr['accesskey'] !== '' ? ' accesskey="' . $attr['accesskey'] . '"' : '') . '><div class="icon">' . inlineSVG($item->getSvg()) .
1090                    '</div><span class="a11y">' . $item->getLabel() . '</span></a>';
1091                $html .= '</li>';
1092            }
1093        }//end foreach
1094
1095        $html .= '</ul>';
1096        $html .= '</nav>';
1097
1098        if ($print === true) {
1099            echo $html;
1100        }
1101        return $html;
1102    }
1103
1104
1105    /**
1106     * Print or return the search bar
1107     *
1108     * @param   boolean $print Print content.
1109     * @return  string         contents of the search bar
1110     */
1111    public function includeSearch(bool $print = true): string
1112    {
1113        $html = $this->parseHTML('tpl_searchform', function($dom) {
1114            $forms = $dom->getElementsByTagName('form');
1115            if (0 !== count($forms)) {
1116                foreach ($forms as $form) {
1117                    $currentClasses = $form->getAttribute('class');
1118                    $newClasses = trim($currentClasses . ' mikio-search');
1119                    $form->setAttribute('class', $newClasses);
1120                }
1121            }
1122
1123            if ($this->getConf('searchUseTypeahead') === true) {
1124                $inputs = $dom->getElementsByTagName('input');
1125                foreach ($inputs as $input) {
1126                    if ($input->getAttribute('name') === 'q') {
1127                        $inputClasses = $input->getAttribute('class');
1128                        $inputNewClasses = trim($inputClasses . ' search_typeahead');
1129                        $input->setAttribute('class', $inputNewClasses);
1130                    }
1131                }
1132            }
1133
1134            if (strcasecmp($this->getConf('searchButton'), tpl_getLang('value_icon')) === 0) {
1135                $buttons = $dom->getElementsByTagName('button');
1136                foreach($buttons as $button) {
1137                    if($button->getAttribute('type') === 'submit') {
1138                        $icon = $this->iconAsDomElement($dom, 'search');
1139                        $button->nodeValue = '';
1140                        $button->appendChild($icon);
1141                    }
1142                }
1143            }
1144        });
1145
1146        if ($print === true) {
1147            echo $html;
1148        }
1149        return $html;
1150    }
1151
1152
1153    /**
1154     * Print or return content
1155     *
1156     * @param   boolean $print Print content.
1157     * @return  string         contents
1158     */
1159    public function includeContent(bool $print = true): string
1160    {
1161        ob_start();
1162        tpl_content(false);
1163        $html = ob_get_clean();
1164
1165        $html = $this->includeIcons($html);
1166        $html = $this->parseContent($html);
1167
1168        $html .= '<div style="clear:both"></div>';
1169
1170        if ($this->getConf('heroTitle') === false && $this->getConf('tagsShowHero') === true) {
1171            $html = '<div class="mikio-tags"></div>' . $html;
1172        }
1173
1174        $html = '<div class="mikio-article-content">' . $html . '</div>';
1175
1176        if ($print === true) {
1177            echo $html;
1178        }
1179        return $html;
1180    }
1181
1182    private function custom_tpl_pageinfo($ret = false)
1183    {
1184        global $conf;
1185        global $lang;
1186        global $INFO;
1187        global $ID;
1188
1189        // return if we are not allowed to view the page
1190        if (!auth_quickaclcheck($ID)) {
1191            return false;
1192        }
1193
1194        if ($INFO['exists']) {
1195            $file = $INFO['filepath'];
1196            if (!$conf['fullpath']) {
1197                if ($INFO['rev']) {
1198                    $file = str_replace($conf['olddir'] . '/', '', $file);
1199                } else {
1200                    $file = str_replace($conf['datadir'] . '/', '', $file);
1201                }
1202            }
1203            $file = utf8_decodeFN($file);
1204            $date = dformat($INFO['lastmod']);
1205
1206            $string = $this->getConf('footerPageInfoText', '');
1207
1208            // replace lang items
1209            $string = preg_replace_callback('/%([^%]+)%/', static function ($matches) use ($lang) {
1210                return $lang[$matches[1]] ?? '';
1211            }, $string);
1212
1213            $options = [
1214                'file' => '<bdi>' . $file . '</bdi>',
1215                'date' => $date,
1216                'user' => $INFO['editor'] ? '<bdi>' . editorinfo($INFO['editor']) . '</bdi>' : $lang['external_edit']
1217            ];
1218
1219            if (!empty($_SERVER['REMOTE_USER'])) {
1220                $options['loggedin'] = true;
1221            }
1222
1223            if ($INFO['locked']) {
1224                $options['locked'] = '<bdi>' . editorinfo($INFO['locked']) . '</bdi>';
1225            }
1226
1227            $parser = new ParensParser();
1228            $result = $parser->parse($string);
1229
1230            $parserIterate = function ($arr, $func) use ($options) {
1231                $str = '';
1232
1233                foreach ($arr as $value) {
1234                    if (is_array($value)) {
1235                        $str .= $func($value, $func);
1236                    } else {
1237                        if (preg_match('/^([a-zA-Z]+)=(.*)/', $value, $matches)) {
1238                            $key = strtolower($matches[1]); // Extract the key (a-zA-Z part)
1239
1240                            if (isset($options[$key])) {
1241                                $str .= $matches[2];
1242                            } else {
1243                                return $str;
1244                            }
1245                        } else {
1246                            $str .= $value;
1247                        }
1248                    }
1249                }//end foreach
1250
1251                return $str;
1252            };
1253
1254            $string = $parserIterate($result, $parserIterate);
1255
1256            $string = preg_replace_callback('/{([^}]+)}/', static function ($matches) use ($options) {
1257                $key = strtolower($matches[1]);
1258                return $options[$key] ?? '';
1259            }, $string);
1260
1261            if ($ret) {
1262                return $string;
1263            }
1264
1265            echo $string;
1266            return true;
1267        }//end if
1268
1269        return false;
1270    }
1271
1272    /**
1273     * Print or return footer
1274     *
1275     * @param   boolean $print Print footer.
1276     * @return  string         HTML string containing footer
1277     */
1278    public function includeFooter(bool $print = true): string
1279    {
1280        global $ACT;
1281
1282        $html = '<footer class="mikio-footer">';
1283        $html .= '<div class="doc">' . $this->custom_tpl_pageinfo(true) . '</div>';
1284        $html .= $this->includePage('footer', false);
1285
1286        $html .= $this->stringToNav($this->getConf('footerCustomMenuText'));
1287
1288        if ($this->getConf('footerSearch') === true) {
1289            $html .= '<div class="mikio-footer-search">';
1290            $html .= $this->includeSearch(false);
1291            $html .= '</div>';
1292        }
1293
1294        $showPageTools = $this->getConf('pageToolsFooter');
1295        if (
1296            strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, tpl_getLang('value_always')) === 0 ||
1297                ($this->userCanEdit() === true && strcasecmp($showPageTools, tpl_getLang('value_page_editors')) === 0))
1298        ) {
1299            $html .= $this->includePageTools(false);
1300        }
1301
1302        $meta['licenseType']            = ['multichoice', '_choices' => [tpl_getLang('value_none'), tpl_getLang('value_badge'), tpl_getLang('value_button')]];
1303        /** @noinspection PhpArrayWriteIsNotUsedInspection */
1304        $meta['licenseImageOnly']       = ['onoff'];
1305
1306        $licenseType = $this->getConf('licenseType');
1307        if ($licenseType !== 'none') {
1308            $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true);
1309        }
1310
1311        $html .= '</footer>';
1312
1313        if ($print === true) {
1314            echo $html;
1315        }
1316        return $html;
1317    }
1318
1319
1320    /**
1321     * Print or return breadcrumb trail
1322     *
1323     * @param   boolean $print Print out trail.
1324     * @param   boolean $parse Parse trail before printing.
1325     * @return  string         HTML string containing breadcrumbs
1326     */
1327    public function includeBreadcrumbs(bool $print = true, bool $parse = true): string
1328    {
1329        global $conf, $ID, $lang, $ACT;
1330
1331        if (
1332            ($this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 &&
1333                strcasecmp($ACT, 'show') === 0) || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0
1334        ) {
1335            return '';
1336        }
1337
1338        $html = '<div class="mikio-breadcrumbs">';
1339        $html .= '<div class="mikio-container">';
1340        if (strcasecmp($ACT, 'show') === 0) {
1341            if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) {
1342                ob_start();
1343                tpl_breadcrumbs();
1344                $html .= ob_get_clean();
1345            } else {
1346                $sep = '•';
1347                $prefix = $lang['breadcrumb'];
1348
1349                if ($this->getConf('breadcrumbSep') === true) {
1350                    $sep = $this->getConf('breadcrumbSepText');
1351                    $img = $this->getMediaFile('breadcrumb-sep', false);
1352
1353                    if ($img !== false) {
1354                        $sep = '<img src="' . $img . '">';
1355                    }
1356                }
1357
1358                if ($this->getConf('breadcrumbPrefix') === true) {
1359                    $prefix = $this->getConf('breadcrumbPrefixText');
1360                    $img = $this->getMediaFile('breadcrumb-prefix', false);
1361
1362                    if ($img !== false) {
1363                        $prefix = '<img src="' . $img . '">';
1364                    }
1365                }
1366
1367                $crumbs = breadcrumbs();
1368
1369                $html .= '<ul>';
1370                if (empty($prefix) === false) {
1371                    $html .= '<li class="prefix">' . $prefix . '</li>';
1372                }
1373
1374                $last = count($crumbs);
1375                $i    = 0;
1376                foreach ($crumbs as $id => $name) {
1377                    $i++;
1378                    if ($i !== 1) {
1379                        $html .= '<li class="sep">' . $sep . '</li>';
1380                    }
1381                    $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>';
1382                    $html .= tpl_pagelink($id, null, true);
1383                    $html .= '</li>';
1384                }
1385
1386                $html .= '</ul>';
1387            }//end if
1388        }//end if
1389
1390        $html .= '</div>';
1391        $html .= '</div>';
1392
1393        if ($parse === true) {
1394            $html = $this->includeIcons($html);
1395        }
1396        if ($print === true) {
1397            echo $html;
1398        }
1399        return $html;
1400    }
1401
1402    /**
1403     * Print or return you are here trail
1404     *
1405     * @param   boolean $print Print out trail.
1406     * @param   boolean $parse Parse trail before printing.
1407     * @return  string         HTML string containing breadcrumbs
1408     */
1409    public function includeYouAreHere(bool $print = true, bool $parse = true): string
1410    {
1411        global $conf, $ID, $lang, $ACT;
1412
1413        if (
1414            ($this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 &&
1415                strcasecmp($ACT, 'show') === 0) || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0
1416        ) {
1417            return '';
1418        }
1419
1420        $html = '<div class="mikio-youarehere">';
1421        $html .= '<div class="mikio-container">';
1422        if (strcasecmp($ACT, 'show') === 0) {
1423            if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) {
1424                $html .= '<div class="mikio-bcdw">';
1425                ob_start();
1426                tpl_youarehere();
1427                $html .= ob_get_clean();
1428                $html .= '</div>';
1429            } else {
1430                $sep = ' » ';
1431                $prefix = $lang['youarehere'];
1432
1433                if ($this->getConf('youarehereSep') === true) {
1434                    $sep = $this->getConf('youarehereSepText');
1435                    $img = $this->getMediaFile('youarehere-sep', false);
1436
1437                    if ($img !== false) {
1438                        $sep = '<img src="' . $img . '">';
1439                    }
1440                }
1441
1442                if ($this->getConf('youareherePrefix') === true) {
1443                    $prefix = $this->getConf('youareherePrefixText');
1444                    $img = $this->getMediaFile('youarehere-prefix', false);
1445
1446                    if ($img !== false) {
1447                        $prefix = '<img src="' . $img . '">';
1448                    }
1449                }
1450
1451                $html .= '<ul>';
1452                if (empty($prefix) === false) {
1453                    $html .= '<li class="prefix">' . $prefix . '</li>';
1454                }
1455                $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>';
1456
1457                $parts = explode(':', $ID);
1458                $count = count($parts);
1459
1460                $part = '';
1461                for ($i = 0; $i < ($count - 1); $i++) {
1462                    $part .= $parts[$i] . ':';
1463                    $page = $part;
1464                    if ($page === $conf['start']) {
1465                        continue;
1466                    }
1467
1468                    $html .= '<li class="sep">' . $sep . '</li>';
1469                    $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>';
1470                }
1471
1472                $page = '';
1473
1474                if ($this->dwVersionNumber() >= 20200729) {
1475                    $page = cleanID($page);
1476                } else {
1477                    $exists = false;
1478                    /** @noinspection PhpDeprecationInspection */
1479                    resolve_pageid('', $page, $exists);
1480                }
1481
1482                if ((isset($page) === true && $page === $part . $parts[$i]) === false) {
1483                    $page = $part . $parts[$i];
1484                    if ($page !== $conf['start']) {
1485                        $html .= '<li class="sep">' . $sep . '</li>';
1486                        $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>';
1487                    }
1488                }
1489
1490                $html .= '</ul>';
1491            }//end if
1492
1493            $showLast = $this->getConf('youarehereShowLast');
1494            if ($showLast !== 0) {
1495                preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches);
1496                if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) {
1497                    $count = count($matches[0]);
1498                    $list = '';
1499
1500                    // Show Home
1501                    $list .= $matches[0][0] . $matches[0][1];
1502
1503                    $list .= '<li>...</li>';
1504                    for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) {
1505                        $list .= $matches[0][$i];
1506                    }
1507
1508                    $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html);
1509                }
1510            }
1511
1512            $value_none = tpl_getLang('value_none');
1513            $value_home = tpl_getLang('value_home');
1514            $value_icon = tpl_getLang('value_icon');
1515
1516            switch ($this->getConf('youarehereHome')) {
1517                case $value_none:
1518                    $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2);
1519                    break;
1520                case $value_home:
1521                    $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1);
1522                    break;
1523                case $value_icon:
1524                    $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' .
1525                        $this->mikioInlineIcon('home') . '$3', $html, 1);
1526                    break;
1527            }
1528        } else {
1529            $html .= '&#8810; ';
1530            if (isset($_GET['page']) === true) {
1531                $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">Back</a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;';
1532            }
1533            $html .= '<a href="' . wl($ID) . '">View Page</a>';
1534        }//end if
1535
1536        $html .= '</div>';
1537        $html .= '</div>';
1538
1539        if ($parse === true) {
1540            $html = $this->includeIcons($html);
1541        }
1542        if ($print === true) {
1543            echo $html;
1544        }
1545        return $html;
1546    }
1547
1548    /**
1549     * Get Page Title
1550     *
1551     * @return string page title
1552     */
1553    public function parsePageTitle(): string
1554    {
1555        global $ID;
1556
1557        $title = p_get_first_heading($ID);
1558        if (strlen($title) <= 0) {
1559            $title = tpl_pagetitle(null, true);
1560        }
1561        return $this->includeIcons($title);
1562    }
1563
1564
1565    /**
1566     * Print or return hero block
1567     *
1568     * @param   boolean $print Print content.
1569     * @return  string         contents of hero
1570     */
1571    public function includeHero(bool $print = true): string
1572    {
1573        $html = '';
1574
1575        if ($this->getConf('heroTitle') === true) {
1576            $html .= '<div class="mikio-hero">';
1577            $html .= '<div class="mikio-container">';
1578            $html .= '<div class="mikio-hero-text">';
1579            if (strcasecmp($this->getConf('youareherePosition'), tpl_getLang('value_hero')) === 0) {
1580                $html .= $this->includeYouAreHere(false);
1581            }
1582            if (strcasecmp($this->getConf('breadcrumbPosition'), tpl_getLang('value_hero')) === 0) {
1583                $html .= $this->includeBreadcrumbs(false);
1584            }
1585
1586            $html .= '<h1 class="mikio-hero-title">';
1587            $html .= $this->parsePageTitle();    // No idea why this requires a blank space afterward to work?
1588            $html .= '</h1>';
1589            $html .= '<h2 class="mikio-hero-subtitle"></h2>';
1590            $html .= '</div>';
1591
1592            $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true));
1593            $hero_image_resize_class = '';
1594            if (empty($hero_image) === false) {
1595                $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"';
1596                $hero_image_resize_class = ' mikio-hero-image-resize';
1597            }
1598
1599            $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image .
1600                '>';
1601
1602            if($this->getConf('tagsShowHero') === true) {
1603                $html .= '<div class="mikio-tags"></div>';
1604            }
1605
1606            $html .= '</div>';
1607
1608            $html .= '</div>';
1609            $html .= '</div>';
1610        }//end if
1611
1612        if ($print === true) {
1613            echo $html;
1614        }
1615
1616        return $html;
1617    }
1618
1619
1620    /**
1621     * Print or return out TOC
1622     *
1623     * @param   boolean $print Print TOC.
1624     * @param   boolean $parse Parse icons.
1625     * @return  string         contents of TOC
1626     */
1627    public function includeTOC(bool $print = true, bool $parse = true): string
1628    {
1629        $html = '';
1630
1631        $tocHtml = tpl_toc(true);
1632
1633        if (empty($tocHtml) === false) {
1634            $tocHtml = preg_replace(
1635                '/(<h3.+?toggle.+?>)(.+?)<\/h3>/',
1636                '$1' .
1637                $this->mikioInlineIcon('hamburger', 'hamburger') . '$2' .
1638                $this->mikioInlineIcon('down-arrow', 'down-arrow') . '</h3>',
1639                $tocHtml
1640            );
1641            $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml);
1642            $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml);
1643
1644            $html .= '<div class="mikio-toc">';
1645            $html .= $tocHtml;
1646            $html .= '</div>';
1647        }
1648
1649        if ($parse === true) {
1650            $html = $this->includeIcons($html);
1651        }
1652
1653        if ($print === true) {
1654            echo $html;
1655        }
1656
1657        return $html;
1658    }
1659
1660
1661    /**
1662     * Parse the string and replace icon elements with included icon libraries
1663     *
1664     * @param   string $str Content to parse.
1665     * @return  string      parsed string
1666     */
1667    public function includeIcons(string $str): string
1668    {
1669        global $ACT, $MIKIO_ICONS;
1670
1671        $iconTag = $this->getConf('iconTag', 'icon');
1672        if (empty($iconTag) === true) {
1673            return $str;
1674        }
1675
1676        if (
1677            in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true ||
1678            (strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0)
1679        ) {
1680            $content = $str;
1681            $preview = null;
1682
1683            $html = null;
1684            if (strcasecmp($ACT, 'preview') === 0) {
1685                $html = new simple_html_dom();
1686                $html->stripRNAttrValues = false;
1687                $html->load($str, true, false);
1688
1689                $preview = $html->find('div.preview');
1690                if (is_array($preview) === true && count($preview) > 0) {
1691                    $content = $preview[0]->innertext;
1692                }
1693            }
1694
1695            $page_regex = '/(.*)/';
1696            if (stripos($str, '<pre') !== false) {
1697                $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/';
1698            }
1699
1700            $content = preg_replace_callback($page_regex, function ($icons) {
1701                $iconTag = $this->getConf('iconTag', 'icon');
1702
1703                return preg_replace_callback(
1704                    '/&lt;' . $iconTag . ' ([\w\- #]*)&gt;(?=[^>]*(<|$))/',
1705                    function ($matches) {
1706                        global $MIKIO_ICONS;
1707
1708                        $s = $matches[0];
1709
1710                        if (count($MIKIO_ICONS) > 0) {
1711                            $icon = $MIKIO_ICONS[0];
1712
1713                            if (count($matches) > 1) {
1714                                $e = explode(' ', $matches[1]);
1715
1716                                if (count($e) > 1) {
1717                                    foreach ($MIKIO_ICONS as $iconItem) {
1718                                        if (strcasecmp($iconItem['name'], $e[0]) === 0) {
1719                                            $icon = $iconItem;
1720
1721                                            $s = $icon['insert'];
1722                                            for ($i = 1; $i < 9; $i++) {
1723                                                if (count($e) < $i || empty($e[$i]) === true) {
1724                                                    if (isset($icon['$' . $i]) === true) {
1725                                                        $s = str_replace('$' . $i, $icon['$' . $i], $s);
1726                                                    }
1727                                                } else {
1728                                                    $s = str_replace('$' . $i, $e[$i], $s);
1729                                                }
1730                                            }
1731
1732                                            $dir = '';
1733                                            if (isset($icon['dir']) === true) {
1734                                                $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/';
1735                                            }
1736
1737                                            $s = str_replace('$0', $dir, $s);
1738
1739                                            break;
1740                                        }//end if
1741                                    }//end foreach
1742                                } else {
1743                                    $s = str_replace('$1', $matches[1], $icon['insert']);
1744                                }//end if
1745                            }//end if
1746                        }//end if
1747
1748                        $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count);
1749                        if ($count === 0) {
1750                            $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s);
1751                        }
1752
1753                        return $s;
1754                    },
1755                    $icons[0]
1756                );
1757            }, $content);
1758
1759            if (strcasecmp($ACT, 'preview') === 0) {
1760                if (is_array($preview) === true && count($preview) > 0) {
1761                    $preview[0]->innertext = $content;
1762                }
1763
1764                $str = $html->save();
1765                $html->clear();
1766                unset($html);
1767            } else {
1768                $str = $content;
1769            }
1770        }//end if
1771
1772        return $str;
1773    }
1774
1775    /**
1776     * Parse HTML for theme
1777     *
1778     * @param   string $content HTML content to parse.
1779     * @return  string          Parsed content
1780     */
1781    public function parseContent(string $content): string
1782    {
1783        global $INPUT, $ACT;
1784
1785        // Add Mikio Section titles
1786        if (strcasecmp($INPUT->str('page'), 'config') === 0) {
1787            $admin_sections = [
1788                // Section      Insert Before                 Icon
1789                'navbar'        => ['navbarUseTitleIcon',      ''],
1790                'search'        => ['searchButton',            ''],
1791                'hero'          => ['heroTitle',               ''],
1792                'tags'          => ['tagsConsolidate',         ''],
1793                'breadcrumb'    => ['breadcrumbHideHome',      ''],
1794                'youarehere'    => ['youarehereHideHome',      ''],
1795                'sidebar'       => ['sidebarShowLeft',         ''],
1796                'toc'           => ['tocFull',                 ''],
1797                'pagetools'     => ['pageToolsFloating',       ''],
1798                'footer'        => ['footerPageInfoText',      ''],
1799                'license'       => ['licenseType',             ''],
1800                'acl'           => ['includePageUseACL',       ''],
1801                'sticky'        => ['stickyTopHeader',         ''],
1802            ];
1803
1804            foreach ($admin_sections as $section => $items) {
1805                $search = $items[0];
1806                $icon   = $items[1];
1807
1808                $content = preg_replace(
1809                    '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/',
1810                    '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) .
1811                        tpl_getLang('config_' . $section) .
1812                        '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' .
1813                        $search . '</span>',
1814                    $content
1815                );
1816            }
1817        } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) {
1818            $mikioPluginMissing = true;
1819            /* Hide plugin fields if not installed */
1820            if (plugin_load('action', 'mikioplugin') !== null) {
1821                $mikioPluginMissing = false;
1822            }
1823
1824            $style_headers = [
1825                ['title' => 'Base', 'starts_with' => '__text_'],
1826                ['title' => 'Code', 'starts_with' => '__code_'],
1827                ['title' => 'Controls', 'starts_with' => '__control_'],
1828                ['title' => 'Header', 'starts_with' => '__topheader_'],
1829                ['title' => 'Navbar', 'starts_with' => '__navbar_'],
1830                ['title' => 'Sub Navbar', 'starts_with' => '__subnavbar_'],
1831                ['title' => 'Tags', 'starts_with' => '__tag_background_color_'],
1832                ['title' => 'Breadcrumbs', 'starts_with' => '__breadcrumb_'],
1833                ['title' => 'Hero', 'starts_with' => '__hero_'],
1834                ['title' => 'Sidebar', 'starts_with' => '__sidebar_'],
1835                ['title' => 'Content', 'starts_with' => '__content_'],
1836                ['title' => 'TOC', 'starts_with' => '__toc_'],
1837                ['title' => 'Page Tools', 'starts_with' => '__pagetools_'],
1838                ['title' => 'Footer', 'starts_with' => '__footer_'],
1839                ['title' => 'Table', 'starts_with' => '__table_'],
1840                ['title' => 'Dropdown', 'starts_with' => '__dropdown_'],
1841                ['title' => 'Section Edit', 'starts_with' => '__section_edit_'],
1842                ['title' => 'Tree', 'starts_with' => '__tree_'],
1843                ['title' => 'Tabs', 'starts_with' => '__tab_'],
1844                ['title' => 'Mikio Plugin', 'starts_with' => '__plugin_', 'heading' => 'h2',
1845                    'hidden' => $mikioPluginMissing
1846                ],
1847                ['title' => 'Primary Colours', 'starts_with' => '__plugin_primary_', 'hidden' => $mikioPluginMissing],
1848                ['title' => 'Secondary Colours', 'starts_with' => '__plugin_secondary_',
1849                    'hidden' => $mikioPluginMissing
1850                ],
1851                ['title' => 'Success Colours', 'starts_with' => '__plugin_success_', 'hidden' => $mikioPluginMissing],
1852                ['title' => 'Danger Colours', 'starts_with' => '__plugin_danger_', 'hidden' => $mikioPluginMissing],
1853                ['title' => 'Warning Colours', 'starts_with' => '__plugin_warning_', 'hidden' => $mikioPluginMissing],
1854                ['title' => 'Info Colours', 'starts_with' => '__plugin_info_', 'hidden' => $mikioPluginMissing],
1855                ['title' => 'Light Colours', 'starts_with' => '__plugin_light_', 'hidden' => $mikioPluginMissing],
1856                ['title' => 'Dark Colours', 'starts_with' => '__plugin_dark_', 'hidden' => $mikioPluginMissing],
1857                ['title' => 'Link Colours', 'starts_with' => '__plugin_link_', 'hidden' => $mikioPluginMissing],
1858                ['title' => 'Carousel', 'starts_with' => '__plugin_carousel_', 'hidden' => $mikioPluginMissing],
1859                ['title' => 'Steps', 'starts_with' => '__plugin_steps_', 'hidden' => $mikioPluginMissing],
1860                ['title' => 'Tabgroup', 'starts_with' => '__plugin_tabgroup_', 'hidden' => $mikioPluginMissing],
1861                ['title' => 'Tooltip', 'starts_with' => '__plugin_tooltip_', 'hidden' => $mikioPluginMissing],
1862                ['title' => 'Dark Mode', 'starts_with' => '__darkmode_', 'heading' => 'h2'],
1863                ['title' => 'Base', 'starts_with' => '__darkmode_text_'],
1864                ['title' => 'Code', 'starts_with' => '__darkmode_code_'],
1865                ['title' => 'Controls', 'starts_with' => '__darkmode_control_'],
1866                ['title' => 'Header', 'starts_with' => '__darkmode_topheader_'],
1867                ['title' => 'Navbar', 'starts_with' => '__darkmode_navbar_'],
1868                ['title' => 'Sub Navbar', 'starts_with' => '__darkmode_subnavbar_'],
1869                ['title' => 'Tags', 'starts_with' => '__darkmode_tag_background_color_'],
1870                ['title' => 'Breadcrumbs', 'starts_with' => '__darkmode_breadcrumb_'],
1871                ['title' => 'Hero', 'starts_with' => '__darkmode_hero_'],
1872                ['title' => 'Sidebar', 'starts_with' => '__darkmode_sidebar_'],
1873                ['title' => 'Content', 'starts_with' => '__darkmode_content_'],
1874                ['title' => 'TOC', 'starts_with' => '__darkmode_toc_'],
1875                ['title' => 'Page Tools', 'starts_with' => '__darkmode_pagetools_'],
1876                ['title' => 'Footer', 'starts_with' => '__darkmode_footer_'],
1877                ['title' => 'Table', 'starts_with' => '__darkmode_table_'],
1878                ['title' => 'Dropdown', 'starts_with' => '__darkmode_dropdown_'],
1879                ['title' => 'Section Edit', 'starts_with' => '__darkmode_section_edit_'],
1880                ['title' => 'Tree', 'starts_with' => '__darkmode_tree_'],
1881                ['title' => 'Tabs', 'starts_with' => '__darkmode_tab_'],
1882                ['title' => 'Mikio Plugin (Dark mode)', 'starts_with' => '__plugin_darkmode_', 'heading' => 'h2',
1883                    'hidden' => $mikioPluginMissing
1884                ],
1885                ['title' => 'Primary Colours', 'starts_with' => '__plugin_darkmode_primary_',
1886                    'hidden' => $mikioPluginMissing
1887                ],
1888                ['title' => 'Secondary Colours', 'starts_with' => '__plugin_darkmode_secondary_',
1889                    'hidden' => $mikioPluginMissing
1890                ],
1891                ['title' => 'Success Colours', 'starts_with' => '__plugin_darkmode_success_',
1892                    'hidden' => $mikioPluginMissing
1893                ],
1894                ['title' => 'Danger Colours', 'starts_with' => '__plugin_darkmode_danger_',
1895                    'hidden' => $mikioPluginMissing
1896                ],
1897                ['title' => 'Warning Colours', 'starts_with' => '__plugin_darkmode_warning_',
1898                    'hidden' => $mikioPluginMissing
1899                ],
1900                ['title' => 'Info Colours', 'starts_with' => '__plugin_darkmode_info_',
1901                    'hidden' => $mikioPluginMissing
1902                ],
1903                ['title' => 'Light Colours', 'starts_with' => '__plugin_darkmode_light_',
1904                    'hidden' => $mikioPluginMissing
1905                ],
1906                ['title' => 'Dark Colours', 'starts_with' => '__plugin_darkmode_dark_',
1907                    'hidden' => $mikioPluginMissing
1908                ],
1909                ['title' => 'Link Colours', 'starts_with' => '__plugin_darkmode_link_',
1910                    'hidden' => $mikioPluginMissing
1911                ],
1912                ['title' => 'Carousel', 'starts_with' => '__plugin_darkmode_carousel_',
1913                    'hidden' => $mikioPluginMissing
1914                ],
1915                ['title' => 'Steps', 'starts_with' => '__plugin_darkmode_steps_', 'hidden' => $mikioPluginMissing],
1916                ['title' => 'Tabgroup', 'starts_with' => '__plugin_darkmode_tabgroup_',
1917                    'hidden' => $mikioPluginMissing
1918                ],
1919                ['title' => 'Tooltip', 'starts_with' => '__plugin_darkmode_tooltip_', 'hidden' => $mikioPluginMissing],
1920            ];
1921
1922            foreach ($style_headers as $header) {
1923                if (array_key_exists('heading', $header) === false) {
1924                    $header['heading'] = 'h3';
1925                }
1926
1927                if (array_key_exists('hidden', $header) === false) {
1928                    $header['hidden'] = false;
1929                }
1930
1931                $content = preg_replace(
1932                    '/(<tr>\s*<td>\s*<label for="tpl__' . $header['starts_with'] . '.+?<\/tr>)/s',
1933                    '</tbody></table><' . $header['heading'] . ' style="display:' .
1934                    ($header['hidden'] === true ? 'none' : 'block') . '">' .
1935                    $header['title'] . '</' . $header['heading'] . '>
1936                    <table style="display:' . ($header['hidden'] === true ? 'none' : 'table') . '"><tbody>$1',
1937                    $content,
1938                    1
1939                );
1940            }
1941
1942            $content = preg_replace_callback('/<input type="color"[^>]*>/', function ($match) {
1943                // Get the ID of the <input type="color"> element
1944                preg_match('/id="([^"]*)"/', $match[0]);
1945
1946                // Replace type with text and remove the id attribute
1947                $replacement = preg_replace(
1948                    ['/type="color"/', '/id="([^"]*)"/'],
1949                    ['type="text" class="mikio-color-text-input"', 'for="$1"'],
1950                    $match[0]
1951                );
1952
1953                return '<div class="mikio-color-picker">' . $replacement . $match[0] . '</div>';
1954            }, $content);
1955        }//end if
1956
1957        if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) {
1958            $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content);
1959        }
1960
1961        // Page Revisions - Table Fix
1962        if (strpos($content, 'id="page__revisions"') !== false) {
1963            $content = preg_replace(
1964                '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/',
1965                '<span>$1</span>',
1966                $content
1967            );
1968        }
1969
1970        $html = new simple_html_dom();
1971        $html->stripRNAttrValues = false;
1972        $html->load($content, true, false);
1973
1974        /* Buttons */
1975        foreach ($html->find('#config__manager button') as $node) {
1976            $c = explode(' ', $node->class);
1977            if (in_array('mikio-button', $c) === false) {
1978                $c[] = 'mikio-button';
1979            }
1980            $node->class = implode(' ', $c);
1981        }
1982
1983
1984        /* Buttons - Primary */
1985        foreach ($html->find('#config__manager [type=submit]') as $node) {
1986            $c = explode(' ', $node->class);
1987            if (in_array('mikio-primary', $c) === false) {
1988                $c[] = 'mikio-primary';
1989            }
1990            $node->class = implode(' ', $c);
1991        }
1992
1993        /* Hide page title if hero is enabled */
1994        if ($this->getConf('heroTitle') === true && $ACT !== 'preview') {
1995            $pageTitle = $this->parsePageTitle();
1996
1997            foreach ($html->find('h1,h2,h3,h4') as $elm) {
1998                if ($elm->innertext === $pageTitle) {
1999                    // $elm->innertext = '';
2000                    $elm->setAttribute('style', 'display:none');
2001
2002                    break;
2003                }
2004            }
2005        }
2006
2007        /* Hero subtitle */
2008        foreach ($html->find('p') as $elm) {
2009            if (preg_match('/[~-]~hero-subtitle (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
2010                $subtitle = $matches[1];
2011                $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')';
2012
2013                $elm->innertext = preg_replace('/[~-]~hero-subtitle (.+?)~[~-]/ui', '', $elm->innertext);
2014                break;
2015            }
2016        }
2017
2018        /* Hero image */
2019        foreach ($html->find('p') as $elm) {
2020            preg_match('/[~-]~hero-image (.+?)~[~-](?!.?")/ui', $elm->innertext, $matches);
2021            if (count($matches) > 0) {
2022                preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches);
2023                if (count($imageTagMatches) > 0) {
2024                    $image = $imageTagMatches[1];
2025                } else {
2026                    preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches);
2027                    if (count($imageTagMatches) > 0) {
2028                        $image = $imageTagMatches[1];
2029                    } else {
2030                        $image = strip_tags($matches[1]);
2031                        if (stripos($image, ':') === false) {
2032                            $image = str_replace(['{', '}'], '', $image);
2033                            $i = stripos($image, '?');
2034                            if ($i !== false) {
2035                                $image = substr($image, 0, $i);
2036                            }
2037
2038                            $image = ml($image, '', true, '');
2039                        }
2040                    }
2041                }
2042
2043                $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')';
2044
2045                $elm->innertext = preg_replace('/[~-]~hero-image (.+?)~[~-].*/ui', '', $elm->innertext);
2046            }//end if
2047        }//end foreach
2048
2049        /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color]
2050        [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */
2051        foreach ($html->find('p') as $elm) {
2052            if (preg_match('/[~-]~hero-colors (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
2053                $subtitle = $matches[1];
2054                $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $subtitle . '\')';
2055
2056                $elm->innertext = preg_replace('/[~-]~hero-colors (.+?)~[~-]/ui', '', $elm->innertext);
2057                break;
2058            }
2059        }
2060
2061        /* Hide parts - ~~hide-parts [parts]~~  */
2062        foreach ($html->find('p') as $elm) {
2063            if (preg_match('/[~-]~hide-parts (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) {
2064                $parts = explode(' ', $matches[1]);
2065                $script = '';
2066
2067                foreach ($parts as $part) {
2068                    if (strlen($part) > 0) {
2069                        $script .= 'mikio.hidePart(\'' . $part . '\');';
2070                    }
2071                }
2072
2073                if (strlen($script) > 0) {
2074                    $this->footerScript['hide-parts'] = $script;
2075                }
2076
2077                $elm->innertext = preg_replace('/[~-]~hide-parts (.+?)~[~-]/ui', '', $elm->innertext);
2078                break;
2079            }
2080        }//end foreach
2081
2082
2083        /* Page Tags (tag plugin) */
2084        if ($this->getConf('tagsConsolidate') === true) {
2085            $tags = '';
2086            foreach ($html->find('div.tags a') as $elm) {
2087                $tags .= $elm->outertext;
2088            }
2089
2090            foreach ($html->find('div.tags') as $elm) {
2091                $elm->innertext = '';
2092                $elm->setAttribute('style', 'display:none');
2093            }
2094
2095            if (empty($tags) === false) {
2096                $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')';
2097            }
2098        }
2099
2100        // Configuration Manager
2101        if (strcasecmp($INPUT->str('page'), 'config') === 0) {
2102            // Additional save buttons
2103            foreach ($html->find('#config__manager') as $cm) {
2104                $saveButtons = '';
2105
2106                foreach ($cm->find('p') as $elm) {
2107                    $saveButtons = $elm->outertext;
2108                    $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons);
2109                    $elm->outertext = '';
2110                }
2111
2112                foreach ($cm->find('fieldset') as $elm) {
2113                    $elm->innertext .= $saveButtons;
2114                }
2115            }
2116        }
2117
2118        $content = $html->save();
2119        $html->clear();
2120        unset($html);
2121
2122        return $content;
2123    }
2124
2125
2126    /**
2127     * Get DokuWiki namespace/page/URI as link
2128     *
2129     * @param   string $str String to parse.
2130     * @return  string      parsed URI
2131     */
2132    public function getLink(string $str): string
2133    {
2134        $i = strpos($str, '://');
2135        if ($i !== false) {
2136            return $str;
2137        }
2138
2139        return wl($str);
2140    }
2141
2142
2143    /**
2144     * Check if the user can edit current namespace/page
2145     *
2146     * @return  boolean  user can edit
2147     */
2148    public function userCanEdit(): bool
2149    {
2150        global $INFO;
2151        global $ID;
2152
2153        $wiki_file = wikiFN($ID);
2154        if (@file_exists($wiki_file) === false) {
2155            return true;
2156        }
2157        if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) {
2158            return true;
2159        }
2160        // $meta_file = metaFN($ID, '.meta');
2161        if ($INFO['meta']['user'] === false) {
2162            return true;
2163        }
2164        if ($INFO['client'] === $INFO['meta']['user']) {
2165            return true;
2166        }
2167
2168        return false;
2169    }
2170
2171
2172    /**
2173     * Search for and return the uri of a media file
2174     *
2175     * @param string  $image           Image name to search for (without extension).
2176     * @param boolean $searchCurrentNS Search the current namespace.
2177     * @param boolean $propagate       Propagate search through the namespace.
2178     * @return string                  URI of the found media file
2179     */
2180    public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true)
2181    {
2182        global $INFO;
2183
2184        $ext = ['png', 'jpg', 'gif', 'svg'];
2185
2186        if ($searchCurrentNS === true) {
2187            $prefix[] = ':' . $INFO['namespace'] . ':';
2188        }
2189        if ($propagate === true) {
2190            $prefix[] = ':';
2191            $prefix[] = ':wiki:';
2192        }
2193        $theme = $this->getConf('customTheme');
2194        if (empty($theme) === false) {
2195            $prefix[] = 'themes/' . $theme . '/images/';
2196        }
2197        $prefix[] = 'images/';
2198
2199        $search = [];
2200        foreach ($prefix as $pitem) {
2201            foreach ($ext as $eitem) {
2202                $search[] = $pitem . $image . '.' . $eitem;
2203            }
2204        }
2205
2206        $img = '';
2207        $ismedia = false;
2208        $found = false;
2209
2210        foreach ($search as $img) {
2211            if (strcasecmp(substr($img, 0, 1), ':') === 0) {
2212                $file    = mediaFN($img);
2213                $ismedia = true;
2214            } else {
2215                $file    = tpl_incdir() . $img;
2216                $ismedia = false;
2217            }
2218
2219            if (file_exists($file) === true) {
2220                $found = true;
2221                break;
2222            }
2223        }
2224
2225        if ($found === false) {
2226            return false;
2227        }
2228
2229        if ($ismedia === true) {
2230            $url = ml($img, '', true, '');
2231        } else {
2232            $url = tpl_basedir() . $img;
2233        }
2234
2235        return $url;
2236    }
2237
2238
2239    /**
2240     * Print or return the page title
2241     *
2242     * @param string $page Page id or empty string for current page.
2243     * @return string      generated content
2244     */
2245    public function getPageTitle(string $page = ''): string
2246    {
2247        global $ID, $conf;
2248
2249        if (empty($page) === true) {
2250            $page = $ID;
2251        }
2252
2253        $html = p_get_first_heading($page);
2254        $html = strip_tags($html);
2255        $html = preg_replace('/\s+/', ' ', $html);
2256        $html .= ' [' . strip_tags($conf['title']) . ']';
2257        return trim($html);
2258    }
2259
2260
2261    /**
2262     * Return inline theme icon
2263     *
2264     * @param   string $type  Icon to retreive.
2265     * @param   string $class Classname to insert.
2266     * @return  string        HTML icon content
2267     */
2268    public function mikioInlineIcon(string $type, string $class = ""): string
2269    {
2270        if (is_array($class) === true) {
2271            $class = implode(' ', $class);
2272        }
2273
2274        if (strlen($class) > 0) {
2275            $class = ' ' . $class;
2276        }
2277
2278        switch ($type) {
2279            case 'wrench':
2280                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792
22811792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,53.152542,1217.0847)"><path d="m 384,64 q 0,26 -19,45 -19,
228219 -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,
2283-37 -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,
2284435 q 0,-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
2285131.5,131.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,
2286-107 q 5,3 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>';
2287            case 'file':
2288                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2289viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991">
2290<path d="M 128,0 H 1152 V 768 H 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
22911280,768 V -32 q 0,-40 -28,-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
2292q 40,0 88,-20 48,-20 76,-48 l 408,-408 q 28,-28 48,-76 20,-48 20,-88 z" id="path2993" /></g></svg>';
2293            case 'gear':
2294                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2295viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027">
2296<path d="m 1024,640 q 0,106 -75,181 -75,75 -181,75 -106,0 -181,-75 -75,-75 -75,-181 0,-106 75,-181 75,-75 181,-75 106,0
2297181,75 75,75 75,181 z m 512,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
229810,-25 0,-13 -9,-23 -27,-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
2299-36,-28 H 657 q -14,0 -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
2300147,186 q -7,10 -7,23 0,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
2301q 0,12 8,23 8,11 19,13 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,
230271.5 13,0 26,-10 l 138,-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
2303q 49,-16 90,-37 l 142,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
2304-54,-70.5 26,-50 41,-98 l 183,-28 q 13,-2 21,-12.5 8,-10.5 8,-23.5 z" id="path3029" />
2305</g></svg>';
2306            case 'user':
2307                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2308viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M
23091408,131 Q 1408,11 1335,-58.5 1262,-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
231028,402 44,452 q 16,50 43,97.5 27,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,
2311-26.5 108,-48 Q 637,565 704,565 q 67,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
231250.5,-20 85.5,-53.5 35,-33.5 62,-81 27,-47.5 43,-97.5 16,-50 26.5,-108.5 10.5,-58.5 14,-109 Q 1408,184 1408,131 z m
2313-320,893 Q 1088,865 975.5,752.5 863,640 704,640 545,640 432.5,752.5 320,865 320,1024 320,1183 432.5,1295.5 545,1408 704,
23141408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>';
2315            case 'search':
2316                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"
2317aria-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
231818.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
231924.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
23206.195 0 0 1-6.188 6.188z"/></svg>';
2321            case 'home':
2322                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2323viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g
2324transform="matrix(1,0,0,-1,68.338983,1285.4237)" id="g3015"><path d="M 1408,544 V 64 Q 1408,38 1389,19 1370,0 1344,0 H
2325960 V 384 H 704 V 0 H 320 q -26,0 -45,19 -19,19 -19,45 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
2326m 223,69 -62,-74 q -8,-9 -21,-11 h -3 q -13,0 -21,7 L 832,1112 140,535 q -12,-8 -24,-7 -13,2 -21,11 l -62,74 q -8,10
2327-7,23.5 1,13.5 11,21.5 l 719,599 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,
2328-9 9,-23 V 840 l 219,-182 q 10,-8 11,-21.5 1,-13.5 -7,-23.5 z" id="path3017" /></g></svg>';
2329            case 'sun':
2330                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2331style="fill:currentColor" viewBox="0 0 16 16"><path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0 1a4 4 0 1 0 0-8 4 4 0 0 0
23320 8zm.5-9.5a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zm0 11a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zm5-5a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1zm-11
23330a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1zm9.743-4.036a.5.5 0 1 1-.707-.707.5.5 0 0 1 .707.707zm-7.779 7.779a.5.5 0 1
23341-.707-.707.5.5 0 0 1 .707.707zm7.072 0a.5.5 0 1 1 .707-.707.5.5 0 0 1-.707.707zM3.757 4.464a.5.5 0 1 1 .707-.707.5.5
23350 0 1-.707.707z" /></svg>';
2336            case 'moon':
2337                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2338style="fill:currentColor" viewBox="0 0 16 16"><path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0
23394.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0
23401 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278zM4.858 1.311A7.269 7.269 0 0 0
23411.025 7.71c0 4.02 3.279 7.276 7.319 7.276a7.316 7.316 0 0 0 5.205-2.162c-.337.042-.68.063-1.029.063-4.61
23420-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>';
2343            case 'sunmoon':
2344                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg"
2345style="fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10"
2346viewBox="0 0 32 32"><line x1="16" y1="3" x2="16" y2="29"/><path d="M16,23c-3.87,0-7-3.13-7-7s3.13-7,7-7"/><line
2347x1="6.81" y1="6.81" x2="8.93" y2="8.93"/><line x1="3" y1="16" x2="6" y2="16"/><line x1="6.81" y1="25.19" x2="8.93"
2348y2="23.07"/><path d="M16,12.55C17.2,10.43,19.48,9,22.09,9c0.16,0,0.31,0.01,0.47,0.02c-1.67,0.88-2.8,2.63-2.8,4.64c0,2.9,
23492.35,5.25,5.25,5.25c1.6,0,3.03-0.72,3.99-1.85C28.48,20.43,25.59,23,22.09,23c-2.61,0-4.89-1.43-6.09-3.55"/></svg>';
2350            case 'hamburger':
2351                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"
2352style="fill:currentColor"><path d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0
235376v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16
235416v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16
235516v40c0 8.837 7.163 16 16 16z"/></svg>';
2356            case 'down-arrow':
2357                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"
2358aria-hidden="true" style="fill:currentColor"><path d="M16.003 18.626l7.081-7.081L25 13.46l-8.997 8.998-9.003-9
23591.917-1.916z"/></svg>';
2360            case 'language':
2361                return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" width="16"
2362height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.545 6.714 4.11
23638H3l1.862-5h1.284L8 8H6.833l-.435-1.286H4.545zm1.634-.736L5.5 3.956h-.049l-.679 2.022H6.18z"/><path d="M0 2a2 2 0 0 1
23642-2h7a2 2 0 0 1 2 2v3h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-3H2a2 2 0 0 1-2-2V2zm2-1a1 1 0 0 0-1 1v7a1 1 0 0
23650 1 1h7a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H2zm7.138 9.995c.193.301.402.583.63.846-.748.575-1.673 1.001-2.768
23661.292.178.217.451.635.555.867 1.125-.359 2.08-.844 2.886-1.494.777.665 1.739 1.165 2.93
23671.472.133-.254.414-.673.629-.89-1.125-.253-2.057-.694-2.82-1.284.681-.747 1.222-1.651
23681.621-2.757H14V8h-3v1.047h.765c-.318.844-.74 1.546-1.272 2.13a6.066 6.066 0 0 1-.415-.492 1.988 1.988 0 0 1-.94.31z"/>
2369</svg>';
2370        }//end switch
2371
2372        return '';
2373    }
2374
2375    /**
2376     * Show Messages
2377     *
2378     * @return void
2379     */
2380    public function showMessages()
2381    {
2382        global $ACT;
2383
2384        $show = $this->getConf('showNotifications');
2385        if (
2386            strlen($show) === 0 ||
2387            strcasecmp($show, tpl_getLang('value_always')) === 0 ||
2388            (strcasecmp($show, tpl_getLang('value_admin')) === 0 && strcasecmp($ACT, 'admin') === 0)
2389        ) {
2390            html_msgarea();
2391
2392            // global $MSG, $MSG_shown;
2393
2394            // if (isset($MSG) !== false) {
2395            //     if (isset($MSG_shown) === false) {
2396            //         $MSG_shown = [];
2397            //     }
2398
2399            //     foreach ($MSG as $msg) {
2400            //         $hash = md5($msg['msg']);
2401            //         if (isset($MSG_shown[$hash]) === true) {
2402            //             continue;
2403            //         }
2404            //         // skip double messages
2405
2406            //         if (info_msg_allowed($msg) === true) {
2407            //             echo '<div class="me ' . $msg['lvl'] . '">';
2408            //             echo $msg['msg'];
2409            //             echo '</div>';
2410            //         }
2411
2412            //         $MSG_shown[$hash] = true;
2413            //     }
2414
2415            //     unset($GLOBALS['MSG']);
2416            // }//end if
2417
2418            if (strlen($this->includedPageNotifications) > 0) {
2419                echo $this->includedPageNotifications;
2420            }
2421        }//end if
2422    }
2423
2424    /**
2425     * Dokuwiki version number
2426     *
2427     * @return  int        the dw version date converted to integer
2428     */
2429    public function dwVersionNumber(): int
2430    {
2431        if (function_exists('getVersionData') === true) {
2432            $version_data = getVersionData();
2433            if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) {
2434                $version_items = explode(' ', $version_data['date']);
2435                if (count($version_items) >= 1) {
2436                    return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0])));
2437                }
2438            }
2439        }
2440
2441        return 0;
2442    }
2443
2444    /**
2445     * Call a method and parse the HTML output
2446     *
2447     * @param callable $method The method to call and capture output
2448     * @param callable $parser The parser method which is passed a DOMDocument to manipulate
2449     * @return  string           The raw parsed HTML
2450     */
2451    protected function parseHTML(callable $method, callable $parser): string
2452    {
2453        if(!is_callable($method) || !is_callable($parser)) {
2454            return '';
2455        }
2456
2457        ob_start();
2458        $method();
2459        $content = ob_get_clean();
2460        if($content !== '') {
2461            $domDocument = new DOMDocument();
2462            $domContent = $domDocument->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES'));
2463            if (false === $domContent) {
2464                return $content;
2465            }
2466
2467            $parser($domDocument);
2468            return $domDocument->saveHTML();
2469        }
2470
2471        return $content;
2472    }
2473
2474
2475    /**
2476     * Get an icon as a DOM element
2477     *
2478     * @param DOMDocument $domDocument The DOMDocument to import the icon into
2479     * @param string $type The icon type
2480     * @param string $class The icon class
2481     * @return DOMNode The icon as a DOM element
2482     */
2483    protected function iconAsDomElement(DOMDocument $domDocument, string $type, string $class = ''): DOMNode
2484    {
2485        $svgDoc = new DOMDocument();
2486        $svgDoc->loadXML($this->mikioInlineIcon($type, $class));
2487        $svgElement = $svgDoc->documentElement;
2488        return $domDocument->importNode($svgElement, true);
2489    }
2490}
2491
2492global $TEMPLATE;
2493$TEMPLATE = mikio::getInstance();
2494