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