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