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