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 || $this->dwVersionNumber() == 0) { 193 // greator than hogfather - defer always on 194 if ($this->dwVersionNumber() >= 20200729 || $this->dwVersionNumber() == 0) { 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 $title = isset($attr['title']) && $attr['title'] !== 0 ? $attr['title'] : $item->getTitle(); 573 574 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . 575 ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $title . '"' . (isset($attr['accesskey']) && $attr['accesskey'] !== '' ? ' accesskey="' . $attr['accesskey'] . '"' : '') . '>'; 576 if ($showIcons === true) { 577 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 578 } 579 if ($showText === true || $isDropDown === true) { 580 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 581 } 582 $itemHtml .= '</a>'; 583 584 $pageToolsMenu[] = $itemHtml; 585 } 586 }//end if 587 }//end foreach 588 589 $items = (new \dokuwiki\Menu\SiteMenu())->getItems('action'); 590 foreach ($items as $item) { 591 $itemHtml = ''; 592 593 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 594 if ( 595 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 596 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 597 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false)) 598 ) { 599 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . ' ' . 600 $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 601 if ($showIcons === true) { 602 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 603 } 604 if ($showText === true || $isDropDown === true) { 605 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 606 } 607 $itemHtml .= '</a>'; 608 609 $siteToolsMenu[] = $itemHtml; 610 } 611 }//end foreach 612 613 $items = (new \dokuwiki\Menu\UserMenu())->getItems('action'); 614 foreach ($items as $item) { 615 $itemHtml = ''; 616 617 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 618 if ( 619 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 620 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 621 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false)) 622 ) { 623 $itemHtml .= '<a class="mikio-nav-link' . ($isDropDown === true ? ' mikio-dropdown-item' : '') . ' ' . 624 $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 625 if ($showIcons === true) { 626 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 627 } 628 if ($showText === true || $isDropDown === true) { 629 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 630 } 631 $itemHtml .= '</a>'; 632 633 $userToolsMenu[] = $itemHtml; 634 } 635 }//end foreach 636 637 638 switch ($this->getConf('navbarDWMenuCombine')) { 639 case 'dropdown': 640 $html .= '<li id="dokuwiki__pagetools" class="mikio-nav-dropdown">'; 641 $html .= '<a id="mikio_dropdown_pagetools" class="nav-link dropdown-toggle" href="#" role="button" 642data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 643 ($showIcons === true ? $this->mikioInlineIcon('file') : '') . 644 ($showText === true ? $lang['page_tools'] : '<span class="mikio-small-only">' . $lang['page_tools'] . 645 '</span>') . '</a>'; 646 $html .= '<div class="mikio-dropdown closed">'; 647 648 foreach ($pageToolsMenu as $item) { 649 $html .= $item; 650 } 651 652 $html .= '</div>'; 653 $html .= '</li>'; 654 655 $html .= '<li id="dokuwiki__sitetools" class="mikio-nav-dropdown">'; 656 $html .= '<a id="mikio_dropdown_sitetools" class="nav-link dropdown-toggle" href="#" role="button" 657data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 658 ($showIcons === true ? $this->mikioInlineIcon('gear') : '') . 659 ($showText === true ? $lang['site_tools'] : '<span class="mikio-small-only">' . 660 $lang['site_tools'] . '</span>') . '</a>'; 661 $html .= '<div class="mikio-dropdown closed">'; 662 663 foreach ($siteToolsMenu as $item) { 664 $html .= $item; 665 } 666 667 $html .= '</div>'; 668 $html .= '</li>'; 669 670 $html .= '<li id="dokuwiki__usertools" class="mikio-nav-dropdown">'; 671 $html .= '<a id="mikio_dropdown_usertools" class="nav-link dropdown-toggle" href="#" role="button" 672data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 673 ($showIcons === true ? $this->mikioInlineIcon('user') : '') . 674 ($showText === true ? $lang['user_tools'] : '<span class="mikio-small-only">' . 675 $lang['user_tools'] . '</span>') . '</a>'; 676 $html .= '<div class="mikio-dropdown closed">'; 677 678 foreach ($userToolsMenu as $item) { 679 $html .= $item; 680 } 681 682 $html .= '</div>'; 683 $html .= '</li>'; 684 685 break; 686 687 case 'combine': 688 $html .= '<li class="mikio-nav-dropdown">'; 689 $html .= '<a class="mikio-nav-link" href="#">' . 690 ($showIcons === true ? $this->mikioInlineIcon('wrench') : '') . 691 ($showText === true ? tpl_getLang('tools-menu') : '<span class="mikio-small-only">' . 692 tpl_getLang('tools-menu') . '</span>') . '</a>'; 693 $html .= '<div class="mikio-dropdown closed">'; 694 695 $html .= '<h6 class="mikio-dropdown-header">' . $lang['page_tools'] . '</h6>'; 696 foreach ($pageToolsMenu as $item) { 697 $html .= $item; 698 } 699 700 $html .= '<div class="mikio-dropdown-divider"></div>'; 701 $html .= '<h6 class="mikio-dropdown-header">' . $lang['site_tools'] . '</h6>'; 702 foreach ($siteToolsMenu as $item) { 703 $html .= $item; 704 } 705 706 $html .= '<div class="mikio-dropdown-divider"></div>'; 707 $html .= '<h6 class="mikio-dropdown-header">' . $lang['user_tools'] . '</h6>'; 708 foreach ($userToolsMenu as $item) { 709 $html .= $item; 710 } 711 712 $html .= '</div>'; 713 $html .= '</li>'; 714 break; 715 716 default: // seperate 717 foreach ($siteToolsMenu as $item) { 718 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 719 } 720 721 foreach ($pageToolsMenu as $item) { 722 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 723 } 724 725 foreach ($userToolsMenu as $item) { 726 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 727 } 728 729 break; 730 }//end switch 731 732 $translation = plugin_load('helper', 'translation'); 733 if ($translation !== null) { 734 $html .= '<li id="mikio__translate" class="mikio-nav-dropdown">'; 735 $html .= '<a id="mikio_dropdown_translate" class="nav-link dropdown-toggle" href="#" role="button" 736data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 737 $this->mikioInlineIcon('language') . 738 '</a>'; 739 $html .= '<div class="mikio-dropdown closed">'; 740 741 $html .= $translation->showTranslations(); 742 743 $html .= '</div>'; 744 $html .= '</li>'; 745 } 746 747 if ($this->getConf('showLightDark') === true) { 748 $autoLightDark = $this->getConf('autoLightDark'); 749 $html .= '<li class="mikio-darklight"> 750<a href="#" class="mikio-control mikio-button mikio-darklight-button">' . 751 ($autoLightDark === true ? $this->mikioInlineIcon('sunmoon', 'mikio-darklight-auto') : '') . 752 $this->mikioInlineIcon('sun', 'mikio-darklight-light') . 753 $this->mikioInlineIcon('moon', 'mikio-darklight-dark') . 754 '</a></li>'; 755 } 756 757 $html .= '</ul>'; 758 759 if ($print === true) { 760 echo $html; 761 } 762 return $html; 763 } 764 765 766 /** 767 * Create a nav element from a string. <uri>|<title>; 768 * 769 * @param string $str String to generate nav. 770 * @return string nav elements generated 771 */ 772 public function stringToNav(string $str) 773 { 774 $html = ''; 775 776 if (empty($str) === false) { 777 $items = explode(';', $str); 778 if (count($items) > 0) { 779 $html .= '<ul class="mikio-nav">'; 780 foreach ($items as $item) { 781 $parts = explode('|', $item); 782 if ($parts > 1) { 783 $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' . 784 strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) . 785 '</a></li>'; 786 } 787 } 788 $html .= '</ul>'; 789 } 790 } 791 792 return $html; 793 } 794 795 /** 796 * print or return the main navbar 797 * 798 * @param boolean $print Print the navbar. 799 * @param boolean $showSub Include the sub navbar. 800 * @return string generated content 801 */ 802 public function includeNavbar(bool $print = true, bool $showSub = false) 803 { 804 global $conf, $USERINFO; 805 806 $homeUrl = wl(); 807 808 if (plugin_isdisabled('showpageafterlogin') === false) { 809 $p = &plugin_load('action', 'showpageafterlogin'); 810 if (empty($p) === false) { 811 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 812 $homeUrl = wl($p->getConf('page_after_login')); 813 } 814 } 815 } else { 816 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 817 $url = $this->getConf('brandURLUser'); 818 if (strlen($url) > 0) { 819 $homeUrl = $url; 820 } 821 } else { 822 $url = $this->getConf('brandURLGuest'); 823 if (strlen($url) > 0) { 824 $homeUrl = $url; 825 } 826 } 827 } 828 829 $html = ''; 830 831 $html .= '<nav class="mikio-navbar' . (($this->getConf('stickyNavbar') === true) ? ' mikio-sticky' : '') . 832 '">'; 833 $html .= '<div class="mikio-container">'; 834 $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '">'; 835 if ($this->getConf('navbarUseTitleIcon') === true || $this->getConf('navbarUseTitleText') === true) { 836 // Brand image 837 if ($this->getConf('navbarUseTitleIcon') === true) { 838 $logo = $this->getMediaFile('logo', false); 839 ; 840 if (empty($logo) === false) { 841 $width = $this->getConf('navbarTitleIconWidth'); 842 $height = $this->getConf('navbarTitleIconHeight'); 843 $styles = ''; 844 845 if (strlen($width) > 0 || strlen($height) > 0) { 846 if (ctype_digit($width) === true) { 847 $styles .= 'max-width:' . intval($width) . 'px;'; 848 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $width) === 1) { 849 $styles .= 'max-width:' . $width . ';'; 850 } elseif (strcasecmp($width, 'none') === 0) { 851 $styles .= 'max-width:none;'; 852 } 853 854 if (ctype_digit($height) === true) { 855 $styles .= 'max-height:' . intval($height) . 'px;'; 856 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $height) === 1) { 857 $styles .= 'max-height:' . $height . ';'; 858 } elseif (strcasecmp($height, 'none') === 0) { 859 $styles .= 'max-height:none;'; 860 } 861 862 if (strlen($styles) > 0) { 863 $styles = ' style="' . $styles . '"'; 864 } 865 }//end if 866 867 $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image"' . $styles . '>'; 868 }//end if 869 }//end if 870 871 // Brand title 872 if ($this->getConf('navbarUseTitleText') === true) { 873 $html .= '<div class="mikio-navbar-brand-title">'; 874 $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>'; 875 if ($this->getConf('navbarUseTaglineText') === true) { 876 $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>'; 877 } 878 $html .= '</div>'; 879 } 880 }//end if 881 $html .= '</a>'; 882 $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>'; 883 884 // Menus 885 $html .= '<div class="mikio-navbar-collapse">'; 886 887 $menus = [$this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'), 888 $this->getConf('navbarPosRight', 'none') 889 ]; 890 foreach ($menus as $menuType) { 891 switch ($menuType) { 892 case 'custom': 893 $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', '')); 894 break; 895 case 'search': 896 $html .= '<div class="mikio-nav-item">'; 897 $html .= $this->includeSearch(false); 898 $html .= '</div>'; 899 break; 900 case 'dokuwiki': 901 $html .= $this->includeDWMenu(false); 902 break; 903 } 904 } 905 906 $html .= '</div>'; 907 $html .= '</div>'; 908 $html .= '</nav>'; 909 910 // Sub Navbar 911 if ($showSub === true) { 912 $sub = $this->includePage('submenu', false); 913 if (empty($sub) === false) { 914 $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>'; 915 } 916 } 917 918 if ($print === true) { 919 echo $html; 920 } 921 return $html; 922 } 923 924 925 /** 926 * Is there a sidebar 927 * 928 * @param string $prefix Sidebar prefix to use when searching. 929 * @return boolean if sidebar exists 930 */ 931 public function sidebarExists(string $prefix = '') 932 { 933 global $conf; 934 935 if (strcasecmp($prefix, 'left') === 0) { 936 $prefix = ''; 937 } 938 939 return $this->pageExists($conf['sidebar' . $prefix]); 940 } 941 942 943 /** 944 * Print or return the sidebar content 945 * 946 * @param string $prefix Sidebar prefix to use when searching. 947 * @param boolean $print Print the generated content to the output buffer. 948 * @param boolean $parse Parse the content. 949 * @return string generated content 950 */ 951 public function includeSidebar(string $prefix = '', bool $print = true, bool $parse = true) 952 { 953 global $conf, $ID; 954 955 $html = ''; 956 $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix)); 957 $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix)); 958 959 if (empty($confPrefix) === true) { 960 $confPrefix = 'Left'; 961 } 962 if (strcasecmp($prefix, 'left') === 0) { 963 $prefix = ''; 964 } 965 966 $sidebarPage = empty($conf[$prefix . 'sidebar']) === true ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar']; 967 968 if ( 969 $this->getConf('sidebarShow' . $confPrefix) === true && page_findnearest($sidebarPage) !== false && 970 p_get_metadata($ID, 'nosidebar', false) === null 971 ) { 972 $content = $this->includePage($sidebarPage . 'header', false); 973 if (empty($content) === false) { 974 $html .= '<div class="mikio-sidebar-header">' . $content . '</div>'; 975 } 976 977 if (empty($prefix) === true) { 978 $rows = [$this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'), 979 $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4') 980 ]; 981 982 foreach ($rows as $row) { 983 switch ($row) { 984 case 'search': 985 $html .= $this->includeSearch(false); 986 break; 987 case 'logged in user': 988 $html .= $this->includeLoggedIn(false); 989 break; 990 case 'content': 991 $content = $this->includePage($sidebarPage, false); 992 if (empty($content) === false) { 993 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 994 } 995 break; 996 case 'tags': 997 $html .= '<div class="mikio-tags"></div>'; 998 } 999 } 1000 } else { 1001 $content = $this->includePage($sidebarPage, false); 1002 if (empty($content) === false) { 1003 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 1004 } 1005 }//end if 1006 1007 $content = $this->includePage($sidebarPage . 'footer', false); 1008 if (empty($content) === false) { 1009 $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>'; 1010 } 1011 }//end if 1012 1013 if (empty($html) === true) { 1014 if (empty($prefix) === true && $this->getConf('sidebarAlwaysShowLeft') === true) { 1015 $html = ' '; 1016 } 1017 if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix)) === true) { 1018 $html = ' '; 1019 } 1020 } 1021 1022 if (empty($html) === false) { 1023 $html = '<aside class="mikio-sidebar mikio-sidebar-' . (empty($prefix) === true ? 'left' : $prefix) . 1024 '"><a class="mikio-sidebar-toggle' . 1025 ($this->getConf('sidebarMobileDefaultCollapse') === true ? ' closed' : '') . '" href="#">' . 1026 tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="mikio-sidebar-collapse">' . 1027 $html . '</div></aside>'; 1028 } 1029 1030 if ($parse === true) { 1031 $html = $this->includeIcons($html); 1032 } 1033 if ($print === true) { 1034 echo $html; 1035 } 1036 1037 return $html; 1038 } 1039 1040 1041 /** 1042 * Print or return the page tools content 1043 * 1044 * @param boolean $print Print the generated content to the output buffer. 1045 * @param boolean $includeId Include the dw__pagetools id in the element. 1046 * @return string generated content 1047 */ 1048 public function includePageTools(bool $print = true, bool $includeId = false) 1049 { 1050 global $USERINFO; 1051 1052 $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0); 1053 $html = ''; 1054 1055 $html .= '<nav' . ($includeId === true ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">'; 1056 $html .= '<ul class="tools">'; 1057 1058 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 1059 foreach ($items as $item) { 1060 $classes = []; 1061 $classes[] = $item->getType(); 1062 $attr = $item->getLinkAttributes(); 1063 1064 if (empty($attr['class']) === false) { 1065 $classes = array_merge($classes, explode(' ', $attr['class'])); 1066 } 1067 1068 $classes = array_unique($classes); 1069 $title = isset($attr['title']) && $attr['title'] !== 0 ? $attr['title'] : $item->getTitle(); 1070 1071 $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType()), 'always'); 1072 if ( 1073 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 1074 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 1075 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === true)) 1076 ) { 1077 $html .= '<li class="' . implode(' ', $classes) . '">'; 1078 $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' . 1079 $title . '"' . (isset($attr['accesskey']) && $attr['accesskey'] !== '' ? ' accesskey="' . $attr['accesskey'] . '"' : '') . '><div class="icon">' . inlineSVG($item->getSvg()) . 1080 '</div><span class="a11y">' . $item->getLabel() . '</span></a>'; 1081 $html .= '</li>'; 1082 } 1083 }//end foreach 1084 1085 $html .= '</ul>'; 1086 $html .= '</nav>'; 1087 1088 if ($print === true) { 1089 echo $html; 1090 } 1091 return $html; 1092 } 1093 1094 1095 /** 1096 * Print or return the search bar 1097 * 1098 * @param boolean $print Print content. 1099 * @return string contents of the search bar 1100 */ 1101 public function includeSearch(bool $print = true) 1102 { 1103 global $lang, $ID, $ACT, $QUERY; 1104 $html = ''; 1105 1106 $html .= '<form class="mikio-search search" action="' . wl() . 1107 '" accept-charset="utf-8" method="get" role="search">'; 1108 $html .= '<input type="hidden" name="do" value="search">'; 1109 $html .= '<input type="hidden" name="id" value="' . $ID . '">'; 1110 $html .= '<input name="q" '; 1111 if ($this->getConf('searchUseTypeahead') === true) { 1112 $html .= 'class="search_typeahead" '; 1113 } 1114 $html .= 'autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . 1115 ((strcasecmp($ACT, 'search') === 0) ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 1116 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 1117 if (strcasecmp($this->getConf('searchButton'), 'icon') === 0) { 1118 $html .= $this->mikioInlineIcon('search'); 1119 } else { 1120 $html .= $lang['btn_search']; 1121 } 1122 $html .= '</button>'; 1123 $html .= '</form>'; 1124 1125 if ($print === true) { 1126 echo $html; 1127 } 1128 return $html; 1129 } 1130 1131 1132 /** 1133 * Print or return content 1134 * 1135 * @param boolean $print Print content. 1136 * @return string contents 1137 */ 1138 public function includeContent(bool $print = true) 1139 { 1140 ob_start(); 1141 tpl_content(false); 1142 $html = ob_get_contents(); 1143 ob_end_clean(); 1144 1145 $html = $this->includeIcons($html); 1146 $html = $this->parseContent($html); 1147 1148 $html .= '<div style="clear:both"></div>'; 1149 1150 if ($this->getConf('heroTitle') === false) { 1151 $html = '<div class="mikio-tags"></div>' . $html; 1152 } 1153 1154 $html = '<div class="mikio-article-content">' . $html . '</div>'; 1155 1156 if ($print === true) { 1157 echo $html; 1158 } 1159 return $html; 1160 } 1161 1162 private function custom_tpl_pageinfo($ret = false) 1163 { 1164 global $conf; 1165 global $lang; 1166 global $INFO; 1167 global $ID; 1168 1169 // return if we are not allowed to view the page 1170 if (!auth_quickaclcheck($ID)) { 1171 return false; 1172 } 1173 1174 if ($INFO['exists']) { 1175 $file = $INFO['filepath']; 1176 if (!$conf['fullpath']) { 1177 if ($INFO['rev']) { 1178 $file = str_replace($conf['olddir'] . '/', '', $file); 1179 } else { 1180 $file = str_replace($conf['datadir'] . '/', '', $file); 1181 } 1182 } 1183 $file = utf8_decodeFN($file); 1184 $date = dformat($INFO['lastmod']); 1185 1186 $string = $this->getConf('footerPageInfoText', ''); 1187 1188 // replace lang items 1189 $string = preg_replace_callback('/%([^%]+)%/', function ($matches) use ($lang) { 1190 return isset($lang[$matches[1]]) ? $lang[$matches[1]] : ''; 1191 }, $string); 1192 1193 $options = [ 1194 'file' => '<bdi>' . $file . '</bdi>', 1195 'date' => $date, 1196 'user' => $INFO['editor'] ? '<bdi>' . editorinfo($INFO['editor']) . '</bdi>' : $lang['external_edit'] 1197 ]; 1198 1199 if (!empty($_SERVER['REMOTE_USER'])) { 1200 $options['loggedin'] = true; 1201 } 1202 1203 if ($INFO['locked']) { 1204 $options['locked'] = '<bdi>' . editorinfo($INFO['locked']) . '</bdi>'; 1205 } 1206 1207 $parser = new \ParensParser(); 1208 $result = $parser->parse($string); 1209 1210 $parserIterate = function ($arr, $func) use ($options) { 1211 $str = ''; 1212 1213 foreach ($arr as $value) { 1214 if (is_array($value)) { 1215 $str .= $func($value, $func); 1216 } else { 1217 if (preg_match('/^([a-zA-Z]+)=(.*)/', $value, $matches)) { 1218 $key = strtolower($matches[1]); // Extract the key (a-zA-Z part) 1219 1220 if (isset($options[$key])) { 1221 $str .= $matches[2]; 1222 } else { 1223 return $str; 1224 } 1225 } else { 1226 $str .= $value; 1227 } 1228 } 1229 }//end foreach 1230 1231 return $str; 1232 }; 1233 1234 $string = $parserIterate($result, $parserIterate); 1235 1236 $string = preg_replace_callback('/{([^}]+)}/', function ($matches) use ($options) { 1237 $key = strtolower($matches[1]); 1238 return isset($options[$key]) ? $options[$key] : ''; 1239 }, $string); 1240 1241 if ($ret) { 1242 return $string; 1243 } else { 1244 echo $string; 1245 return true; 1246 } 1247 }//end if 1248 1249 return false; 1250 } 1251 1252 /** 1253 * Print or return footer 1254 * 1255 * @param boolean $print Print footer. 1256 * @return string HTML string containing footer 1257 */ 1258 public function includeFooter(bool $print = true) 1259 { 1260 global $ACT; 1261 1262 $html = ''; 1263 1264 $html .= '<footer class="mikio-footer">'; 1265 $html .= '<div class="doc">' . $this->custom_tpl_pageinfo(true) . '</div>'; 1266 $html .= $this->includePage('footer', false); 1267 1268 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 1269 1270 if ($this->getConf('footerSearch') === true) { 1271 $html .= '<div class="mikio-footer-search">'; 1272 $html .= $this->includeSearch(false); 1273 $html .= '</div>'; 1274 } 1275 1276 $showPageTools = $this->getConf('pageToolsFooter'); 1277 if ( 1278 strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, 'always') === 0 || 1279 $this->userCanEdit() === true && strcasecmp($showPageTools, 'page editors') === 0) 1280 ) { 1281 $html .= $this->includePageTools(false); 1282 } 1283 1284 $meta['licenseType'] = ['multichoice', '_choices' => ['none', 'badge', 'button']]; 1285 $meta['licenseImageOnly'] = ['onoff']; 1286 1287 $licenseType = $this->getConf('licenseType'); 1288 if ($licenseType !== 'none') { 1289 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true, true); 1290 } 1291 1292 $html .= '</footer>'; 1293 1294 if ($print === true) { 1295 echo $html; 1296 } 1297 return $html; 1298 } 1299 1300 1301 /** 1302 * Print or return breadcrumb trail 1303 * 1304 * @param boolean $print Print out trail. 1305 * @param boolean $parse Parse trail before printing. 1306 * @return string HTML string containing breadcrumbs 1307 */ 1308 public function includeBreadcrumbs(bool $print = true, bool $parse = true) 1309 { 1310 global $conf, $ID, $lang, $ACT; 1311 1312 if ( 1313 $this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 && 1314 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0 1315 ) { 1316 return ''; 1317 } 1318 1319 $html = '<div class="mikio-breadcrumbs">'; 1320 $html .= '<div class="mikio-container">'; 1321 if (strcasecmp($ACT, 'show') === 0) { 1322 if ($conf['breadcrumbs'] !== 0) { 1323 if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) { 1324 ob_start(); 1325 tpl_breadcrumbs(); 1326 $html .= ob_get_contents(); 1327 ob_end_clean(); 1328 } else { 1329 $sep = '•'; 1330 $prefix = $lang['breadcrumb']; 1331 1332 if ($this->getConf('breadcrumbSep') === true) { 1333 $sep = $this->getConf('breadcrumbSepText'); 1334 $img = $this->getMediaFile('breadcrumb-sep', false); 1335 1336 if ($img !== false) { 1337 $sep = '<img src="' . $img . '">'; 1338 } 1339 } 1340 1341 if ($this->getConf('breadcrumbPrefix') === true) { 1342 $prefix = $this->getConf('breadcrumbPrefixText'); 1343 $img = $this->getMediaFile('breadcrumb-prefix', false); 1344 1345 if ($img !== false) { 1346 $prefix = '<img src="' . $img . '">'; 1347 } 1348 } 1349 1350 $crumbs = breadcrumbs(); 1351 1352 $html .= '<ul>'; 1353 if (empty($prefix) === false) { 1354 $html .= '<li class="prefix">' . $prefix . '</li>'; 1355 } 1356 1357 $last = count($crumbs); 1358 $i = 0; 1359 foreach ($crumbs as $id => $name) { 1360 $i++; 1361 if ($i !== 1) { 1362 $html .= '<li class="sep">' . $sep . '</li>'; 1363 } 1364 $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>'; 1365 $html .= tpl_pagelink($id, null, true); 1366 $html .= '</li>'; 1367 } 1368 1369 $html .= '</ul>'; 1370 }//end if 1371 }//end if 1372 }//end if 1373 1374 $html .= '</div>'; 1375 $html .= '</div>'; 1376 1377 if ($parse === true) { 1378 $html = $this->includeIcons($html); 1379 } 1380 if ($print === true) { 1381 echo $html; 1382 } 1383 return $html; 1384 } 1385 1386 /** 1387 * Print or return you are here trail 1388 * 1389 * @param boolean $print Print out trail. 1390 * @param boolean $parse Parse trail before printing. 1391 * @return string HTML string containing breadcrumbs 1392 */ 1393 public function includeYouAreHere(bool $print = true, bool $parse = true) 1394 { 1395 global $conf, $ID, $lang, $ACT; 1396 1397 if ( 1398 $this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 && 1399 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0 1400 ) { 1401 return ''; 1402 } 1403 1404 $html = '<div class="mikio-youarehere">'; 1405 $html .= '<div class="mikio-container">'; 1406 if (strcasecmp($ACT, 'show') === 0) { 1407 if ($conf['youarehere'] !== 0) { 1408 if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) { 1409 $html .= '<div class="mikio-bcdw">'; 1410 ob_start(); 1411 tpl_youarehere(); 1412 $html .= ob_get_contents(); 1413 ob_end_clean(); 1414 $html .= '</div>'; 1415 } else { 1416 $sep = ' » '; 1417 $prefix = $lang['youarehere']; 1418 1419 if ($this->getConf('youarehereSep') === true) { 1420 $sep = $this->getConf('youarehereSepText'); 1421 $img = $this->getMediaFile('youarehere-sep', false); 1422 1423 if ($img !== false) { 1424 $sep = '<img src="' . $img . '">'; 1425 } 1426 } 1427 1428 if ($this->getConf('youareherePrefix') === true) { 1429 $prefix = $this->getConf('youareherePrefixText'); 1430 $img = $this->getMediaFile('youarehere-prefix', false); 1431 1432 if ($img !== false) { 1433 $prefix = '<img src="' . $img . '">'; 1434 } 1435 } 1436 1437 $html .= '<ul>'; 1438 if (empty($prefix) === false) { 1439 $html .= '<li class="prefix">' . $prefix . '</li>'; 1440 } 1441 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>'; 1442 1443 $parts = explode(':', $ID); 1444 $count = count($parts); 1445 1446 $part = ''; 1447 for ($i = 0; $i < ($count - 1); $i++) { 1448 $part .= $parts[$i] . ':'; 1449 $page = $part; 1450 if ($page === $conf['start']) { 1451 continue; 1452 } 1453 1454 $html .= '<li class="sep">' . $sep . '</li>'; 1455 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1456 } 1457 1458 $exists = false; 1459 resolve_pageid('', $page, $exists); 1460 if ((isset($page) === true && $page === $part . $parts[$i]) === false) { 1461 $page = $part . $parts[$i]; 1462 if ($page !== $conf['start']) { 1463 $html .= '<li class="sep">' . $sep . '</li>'; 1464 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1465 } 1466 } 1467 1468 $html .= '</ul>'; 1469 }//end if 1470 }//end if 1471 1472 $showLast = $this->getConf('youarehereShowLast'); 1473 if ($showLast !== 0) { 1474 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1475 if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) { 1476 $count = count($matches[0]); 1477 $list = ''; 1478 1479 // Show Home 1480 $list .= $matches[0][0] . $matches[0][1]; 1481 1482 $list .= '<li>...</li>'; 1483 for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) { 1484 $list .= $matches[0][$i]; 1485 } 1486 1487 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1488 } 1489 } 1490 1491 switch ($this->getConf('youarehereHome')) { 1492 case 'none': 1493 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1494 break; 1495 case 'home': 1496 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1497 break; 1498 case 'icon': 1499 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . 1500 $this->mikioInlineIcon('home') . '$3', $html, 1); 1501 break; 1502 } 1503 } else { 1504 $html .= '≪ '; 1505 if (isset($_GET['page']) === true) { 1506 $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">Back</a> / '; 1507 } 1508 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1509 }//end if 1510 1511 $html .= '</div>'; 1512 $html .= '</div>'; 1513 1514 if ($parse === true) { 1515 $html = $this->includeIcons($html); 1516 } 1517 if ($print === true) { 1518 echo $html; 1519 } 1520 return $html; 1521 } 1522 1523 /** 1524 * Get Page Title 1525 * 1526 * @return string page title 1527 */ 1528 public function parsePageTitle() 1529 { 1530 global $ID; 1531 1532 $title = p_get_first_heading($ID); 1533 if (strlen($title) <= 0) { 1534 $title = tpl_pagetitle(null, true); 1535 } 1536 $title = $this->includeIcons($title); 1537 1538 return $title; 1539 } 1540 1541 1542 /** 1543 * Print or return hero block 1544 * 1545 * @param boolean $print Print content. 1546 * @return string contents of hero 1547 */ 1548 public function includeHero(bool $print = true) 1549 { 1550 $html = ''; 1551 1552 if ($this->getConf('heroTitle') === true) { 1553 $html .= '<div class="mikio-hero">'; 1554 $html .= '<div class="mikio-container">'; 1555 $html .= '<div class="mikio-hero-text">'; 1556 if (strcasecmp($this->getConf('youareherePosition'), 'hero') === 0) { 1557 $html .= $this->includeYouAreHere(false); 1558 } 1559 if (strcasecmp($this->getConf('breadcrumbPosition'), 'hero') === 0) { 1560 $html .= $this->includeBreadcrumbs(false); 1561 } 1562 1563 $html .= '<h1 class="mikio-hero-title">'; 1564 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1565 $html .= '</h1>'; 1566 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1567 $html .= '</div>'; 1568 1569 $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true)); 1570 $hero_image_resize_class = ''; 1571 if (empty($hero_image) === false) { 1572 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1573 $hero_image_resize_class = ' mikio-hero-image-resize'; 1574 } 1575 1576 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . 1577 '><div class="mikio-tags"></div></div>'; 1578 1579 $html .= '</div>'; 1580 $html .= '</div>'; 1581 }//end if 1582 1583 if ($print === true) { 1584 echo $html; 1585 } 1586 1587 return $html; 1588 } 1589 1590 1591 /** 1592 * Print or return out TOC 1593 * 1594 * @param boolean $print Print TOC. 1595 * @param boolean $parse Parse icons. 1596 * @return string contents of TOC 1597 */ 1598 public function includeTOC(bool $print = true, bool $parse = true) 1599 { 1600 $html = ''; 1601 1602 $tocHtml = tpl_toc(true); 1603 1604 if (empty($tocHtml) === false) { 1605 $tocHtml = preg_replace( 1606 '/(<h3.+?toggle.+?>)(.+?)<\/h3>/', 1607 '$1' . 1608 $this->mikioInlineIcon('hamburger', 'hamburger') . '$2' . 1609 $this->mikioInlineIcon('down-arrow', 'down-arrow') . '</h3>', 1610 $tocHtml 1611 ); 1612 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1613 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1614 1615 $html .= '<div class="mikio-toc">'; 1616 $html .= $tocHtml; 1617 $html .= '</div>'; 1618 } 1619 1620 if ($parse === true) { 1621 $html = $this->includeIcons($html); 1622 } 1623 1624 if ($print === true) { 1625 echo $html; 1626 } 1627 1628 return $html; 1629 } 1630 1631 1632 /** 1633 * Parse the string and replace icon elements with included icon libraries 1634 * 1635 * @param string $str Content to parse. 1636 * @return string parsed string 1637 */ 1638 public function includeIcons(string $str) 1639 { 1640 global $ACT, $MIKIO_ICONS; 1641 1642 $iconTag = $this->getConf('iconTag', 'icon'); 1643 if (empty($iconTag) === true) { 1644 return $str; 1645 } 1646 1647 if ( 1648 in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true || 1649 strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0 1650 ) { 1651 $content = $str; 1652 $preview = null; 1653 1654 if (strcasecmp($ACT, 'preview') === 0) { 1655 $html = new \simple_html_dom(); 1656 $html->stripRNAttrValues = false; 1657 $html->load($str, true, false); 1658 1659 $preview = $html->find('div.preview'); 1660 if (is_array($preview) === true && count($preview) > 0) { 1661 $content = $preview[0]->innertext; 1662 } 1663 } 1664 1665 $page_regex = '/(.*)/'; 1666 if (stripos($str, '<pre') !== false) { 1667 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1668 } 1669 1670 $content = preg_replace_callback($page_regex, function ($icons) { 1671 $iconTag = $this->getConf('iconTag', 'icon'); 1672 1673 return preg_replace_callback( 1674 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1675 function ($matches) { 1676 global $MIKIO_ICONS; 1677 1678 $s = $matches[0]; 1679 1680 if (count($MIKIO_ICONS) > 0) { 1681 $icon = $MIKIO_ICONS[0]; 1682 1683 if (count($matches) > 1) { 1684 $e = explode(' ', $matches[1]); 1685 1686 if (count($e) > 1) { 1687 foreach ($MIKIO_ICONS as $iconItem) { 1688 if (strcasecmp($iconItem['name'], $e[0]) === 0) { 1689 $icon = $iconItem; 1690 1691 $s = $icon['insert']; 1692 for ($i = 1; $i < 9; $i++) { 1693 if (count($e) < $i || empty($e[$i]) === true) { 1694 if (isset($icon['$' . $i]) === true) { 1695 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1696 } 1697 } else { 1698 $s = str_replace('$' . $i, $e[$i], $s); 1699 } 1700 } 1701 1702 $dir = ''; 1703 if (isset($icon['dir']) === true) { 1704 $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1705 } 1706 1707 $s = str_replace('$0', $dir, $s); 1708 1709 break; 1710 }//end if 1711 }//end foreach 1712 } else { 1713 $s = str_replace('$1', $matches[1], $icon['insert']); 1714 }//end if 1715 }//end if 1716 }//end if 1717 1718 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1719 if ($count === 0) { 1720 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1721 } 1722 1723 return $s; 1724 }, 1725 $icons[0] 1726 ); 1727 }, $content); 1728 1729 if (strcasecmp($ACT, 'preview') === 0) { 1730 if (is_array($preview) === true && count($preview) > 0) { 1731 $preview[0]->innertext = $content; 1732 } 1733 1734 $str = $html->save(); 1735 $html->clear(); 1736 unset($html); 1737 } else { 1738 $str = $content; 1739 } 1740 }//end if 1741 1742 return $str; 1743 } 1744 1745 /** 1746 * Parse HTML for theme 1747 * 1748 * @param string $content HTML content to parse. 1749 * @return string Parsed content 1750 */ 1751 public function parseContent(string $content) 1752 { 1753 global $INPUT, $ACT; 1754 1755 // Add Mikio Section titles 1756 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1757 $admin_sections = [ 1758 // Section Insert Before Icon 1759 'navbar' => ['navbarUseTitleIcon', ''], 1760 'search' => ['searchButton', ''], 1761 'hero' => ['heroTitle', ''], 1762 'tags' => ['tagsConsolidate', ''], 1763 'breadcrumb' => ['breadcrumbHideHome', ''], 1764 'youarehere' => ['youarehereHideHome', ''], 1765 'sidebar' => ['sidebarShowLeft', ''], 1766 'toc' => ['tocFull', ''], 1767 'pagetools' => ['pageToolsFloating', ''], 1768 'footer' => ['footerPageInfoText', ''], 1769 'license' => ['licenseType', ''], 1770 'acl' => ['includePageUseACL', ''], 1771 'sticky' => ['stickyTopHeader', ''], 1772 ]; 1773 1774 foreach ($admin_sections as $section => $items) { 1775 $search = $items[0]; 1776 $icon = $items[1]; 1777 1778 $content = preg_replace( 1779 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1780 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . 1781 tpl_getLang('config_' . $section) . 1782 '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . 1783 $search . '</span>', 1784 $content 1785 ); 1786 } 1787 } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) { 1788 $mikioPluginMissing = true; 1789 /* Hide plugin fields if not installed */ 1790 if (plugin_load('action', 'mikioplugin') !== null) { 1791 $mikioPluginMissing = false; 1792 } 1793 1794 $style_headers = [ 1795 ['title' => 'Base', 'starts_with' => '__text_'], 1796 ['title' => 'Code', 'starts_with' => '__code_'], 1797 ['title' => 'Controls', 'starts_with' => '__control_'], 1798 ['title' => 'Header', 'starts_with' => '__topheader_'], 1799 ['title' => 'Navbar', 'starts_with' => '__navbar_'], 1800 ['title' => 'Sub Navbar', 'starts_with' => '__subnavbar_'], 1801 ['title' => 'Tags', 'starts_with' => '__tag_background_color_'], 1802 ['title' => 'Breadcrumbs', 'starts_with' => '__breadcrumb_'], 1803 ['title' => 'Hero', 'starts_with' => '__hero_'], 1804 ['title' => 'Sidebar', 'starts_with' => '__sidebar_'], 1805 ['title' => 'Content', 'starts_with' => '__content_'], 1806 ['title' => 'TOC', 'starts_with' => '__toc_'], 1807 ['title' => 'Page Tools', 'starts_with' => '__pagetools_'], 1808 ['title' => 'Footer', 'starts_with' => '__footer_'], 1809 ['title' => 'Table', 'starts_with' => '__table_'], 1810 ['title' => 'Dropdown', 'starts_with' => '__dropdown_'], 1811 ['title' => 'Section Edit', 'starts_with' => '__section_edit_'], 1812 ['title' => 'Tree', 'starts_with' => '__tree_'], 1813 ['title' => 'Tabs', 'starts_with' => '__tab_'], 1814 ['title' => 'Mikio Plugin', 'starts_with' => '__plugin_', 'heading' => 'h2', 1815 'hidden' => $mikioPluginMissing 1816 ], 1817 ['title' => 'Primary Colours', 'starts_with' => '__plugin_primary_', 'hidden' => $mikioPluginMissing], 1818 ['title' => 'Secondary Colours', 'starts_with' => '__plugin_secondary_', 1819 'hidden' => $mikioPluginMissing 1820 ], 1821 ['title' => 'Success Colours', 'starts_with' => '__plugin_success_', 'hidden' => $mikioPluginMissing], 1822 ['title' => 'Danger Colours', 'starts_with' => '__plugin_danger_', 'hidden' => $mikioPluginMissing], 1823 ['title' => 'Warning Colours', 'starts_with' => '__plugin_warning_', 'hidden' => $mikioPluginMissing], 1824 ['title' => 'Info Colours', 'starts_with' => '__plugin_info_', 'hidden' => $mikioPluginMissing], 1825 ['title' => 'Light Colours', 'starts_with' => '__plugin_light_', 'hidden' => $mikioPluginMissing], 1826 ['title' => 'Dark Colours', 'starts_with' => '__plugin_dark_', 'hidden' => $mikioPluginMissing], 1827 ['title' => 'Link Colours', 'starts_with' => '__plugin_link_', 'hidden' => $mikioPluginMissing], 1828 ['title' => 'Carousel', 'starts_with' => '__plugin_carousel_', 'hidden' => $mikioPluginMissing], 1829 ['title' => 'Steps', 'starts_with' => '__plugin_steps_', 'hidden' => $mikioPluginMissing], 1830 ['title' => 'Tabgroup', 'starts_with' => '__plugin_tabgroup_', 'hidden' => $mikioPluginMissing], 1831 ['title' => 'Tooltip', 'starts_with' => '__plugin_tooltip_', 'hidden' => $mikioPluginMissing], 1832 ['title' => 'Dark Mode', 'starts_with' => '__darkmode_', 'heading' => 'h2'], 1833 ['title' => 'Base', 'starts_with' => '__darkmode_text_'], 1834 ['title' => 'Code', 'starts_with' => '__darkmode_code_'], 1835 ['title' => 'Controls', 'starts_with' => '__darkmode_control_'], 1836 ['title' => 'Header', 'starts_with' => '__darkmode_topheader_'], 1837 ['title' => 'Navbar', 'starts_with' => '__darkmode_navbar_'], 1838 ['title' => 'Sub Navbar', 'starts_with' => '__darkmode_subnavbar_'], 1839 ['title' => 'Tags', 'starts_with' => '__darkmode_tag_background_color_'], 1840 ['title' => 'Breadcrumbs', 'starts_with' => '__darkmode_breadcrumb_'], 1841 ['title' => 'Hero', 'starts_with' => '__darkmode_hero_'], 1842 ['title' => 'Sidebar', 'starts_with' => '__darkmode_sidebar_'], 1843 ['title' => 'Content', 'starts_with' => '__darkmode_content_'], 1844 ['title' => 'TOC', 'starts_with' => '__darkmode_toc_'], 1845 ['title' => 'Page Tools', 'starts_with' => '__darkmode_pagetools_'], 1846 ['title' => 'Footer', 'starts_with' => '__darkmode_footer_'], 1847 ['title' => 'Table', 'starts_with' => '__darkmode_table_'], 1848 ['title' => 'Dropdown', 'starts_with' => '__darkmode_dropdown_'], 1849 ['title' => 'Section Edit', 'starts_with' => '__darkmode_section_edit_'], 1850 ['title' => 'Tree', 'starts_with' => '__darkmode_tree_'], 1851 ['title' => 'Tabs', 'starts_with' => '__darkmode_tab_'], 1852 ['title' => 'Mikio Plugin (Dark mode)', 'starts_with' => '__plugin_darkmode_', 'heading' => 'h2', 1853 'hidden' => $mikioPluginMissing 1854 ], 1855 ['title' => 'Primary Colours', 'starts_with' => '__plugin_darkmode_primary_', 1856 'hidden' => $mikioPluginMissing 1857 ], 1858 ['title' => 'Secondary Colours', 'starts_with' => '__plugin_darkmode_secondary_', 1859 'hidden' => $mikioPluginMissing 1860 ], 1861 ['title' => 'Success Colours', 'starts_with' => '__plugin_darkmode_success_', 1862 'hidden' => $mikioPluginMissing 1863 ], 1864 ['title' => 'Danger Colours', 'starts_with' => '__plugin_darkmode_danger_', 1865 'hidden' => $mikioPluginMissing 1866 ], 1867 ['title' => 'Warning Colours', 'starts_with' => '__plugin_darkmode_warning_', 1868 'hidden' => $mikioPluginMissing 1869 ], 1870 ['title' => 'Info Colours', 'starts_with' => '__plugin_darkmode_info_', 1871 'hidden' => $mikioPluginMissing 1872 ], 1873 ['title' => 'Light Colours', 'starts_with' => '__plugin_darkmode_light_', 1874 'hidden' => $mikioPluginMissing 1875 ], 1876 ['title' => 'Dark Colours', 'starts_with' => '__plugin_darkmode_dark_', 1877 'hidden' => $mikioPluginMissing 1878 ], 1879 ['title' => 'Link Colours', 'starts_with' => '__plugin_darkmode_link_', 1880 'hidden' => $mikioPluginMissing 1881 ], 1882 ['title' => 'Carousel', 'starts_with' => '__plugin_darkmode_carousel_', 1883 'hidden' => $mikioPluginMissing 1884 ], 1885 ['title' => 'Steps', 'starts_with' => '__plugin_darkmode_steps_', 'hidden' => $mikioPluginMissing], 1886 ['title' => 'Tabgroup', 'starts_with' => '__plugin_darkmode_tabgroup_', 1887 'hidden' => $mikioPluginMissing 1888 ], 1889 ['title' => 'Tooltip', 'starts_with' => '__plugin_darkmode_tooltip_', 'hidden' => $mikioPluginMissing], 1890 ]; 1891 1892 foreach ($style_headers as $header) { 1893 if (array_key_exists('heading', $header) === false) { 1894 $header['heading'] = 'h3'; 1895 } 1896 1897 if (array_key_exists('hidden', $header) === false) { 1898 $header['hidden'] = false; 1899 } 1900 1901 $content = preg_replace( 1902 '/(<tr>\s*<td>\s*<label for="tpl__' . $header['starts_with'] . '.+?<\/tr>)/s', 1903 '</tbody></table><' . $header['heading'] . ' style="display:' . 1904 ($header['hidden'] === true ? 'none' : 'block') . '">' . 1905 $header['title'] . '</' . $header['heading'] . '> 1906 <table style="display:' . ($header['hidden'] === true ? 'none' : 'table') . '"><tbody>$1', 1907 $content, 1908 1 1909 ); 1910 } 1911 1912 $content = preg_replace_callback('/<input type="color"[^>]*>/', function ($match) { 1913 // Get the ID of the <input type="color"> element 1914 preg_match('/id="([^"]*)"/', $match[0], $matches); 1915 1916 // Replace type with text and remove the id attribute 1917 $replacement = preg_replace( 1918 ['/type="color"/', '/id="([^"]*)"/'], 1919 ['type="text" class="mikio-color-text-input"', 'for="$1"'], 1920 $match[0] 1921 ); 1922 1923 return '<div class="mikio-color-picker">' . $replacement . $match[0] . '</div>'; 1924 }, $content); 1925 }//end if 1926 1927 if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) { 1928 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1929 } 1930 1931 // Page Revisions - Table Fix 1932 if (strpos($content, 'id="page__revisions"') !== false) { 1933 $content = preg_replace( 1934 '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', 1935 '<span>$1</span>', 1936 $content 1937 ); 1938 } 1939 1940 $html = new \simple_html_dom(); 1941 $html->stripRNAttrValues = false; 1942 $html->load($content, true, false); 1943 1944 if ($html === false) { 1945 return $content; 1946 } 1947 1948 /* Buttons */ 1949 foreach ($html->find('#config__manager button') as $node) { 1950 $c = explode(' ', $node->class); 1951 if (in_array('mikio-button', $c) === false) { 1952 $c[] = 'mikio-button'; 1953 } 1954 $node->class = implode(' ', $c); 1955 } 1956 1957 1958 /* Buttons - Primary */ 1959 foreach ($html->find('#config__manager [type=submit]') as $node) { 1960 $c = explode(' ', $node->class); 1961 if (in_array('mikio-primary', $c) === false) { 1962 $c[] = 'mikio-primary'; 1963 } 1964 $node->class = implode(' ', $c); 1965 } 1966 1967 /* Hide page title if hero is enabled */ 1968 if ($this->getConf('heroTitle') === true && $ACT !== 'preview') { 1969 $pageTitle = $this->parsePageTitle(); 1970 1971 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1972 if ($elm->innertext === $pageTitle) { 1973 // $elm->innertext = ''; 1974 $elm->setAttribute('style', 'display:none'); 1975 1976 break; 1977 } 1978 } 1979 } 1980 1981 /* Hero subtitle */ 1982 foreach ($html->find('p') as $elm) { 1983 if (preg_match('/[~-]~hero-subtitle (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 1984 $subtitle = $matches[1]; 1985 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1986 1987 $elm->innertext = preg_replace('/[~-]~hero-subtitle (.+?)~[~-]/ui', '', $elm->innertext); 1988 break; 1989 } 1990 } 1991 1992 /* Hero image */ 1993 foreach ($html->find('p') as $elm) { 1994 $image = ''; 1995 preg_match('/[~-]~hero-image (.+?)~[~-](?!.?")/ui', $elm->innertext, $matches); 1996 if (count($matches) > 0) { 1997 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1998 if (count($imageTagMatches) > 0) { 1999 $image = $imageTagMatches[1]; 2000 } else { 2001 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 2002 if (count($imageTagMatches) > 0) { 2003 $image = $imageTagMatches[1]; 2004 } else { 2005 $image = strip_tags($matches[1]); 2006 if (stripos($image, ':') === false) { 2007 $image = str_replace(['{', '}'], '', $image); 2008 $i = stripos($image, '?'); 2009 if ($i !== false) { 2010 $image = substr($image, 0, $i); 2011 } 2012 2013 $image = ml($image, '', true, '', false); 2014 } 2015 } 2016 } 2017 2018 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 2019 2020 $elm->innertext = preg_replace('/[~-]~hero-image (.+?)~[~-].*/ui', '', $elm->innertext); 2021 }//end if 2022 }//end foreach 2023 2024 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] 2025 [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 2026 foreach ($html->find('p') as $elm) { 2027 if (preg_match('/[~-]~hero-colors (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 2028 $subtitle = $matches[1]; 2029 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $subtitle . '\')'; 2030 2031 $elm->innertext = preg_replace('/[~-]~hero-colors (.+?)~[~-]/ui', '', $elm->innertext); 2032 break; 2033 } 2034 } 2035 2036 /* Hide parts - ~~hide-parts [parts]~~ */ 2037 foreach ($html->find('p') as $elm) { 2038 if (preg_match('/[~-]~hide-parts (.+?)~[~-]/ui', $elm->innertext, $matches) === 1) { 2039 $parts = explode(' ', $matches[1]); 2040 $script = ''; 2041 2042 foreach ($parts as $part) { 2043 if (strlen($part) > 0) { 2044 $script .= 'mikio.hidePart(\'' . $part . '\');'; 2045 } 2046 } 2047 2048 if (strlen($script) > 0) { 2049 $this->footerScript['hide-parts'] = $script; 2050 } 2051 2052 $elm->innertext = preg_replace('/[~-]~hide-parts (.+?)~[~-]/ui', '', $elm->innertext); 2053 break; 2054 } 2055 }//end foreach 2056 2057 2058 /* Page Tags (tag plugin) */ 2059 if ($this->getConf('tagsConsolidate') === true) { 2060 $tags = ''; 2061 foreach ($html->find('div.tags a') as $elm) { 2062 $tags .= $elm->outertext; 2063 } 2064 2065 foreach ($html->find('div.tags') as $elm) { 2066 $elm->innertext = ''; 2067 $elm->setAttribute('style', 'display:none'); 2068 } 2069 2070 if (empty($tags) === false) { 2071 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 2072 } 2073 } 2074 2075 // Configuration Manager 2076 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 2077 // Additional save buttons 2078 foreach ($html->find('#config__manager') as $cm) { 2079 $saveButtons = ''; 2080 2081 foreach ($cm->find('p') as $elm) { 2082 $saveButtons = $elm->outertext; 2083 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 2084 $elm->outertext = ''; 2085 } 2086 2087 foreach ($cm->find('fieldset') as $elm) { 2088 $elm->innertext .= $saveButtons; 2089 } 2090 } 2091 } 2092 2093 $content = $html->save(); 2094 $html->clear(); 2095 unset($html); 2096 2097 return $content; 2098 } 2099 2100 2101 /** 2102 * Get DokuWiki namespace/page/URI as link 2103 * 2104 * @param string $str String to parse. 2105 * @return string parsed URI 2106 */ 2107 public function getLink(string $str) 2108 { 2109 $i = strpos($str, '://'); 2110 if ($i !== false) { 2111 return $str; 2112 } 2113 2114 return wl($str); 2115 } 2116 2117 2118 /** 2119 * Check if the user can edit current namespace/page 2120 * 2121 * @return boolean user can edit 2122 */ 2123 public function userCanEdit() 2124 { 2125 global $INFO; 2126 global $ID; 2127 2128 $wiki_file = wikiFN($ID); 2129 if (@file_exists($wiki_file) === false) { 2130 return true; 2131 } 2132 if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) { 2133 return true; 2134 } 2135 // $meta_file = metaFN($ID, '.meta'); 2136 if ($INFO['meta']['user'] === false) { 2137 return true; 2138 } 2139 if ($INFO['client'] === $INFO['meta']['user']) { 2140 return true; 2141 } 2142 2143 return false; 2144 } 2145 2146 2147 /** 2148 * Search for and return the uri of a media file 2149 * 2150 * @param string $image Image name to search for (without extension). 2151 * @param boolean $searchCurrentNS Search the current namespace. 2152 * @param boolean $propagate Propagate search through the namespace. 2153 * @return string URI of the found media file 2154 */ 2155 public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true) 2156 { 2157 global $INFO; 2158 2159 $ext = ['png', 'jpg', 'gif', 'svg']; 2160 2161 if ($searchCurrentNS === true) { 2162 $prefix[] = ':' . $INFO['namespace'] . ':'; 2163 } 2164 if ($propagate === true) { 2165 $prefix[] = ':'; 2166 $prefix[] = ':wiki:'; 2167 } 2168 $theme = $this->getConf('customTheme'); 2169 if (empty($theme) === false) { 2170 $prefix[] = 'themes/' . $theme . '/images/'; 2171 } 2172 $prefix[] = 'images/'; 2173 2174 $search = []; 2175 foreach ($prefix as $pitem) { 2176 foreach ($ext as $eitem) { 2177 $search[] = $pitem . $image . '.' . $eitem; 2178 } 2179 } 2180 2181 $img = ''; 2182 $file = ''; 2183 $url = ''; 2184 $ismedia = false; 2185 $found = false; 2186 2187 foreach ($search as $img) { 2188 if (strcasecmp(substr($img, 0, 1), ':') === 0) { 2189 $file = mediaFN($img); 2190 $ismedia = true; 2191 } else { 2192 $file = tpl_incdir() . $img; 2193 $ismedia = false; 2194 } 2195 2196 if (file_exists($file) === true) { 2197 $found = true; 2198 break; 2199 } 2200 } 2201 2202 if ($found === false) { 2203 return false; 2204 } 2205 2206 if ($ismedia === true) { 2207 $url = ml($img, '', true, '', false); 2208 } else { 2209 $url = tpl_basedir() . $img; 2210 } 2211 2212 return $url; 2213 } 2214 2215 2216 /** 2217 * Print or return the page title 2218 * 2219 * @param string $page Page id or empty string for current page. 2220 * @return string generated content 2221 */ 2222 public function getPageTitle(string $page = '') 2223 { 2224 global $ID, $conf; 2225 2226 $html = ''; 2227 2228 if (empty($page) === true) { 2229 $page = $ID; 2230 } 2231 2232 $html = p_get_first_heading($page); 2233 $html = strip_tags($html); 2234 $html = preg_replace('/\s+/', ' ', $html); 2235 $html .= ' [' . strip_tags($conf['title']) . ']'; 2236 $html = trim($html); 2237 2238 return $html; 2239 } 2240 2241 2242 /** 2243 * Return inline theme icon 2244 * 2245 * @param string $type Icon to retreive. 2246 * @param string $class Classname to insert. 2247 * @return string HTML icon content 2248 */ 2249 public function mikioInlineIcon(string $type, string $class = "") 2250 { 2251 if (is_array($class) === true) { 2252 $class = explode(' ', $class); 2253 } 2254 2255 if (strlen($class) > 0) { 2256 $class = ' ' . $class; 2257 } 2258 2259 switch ($type) { 2260 case 'wrench': 2261 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 22621792" 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, 226319 -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, 2264-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, 2265435 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 2266131.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, 2267-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>'; 2268 case 'file': 2269 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2270viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"> 2271<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 22721280,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 2273q 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" 2274xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2275 case 'gear': 2276 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2277viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"> 2278<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 2279181,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 228010,-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 2281-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 2282147,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 2283q 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, 228471.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 2285q 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 2286-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" /> 2287</g></svg>'; 2288 case 'user': 2289 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2290viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 22911408,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 229228,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, 2293-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 229450.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 2295-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, 22961408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>'; 2297 case 'search': 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="M27 24.57l-5.647-5.648a8.895 8.895 0 0 0 1.522-4.984C22.875 9.01 230018.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 230124.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 23026.195 0 0 1-6.188 6.188z"/></svg>'; 2303 case 'home': 2304 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2305viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g 2306transform="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 2307960 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 2308m 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 2309-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, 2310-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" 2311xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2312 case 'sun': 2313 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2314style="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 23150 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 23160a.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 23171-.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 23180 0 1-.707.707z" /></svg>'; 2319 case 'moon': 2320 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2321style="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 23224.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 23231 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 23241.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 23250-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>'; 2326 case 'sunmoon': 2327 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2328style="fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10" 2329viewBox="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 2330x1="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" 2331y2="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, 23322.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>'; 2333 case 'hamburger': 2334 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" 2335style="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 233676v40c0 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 233716v40c0 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 233816v40c0 8.837 7.163 16 16 16z"/></svg>'; 2339 case 'down-arrow': 2340 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2341aria-hidden="true" style="fill:currentColor"><path d="M16.003 18.626l7.081-7.081L25 13.46l-8.997 8.998-9.003-9 23421.917-1.916z"/></svg>'; 2343 case 'language': 2344 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" width="16" 2345height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.545 6.714 4.11 23468H3l1.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 23472-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 23480 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 23491.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 23501.472.133-.254.414-.673.629-.89-1.125-.253-2.057-.694-2.82-1.284.681-.747 1.222-1.651 23511.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"/> 2352</svg>'; 2353 }//end switch 2354 2355 return ''; 2356 } 2357 2358 /** 2359 * Finalize theme 2360 * 2361 * @return void 2362 */ 2363 public function finalize() 2364 { 2365 } 2366 2367 /** 2368 * Show Messages 2369 * 2370 * @return void 2371 */ 2372 public function showMessages() 2373 { 2374 global $ACT; 2375 2376 if ($this->lessIgnored === true) { 2377 msg( 2378 'useLESS is enabled on the Mikio template, however is not supported on this server', 2379 2, 2380 '', 2381 '', 2382 MSG_ADMINS_ONLY 2383 ); 2384 } 2385 2386 $show = $this->getConf('showNotifications'); 2387 if ( 2388 strlen($show) === 0 || 2389 strcasecmp($show, 'always') === 0 || 2390 (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0) 2391 ) { 2392 html_msgarea(); 2393 2394 // global $MSG, $MSG_shown; 2395 2396 // if (isset($MSG) !== false) { 2397 // if (isset($MSG_shown) === false) { 2398 // $MSG_shown = []; 2399 // } 2400 2401 // foreach ($MSG as $msg) { 2402 // $hash = md5($msg['msg']); 2403 // if (isset($MSG_shown[$hash]) === true) { 2404 // continue; 2405 // } 2406 // // skip double messages 2407 2408 // if (info_msg_allowed($msg) === true) { 2409 // echo '<div class="me ' . $msg['lvl'] . '">'; 2410 // echo $msg['msg']; 2411 // echo '</div>'; 2412 // } 2413 2414 // $MSG_shown[$hash] = true; 2415 // } 2416 2417 // unset($GLOBALS['MSG']); 2418 // }//end if 2419 2420 if (strlen($this->includedPageNotifications) > 0) { 2421 echo $this->includedPageNotifications; 2422 } 2423 }//end if 2424 } 2425 2426 /** 2427 * Dokuwiki version 2428 * 2429 * @return string the dw version name 2430 */ 2431 public function dwVersion() 2432 { 2433 if (function_exists('getVersionData') === true) { 2434 $version_data = getVersionData(); 2435 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2436 $version_items = explode(' ', $version_data['date']); 2437 if (count($version_items) >= 2) { 2438 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 2439 } 2440 } 2441 } 2442 2443 return 'unknown'; 2444 } 2445 2446 /** 2447 * Dokuwiki version number 2448 * 2449 * @return string the dw version date converted to integer 2450 */ 2451 public function dwVersionNumber() 2452 { 2453 if (function_exists('getVersionData') === true) { 2454 $version_data = getVersionData(); 2455 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2456 $version_items = explode(' ', $version_data['date']); 2457 if (count($version_items) >= 1) { 2458 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 2459 } 2460 } 2461 } 2462 2463 return 0; 2464 } 2465} 2466 2467global $TEMPLATE; 2468$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 2469