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( 1460 '/(<h3.+?toggle.+?>)(.+?)<\/h3>/', 1461 '$1' . 1462 $this->mikioInlineIcon('hamburger', 'hamburger') . '$2' . 1463 $this->mikioInlineIcon('down-arrow', 'down-arrow') . '</h3>', 1464 $tocHtml 1465 ); 1466 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1467 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1468 1469 $html .= '<div class="mikio-toc">'; 1470 $html .= $tocHtml; 1471 $html .= '</div>'; 1472 } 1473 1474 if ($parse === true) { 1475 $html = $this->includeIcons($html); 1476 } 1477 1478 if ($print === true) { 1479 echo $html; 1480 } 1481 1482 return $html; 1483 } 1484 1485 1486 /** 1487 * Parse the string and replace icon elements with included icon libraries 1488 * 1489 * @param string $str Content to parse. 1490 * @return string parsed string 1491 */ 1492 public function includeIcons(string $str) 1493 { 1494 global $ACT, $MIKIO_ICONS; 1495 1496 $iconTag = $this->getConf('iconTag', 'icon'); 1497 if (empty($iconTag) === true) { 1498 return $str; 1499 } 1500 1501 if ( 1502 in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true || 1503 strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0 1504 ) { 1505 $content = $str; 1506 $preview = null; 1507 1508 if (strcasecmp($ACT, 'preview') === 0) { 1509 $html = new \simple_html_dom(); 1510 $html->stripRNAttrValues = false; 1511 $html->load($str, true, false); 1512 1513 $preview = $html->find('div.preview'); 1514 if (is_array($preview) === true && count($preview) > 0) { 1515 $content = $preview[0]->innertext; 1516 } 1517 } 1518 1519 $page_regex = '/(.*)/'; 1520 if (stripos($str, '<pre') !== false) { 1521 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1522 } 1523 1524 $content = preg_replace_callback($page_regex, function ($icons) { 1525 $iconTag = $this->getConf('iconTag', 'icon'); 1526 1527 return preg_replace_callback( 1528 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1529 function ($matches) { 1530 global $MIKIO_ICONS; 1531 1532 $s = $matches[0]; 1533 1534 if (count($MIKIO_ICONS) > 0) { 1535 $icon = $MIKIO_ICONS[0]; 1536 1537 if (count($matches) > 1) { 1538 $e = explode(' ', $matches[1]); 1539 1540 if (count($e) > 1) { 1541 foreach ($MIKIO_ICONS as $iconItem) { 1542 if (strcasecmp($iconItem['name'], $e[0]) === 0) { 1543 $icon = $iconItem; 1544 1545 $s = $icon['insert']; 1546 for ($i = 1; $i < 9; $i++) { 1547 if (count($e) < $i || empty($e[$i]) === true) { 1548 if (isset($icon['$' . $i]) === true) { 1549 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1550 } 1551 } else { 1552 $s = str_replace('$' . $i, $e[$i], $s); 1553 } 1554 } 1555 1556 $dir = ''; 1557 if (isset($icon['dir']) === true) { 1558 $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1559 } 1560 1561 $s = str_replace('$0', $dir, $s); 1562 1563 break; 1564 }//end if 1565 }//end foreach 1566 } else { 1567 $s = str_replace('$1', $matches[1], $icon['insert']); 1568 }//end if 1569 }//end if 1570 }//end if 1571 1572 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1573 if ($count === 0) { 1574 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1575 } 1576 1577 return $s; 1578 }, 1579 $icons[0] 1580 ); 1581 }, $content); 1582 1583 if (strcasecmp($ACT, 'preview') === 0) { 1584 if (is_array($preview) === true && count($preview) > 0) { 1585 $preview[0]->innertext = $content; 1586 } 1587 1588 $str = $html->save(); 1589 $html->clear(); 1590 unset($html); 1591 } else { 1592 $str = $content; 1593 } 1594 }//end if 1595 1596 return $str; 1597 } 1598 1599 /** 1600 * Parse HTML for theme 1601 * 1602 * @param string $content HTML content to parse. 1603 * @return string Parsed content 1604 */ 1605 public function parseContent(string $content) 1606 { 1607 global $INPUT, $ACT; 1608 1609 // Add Mikio Section titles 1610 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1611 $admin_sections = [ 1612 // Section Insert Before Icon 1613 'navbar' => ['navbarUseTitleIcon', ''], 1614 'search' => ['searchButton', ''], 1615 'hero' => ['heroTitle', ''], 1616 'tags' => ['tagsConsolidate', ''], 1617 'breadcrumb' => ['breadcrumbHideHome', ''], 1618 'youarehere' => ['youarehereHideHome', ''], 1619 'sidebar' => ['sidebarShowLeft', ''], 1620 'toc' => ['tocFull', ''], 1621 'pagetools' => ['pageToolsFloating', ''], 1622 'footer' => ['footerCustomMenuText', ''], 1623 'license' => ['licenseType', ''], 1624 'acl' => ['includePageUseACL', ''], 1625 'sticky' => ['stickyTopHeader', ''], 1626 ]; 1627 1628 foreach ($admin_sections as $section => $items) { 1629 $search = $items[0]; 1630 $icon = $items[1]; 1631 1632 $content = preg_replace( 1633 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1634 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . 1635 tpl_getLang('config_' . $section) . 1636 '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . 1637 $search . '</span>', 1638 $content 1639 ); 1640 } 1641 } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) { 1642 $style_headers = [ 1643 ['title' => 'Base', 'starts_with' => '__text_'], 1644 ['title' => 'Code', 'starts_with' => '__code_'], 1645 ['title' => 'Controls', 'starts_with' => '__control_'], 1646 ['title' => 'Header', 'starts_with' => '__topheader_'], 1647 ['title' => 'Navbar', 'starts_with' => '__navbar_'], 1648 ['title' => 'Sub Navbar', 'starts_with' => '__subnavbar_'], 1649 ['title' => 'Tags', 'starts_with' => '__tag_background_color_'], 1650 ['title' => 'Breadcrumbs', 'starts_with' => '__breadcrumb_'], 1651 ['title' => 'Hero', 'starts_with' => '__hero_'], 1652 ['title' => 'Sidebar', 'starts_with' => '__sidebar_'], 1653 ['title' => 'Content', 'starts_with' => '__content_'], 1654 ['title' => 'TOC', 'starts_with' => '__toc_'], 1655 ['title' => 'Page Tools', 'starts_with' => '__pagetools_'], 1656 ['title' => 'Footer', 'starts_with' => '__footer_'], 1657 ['title' => 'Table', 'starts_with' => '__table_'], 1658 ['title' => 'Dropdown', 'starts_with' => '__dropdown_'], 1659 ['title' => 'Section Edit', 'starts_with' => '__section_edit_'], 1660 ['title' => 'Tree', 'starts_with' => '__tree_'], 1661 ['title' => 'Tabs', 'starts_with' => '__tab_'], 1662 ['title' => 'Dark Mode', 'starts_with' => '__darkmode_', 'heading' => 'h2'], 1663 ['title' => 'Base', 'starts_with' => '__darkmode_text_'], 1664 ['title' => 'Code', 'starts_with' => '__darkmode_code_'], 1665 ['title' => 'Controls', 'starts_with' => '__darkmode_control_'], 1666 ['title' => 'Header', 'starts_with' => '__darkmode_topheader_'], 1667 ['title' => 'Navbar', 'starts_with' => '__darkmode_navbar_'], 1668 ['title' => 'Sub Navbar', 'starts_with' => '__darkmode_subnavbar_'], 1669 ['title' => 'Tags', 'starts_with' => '__darkmode_tag_background_color_'], 1670 ['title' => 'Breadcrumbs', 'starts_with' => '__darkmode_breadcrumb_'], 1671 ['title' => 'Hero', 'starts_with' => '__darkmode_hero_'], 1672 ['title' => 'Sidebar', 'starts_with' => '__darkmode_sidebar_'], 1673 ['title' => 'Content', 'starts_with' => '__darkmode_content_'], 1674 ['title' => 'TOC', 'starts_with' => '__darkmode_toc_'], 1675 ['title' => 'Page Tools', 'starts_with' => '__darkmode_pagetools_'], 1676 ['title' => 'Footer', 'starts_with' => '__darkmode_footer_'], 1677 ['title' => 'Table', 'starts_with' => '__darkmode_table_'], 1678 ['title' => 'Dropdown', 'starts_with' => '__darkmode_dropdown_'], 1679 ['title' => 'Section Edit', 'starts_with' => '__darkmode_section_edit_'], 1680 ['title' => 'Tree', 'starts_with' => '__darkmode_tree_'], 1681 ['title' => 'Tabs', 'starts_with' => '__darkmode_tab_'], 1682 ]; 1683 1684 foreach ($style_headers as $header) { 1685 if (array_key_exists('heading', $header) === false) { 1686 $header['heading'] = 'h3'; 1687 } 1688 1689 $content = preg_replace( 1690 '/(<tr>\s*<td>\s*<label for="tpl__' . $header['starts_with'] . '.+?<\/tr>)/s', 1691 '</tbody></table><' . $header['heading'] . '>' . $header['title'] . '</' . $header['heading'] . '> 1692 <table><tbody>$1', 1693 $content, 1694 1 1695 ); 1696 } 1697 1698 $content = preg_replace('/type="color"/', 'type="text"', $content); 1699 }//end if 1700 1701 if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) { 1702 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1703 } 1704 1705 // Page Revisions - Table Fix 1706 if (strpos($content, 'id="page__revisions"') !== false) { 1707 $content = preg_replace( 1708 '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', 1709 '<span>$1</span>', 1710 $content 1711 ); 1712 } 1713 1714 $html = new \simple_html_dom(); 1715 $html->stripRNAttrValues = false; 1716 $html->load($content, true, false); 1717 1718 if ($html === false) { 1719 return $content; 1720 } 1721 1722 /* Buttons */ 1723 foreach ($html->find('#config__manager button') as $node) { 1724 $c = explode(' ', $node->class); 1725 if (in_array('mikio-button', $c) === false) { 1726 $c[] = 'mikio-button'; 1727 } 1728 $node->class = implode(' ', $c); 1729 } 1730 1731 1732 /* Buttons - Primary */ 1733 foreach ($html->find('#config__manager [type=submit]') as $node) { 1734 $c = explode(' ', $node->class); 1735 if (in_array('mikio-primary', $c) === false) { 1736 $c[] = 'mikio-primary'; 1737 } 1738 $node->class = implode(' ', $c); 1739 } 1740 1741 /* Hide page title if hero is enabled */ 1742 if ($this->getConf('heroTitle') === true && $ACT !== 'preview') { 1743 $pageTitle = $this->parsePageTitle(); 1744 1745 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1746 if ($elm->innertext === $pageTitle) { 1747 // $elm->innertext = ''; 1748 $elm->setAttribute('style', 'display:none'); 1749 1750 break; 1751 } 1752 } 1753 } 1754 1755 /* Hero subtitle */ 1756 foreach ($html->find('p') as $elm) { 1757 $i = stripos($elm->innertext, '~~hero-subtitle'); 1758 if ($i !== false) { 1759 $j = strpos($elm->innertext, '~~', ($i + 2)); 1760 if ($j !== false) { 1761 if ($j > ($i + 16)) { 1762 $subtitle = substr($elm->innertext, ($i + 16), ($j - $i - 16)); 1763 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1764 1765 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1766 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1767 } 1768 1769 break; 1770 } 1771 } 1772 } 1773 1774 /* Hero image */ 1775 foreach ($html->find('p') as $elm) { 1776 $image = ''; 1777 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1778 if (count($matches) > 0) { 1779 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1780 if (count($imageTagMatches) > 0) { 1781 $image = $imageTagMatches[1]; 1782 } else { 1783 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1784 if (count($imageTagMatches) > 0) { 1785 $image = $imageTagMatches[1]; 1786 } else { 1787 $image = strip_tags($matches[1]); 1788 if (stripos($image, ':') === false) { 1789 $image = str_replace(['{', '}'], '', $image); 1790 $i = stripos($image, '?'); 1791 if ($i !== false) { 1792 $image = substr($image, 0, $i); 1793 } 1794 1795 $image = ml($image, '', true, '', false); 1796 } 1797 } 1798 } 1799 1800 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 1801 1802 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1803 }//end if 1804 }//end foreach 1805 1806 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] 1807 [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1808 foreach ($html->find('p') as $elm) { 1809 $i = stripos($elm->innertext, '~~hero-colors'); 1810 if ($i !== false) { 1811 $j = strpos($elm->innertext, '~~', ($i + 2)); 1812 if ($j !== false) { 1813 if ($j > ($i + 14)) { 1814 $color = substr($elm->innertext, ($i + 14), ($j - $i - 14)); 1815 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')'; 1816 1817 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1818 } 1819 1820 break; 1821 } 1822 } 1823 } 1824 1825 /* Hide parts - ~~hide-parts [parts]~~ */ 1826 foreach ($html->find('p') as $elm) { 1827 $i = stripos($elm->innertext, '~~hide-parts'); 1828 if ($i !== false) { 1829 $j = strpos($elm->innertext, '~~', ($i + 2)); 1830 if ($j !== false) { 1831 if ($j > ($i + 13)) { 1832 $parts = explode(' ', substr($elm->innertext, ($i + 13), ($j - $i - 13))); 1833 $script = ''; 1834 1835 foreach ($parts as $part) { 1836 // $part = trim($part); 1837 if (strlen($part) > 0) { 1838 $script .= 'mikio.hidePart(\'' . $part . '\');'; 1839 } 1840 } 1841 1842 if (strlen($script) > 0) { 1843 $this->footerScript['hide-parts'] = $script; 1844 } 1845 1846 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1847 } 1848 1849 break; 1850 }//end if 1851 }//end if 1852 }//end foreach 1853 1854 1855 /* Page Tags (tag plugin) */ 1856 if ($this->getConf('tagsConsolidate') === true) { 1857 $tags = ''; 1858 foreach ($html->find('div.tags a') as $elm) { 1859 $tags .= $elm->outertext; 1860 } 1861 1862 foreach ($html->find('div.tags') as $elm) { 1863 $elm->innertext = ''; 1864 $elm->setAttribute('style', 'display:none'); 1865 } 1866 1867 if (empty($tags) === false) { 1868 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1869 } 1870 } 1871 1872 // Configuration Manager 1873 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1874 // Additional save buttons 1875 foreach ($html->find('#config__manager') as $cm) { 1876 $saveButtons = ''; 1877 1878 foreach ($cm->find('p') as $elm) { 1879 $saveButtons = $elm->outertext; 1880 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1881 $elm->outertext = ''; 1882 } 1883 1884 foreach ($cm->find('fieldset') as $elm) { 1885 $elm->innertext .= $saveButtons; 1886 } 1887 } 1888 } 1889 1890 $content = $html->save(); 1891 $html->clear(); 1892 unset($html); 1893 1894 return $content; 1895 } 1896 1897 1898 /** 1899 * Get DokuWiki namespace/page/URI as link 1900 * 1901 * @param string $str String to parse. 1902 * @return string parsed URI 1903 */ 1904 public function getLink(string $str) 1905 { 1906 $i = strpos($str, '://'); 1907 if ($i !== false) { 1908 return $str; 1909 } 1910 1911 return wl($str); 1912 } 1913 1914 1915 /** 1916 * Check if the user can edit current namespace/page 1917 * 1918 * @return boolean user can edit 1919 */ 1920 public function userCanEdit() 1921 { 1922 global $INFO; 1923 global $ID; 1924 1925 $wiki_file = wikiFN($ID); 1926 if (@file_exists($wiki_file) === false) { 1927 return true; 1928 } 1929 if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) { 1930 return true; 1931 } 1932 // $meta_file = metaFN($ID, '.meta'); 1933 if ($INFO['meta']['user'] === false) { 1934 return true; 1935 } 1936 if ($INFO['client'] === $INFO['meta']['user']) { 1937 return true; 1938 } 1939 1940 return false; 1941 } 1942 1943 1944 /** 1945 * Search for and return the uri of a media file 1946 * 1947 * @param string $image Image name to search for (without extension). 1948 * @param boolean $searchCurrentNS Search the current namespace. 1949 * @param boolean $propagate Propagate search through the namespace. 1950 * @return string URI of the found media file 1951 */ 1952 public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true) 1953 { 1954 global $INFO; 1955 1956 $ext = ['png', 'jpg', 'gif', 'svg']; 1957 1958 if ($searchCurrentNS === true) { 1959 $prefix[] = ':' . $INFO['namespace'] . ':'; 1960 } 1961 if ($propagate === true) { 1962 $prefix[] = ':'; 1963 $prefix[] = ':wiki:'; 1964 } 1965 $theme = $this->getConf('customTheme'); 1966 if (empty($theme) === false) { 1967 $prefix[] = 'themes/' . $theme . '/images/'; 1968 } 1969 $prefix[] = 'images/'; 1970 1971 $search = []; 1972 foreach ($prefix as $pitem) { 1973 foreach ($ext as $eitem) { 1974 $search[] = $pitem . $image . '.' . $eitem; 1975 } 1976 } 1977 1978 $img = ''; 1979 $file = ''; 1980 $url = ''; 1981 $ismedia = false; 1982 $found = false; 1983 1984 foreach ($search as $img) { 1985 if (strcasecmp(substr($img, 0, 1), ':') === 0) { 1986 $file = mediaFN($img); 1987 $ismedia = true; 1988 } else { 1989 $file = tpl_incdir() . $img; 1990 $ismedia = false; 1991 } 1992 1993 if (file_exists($file) === true) { 1994 $found = true; 1995 break; 1996 } 1997 } 1998 1999 if ($found === false) { 2000 return false; 2001 } 2002 2003 if ($ismedia === true) { 2004 $url = ml($img, '', true, '', false); 2005 } else { 2006 $url = tpl_basedir() . $img; 2007 } 2008 2009 return $url; 2010 } 2011 2012 2013 /** 2014 * Print or return the page title 2015 * 2016 * @param string $page Page id or empty string for current page. 2017 * @return string generated content 2018 */ 2019 public function getPageTitle(string $page = '') 2020 { 2021 global $ID, $conf; 2022 2023 $html = ''; 2024 2025 if (empty($page) === true) { 2026 $page = $ID; 2027 } 2028 2029 $html = p_get_first_heading($page); 2030 $html = strip_tags($html); 2031 $html = preg_replace('/\s+/', ' ', $html); 2032 $html .= ' [' . strip_tags($conf['title']) . ']'; 2033 $html = trim($html); 2034 2035 return $html; 2036 } 2037 2038 2039 /** 2040 * Return inline theme icon 2041 * 2042 * @param string $type Icon to retreive. 2043 * @param string $class Classname to insert. 2044 * @return string HTML icon content 2045 */ 2046 public function mikioInlineIcon(string $type, string $class = "") 2047 { 2048 if (is_array($class) === true) { 2049 $class = explode(' ', $class); 2050 } 2051 2052 if (strlen($class) > 0) { 2053 $class = ' ' . $class; 2054 } 2055 2056 switch ($type) { 2057 case 'wrench': 2058 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 20591792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,53.152542,1217.0847)"><path d="m 384,64 q 0,26 -19,45 -19, 206019 -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, 2061-37 -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, 2062435 q 0,-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 2063131.5,131.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, 2064-107 q 5,3 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>'; 2065 case 'file': 2066 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2067viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"> 2068<path d="M 128,0 H 1152 V 768 H 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 20691280,768 V -32 q 0,-40 -28,-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 2070q 40,0 88,-20 48,-20 76,-48 l 408,-408 q 28,-28 48,-76 20,-48 20,-88 z" id="path2993" inkscape:connector-curvature="0" 2071xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2072 case 'gear': 2073 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2074viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"> 2075<path d="m 1024,640 q 0,106 -75,181 -75,75 -181,75 -106,0 -181,-75 -75,-75 -75,-181 0,-106 75,-181 75,-75 181,-75 106,0 2076181,75 75,75 75,181 z m 512,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 207710,-25 0,-13 -9,-23 -27,-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 2078-36,-28 H 657 q -14,0 -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 2079147,186 q -7,10 -7,23 0,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 2080q 0,12 8,23 8,11 19,13 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, 208171.5 13,0 26,-10 l 138,-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 2082q 49,-16 90,-37 l 142,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 2083-54,-70.5 26,-50 41,-98 l 183,-28 q 13,-2 21,-12.5 8,-10.5 8,-23.5 z" id="path3029" inkscape:connector-curvature="0" /> 2084</g></svg>'; 2085 case 'user': 2086 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2087viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 20881408,131 Q 1408,11 1335,-58.5 1262,-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 208928,402 44,452 q 16,50 43,97.5 27,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, 2090-26.5 108,-48 Q 637,565 704,565 q 67,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 209150.5,-20 85.5,-53.5 35,-33.5 62,-81 27,-47.5 43,-97.5 16,-50 26.5,-108.5 10.5,-58.5 14,-109 Q 1408,184 1408,131 z m 2092-320,893 Q 1088,865 975.5,752.5 863,640 704,640 545,640 432.5,752.5 320,865 320,1024 320,1183 432.5,1295.5 545,1408 704, 20931408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>'; 2094 case 'search': 2095 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2096aria-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 209718.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 209824.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 20996.195 0 0 1-6.188 6.188z"/></svg>'; 2100 case 'home': 2101 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2102viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g 2103transform="matrix(1,0,0,-1,68.338983,1285.4237)" id="g3015"><path d="M 1408,544 V 64 Q 1408,38 1389,19 1370,0 1344,0 H 2104960 V 384 H 704 V 0 H 320 q -26,0 -45,19 -19,19 -19,45 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 2105m 223,69 -62,-74 q -8,-9 -21,-11 h -3 q -13,0 -21,7 L 832,1112 140,535 q -12,-8 -24,-7 -13,2 -21,11 l -62,74 q -8,10 2106-7,23.5 1,13.5 11,21.5 l 719,599 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, 2107-9 9,-23 V 840 l 219,-182 q 10,-8 11,-21.5 1,-13.5 -7,-23.5 z" id="path3017" inkscape:connector-curvature="0" 2108xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2109 case 'sun': 2110 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2111style="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 21120 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 21130a.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 21141-.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 21150 0 1-.707.707z" /></svg>'; 2116 case 'moon': 2117 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2118style="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 21194.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 21201 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 21211.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 21220-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>'; 2123 case 'hamburger': 2124 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" 2125style="fill:currentColor"><path d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 212676v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 212716v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 212816v40c0 8.837 7.163 16 16 16z"/></svg>'; 2129 case 'down-arrow': 2130 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2131aria-hidden="true" style="fill:currentColor"><path d="M16.003 18.626l7.081-7.081L25 13.46l-8.997 8.998-9.003-9 21321.917-1.916z"/></svg>'; 2133 }//end switch 2134 2135 return ''; 2136 } 2137 2138 /** 2139 * Finalize theme 2140 * 2141 * @return void 2142 */ 2143 public function finalize() 2144 { 2145 } 2146 2147 /** 2148 * Show Messages 2149 * 2150 * @return void 2151 */ 2152 public function showMessages() 2153 { 2154 global $ACT; 2155 2156 if ($this->lessIgnored === true) { 2157 msg( 2158 'useLESS is enabled on the Mikio template, however is not supported on this server', 2159 2, 2160 '', 2161 '', 2162 MSG_ADMINS_ONLY 2163 ); 2164 } 2165 2166 $show = $this->getConf('showNotifications'); 2167 if ( 2168 strcasecmp($show, 'always') === 0 || 2169 (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0) 2170 ) { 2171 global $MSG, $MSG_shown; 2172 2173 if (isset($MSG) === false) { 2174 return; 2175 } 2176 2177 if (isset($MSG_shown) === false) { 2178 $MSG_shown = []; 2179 } 2180 2181 foreach ($MSG as $msg) { 2182 $hash = md5($msg['msg']); 2183 if (isset($MSG_shown[$hash]) === true) { 2184 continue; 2185 } 2186 // skip double messages 2187 2188 if (info_msg_allowed($msg) === true) { 2189 echo '<div class="' . $msg['lvl'] . '">'; 2190 echo $msg['msg']; 2191 echo '</div>'; 2192 } 2193 2194 $MSG_shown[$hash] = true; 2195 } 2196 2197 unset($GLOBALS['MSG']); 2198 }//end if 2199 } 2200 2201 /** 2202 * Dokuwiki version 2203 * 2204 * @return string the dw version name 2205 */ 2206 public function dwVersion() 2207 { 2208 if (function_exists('getVersionData') === true) { 2209 $version_data = getVersionData(); 2210 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2211 $version_items = explode(' ', $version_data['date']); 2212 if (count($version_items) >= 2) { 2213 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 2214 } 2215 } 2216 } 2217 2218 return 'unknown'; 2219 } 2220 2221 /** 2222 * Dokuwiki version number 2223 * 2224 * @return string the dw version date converted to integer 2225 */ 2226 public function dwVersionNumber() 2227 { 2228 if (function_exists('getVersionData') === true) { 2229 $version_data = getVersionData(); 2230 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2231 $version_items = explode(' ', $version_data['date']); 2232 if (count($version_items) >= 1) { 2233 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 2234 } 2235 } 2236 } 2237 2238 return 0; 2239 } 2240} 2241 2242global $TEMPLATE; 2243$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 2244