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