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