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 * @var string Notifications from included pages. 44 */ 45 private $includedPageNotifications = ''; 46 47 48 /** 49 * Class constructor 50 */ 51 public function __construct() 52 { 53 $this->tplDir = tpl_incdir(); 54 $this->baseDir = tpl_basedir(); 55 56 $this->registerHooks(); 57 } 58 59 /** 60 * Returns the instance of the class 61 * 62 * @return Template class instance 63 */ 64 public static function getInstance() 65 { 66 static $instance = null; 67 68 if (empty($instance) === true) { 69 $instance = new Template(); 70 } 71 72 return $instance; 73 } 74 75 76 /** 77 * Register the themes hooks into Dokuwiki 78 * 79 * @return void 80 */ 81 private function registerHooks() 82 { 83 global $EVENT_HANDLER; 84 85 $events_dispatcher = [ 86 'TPL_METAHEADER_OUTPUT' => 'metaheadersHandler' 87 ]; 88 89 foreach ($events_dispatcher as $event => $method) { 90 $EVENT_HANDLER->register_hook($event, 'BEFORE', $this, $method); 91 } 92 } 93 94 95 /** 96 * Meta handler hook for DokuWiki 97 * 98 * @param \Doku_Event $event DokuWiki Event. 99 * @return void 100 */ 101 public function metaHeadersHandler(\Doku_Event $event) 102 { 103 global $MIKIO_ICONS; 104 global $conf; 105 106 global $MIKIO_TEMPLATE; 107 $MIKIO_TEMPLATE = '123'; 108 109 $this->includePage('theme', false, true); 110 111 $stylesheets = []; 112 $scripts = []; 113 114 if (empty($this->getConf('customTheme')) === false) { 115 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.less') === true) { 116 $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.less'; 117 } else { 118 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.css') === true) { 119 $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.css'; 120 } 121 } 122 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/script.js') === true) { 123 $scripts[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/script.js'; 124 } 125 } 126 127 if (is_array($MIKIO_ICONS) === true && empty($this->getConf('iconTag', 'icon')) === false) { 128 $icons = []; 129 foreach ($MIKIO_ICONS as $icon) { 130 if (isset($icon['name']) === true && isset($icon['css']) === true && isset($icon['insert']) === true) { 131 $icons[] = $icon; 132 133 if (empty($icon['css']) === false) { 134 if (strpos($icon['css'], '//') === false) { 135 $stylesheets[] = $this->baseDir . 'icons/' . $icon['css']; 136 } else { 137 $stylesheets[] = $icon['css']; 138 } 139 } 140 } 141 } 142 $MIKIO_ICONS = $icons; 143 } else { 144 $MIKIO_ICONS = []; 145 } 146 147 $scripts[] = $this->baseDir . 'assets/mikio-typeahead.js'; 148 $scripts[] = $this->baseDir . 'assets/mikio.js'; 149 150 if ($this->getConf('useLESS') === true) { 151 $stylesheets[] = $this->baseDir . 'assets/mikio.less'; 152 } else { 153 $stylesheets[] = $this->baseDir . 'assets/mikio.css'; 154 } 155 156 /* MikioPlugin Support */ 157 if (plugin_load('action', 'mikioplugin') !== null) { 158 if ($this->getConf('useLESS') === true) { 159 $stylesheets[] = $this->baseDir . 'assets/mikioplugin.less'; 160 } else { 161 $stylesheets[] = $this->baseDir . 'assets/mikioplugin.css'; 162 } 163 } 164 165 $set = []; 166 foreach ($stylesheets as $style) { 167 if (in_array($style, $set) === false) { 168 if (strcasecmp(substr($style, -5), '.less') === 0 && $this->getConf('useLESS') === true) { 169 $style = $this->baseDir . 'css.php?css=' . str_replace($this->baseDir, '', $style); 170 } 171 172 array_unshift($event->data['link'], [ 173 'type' => 'text/css', 174 'rel' => 'stylesheet', 175 'href' => $style 176 ]); 177 } 178 $set[] = $style; 179 } 180 181 $set = []; 182 foreach ($scripts as $script) { 183 if (in_array($script, $set) === false) { 184 $script_params = [ 185 'type' => 'text/javascript', 186 '_data' => '', 187 'src' => $script 188 ]; 189 190 // equal to or greator than hogfather 191 if ($this->dwVersionNumber() >= 20200729) { 192 // greator than hogfather - defer always on 193 if ($this->dwVersionNumber() >= 20200729) { 194 $script_params += ['defer' => 'defer']; 195 } else { 196 // hogfather - defer always on unless $conf['defer_js'] is false 197 if (array_key_exists('defer_js', $conf) === false || $conf['defer_js'] === true) { 198 $script_params += ['defer' => 'defer']; 199 } 200 } 201 } 202 203 $event->data['script'][] = $script_params; 204 }//end if 205 $set[] = $script; 206 }//end foreach 207 } 208 209 210 /** 211 * Print or return the footer meta data 212 * 213 * @param boolean $print Print the data to buffer. 214 * @return string HTML footer meta data 215 */ 216 public function includeFooterMeta(bool $print = true) 217 { 218 $html = ''; 219 220 if (count($this->footerScript) > 0) { 221 $html .= '<script type="text/javascript">function mikioFooterRun() {'; 222 foreach ($this->footerScript as $script) { 223 $html .= $script . ';'; 224 } 225 $html .= '}</script>'; 226 } 227 228 229 if ($print === true) { 230 echo $html; 231 } 232 return $html; 233 } 234 235 236 // phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing 237 238 239 /** 240 * Retreive and parse theme configuration options 241 * 242 * @param string $key The configuration key to retreive. 243 * @param mixed $default If key doesn't exist, return this value. 244 * @return mixed parsed value of configuration 245 */ 246 public function getConf(string $key, $default = false) 247 { 248 $value = tpl_getConf($key, $default); 249 250 $data = [ 251 ['keys' => ['navbarDWMenuType'], 'type' => 'choice', 252 'values' => ['both', 'icons', 'text'] 253 ], 254 ['keys' => ['navbarDWMenuCombine'], 'type' => 'choice', 255 'values' => ['combine', 'seperate', 'dropdown'] 256 ], 257 ['keys' => ['navbarPosLeft', 'navbarPosMiddle', 'navbarPosRight'], 258 'type' => 'choice', 259 'values' => ['none', 'custom', 'search', 'dokuwiki'], 260 'default' => [ 261 'navbarPosLeft' => 'none', 262 'navbarPosMiddle' => 'search', 263 'navbarPosRight' => 'dokuwiki' 264 ] 265 ], 266 ['keys' => ['navbarItemShowCreate', 'navbarItemShowShow', 'navbarItemShowRevs', 'navbarItemShowBacklink', 267 'navbarItemShowRecent', 'navbarItemShowMedia', 'navbarItemShowIndex', 'navbarItemShowProfile', 268 'navbarItemShowAdmin' 269 ], 270 'type' => 'choice', 271 'values' => ['always', 'logged in', 'logged out', 'never'] 272 ], 273 ['keys' => ['navbarItemShowLogin', 'navbarItemShowLogout'], 274 'type' => 'choice', 275 'values' => ['always', 'never'] 276 ], 277 ['keys' => ['searchButton'], 'type' => 'choice', 278 'values' => ['icon', 'text'] 279 ], 280 ['keys' => ['breadcrumbPosition', 'youareherePosition'], 281 'type' => 'choice', 282 'values' => ['top', 'hero', 'page', 'none'] 283 ], 284 ['keys' => ['youarehereHome'], 'type' => 'choice', 285 'values' => ['page title', 'home', 'icon', 'none'] 286 ], 287 ['keys' => ['sidebarLeftRow1', 'sidebarLeftRow2', 'sidebarLeftRow3', 'sidebarLeftRow4'], 288 'type' => 'choice', 289 'values' => ['none', 'logged in user', 'search', 'content', 'tags'], 290 'default' => [ 291 'sidebarLeftRow1' => 'logged in user', 292 'sidebarLeftRow2' => 'search', 293 'sidebarLeftRow3' => 'content' 294 ] 295 ], 296 ['keys' => ['pageToolsFloating', 'pageToolsFooter'], 297 'type' => 'choice', 298 'values' => ['always', 'none', 'page editors'] 299 ], 300 ['keys' => ['pageToolsShowCreate', 'pageToolsShowEdit', 'pageToolsShowRevs', 'pageToolsShowBacklink', 301 'pageToolsShowTop' 302 ], 303 'type' => 'choice', 304 'values' => ['always', 'logged in', 'logged out', 'never'] 305 ], 306 ['keys' => ['showNotifications'], 'type' => 'choice', 307 'values' => ['admin', 'always', 'none'] 308 ], 309 ['keys' => ['licenseType'], 'type' => 'choice', 310 'values' => ['badge', 'button', 'none'] 311 ], 312 ['keys' => ['navbarUseTitleIcon'], 'type' => 'bool'], 313 ['keys' => ['navbarUseTitleText'], 'type' => 'bool'], 314 ['keys' => ['navbarUseTaglineText'], 'type' => 'bool'], 315 ['keys' => ['navbarShowSub'], 'type' => 'bool'], 316 ['keys' => ['heroTitle'], 'type' => 'bool'], 317 ['keys' => ['heroImagePropagation'], 'type' => 'bool'], 318 ['keys' => ['breadcrumbPrefix'], 'type' => 'bool'], 319 ['keys' => ['breadcrumbSep'], 'type' => 'bool'], 320 ['keys' => ['youareherePrefix'], 'type' => 'bool'], 321 ['keys' => ['youarehereSep'], 'type' => 'bool'], 322 ['keys' => ['sidebarShowLeft'], 'type' => 'bool'], 323 ['keys' => ['sidebarShowRight'], 'type' => 'bool'], 324 ['keys' => ['tocFull'], 'type' => 'bool'], 325 ['keys' => ['footerSearch'], 'type' => 'bool'], 326 ['keys' => ['licenseImageOnly'], 'type' => 'bool'], 327 ['keys' => ['includePageUseACL'], 'type' => 'bool'], 328 ['keys' => ['includePagePropagate'], 'type' => 'bool'], 329 ['keys' => ['youarehereHideHome'], 'type' => 'bool'], 330 ['keys' => ['tagsConsolidate'], 'type' => 'bool'], 331 ['keys' => ['footerInPage'], 'type' => 'bool'], 332 ['keys' => ['sidebarMobileDefaultCollapse'], 'type' => 'bool'], 333 ['keys' => ['sidebarAlwaysShowLeft'], 'type' => 'bool'], 334 ['keys' => ['sidebarAlwaysShowRight'], 'type' => 'bool'], 335 ['keys' => ['searchUseTypeahead'], 'type' => 'bool'], 336 ['keys' => ['showLightDark'], 'type' => 'bool'], 337 ['keys' => ['autoLightDark'], 'type' => 'bool'], 338 ['keys' => ['youarehereShowLast'], 'type' => 'int'], 339 340 ['keys' => ['iconTag'], 'type' => 'string'], 341 ['keys' => ['customTheme'], 'type' => 'string'], 342 ['keys' => ['navbarCustomMenuText'], 'type' => 'string'], 343 ['keys' => ['breadcrumbPrefixText'], 'type' => 'string'], 344 ['keys' => ['breadcrumbSepText'], 'type' => 'string'], 345 ['keys' => ['youareherePrefixText'], 'type' => 'string'], 346 ['keys' => ['youarehereSepText'], 'type' => 'string'], 347 ['keys' => ['footerCustomMenuText'], 'type' => 'string'], 348 ['keys' => ['brandURLGuest'], 'type' => 'string'], 349 ['keys' => ['brandURLUser'], 'type' => 'string'], 350 351 ['keys' => ['useLESS'], 'type' => 'less'], 352 ]; 353 354 foreach ($data as $row) { 355 // does not check case.... 356 if (in_array($key, $row['keys']) === true) { 357 if (array_key_exists('type', $row) === true) { 358 switch ($row['type']) { 359 case 'bool': 360 return (bool) $value; 361 case 'int': 362 return (int) $value; 363 case 'string': 364 return $value; 365 case 'less': 366 $value = (bool) $value; 367 $lessAvailable = true; 368 369 // check for less library 370 $lesscLib = '../../../vendor/marcusschwarz/lesserphp/lessc.inc.php'; 371 if (file_exists($lesscLib) === false) { 372 $lesscLib = $_SERVER['DOCUMENT_ROOT'] . '/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 373 } 374 if (file_exists($lesscLib) === false) { 375 $lesscLib = '../../../../../app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 376 } 377 if (file_exists($lesscLib) === false) { 378 $lesscLib = $_SERVER['DOCUMENT_ROOT'] . 379 '/app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 380 } 381 if (file_exists($lesscLib) === false) { 382 $lessAvailable = false; 383 } 384 385 // check for ctype extensions 386 if (function_exists('ctype_digit') === false) { 387 $lessAvailable = false; 388 } 389 390 if ($value === true && $lessAvailable === false) { 391 $this->lessIgnored = true; 392 $value = false; 393 } 394 395 return $value; 396 }//end switch 397 }//end if 398 399 if (in_array($value, $row['values']) === true) { 400 return $value; 401 } 402 403 if (array_key_exists('default', $row) === true) { 404 if (is_array($row['default']) === true) { 405 if (array_key_exists($key, $row['default']) === true) { 406 return $row['default'][$key]; 407 } 408 } else { 409 return $row['default']; 410 } 411 } 412 413 return reset($row['values']); 414 }//end if 415 }//end foreach 416 417 return $value; 418 } 419 420 421 // phpcs:enable 422 423 424 /** 425 * Check if a page exist in directory or namespace 426 * 427 * @param string $page Page/namespace to search. 428 * @return boolean if page exists 429 */ 430 public function pageExists(string $page) 431 { 432 ob_start(); 433 tpl_includeFile($page . '.html'); 434 $html = ob_get_contents(); 435 ob_end_clean(); 436 437 if (empty($html) === false) { 438 return true; 439 } 440 441 $useACL = $this->getConf('includePageUseACL'); 442 $propagate = $this->getConf('includePagePropagate'); 443 444 if ($propagate === true) { 445 if (page_findnearest($page, $useACL) !== false) { 446 return true; 447 } 448 } elseif ($useACL === true && auth_quickaclcheck($page) !== AUTH_NONE) { 449 return true; 450 } 451 452 return false; 453 } 454 455 456 /** 457 * Print or return page from directory or namespace 458 * 459 * @param string $page Page/namespace to include. 460 * @param boolean $print Print content. 461 * @param boolean $parse Parse content before printing/returning. 462 * @param string $classWrapper Wrap page in a div with class. 463 * @return string contents of page found 464 */ 465 public function includePage(string $page, bool $print = true, bool $parse = true, string $classWrapper = '') 466 { 467 ob_start(); 468 tpl_includeFile($page . '.html'); 469 $html = ob_get_contents(); 470 ob_end_clean(); 471 472 if (empty($html) === true) { 473 global $MSG; 474 475 $useACL = $this->getConf('includePageUseACL'); 476 $propagate = $this->getConf('includePagePropagate'); 477 $html = ''; 478 479 ob_start(); 480 $html = tpl_include_page($page, false, $propagate, $useACL); 481 $this->includedPageNotifications .= ob_get_contents(); 482 ob_end_clean(); 483 } 484 485 if (empty($html) === false && $parse === true) { 486 $html = $this->parseContent($html); 487 } 488 489 if (empty($classWrapper) === false && empty($html) === false) { 490 $html = '<div class="' . $classWrapper . '">' . $html . '</div>'; 491 } 492 493 if ($print === true) { 494 echo $html; 495 } 496 return $html; 497 } 498 499 500 /** 501 * Print or return logged in user information 502 * 503 * @param boolean $print Print content. 504 * @return string user information 505 */ 506 public function includeLoggedIn(bool $print = true) 507 { 508 $html = ''; 509 510 if (empty($_SERVER['REMOTE_USER']) === false) { 511 $html .= '<div class="mikio-user-info">'; 512 ob_start(); 513 tpl_userinfo(); 514 $html .= ob_get_contents(); 515 ob_end_clean(); 516 $html .= '</div>'; 517 } 518 519 if ($print === true) { 520 echo $html; 521 } 522 return $html; 523 } 524 525 526 /** 527 * Print or return DokuWiki Menu 528 * 529 * @param boolean $print Print content. 530 * @return string contents of the menu 531 */ 532 public function includeDWMenu(bool $print = true) 533 { 534 global $lang; 535 global $USERINFO; 536 537 $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0); 538 $html = '<ul class="mikio-nav">'; 539 540 $pageToolsMenu = []; 541 $siteToolsMenu = []; 542 $userToolsMenu = []; 543 544 $showIcons = ($this->getConf('navbarDWMenuType') != 'text'); 545 $showText = ($this->getConf('navbarDWMenuType') != 'icons'); 546 $isDropDown = ($this->getConf('navbarDWMenuCombine') != 'seperate'); 547 548 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 549 foreach ($items as $item) { 550 if ($item->getType() !== 'top') { 551 $itemHtml = ''; 552 553 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 554 if ( 555 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 556 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 557 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false)) 558 ) { 559 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . 560 ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 561 if ($showIcons === true) { 562 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 563 } 564 if ($showText === true || $isDropDown === true) { 565 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 566 } 567 $itemHtml .= '</a>'; 568 569 $pageToolsMenu[] = $itemHtml; 570 } 571 }//end if 572 }//end foreach 573 574 $items = (new \dokuwiki\Menu\SiteMenu())->getItems('action'); 575 foreach ($items as $item) { 576 $itemHtml = ''; 577 578 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 579 if ( 580 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 581 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 582 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false)) 583 ) { 584 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown === true ? 'mikio-dropdown-item' : '') . ' ' . 585 $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 586 if ($showIcons === true) { 587 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 588 } 589 if ($showText === true || $isDropDown === true) { 590 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 591 } 592 $itemHtml .= '</a>'; 593 594 $siteToolsMenu[] = $itemHtml; 595 } 596 }//end foreach 597 598 $items = (new \dokuwiki\Menu\UserMenu())->getItems('action'); 599 foreach ($items as $item) { 600 $itemHtml = ''; 601 602 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 603 if ( 604 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 605 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 606 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === false)) 607 ) { 608 $itemHtml .= '<a class="mikio-nav-link' . ($isDropDown === true ? ' mikio-dropdown-item' : '') . ' ' . 609 $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 610 if ($showIcons === true) { 611 $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 612 } 613 if ($showText === true || $isDropDown === true) { 614 $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 615 } 616 $itemHtml .= '</a>'; 617 618 $userToolsMenu[] = $itemHtml; 619 } 620 }//end foreach 621 622 623 switch ($this->getConf('navbarDWMenuCombine')) { 624 case 'dropdown': 625 $html .= '<li id="dokuwiki__pagetools" class="mikio-nav-dropdown">'; 626 $html .= '<a id="mikio_dropdown_pagetools" class="nav-link dropdown-toggle" href="#" role="button" 627data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 628 ($showIcons === true ? $this->mikioInlineIcon('file') : '') . 629 ($showText === true ? $lang['page_tools'] : '<span class="mikio-small-only">' . $lang['page_tools'] . 630 '</span>') . '</a>'; 631 $html .= '<div class="mikio-dropdown closed">'; 632 633 foreach ($pageToolsMenu as $item) { 634 $html .= $item; 635 } 636 637 $html .= '</div>'; 638 $html .= '</li>'; 639 640 $html .= '<li id="dokuwiki__sitetools" class="mikio-nav-dropdown">'; 641 $html .= '<a id="mikio_dropdown_sitetools" class="nav-link dropdown-toggle" href="#" role="button" 642data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 643 ($showIcons === true ? $this->mikioInlineIcon('gear') : '') . 644 ($showText === true ? $lang['site_tools'] : '<span class="mikio-small-only">' . 645 $lang['site_tools'] . '</span>') . '</a>'; 646 $html .= '<div class="mikio-dropdown closed">'; 647 648 foreach ($siteToolsMenu as $item) { 649 $html .= $item; 650 } 651 652 $html .= '</div>'; 653 $html .= '</li>'; 654 655 $html .= '<li id="dokuwiki__usertools" class="mikio-nav-dropdown">'; 656 $html .= '<a id="mikio_dropdown_usertools" class="nav-link dropdown-toggle" href="#" role="button" 657data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 658 ($showIcons === true ? $this->mikioInlineIcon('user') : '') . 659 ($showText === true ? $lang['user_tools'] : '<span class="mikio-small-only">' . 660 $lang['user_tools'] . '</span>') . '</a>'; 661 $html .= '<div class="mikio-dropdown closed">'; 662 663 foreach ($userToolsMenu as $item) { 664 $html .= $item; 665 } 666 667 $html .= '</div>'; 668 $html .= '</li>'; 669 670 break; 671 672 case 'combine': 673 $html .= '<li class="mikio-nav-dropdown">'; 674 $html .= '<a class="mikio-nav-link" href="#">' . 675 ($showIcons === true ? $this->mikioInlineIcon('wrench') : '') . 676 ($showText === true ? tpl_getLang('tools-menu') : '<span class="mikio-small-only">' . 677 tpl_getLang('tools-menu') . '</span>') . '</a>'; 678 $html .= '<div class="mikio-dropdown closed">'; 679 680 $html .= '<h6 class="mikio-dropdown-header">' . $lang['page_tools'] . '</h6>'; 681 foreach ($pageToolsMenu as $item) { 682 $html .= $item; 683 } 684 685 $html .= '<div class="mikio-dropdown-divider"></div>'; 686 $html .= '<h6 class="mikio-dropdown-header">' . $lang['site_tools'] . '</h6>'; 687 foreach ($siteToolsMenu as $item) { 688 $html .= $item; 689 } 690 691 $html .= '<div class="mikio-dropdown-divider"></div>'; 692 $html .= '<h6 class="mikio-dropdown-header">' . $lang['user_tools'] . '</h6>'; 693 foreach ($userToolsMenu as $item) { 694 $html .= $item; 695 } 696 697 $html .= '</div>'; 698 $html .= '</li>'; 699 break; 700 701 default: // seperate 702 foreach ($siteToolsMenu as $item) { 703 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 704 } 705 706 foreach ($pageToolsMenu as $item) { 707 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 708 } 709 710 foreach ($userToolsMenu as $item) { 711 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 712 } 713 714 break; 715 }//end switch 716 717 $translation = plugin_load('helper', 'translation'); 718 if ($translation !== null) { 719 $html .= '<li id="mikio__translate" class="mikio-nav-dropdown">'; 720 $html .= '<a id="mikio_dropdown_translate" class="nav-link dropdown-toggle" href="#" role="button" 721data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . 722 $this->mikioInlineIcon('language') . 723 '</a>'; 724 $html .= '<div class="mikio-dropdown closed">'; 725 726 $html .= $translation->showTranslations(); 727 728 $html .= '</div>'; 729 $html .= '</li>'; 730 } 731 732 if ($this->getConf('showLightDark') === true) { 733 $autoLightDark = $this->getConf('autoLightDark'); 734 $html .= '<li class="mikio-darklight"> 735<a href="#" class="mikio-control mikio-button mikio-darklight-button">' . 736 ($autoLightDark === true ? $this->mikioInlineIcon('sunmoon', 'mikio-darklight-auto') : '') . 737 $this->mikioInlineIcon('sun', 'mikio-darklight-light') . 738 $this->mikioInlineIcon('moon', 'mikio-darklight-dark') . 739 '</a></li>'; 740 } 741 742 $html .= '</ul>'; 743 744 if ($print === true) { 745 echo $html; 746 } 747 return $html; 748 } 749 750 751 /** 752 * Create a nav element from a string. <uri>|<title>; 753 * 754 * @param string $str String to generate nav. 755 * @return string nav elements generated 756 */ 757 public function stringToNav(string $str) 758 { 759 $html = ''; 760 761 if (empty($str) === false) { 762 $items = explode(';', $str); 763 if (count($items) > 0) { 764 $html .= '<ul class="mikio-nav">'; 765 foreach ($items as $item) { 766 $parts = explode('|', $item); 767 if ($parts > 1) { 768 $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' . 769 strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) . 770 '</a></li>'; 771 } 772 } 773 $html .= '</ul>'; 774 } 775 } 776 777 return $html; 778 } 779 780 /** 781 * print or return the main navbar 782 * 783 * @param boolean $print Print the navbar. 784 * @param boolean $showSub Include the sub navbar. 785 * @return string generated content 786 */ 787 public function includeNavbar(bool $print = true, bool $showSub = false) 788 { 789 global $conf, $USERINFO; 790 791 $homeUrl = wl(); 792 793 if (plugin_isdisabled('showpageafterlogin') === false) { 794 $p = &plugin_load('action', 'showpageafterlogin'); 795 if (empty($p) === false) { 796 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 797 $homeUrl = wl($p->getConf('page_after_login')); 798 } 799 } 800 } else { 801 if (is_array($USERINFO) === true && count($USERINFO) > 0) { 802 $url = $this->getConf('brandURLUser'); 803 if (strlen($url) > 0) { 804 $homeUrl = $url; 805 } 806 } else { 807 $url = $this->getConf('brandURLGuest'); 808 if (strlen($url) > 0) { 809 $homeUrl = $url; 810 } 811 } 812 } 813 814 $html = ''; 815 816 $html .= '<nav class="mikio-navbar' . (($this->getConf('stickyNavbar') === true) ? ' mikio-sticky' : '') . 817 '">'; 818 $html .= '<div class="mikio-container">'; 819 $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '">'; 820 if ($this->getConf('navbarUseTitleIcon') === true || $this->getConf('navbarUseTitleText') === true) { 821 // Brand image 822 if ($this->getConf('navbarUseTitleIcon') === true) { 823 $logo = $this->getMediaFile('logo', false); 824 ; 825 if (empty($logo) === false) { 826 $width = $this->getConf('navbarTitleIconWidth'); 827 $height = $this->getConf('navbarTitleIconHeight'); 828 $styles = ''; 829 830 if (strlen($width) > 0 || strlen($height) > 0) { 831 if (ctype_digit($width) === true) { 832 $styles .= 'max-width:' . intval($width) . 'px;'; 833 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $width) === 1) { 834 $styles .= 'max-width:' . $width . ';'; 835 } elseif (strcasecmp($width, 'none') === 0) { 836 $styles .= 'max-width:none;'; 837 } 838 839 if (ctype_digit($height) === true) { 840 $styles .= 'max-height:' . intval($height) . 'px;'; 841 } elseif (preg_match('/^\d+(px|rem|em|%)$/', $height) === 1) { 842 $styles .= 'max-height:' . $height . ';'; 843 } elseif (strcasecmp($height, 'none') === 0) { 844 $styles .= 'max-height:none;'; 845 } 846 847 if (strlen($styles) > 0) { 848 $styles = ' style="' . $styles . '"'; 849 } 850 }//end if 851 852 $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image"' . $styles . '>'; 853 }//end if 854 }//end if 855 856 // Brand title 857 if ($this->getConf('navbarUseTitleText') === true) { 858 $html .= '<div class="mikio-navbar-brand-title">'; 859 $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>'; 860 if ($this->getConf('navbarUseTaglineText') === true) { 861 $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>'; 862 } 863 $html .= '</div>'; 864 } 865 }//end if 866 $html .= '</a>'; 867 $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>'; 868 869 // Menus 870 $html .= '<div class="mikio-navbar-collapse">'; 871 872 $menus = [$this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'), 873 $this->getConf('navbarPosRight', 'none') 874 ]; 875 foreach ($menus as $menuType) { 876 switch ($menuType) { 877 case 'custom': 878 $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', '')); 879 break; 880 case 'search': 881 $html .= '<div class="mikio-nav-item">'; 882 $html .= $this->includeSearch(false); 883 $html .= '</div>'; 884 break; 885 case 'dokuwiki': 886 $html .= $this->includeDWMenu(false); 887 break; 888 } 889 } 890 891 $html .= '</div>'; 892 $html .= '</div>'; 893 $html .= '</nav>'; 894 895 // Sub Navbar 896 if ($showSub === true) { 897 $sub = $this->includePage('submenu', false); 898 if (empty($sub) === false) { 899 $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>'; 900 } 901 } 902 903 if ($print === true) { 904 echo $html; 905 } 906 return $html; 907 } 908 909 910 /** 911 * Is there a sidebar 912 * 913 * @param string $prefix Sidebar prefix to use when searching. 914 * @return boolean if sidebar exists 915 */ 916 public function sidebarExists(string $prefix = '') 917 { 918 global $conf; 919 920 if (strcasecmp($prefix, 'left') === 0) { 921 $prefix = ''; 922 } 923 924 return $this->pageExists($conf['sidebar' . $prefix]); 925 } 926 927 928 /** 929 * Print or return the sidebar content 930 * 931 * @param string $prefix Sidebar prefix to use when searching. 932 * @param boolean $print Print the generated content to the output buffer. 933 * @param boolean $parse Parse the content. 934 * @return string generated content 935 */ 936 public function includeSidebar(string $prefix = '', bool $print = true, bool $parse = true) 937 { 938 global $conf, $ID; 939 940 $html = ''; 941 $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix)); 942 $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix)); 943 944 if (empty($confPrefix) === true) { 945 $confPrefix = 'Left'; 946 } 947 if (strcasecmp($prefix, 'left') === 0) { 948 $prefix = ''; 949 } 950 951 $sidebarPage = empty($conf[$prefix . 'sidebar']) === true ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar']; 952 953 if ( 954 $this->getConf('sidebarShow' . $confPrefix) === true && page_findnearest($sidebarPage) !== false && 955 p_get_metadata($ID, 'nosidebar', false) === null 956 ) { 957 $content = $this->includePage($sidebarPage . 'header', false); 958 if (empty($content) === false) { 959 $html .= '<div class="mikio-sidebar-header">' . $content . '</div>'; 960 } 961 962 if (empty($prefix) === true) { 963 $rows = [$this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'), 964 $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4') 965 ]; 966 967 foreach ($rows as $row) { 968 switch ($row) { 969 case 'search': 970 $html .= $this->includeSearch(false); 971 break; 972 case 'logged in user': 973 $html .= $this->includeLoggedIn(false); 974 break; 975 case 'content': 976 $content = $this->includePage($sidebarPage, false); 977 if (empty($content) === false) { 978 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 979 } 980 break; 981 case 'tags': 982 $html .= '<div class="mikio-tags"></div>'; 983 } 984 } 985 } else { 986 $content = $this->includePage($sidebarPage, false); 987 if (empty($content) === false) { 988 $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 989 } 990 }//end if 991 992 $content = $this->includePage($sidebarPage . 'footer', false); 993 if (empty($content) === false) { 994 $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>'; 995 } 996 }//end if 997 998 if (empty($html) === true) { 999 if (empty($prefix) === true && $this->getConf('sidebarAlwaysShowLeft') === true) { 1000 $html = ' '; 1001 } 1002 if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix)) === true) { 1003 $html = ' '; 1004 } 1005 } 1006 1007 if (empty($html) === false) { 1008 $html = '<aside class="mikio-sidebar mikio-sidebar-' . (empty($prefix) === true ? 'left' : $prefix) . 1009 '"><a class="mikio-sidebar-toggle' . 1010 ($this->getConf('sidebarMobileDefaultCollapse') === true ? ' closed' : '') . '" href="#">' . 1011 tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="mikio-sidebar-collapse">' . 1012 $html . '</div></aside>'; 1013 } 1014 1015 if ($parse === true) { 1016 $html = $this->includeIcons($html); 1017 } 1018 if ($print === true) { 1019 echo $html; 1020 } 1021 1022 return $html; 1023 } 1024 1025 1026 /** 1027 * Print or return the page tools content 1028 * 1029 * @param boolean $print Print the generated content to the output buffer. 1030 * @param boolean $includeId Include the dw__pagetools id in the element. 1031 * @return string generated content 1032 */ 1033 public function includePageTools(bool $print = true, bool $includeId = false) 1034 { 1035 global $USERINFO; 1036 1037 $loggedIn = (is_array($USERINFO) === true && count($USERINFO) > 0); 1038 $html = ''; 1039 1040 $html .= '<nav' . ($includeId === true ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">'; 1041 $html .= '<ul class="tools">'; 1042 1043 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 1044 foreach ($items as $item) { 1045 $classes = []; 1046 $classes[] = $item->getType(); 1047 $attr = $item->getLinkAttributes(); 1048 1049 if (empty($attr['class']) === false) { 1050 $classes = array_merge($classes, explode(' ', $attr['class'])); 1051 } 1052 1053 $classes = array_unique($classes); 1054 1055 $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType())); 1056 if ( 1057 $showItem !== false && (strcasecmp($showItem, 'always') === 0 || 1058 (strcasecmp($showItem, 'logged in') === 0 && $loggedIn === true) || 1059 (strcasecmp($showItem, 'logged out') === 0 && $loggedIn === true)) 1060 ) { 1061 $html .= '<li class="' . implode(' ', $classes) . '">'; 1062 $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' . 1063 $item->getTitle() . '"><div class="icon">' . inlineSVG($item->getSvg()) . 1064 '</div><span class="a11y">' . $item->getLabel() . '</span></a>'; 1065 $html .= '</li>'; 1066 } 1067 }//end foreach 1068 1069 $html .= '</ul>'; 1070 $html .= '</nav>'; 1071 1072 if ($print === true) { 1073 echo $html; 1074 } 1075 return $html; 1076 } 1077 1078 1079 /** 1080 * Print or return the search bar 1081 * 1082 * @param boolean $print Print content. 1083 * @return string contents of the search bar 1084 */ 1085 public function includeSearch(bool $print = true) 1086 { 1087 global $lang, $ID, $ACT, $QUERY; 1088 $html = ''; 1089 1090 $html .= '<form class="mikio-search search" action="' . wl() . 1091 '" accept-charset="utf-8" method="get" role="search">'; 1092 $html .= '<input type="hidden" name="do" value="search">'; 1093 $html .= '<input type="hidden" name="id" value="' . $ID . '">'; 1094 $html .= '<input name="q" '; 1095 if ($this->getConf('searchUseTypeahead') === true) { 1096 $html .= 'class="search_typeahead" '; 1097 } 1098 $html .= 'autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . 1099 ((strcasecmp($ACT, 'search') === 0) ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 1100 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 1101 if (strcasecmp($this->getConf('searchButton'), 'icon') === 0) { 1102 $html .= $this->mikioInlineIcon('search'); 1103 } else { 1104 $html .= $lang['btn_search']; 1105 } 1106 $html .= '</button>'; 1107 $html .= '</form>'; 1108 1109 if ($print === true) { 1110 echo $html; 1111 } 1112 return $html; 1113 } 1114 1115 1116 /** 1117 * Print or return content 1118 * 1119 * @param boolean $print Print content. 1120 * @return string contents 1121 */ 1122 public function includeContent(bool $print = true) 1123 { 1124 ob_start(); 1125 tpl_content(false); 1126 $html = ob_get_contents(); 1127 ob_end_clean(); 1128 1129 $html = $this->includeIcons($html); 1130 $html = $this->parseContent($html); 1131 1132 $html .= '<div style="clear:both"></div>'; 1133 1134 if ($this->getConf('heroTitle') === false) { 1135 $html = '<div class="mikio-tags"></div>' . $html; 1136 } 1137 1138 $html = '<div class="mikio-article-content">' . $html . '</div>'; 1139 1140 if ($print === true) { 1141 echo $html; 1142 } 1143 return $html; 1144 } 1145 1146 /** 1147 * Print or return footer 1148 * 1149 * @param boolean $print Print footer. 1150 * @return string HTML string containing footer 1151 */ 1152 public function includeFooter(bool $print = true) 1153 { 1154 global $ACT; 1155 1156 $html = ''; 1157 1158 $html .= '<footer class="mikio-footer">'; 1159 $html .= '<div class="doc">' . tpl_pageinfo(true) . '</div>'; 1160 $html .= $this->includePage('footer', false); 1161 1162 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 1163 1164 if ($this->getConf('footerSearch') === true) { 1165 $html .= '<div class="mikio-footer-search">'; 1166 $html .= $this->includeSearch(false); 1167 $html .= '</div>'; 1168 } 1169 1170 $showPageTools = $this->getConf('pageToolsFooter'); 1171 if ( 1172 strcasecmp($ACT, 'show') === 0 && (strcasecmp($showPageTools, 'always') === 0 || 1173 $this->userCanEdit() === true && strcasecmp($showPageTools, 'page editors') === 0) 1174 ) { 1175 $html .= $this->includePageTools(false); 1176 } 1177 1178 $meta['licenseType'] = ['multichoice', '_choices' => ['none', 'badge', 'button']]; 1179 $meta['licenseImageOnly'] = ['onoff']; 1180 1181 $licenseType = $this->getConf('licenseType'); 1182 if ($licenseType !== 'none') { 1183 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), true, true); 1184 } 1185 1186 $html .= '</footer>'; 1187 1188 if ($print === true) { 1189 echo $html; 1190 } 1191 return $html; 1192 } 1193 1194 1195 /** 1196 * Print or return breadcrumb trail 1197 * 1198 * @param boolean $print Print out trail. 1199 * @param boolean $parse Parse trail before printing. 1200 * @return string HTML string containing breadcrumbs 1201 */ 1202 public function includeBreadcrumbs(bool $print = true, bool $parse = true) 1203 { 1204 global $conf, $ID, $lang, $ACT; 1205 1206 if ( 1207 $this->getConf('breadcrumbHideHome') === true && strcasecmp($ID, 'start') === 0 && 1208 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['breadcrumbs'] === 0 1209 ) { 1210 return ''; 1211 } 1212 1213 $html = '<div class="mikio-breadcrumbs">'; 1214 $html .= '<div class="mikio-container">'; 1215 if (strcasecmp($ACT, 'show') === 0) { 1216 if ($conf['breadcrumbs'] !== 0) { 1217 if ($this->getConf('breadcrumbPrefix') === false && $this->getConf('breadcrumbSep') === false) { 1218 ob_start(); 1219 tpl_breadcrumbs(); 1220 $html .= ob_get_contents(); 1221 ob_end_clean(); 1222 } else { 1223 $sep = '•'; 1224 $prefix = $lang['breadcrumb']; 1225 1226 if ($this->getConf('breadcrumbSep') === true) { 1227 $sep = $this->getConf('breadcrumbSepText'); 1228 $img = $this->getMediaFile('breadcrumb-sep', false); 1229 1230 if ($img !== false) { 1231 $sep = '<img src="' . $img . '">'; 1232 } 1233 } 1234 1235 if ($this->getConf('breadcrumbPrefix') === true) { 1236 $prefix = $this->getConf('breadcrumbPrefixText'); 1237 $img = $this->getMediaFile('breadcrumb-prefix', false); 1238 1239 if ($img !== false) { 1240 $prefix = '<img src="' . $img . '">'; 1241 } 1242 } 1243 1244 $crumbs = breadcrumbs(); 1245 1246 $html .= '<ul>'; 1247 if (empty($prefix) === false) { 1248 $html .= '<li class="prefix">' . $prefix . '</li>'; 1249 } 1250 1251 $last = count($crumbs); 1252 $i = 0; 1253 foreach ($crumbs as $id => $name) { 1254 $i++; 1255 if ($i !== 1) { 1256 $html .= '<li class="sep">' . $sep . '</li>'; 1257 } 1258 $html .= '<li' . ($i === $last ? ' class="curid"' : '') . '>'; 1259 $html .= tpl_pagelink($id, null, true); 1260 $html .= '</li>'; 1261 } 1262 1263 $html .= '</ul>'; 1264 }//end if 1265 }//end if 1266 }//end if 1267 1268 $html .= '</div>'; 1269 $html .= '</div>'; 1270 1271 if ($parse === true) { 1272 $html = $this->includeIcons($html); 1273 } 1274 if ($print === true) { 1275 echo $html; 1276 } 1277 return $html; 1278 } 1279 1280 /** 1281 * Print or return you are here trail 1282 * 1283 * @param boolean $print Print out trail. 1284 * @param boolean $parse Parse trail before printing. 1285 * @return string HTML string containing breadcrumbs 1286 */ 1287 public function includeYouAreHere(bool $print = true, bool $parse = true) 1288 { 1289 global $conf, $ID, $lang, $ACT; 1290 1291 if ( 1292 $this->getConf('youarehereHideHome') === true && strcasecmp($ID, 'start') === 0 && 1293 strcasecmp($ACT, 'show') === 0 || strcasecmp($ACT, 'showtag') === 0 || $conf['youarehere'] === 0 1294 ) { 1295 return ''; 1296 } 1297 1298 $html = '<div class="mikio-youarehere">'; 1299 $html .= '<div class="mikio-container">'; 1300 if (strcasecmp($ACT, 'show') === 0) { 1301 if ($conf['youarehere'] !== 0) { 1302 if ($this->getConf('youareherePrefix') === false && $this->getConf('youarehereSep') === false) { 1303 $html .= '<div class="mikio-bcdw">'; 1304 ob_start(); 1305 tpl_youarehere(); 1306 $html .= ob_get_contents(); 1307 ob_end_clean(); 1308 $html .= '</div>'; 1309 } else { 1310 $sep = ' » '; 1311 $prefix = $lang['youarehere']; 1312 1313 if ($this->getConf('youarehereSep') === true) { 1314 $sep = $this->getConf('youarehereSepText'); 1315 $img = $this->getMediaFile('youarehere-sep', false); 1316 1317 if ($img !== false) { 1318 $sep = '<img src="' . $img . '">'; 1319 } 1320 } 1321 1322 if ($this->getConf('youareherePrefix') === true) { 1323 $prefix = $this->getConf('youareherePrefixText'); 1324 $img = $this->getMediaFile('youarehere-prefix', false); 1325 1326 if ($img !== false) { 1327 $prefix = '<img src="' . $img . '">'; 1328 } 1329 } 1330 1331 $html .= '<ul>'; 1332 if (empty($prefix) === false) { 1333 $html .= '<li class="prefix">' . $prefix . '</li>'; 1334 } 1335 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], null, true) . '</li>'; 1336 1337 $parts = explode(':', $ID); 1338 $count = count($parts); 1339 1340 $part = ''; 1341 for ($i = 0; $i < ($count - 1); $i++) { 1342 $part .= $parts[$i] . ':'; 1343 $page = $part; 1344 if ($page === $conf['start']) { 1345 continue; 1346 } 1347 1348 $html .= '<li class="sep">' . $sep . '</li>'; 1349 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1350 } 1351 1352 resolve_pageid('', $page, $exists); 1353 if ((isset($page) === true && $page === $part . $parts[$i]) === false) { 1354 $page = $part . $parts[$i]; 1355 if ($page !== $conf['start']) { 1356 $html .= '<li class="sep">' . $sep . '</li>'; 1357 $html .= '<li>' . tpl_pagelink($page, null, true) . '</li>'; 1358 } 1359 } 1360 1361 $html .= '</ul>'; 1362 }//end if 1363 }//end if 1364 1365 $showLast = $this->getConf('youarehereShowLast'); 1366 if ($showLast !== 0) { 1367 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1368 if (count($matches) > 0 && count($matches[0]) > (($showLast * 2) + 2)) { 1369 $count = count($matches[0]); 1370 $list = ''; 1371 1372 // Show Home 1373 $list .= $matches[0][0] . $matches[0][1]; 1374 1375 $list .= '<li>...</li>'; 1376 for ($i = ($count - ($showLast * 2)); $i <= $count; $i++) { 1377 $list .= $matches[0][$i]; 1378 } 1379 1380 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1381 } 1382 } 1383 1384 switch ($this->getConf('youarehereHome')) { 1385 case 'none': 1386 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1387 break; 1388 case 'home': 1389 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1390 break; 1391 case 'icon': 1392 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . 1393 $this->mikioInlineIcon('home') . '$3', $html, 1); 1394 break; 1395 } 1396 } else { 1397 $html .= '≪ '; 1398 if (isset($_GET['page']) === true) { 1399 $html .= '<a href="' . wl($ID, ['do' => $ACT]) . '">Back</a> / '; 1400 } 1401 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1402 }//end if 1403 1404 $html .= '</div>'; 1405 $html .= '</div>'; 1406 1407 if ($parse === true) { 1408 $html = $this->includeIcons($html); 1409 } 1410 if ($print === true) { 1411 echo $html; 1412 } 1413 return $html; 1414 } 1415 1416 /** 1417 * Get Page Title 1418 * 1419 * @return string page title 1420 */ 1421 public function parsePageTitle() 1422 { 1423 global $ID; 1424 1425 $title = p_get_first_heading($ID); 1426 if (strlen($title) <= 0) { 1427 $title = tpl_pagetitle(null, true); 1428 } 1429 $title = $this->includeIcons($title); 1430 1431 return $title; 1432 } 1433 1434 1435 /** 1436 * Print or return hero block 1437 * 1438 * @param boolean $print Print content. 1439 * @return string contents of hero 1440 */ 1441 public function includeHero(bool $print = true) 1442 { 1443 $html = ''; 1444 1445 if ($this->getConf('heroTitle') === true) { 1446 $html .= '<div class="mikio-hero">'; 1447 $html .= '<div class="mikio-container">'; 1448 $html .= '<div class="mikio-hero-text">'; 1449 if (strcasecmp($this->getConf('youareherePosition'), 'hero') === 0) { 1450 $html .= $this->includeYouAreHere(false); 1451 } 1452 if (strcasecmp($this->getConf('breadcrumbPosition'), 'hero') === 0) { 1453 $html .= $this->includeBreadcrumbs(false); 1454 } 1455 1456 $html .= '<h1 class="mikio-hero-title">'; 1457 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1458 $html .= '</h1>'; 1459 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1460 $html .= '</div>'; 1461 1462 $hero_image = $this->getMediaFile('hero', true, $this->getConf('heroImagePropagation', true)); 1463 $hero_image_resize_class = ''; 1464 if (empty($hero_image) === false) { 1465 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1466 $hero_image_resize_class = ' mikio-hero-image-resize'; 1467 } 1468 1469 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . 1470 '><div class="mikio-tags"></div></div>'; 1471 1472 $html .= '</div>'; 1473 $html .= '</div>'; 1474 }//end if 1475 1476 if ($print === true) { 1477 echo $html; 1478 } 1479 1480 return $html; 1481 } 1482 1483 1484 /** 1485 * Print or return out TOC 1486 * 1487 * @param boolean $print Print TOC. 1488 * @param boolean $parse Parse icons. 1489 * @return string contents of TOC 1490 */ 1491 public function includeTOC(bool $print = true, bool $parse = true) 1492 { 1493 $html = ''; 1494 1495 $tocHtml = tpl_toc(true); 1496 1497 if (empty($tocHtml) === false) { 1498 $tocHtml = preg_replace( 1499 '/(<h3.+?toggle.+?>)(.+?)<\/h3>/', 1500 '$1' . 1501 $this->mikioInlineIcon('hamburger', 'hamburger') . '$2' . 1502 $this->mikioInlineIcon('down-arrow', 'down-arrow') . '</h3>', 1503 $tocHtml 1504 ); 1505 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1506 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1507 1508 $html .= '<div class="mikio-toc">'; 1509 $html .= $tocHtml; 1510 $html .= '</div>'; 1511 } 1512 1513 if ($parse === true) { 1514 $html = $this->includeIcons($html); 1515 } 1516 1517 if ($print === true) { 1518 echo $html; 1519 } 1520 1521 return $html; 1522 } 1523 1524 1525 /** 1526 * Parse the string and replace icon elements with included icon libraries 1527 * 1528 * @param string $str Content to parse. 1529 * @return string parsed string 1530 */ 1531 public function includeIcons(string $str) 1532 { 1533 global $ACT, $MIKIO_ICONS; 1534 1535 $iconTag = $this->getConf('iconTag', 'icon'); 1536 if (empty($iconTag) === true) { 1537 return $str; 1538 } 1539 1540 if ( 1541 in_array($ACT, ['show', 'showtag', 'revisions', 'index', 'preview']) === true || 1542 strcasecmp($ACT, 'admin') === 0 && count($MIKIO_ICONS) > 0 1543 ) { 1544 $content = $str; 1545 $preview = null; 1546 1547 if (strcasecmp($ACT, 'preview') === 0) { 1548 $html = new \simple_html_dom(); 1549 $html->stripRNAttrValues = false; 1550 $html->load($str, true, false); 1551 1552 $preview = $html->find('div.preview'); 1553 if (is_array($preview) === true && count($preview) > 0) { 1554 $content = $preview[0]->innertext; 1555 } 1556 } 1557 1558 $page_regex = '/(.*)/'; 1559 if (stripos($str, '<pre') !== false) { 1560 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1561 } 1562 1563 $content = preg_replace_callback($page_regex, function ($icons) { 1564 $iconTag = $this->getConf('iconTag', 'icon'); 1565 1566 return preg_replace_callback( 1567 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1568 function ($matches) { 1569 global $MIKIO_ICONS; 1570 1571 $s = $matches[0]; 1572 1573 if (count($MIKIO_ICONS) > 0) { 1574 $icon = $MIKIO_ICONS[0]; 1575 1576 if (count($matches) > 1) { 1577 $e = explode(' ', $matches[1]); 1578 1579 if (count($e) > 1) { 1580 foreach ($MIKIO_ICONS as $iconItem) { 1581 if (strcasecmp($iconItem['name'], $e[0]) === 0) { 1582 $icon = $iconItem; 1583 1584 $s = $icon['insert']; 1585 for ($i = 1; $i < 9; $i++) { 1586 if (count($e) < $i || empty($e[$i]) === true) { 1587 if (isset($icon['$' . $i]) === true) { 1588 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1589 } 1590 } else { 1591 $s = str_replace('$' . $i, $e[$i], $s); 1592 } 1593 } 1594 1595 $dir = ''; 1596 if (isset($icon['dir']) === true) { 1597 $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1598 } 1599 1600 $s = str_replace('$0', $dir, $s); 1601 1602 break; 1603 }//end if 1604 }//end foreach 1605 } else { 1606 $s = str_replace('$1', $matches[1], $icon['insert']); 1607 }//end if 1608 }//end if 1609 }//end if 1610 1611 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1612 if ($count === 0) { 1613 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1614 } 1615 1616 return $s; 1617 }, 1618 $icons[0] 1619 ); 1620 }, $content); 1621 1622 if (strcasecmp($ACT, 'preview') === 0) { 1623 if (is_array($preview) === true && count($preview) > 0) { 1624 $preview[0]->innertext = $content; 1625 } 1626 1627 $str = $html->save(); 1628 $html->clear(); 1629 unset($html); 1630 } else { 1631 $str = $content; 1632 } 1633 }//end if 1634 1635 return $str; 1636 } 1637 1638 /** 1639 * Parse HTML for theme 1640 * 1641 * @param string $content HTML content to parse. 1642 * @return string Parsed content 1643 */ 1644 public function parseContent(string $content) 1645 { 1646 global $INPUT, $ACT; 1647 1648 // Add Mikio Section titles 1649 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1650 $admin_sections = [ 1651 // Section Insert Before Icon 1652 'navbar' => ['navbarUseTitleIcon', ''], 1653 'search' => ['searchButton', ''], 1654 'hero' => ['heroTitle', ''], 1655 'tags' => ['tagsConsolidate', ''], 1656 'breadcrumb' => ['breadcrumbHideHome', ''], 1657 'youarehere' => ['youarehereHideHome', ''], 1658 'sidebar' => ['sidebarShowLeft', ''], 1659 'toc' => ['tocFull', ''], 1660 'pagetools' => ['pageToolsFloating', ''], 1661 'footer' => ['footerCustomMenuText', ''], 1662 'license' => ['licenseType', ''], 1663 'acl' => ['includePageUseACL', ''], 1664 'sticky' => ['stickyTopHeader', ''], 1665 ]; 1666 1667 foreach ($admin_sections as $section => $items) { 1668 $search = $items[0]; 1669 $icon = $items[1]; 1670 1671 $content = preg_replace( 1672 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1673 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . 1674 tpl_getLang('config_' . $section) . 1675 '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . 1676 $search . '</span>', 1677 $content 1678 ); 1679 } 1680 } elseif (strcasecmp($INPUT->str('page'), 'styling') === 0) { 1681 $mikioPluginMissing = true; 1682 /* Hide plugin fields if not installed */ 1683 if (plugin_load('action', 'mikioplugin') !== null) { 1684 $mikioPluginMissing = false; 1685 } 1686 1687 $style_headers = [ 1688 ['title' => 'Base', 'starts_with' => '__text_'], 1689 ['title' => 'Code', 'starts_with' => '__code_'], 1690 ['title' => 'Controls', 'starts_with' => '__control_'], 1691 ['title' => 'Header', 'starts_with' => '__topheader_'], 1692 ['title' => 'Navbar', 'starts_with' => '__navbar_'], 1693 ['title' => 'Sub Navbar', 'starts_with' => '__subnavbar_'], 1694 ['title' => 'Tags', 'starts_with' => '__tag_background_color_'], 1695 ['title' => 'Breadcrumbs', 'starts_with' => '__breadcrumb_'], 1696 ['title' => 'Hero', 'starts_with' => '__hero_'], 1697 ['title' => 'Sidebar', 'starts_with' => '__sidebar_'], 1698 ['title' => 'Content', 'starts_with' => '__content_'], 1699 ['title' => 'TOC', 'starts_with' => '__toc_'], 1700 ['title' => 'Page Tools', 'starts_with' => '__pagetools_'], 1701 ['title' => 'Footer', 'starts_with' => '__footer_'], 1702 ['title' => 'Table', 'starts_with' => '__table_'], 1703 ['title' => 'Dropdown', 'starts_with' => '__dropdown_'], 1704 ['title' => 'Section Edit', 'starts_with' => '__section_edit_'], 1705 ['title' => 'Tree', 'starts_with' => '__tree_'], 1706 ['title' => 'Tabs', 'starts_with' => '__tab_'], 1707 ['title' => 'Mikio Plugin', 'starts_with' => '__plugin_', 'heading' => 'h2', 1708 'hidden' => $mikioPluginMissing 1709 ], 1710 ['title' => 'Primary Colours', 'starts_with' => '__plugin_primary_', 'hidden' => $mikioPluginMissing], 1711 ['title' => 'Secondary Colours', 'starts_with' => '__plugin_secondary_', 1712 'hidden' => $mikioPluginMissing 1713 ], 1714 ['title' => 'Success Colours', 'starts_with' => '__plugin_success_', 'hidden' => $mikioPluginMissing], 1715 ['title' => 'Danger Colours', 'starts_with' => '__plugin_danger_', 'hidden' => $mikioPluginMissing], 1716 ['title' => 'Warning Colours', 'starts_with' => '__plugin_warning_', 'hidden' => $mikioPluginMissing], 1717 ['title' => 'Info Colours', 'starts_with' => '__plugin_info_', 'hidden' => $mikioPluginMissing], 1718 ['title' => 'Light Colours', 'starts_with' => '__plugin_light_', 'hidden' => $mikioPluginMissing], 1719 ['title' => 'Dark Colours', 'starts_with' => '__plugin_dark_', 'hidden' => $mikioPluginMissing], 1720 ['title' => 'Link Colours', 'starts_with' => '__plugin_link_', 'hidden' => $mikioPluginMissing], 1721 ['title' => 'Carousel', 'starts_with' => '__plugin_carousel_', 'hidden' => $mikioPluginMissing], 1722 ['title' => 'Steps', 'starts_with' => '__plugin_steps_', 'hidden' => $mikioPluginMissing], 1723 ['title' => 'Tabgroup', 'starts_with' => '__plugin_tabgroup_', 'hidden' => $mikioPluginMissing], 1724 ['title' => 'Tooltip', 'starts_with' => '__plugin_tooltip_', 'hidden' => $mikioPluginMissing], 1725 ['title' => 'Dark Mode', 'starts_with' => '__darkmode_', 'heading' => 'h2'], 1726 ['title' => 'Base', 'starts_with' => '__darkmode_text_'], 1727 ['title' => 'Code', 'starts_with' => '__darkmode_code_'], 1728 ['title' => 'Controls', 'starts_with' => '__darkmode_control_'], 1729 ['title' => 'Header', 'starts_with' => '__darkmode_topheader_'], 1730 ['title' => 'Navbar', 'starts_with' => '__darkmode_navbar_'], 1731 ['title' => 'Sub Navbar', 'starts_with' => '__darkmode_subnavbar_'], 1732 ['title' => 'Tags', 'starts_with' => '__darkmode_tag_background_color_'], 1733 ['title' => 'Breadcrumbs', 'starts_with' => '__darkmode_breadcrumb_'], 1734 ['title' => 'Hero', 'starts_with' => '__darkmode_hero_'], 1735 ['title' => 'Sidebar', 'starts_with' => '__darkmode_sidebar_'], 1736 ['title' => 'Content', 'starts_with' => '__darkmode_content_'], 1737 ['title' => 'TOC', 'starts_with' => '__darkmode_toc_'], 1738 ['title' => 'Page Tools', 'starts_with' => '__darkmode_pagetools_'], 1739 ['title' => 'Footer', 'starts_with' => '__darkmode_footer_'], 1740 ['title' => 'Table', 'starts_with' => '__darkmode_table_'], 1741 ['title' => 'Dropdown', 'starts_with' => '__darkmode_dropdown_'], 1742 ['title' => 'Section Edit', 'starts_with' => '__darkmode_section_edit_'], 1743 ['title' => 'Tree', 'starts_with' => '__darkmode_tree_'], 1744 ['title' => 'Tabs', 'starts_with' => '__darkmode_tab_'], 1745 ['title' => 'Mikio Plugin (Dark mode)', 'starts_with' => '__plugin_darkmode_', 'heading' => 'h2', 1746 'hidden' => $mikioPluginMissing 1747 ], 1748 ['title' => 'Primary Colours', 'starts_with' => '__plugin_darkmode_primary_', 1749 'hidden' => $mikioPluginMissing 1750 ], 1751 ['title' => 'Secondary Colours', 'starts_with' => '__plugin_darkmode_secondary_', 1752 'hidden' => $mikioPluginMissing 1753 ], 1754 ['title' => 'Success Colours', 'starts_with' => '__plugin_darkmode_success_', 1755 'hidden' => $mikioPluginMissing 1756 ], 1757 ['title' => 'Danger Colours', 'starts_with' => '__plugin_darkmode_danger_', 1758 'hidden' => $mikioPluginMissing 1759 ], 1760 ['title' => 'Warning Colours', 'starts_with' => '__plugin_darkmode_warning_', 1761 'hidden' => $mikioPluginMissing 1762 ], 1763 ['title' => 'Info Colours', 'starts_with' => '__plugin_darkmode_info_', 1764 'hidden' => $mikioPluginMissing 1765 ], 1766 ['title' => 'Light Colours', 'starts_with' => '__plugin_darkmode_light_', 1767 'hidden' => $mikioPluginMissing 1768 ], 1769 ['title' => 'Dark Colours', 'starts_with' => '__plugin_darkmode_dark_', 1770 'hidden' => $mikioPluginMissing 1771 ], 1772 ['title' => 'Link Colours', 'starts_with' => '__plugin_darkmode_link_', 1773 'hidden' => $mikioPluginMissing 1774 ], 1775 ['title' => 'Carousel', 'starts_with' => '__plugin_darkmode_carousel_', 1776 'hidden' => $mikioPluginMissing 1777 ], 1778 ['title' => 'Steps', 'starts_with' => '__plugin_darkmode_steps_', 'hidden' => $mikioPluginMissing], 1779 ['title' => 'Tabgroup', 'starts_with' => '__plugin_darkmode_tabgroup_', 1780 'hidden' => $mikioPluginMissing 1781 ], 1782 ['title' => 'Tooltip', 'starts_with' => '__plugin_darkmode_tooltip_', 'hidden' => $mikioPluginMissing], 1783 ]; 1784 1785 foreach ($style_headers as $header) { 1786 if (array_key_exists('heading', $header) === false) { 1787 $header['heading'] = 'h3'; 1788 } 1789 1790 if (array_key_exists('hidden', $header) === false) { 1791 $header['hidden'] = false; 1792 } 1793 1794 $content = preg_replace( 1795 '/(<tr>\s*<td>\s*<label for="tpl__' . $header['starts_with'] . '.+?<\/tr>)/s', 1796 '</tbody></table><' . $header['heading'] . ' style="display:' . 1797 ($header['hidden'] === true ? 'none' : 'block') . '">' . 1798 $header['title'] . '</' . $header['heading'] . '> 1799 <table style="display:' . ($header['hidden'] === true ? 'none' : 'table') . '"><tbody>$1', 1800 $content, 1801 1 1802 ); 1803 } 1804 1805 $content = preg_replace('/type="color"/', 'type="text"', $content); 1806 }//end if 1807 1808 if (strcasecmp($ACT, 'admin') === 0 && isset($_GET['page']) === false) { 1809 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1810 } 1811 1812 // Page Revisions - Table Fix 1813 if (strpos($content, 'id="page__revisions"') !== false) { 1814 $content = preg_replace( 1815 '/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', 1816 '<span>$1</span>', 1817 $content 1818 ); 1819 } 1820 1821 $html = new \simple_html_dom(); 1822 $html->stripRNAttrValues = false; 1823 $html->load($content, true, false); 1824 1825 if ($html === false) { 1826 return $content; 1827 } 1828 1829 /* Buttons */ 1830 foreach ($html->find('#config__manager button') as $node) { 1831 $c = explode(' ', $node->class); 1832 if (in_array('mikio-button', $c) === false) { 1833 $c[] = 'mikio-button'; 1834 } 1835 $node->class = implode(' ', $c); 1836 } 1837 1838 1839 /* Buttons - Primary */ 1840 foreach ($html->find('#config__manager [type=submit]') as $node) { 1841 $c = explode(' ', $node->class); 1842 if (in_array('mikio-primary', $c) === false) { 1843 $c[] = 'mikio-primary'; 1844 } 1845 $node->class = implode(' ', $c); 1846 } 1847 1848 /* Hide page title if hero is enabled */ 1849 if ($this->getConf('heroTitle') === true && $ACT !== 'preview') { 1850 $pageTitle = $this->parsePageTitle(); 1851 1852 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1853 if ($elm->innertext === $pageTitle) { 1854 // $elm->innertext = ''; 1855 $elm->setAttribute('style', 'display:none'); 1856 1857 break; 1858 } 1859 } 1860 } 1861 1862 /* Hero subtitle */ 1863 foreach ($html->find('p') as $elm) { 1864 $i = stripos($elm->innertext, '~~hero-subtitle'); 1865 if ($i !== false) { 1866 $j = strpos($elm->innertext, '~~', ($i + 2)); 1867 if ($j !== false) { 1868 if ($j > ($i + 16)) { 1869 $subtitle = substr($elm->innertext, ($i + 16), ($j - $i - 16)); 1870 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1871 1872 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1873 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1874 } 1875 1876 break; 1877 } 1878 } 1879 } 1880 1881 /* Hero image */ 1882 foreach ($html->find('p') as $elm) { 1883 $image = ''; 1884 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1885 if (count($matches) > 0) { 1886 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1887 if (count($imageTagMatches) > 0) { 1888 $image = $imageTagMatches[1]; 1889 } else { 1890 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1891 if (count($imageTagMatches) > 0) { 1892 $image = $imageTagMatches[1]; 1893 } else { 1894 $image = strip_tags($matches[1]); 1895 if (stripos($image, ':') === false) { 1896 $image = str_replace(['{', '}'], '', $image); 1897 $i = stripos($image, '?'); 1898 if ($i !== false) { 1899 $image = substr($image, 0, $i); 1900 } 1901 1902 $image = ml($image, '', true, '', false); 1903 } 1904 } 1905 } 1906 1907 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 1908 1909 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1910 }//end if 1911 }//end foreach 1912 1913 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] 1914 [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1915 foreach ($html->find('p') as $elm) { 1916 $i = stripos($elm->innertext, '~~hero-colors'); 1917 if ($i !== false) { 1918 $j = strpos($elm->innertext, '~~', ($i + 2)); 1919 if ($j !== false) { 1920 if ($j > ($i + 14)) { 1921 $color = substr($elm->innertext, ($i + 14), ($j - $i - 14)); 1922 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')'; 1923 1924 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1925 } 1926 1927 break; 1928 } 1929 } 1930 } 1931 1932 /* Hide parts - ~~hide-parts [parts]~~ */ 1933 foreach ($html->find('p') as $elm) { 1934 $i = stripos($elm->innertext, '~~hide-parts'); 1935 if ($i !== false) { 1936 $j = strpos($elm->innertext, '~~', ($i + 2)); 1937 if ($j !== false) { 1938 if ($j > ($i + 13)) { 1939 $parts = explode(' ', substr($elm->innertext, ($i + 13), ($j - $i - 13))); 1940 $script = ''; 1941 1942 foreach ($parts as $part) { 1943 // $part = trim($part); 1944 if (strlen($part) > 0) { 1945 $script .= 'mikio.hidePart(\'' . $part . '\');'; 1946 } 1947 } 1948 1949 if (strlen($script) > 0) { 1950 $this->footerScript['hide-parts'] = $script; 1951 } 1952 1953 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1954 } 1955 1956 break; 1957 }//end if 1958 }//end if 1959 }//end foreach 1960 1961 1962 /* Page Tags (tag plugin) */ 1963 if ($this->getConf('tagsConsolidate') === true) { 1964 $tags = ''; 1965 foreach ($html->find('div.tags a') as $elm) { 1966 $tags .= $elm->outertext; 1967 } 1968 1969 foreach ($html->find('div.tags') as $elm) { 1970 $elm->innertext = ''; 1971 $elm->setAttribute('style', 'display:none'); 1972 } 1973 1974 if (empty($tags) === false) { 1975 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1976 } 1977 } 1978 1979 // Configuration Manager 1980 if (strcasecmp($INPUT->str('page'), 'config') === 0) { 1981 // Additional save buttons 1982 foreach ($html->find('#config__manager') as $cm) { 1983 $saveButtons = ''; 1984 1985 foreach ($cm->find('p') as $elm) { 1986 $saveButtons = $elm->outertext; 1987 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1988 $elm->outertext = ''; 1989 } 1990 1991 foreach ($cm->find('fieldset') as $elm) { 1992 $elm->innertext .= $saveButtons; 1993 } 1994 } 1995 } 1996 1997 $content = $html->save(); 1998 $html->clear(); 1999 unset($html); 2000 2001 return $content; 2002 } 2003 2004 2005 /** 2006 * Get DokuWiki namespace/page/URI as link 2007 * 2008 * @param string $str String to parse. 2009 * @return string parsed URI 2010 */ 2011 public function getLink(string $str) 2012 { 2013 $i = strpos($str, '://'); 2014 if ($i !== false) { 2015 return $str; 2016 } 2017 2018 return wl($str); 2019 } 2020 2021 2022 /** 2023 * Check if the user can edit current namespace/page 2024 * 2025 * @return boolean user can edit 2026 */ 2027 public function userCanEdit() 2028 { 2029 global $INFO; 2030 global $ID; 2031 2032 $wiki_file = wikiFN($ID); 2033 if (@file_exists($wiki_file) === false) { 2034 return true; 2035 } 2036 if ($INFO['isadmin'] === true || $INFO['ismanager'] === true) { 2037 return true; 2038 } 2039 // $meta_file = metaFN($ID, '.meta'); 2040 if ($INFO['meta']['user'] === false) { 2041 return true; 2042 } 2043 if ($INFO['client'] === $INFO['meta']['user']) { 2044 return true; 2045 } 2046 2047 return false; 2048 } 2049 2050 2051 /** 2052 * Search for and return the uri of a media file 2053 * 2054 * @param string $image Image name to search for (without extension). 2055 * @param boolean $searchCurrentNS Search the current namespace. 2056 * @param boolean $propagate Propagate search through the namespace. 2057 * @return string URI of the found media file 2058 */ 2059 public function getMediaFile(string $image, bool $searchCurrentNS = true, bool $propagate = true) 2060 { 2061 global $INFO; 2062 2063 $ext = ['png', 'jpg', 'gif', 'svg']; 2064 2065 if ($searchCurrentNS === true) { 2066 $prefix[] = ':' . $INFO['namespace'] . ':'; 2067 } 2068 if ($propagate === true) { 2069 $prefix[] = ':'; 2070 $prefix[] = ':wiki:'; 2071 } 2072 $theme = $this->getConf('customTheme'); 2073 if (empty($theme) === false) { 2074 $prefix[] = 'themes/' . $theme . '/images/'; 2075 } 2076 $prefix[] = 'images/'; 2077 2078 $search = []; 2079 foreach ($prefix as $pitem) { 2080 foreach ($ext as $eitem) { 2081 $search[] = $pitem . $image . '.' . $eitem; 2082 } 2083 } 2084 2085 $img = ''; 2086 $file = ''; 2087 $url = ''; 2088 $ismedia = false; 2089 $found = false; 2090 2091 foreach ($search as $img) { 2092 if (strcasecmp(substr($img, 0, 1), ':') === 0) { 2093 $file = mediaFN($img); 2094 $ismedia = true; 2095 } else { 2096 $file = tpl_incdir() . $img; 2097 $ismedia = false; 2098 } 2099 2100 if (file_exists($file) === true) { 2101 $found = true; 2102 break; 2103 } 2104 } 2105 2106 if ($found === false) { 2107 return false; 2108 } 2109 2110 if ($ismedia === true) { 2111 $url = ml($img, '', true, '', false); 2112 } else { 2113 $url = tpl_basedir() . $img; 2114 } 2115 2116 return $url; 2117 } 2118 2119 2120 /** 2121 * Print or return the page title 2122 * 2123 * @param string $page Page id or empty string for current page. 2124 * @return string generated content 2125 */ 2126 public function getPageTitle(string $page = '') 2127 { 2128 global $ID, $conf; 2129 2130 $html = ''; 2131 2132 if (empty($page) === true) { 2133 $page = $ID; 2134 } 2135 2136 $html = p_get_first_heading($page); 2137 $html = strip_tags($html); 2138 $html = preg_replace('/\s+/', ' ', $html); 2139 $html .= ' [' . strip_tags($conf['title']) . ']'; 2140 $html = trim($html); 2141 2142 return $html; 2143 } 2144 2145 2146 /** 2147 * Return inline theme icon 2148 * 2149 * @param string $type Icon to retreive. 2150 * @param string $class Classname to insert. 2151 * @return string HTML icon content 2152 */ 2153 public function mikioInlineIcon(string $type, string $class = "") 2154 { 2155 if (is_array($class) === true) { 2156 $class = explode(' ', $class); 2157 } 2158 2159 if (strlen($class) > 0) { 2160 $class = ' ' . $class; 2161 } 2162 2163 switch ($type) { 2164 case 'wrench': 2165 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 21661792" 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, 216719 -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, 2168-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, 2169435 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 2170131.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, 2171-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>'; 2172 case 'file': 2173 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2174viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"> 2175<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 21761280,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 2177q 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" 2178xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2179 case 'gear': 2180 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2181viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"> 2182<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 2183181,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 218410,-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 2185-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 2186147,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 2187q 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, 218871.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 2189q 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 2190-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" /> 2191</g></svg>'; 2192 case 'user': 2193 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2194viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 21951408,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 219628,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, 2197-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 219850.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 2199-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, 22001408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>'; 2201 case 'search': 2202 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2203aria-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 220418.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 220524.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 22066.195 0 0 1-6.188 6.188z"/></svg>'; 2207 case 'home': 2208 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2209viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g 2210transform="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 2211960 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 2212m 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 2213-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, 2214-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" 2215xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 2216 case 'sun': 2217 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2218style="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 22190 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 22200a.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 22211-.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 22220 0 1-.707.707z" /></svg>'; 2223 case 'moon': 2224 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2225style="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 22264.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 22271 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 22281.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 22290-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z" /></svg>'; 2230 case 'sunmoon': 2231 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" 2232style="fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10" 2233viewBox="0 0 32 32"><line x1="16" y1="3" x2="16" y2="29"/><path d="M16,23c-3.87,0-7-3.13-7-7s3.13-7,7-7"/><line 2234x1="6.81" y1="6.81" x2="8.93" y2="8.93"/><line x1="3" y1="16" x2="6" y2="16"/><line x1="6.81" y1="25.19" x2="8.93" 2235y2="23.07"/><path d="M16,12.55C17.2,10.43,19.48,9,22.09,9c0.16,0,0.31,0.01,0.47,0.02c-1.67,0.88-2.8,2.63-2.8,4.64c0,2.9, 22362.35,5.25,5.25,5.25c1.6,0,3.03-0.72,3.99-1.85C28.48,20.43,25.59,23,22.09,23c-2.61,0-4.89-1.43-6.09-3.55"/></svg>'; 2237 case 'hamburger': 2238 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" 2239style="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 224076v40c0 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 224116v40c0 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 224216v40c0 8.837 7.163 16 16 16z"/></svg>'; 2243 case 'down-arrow': 2244 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" 2245aria-hidden="true" style="fill:currentColor"><path d="M16.003 18.626l7.081-7.081L25 13.46l-8.997 8.998-9.003-9 22461.917-1.916z"/></svg>'; 2247 case 'language': 2248 return '<svg class="mikio-iicon' . $class . '" xmlns="http://www.w3.org/2000/svg" width="16" 2249height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.545 6.714 4.11 22508H3l1.862-5h1.284L8 8H6.833l-.435-1.286H4.545zm1.634-.736L5.5 3.956h-.049l-.679 2.022H6.18z"/><path d="M0 2a2 2 0 0 1 22512-2h7a2 2 0 0 1 2 2v3h3a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-3H2a2 2 0 0 1-2-2V2zm2-1a1 1 0 0 0-1 1v7a1 1 0 0 22520 1 1h7a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H2zm7.138 9.995c.193.301.402.583.63.846-.748.575-1.673 1.001-2.768 22531.292.178.217.451.635.555.867 1.125-.359 2.08-.844 2.886-1.494.777.665 1.739 1.165 2.93 22541.472.133-.254.414-.673.629-.89-1.125-.253-2.057-.694-2.82-1.284.681-.747 1.222-1.651 22551.621-2.757H14V8h-3v1.047h.765c-.318.844-.74 1.546-1.272 2.13a6.066 6.066 0 0 1-.415-.492 1.988 1.988 0 0 1-.94.31z"/> 2256</svg>'; 2257 }//end switch 2258 2259 return ''; 2260 } 2261 2262 /** 2263 * Finalize theme 2264 * 2265 * @return void 2266 */ 2267 public function finalize() 2268 { 2269 } 2270 2271 /** 2272 * Show Messages 2273 * 2274 * @return void 2275 */ 2276 public function showMessages() 2277 { 2278 global $ACT; 2279 2280 if ($this->lessIgnored === true) { 2281 msg( 2282 'useLESS is enabled on the Mikio template, however is not supported on this server', 2283 2, 2284 '', 2285 '', 2286 MSG_ADMINS_ONLY 2287 ); 2288 } 2289 2290 $show = $this->getConf('showNotifications'); 2291 if ( 2292 strlen($show) === 0 || 2293 strcasecmp($show, 'always') === 0 || 2294 (strcasecmp($show, 'admin') === 0 && strcasecmp($ACT, 'admin') === 0) 2295 ) { 2296 global $MSG, $MSG_shown; 2297 2298 if (isset($MSG) !== false) { 2299 if (isset($MSG_shown) === false) { 2300 $MSG_shown = []; 2301 } 2302 2303 foreach ($MSG as $msg) { 2304 $hash = md5($msg['msg']); 2305 if (isset($MSG_shown[$hash]) === true) { 2306 continue; 2307 } 2308 // skip double messages 2309 2310 if (info_msg_allowed($msg) === true) { 2311 echo '<div class="' . $msg['lvl'] . '">'; 2312 echo $msg['msg']; 2313 echo '</div>'; 2314 } 2315 2316 $MSG_shown[$hash] = true; 2317 } 2318 2319 unset($GLOBALS['MSG']); 2320 }//end if 2321 2322 if (strlen($this->includedPageNotifications) > 0) { 2323 echo $this->includedPageNotifications; 2324 } 2325 }//end if 2326 } 2327 2328 /** 2329 * Dokuwiki version 2330 * 2331 * @return string the dw version name 2332 */ 2333 public function dwVersion() 2334 { 2335 if (function_exists('getVersionData') === true) { 2336 $version_data = getVersionData(); 2337 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2338 $version_items = explode(' ', $version_data['date']); 2339 if (count($version_items) >= 2) { 2340 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 2341 } 2342 } 2343 } 2344 2345 return 'unknown'; 2346 } 2347 2348 /** 2349 * Dokuwiki version number 2350 * 2351 * @return string the dw version date converted to integer 2352 */ 2353 public function dwVersionNumber() 2354 { 2355 if (function_exists('getVersionData') === true) { 2356 $version_data = getVersionData(); 2357 if (is_array($version_data) === true && array_key_exists('date', $version_data) === true) { 2358 $version_items = explode(' ', $version_data['date']); 2359 if (count($version_items) >= 1) { 2360 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 2361 } 2362 } 2363 } 2364 2365 return 0; 2366 } 2367} 2368 2369global $TEMPLATE; 2370$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 2371