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' => ['page title', 'home', 'icon', 'none'] 302 ], 303 ['keys' => ['sidebarLeftRow1', 'sidebarLeftRow2', 'sidebarLeftRow3', 'sidebarLeftRow4'], 304 'type' => 'choice', 305 'values' => ['none', 'logged in user', 'search', 'content', 'tags'], 306 'default' => [ 307 'sidebarLeftRow1' => 'logged in user', 308 'sidebarLeftRow2' => 'search', 309 'sidebarLeftRow3' => 'content' 310 ] 311 ], 312 ['keys' => ['pageToolsFloating', 'pageToolsFooter'], 313 'type' => 'choice', 314 'values' => ['always', 'none', '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 = '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 === false)) 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 // Extract only the <form> element 1189 $dom = new DOMDocument(); 1190 @$dom->loadHTML($html); 1191 $forms = $dom->getElementsByTagName('form'); 1192 if ($forms->length > 0) { 1193 $html = $dom->saveHTML($forms->item(0)); 1194 } else { 1195 $html = ''; 1196 } 1197 1198 if ($print === true) { 1199 echo $html; 1200 } 1201 return $html; 1202 } 1203 1204 1205 /** 1206 * Print or return content 1207 * 1208 * @param boolean $print Print content. 1209 * @return string contents 1210 */ 1211 public function includeContent(bool $print = true): string 1212 { 1213 ob_start(); 1214 tpl_content(false); 1215 $html = ob_get_clean(); 1216 1217 $html = $this->includeIcons($html); 1218 $html = $this->parseContent($html); 1219 1220 $html .= '<div style="clear:both"></div>'; 1221 1222 if ($this->getConf('heroTitle') === false && $this->getConf('tagsShowHero') === true) { 1223 $html = '<div class="mikio-tags"></div>' . $html; 1224 } 1225 1226 $html = '<div class="mikio-article-content">' . $html . '</div>'; 1227 1228 if ($print === true) { 1229 echo $html; 1230 } 1231 return $html; 1232 } 1233 1234 private function custom_tpl_pageinfo($ret = false) 1235 { 1236 global $conf; 1237 global $lang; 1238 global $INFO; 1239 global $ID; 1240 1241 // return if we are not allowed to view the page 1242 if (!auth_quickaclcheck($ID)) { 1243 return false; 1244 } 1245 1246 if (isset($INFO['exists'])) { 1247 $file = $INFO['filepath']; 1248 if (!$conf['fullpath']) { 1249 if ($INFO['rev']) { 1250 $file = str_replace($conf['olddir'] . '/', '', $file); 1251 } else { 1252 $file = str_replace($conf['datadir'] . '/', '', $file); 1253 } 1254 } 1255 $file = utf8_decodeFN($file); 1256 $date = dformat($INFO['lastmod']); 1257 1258 $string = $this->getConf('footerPageInfoText', ''); 1259 1260 // replace lang items 1261 $string = preg_replace_callback('/%([^%]+)%/', static function ($matches) use ($lang) { 1262 return $lang[$matches[1]] ?? ''; 1263 }, $string); 1264 1265 $options = [ 1266 'file' => '<bdi>' . $file . '</bdi>', 1267 'date' => $date, 1268 'user' => $INFO['editor'] ? '<bdi>' . editorinfo($INFO['editor']) . '</bdi>' : $lang['external_edit'] 1269 ]; 1270 1271 if (!empty($_SERVER['REMOTE_USER'])) { 1272 $options['loggedin'] = true; 1273 } 1274 1275 if ($INFO['locked']) { 1276 $options['locked'] = '<bdi>' . editorinfo($INFO['locked']) . '</bdi>'; 1277 } 1278 1279 $parser = new ParensParser(); 1280 $result = $parser->parse($string); 1281 1282 $parserIterate = function ($arr, $func) use ($options) { 1283 $str = ''; 1284 1285 foreach ($arr as $value) { 1286 if (is_array($value)) { 1287 $str .= $func($value, $func); 1288 } else { 1289 if (preg_match('/^([a-zA-Z]+)=(.*)/', $value, $matches)) { 1290 $key = strtolower($matches[1]); // Extract the key (a-zA-Z part) 1291 1292 if (isset($options[$key])) { 1293 $str .= $matches[2]; 1294 } else { 1295 return $str; 1296 } 1297 } else { 1298 $str .= $value; 1299 } 1300 } 1301 }//end foreach 1302 1303 return $str; 1304 }; 1305 1306 $string = $parserIterate($result, $parserIterate); 1307 1308 $string = preg_replace_callback('/{([^}]+)}/', static function ($matches) use ($options) { 1309 $key = strtolower($matches[1]); 1310 return $options[$key] ?? ''; 1311 }, $string); 1312 1313 if ($ret) { 1314 return $string; 1315 } 1316 1317 echo $string; 1318 return true; 1319 }//end if 1320 1321 return false; 1322 } 1323 1324 /** 1325 * Print or return footer 1326 * 1327 * @param boolean $print Print footer. 1328 * @return string HTML string containing footer 1329 */ 1330 public function includeFooter(bool $print = true): string 1331 { 1332 global $ACT; 1333 1334 $html = '<footer class="mikio-footer">'; 1335 $html .= '<div class="doc">' . $this->custom_tpl_pageinfo(true) . '</div>'; 1336 $html .= $this->includePage('footer', false); 1337 1338 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 1339 1340 if ($this->getConf('footerSearch') === true) { 1341 $html .= '<div class="mikio-footer-search">'; 1342 $html .= $this->includeSearch(false); 1343 $html .= '</div>'; 1344 } 1345 1346 $showPageTools = $this->getConf('pageToolsFooter'); 1347 if ( 1348 !is_null($ACT) && !is_null($showPageTools) && 1349 strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, 'always') === 0 || 1350 ($this->userCanEdit() === true && strcasecmp($showPageTools, 'page editors') === 0)) 1351 ) { 1352 $html .= $this->includePageTools(false); 1353 } 1354 1355 $meta['licenseType'] = ['multichoice', '_choices' => ['none', 'badge', 'button']]; 1356 /** @noinspection PhpArrayWriteIsNotUsedInspection */ 1357 $meta['licenseImageOnly'] = ['onoff']; 1358 1359 $licenseType = $this->getConf('licenseType'); 1360 if ($licenseType !== 'none') { 1361 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true); 1362 } 1363 1364 $html .= '</footer>'; 1365 1366 if ($print === true) { 1367 echo $html; 1368 } 1369 return $html; 1370 } 1371 1372 1373 /** 1374 * Print or return breadcrumb trail 1375 * 1376 * @param boolean $print Print out trail. 1377 * @param boolean $parse Parse trail before printing. 1378 * @return string HTML string containing breadcrumbs 1379 */ 1380 public function includeBreadcrumbs(bool $print = true, bool $parse = true): string 1381 { 1382 global $conf, $ID, $lang, $ACT; 1383 1384 if ( 1385 ($this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 && 1386 strcasecmp($ACT, 'show') === 0) || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0 1387 ) { 1388 return ''; 1389 } 1390 1391 $html = '<div class="mikio-breadcrumbs">'; 1392 $html .= '<div class="mikio-container">'; 1393 if (strcasecmp($ACT, 'show') === 0) { 1394 if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) { 1395 ob_start(); 1396 tpl_breadcrumbs(); 1397 $html .= ob_get_clean(); 1398 } else { 1399 $sep = '•'; 1400 $prefix = $lang['breadcrumb']; 1401 1402 if ($this->getConf('breadcrumbSep') === true) { 1403 $sep = $this->getConf('breadcrumbSepText'); 1404 $img = $this->getMediaFile('breadcrumb-sep', false); 1405 1406 if ($img !== false) { 1407 $sep = '<img src="' . $img . '">'; 1408 } 1409 } 1410 1411 if ($this->getConf('breadcrumbPrefix') === true) { 1412 $prefix = $this->getConf('breadcrumbPrefixText'); 1413 $img = $this->getMediaFile('breadcrumb-prefix', false); 1414 1415 if ($img !== false) { 1416 $prefix = '<img src="' . $img . '">'; 1417 } 1418 } 1419 1420 $crumbs = breadcrumbs(); 1421 1422 $html .= '<ul>'; 1423 if (empty($prefix) === false) { 1424 $html .= '<li class="prefix">' . $prefix . '</li>'; 1425 } 1426 1427 $last = count($crumbs); 1428 $i = 0; 1429 foreach ($crumbs as $id => $name) { 1430 $i++; 1431 if ($i !== 1) { 1432 $html .= '<li class="sep">' . $sep . '</li>'; 1433 } 1434 $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>'; 1435 $html .= tpl_pagelink($id, null, true); 1436 $html .= '</li>'; 1437 } 1438 1439 $html .= '</ul>'; 1440 }//end if 1441 }//end if 1442 1443 $html .= '</div>'; 1444 $html .= '</div>'; 1445 1446 if ($parse === true) { 1447 $html = $this->includeIcons($html); 1448 } 1449 if ($print === true) { 1450 echo $html; 1451 } 1452 return $html; 1453 } 1454 1455 /** 1456 * Print or return you are here trail 1457 * 1458 * @param boolean $print Print out trail. 1459 * @param boolean $parse Parse trail before printing. 1460 * @return string HTML string containing breadcrumbs 1461 */ 1462 public function includeYouAreHere(bool $print = true, bool $parse = true): string 1463 { 1464 global $conf, $ID, $lang, $ACT; 1465 1466 if ( 1467 ($this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 && 1468 strcasecmp($ACT, 'show') === 0) || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0 1469 ) { 1470 return ''; 1471 } 1472 1473 $html = '<div class="mikio-youarehere">'; 1474 $html .= '<div class="mikio-container">'; 1475 if (strcasecmp($ACT, 'show') === 0) { 1476 if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) { 1477 $html .= '<div class="mikio-bcdw">'; 1478 ob_start(); 1479 tpl_youarehere(); 1480 $html .= ob_get_clean(); 1481 $html .= '</div>'; 1482 } else { 1483 $sep = ' » '; 1484 $prefix = $lang['youarehere']; 1485 1486 if ($this->getConf('youarehereSep') === true) { 1487 $sep = $this->getConf('youarehereSepText'); 1488 $img = $this->getMediaFile('youarehere-sep', false); 1489 1490 if ($img !== false) { 1491 $sep = '<img src="' . $img . '">'; 1492 } 1493 } 1494 1495 if ($this->getConf('youareherePrefix') === true) { 1496 $prefix = $this->getConf('youareherePrefixText'); 1497 $img = $this->getMediaFile('youarehere-prefix', false); 1498 1499 if ($img !== false) { 1500 $prefix = '<img src="' . $img . '">'; 1501 } 1502 } 1503 1504 $html .= '<ul>'; 1505 if (empty($prefix) === false) { 1506 $html .= '<li class="prefix">' . $prefix . '</li>'; 1507 } 1508 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>'; 1509 1510 $parts = explode(':', $ID); 1511 $count = count($parts); 1512 1513 $part = ''; 1514 for ($i = 0; $i < ($count - 1); $i++) { 1515 $part .= $parts[$i] . ':'; 1516 $page = $part; 1517 if ($page === $conf['start']) { 1518 continue; 1519 } 1520 1521 $html .= '<li class="sep">' . $sep . '</li>'; 1522 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1523 } 1524 1525 $page = ''; 1526 1527 if ($this->getDokuWikiVersion() >= 20200729) { 1528 $page = cleanID($page); 1529 } else { 1530 $exists = false; 1531 /** @noinspection PhpDeprecationInspection */ 1532 resolve_pageid('', $page, $exists); 1533 } 1534 1535 if ((isset($page) === true && $page === $part . $parts[$i]) === false) { 1536 $page = $part . $parts[$i]; 1537 if ($page !== $conf['start']) { 1538 $html .= '<li class="sep">' . $sep . '</li>'; 1539 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1540 } 1541 } 1542 1543 $html .= '</ul>'; 1544 }//end if 1545 1546 $showLast = $this->getConf('youarehereShowLast'); 1547 if ($showLast !== 0) { 1548 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1549 if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) { 1550 $count = count($matches[0]); 1551 $list = ''; 1552 1553 // Show Home 1554 $list .= $matches[0][0] . $matches[0][1]; 1555 1556 $list .= '<li>...</li>'; 1557 for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) { 1558 $list .= $matches[0][$i]; 1559 } 1560 1561 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1562 } 1563 } 1564 1565 $value_none = 'none'; 1566 $value_home = 'home'; 1567 $value_icon = 'icon'; 1568 1569 switch ($this->getConf('youarehereHome')) { 1570 case $value_none: 1571 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1572 break; 1573 case $value_home: 1574 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1575 break; 1576 case $value_icon: 1577 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . 1578 $this->mikioInlineIcon('home') . '$3', $html, 1); 1579 break; 1580 } 1581 } else { 1582 $title_back = tpl_getlang('back'); 1583 $title_view_page = tpl_getlang('view-page'); 1584 1585 $html .= '≪ '; 1586 if (isset($_GET['page']) === true) { 1587 $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">' . $title_back . '</a> / '; 1588 } 1589 $html .= '<a href="' . wl($ID) . '">' . $title_view_page . '</a>'; 1590 }//end if 1591 1592 $html .= '</div>'; 1593 $html .= '</div>'; 1594 1595 if ($parse === true) { 1596 $html = $this->includeIcons($html); 1597 } 1598 if ($print === true) { 1599 echo $html; 1600 } 1601 return $html; 1602 } 1603 1604 /** 1605 * Get Page Title 1606 * 1607 * @return string page title 1608 */ 1609 public function parsePageTitle(): string 1610 { 1611 global $ID; 1612 1613 $title = hsc(p_get_first_heading($ID)); 1614 if (strlen($title) <= 0) { 1615 $title = tpl_pagetitle(null, true); 1616 } 1617 return $this->includeIcons($title); 1618 } 1619 1620 1621 /** 1622 * Print or return hero block 1623 * 1624 * @param boolean $print Print content. 1625 * @return string contents of hero 1626 */ 1627 public function includeHero(bool $print = true): string 1628 { 1629 $html = ''; 1630 1631 if ($this->getConf('heroTitle') === true) { 1632 $html .= '<div class="mikio-hero">'; 1633 $html .= '<div class="mikio-container">'; 1634 $html .= '<div class="mikio-hero-text">'; 1635 if (strcasecmp($this->getConf('youareherePosition'), 'hero') === 0) { 1636 $html .= $this->includeYouAreHere(false); 1637 } 1638 if (strcasecmp($this->getConf('breadcrumbPosition'), 'hero') === 0) { 1639 $html .= $this->includeBreadcrumbs(false); 1640 } 1641 1642 $html .= '<h1 class="mikio-hero-title">'; 1643 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterward to work? 1644 $html .= '</h1>'; 1645 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1646 $html .= '</div>'; 1647 1648 $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true)); 1649 $hero_image_resize_class = ''; 1650 if (empty($hero_image) === false) { 1651 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1652 $hero_image_resize_class = ' mikio-hero-image-resize'; 1653 } 1654 1655 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . 1656 '>'; 1657 1658 if($this->getConf('tagsShowHero') === true) { 1659 $html .= '<div class="mikio-tags"></div>'; 1660 } 1661 1662 $html .= '</div>'; 1663 1664 $html .= '</div>'; 1665 $html .= '</div>'; 1666 }//end if 1667 1668 if ($print === true) { 1669 echo $html; 1670 } 1671 1672 return $html; 1673 } 1674 1675 1676 /** 1677 * Print or return out TOC 1678 * 1679 * @param boolean $print Print TOC. 1680 * @param boolean $parse Parse icons. 1681 * @return string contents of TOC 1682 */ 1683 public function includeTOC(bool $print = true, bool $parse = true): string 1684 { 1685 $html = ''; 1686 1687 $tocHtml = tpl_toc(true); 1688 1689 if (empty($tocHtml) === false) { 1690 $tocHtml = preg_replace( 1691 '/(<h3.+?toggle.+?>)(.+?)<\/h3>/', 1692 '$1' . 1693 $this->mikioInlineIcon('hamburger', 'hamburger') . '$2' . 1694 $this->mikioInlineIcon('down-arrow', 'down-arrow') . '</h3>', 1695 $tocHtml 1696 ); 1697 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1698 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1699 1700 $html .= '<div class="mikio-toc">'; 1701 $html .= $tocHtml; 1702 $html .= '</div>'; 1703 } 1704 1705 if ($parse === true) { 1706 $html = $this->includeIcons($html); 1707 } 1708 1709 if ($print === true) { 1710 echo $html; 1711 } 1712 1713 return $html; 1714 } 1715 1716 1717 /** 1718 * Parse the string and replace icon elements with included icon libraries 1719 * 1720 * @param string $str Content to parse. 1721 * @return string parsed string 1722 */ 1723 public function includeIcons(string $str): string 1724 { 1725 global $ACT, $MIKIO_ICONS; 1726 1727 $iconTag = $this->getConf('iconTag', 'icon'); 1728 if (empty($iconTag) === true) { 1729 return $str; 1730 } 1731 1732 if ( 1733 in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true || 1734 (strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0) 1735 ) { 1736 $content = $str; 1737 $preview = null; 1738 1739 $html = null; 1740 if (strcasecmp($ACT, 'preview') === 0) { 1741 $html = new simple_html_dom(); 1742 $html->stripRNAttrValues = false; 1743 $html->load($str, true, false); 1744 1745 $preview = $html->find('div.preview'); 1746 if (is_array($preview) === true && count($preview) > 0) { 1747 $content = $preview[0]->innertext; 1748 } 1749 } 1750 1751 $page_regex = '/(.*)/'; 1752 if (stripos($str, '<pre') !== false) { 1753 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1754 } 1755 1756 $content = preg_replace_callback($page_regex, function ($icons) { 1757 $iconTag = $this->getConf('iconTag', 'icon'); 1758 1759 return preg_replace_callback( 1760 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1761 function ($matches) { 1762 global $MIKIO_ICONS; 1763 1764 $s = $matches[0]; 1765 1766 if (count($MIKIO_ICONS) > 0) { 1767 $icon = $MIKIO_ICONS[0]; 1768 1769 if (count($matches) > 1) { 1770 $e = explode(' ', $matches[1]); 1771 1772 if (count($e) > 1) { 1773 foreach ($MIKIO_ICONS as $iconItem) { 1774 if (strcasecmp($iconItem['name'], $e[0]) === 0) { 1775 $icon = $iconItem; 1776 1777 $s = $icon['insert']; 1778 for ($i = 1; $i < 9; $i++) { 1779 if (count($e) < $i || empty($e[$i]) === true) { 1780 if (isset($icon['$' . $i]) === true) { 1781 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1782 } 1783 } else { 1784 $s = str_replace('$' . $i, $e[$i], $s); 1785 } 1786 } 1787 1788 $dir = ''; 1789 if (isset($icon['dir']) === true) { 1790 $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1791 } 1792 1793 $s = str_replace('$0', $dir, $s); 1794 1795 break; 1796 }//end if 1797 }//end foreach 1798 } else { 1799 $s = str_replace('$1', $matches[1], $icon['insert']); 1800 }//end if 1801 }//end if 1802 }//end if 1803 1804 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1805 if ($count === 0) { 1806 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1807 } 1808 1809 return $s; 1810 }, 1811 $icons[0] 1812 ); 1813 }, $content); 1814 1815 if (strcasecmp($ACT, 'preview') === 0) { 1816 if (is_array($preview) === true && count($preview) > 0) { 1817 $preview[0]->innertext = $content; 1818 } 1819 1820 $str = $html->save(); 1821 $html->clear(); 1822 unset($html); 1823 } else { 1824 $str = $content; 1825 } 1826 }//end if 1827 1828 return $str; 1829 } 1830 1831 /** 1832 * Parse HTML for theme 1833 * 1834 * @param string $content HTML content to parse. 1835 * @return string Parsed content 1836 */ 1837 public function parseContent(string $content): string 1838 { 1839 global $INPUT, $ACT; 1840 1841 // Add Mikio Section titles 1842 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1843 $admin_sections = [ 1844 // Section Insert Before Icon 1845 'navbar' => ['navbarUseTitleIcon', ''], 1846 'search' => ['searchButton', ''], 1847 'hero' => ['heroTitle', ''], 1848 'tags' => ['tagsConsolidate', ''], 1849 'breadcrumb' => ['breadcrumbHideHome', ''], 1850 'youarehere' => ['youarehereHideHome', ''], 1851 'sidebar' => ['sidebarShowLeft', ''], 1852 'toc' => ['tocFull', ''], 1853 'pagetools' => ['pageToolsFloating', ''], 1854 'footer' => ['footerPageInfoText', ''], 1855 'license' => ['licenseType', ''], 1856 'acl' => ['includePageUseACL', ''], 1857 'sticky' => ['stickyTopHeader', ''], 1858 ]; 1859 1860 foreach ($admin_sections as $section => $items) { 1861 $search = $items[0]; 1862 $icon = $items[1]; 1863 1864 $content = preg_replace( 1865 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1866 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . 1867 tpl_getLang('config_' . $section) . 1868 '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . 1869 $search . '</span>', 1870 $content 1871 ); 1872 } 1873 } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) { 1874 $mikioPluginMissing = true; 1875 /* Hide plugin fields if not installed */ 1876 if (plugin_load('action', 'mikioplugin') !== null) { 1877 $mikioPluginMissing = false; 1878 } 1879 1880 $style_headers = [ 1881 ['title' => tpl_getLang('style_header_base'), 'starts_with' => '__text_'], 1882 ['title' => tpl_getLang('style_header_code'), 'starts_with' => '__code_'], 1883 ['title' => tpl_getLang('style_header_controls'), 'starts_with' => '__control_'], 1884 ['title' => tpl_getLang('style_header_header'), 'starts_with' => '__topheader_'], 1885 ['title' => tpl_getLang('style_header_navbar'), 'starts_with' => '__navbar_'], 1886 ['title' => tpl_getLang('style_header_sub_navbar'), 'starts_with' => '__subnavbar_'], 1887 ['title' => tpl_getLang('style_header_tags'), 'starts_with' => '__tag_background_color_'], 1888 ['title' => tpl_getLang('style_header_breadcrumbs'), 'starts_with' => '__breadcrumb_'], 1889 ['title' => tpl_getLang('style_header_hero'), 'starts_with' => '__hero_'], 1890 ['title' => tpl_getLang('style_header_sidebar'), 'starts_with' => '__sidebar_'], 1891 ['title' => tpl_getLang('style_header_content'), 'starts_with' => '__content_'], 1892 ['title' => tpl_getLang('style_header_toc'), 'starts_with' => '__toc_'], 1893 ['title' => tpl_getLang('style_header_page_tools'), 'starts_with' => '__pagetools_'], 1894 ['title' => tpl_getLang('style_header_footer'), 'starts_with' => '__footer_'], 1895 ['title' => tpl_getLang('style_header_table'), 'starts_with' => '__table_'], 1896 ['title' => tpl_getLang('style_header_dropdown'), 'starts_with' => '__dropdown_'], 1897 ['title' => tpl_getLang('style_header_section_edit'), 'starts_with' => '__section_edit_'], 1898 ['title' => tpl_getLang('style_header_tree'), 'starts_with' => '__tree_'], 1899 ['title' => tpl_getLang('style_header_tabs'), 'starts_with' => '__tab_'], 1900 ['title' => tpl_getLang('style_header_mikio_plugin'), 'starts_with' => '__plugin_', 'heading' => 'h2', 1901 'hidden' => $mikioPluginMissing 1902 ], 1903 ['title' => tpl_getLang('style_header_primary_colours'), 'starts_with' => '__plugin_primary_', 'hidden' => $mikioPluginMissing], 1904 ['title' => tpl_getLang('style_header_secondary_colours'), 'starts_with' => '__plugin_secondary_', 1905 'hidden' => $mikioPluginMissing 1906 ], 1907 ['title' => tpl_getLang('style_header_success_colours'), 'starts_with' => '__plugin_success_', 'hidden' => $mikioPluginMissing], 1908 ['title' => tpl_getLang('style_header_danger_colours'), 'starts_with' => '__plugin_danger_', 'hidden' => $mikioPluginMissing], 1909 ['title' => tpl_getLang('style_header_warning_colours'), 'starts_with' => '__plugin_warning_', 'hidden' => $mikioPluginMissing], 1910 ['title' => tpl_getLang('style_header_info_colours'), 'starts_with' => '__plugin_info_', 'hidden' => $mikioPluginMissing], 1911 ['title' => tpl_getLang('style_header_light_colours'), 'starts_with' => '__plugin_light_', 'hidden' => $mikioPluginMissing], 1912 ['title' => tpl_getLang('style_header_dark_colours'), 'starts_with' => '__plugin_dark_', 'hidden' => $mikioPluginMissing], 1913 ['title' => tpl_getLang('style_header_link_colours'), 'starts_with' => '__plugin_link_', 'hidden' => $mikioPluginMissing], 1914 ['title' => tpl_getLang('style_header_carousel'), 'starts_with' => '__plugin_carousel_', 'hidden' => $mikioPluginMissing], 1915 ['title' => tpl_getLang('style_header_steps'), 'starts_with' => '__plugin_steps_', 'hidden' => $mikioPluginMissing], 1916 ['title' => tpl_getLang('style_header_tabgroup'), 'starts_with' => '__plugin_tabgroup_', 'hidden' => $mikioPluginMissing], 1917 ['title' => tpl_getLang('style_header_tooltip'), 'starts_with' => '__plugin_tooltip_', 'hidden' => $mikioPluginMissing], 1918 ['title' => tpl_getLang('style_header_dark_mode'), 'starts_with' => '__darkmode_', 'heading' => 'h2'], 1919 ['title' => tpl_getLang('style_header_dark_mode_base'), 'starts_with' => '__darkmode_text_'], 1920 ['title' => tpl_getLang('style_header_dark_mode_code'), 'starts_with' => '__darkmode_code_'], 1921 ['title' => tpl_getLang('style_header_dark_mode_controls'), 'starts_with' => '__darkmode_control_'], 1922 ['title' => tpl_getLang('style_header_dark_mode_header'), 'starts_with' => '__darkmode_topheader_'], 1923 ['title' => tpl_getLang('style_header_dark_mode_navbar'), 'starts_with' => '__darkmode_navbar_'], 1924 ['title' => tpl_getLang('style_header_dark_mode_sub_navbar'), 'starts_with' => '__darkmode_subnavbar_'], 1925 ['title' => tpl_getLang('style_header_dark_mode_tags'), 'starts_with' => '__darkmode_tag_background_color_'], 1926 ['title' => tpl_getLang('style_header_dark_mode_breadcrumbs'), 'starts_with' => '__darkmode_breadcrumb_'], 1927 ['title' => tpl_getLang('style_header_dark_mode_hero'), 'starts_with' => '__darkmode_hero_'], 1928 ['title' => tpl_getLang('style_header_dark_mode_sidebar'), 'starts_with' => '__darkmode_sidebar_'], 1929 ['title' => tpl_getLang('style_header_dark_mode_content'), 'starts_with' => '__darkmode_content_'], 1930 ['title' => tpl_getLang('style_header_dark_mode_toc'), 'starts_with' => '__darkmode_toc_'], 1931 ['title' => tpl_getLang('style_header_dark_mode_page_tools'), 'starts_with' => '__darkmode_pagetools_'], 1932 ['title' => tpl_getLang('style_header_dark_mode_footer'), 'starts_with' => '__darkmode_footer_'], 1933 ['title' => tpl_getLang('style_header_dark_mode_table'), 'starts_with' => '__darkmode_table_'], 1934 ['title' => tpl_getLang('style_header_dark_mode_dropdown'), 'starts_with' => '__darkmode_dropdown_'], 1935 ['title' => tpl_getLang('style_header_dark_mode_section_edit'), 'starts_with' => '__darkmode_section_edit_'], 1936 ['title' => tpl_getLang('style_header_dark_mode_tree'), 'starts_with' => '__darkmode_tree_'], 1937 ['title' => tpl_getLang('style_header_dark_mode_tabs'), 'starts_with' => '__darkmode_tab_'], 1938 ['title' => tpl_getLang('style_header_mikio_plugin_dark_mode'), 'starts_with' => '__plugin_darkmode_', 'heading' => 'h2', 1939 'hidden' => $mikioPluginMissing 1940 ], 1941 ['title' => tpl_getLang('style_header_dark_mode_primary_colours'), 'starts_with' => '__plugin_darkmode_primary_', 1942 'hidden' => $mikioPluginMissing 1943 ], 1944 ['title' => tpl_getLang('style_header_dark_mode_secondary_colours'), 'starts_with' => '__plugin_darkmode_secondary_', 1945 'hidden' => $mikioPluginMissing 1946 ], 1947 ['title' => tpl_getLang('style_header_dark_mode_success_colours'), 'starts_with' => '__plugin_darkmode_success_', 1948 'hidden' => $mikioPluginMissing 1949 ], 1950 ['title' => tpl_getLang('style_header_dark_mode_danger_colours'), 'starts_with' => '__plugin_darkmode_danger_', 1951 'hidden' => $mikioPluginMissing 1952 ], 1953 ['title' => tpl_getLang('style_header_dark_mode_warning_colours'), 'starts_with' => '__plugin_darkmode_warning_', 1954 'hidden' => $mikioPluginMissing 1955 ], 1956 ['title' => tpl_getLang('style_header_dark_mode_info_colours'), 'starts_with' => '__plugin_darkmode_info_', 1957 'hidden' => $mikioPluginMissing 1958 ], 1959 ['title' => tpl_getLang('style_header_dark_mode_light_colours'), 'starts_with' => '__plugin_darkmode_light_', 1960 'hidden' => $mikioPluginMissing 1961 ], 1962 ['title' => tpl_getLang('style_header_dark_mode_dark_colours'), 'starts_with' => '__plugin_darkmode_dark_', 1963 'hidden' => $mikioPluginMissing 1964 ], 1965 ['title' => tpl_getLang('style_header_dark_mode_link_colours'), 'starts_with' => '__plugin_darkmode_link_', 1966 'hidden' => $mikioPluginMissing 1967 ], 1968 ['title' => tpl_getLang('style_header_dark_mode_carousel'), 'starts_with' => '__plugin_darkmode_carousel_', 1969 'hidden' => $mikioPluginMissing 1970 ], 1971 ['title' => tpl_getLang('style_header_dark_mode_steps'), 'starts_with' => '__plugin_darkmode_steps_', 'hidden' => $mikioPluginMissing], 1972 ['title' => tpl_getLang('style_header_dark_mode_tabgroup'), 'starts_with' => '__plugin_darkmode_tabgroup_', 1973 'hidden' => $mikioPluginMissing 1974 ], 1975 ['title' => tpl_getLang('style_header_dark_mode_tooltip'), 'starts_with' => '__plugin_darkmode_tooltip_', 'hidden' => $mikioPluginMissing], 1976 ]; 1977 1978 foreach ($style_headers as $header) { 1979 if (array_key_exists('heading', $header) === false) { 1980 $header['heading'] = 'h3'; 1981 } 1982 1983 if (array_key_exists('hidden', $header) === false) { 1984 $header['hidden'] = false; 1985 } 1986 1987 $content = preg_replace( 1988 '/(<tr>\s*<td>\s*<label for="tpl__' . $header['starts_with'] . '.+?<\/tr>)/s', 1989 '</tbody></table><' . $header['heading'] . ' style="display:' . 1990 ($header['hidden'] === true ? 'none' : 'block') . '">' . 1991 $header['title'] . '</' . $header['heading'] . '> 1992 <table style="display:' . ($header['hidden'] === true ? 'none' : 'table') . '"><tbody>$1', 1993 $content, 1994 1 1995 ); 1996 } 1997 1998 $content = preg_replace_callback('/<input type="color"[^>]*>/', function ($match) { 1999 // Get the ID of the <input type="color"> element 2000 preg_match('/id="([^"]*)"/', $match[0]); 2001 2002 // Replace type with text and remove the id attribute 2003 $replacement = preg_replace( 2004 ['/type="color"/', '/id="([^"]*)"/'], 2005 ['type="text" class="mikio-color-text-input"', 'for="$1"'], 2006 $match[0] 2007 ); 2008 2009 return '<div class="mikio-color-picker">' . $replacement . $match[0] . '</div>'; 2010 }, $content); 2011 }//end if 2012 2013 if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) { 2014 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 2015 } 2016 2017 // Page Revisions - Table Fix 2018 if (strpos($content, 'id="page__revisions"') !== false) { 2019 $content = preg_replace( 2020 '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', 2021 '<span>$1</span>', 2022 $content 2023 ); 2024 } 2025 2026 $html = new simple_html_dom(); 2027 $html->stripRNAttrValues = false; 2028 $html->load($content, true, false); 2029 2030 /* Buttons */ 2031 foreach ($html->find('#config__manager button') as $node) { 2032 $c = explode(' ', $node->class); 2033 if (in_array('mikio-button', $c) === false) { 2034 $c[] = 'mikio-button'; 2035 } 2036 $node->class = implode(' ', $c); 2037 } 2038 2039 2040 /* Buttons - Primary */ 2041 foreach ($html->find('#config__manager [type=submit]') as $node) { 2042 $c = explode(' ', $node->class); 2043 if (in_array('mikio-primary', $c) === false) { 2044 $c[] = 'mikio-primary'; 2045 } 2046 $node->class = implode(' ', $c); 2047 } 2048 2049 /* Hide page title if hero is enabled */ 2050 if ($this->getConf('heroTitle') === true && $ACT !== 'preview') { 2051 $pageTitle = $this->parsePageTitle(); 2052 2053 foreach ($html->find('h1,h2,h3,h4') as $elm) { 2054 if ($elm->innertext === $pageTitle) { 2055 // $elm->innertext = ''; 2056 $elm->setAttribute('style', 'display:none'); 2057 2058 break; 2059 } 2060 } 2061 } 2062 2063 /* Hero subtitle */ 2064 foreach ($html->find('p') as $elm) { 2065 if (preg_match('/[~-]~hero-subtitle (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 2066 $subtitle = $matches[1]; 2067 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 2068 2069 $elm->innertext = preg_replace('/[~-]~hero-subtitle (.+?)~[~-]/ui', '', $elm->innertext); 2070 break; 2071 } 2072 } 2073 2074 /* Hero image */ 2075 foreach ($html->find('p') as $elm) { 2076 preg_match('/[~-]~hero-image (.+?)~[~-](?!.?")/ui', $elm->innertext, $matches); 2077 if (count($matches) > 0) { 2078 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 2079 if (count($imageTagMatches) > 0) { 2080 $image = $imageTagMatches[1]; 2081 } else { 2082 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 2083 if (count($imageTagMatches) > 0) { 2084 $image = $imageTagMatches[1]; 2085 } else { 2086 $image = strip_tags($matches[1]); 2087 if (stripos($image, ':') === false) { 2088 $image = str_replace(['{', '}'], '', $image); 2089 $i = stripos($image, '?'); 2090 if ($i !== false) { 2091 $image = substr($image, 0, $i); 2092 } 2093 2094 $image = ml($image, '', true, ''); 2095 } 2096 } 2097 } 2098 2099 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 2100 2101 $elm->innertext = preg_replace('/[~-]~hero-image (.+?)~[~-].*/ui', '', $elm->innertext); 2102 }//end if 2103 }//end foreach 2104 2105 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] 2106 [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 2107 foreach ($html->find('p') as $elm) { 2108 if (preg_match('/[~-]~hero-colors (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 2109 $subtitle = $matches[1]; 2110 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $subtitle . '\')'; 2111 2112 $elm->innertext = preg_replace('/[~-]~hero-colors (.+?)~[~-]/ui', '', $elm->innertext); 2113 break; 2114 } 2115 } 2116 2117 /* Hide parts - ~~hide-parts [parts]~~ */ 2118 foreach ($html->find('p') as $elm) { 2119 if (preg_match('/[~-]~hide-parts (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 2120 $parts = explode(' ', $matches[1]); 2121 $script = ''; 2122 2123 foreach ($parts as $part) { 2124 if (strlen($part) > 0) { 2125 $script .= 'mikio.hidePart(\'' . $part . '\');'; 2126 } 2127 } 2128 2129 if (strlen($script) > 0) { 2130 $this->footerScript['hide-parts'] = $script; 2131 } 2132 2133 $elm->innertext = preg_replace('/[~-]~hide-parts (.+?)~[~-]/ui', '', $elm->innertext); 2134 break; 2135 } 2136 }//end foreach 2137 2138 2139 /* Page Tags (tag plugin) */ 2140 if ($this->getConf('tagsConsolidate') === true) { 2141 $tags = ''; 2142 foreach ($html->find('div.tags a') as $elm) { 2143 $tags .= $elm->outertext; 2144 } 2145 2146 foreach ($html->find('div.tags') as $elm) { 2147 $elm->innertext = ''; 2148 $elm->setAttribute('style', 'display:none'); 2149 } 2150 2151 if (empty($tags) === false) { 2152 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 2153 } 2154 } 2155 2156 // Configuration Manager 2157 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 2158 // Additional save buttons 2159 foreach ($html->find('#config__manager') as $cm) { 2160 $saveButtons = ''; 2161 2162 foreach ($cm->find('p') as $elm) { 2163 $saveButtons = $elm->outertext; 2164 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 2165 $elm->outertext = ''; 2166 } 2167 2168 foreach ($cm->find('fieldset') as $elm) { 2169 $elm->innertext .= $saveButtons; 2170 } 2171 } 2172 } 2173 2174 $content = $html->save(); 2175 $html->clear(); 2176 unset($html); 2177 2178 return $content; 2179 } 2180 2181 2182 /** 2183 * Get DokuWiki namespace/page/URI as link 2184 * 2185 * @param string $str String to parse. 2186 * @return string parsed URI 2187 */ 2188 public function getLink(string $str): string 2189 { 2190 $i = strpos($str, '://'); 2191 if ($i !== false) { 2192 return $str; 2193 } 2194 2195 return wl($str); 2196 } 2197 2198 2199 /** 2200 * Check if the user can edit current namespace/page 2201 * 2202 * @return boolean user can edit 2203 */ 2204 public function userCanEdit(): bool 2205 { 2206 global $INFO; 2207 global $ID; 2208 2209 $wiki_file = wikiFN($ID); 2210 if (@file_exists($wiki_file) === false) { 2211 return true; 2212 } 2213 if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) { 2214 return true; 2215 } 2216 // $meta_file = metaFN($ID, '.meta'); 2217 if ($INFO['meta']['user'] === false) { 2218 return true; 2219 } 2220 if ($INFO['client'] === $INFO['meta']['user']) { 2221 return true; 2222 } 2223 2224 return false; 2225 } 2226 2227 2228 /** 2229 * Search for and return the uri of a media file 2230 * 2231 * @param string $image Image name to search for (without extension). 2232 * @param boolean $searchCurrentNS Search the current namespace. 2233 * @param boolean $propagate Propagate search through the namespace. 2234 * @return string URI of the found media file 2235 */ 2236 public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true) 2237 { 2238 global $INFO; 2239 2240 $ext = ['png', 'jpg', 'gif', 'svg']; 2241 2242 if ($searchCurrentNS === true) { 2243 $prefix[] = ':' . $INFO['namespace'] . ':'; 2244 } 2245 if ($propagate === true) { 2246 $prefix[] = ':'; 2247 $prefix[] = ':wiki:'; 2248 } 2249 $theme = $this->getConf('customTheme'); 2250 if (empty($theme) === false) { 2251 $prefix[] = 'themes/' . $theme . '/images/'; 2252 } 2253 $prefix[] = 'images/'; 2254 2255 $search = []; 2256 foreach ($prefix as $pitem) { 2257 foreach ($ext as $eitem) { 2258 $search[] = $pitem . $image . '.' . $eitem; 2259 } 2260 } 2261 2262 $img = ''; 2263 $ismedia = false; 2264 $found = false; 2265 2266 foreach ($search as $img) { 2267 if (strcasecmp(substr($img, 0, 1), ':') === 0) { 2268 $file = mediaFN($img); 2269 $ismedia = true; 2270 } else { 2271 $file = tpl_incdir() . $img; 2272 $ismedia = false; 2273 } 2274 2275 if (file_exists($file) === true) { 2276 $found = true; 2277 break; 2278 } 2279 } 2280 2281 if ($found === false) { 2282 return false; 2283 } 2284 2285 if ($ismedia === true) { 2286 $url = ml($img, '', true, ''); 2287 } else { 2288 $url = tpl_basedir() . $img; 2289 } 2290 2291 return $url; 2292 } 2293 2294 2295 /** 2296 * Print or return the page title 2297 * 2298 * @param string $page Page id or empty string for current page. 2299 * @return string generated content 2300 */ 2301 public function getPageTitle(string $page = ''): string 2302 { 2303 global $ID, $conf; 2304 2305 if (empty($page) === true) { 2306 $page = $ID; 2307 } 2308 2309 $html = hsc(p_get_first_heading($page)); 2310 2311 if(empty($html) === true) { 2312 $html = $conf['title']; 2313 } 2314 $html = strip_tags($html); 2315 $html = preg_replace('/\s+/', ' ', $html); 2316 $html .= ' [' . strip_tags($conf['title']) . ']'; 2317 return trim($html); 2318 } 2319 2320 2321 /** 2322 * Return inline theme icon 2323 * 2324 * @param string $type Icon to retreive. 2325 * @param string $class Classname to insert. 2326 * @return string HTML icon content 2327 */ 2328 public function mikioInlineIcon(string $type, string $class = ""): string 2329 { 2330 if (is_array($class) === true) { 2331 $class = implode(' ', $class); 2332 } 2333 2334 if (strlen($class) > 0) { 2335 $class = ' ' . $class; 2336 } 2337 2338 switch ($type) { 2339 case 'wrench': 2340 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 23411792" 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, 234219 -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, 2343-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, 2344435 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 2345131.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, 2346-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>'; 2347 case 'file': 2348 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2349viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"> 2350<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 23511280,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 2352q 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>'; 2353 case 'gear': 2354 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2355viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"> 2356<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 2357181,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 235810,-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 2359-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 2360147,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 2361q 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, 236271.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 2363q 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 2364-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" /> 2365</g></svg>'; 2366 case 'user': 2367 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2368viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 23691408,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 237028,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, 2371-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 237250.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 2373-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, 23741408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>'; 2375 case 'search': 2376 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2377aria-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 237818.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 237924.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 23806.195 0 0 1-6.188 6.188z"/></svg>'; 2381 case 'home': 2382 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2383viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g 2384transform="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 2385960 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 2386m 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 2387-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, 2388-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>'; 2389 case 'sun': 2390 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2391style="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 23920 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 23930a.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 23941-.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 23950 0 1-.707.707z" /></svg>'; 2396 case 'moon': 2397 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2398style="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 23994.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 24001 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 24011.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 24020-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>'; 2403 case 'sunmoon': 2404 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2405style="fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10" 2406viewBox="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 2407x1="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" 2408y2="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, 24092.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>'; 2410 case 'hamburger': 2411 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" 2412style="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 241376v40c0 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 241416v40c0 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 241516v40c0 8.837 7.163 16 16 16z"/></svg>'; 2416 case 'down-arrow': 2417 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2418aria-hidden="true" style="fill:currentColor"><path d="M16.003 18.626l7.081-7.081L25 13.46l-8.997 8.998-9.003-9 24191.917-1.916z"/></svg>'; 2420 case 'language': 2421 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" width="16" 2422height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.545 6.714 4.11 24238H3l1.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 24242-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 24250 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 24261.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 24271.472.133-.254.414-.673.629-.89-1.125-.253-2.057-.694-2.82-1.284.681-.747 1.222-1.651 24281.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"/> 2429</svg>'; 2430 }//end switch 2431 2432 return ''; 2433 } 2434 2435 /** 2436 * Show Messages 2437 * 2438 * @return void 2439 */ 2440 public function showMessages() 2441 { 2442 global $ACT; 2443 2444 $show = $this->getConf('showNotifications'); 2445 if ( 2446 strlen($show) === 0 || 2447 strcasecmp($show, 'always') === 0 || 2448 (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0) 2449 ) { 2450 html_msgarea(); 2451 2452 // global $MSG, $MSG_shown; 2453 2454 // if (isset($MSG) !== false) { 2455 // if (isset($MSG_shown) === false) { 2456 // $MSG_shown = []; 2457 // } 2458 2459 // foreach ($MSG as $msg) { 2460 // $hash = md5($msg['msg']); 2461 // if (isset($MSG_shown[$hash]) === true) { 2462 // continue; 2463 // } 2464 // // skip double messages 2465 2466 // if (info_msg_allowed($msg) === true) { 2467 // echo '<div class="me ' . $msg['lvl'] . '">'; 2468 // echo $msg['msg']; 2469 // echo '</div>'; 2470 // } 2471 2472 // $MSG_shown[$hash] = true; 2473 // } 2474 2475 // unset($GLOBALS['MSG']); 2476 // }//end if 2477 2478 if (strlen($this->includedPageNotifications) > 0) { 2479 echo $this->includedPageNotifications; 2480 } 2481 }//end if 2482 } 2483 2484 /** 2485 * Dokuwiki version number 2486 * 2487 * @return int the dw version date converted to integer 2488 */ 2489 public function getDokuWikiVersion(): int 2490 { 2491 if (function_exists('getVersionData') === true) { 2492 $version_data = getVersionData(); 2493 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2494 $version_items = explode(' ', $version_data['date']); 2495 if (count($version_items) >= 1) { 2496 return (int)preg_replace('/\D+/', '', strtolower($version_items[0])); 2497 } 2498 } 2499 } 2500 2501 return 0; 2502 } 2503 2504 /** 2505 * Call a method and parse the HTML output 2506 * 2507 * @param callable $method The method to call and capture output 2508 * @param callable $parser The parser method which is passed a DOMDocument to manipulate 2509 * @return string The raw parsed HTML 2510 */ 2511 protected function parseHTML(callable $method, callable $parser): string 2512 { 2513 if(!is_callable($method) || !is_callable($parser)) { 2514 return ''; 2515 } 2516 2517 ob_start(); 2518 $method(); 2519 $content = ob_get_clean(); 2520 if($content !== '') { 2521 $domDocument = new DOMDocument(); 2522 2523 if(function_exists('mb_convert_encoding')) { 2524 $content = mb_convert_encoding($content, 'HTML-ENTITIES'); 2525 } 2526 2527 $domContent = $domDocument->loadHTML($content); 2528 if (false === $domContent) { 2529 return $content; 2530 } 2531 2532 $parser($domDocument); 2533 return $domDocument->saveHTML(); 2534 } 2535 2536 return $content; 2537 } 2538 2539 2540 /** 2541 * Get an icon as a DOM element 2542 * 2543 * @param DOMDocument $domDocument The DOMDocument to import the icon into 2544 * @param string $type The icon type 2545 * @param string $class The icon class 2546 * @return DOMNode The icon as a DOM element 2547 */ 2548 protected function iconAsDomElement(DOMDocument $domDocument, string $type, string $class = ''): DOMNode 2549 { 2550 $svgDoc = new DOMDocument(); 2551 $svgDoc->loadXML($this->mikioInlineIcon($type, $class)); 2552 $svgElement = $svgDoc->documentElement; 2553 return $domDocument->importNode($svgElement, true); 2554 } 2555} 2556 2557global $TEMPLATE; 2558$TEMPLATE = mikio::getInstance(); 2559// 2494 2560