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