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