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