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