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