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