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