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