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