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