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