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