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')) die(); 14 15require_once('icons/icons.php'); 16require_once('inc/simple_html_dom.php'); 17 18class Template 19{ 20 public $tplDir = ''; 21 public $baseDir = ''; 22 public $footerScript = array(); 23 public $lessIgnored = false; 24 25 26 /** 27 * Class constructor 28 */ 29 public function __construct() 30 { 31 $this->tplDir = tpl_incdir(); 32 $this->baseDir = tpl_basedir(); 33 34 $this->_registerHooks(); 35 } 36 37 38 /** 39 * Returns the instance of the class 40 * 41 * @return Template class instance 42 */ 43 public static function getInstance() 44 { 45 static $instance = null; 46 47 if ($instance === null) { 48 $instance = new Template(); 49 } 50 51 return $instance; 52 } 53 54 55 /** 56 * Register the themes hooks into Dokuwiki 57 */ 58 private function _registerHooks() 59 { 60 global $EVENT_HANDLER; 61 62 $events_dispatcher = array( 63 'TPL_METAHEADER_OUTPUT' => 'metaheadersHandler' 64 ); 65 66 foreach ($events_dispatcher as $event => $method) { 67 $EVENT_HANDLER->register_hook($event, 'BEFORE', $this, $method); 68 } 69 } 70 71 72 /** 73 * Meta handler hook for DokuWiki 74 * 75 * @param Doku_Event $event 76 */ 77 public function metaHeadersHandler(\Doku_Event $event) 78 { 79 global $MIKIO_ICONS; 80 global $conf; 81 82 $this->includePage('theme', FALSE, TRUE); 83 84 $stylesheets = array(); 85 $scripts = array(); 86 87 if ($this->getConf('customTheme') != '') { 88 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.less')) { 89 $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.less'; 90 } else { 91 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/style.css')) { 92 $stylesheets[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/style.css'; 93 } 94 } 95 if (file_exists($this->tplDir . 'themes/' . $this->getConf('customTheme') . '/script.js')) { 96 $scripts[] = $this->baseDir . 'themes/' . $this->getConf('customTheme') . '/script.js'; 97 } 98 } 99 100 if (is_array($MIKIO_ICONS) && $this->getConf('iconTag', 'icon') != '') { 101 $icons = array(); 102 foreach ($MIKIO_ICONS as $icon) { 103 if (isset($icon['name']) && isset($icon['css']) && isset($icon['insert'])) { 104 $icons[] = $icon; 105 106 if ($icon['css'] != '') { 107 if (strpos($icon['css'], '//') === FALSE) { 108 $stylesheets[] = $this->baseDir . 'icons/' . $icon['css']; 109 } else { 110 $stylesheets[] = $icon['css']; 111 } 112 } 113 } 114 } 115 $MIKIO_ICONS = $icons; 116 } else { 117 $MIKIO_ICONS = []; 118 } 119 120 $scripts[] = $this->baseDir . 'assets/mikio-typeahead.js'; 121 $scripts[] = $this->baseDir . 'assets/mikio.js'; 122 123 if ($this->getConf('useLESS')) { 124 $stylesheets[] = $this->baseDir . 'assets/mikio.less'; 125 } else { 126 $stylesheets[] = $this->baseDir . 'assets/mikio.css'; 127 } 128 129 130 $set = []; 131 foreach ($stylesheets as $style) { 132 if (in_array($style, $set) == FALSE) { 133 if (strtolower(substr($style, -5)) == '.less' && $this->getConf('useLESS')) { 134 $style = $this->baseDir . 'css.php?css=' . str_replace($this->baseDir, '', $style); 135 } 136 137 array_unshift($event->data['link'], array( 138 'type' => 'text/css', 139 'rel' => 'stylesheet', 140 'href' => $style 141 )); 142 } 143 $set[] = $style; 144 } 145 146 $set = []; 147 foreach ($scripts as $script) { 148 if (in_array($script, $set) == FALSE) { 149 $script_params = array( 150 'type' => 'text/javascript', 151 '_data' => '', 152 'src' => $script 153 ); 154 155 // equal to or greator than hogfather 156 if($this->dwVersionNumber() >= 20200729) { 157 // greator than hogfather - defer always on 158 if($this->dwVersionNumber() >= 20200729) { 159 $script_params += ['defer' => 'defer']; 160 } else { 161 // hogfather - defer always on unless $conf['defer_js'] is false 162 if(!array_key_exists('defer_js', $conf) || $conf['defer_js']) { 163 $script_params += ['defer' => 'defer']; 164 } 165 } 166 } 167 168 $event->data['script'][] = $script_params; 169 } 170 $set[] = $script; 171 } 172 } 173 174 175 /** 176 * Print or return the footer meta data 177 * 178 * @param boolean $print print the data to buffer 179 */ 180 public function includeFooterMeta($print = TRUE) 181 { 182 $html = ''; 183 184 if (count($this->footerScript) > 0) { 185 $html .= '<script type="text/javascript">function mikioFooterRun() {'; 186 foreach ($this->footerScript as $script) { 187 $html .= $script . ';'; 188 } 189 $html .= '}</script>'; 190 } 191 192 193 if ($print) echo $html; 194 return $html; 195 } 196 197 /** 198 * Retreive and parse theme configuration options 199 * 200 * @param string $key the configuration key to retreive 201 * @param mixed $default if key doesn't exist, return this value 202 * @return mixed parsed value of configuration 203 */ 204 public function getConf($key, $default = FALSE) 205 { 206 $value = tpl_getConf($key, $default); 207 208 switch ($key) { 209 case 'navbarDWMenuType': 210 $value = strtolower($value); 211 if ($value != 'icons' && $value != 'text' && $value != 'both') $value = 'both'; 212 break; 213 case 'navbarDWMenuCombine': 214 $value = strtolower($value); 215 if ($value != 'seperate' && $value != 'dropdown' && $value != 'combine') $value = 'combine'; 216 break; 217 case 'navbarPosLeft': 218 case 'navbarPosMiddle': 219 case 'navbarPosRight': 220 $value = strtolower($value); 221 if ($value != 'none' && $value != 'custom' && $value != 'search' && $value != 'dokuwiki') { 222 if ($key == 'navbarPosLeft') $value = 'none'; 223 if ($key == 'navbarPosMiddle') $value = 'search'; 224 if ($key == 'navbarPosRight') $value = 'dokuwiki'; 225 } 226 break; 227 case 'navbarItemShowCreate': 228 case 'navbarItemShowShow': 229 case 'navbarItemShowRevs': 230 case 'navbarItemShowBacklink': 231 case 'navbarItemShowRecent': 232 case 'navbarItemShowMedia': 233 case 'navbarItemShowIndex': 234 case 'navbarItemShowProfile': 235 case 'navbarItemShowAdmin': 236 $value = strtolower($value); 237 if ($value != 'always' && $value != 'logged in' && $value != 'logged out' && $value != 'never') { 238 $value = 'always'; 239 } 240 break; 241 case 'navbarItemShowLogin': 242 case 'navbarItemShowLogout': 243 $value = strtolower($value); 244 if ($value != 'always' && $value != 'never') { 245 $value = 'always'; 246 } 247 break; 248 case 'searchButton': 249 $value = strtolower($value); 250 if ($value != 'icon' && $value != 'text') $value = 'icon'; 251 break; 252 case 'searchButton': 253 $value = strtolower($value); 254 if ($value != 'icon' && $value != 'text') $value = 'icon'; 255 break; 256 case 'breadcrumbPosition': 257 $value = strtolower($value); 258 if ($value != 'none' && $value != 'top' && $value != 'hero' && $value != 'page') $value = 'top'; 259 break; 260 case 'youareherePosition': 261 $value = strtolower($value); 262 if ($value != 'none' && $value != 'top' && $value != 'hero' && $value != 'page') $value = 'top'; 263 break; 264 case 'youarehereHome': 265 $value = strtolower($value); 266 if ($value != 'none' && $value != 'page title' && $value != 'home' && $value != 'icon') $value = 'page title'; 267 break; 268 case 'sidebarLeftRow1': 269 case 'sidebarLeftRow2': 270 case 'sidebarLeftRow3': 271 case 'sidebarLeftRow4': 272 $value = strtolower($value); 273 if ($value != 'none' && $value != 'logged in user' && $value != 'search' && $value != 'content' && $value != 'tags') { 274 if ($key == 'sidebarLeftRow1') $value = 'logged in user'; 275 if ($key == 'sidebarLeftRow2') $value = 'search'; 276 if ($key == 'sidebarLeftRow3') $value = 'content'; 277 if ($key == 'sidebarLeftRow4') $value = 'none'; 278 } 279 break; 280 case 'pageToolsFloating': 281 case 'pageToolsFooter': 282 $value = strtolower($value); 283 if ($value != 'none' && $value != 'page editors' && $value != 'always') { 284 if ($key == 'pageToolsFloating') $value = 'always'; 285 if ($key == 'pageToolsFooter') $value = 'always'; 286 } 287 break; 288 case 'pageToolsShowCreate': 289 case 'pageToolsShowEdit': 290 case 'pageToolsShowRevs': 291 case 'pageToolsShowBacklink': 292 case 'pageToolsShowTop': 293 $value = strtolower($value); 294 if ($value != 'always' && $value != 'logged in' && $value != 'logged out' && $value != 'never') { 295 $value = 'always'; 296 } 297 break; 298 case 'showNotifications': 299 $value = strtolower($value); 300 if ($value != 'none' && $value != 'admin' && $value != 'always') $value = 'admin'; 301 break; 302 case 'licenseType': 303 $value = strtolower($value); 304 if ($value != 'none' && $value != 'badge' && $value != 'buttom') $value = 'badge'; 305 break; 306 case 'navbarUseTitleIcon': 307 case 'navbarUseTitleText': 308 case 'navbarUseTaglineText': 309 case 'navbarShowSub': 310 case 'heroTitle': 311 case 'heroImagePropagation': 312 case 'breadcrumbPrefix': 313 case 'breadcrumbSep': 314 case 'youareherePrefix': 315 case 'youarehereSep': 316 case 'sidebarShowLeft': 317 case 'sidebarShowRight': 318 case 'tocFull': 319 case 'footerSearch': 320 case 'licenseImageOnly': 321 case 'includePageUseACL': 322 case 'includePagePropagate': 323 case 'youarehereHideHome': 324 case 'tagsConsolidate': 325 case 'footerInPage': 326 case 'sidebarMobileDefaultCollapse': 327 case 'sidebarAlwaysShowLeft': 328 case 'sidebarAlwaysShowRight': 329 $value = (bool)$value; 330 break; 331 case 'youarehereShowLast': 332 $value = (int)$value; 333 break; 334 case 'iconTag': 335 case 'customTheme': 336 case 'navbarCustomMenuText': 337 case 'breadcrumbPrefixText': 338 case 'breadcrumbSepText': 339 case 'youareherePrefixText': 340 case 'youarehereSepText': 341 case 'footerCustomMenuText': 342 break; 343 case 'useLESS': 344 $value = (bool)$value; 345 $lessAvailable = true; 346 347 // check for less library 348 $lesscLib = '../../../vendor/marcusschwarz/lesserphp/lessc.inc.php'; 349 if (!file_exists($lesscLib)) 350 $lesscLib = $_SERVER['DOCUMENT_ROOT'] . '/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 351 if (!file_exists($lesscLib)) 352 $lesscLib = '../../../../../app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 353 if (!file_exists($lesscLib)) 354 $lesscLib = $_SERVER['DOCUMENT_ROOT'] . '/app/dokuwiki/vendor/marcusschwarz/lesserphp/lessc.inc.php'; 355 if (!file_exists($lesscLib)) { 356 $lessAvailable = false; 357 } 358 359 // check for ctype extensions 360 if (!function_exists('ctype_digit')) { 361 $lessAvailable = false; 362 } 363 364 if ($value && !$lessAvailable) { 365 $this->lessIgnored = true; 366 $value = false; 367 } 368 break; 369 } 370 371 return $value; 372 } 373 374 375 /** 376 * Check if a page exist in directory or namespace 377 * 378 * @param string $page page/namespace to search 379 * @return boolean if page exists 380 */ 381 public function pageExists($page) 382 { 383 ob_start(); 384 tpl_includeFile($page . '.html'); 385 $html = ob_get_contents(); 386 ob_end_clean(); 387 388 if ($html != '') return TRUE; 389 390 $useACL = $this->getConf('includePageUseACL'); 391 $propagate = $this->getConf('includePagePropagate'); 392 393 if ($propagate) { 394 if (page_findnearest($page, $useACL)) return TRUE; 395 } elseif ($useACL && auth_quickaclcheck($page) != AUTH_NONE) { 396 return TRUE; 397 } 398 399 return FALSE; 400 } 401 402 403 /** 404 * Print or return page from directory or namespace 405 * 406 * @param string $page page/namespace to include 407 * @param boolean $print print content 408 * @param boolean $parse parse content before printing/returning 409 * @param string $classWrapper wrap page in a div with class 410 * @return string contents of page found 411 */ 412 public function includePage($page, $print = TRUE, $parse = TRUE, $classWrapper = '') 413 { 414 ob_start(); 415 tpl_includeFile($page . '.html'); 416 $html = ob_get_contents(); 417 ob_end_clean(); 418 419 if ($html == '') { 420 $useACL = $this->getConf('includePageUseACL'); 421 $propagate = $this->getConf('includePagePropagate'); 422 $html = ''; 423 424 $html = tpl_include_page($page, false, $propagate, $useACL); 425 } 426 427 if ($html != '' && $parse) { 428 $html = $this->parseContent($html); 429 } 430 431 if ($classWrapper != '' && $html != '') $html = '<div class="' . $classWrapper . '">' . $html . '</div>'; 432 433 if ($print) echo $html; 434 return $html; 435 } 436 437 438 /** 439 * Print or return logged in user information 440 * 441 * @param boolean $print print content 442 * @return string user information 443 */ 444 public function includeLoggedIn($print = TRUE) 445 { 446 $html = ''; 447 448 if (!empty($_SERVER['REMOTE_USER'])) { 449 $html .= '<div class="mikio-user-info">'; 450 ob_start(); 451 tpl_userinfo(); 452 $html .= ob_get_contents(); 453 ob_end_clean(); 454 $html .= '</div>'; 455 } 456 457 if ($print) echo $html; 458 return $html; 459 } 460 461 462 /** 463 * Print or return DokuWiki Menu 464 * 465 * @param boolean $print print content 466 * @return string contents of the menu 467 */ 468 public function includeDWMenu($print = TRUE) 469 { 470 global $lang; 471 global $USERINFO; 472 473 $loggedIn = (is_array($USERINFO) && count($USERINFO) > 0); 474 $html = '<ul class="mikio-nav">'; 475 476 $pageToolsMenu = []; 477 $siteToolsMenu = []; 478 $userToolsMenu = []; 479 480 $showIcons = ($this->getConf('navbarDWMenuType') != 'text'); 481 $showText = ($this->getConf('navbarDWMenuType') != 'icons'); 482 $isDropDown = ($this->getConf('navbarDWMenuCombine') != 'seperate'); 483 484 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 485 foreach ($items as $item) { 486 if ($item->getType() != 'top') { 487 $itemHtml = ''; 488 489 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 490 if ($showItem !== false && ($showItem == 'always' || ($showItem == 'logged in' && $loggedIn) || ($showItem == 'logged out' && !$loggedIn))) { 491 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown ? 'mikio-dropdown-item' : '') . ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 492 if ($showIcons) $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 493 if ($showText || $isDropDown) $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 494 $itemHtml .= '</a>'; 495 496 $pageToolsMenu[] = $itemHtml; 497 } 498 } 499 } 500 501 $items = (new \dokuwiki\Menu\SiteMenu())->getItems('action'); 502 foreach ($items as $item) { 503 $itemHtml = ''; 504 505 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 506 if ($showItem !== false && ($showItem == 'always' || ($showItem == 'logged in' && $loggedIn) || ($showItem == 'logged out' && !$loggedIn))) { 507 $itemHtml .= '<a class="mikio-nav-link ' . ($isDropDown ? 'mikio-dropdown-item' : '') . ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 508 if ($showIcons) $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 509 if ($showText || $isDropDown) $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 510 $itemHtml .= '</a>'; 511 512 $siteToolsMenu[] = $itemHtml; 513 } 514 } 515 516 $items = (new \dokuwiki\Menu\UserMenu())->getItems('action'); 517 foreach ($items as $item) { 518 $itemHtml = ''; 519 520 $showItem = $this->getConf('navbarItemShow' . ucfirst($item->getType())); 521 if ($showItem !== false && ($showItem == 'always' || ($showItem == 'logged in' && $loggedIn) || ($showItem == 'logged out' && !$loggedIn))) { 522 $itemHtml .= '<a class="mikio-nav-link' . ($isDropDown ? ' mikio-dropdown-item' : '') . ' ' . $item->getType() . '" href="' . $item->getLink() . '" title="' . $item->getTitle() . '">'; 523 if ($showIcons) $itemHtml .= '<span class="mikio-icon">' . inlineSVG($item->getSvg()) . '</span>'; 524 if ($showText || $isDropDown) $itemHtml .= '<span>' . $item->getLabel() . '</span>'; 525 $itemHtml .= '</a>'; 526 527 $userToolsMenu[] = $itemHtml; 528 } 529 } 530 531 532 switch ($this->getConf('navbarDWMenuCombine')) { 533 case 'dropdown': 534 $html .= '<li id="dokuwiki__pagetools" class="mikio-nav-dropdown">'; 535 $html .= '<a id="mikio_dropdown_pagetools" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . ($showIcons ? $this->mikioInlineIcon('file') : '') . ($showText ? $lang['page_tools'] : '<span class="mikio-small-only">' . $lang['page_tools'] . '</span>') . '</a>'; 536 $html .= '<div class="mikio-dropdown closed">'; 537 538 foreach ($pageToolsMenu as $item) { 539 $html .= $item; 540 } 541 542 $html .= '</div>'; 543 $html .= '</li>'; 544 545 $html .= '<li id="dokuwiki__sitetools" class="mikio-nav-dropdown">'; 546 $html .= '<a id="mikio_dropdown_sitetools" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . ($showIcons ? $this->mikioInlineIcon('gear') : '') . ($showText ? $lang['site_tools'] : '<span class="mikio-small-only">' . $lang['site_tools'] . '</span>') . '</a>'; 547 $html .= '<div class="mikio-dropdown closed">'; 548 549 foreach ($siteToolsMenu as $item) { 550 $html .= $item; 551 } 552 553 $html .= '</div>'; 554 $html .= '</li>'; 555 556 $html .= '<li id="dokuwiki__usertools" class="mikio-nav-dropdown">'; 557 $html .= '<a id="mikio_dropdown_usertools" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . ($showIcons ? $this->mikioInlineIcon('user') : '') . ($showText ? $lang['user_tools'] : '<span class="mikio-small-only">' . $lang['user_tools'] . '</span>') . '</a>'; 558 $html .= '<div class="mikio-dropdown closed">'; 559 560 foreach ($userToolsMenu as $item) { 561 $html .= $item; 562 } 563 564 $html .= '</div>'; 565 $html .= '</li>'; 566 567 break; 568 569 case 'combine': 570 $html .= '<li class="mikio-nav-dropdown">'; 571 $html .= '<a class="mikio-nav-link" href="#">' . ($showIcons ? $this->mikioInlineIcon('wrench') : '') . ($showText ? tpl_getLang('tools-menu') : '<span class="mikio-small-only">' . tpl_getLang('tools-menu') . '</span>') . '</a>'; // TODO change $lang 572 $html .= '<div class="mikio-dropdown closed">'; 573 574 $html .= '<h6 class="mikio-dropdown-header">' . $lang['page_tools'] . '</h6>'; 575 foreach ($pageToolsMenu as $item) { 576 $html .= $item; 577 } 578 579 $html .= '<div class="mikio-dropdown-divider"></div>'; 580 $html .= '<h6 class="mikio-dropdown-header">' . $lang['site_tools'] . '</h6>'; 581 foreach ($siteToolsMenu as $item) { 582 $html .= $item; 583 } 584 585 $html .= '<div class="mikio-dropdown-divider"></div>'; 586 $html .= '<h6 class="mikio-dropdown-header">' . $lang['user_tools'] . '</h6>'; 587 foreach ($userToolsMenu as $item) { 588 $html .= $item; 589 } 590 591 $html .= '</div>'; 592 $html .= '</li>'; 593 break; 594 595 default: // seperate 596 foreach ($siteToolsMenu as $item) { 597 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 598 } 599 600 foreach ($pageToolsMenu as $item) { 601 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 602 } 603 604 foreach ($userToolsMenu as $item) { 605 $html .= '<li class="mikio-nav-item">' . $item . '</li>'; 606 } 607 608 break; 609 } 610 611 $html .= '</ul>'; 612 613 if ($print) echo $html; 614 return $html; 615 } 616 617 618 /** 619 * Create a nav element from a string. <uri>|<title>; 620 * 621 * @param string $str string to generate nav 622 * @return string nav elements generated 623 */ 624 public function stringToNav($str) 625 { 626 $html = ''; 627 628 if ($str != '') { 629 $items = explode(';', $str); 630 if (count($items) > 0) { 631 $html .= '<ul class="mikio-nav">'; 632 foreach ($items as $item) { 633 $parts = explode('|', $item); 634 if ($parts > 1) { 635 $html .= '<li class="mikio-nav-item"><a class="mikio-nav-link" href="' . strip_tags($this->getLink(trim($parts[0]))) . '">' . strip_tags(trim($parts[1])) . '</a></li>'; 636 } 637 } 638 $html .= '</ul>'; 639 } 640 } 641 642 return $html; 643 } 644 645 /** 646 * print or return the main navbar 647 * 648 * @param boolean $print print the navbar 649 * @param boolean $showSub include the sub navbar 650 * @return string generated content 651 */ 652 public function includeNavbar($print = TRUE, $showSub = FALSE) 653 { 654 global $conf; 655 656 $homeUrl = wl(); 657 658 if (!plugin_isdisabled('showpageafterlogin')) { 659 $p = &plugin_load('action', 'showpageafterlogin'); 660 if ($p) { 661 global $USERINFO; 662 663 if (is_array($USERINFO) && count($USERINFO) > 0) { 664 $homeUrl = wl($p->getConf('page_after_login')); 665 } 666 } 667 } 668 669 670 $html = ''; 671 672 $html .= '<nav class="mikio-navbar' . (($this->getConf('stickyNavbar')) ? ' mikio-sticky' : '') . '">'; 673 $html .= '<div class="mikio-container">'; 674 $html .= '<a class="mikio-navbar-brand" href="' . $homeUrl . '">'; 675 if ($this->getConf('navbarUseTitleIcon') || $this->getConf('navbarUseTitleText')) { 676 677 // Brand image 678 if ($this->getConf('navbarUseTitleIcon')) { 679 $logo = $this->getMediaFile('logo', FALSE);; 680 if ($logo != '') { 681 $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image">'; 682 } 683 } 684 685 // Brand title 686 if ($this->getConf('navbarUseTitleText')) { 687 $html .= '<div class="mikio-navbar-brand-title">'; 688 $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>'; 689 if ($this->getConf('navbarUseTaglineText')) { 690 $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>'; 691 } 692 $html .= '</div>'; 693 } 694 } 695 $html .= '</a>'; 696 $html .= '<div class="mikio-navbar-toggle"><span class="icon"></span></div>'; 697 698 // Menus 699 $html .= '<div class="mikio-navbar-collapse">'; 700 701 $menus = array($this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'), $this->getConf('navbarPosRight', 'none')); 702 foreach ($menus as $menuType) { 703 switch ($menuType) { 704 case 'custom': 705 $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', '')); 706 break; 707 case 'search': 708 $html .= '<div class="mikio-nav-item">'; 709 $html .= $this->includeSearch(false); 710 $html .= '</div>'; 711 break; 712 case 'dokuwiki': 713 $html .= $this->includeDWMenu(FALSE); 714 break; 715 } 716 } 717 718 $html .= '</div>'; 719 $html .= '</div>'; 720 $html .= '</nav>'; 721 722 // Sub Navbar 723 if ($showSub) { 724 $sub = $this->includePage('submenu', FALSE); 725 if ($sub != '') $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>'; 726 } 727 728 if ($print) echo $html; 729 return $html; 730 } 731 732 733 /** 734 * Is there a sidebar 735 * 736 * @param string $prefix sidebar prefix to use when searching 737 * @return boolean if sidebar exists 738 */ 739 public function sidebarExists($prefix = '') 740 { 741 global $conf; 742 743 if ($prefix == 'left') $prefix = ''; 744 745 return $this->pageExists($conf['sidebar' . $prefix]); 746 } 747 748 749 /** 750 * Print or return the sidebar content 751 * 752 * @param string $prefix sidebar prefix to use when searching 753 * @param boolean $print print the generated content to the output buffer 754 * @param boolean $parse parse the content 755 * @return string generated content 756 */ 757 public function includeSidebar($prefix = '', $print = TRUE, $parse = TRUE) 758 { 759 global $conf, $ID; 760 761 $html = ''; 762 $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix)); 763 $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix)); 764 765 if ($confPrefix == '') $confPrefix = 'Left'; 766 if ($prefix == 'Left') $prefix = ''; 767 768 $sidebarPage = $conf[$prefix . 'sidebar'] == '' ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar']; 769 770 if ($this->getConf('sidebarShow' . $confPrefix) && page_findnearest($sidebarPage) != FALSE && p_get_metadata($ID, 'nosidebar', FALSE) == FALSE) { 771 $content = $this->includePage($sidebarPage . 'header', FALSE); 772 if ($content != '') $html .= '<div class="mikio-sidebar-header">' . $content . '</div>'; 773 774 if ($prefix == '') { 775 $rows = array($this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'), $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4')); 776 777 foreach ($rows as $row) { 778 switch ($row) { 779 case 'search': 780 $html .= $this->includeSearch(FALSE); 781 break; 782 case 'logged in user': 783 $html .= $this->includeLoggedIn(FALSE); 784 break; 785 case 'content': 786 $content = $this->includePage($sidebarPage, FALSE); 787 if ($content != '') $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 788 break; 789 case 'tags': 790 $html .= '<div class="mikio-tags"></div>'; 791 } 792 } 793 } else { 794 $content = $this->includePage($sidebarPage, FALSE); 795 if ($content != '') $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 796 } 797 798 $content = $this->includePage($sidebarPage . 'footer', FALSE); 799 if ($content != '') $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>'; 800 } 801 802 if ($html == '') { 803 if ($prefix == '' && $this->getConf('sidebarAlwaysShowLeft')) $html = ' '; 804 if ($this->getConf('sidebarAlwaysShow' . ucfirst($prefix))) $html = ' '; 805 } 806 807 if ($html != '') { 808 $html = '<aside class="mikio-sidebar mikio-sidebar-' . ($prefix == '' ? 'left' : $prefix) . '"><a class="mikio-sidebar-toggle' . ($this->getConf('sidebarMobileDefaultCollapse') ? ' closed' : '') . '" href="#">' . tpl_getLang('sidebar-title') . ' <span class="icon"></span></a><div class="mikio-sidebar-collapse">' . $html . '</div></aside>'; 809 } 810 811 if ($parse) $html = $this->includeIcons($html); 812 if ($print) echo $html; 813 return $html; 814 } 815 816 817 /** 818 * Print or return the page tools content 819 * 820 * @param boolean $print print the generated content to the output buffer 821 * @param boolean $includeId include the dw__pagetools id in the element 822 * @return string generated content 823 */ 824 public function includePageTools($print = TRUE, $includeId = FALSE) 825 { 826 global $USERINFO; 827 828 $loggedIn = (is_array($USERINFO) && count($USERINFO) > 0); 829 $html = ''; 830 831 $html .= '<nav' . ($includeId ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">'; 832 $html .= '<ul class="tools">'; 833 834 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 835 foreach ($items as $item) { 836 $classes = array(); 837 $classes[] = $item->getType(); 838 $attr = $item->getLinkAttributes(); 839 840 if (!empty($attr['class'])) { 841 $classes = array_merge($classes, explode(' ', $attr['class'])); 842 } 843 844 $classes = array_unique($classes); 845 846 $showItem = $this->getConf('pageToolsShow' . ucfirst($item->getType())); 847 if ($showItem !== false && ($showItem == 'always' || ($showItem == 'logged in' && $loggedIn) || ($showItem == 'logged out' && !$loggedIn))) { 848 $html .= '<li class="' . implode(' ', $classes) . '">'; 849 $html .= '<a href="' . $item->getLink() . '" class="' . $item->getType() . '" title="' . $item->getTitle() . '"><div class="icon">' . inlineSVG($item->getSvg()) . '</div><span class="a11y">' . $item->getLabel() . '</span></a>'; 850 $html .= '</li>'; 851 } 852 } 853 854 $html .= '</ul>'; 855 $html .= '</nav>'; 856 857 if ($print) echo $html; 858 return $html; 859 } 860 861 862 /** 863 * Print or return the search bar 864 * 865 * @param boolean $print print content 866 * @return string contents of the search bar 867 */ 868 public function includeSearch($print = TRUE) 869 { 870 global $lang, $ID; 871 $html = ''; 872 873 $html .= '<form class="mikio-search search" action="' . wl() . '" accept-charset="utf-8" method="get" role="search">'; 874 $html .= '<input type="hidden" name="do" value="search">'; 875 $html .= '<input type="hidden" name="id" value="' . $ID . '">'; 876 $html .= '<input name="q" class="search_typeahead" autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . (($ACT == 'search') ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 877 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 878 if ($this->getConf('searchButton') == 'icon') { 879 $html .= $this->mikioInlineIcon('search'); 880 } else { 881 $html .= $lang['btn_search']; 882 } 883 $html .= '</button>'; 884 $html .= '</form>'; 885 886 887 888 if ($print) print $html; 889 return $html; 890 } 891 892 893 /** 894 * Print or return content 895 * 896 * @param boolean $print print content 897 * @return string contents 898 */ 899 public function includeContent($print = TRUE) 900 { 901 ob_start(); 902 tpl_content(FALSE); 903 $html = ob_get_contents(); 904 ob_end_clean(); 905 906 $html = $this->includeIcons($html); 907 $html = $this->parseContent($html); 908 909 $html .= '<div style="clear:both"></div>'; 910 911 if (!$this->getConf('heroTitle')) $html = '<div class="mikio-tags"></div>' . $html; 912 913 $html = '<div class="mikio-article-content">' . $html . '</div>'; 914 915 if ($print) echo $html; 916 return $html; 917 } 918 919 /** 920 * Print or return footer 921 * 922 * @param boolean $print print footer 923 * @return string html string containing footer 924 */ 925 public function includeFooter($print = TRUE) 926 { 927 global $ACT; 928 929 $html = ''; 930 931 $html .= '<footer class="mikio-footer">'; 932 $html .= '<div class="doc">' . tpl_pageinfo(TRUE) . '</div>'; 933 $html .= $this->includePage('footer', FALSE); 934 935 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 936 937 if ($this->getConf('footerSearch')) { 938 $html .= '<div class="mikio-footer-search">'; 939 $html .= $this->includeSearch(FALSE); 940 $html .= '</div>'; 941 } 942 943 $showPageTools = $this->getConf('pageToolsFooter'); 944 if ($ACT == 'show' && ($showPageTools == 'always' || $this->userCanEdit() && $showPageTools == 'page editors')) $html .= $this->includePageTools(FALSE); 945 946 $meta['licenseType'] = array('multichoice', '_choices' => array('none', 'badge', 'button')); 947 $meta['licenseImageOnly'] = array('onoff'); 948 949 $licenseType = $this->getConf('licenseType'); 950 if ($licenseType != 'none') { 951 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), TRUE, TRUE); 952 } 953 954 $html .= '</footer>'; 955 956 if ($print) echo $html; 957 return $html; 958 } 959 960 961 /** 962 * Print or return breadcrumb trail 963 * 964 * @param boolean $print print out trail 965 * @param boolean $parse parse trail before printing 966 * @return string html string containing breadcrumbs 967 */ 968 public function includeBreadcrumbs($print = TRUE, $parse = TRUE) 969 { 970 global $conf, $ID, $lang, $ACT; 971 972 if ($this->getConf('breadcrumbHideHome') && $ID == 'start' && $ACT == 'show' || $ACT == 'showtag') return ''; 973 974 $html = '<div class="mikio-breadcrumbs">'; 975 $html .= '<div class="mikio-container">'; 976 if ($ACT == 'show') { 977 if ($conf['breadcrumbs']) { 978 if (!$this->getConf('breadcrumbPrefix') && !$this->getConf('breadcrumbSep')) { 979 ob_start(); 980 tpl_breadcrumbs(); 981 $html .= ob_get_contents(); 982 ob_end_clean(); 983 } else { 984 $sep = '•'; 985 $prefix = $lang['breadcrumb']; 986 987 if ($this->getConf('breadcrumbSep')) { 988 $sep = $this->getConf('breadcrumbSepText'); 989 $img = $this->getMediaFile('breadcrumb-sep', FALSE); 990 991 if ($img !== FALSE) { 992 $sep = '<img src="' . $img . '">'; 993 } 994 } 995 996 if ($this->getConf('breadcrumbPrefix')) { 997 $prefix = $this->getConf('breadcrumbPrefixText'); 998 $img = $this->getMediaFile('breadcrumb-prefix', FALSE); 999 1000 if ($img !== FALSE) { 1001 $prefix = '<img src="' . $img . '">'; 1002 } 1003 } 1004 1005 $crumbs = breadcrumbs(); 1006 1007 $html .= '<ul>'; 1008 if ($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 1009 1010 $last = count($crumbs); 1011 $i = 0; 1012 foreach ($crumbs as $id => $name) { 1013 $i++; 1014 $html .= '<li class="sep">' . $sep . '</li>'; 1015 $html .= '<li' . ($i == $last ? ' class="curid"' : '') . '>'; 1016 $html .= tpl_pagelink($id, NULL, TRUE); 1017 $html .= '</li>'; 1018 } 1019 1020 $html .= '</ul>'; 1021 } 1022 } 1023 } 1024 1025 $html .= '</div>'; 1026 $html .= '</div>'; 1027 1028 if ($parse) $html = $this->includeIcons($html); 1029 if ($print) echo $html; 1030 return $html; 1031 } 1032 1033 /** 1034 * Print or return you are here trail 1035 * 1036 * @param boolean $print print out trail 1037 * @param boolean $parse parse trail before printing 1038 * @return string html string containing breadcrumbs 1039 */ 1040 public function includeYouAreHere($print = TRUE, $parse = TRUE) 1041 { 1042 global $conf, $ID, $lang, $ACT; 1043 1044 if ($this->getConf('youarehereHideHome') && $ID == 'start' && $ACT == 'show' || $ACT == 'showtag') return ''; 1045 1046 $html = '<div class="mikio-youarehere">'; 1047 $html .= '<div class="mikio-container">'; 1048 if ($ACT == 'show') { 1049 if ($conf['youarehere']) { 1050 if (!$this->getConf('youareherePrefix') && !$this->getConf('youarehereSep')) { 1051 ob_start(); 1052 tpl_youarehere(); 1053 $html .= ob_get_contents(); 1054 ob_end_clean(); 1055 } else { 1056 $sep = ' » '; 1057 $prefix = $lang['youarehere']; 1058 1059 if ($this->getConf('youarehereSep')) { 1060 $sep = $this->getConf('youarehereSepText'); 1061 $img = $this->getMediaFile('youarehere-sep', FALSE); 1062 1063 if ($img !== FALSE) { 1064 $sep = '<img src="' . $img . '">'; 1065 } 1066 } 1067 1068 if ($this->getConf('youareherePrefix')) { 1069 $prefix = $this->getConf('youareherePrefixText'); 1070 $img = $this->getMediaFile('youarehere-prefix', FALSE); 1071 1072 if ($img !== FALSE) { 1073 $prefix = '<img src="' . $img . '">'; 1074 } 1075 } 1076 1077 $html .= '<ul>'; 1078 if ($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 1079 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], NULL, TRUE) . '</li>'; 1080 1081 $parts = explode(':', $ID); 1082 $count = count($parts); 1083 1084 $part = ''; 1085 for ($i = 0; $i < $count - 1; $i++) { 1086 $part .= $parts[$i] . ':'; 1087 $page = $part; 1088 if ($page == $conf['start']) continue; 1089 1090 $html .= '<li class="sep">' . $sep . '</li>'; 1091 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 1092 } 1093 1094 resolve_pageid('', $page, $exists); 1095 if (!(isset($page) && $page == $part . $parts[$i])) { 1096 $page = $part . $parts[$i]; 1097 if ($page != $conf['start']) { 1098 $html .= '<li class="sep">' . $sep . '</li>'; 1099 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 1100 } 1101 } 1102 1103 $html .= '</ul>'; 1104 } 1105 } 1106 1107 $showLast = $this->getConf('youarehereShowLast'); 1108 if ($showLast != 0) { 1109 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1110 if (count($matches) > 0 && count($matches[0]) > ($showLast * 2) + 2) { 1111 $count = count($matches[0]); 1112 $list = ''; 1113 1114 // Show Home 1115 $list .= $matches[0][0] . $matches[0][1]; 1116 1117 $list .= '<li>...</li>'; 1118 for ($i = $count - ($showLast * 2); $i <= $count; $i++) { 1119 $list .= $matches[0][$i]; 1120 } 1121 1122 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1123 } 1124 } 1125 1126 switch ($this->getConf('youarehereHome')) { 1127 case 'none': 1128 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1129 break; 1130 case 'home': 1131 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1132 break; 1133 case 'icon': 1134 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . $this->mikioInlineIcon('home') . '$3', $html, 1); 1135 break; 1136 } 1137 } else { 1138 $html .= '≪ '; 1139 if (isset($_GET['page'])) { 1140 $html .= '<a href="' . wl($ID, array('do' => $ACT)) . '">Back</a> / '; 1141 } 1142 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1143 } 1144 1145 $html .= '</div>'; 1146 $html .= '</div>'; 1147 1148 if ($parse) $html = $this->includeIcons($html); 1149 if ($print) echo $html; 1150 return $html; 1151 } 1152 1153 /** 1154 * Get Page Title 1155 */ 1156 public function parsePageTitle() 1157 { 1158 global $ID; 1159 1160 $title = p_get_first_heading($ID); 1161 if (strlen($title) <= 0) $title = tpl_pagetitle(null, TRUE); 1162 $title = $this->includeIcons($title); 1163 1164 return $title; 1165 } 1166 1167 1168 /** 1169 * Print or return hero block 1170 * 1171 * @param boolean $print print content 1172 * @return string contents of hero 1173 */ 1174 public function includeHero($print = TRUE) 1175 { 1176 $html = ''; 1177 1178 if ($this->getConf('heroTitle')) { 1179 $html .= '<div class="mikio-hero">'; 1180 $html .= '<div class="mikio-container">'; 1181 $html .= '<div class="mikio-hero-text">'; 1182 if ($this->getConf('youareherePosition') == 'hero') $html .= $this->includeYouAreHere(FALSE); 1183 if ($this->getConf('breadcrumbPosition') == 'hero') $html .= $this->includeBreadcrumbs(FALSE); 1184 1185 $html .= '<h1 class="mikio-hero-title">'; 1186 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1187 $html .= '</h1>'; 1188 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1189 $html .= '</div>'; 1190 1191 $hero_image = $this->getMediaFile('hero', TRUE, $this->getConf('heroImagePropagation', TRUE)); 1192 $hero_image_resize_class = ''; 1193 if ($hero_image != '') { 1194 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1195 $hero_image_resize_class = ' mikio-hero-image-resize'; 1196 } 1197 1198 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . '><div class="mikio-tags"></div></div>'; 1199 1200 $html .= '</div>'; 1201 $html .= '</div>'; 1202 } 1203 1204 if ($print) echo $html; 1205 1206 return $html; 1207 } 1208 1209 1210 /** 1211 * Print or return out TOC 1212 * 1213 * @param boolean $print print TOC 1214 * @return string contents of TOC 1215 */ 1216 public function includeTOC($parse = TRUE) 1217 { 1218 $html = ''; 1219 1220 $tocHtml = tpl_toc(true); 1221 1222 if ($tocHtml != '') { 1223 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1224 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1225 1226 $html .= '<div class="mikio-toc">'; 1227 $html .= $tocHtml; 1228 $html .= '</div>'; 1229 } 1230 1231 if ($parse) $html = $this->includeIcons($html); 1232 echo $html; 1233 } 1234 1235 1236 /** 1237 * Parse the string and replace icon elements with included icon libraries 1238 * 1239 * @param string $str content to parse 1240 * @return string parsed string 1241 */ 1242 public function includeIcons($str) 1243 { 1244 global $ACT, $MIKIO_ICONS; 1245 1246 $iconTag = $this->getConf('iconTag', 'icon'); 1247 if ($iconTag == '') return $str; 1248 1249 if ($ACT == 'show' || $ACT == 'admin' && count($MIKIO_ICONS) > 0 || $ACT == 'showtag' || $ACT == 'revisions' || $ACT == 'index' || $ACT == 'preview') { 1250 $content = $str; 1251 $preview = null; 1252 1253 if ($ACT == 'preview') { 1254 $html = new \simple_html_dom; 1255 $html->stripRNAttrValues = false; 1256 $html->load($str, true, false); 1257 1258 $preview = $html->find('div.preview'); 1259 if (is_array($preview) && count($preview) > 0) { 1260 $content = $preview[0]->innertext; 1261 } 1262 } 1263 1264 $page_regex = '/(.*)/'; 1265 if (stripos($str, '<pre')) { 1266 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1267 } 1268 1269 $content = preg_replace_callback($page_regex, function ($icons) { 1270 $iconTag = $this->getConf('iconTag', 'icon'); 1271 1272 return preg_replace_callback( 1273 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1274 function ($matches) { 1275 global $MIKIO_ICONS; 1276 1277 $s = $matches[0]; 1278 1279 if (count($MIKIO_ICONS) > 0) { 1280 $icon = $MIKIO_ICONS[0]; 1281 1282 if (count($matches) > 1) { 1283 $e = explode(' ', $matches[1]); 1284 1285 if (count($e) > 1) { 1286 foreach ($MIKIO_ICONS as $iconItem) { 1287 if (strcasecmp($iconItem['name'], $e[0]) == 0) { 1288 $icon = $iconItem; 1289 1290 $s = $icon['insert']; 1291 for ($i = 1; $i < 9; $i++) { 1292 if (count($e) < $i || $e[$i] == '') { 1293 if (isset($icon['$' . $i])) { 1294 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1295 } 1296 } else { 1297 $s = str_replace('$' . $i, $e[$i], $s); 1298 } 1299 } 1300 1301 $dir = ''; 1302 if (isset($icon['dir'])) $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1303 1304 $s = str_replace('$0', $dir, $s); 1305 1306 break; 1307 } 1308 } 1309 } else { 1310 $s = str_replace('$1', $matches[1], $icon['insert']); 1311 } 1312 } 1313 } 1314 1315 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1316 if ($count == 0) { 1317 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1318 } 1319 1320 return $s; 1321 }, 1322 $icons[0] 1323 ); 1324 }, $content); 1325 1326 if ($ACT == 'preview') { 1327 if (is_array($preview) && count($preview) > 0) { 1328 $preview[0]->innertext = $content; 1329 } 1330 1331 $str = $html->save(); 1332 $html->clear(); 1333 unset($html); 1334 } else { 1335 $str = $content; 1336 } 1337 } 1338 1339 return $str; 1340 } 1341 1342 /** 1343 * Parse HTML for theme 1344 * 1345 * @param string $content HTML content to parse 1346 * @return string Parsed content 1347 */ 1348 public function parseContent($content) 1349 { 1350 global $INPUT, $ACT; 1351 1352 // Add Mikio Section titles 1353 if ($INPUT->str('page') == 'config') { 1354 $admin_sections = array( 1355 // Section Insert Before Icon 1356 'navbar' => array('navbarUseTitleIcon', ''), 1357 'search' => array('searchButton', ''), 1358 'hero' => array('heroTitle', ''), 1359 'tags' => array('tagsConsolidate', ''), 1360 'breadcrumb' => array('breadcrumbHideHome', ''), 1361 'youarehere' => array('youareherePosition', ''), 1362 'sidebar' => array('sidebarShowLeft', ''), 1363 'toc' => array('tocFull', ''), 1364 'pagetools' => array('pageToolsFloating', ''), 1365 'footer' => array('footerCustomMenuText', ''), 1366 'license' => array('licenseType', ''), 1367 'acl' => array('includePageUseACL', ''), 1368 'sticky' => array('stickyTopHeader', ''), 1369 ); 1370 1371 foreach ($admin_sections as $section => $items) { 1372 $search = $items[0]; 1373 $icon = $items[1]; 1374 1375 // $content = preg_replace('/<tr(.*)>\s+<td(.*)>\s+<span(.*)>(tpl»mikio»' . $search . ')<\/span>/', 1376 // '<tr class="default"><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . tpl_getLang('config_' . $section) . '</td></tr><tr$1><td$2><span$3>$4</span>', $content); 1377 1378 $content = preg_replace( 1379 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1380 '<tr$1><td class="mikio-config-table-header" colspan="2">' . $this->mikioInlineIcon($icon) . tpl_getLang('config_' . $section) . '</td></tr><tr class="default"><td class="label"><span class="outkey">tpl»mikio»' . $search . '</span>', 1381 $content 1382 ); 1383 } 1384 } 1385 1386 if ($ACT == 'admin' && !isset($_GET['page'])) { 1387 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1388 } 1389 1390 // Page Revisions - Table Fix 1391 if (strpos($content, 'id="page__revisions"') !== FALSE) { 1392 $content = preg_replace('/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', '<span>$1</span>', $content); 1393 } 1394 1395 $html = new \simple_html_dom; 1396 $html->stripRNAttrValues = false; 1397 $html->load($content, true, false); 1398 1399 if (!$html) return $content; 1400 1401 /* Buttons */ 1402 foreach ($html->find('#config__manager button') as $node) { 1403 $c = explode(' ', $node->class); 1404 if (!in_array('mikio-button', $c)) $c[] = 'mikio-button'; 1405 $node->class = implode(' ', $c); 1406 } 1407 1408 1409 /* Buttons - Primary */ 1410 foreach ($html->find('#config__manager [type=submit]') as $node) { 1411 $c = explode(' ', $node->class); 1412 if (!in_array('mikio-primary', $c)) $c[] = 'mikio-primary'; 1413 $node->class = implode(' ', $c); 1414 } 1415 1416 /* Hide page title if hero is enabled */ 1417 if ($this->getConf('heroTitle') && $ACT != 'preview') { 1418 $pageTitle = $this->parsePageTitle(); 1419 1420 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1421 if ($elm->innertext == $pageTitle) { 1422 // $elm->innertext = ''; 1423 $elm->setAttribute('style', 'display:none'); 1424 1425 break; 1426 } 1427 } 1428 } 1429 1430 /* Hero subtitle */ 1431 foreach ($html->find('p') as $elm) { 1432 $i = stripos($elm->innertext, '~~hero-subtitle'); 1433 if ($i !== false) { 1434 $j = strpos($elm->innertext, '~~', $i + 2); 1435 if ($j !== false) { 1436 if ($j > $i + 16) { 1437 $subtitle = substr($elm->innertext, $i + 16, $j - $i - 16); 1438 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1439 1440 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1441 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1442 } 1443 1444 break; 1445 } 1446 } 1447 } 1448 1449 /* Hero image */ 1450 foreach ($html->find('p') as $elm) { 1451 $image = ''; 1452 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1453 if (count($matches) > 0) { 1454 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1455 if (count($imageTagMatches) > 0) { 1456 $image = $imageTagMatches[1]; 1457 } else { 1458 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1459 if (count($imageTagMatches) > 0) { 1460 $image = $imageTagMatches[1]; 1461 } else { 1462 $image = strip_tags($matches[1]); 1463 if (stripos($image, ':') === FALSE) { 1464 $image = str_replace(array('{', '}'), '', $image); 1465 $i = stripos($image, '?'); 1466 if ($i !== FALSE) { 1467 $image = substr($image, 0, $i); 1468 } 1469 1470 $image = ml($image, '', true, '', false); 1471 } 1472 } 1473 } 1474 1475 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 1476 1477 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1478 } 1479 } 1480 1481 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1482 foreach ($html->find('p') as $elm) { 1483 $i = stripos($elm->innertext, '~~hero-colors'); 1484 if ($i !== false) { 1485 $j = strpos($elm->innertext, '~~', $i + 2); 1486 if ($j !== false) { 1487 if ($j > $i + 14) { 1488 $color = substr($elm->innertext, $i + 14, $j - $i - 14); 1489 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')'; 1490 1491 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1492 } 1493 1494 break; 1495 } 1496 } 1497 } 1498 1499 /* Hide parts - ~~hide-parts [parts]~~ */ 1500 foreach ($html->find('p') as $elm) { 1501 $i = stripos($elm->innertext, '~~hide-parts'); 1502 if ($i !== false) { 1503 $j = strpos($elm->innertext, '~~', $i + 2); 1504 if ($j !== false) { 1505 if ($j > $i + 13) { 1506 $parts = explode(' ', substr($elm->innertext, $i + 13, $j - $i - 13)); 1507 $script = ''; 1508 1509 foreach ($parts as $part) { 1510 // $part = trim($part); 1511 if (strlen($part) > 0) { 1512 $script .= 'mikio.hidePart(\'' . $part . '\');'; 1513 } 1514 } 1515 1516 if (strlen($script) > 0) { 1517 $this->footerScript['hide-parts'] = $script; 1518 } 1519 1520 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1521 } 1522 1523 break; 1524 } 1525 } 1526 } 1527 1528 1529 /* Page Tags (tag plugin) */ 1530 if ($this->getConf('tagsConsolidate')) { 1531 $tags = ''; 1532 foreach ($html->find('div.tags a') as $elm) { 1533 $tags .= $elm->outertext; 1534 } 1535 1536 foreach ($html->find('div.tags') as $elm) { 1537 $elm->innertext = ''; 1538 $elm->setAttribute('style', 'display:none'); 1539 } 1540 1541 if ($tags != '') { 1542 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1543 } 1544 } 1545 1546 // Configuration Manager 1547 if ($INPUT->str('page') == 'config') { 1548 1549 // Additional save buttons 1550 foreach ($html->find('#config__manager') as $cm) { 1551 $saveButtons = ''; 1552 1553 foreach ($cm->find('p') as $elm) { 1554 $saveButtons = $elm->outertext; 1555 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1556 $elm->outertext = ''; 1557 } 1558 1559 foreach ($cm->find('fieldset') as $elm) { 1560 $elm->innertext .= $saveButtons; 1561 } 1562 } 1563 } 1564 1565 $content = $html->save(); 1566 $html->clear(); 1567 unset($html); 1568 1569 return $content; 1570 } 1571 1572 1573 /** 1574 * Get DokuWiki namespace/page/URI as link 1575 * 1576 * @param string $str string to parse 1577 * @return string parsed uri 1578 */ 1579 public function getLink($str) 1580 { 1581 $i = strpos($str, '://'); 1582 if ($i !== false) return $str; 1583 1584 return wl($str); 1585 } 1586 1587 1588 /** 1589 * Check if the user can edit current namespace/page 1590 * 1591 * @return boolean user can edit 1592 */ 1593 public function userCanEdit() 1594 { 1595 global $INFO; 1596 global $ID; 1597 1598 $wiki_file = wikiFN($ID); 1599 if (@!file_exists($wiki_file)) return true; 1600 if ($INFO['isadmin'] || $INFO['ismanager']) return true; 1601 // $meta_file = metaFN($ID, '.meta'); 1602 if (!$INFO['meta']['user']) return true; 1603 if ($INFO['client'] == $INFO['meta']['user']) return true; 1604 1605 return false; 1606 } 1607 1608 1609 /** 1610 * Search for and return the uri of a media file 1611 * 1612 * @param string $image image name to search for (without extension) 1613 * @param bool $searchCurrentNS search the current namespace 1614 * @return string uri of the found media file 1615 */ 1616 public function getMediaFile($image, $searchCurrentNS = TRUE, $propagate = TRUE) 1617 { 1618 global $INFO; 1619 1620 $ext = array('png', 'jpg', 'gif', 'svg'); 1621 1622 if ($searchCurrentNS) $prefix[] = ':' . $INFO['namespace'] . ':'; 1623 if ($propagate) { 1624 $prefix[] = ':'; 1625 $prefix[] = ':wiki:'; 1626 } 1627 $theme = $this->getConf('customTheme'); 1628 if ($theme != '') $prefix[] = $this->tplDir . 'themes/' . $theme . '/images/'; 1629 $prefix[] = 'images/'; 1630 1631 $search = array(); 1632 foreach ($prefix as $pitem) { 1633 foreach ($ext as $eitem) { 1634 $search[] = $pitem . $image . '.' . $eitem; 1635 } 1636 } 1637 1638 $img = ''; 1639 $file = ''; 1640 $url = ''; 1641 $ismedia = false; 1642 $found = false; 1643 1644 foreach ($search as $img) { 1645 if (substr($img, 0, 1) == ':') { 1646 $file = mediaFN($img); 1647 $ismedia = true; 1648 } else { 1649 $file = tpl_incdir() . $img; 1650 $ismedia = false; 1651 } 1652 1653 if (file_exists($file)) { 1654 $found = true; 1655 break; 1656 } 1657 } 1658 1659 if (!$found) return false; 1660 1661 if ($ismedia) { 1662 $url = ml($img, '', true, '', false); 1663 } else { 1664 $url = tpl_basedir() . $img; 1665 } 1666 1667 return $url; 1668 } 1669 1670 1671 /** 1672 * Print or return the page title 1673 * 1674 * @param string $page page id or empty string for current page 1675 * @return string generated content 1676 */ 1677 public function getPageTitle($page = '') 1678 { 1679 global $ID, $conf; 1680 1681 $html = ''; 1682 1683 if ($page == '') $page = $ID; 1684 1685 $html = p_get_first_heading($page); 1686 $html = strip_tags($html); 1687 $html = preg_replace('/\s+/', ' ', $html); 1688 $html .= ' [' . strip_tags($conf['title']) . ']'; 1689 $html = trim($html); 1690 1691 return $html; 1692 } 1693 1694 1695 /** 1696 * Return inline theme icon 1697 * 1698 * @param string $type icon to retreive 1699 * @return string html icon content 1700 */ 1701 public function mikioInlineIcon($type) 1702 { 1703 switch ($type) { 1704 case 'wrench': 1705 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" 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,19 -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,-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,435 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 131.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,-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>'; 1706 case 'file': 1707 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,235.38983,1277.8305)" id="g2991"><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 1280,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 q 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" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 1708 case 'gear': 1709 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,121.49153,1285.4237)" id="g3027"><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 181,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 10,-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 -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 147,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 q 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,71.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 q 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 -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" /></g></svg>'; 1710 case 'user': 1711 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" style="fill:currentColor"><g transform="matrix(1,0,0,-1,197.42373,1300.6102)"><path d="M 1408,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 28,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,-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 50.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 -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,1408 863,1408 975.5,1295.5 1088,1183 1088,1024 z"/></g></svg>'; 1712 case 'search': 1713 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-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 18.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 24.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 6.195 0 0 1-6.188 6.188z"/></svg>'; 1714 case 'home': 1715 return '<svg class="mikio-iicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -256 1792 1792" aria-hidden="true" style="fill:currentColor"><g transform="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 960 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 m 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 -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,-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" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" /></g></svg>'; 1716 } 1717 1718 return ''; 1719 } 1720 1721 /** 1722 * Finalize theme 1723 */ 1724 public function finalize() 1725 { 1726 } 1727 1728 /** 1729 * Show Messages 1730 */ 1731 public function showMessages() 1732 { 1733 global $ACT; 1734 1735 if ($this->lessIgnored) { 1736 msg('useLESS is enabled on the Mikio template, however is not supported on this server', 2, '', '', MSG_ADMINS_ONLY); 1737 } 1738 1739 $show = $this->getConf('showNotifications'); 1740 if ($show == 'always' || ($show == 'admin' && $ACT == 'admin')) { 1741 global $MSG, $MSG_shown; 1742 1743 if (!isset($MSG)) { 1744 return; 1745 } 1746 1747 if (!isset($MSG_shown)) { 1748 $MSG_shown = array(); 1749 } 1750 1751 foreach ($MSG as $msg) { 1752 1753 $hash = md5($msg['msg']); 1754 if (isset($MSG_shown[$hash])) { 1755 continue; 1756 } 1757 // skip double messages 1758 1759 if (info_msg_allowed($msg)) { 1760 1761 print '<div class="' . $msg['lvl'] . '">'; 1762 print $msg['msg']; 1763 print '</div>'; 1764 } 1765 1766 $MSG_shown[$hash] = true; 1767 } 1768 1769 unset($GLOBALS['MSG']); 1770 } 1771 } 1772 1773 /** 1774 * Dokuwiki version 1775 * 1776 * @return string the dw version name 1777 */ 1778 public function dwVersion() { 1779 if(function_exists('getVersionData')) { 1780 $version_data = getVersionData(); 1781 if(is_array($version_data) && array_key_exists('date', $version_data)) { 1782 $version_items = explode(' ', $version_data['date']); 1783 if(count($version_items) >= 2) { 1784 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 1785 } 1786 } 1787 } 1788 1789 return 'unknown'; 1790 } 1791 1792 /** 1793 * Dokuwiki version number 1794 * 1795 * @return string the dw version date converted to integer 1796 */ 1797 public function dwVersionNumber() { 1798 if(function_exists('getVersionData')) { 1799 $version_data = getVersionData(); 1800 if(is_array($version_data) && array_key_exists('date', $version_data)) { 1801 $version_items = explode(' ', $version_data['date']); 1802 if(count($version_items) >= 1) { 1803 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 1804 } 1805 } 1806 } 1807 1808 return 0; 1809 } 1810} 1811 1812global $TEMPLATE; 1813$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 1814