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