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