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-darklight"> 698<a href="#" class="mikio-control mikio-button mikio-darklight-button">' . 699$this->mikioInlineIcon('sun', 'mikio-darklight-light') . 700$this->mikioInlineIcon('moon', 'mikio-darklight-dark') . 701'</a></li>'; 702 } 703 704 $html .= '</ul>'; 705 706 if ($print === true) { 707 echo $html; 708 } 709 return $html; 710 } 711 712 713 /** 714 * Create a nav element from a string. <uri>|<title>; 715 * 716 * @param string $str String to generate nav. 717 * @return string nav elements generated 718 */ 719 public function stringToNav(string $str) 720 { 721 $html = ''; 722 723 if (empty($str) === false) { 724 $items = explode(';', $str); 725 if (count($items) > 0) { 726 $html .= '<ul class="mikio-nav">'; 727 foreach ($items as $item) { 728 $parts = explode('|', $item); 729 if ($parts > 1) { 730 $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' . 731 strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) . 732 '</a></li>'; 733 } 734 } 735 $html .= '</ul>'; 736 } 737 } 738 739 return $html; 740 } 741 742 /** 743 * print or return the main navbar 744 * 745 * @param boolean $print Print the navbar. 746 * @param boolean $showSub Include the sub navbar. 747 * @return string generated content 748 */ 749 public function includeNavbar(bool $print = true, bool $showSub = false) 750 { 751 global $conf, $USERINFO; 752 753 $homeUrl = wl(); 754 755 if (plugin_isdisabled('showpageafterlogin') === false) { 756 $p = &plugin_load('action', 'showpageafterlogin'); 757 if (empty($p) === false) { 758 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 759 $homeUrl = wl($p->getConf('page_after_login')); 760 } 761 } 762 } else { 763 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 764 $url = $this->getConf('brandURLUser'); 765 if (strlen($url) > 0) { 766 $homeUrl = $url; 767 } 768 } else { 769 $url = $this->getConf('brandURLGuest'); 770 if (strlen($url) > 0) { 771 $homeUrl = $url; 772 } 773 } 774 } 775 776 $html = ''; 777 778 $html .= '<nav class="mikio-navbar' . (($this->getConf('stickyNavbar') === true) ? ' mikio-sticky' : '') . 779 '">'; 780 $html .= '<div class="mikio-container">'; 781 $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '">'; 782 if ($this->getConf('navbarUseTitleIcon') === true || $this->getConf('navbarUseTitleText') === true) { 783 // Brand image 784 if ($this->getConf('navbarUseTitleIcon') === true) { 785 $logo = $this->getMediaFile('logo', false); 786 ; 787 if (empty($logo) === false) { 788 $width = $this->getConf('navbarTitleIconWidth'); 789 $height = $this->getConf('navbarTitleIconHeight'); 790 $styles = ''; 791 792 if (strlen($width) > 0 || strlen($height) > 0) { 793 if (ctype_digit($width) === true) { 794 $styles .= 'max-width:' . intval($width) . 'px;'; 795 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $width) === 1) { 796 $styles .= 'max-width:' . $width . ';'; 797 } elseif (strcasecmp($width, 'none') === 0) { 798 $styles .= 'max-width:none;'; 799 } 800 801 if (ctype_digit($height) === true) { 802 $styles .= 'max-height:' . intval($height) . 'px;'; 803 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $height) === 1) { 804 $styles .= 'max-height:' . $height . ';'; 805 } elseif (strcasecmp($height, 'none') === 0) { 806 $styles .= 'max-height:none;'; 807 } 808 809 if (strlen($styles) > 0) { 810 $styles = ' style="' . $styles . '"'; 811 } 812 }//end if 813 814 $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image"' . $styles . '>'; 815 }//end if 816 }//end if 817 818 // Brand title 819 if ($this->getConf('navbarUseTitleText') === true) { 820 $html .= '<div class="mikio-navbar-brand-title">'; 821 $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>'; 822 if ($this->getConf('navbarUseTaglineText') === true) { 823 $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>'; 824 } 825 $html .= '</div>'; 826 } 827 }//end if 828 $html .= '</a>'; 829 $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>'; 830 831 // Menus 832 $html .= '<div class="mikio-navbar-collapse">'; 833 834 $menus = [$this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'), 835 $this->getConf('navbarPosRight', 'none') 836 ]; 837 foreach ($menus as $menuType) { 838 switch ($menuType) { 839 case 'custom': 840 $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', '')); 841 break; 842 case 'search': 843 $html .= '<div class="mikio-nav-item">'; 844 $html .= $this->includeSearch(false); 845 $html .= '</div>'; 846 break; 847 case 'dokuwiki': 848 $html .= $this->includeDWMenu(false); 849 break; 850 } 851 } 852 853 $html .= '</div>'; 854 $html .= '</div>'; 855 $html .= '</nav>'; 856 857 // Sub Navbar 858 if ($showSub === true) { 859 $sub = $this->includePage('submenu', false); 860 if (empty($sub) === false) { 861 $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>'; 862 } 863 } 864 865 if ($print === true) { 866 echo $html; 867 } 868 return $html; 869 } 870 871 872 /** 873 * Is there a sidebar 874 * 875 * @param string $prefix Sidebar prefix to use when searching. 876 * @return boolean if sidebar exists 877 */ 878 public function sidebarExists(string $prefix = '') 879 { 880 global $conf; 881 882 if (strcasecmp($prefix, 'left') === 0) { 883 $prefix = ''; 884 } 885 886 return $this->pageExists($conf['sidebar' . $prefix]); 887 } 888 889 890 /** 891 * Print or return the sidebar content 892 * 893 * @param string $prefix Sidebar prefix to use when searching. 894 * @param boolean $print Print the generated content to the output buffer. 895 * @param boolean $parse Parse the content. 896 * @return string generated content 897 */ 898 public function includeSidebar(string $prefix = '', bool $print = true, bool $parse = true) 899 { 900 global $conf, $ID; 901 902 $html = ''; 903 $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix)); 904 $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix)); 905 906 if (empty($confPrefix) === true) { 907 $confPrefix = 'Left'; 908 } 909 if (strcasecmp($prefix, 'left') === 0) { 910 $prefix = ''; 911 } 912 913 $sidebarPage = empty($conf[$prefix . 'sidebar']) === true ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar']; 914 915 if ( 916 $this->getConf('sidebarShow' . $confPrefix) === true && page_findnearest($sidebarPage) !== false && 917 p_get_metadata($ID, 'nosidebar', false) === null 918 ) { 919 $content = $this->includePage($sidebarPage . 'header', false); 920 if (empty($content) === false) { 921 $html .= '<div class="mikio-sidebar-header">' . $content . '</div>'; 922 } 923 924 if (empty($prefix) === true) { 925 $rows = [$this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'), 926 $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4') 927 ]; 928 929 foreach ($rows as $row) { 930 switch ($row) { 931 case 'search': 932 $html .= $this->includeSearch(false); 933 break; 934 case 'logged in user': 935 $html .= $this->includeLoggedIn(false); 936 break; 937 case 'content': 938 $content = $this->includePage($sidebarPage, false); 939 if (empty($content) === false) { 940 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 941 } 942 break; 943 case 'tags': 944 $html .= '<div class="mikio-tags"></div>'; 945 } 946 } 947 } else { 948 $content = $this->includePage($sidebarPage, false); 949 if (empty($content) === false) { 950 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 951 } 952 }//end if 953 954 $content = $this->includePage($sidebarPage . 'footer', false); 955 if (empty($content) === false) { 956 $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>'; 957 } 958 }//end if 959 960 if (empty($html) === true) { 961 if (empty($prefix) === true && $this->getConf('sidebarAlwaysShowLeft') === true) { 962 $html = ' '; 963 } 964 if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix)) === true) { 965 $html = ' '; 966 } 967 } 968 969 if (empty($html) === false) { 970 $html = '<aside class="mikio-sidebar mikio-sidebar-' . (empty($prefix) === true ? 'left' : $prefix) . 971 '"><a class="mikio-sidebar-toggle' . 972 ($this->getConf('sidebarMobileDefaultCollapse') === true ? ' closed' : '') . '" href="#">' . 973 tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="mikio-sidebar-collapse">' . 974 $html . '</div></aside>'; 975 } 976 977 if ($parse === true) { 978 $html = $this->includeIcons($html); 979 } 980 if ($print === true) { 981 echo $html; 982 } 983 return $html; 984 } 985 986 987 /** 988 * Print or return the page tools content 989 * 990 * @param boolean $print Print the generated content to the output buffer. 991 * @param boolean $includeId Include the dw__pagetools id in the element. 992 * @return string generated content 993 */ 994 public function includePageTools(bool $print = true, bool $includeId = false) 995 { 996 global $USERINFO; 997 998 $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0); 999 $html = ''; 1000 1001 $html .= '<nav' . ($includeId === true ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">'; 1002 $html .= '<ul class="tools">'; 1003 1004 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 1005 foreach ($items as $item) { 1006 $classes = []; 1007 $classes[] = $item->getType(); 1008 $attr = $item->getLinkAttributes(); 1009 1010 if (empty($attr['class']) === false) { 1011 $classes = array_merge($classes, explode(' ', $attr['class'])); 1012 } 1013 1014 $classes = array_unique($classes); 1015 1016 $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType())); 1017 if ( 1018 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 1019 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 1020 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === true)) 1021 ) { 1022 $html .= '<li class="' . implode(' ', $classes) . '">'; 1023 $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' . 1024 $item->getTitle() . '"><div class="icon">' . inlineSVG($item->getSvg()) . 1025 '</div><span class="a11y">' . $item->getLabel() . '</span></a>'; 1026 $html .= '</li>'; 1027 } 1028 }//end foreach 1029 1030 $html .= '</ul>'; 1031 $html .= '</nav>'; 1032 1033 if ($print === true) { 1034 echo $html; 1035 } 1036 return $html; 1037 } 1038 1039 1040 /** 1041 * Print or return the search bar 1042 * 1043 * @param boolean $print Print content. 1044 * @return string contents of the search bar 1045 */ 1046 public function includeSearch(bool $print = true) 1047 { 1048 global $lang, $ID, $ACT, $QUERY; 1049 $html = ''; 1050 1051 $html .= '<form class="mikio-search search" action="' . wl() . 1052 '" accept-charset="utf-8" method="get" role="search">'; 1053 $html .= '<input type="hidden" name="do" value="search">'; 1054 $html .= '<input type="hidden" name="id" value="' . $ID . '">'; 1055 $html .= '<input name="q" '; 1056 if ($this->getConf('searchUseTypeahead') === true) { 1057 $html .= 'class="search_typeahead" '; 1058 } 1059 $html .= 'autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . 1060 ((strcasecmp($ACT, 'search') === 0) ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 1061 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 1062 if (strcasecmp($this->getConf('searchButton'), 'icon') === 0) { 1063 $html .= $this->mikioInlineIcon('search'); 1064 } else { 1065 $html .= $lang['btn_search']; 1066 } 1067 $html .= '</button>'; 1068 $html .= '</form>'; 1069 1070 if ($print === true) { 1071 echo $html; 1072 } 1073 return $html; 1074 } 1075 1076 1077 /** 1078 * Print or return content 1079 * 1080 * @param boolean $print Print content. 1081 * @return string contents 1082 */ 1083 public function includeContent(bool $print = true) 1084 { 1085 ob_start(); 1086 tpl_content(false); 1087 $html = ob_get_contents(); 1088 ob_end_clean(); 1089 1090 $html = $this->includeIcons($html); 1091 $html = $this->parseContent($html); 1092 1093 $html .= '<div style="clear:both"></div>'; 1094 1095 if ($this->getConf('heroTitle') === false) { 1096 $html = '<div class="mikio-tags"></div>' . $html; 1097 } 1098 1099 $html = '<div class="mikio-article-content">' . $html . '</div>'; 1100 1101 if ($print === true) { 1102 echo $html; 1103 } 1104 return $html; 1105 } 1106 1107 /** 1108 * Print or return footer 1109 * 1110 * @param boolean $print Print footer. 1111 * @return string HTML string containing footer 1112 */ 1113 public function includeFooter(bool $print = true) 1114 { 1115 global $ACT; 1116 1117 $html = ''; 1118 1119 $html .= '<footer class="mikio-footer">'; 1120 $html .= '<div class="doc">' . tpl_pageinfo(true) . '</div>'; 1121 $html .= $this->includePage('footer', false); 1122 1123 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 1124 1125 if ($this->getConf('footerSearch') === true) { 1126 $html .= '<div class="mikio-footer-search">'; 1127 $html .= $this->includeSearch(false); 1128 $html .= '</div>'; 1129 } 1130 1131 $showPageTools = $this->getConf('pageToolsFooter'); 1132 if ( 1133 strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, 'always') === 0 || 1134 $this->userCanEdit() === true && strcasecmp($showPageTools, 'page editors') === 0) 1135 ) { 1136 $html .= $this->includePageTools(false); 1137 } 1138 1139 $meta['licenseType'] = ['multichoice', '_choices' => ['none', 'badge', 'button']]; 1140 $meta['licenseImageOnly'] = ['onoff']; 1141 1142 $licenseType = $this->getConf('licenseType'); 1143 if ($licenseType !== 'none') { 1144 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true, true); 1145 } 1146 1147 $html .= '</footer>'; 1148 1149 if ($print === true) { 1150 echo $html; 1151 } 1152 return $html; 1153 } 1154 1155 1156 /** 1157 * Print or return breadcrumb trail 1158 * 1159 * @param boolean $print Print out trail. 1160 * @param boolean $parse Parse trail before printing. 1161 * @return string HTML string containing breadcrumbs 1162 */ 1163 public function includeBreadcrumbs(bool $print = true, bool $parse = true) 1164 { 1165 global $conf, $ID, $lang, $ACT; 1166 1167 if ( 1168 $this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 && 1169 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0 1170 ) { 1171 return ''; 1172 } 1173 1174 $html = '<div class="mikio-breadcrumbs">'; 1175 $html .= '<div class="mikio-container">'; 1176 if (strcasecmp($ACT, 'show') === 0) { 1177 if ($conf['breadcrumbs'] !== 0) { 1178 if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) { 1179 ob_start(); 1180 tpl_breadcrumbs(); 1181 $html .= ob_get_contents(); 1182 ob_end_clean(); 1183 } else { 1184 $sep = '•'; 1185 $prefix = $lang['breadcrumb']; 1186 1187 if ($this->getConf('breadcrumbSep') === true) { 1188 $sep = $this->getConf('breadcrumbSepText'); 1189 $img = $this->getMediaFile('breadcrumb-sep', false); 1190 1191 if ($img !== false) { 1192 $sep = '<img src="' . $img . '">'; 1193 } 1194 } 1195 1196 if ($this->getConf('breadcrumbPrefix') === true) { 1197 $prefix = $this->getConf('breadcrumbPrefixText'); 1198 $img = $this->getMediaFile('breadcrumb-prefix', false); 1199 1200 if ($img !== false) { 1201 $prefix = '<img src="' . $img . '">'; 1202 } 1203 } 1204 1205 $crumbs = breadcrumbs(); 1206 1207 $html .= '<ul>'; 1208 if (empty($prefix) === false) { 1209 $html .= '<li class="prefix">' . $prefix . '</li>'; 1210 } 1211 1212 $last = count($crumbs); 1213 $i = 0; 1214 foreach ($crumbs as $id => $name) { 1215 $i++; 1216 if ($i !== 1) { 1217 $html .= '<li class="sep">' . $sep . '</li>'; 1218 } 1219 $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>'; 1220 $html .= tpl_pagelink($id, null, true); 1221 $html .= '</li>'; 1222 } 1223 1224 $html .= '</ul>'; 1225 }//end if 1226 }//end if 1227 }//end if 1228 1229 $html .= '</div>'; 1230 $html .= '</div>'; 1231 1232 if ($parse === true) { 1233 $html = $this->includeIcons($html); 1234 } 1235 if ($print === true) { 1236 echo $html; 1237 } 1238 return $html; 1239 } 1240 1241 /** 1242 * Print or return you are here trail 1243 * 1244 * @param boolean $print Print out trail. 1245 * @param boolean $parse Parse trail before printing. 1246 * @return string HTML string containing breadcrumbs 1247 */ 1248 public function includeYouAreHere(bool $print = true, bool $parse = true) 1249 { 1250 global $conf, $ID, $lang, $ACT; 1251 1252 if ( 1253 $this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 && 1254 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0 1255 ) { 1256 return ''; 1257 } 1258 1259 $html = '<div class="mikio-youarehere">'; 1260 $html .= '<div class="mikio-container">'; 1261 if (strcasecmp($ACT, 'show') === 0) { 1262 if ($conf['youarehere'] !== 0) { 1263 if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) { 1264 $html .= '<div class="mikio-bcdw">'; 1265 ob_start(); 1266 tpl_youarehere(); 1267 $html .= ob_get_contents(); 1268 ob_end_clean(); 1269 $html .= '</div>'; 1270 } else { 1271 $sep = ' » '; 1272 $prefix = $lang['youarehere']; 1273 1274 if ($this->getConf('youarehereSep') === true) { 1275 $sep = $this->getConf('youarehereSepText'); 1276 $img = $this->getMediaFile('youarehere-sep', false); 1277 1278 if ($img !== false) { 1279 $sep = '<img src="' . $img . '">'; 1280 } 1281 } 1282 1283 if ($this->getConf('youareherePrefix') === true) { 1284 $prefix = $this->getConf('youareherePrefixText'); 1285 $img = $this->getMediaFile('youarehere-prefix', false); 1286 1287 if ($img !== false) { 1288 $prefix = '<img src="' . $img . '">'; 1289 } 1290 } 1291 1292 $html .= '<ul>'; 1293 if (empty($prefix) === false) { 1294 $html .= '<li class="prefix">' . $prefix . '</li>'; 1295 } 1296 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>'; 1297 1298 $parts = explode(':', $ID); 1299 $count = count($parts); 1300 1301 $part = ''; 1302 for ($i = 0; $i < ($count - 1); $i++) { 1303 $part .= $parts[$i] . ':'; 1304 $page = $part; 1305 if ($page === $conf['start']) { 1306 continue; 1307 } 1308 1309 $html .= '<li class="sep">' . $sep . '</li>'; 1310 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1311 } 1312 1313 resolve_pageid('', $page, $exists); 1314 if ((isset($page) === true && $page === $part . $parts[$i]) === false) { 1315 $page = $part . $parts[$i]; 1316 if ($page !== $conf['start']) { 1317 $html .= '<li class="sep">' . $sep . '</li>'; 1318 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1319 } 1320 } 1321 1322 $html .= '</ul>'; 1323 }//end if 1324 }//end if 1325 1326 $showLast = $this->getConf('youarehereShowLast'); 1327 if ($showLast !== 0) { 1328 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1329 if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) { 1330 $count = count($matches[0]); 1331 $list = ''; 1332 1333 // Show Home 1334 $list .= $matches[0][0] . $matches[0][1]; 1335 1336 $list .= '<li>...</li>'; 1337 for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) { 1338 $list .= $matches[0][$i]; 1339 } 1340 1341 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1342 } 1343 } 1344 1345 switch ($this->getConf('youarehereHome')) { 1346 case 'none': 1347 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1348 break; 1349 case 'home': 1350 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1351 break; 1352 case 'icon': 1353 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . 1354 $this->mikioInlineIcon('home') . '$3', $html, 1); 1355 break; 1356 } 1357 } else { 1358 $html .= '≪ '; 1359 if (isset($_GET['page']) === true) { 1360 $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">Back</a> / '; 1361 } 1362 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1363 }//end if 1364 1365 $html .= '</div>'; 1366 $html .= '</div>'; 1367 1368 if ($parse === true) { 1369 $html = $this->includeIcons($html); 1370 } 1371 if ($print === true) { 1372 echo $html; 1373 } 1374 return $html; 1375 } 1376 1377 /** 1378 * Get Page Title 1379 * 1380 * @return string page title 1381 */ 1382 public function parsePageTitle() 1383 { 1384 global $ID; 1385 1386 $title = p_get_first_heading($ID); 1387 if (strlen($title) <= 0) { 1388 $title = tpl_pagetitle(null, true); 1389 } 1390 $title = $this->includeIcons($title); 1391 1392 return $title; 1393 } 1394 1395 1396 /** 1397 * Print or return hero block 1398 * 1399 * @param boolean $print Print content. 1400 * @return string contents of hero 1401 */ 1402 public function includeHero(bool $print = true) 1403 { 1404 $html = ''; 1405 1406 if ($this->getConf('heroTitle') === true) { 1407 $html .= '<div class="mikio-hero">'; 1408 $html .= '<div class="mikio-container">'; 1409 $html .= '<div class="mikio-hero-text">'; 1410 if (strcasecmp($this->getConf('youareherePosition'), 'hero') === 0) { 1411 $html .= $this->includeYouAreHere(false); 1412 } 1413 if (strcasecmp($this->getConf('breadcrumbPosition'), 'hero') === 0) { 1414 $html .= $this->includeBreadcrumbs(false); 1415 } 1416 1417 $html .= '<h1 class="mikio-hero-title">'; 1418 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1419 $html .= '</h1>'; 1420 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1421 $html .= '</div>'; 1422 1423 $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true)); 1424 $hero_image_resize_class = ''; 1425 if (empty($hero_image) === false) { 1426 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1427 $hero_image_resize_class = ' mikio-hero-image-resize'; 1428 } 1429 1430 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . 1431 '><div class="mikio-tags"></div></div>'; 1432 1433 $html .= '</div>'; 1434 $html .= '</div>'; 1435 }//end if 1436 1437 if ($print === true) { 1438 echo $html; 1439 } 1440 1441 return $html; 1442 } 1443 1444 1445 /** 1446 * Print or return out TOC 1447 * 1448 * @param boolean $print Print TOC. 1449 * @param boolean $parse Parse icons. 1450 * @return string contents of TOC 1451 */ 1452 public function includeTOC(bool $print = true, bool $parse = true) 1453 { 1454 $html = ''; 1455 1456 $tocHtml = tpl_toc(true); 1457 1458 if (empty($tocHtml) === false) { 1459 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1460 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1461 1462 $html .= '<div class="mikio-toc">'; 1463 $html .= $tocHtml; 1464 $html .= '</div>'; 1465 } 1466 1467 if ($parse === true) { 1468 $html = $this->includeIcons($html); 1469 } 1470 1471 if ($print === true) { 1472 echo $html; 1473 } 1474 1475 return $html; 1476 } 1477 1478 1479 /** 1480 * Parse the string and replace icon elements with included icon libraries 1481 * 1482 * @param string $str Content to parse. 1483 * @return string parsed string 1484 */ 1485 public function includeIcons(string $str) 1486 { 1487 global $ACT, $MIKIO_ICONS; 1488 1489 $iconTag = $this->getConf('iconTag', 'icon'); 1490 if (empty($iconTag) === true) { 1491 return $str; 1492 } 1493 1494 if ( 1495 in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true || 1496 strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0 1497 ) { 1498 $content = $str; 1499 $preview = null; 1500 1501 if (strcasecmp($ACT, 'preview') === 0) { 1502 $html = new \simple_html_dom(); 1503 $html->stripRNAttrValues = false; 1504 $html->load($str, true, false); 1505 1506 $preview = $html->find('div.preview'); 1507 if (is_array($preview) === true && count($preview) > 0) { 1508 $content = $preview[0]->innertext; 1509 } 1510 } 1511 1512 $page_regex = '/(.*)/'; 1513 if (stripos($str, '<pre') !== false) { 1514 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1515 } 1516 1517 $content = preg_replace_callback($page_regex, function ($icons) { 1518 $iconTag = $this->getConf('iconTag', 'icon'); 1519 1520 return preg_replace_callback( 1521 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1522 function ($matches) { 1523 global $MIKIO_ICONS; 1524 1525 $s = $matches[0]; 1526 1527 if (count($MIKIO_ICONS) > 0) { 1528 $icon = $MIKIO_ICONS[0]; 1529 1530 if (count($matches) > 1) { 1531 $e = explode(' ', $matches[1]); 1532 1533 if (count($e) > 1) { 1534 foreach ($MIKIO_ICONS as $iconItem) { 1535 if (strcasecmp($iconItem['name'], $e[0]) === 0) { 1536 $icon = $iconItem; 1537 1538 $s = $icon['insert']; 1539 for ($i = 1; $i < 9; $i++) { 1540 if (count($e) < $i || empty($e[$i]) === true) { 1541 if (isset($icon['$' . $i]) === true) { 1542 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1543 } 1544 } else { 1545 $s = str_replace('$' . $i, $e[$i], $s); 1546 } 1547 } 1548 1549 $dir = ''; 1550 if (isset($icon['dir']) === true) { 1551 $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1552 } 1553 1554 $s = str_replace('$0', $dir, $s); 1555 1556 break; 1557 }//end if 1558 }//end foreach 1559 } else { 1560 $s = str_replace('$1', $matches[1], $icon['insert']); 1561 }//end if 1562 }//end if 1563 }//end if 1564 1565 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1566 if ($count === 0) { 1567 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1568 } 1569 1570 return $s; 1571 }, 1572 $icons[0] 1573 ); 1574 }, $content); 1575 1576 if (strcasecmp($ACT, 'preview') === 0) { 1577 if (is_array($preview) === true && count($preview) > 0) { 1578 $preview[0]->innertext = $content; 1579 } 1580 1581 $str = $html->save(); 1582 $html->clear(); 1583 unset($html); 1584 } else { 1585 $str = $content; 1586 } 1587 }//end if 1588 1589 return $str; 1590 } 1591 1592 /** 1593 * Parse HTML for theme 1594 * 1595 * @param string $content HTML content to parse. 1596 * @return string Parsed content 1597 */ 1598 public function parseContent(string $content) 1599 { 1600 global $INPUT, $ACT; 1601 1602 // Add Mikio Section titles 1603 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1604 $admin_sections = [ 1605 // Section Insert Before Icon 1606 'navbar' => ['navbarUseTitleIcon', ''], 1607 'search' => ['searchButton', ''], 1608 'hero' => ['heroTitle', ''], 1609 'tags' => ['tagsConsolidate', ''], 1610 'breadcrumb' => ['breadcrumbHideHome', ''], 1611 'youarehere' => ['youarehereHideHome', ''], 1612 'sidebar' => ['sidebarShowLeft', ''], 1613 'toc' => ['tocFull', ''], 1614 'pagetools' => ['pageToolsFloating', ''], 1615 'footer' => ['footerCustomMenuText', ''], 1616 'license' => ['licenseType', ''], 1617 'acl' => ['includePageUseACL', ''], 1618 'sticky' => ['stickyTopHeader', ''], 1619 ]; 1620 1621 foreach ($admin_sections as $section => $items) { 1622 $search = $items[0]; 1623 $icon = $items[1]; 1624 1625 $content = preg_replace( 1626 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1627 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . 1628 tpl_getLang('config_' . $section) . 1629 '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . 1630 $search . '</span>', 1631 $content 1632 ); 1633 } 1634 } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) { 1635 $style_headers = [ 1636 ['title' => 'Base', 'starts_with' => '__text'], 1637 ['title' => 'Code', 'starts_with' => '__code'], 1638 ['title' => 'Controls', 'starts_with' => '__control'], 1639 ['title' => 'Header', 'starts_with' => '__topheader'], 1640 ['title' => 'Navbar', 'starts_with' => '__navbar'], 1641 ['title' => 'Sub Navbar', 'starts_with' => '__subnavbar'], 1642 ['title' => 'Tags', 'starts_with' => '__tag_background_color'], 1643 ['title' => 'Breadcrumbs', 'starts_with' => '__breadcrumb'], 1644 ['title' => 'Hero', 'starts_with' => '__hero'], 1645 ['title' => 'Sidebar', 'starts_with' => '__sidebar'], 1646 ['title' => 'Content', 'starts_with' => '__content'], 1647 ['title' => 'TOC', 'starts_with' => '__toc'], 1648 ['title' => 'Page Tools', 'starts_with' => '__pagetools'], 1649 ['title' => 'Footer', 'starts_with' => '__footer'], 1650 ['title' => 'Table', 'starts_with' => '__table'], 1651 ['title' => 'Dropdown', 'starts_with' => '__dropdown'], 1652 ['title' => 'Section Edit', 'starts_with' => '__section_edit'], 1653 ['title' => 'Dark Mode', 'starts_with' => '__darkmode_', 'heading' => 'h2'], 1654 ['title' => 'Base', 'starts_with' => '__darkmode_text'], 1655 ['title' => 'Code', 'starts_with' => '__darkmode_code'], 1656 ['title' => 'Controls', 'starts_with' => '__darkmode_control'], 1657 ['title' => 'Header', 'starts_with' => '__darkmode_topheader'], 1658 ['title' => 'Navbar', 'starts_with' => '__darkmode_navbar'], 1659 ['title' => 'Sub Navbar', 'starts_with' => '__darkmode_subnavbar'], 1660 ['title' => 'Tags', 'starts_with' => '__darkmode_tag_background_color'], 1661 ['title' => 'Breadcrumbs', 'starts_with' => '__darkmode_breadcrumb'], 1662 ['title' => 'Hero', 'starts_with' => '__darkmode_hero'], 1663 ['title' => 'Sidebar', 'starts_with' => '__darkmode_sidebar'], 1664 ['title' => 'Content', 'starts_with' => '__darkmode_content'], 1665 ['title' => 'TOC', 'starts_with' => '__darkmode_toc'], 1666 ['title' => 'Page Tools', 'starts_with' => '__darkmode_pagetools'], 1667 ['title' => 'Footer', 'starts_with' => '__darkmode_footer'], 1668 ['title' => 'Table', 'starts_with' => '__darkmode_table'], 1669 ['title' => 'Dropdown', 'starts_with' => '__darkmode_dropdown'], 1670 ['title' => 'Section Edit', 'starts_with' => '__darkmode_section_edit'], 1671 ]; 1672 1673 foreach($style_headers as $header) { 1674 if(array_key_exists('heading', $header) === false) { 1675 $header['heading'] = 'h3'; 1676 } 1677 1678 $content = preg_replace( 1679 '/(<tr>\s*<td>\s*<label for="tpl__'.$header['starts_with'].'.*?<\/tr>)/', 1680 '</tbody></table><'.$header['heading'].'>'.$header['title'].'</'.$header['heading'].'><table><tbody>$1', 1681 $content, 1682 1 1683 ); 1684 } 1685 }//end if 1686 1687 if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) { 1688 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1689 } 1690 1691 // Page Revisions - Table Fix 1692 if (strpos($content, 'id="page__revisions"') !== false) { 1693 $content = preg_replace( 1694 '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', 1695 '<span>$1</span>', 1696 $content 1697 ); 1698 } 1699 1700 $html = new \simple_html_dom(); 1701 $html->stripRNAttrValues = false; 1702 $html->load($content, true, false); 1703 1704 if ($html === false) { 1705 return $content; 1706 } 1707 1708 /* Buttons */ 1709 foreach ($html->find('#config__manager button') as $node) { 1710 $c = explode(' ', $node->class); 1711 if (in_array('mikio-button', $c) === false) { 1712 $c[] = 'mikio-button'; 1713 } 1714 $node->class = implode(' ', $c); 1715 } 1716 1717 1718 /* Buttons - Primary */ 1719 foreach ($html->find('#config__manager [type=submit]') as $node) { 1720 $c = explode(' ', $node->class); 1721 if (in_array('mikio-primary', $c) === false) { 1722 $c[] = 'mikio-primary'; 1723 } 1724 $node->class = implode(' ', $c); 1725 } 1726 1727 /* Hide page title if hero is enabled */ 1728 if ($this->getConf('heroTitle') === true && $ACT !== 'preview') { 1729 $pageTitle = $this->parsePageTitle(); 1730 1731 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1732 if ($elm->innertext === $pageTitle) { 1733 // $elm->innertext = ''; 1734 $elm->setAttribute('style', 'display:none'); 1735 1736 break; 1737 } 1738 } 1739 } 1740 1741 /* Hero subtitle */ 1742 foreach ($html->find('p') as $elm) { 1743 $i = stripos($elm->innertext, '~~hero-subtitle'); 1744 if ($i !== false) { 1745 $j = strpos($elm->innertext, '~~', ($i + 2)); 1746 if ($j !== false) { 1747 if ($j > ($i + 16)) { 1748 $subtitle = substr($elm->innertext, ($i + 16), ($j - $i - 16)); 1749 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1750 1751 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1752 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1753 } 1754 1755 break; 1756 } 1757 } 1758 } 1759 1760 /* Hero image */ 1761 foreach ($html->find('p') as $elm) { 1762 $image = ''; 1763 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1764 if (count($matches) > 0) { 1765 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1766 if (count($imageTagMatches) > 0) { 1767 $image = $imageTagMatches[1]; 1768 } else { 1769 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1770 if (count($imageTagMatches) > 0) { 1771 $image = $imageTagMatches[1]; 1772 } else { 1773 $image = strip_tags($matches[1]); 1774 if (stripos($image, ':') === false) { 1775 $image = str_replace(['{', '}'], '', $image); 1776 $i = stripos($image, '?'); 1777 if ($i !== false) { 1778 $image = substr($image, 0, $i); 1779 } 1780 1781 $image = ml($image, '', true, '', false); 1782 } 1783 } 1784 } 1785 1786 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 1787 1788 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1789 }//end if 1790 }//end foreach 1791 1792 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] 1793 [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1794 foreach ($html->find('p') as $elm) { 1795 $i = stripos($elm->innertext, '~~hero-colors'); 1796 if ($i !== false) { 1797 $j = strpos($elm->innertext, '~~', ($i + 2)); 1798 if ($j !== false) { 1799 if ($j > ($i + 14)) { 1800 $color = substr($elm->innertext, ($i + 14), ($j - $i - 14)); 1801 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')'; 1802 1803 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1804 } 1805 1806 break; 1807 } 1808 } 1809 } 1810 1811 /* Hide parts - ~~hide-parts [parts]~~ */ 1812 foreach ($html->find('p') as $elm) { 1813 $i = stripos($elm->innertext, '~~hide-parts'); 1814 if ($i !== false) { 1815 $j = strpos($elm->innertext, '~~', ($i + 2)); 1816 if ($j !== false) { 1817 if ($j > ($i + 13)) { 1818 $parts = explode(' ', substr($elm->innertext, ($i + 13), ($j - $i - 13))); 1819 $script = ''; 1820 1821 foreach ($parts as $part) { 1822 // $part = trim($part); 1823 if (strlen($part) > 0) { 1824 $script .= 'mikio.hidePart(\'' . $part . '\');'; 1825 } 1826 } 1827 1828 if (strlen($script) > 0) { 1829 $this->footerScript['hide-parts'] = $script; 1830 } 1831 1832 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1833 } 1834 1835 break; 1836 }//end if 1837 }//end if 1838 }//end foreach 1839 1840 1841 /* Page Tags (tag plugin) */ 1842 if ($this->getConf('tagsConsolidate') === true) { 1843 $tags = ''; 1844 foreach ($html->find('div.tags a') as $elm) { 1845 $tags .= $elm->outertext; 1846 } 1847 1848 foreach ($html->find('div.tags') as $elm) { 1849 $elm->innertext = ''; 1850 $elm->setAttribute('style', 'display:none'); 1851 } 1852 1853 if (empty($tags) === false) { 1854 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1855 } 1856 } 1857 1858 // Configuration Manager 1859 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1860 // Additional save buttons 1861 foreach ($html->find('#config__manager') as $cm) { 1862 $saveButtons = ''; 1863 1864 foreach ($cm->find('p') as $elm) { 1865 $saveButtons = $elm->outertext; 1866 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1867 $elm->outertext = ''; 1868 } 1869 1870 foreach ($cm->find('fieldset') as $elm) { 1871 $elm->innertext .= $saveButtons; 1872 } 1873 } 1874 } 1875 1876 $content = $html->save(); 1877 $html->clear(); 1878 unset($html); 1879 1880 return $content; 1881 } 1882 1883 1884 /** 1885 * Get DokuWiki namespace/page/URI as link 1886 * 1887 * @param string $str String to parse. 1888 * @return string parsed URI 1889 */ 1890 public function getLink(string $str) 1891 { 1892 $i = strpos($str, '://'); 1893 if ($i !== false) { 1894 return $str; 1895 } 1896 1897 return wl($str); 1898 } 1899 1900 1901 /** 1902 * Check if the user can edit current namespace/page 1903 * 1904 * @return boolean user can edit 1905 */ 1906 public function userCanEdit() 1907 { 1908 global $INFO; 1909 global $ID; 1910 1911 $wiki_file = wikiFN($ID); 1912 if (@file_exists($wiki_file) === false) { 1913 return true; 1914 } 1915 if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) { 1916 return true; 1917 } 1918 // $meta_file = metaFN($ID, '.meta'); 1919 if ($INFO['meta']['user'] === false) { 1920 return true; 1921 } 1922 if ($INFO['client'] === $INFO['meta']['user']) { 1923 return true; 1924 } 1925 1926 return false; 1927 } 1928 1929 1930 /** 1931 * Search for and return the uri of a media file 1932 * 1933 * @param string $image Image name to search for (without extension). 1934 * @param boolean $searchCurrentNS Search the current namespace. 1935 * @param boolean $propagate Propagate search through the namespace. 1936 * @return string URI of the found media file 1937 */ 1938 public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true) 1939 { 1940 global $INFO; 1941 1942 $ext = ['png', 'jpg', 'gif', 'svg']; 1943 1944 if ($searchCurrentNS === true) { 1945 $prefix[] = ':' . $INFO['namespace'] . ':'; 1946 } 1947 if ($propagate === true) { 1948 $prefix[] = ':'; 1949 $prefix[] = ':wiki:'; 1950 } 1951 $theme = $this->getConf('customTheme'); 1952 if (empty($theme) === false) { 1953 $prefix[] = 'themes/' . $theme . '/images/'; 1954 } 1955 $prefix[] = 'images/'; 1956 1957 $search = []; 1958 foreach ($prefix as $pitem) { 1959 foreach ($ext as $eitem) { 1960 $search[] = $pitem . $image . '.' . $eitem; 1961 } 1962 } 1963 1964 $img = ''; 1965 $file = ''; 1966 $url = ''; 1967 $ismedia = false; 1968 $found = false; 1969 1970 foreach ($search as $img) { 1971 if (strcasecmp(substr($img, 0, 1), ':') === 0) { 1972 $file = mediaFN($img); 1973 $ismedia = true; 1974 } else { 1975 $file = tpl_incdir() . $img; 1976 $ismedia = false; 1977 } 1978 1979 if (file_exists($file) === true) { 1980 $found = true; 1981 break; 1982 } 1983 } 1984 1985 if ($found === false) { 1986 return false; 1987 } 1988 1989 if ($ismedia === true) { 1990 $url = ml($img, '', true, '', false); 1991 } else { 1992 $url = tpl_basedir() . $img; 1993 } 1994 1995 return $url; 1996 } 1997 1998 1999 /** 2000 * Print or return the page title 2001 * 2002 * @param string $page Page id or empty string for current page. 2003 * @return string generated content 2004 */ 2005 public function getPageTitle(string $page = '') 2006 { 2007 global $ID, $conf; 2008 2009 $html = ''; 2010 2011 if (empty($page) === true) { 2012 $page = $ID; 2013 } 2014 2015 $html = p_get_first_heading($page); 2016 $html = strip_tags($html); 2017 $html = preg_replace('/\s+/', ' ', $html); 2018 $html .= ' [' . strip_tags($conf['title']) . ']'; 2019 $html = trim($html); 2020 2021 return $html; 2022 } 2023 2024 2025 /** 2026 * Return inline theme icon 2027 * 2028 * @param string $type Icon to retreive. 2029 * @param string $class Classname to insert. 2030 * @return string HTML icon content 2031 */ 2032 public function mikioInlineIcon(string $type, string $class="") 2033 { 2034 if(is_array($class) === true) { 2035 $class = explode(' ', $class); 2036 } 2037 2038 if(strlen($class) > 0) { 2039 $class = ' ' . $class; 2040 } 2041 2042 switch ($type) { 2043 case 'wrench': 2044 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 2045style="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 2046-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 2047-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 20480,-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, 2049131.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, 20503 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>'; 2051 case 'file': 2052 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 2053style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"><path d="M 128,0 H 1152 V 768 2054H 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, 2055-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 2056l 408,-408 q 28,-28 48,-76 20,-48 20,-88 z" id="path2993" inkscape:connector-curvature="0" 2057xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2058 case 'gear': 2059 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 2060style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"><path d="m 1024,640 q 0,106 2061-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 2062512,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, 2063-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 2064-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 20650,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, 206613 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 2067138,-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 2068142,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 206941,-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>'; 2070 case 'user': 2071 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 2072style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 1408,131 Q 1408,11 1335,-58.5 20731262,-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 207427,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 207567,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 207627,-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 2077704,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 20781088,1024 z"/></g></svg>'; 2079 case 'search': 2080 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2081aria-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 208218.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 208324.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 20846.195 0 0 1-6.188 6.188z"/></svg>'; 2085 case 'home': 2086 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 2087aria-hidden="true" style="fill:currentColor"><g transform="matrix(1,0,0,-1,68.338983,1285.4237)" id="g3015"> 2088<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, 208945 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, 20900 -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, 2091599 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, 2092-182 q 10,-8 11,-21.5 1,-13.5 -7,-23.5 z" id="path3017" inkscape:connector-curvature="0" 2093xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2094 case 'sun': 2095 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" style="fill:currentColor" viewBox="0 0 16 16"><path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8zm.5-9.5a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zm0 11a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0zm5-5a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1zm-11 0a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1zm9.743-4.036a.5.5 0 1 1-.707-.707.5.5 0 0 1 .707.707zm-7.779 7.779a.5.5 0 1 1-.707-.707.5.5 0 0 1 .707.707zm7.072 0a.5.5 0 1 1 .707-.707.5.5 0 0 1-.707.707zM3.757 4.464a.5.5 0 1 1 .707-.707.5.5 0 0 1-.707.707z" /></svg>'; 2096 case 'moon': 2097 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" style="fill:currentColor" viewBox="0 0 16 16"><path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278zM4.858 1.311A7.269 7.269 0 0 0 1.025 7.71c0 4.02 3.279 7.276 7.319 7.276a7.316 7.316 0 0 0 5.205-2.162c-.337.042-.68.063-1.029.063-4.61 0-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>'; 2098 }//end switch 2099 2100 return ''; 2101 } 2102 2103 /** 2104 * Finalize theme 2105 * 2106 * @return void 2107 */ 2108 public function finalize() 2109 { 2110 } 2111 2112 /** 2113 * Show Messages 2114 * 2115 * @return void 2116 */ 2117 public function showMessages() 2118 { 2119 global $ACT; 2120 2121 if ($this->lessIgnored === true) { 2122 msg( 2123 'useLESS is enabled on the Mikio template, however is not supported on this server', 2124 2, 2125 '', 2126 '', 2127 MSG_ADMINS_ONLY 2128 ); 2129 } 2130 2131 $show = $this->getConf('showNotifications'); 2132 if ( 2133 strcasecmp($show, 'always') === 0 || 2134 (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0) 2135 ) { 2136 global $MSG, $MSG_shown; 2137 2138 if (isset($MSG) === false) { 2139 return; 2140 } 2141 2142 if (isset($MSG_shown) === false) { 2143 $MSG_shown = []; 2144 } 2145 2146 foreach ($MSG as $msg) { 2147 $hash = md5($msg['msg']); 2148 if (isset($MSG_shown[$hash]) === true) { 2149 continue; 2150 } 2151 // skip double messages 2152 2153 if (info_msg_allowed($msg) === true) { 2154 echo '<div class="' . $msg['lvl'] . '">'; 2155 echo $msg['msg']; 2156 echo '</div>'; 2157 } 2158 2159 $MSG_shown[$hash] = true; 2160 } 2161 2162 unset($GLOBALS['MSG']); 2163 }//end if 2164 } 2165 2166 /** 2167 * Dokuwiki version 2168 * 2169 * @return string the dw version name 2170 */ 2171 public function dwVersion() 2172 { 2173 if (function_exists('getVersionData') === true) { 2174 $version_data = getVersionData(); 2175 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2176 $version_items = explode(' ', $version_data['date']); 2177 if (count($version_items) >= 2) { 2178 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 2179 } 2180 } 2181 } 2182 2183 return 'unknown'; 2184 } 2185 2186 /** 2187 * Dokuwiki version number 2188 * 2189 * @return string the dw version date converted to integer 2190 */ 2191 public function dwVersionNumber() 2192 { 2193 if (function_exists('getVersionData') === true) { 2194 $version_data = getVersionData(); 2195 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2196 $version_items = explode(' ', $version_data['date']); 2197 if (count($version_items) >= 1) { 2198 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 2199 } 2200 } 2201 } 2202 2203 return 0; 2204 } 2205} 2206 2207global $TEMPLATE; 2208$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 2209