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