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