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" '; 877 if ($this->getConf('navbarUseTitleText')) { 878 $html .= 'class="search_typeahead" '; 879 } 880 $html .= 'autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . (($ACT == 'search') ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 881 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 882 if ($this->getConf('searchButton') == 'icon') { 883 $html .= $this->mikioInlineIcon('search'); 884 } else { 885 $html .= $lang['btn_search']; 886 } 887 $html .= '</button>'; 888 $html .= '</form>'; 889 890 891 892 if ($print) print $html; 893 return $html; 894 } 895 896 897 /** 898 * Print or return content 899 * 900 * @param boolean $print print content 901 * @return string contents 902 */ 903 public function includeContent($print = TRUE) 904 { 905 ob_start(); 906 tpl_content(FALSE); 907 $html = ob_get_contents(); 908 ob_end_clean(); 909 910 $html = $this->includeIcons($html); 911 $html = $this->parseContent($html); 912 913 $html .= '<div style="clear:both"></div>'; 914 915 if (!$this->getConf('heroTitle')) $html = '<div class="mikio-tags"></div>' . $html; 916 917 $html = '<div class="mikio-article-content">' . $html . '</div>'; 918 919 if ($print) echo $html; 920 return $html; 921 } 922 923 /** 924 * Print or return footer 925 * 926 * @param boolean $print print footer 927 * @return string html string containing footer 928 */ 929 public function includeFooter($print = TRUE) 930 { 931 global $ACT; 932 933 $html = ''; 934 935 $html .= '<footer class="mikio-footer">'; 936 $html .= '<div class="doc">' . tpl_pageinfo(TRUE) . '</div>'; 937 $html .= $this->includePage('footer', FALSE); 938 939 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 940 941 if ($this->getConf('footerSearch')) { 942 $html .= '<div class="mikio-footer-search">'; 943 $html .= $this->includeSearch(FALSE); 944 $html .= '</div>'; 945 } 946 947 $showPageTools = $this->getConf('pageToolsFooter'); 948 if ($ACT == 'show' && ($showPageTools == 'always' || $this->userCanEdit() && $showPageTools == 'page editors')) $html .= $this->includePageTools(FALSE); 949 950 $meta['licenseType'] = array('multichoice', '_choices' => array('none', 'badge', 'button')); 951 $meta['licenseImageOnly'] = array('onoff'); 952 953 $licenseType = $this->getConf('licenseType'); 954 if ($licenseType != 'none') { 955 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), TRUE, TRUE); 956 } 957 958 $html .= '</footer>'; 959 960 if ($print) echo $html; 961 return $html; 962 } 963 964 965 /** 966 * Print or return breadcrumb trail 967 * 968 * @param boolean $print print out trail 969 * @param boolean $parse parse trail before printing 970 * @return string html string containing breadcrumbs 971 */ 972 public function includeBreadcrumbs($print = TRUE, $parse = TRUE) 973 { 974 global $conf, $ID, $lang, $ACT; 975 976 if ($this->getConf('breadcrumbHideHome') && $ID == 'start' && $ACT == 'show' || $ACT == 'showtag') return ''; 977 978 $html = '<div class="mikio-breadcrumbs">'; 979 $html .= '<div class="mikio-container">'; 980 if ($ACT == 'show') { 981 if ($conf['breadcrumbs']) { 982 if (!$this->getConf('breadcrumbPrefix') && !$this->getConf('breadcrumbSep')) { 983 ob_start(); 984 tpl_breadcrumbs(); 985 $html .= ob_get_contents(); 986 ob_end_clean(); 987 } else { 988 $sep = '•'; 989 $prefix = $lang['breadcrumb']; 990 991 if ($this->getConf('breadcrumbSep')) { 992 $sep = $this->getConf('breadcrumbSepText'); 993 $img = $this->getMediaFile('breadcrumb-sep', FALSE); 994 995 if ($img !== FALSE) { 996 $sep = '<img src="' . $img . '">'; 997 } 998 } 999 1000 if ($this->getConf('breadcrumbPrefix')) { 1001 $prefix = $this->getConf('breadcrumbPrefixText'); 1002 $img = $this->getMediaFile('breadcrumb-prefix', FALSE); 1003 1004 if ($img !== FALSE) { 1005 $prefix = '<img src="' . $img . '">'; 1006 } 1007 } 1008 1009 $crumbs = breadcrumbs(); 1010 1011 $html .= '<ul>'; 1012 if ($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 1013 1014 $last = count($crumbs); 1015 $i = 0; 1016 foreach ($crumbs as $id => $name) { 1017 $i++; 1018 $html .= '<li class="sep">' . $sep . '</li>'; 1019 $html .= '<li' . ($i == $last ? ' class="curid"' : '') . '>'; 1020 $html .= tpl_pagelink($id, NULL, TRUE); 1021 $html .= '</li>'; 1022 } 1023 1024 $html .= '</ul>'; 1025 } 1026 } 1027 } 1028 1029 $html .= '</div>'; 1030 $html .= '</div>'; 1031 1032 if ($parse) $html = $this->includeIcons($html); 1033 if ($print) echo $html; 1034 return $html; 1035 } 1036 1037 /** 1038 * Print or return you are here trail 1039 * 1040 * @param boolean $print print out trail 1041 * @param boolean $parse parse trail before printing 1042 * @return string html string containing breadcrumbs 1043 */ 1044 public function includeYouAreHere($print = TRUE, $parse = TRUE) 1045 { 1046 global $conf, $ID, $lang, $ACT; 1047 1048 if ($this->getConf('youarehereHideHome') && $ID == 'start' && $ACT == 'show' || $ACT == 'showtag') return ''; 1049 1050 $html = '<div class="mikio-youarehere">'; 1051 $html .= '<div class="mikio-container">'; 1052 if ($ACT == 'show') { 1053 if ($conf['youarehere']) { 1054 if (!$this->getConf('youareherePrefix') && !$this->getConf('youarehereSep')) { 1055 ob_start(); 1056 tpl_youarehere(); 1057 $html .= ob_get_contents(); 1058 ob_end_clean(); 1059 } else { 1060 $sep = ' » '; 1061 $prefix = $lang['youarehere']; 1062 1063 if ($this->getConf('youarehereSep')) { 1064 $sep = $this->getConf('youarehereSepText'); 1065 $img = $this->getMediaFile('youarehere-sep', FALSE); 1066 1067 if ($img !== FALSE) { 1068 $sep = '<img src="' . $img . '">'; 1069 } 1070 } 1071 1072 if ($this->getConf('youareherePrefix')) { 1073 $prefix = $this->getConf('youareherePrefixText'); 1074 $img = $this->getMediaFile('youarehere-prefix', FALSE); 1075 1076 if ($img !== FALSE) { 1077 $prefix = '<img src="' . $img . '">'; 1078 } 1079 } 1080 1081 $html .= '<ul>'; 1082 if ($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 1083 $html .= '<li>' . tpl_pagelink(':' . $conf['start'], NULL, TRUE) . '</li>'; 1084 1085 $parts = explode(':', $ID); 1086 $count = count($parts); 1087 1088 $part = ''; 1089 for ($i = 0; $i < $count - 1; $i++) { 1090 $part .= $parts[$i] . ':'; 1091 $page = $part; 1092 if ($page == $conf['start']) continue; 1093 1094 $html .= '<li class="sep">' . $sep . '</li>'; 1095 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 1096 } 1097 1098 resolve_pageid('', $page, $exists); 1099 if (!(isset($page) && $page == $part . $parts[$i])) { 1100 $page = $part . $parts[$i]; 1101 if ($page != $conf['start']) { 1102 $html .= '<li class="sep">' . $sep . '</li>'; 1103 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 1104 } 1105 } 1106 1107 $html .= '</ul>'; 1108 } 1109 } 1110 1111 $showLast = $this->getConf('youarehereShowLast'); 1112 if ($showLast != 0) { 1113 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 1114 if (count($matches) > 0 && count($matches[0]) > ($showLast * 2) + 2) { 1115 $count = count($matches[0]); 1116 $list = ''; 1117 1118 // Show Home 1119 $list .= $matches[0][0] . $matches[0][1]; 1120 1121 $list .= '<li>...</li>'; 1122 for ($i = $count - ($showLast * 2); $i <= $count; $i++) { 1123 $list .= $matches[0][$i]; 1124 } 1125 1126 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>' . $list . '</ul>', $html); 1127 } 1128 } 1129 1130 switch ($this->getConf('youarehereHome')) { 1131 case 'none': 1132 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 1133 break; 1134 case 'home': 1135 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . tpl_getlang('home') . '$3', $html, 1); 1136 break; 1137 case 'icon': 1138 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1' . $this->mikioInlineIcon('home') . '$3', $html, 1); 1139 break; 1140 } 1141 } else { 1142 $html .= '≪ '; 1143 if (isset($_GET['page'])) { 1144 $html .= '<a href="' . wl($ID, array('do' => $ACT)) . '">Back</a> / '; 1145 } 1146 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1147 } 1148 1149 $html .= '</div>'; 1150 $html .= '</div>'; 1151 1152 if ($parse) $html = $this->includeIcons($html); 1153 if ($print) echo $html; 1154 return $html; 1155 } 1156 1157 /** 1158 * Get Page Title 1159 */ 1160 public function parsePageTitle() 1161 { 1162 global $ID; 1163 1164 $title = p_get_first_heading($ID); 1165 if (strlen($title) <= 0) $title = tpl_pagetitle(null, TRUE); 1166 $title = $this->includeIcons($title); 1167 1168 return $title; 1169 } 1170 1171 1172 /** 1173 * Print or return hero block 1174 * 1175 * @param boolean $print print content 1176 * @return string contents of hero 1177 */ 1178 public function includeHero($print = TRUE) 1179 { 1180 $html = ''; 1181 1182 if ($this->getConf('heroTitle')) { 1183 $html .= '<div class="mikio-hero">'; 1184 $html .= '<div class="mikio-container">'; 1185 $html .= '<div class="mikio-hero-text">'; 1186 if ($this->getConf('youareherePosition') == 'hero') $html .= $this->includeYouAreHere(FALSE); 1187 if ($this->getConf('breadcrumbPosition') == 'hero') $html .= $this->includeBreadcrumbs(FALSE); 1188 1189 $html .= '<h1 class="mikio-hero-title">'; 1190 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1191 $html .= '</h1>'; 1192 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1193 $html .= '</div>'; 1194 1195 $hero_image = $this->getMediaFile('hero', TRUE, $this->getConf('heroImagePropagation', TRUE)); 1196 $hero_image_resize_class = ''; 1197 if ($hero_image != '') { 1198 $hero_image = ' style="background-image:url(\'' . $hero_image . '\');"'; 1199 $hero_image_resize_class = ' mikio-hero-image-resize'; 1200 } 1201 1202 $html .= '<div class="mikio-hero-image' . $hero_image_resize_class . '"' . $hero_image . '><div class="mikio-tags"></div></div>'; 1203 1204 $html .= '</div>'; 1205 $html .= '</div>'; 1206 } 1207 1208 if ($print) echo $html; 1209 1210 return $html; 1211 } 1212 1213 1214 /** 1215 * Print or return out TOC 1216 * 1217 * @param boolean $print print TOC 1218 * @return string contents of TOC 1219 */ 1220 public function includeTOC($parse = TRUE) 1221 { 1222 $html = ''; 1223 1224 $tocHtml = tpl_toc(true); 1225 1226 if ($tocHtml != '') { 1227 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1228 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1229 1230 $html .= '<div class="mikio-toc">'; 1231 $html .= $tocHtml; 1232 $html .= '</div>'; 1233 } 1234 1235 if ($parse) $html = $this->includeIcons($html); 1236 echo $html; 1237 } 1238 1239 1240 /** 1241 * Parse the string and replace icon elements with included icon libraries 1242 * 1243 * @param string $str content to parse 1244 * @return string parsed string 1245 */ 1246 public function includeIcons($str) 1247 { 1248 global $ACT, $MIKIO_ICONS; 1249 1250 $iconTag = $this->getConf('iconTag', 'icon'); 1251 if ($iconTag == '') return $str; 1252 1253 if ($ACT == 'show' || $ACT == 'admin' && count($MIKIO_ICONS) > 0 || $ACT == 'showtag' || $ACT == 'revisions' || $ACT == 'index' || $ACT == 'preview') { 1254 $content = $str; 1255 $preview = null; 1256 1257 if ($ACT == 'preview') { 1258 $html = new \simple_html_dom; 1259 $html->stripRNAttrValues = false; 1260 $html->load($str, true, false); 1261 1262 $preview = $html->find('div.preview'); 1263 if (is_array($preview) && count($preview) > 0) { 1264 $content = $preview[0]->innertext; 1265 } 1266 } 1267 1268 $page_regex = '/(.*)/'; 1269 if (stripos($str, '<pre')) { 1270 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1271 } 1272 1273 $content = preg_replace_callback($page_regex, function ($icons) { 1274 $iconTag = $this->getConf('iconTag', 'icon'); 1275 1276 return preg_replace_callback( 1277 '/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1278 function ($matches) { 1279 global $MIKIO_ICONS; 1280 1281 $s = $matches[0]; 1282 1283 if (count($MIKIO_ICONS) > 0) { 1284 $icon = $MIKIO_ICONS[0]; 1285 1286 if (count($matches) > 1) { 1287 $e = explode(' ', $matches[1]); 1288 1289 if (count($e) > 1) { 1290 foreach ($MIKIO_ICONS as $iconItem) { 1291 if (strcasecmp($iconItem['name'], $e[0]) == 0) { 1292 $icon = $iconItem; 1293 1294 $s = $icon['insert']; 1295 for ($i = 1; $i < 9; $i++) { 1296 if (count($e) < $i || $e[$i] == '') { 1297 if (isset($icon['$' . $i])) { 1298 $s = str_replace('$' . $i, $icon['$' . $i], $s); 1299 } 1300 } else { 1301 $s = str_replace('$' . $i, $e[$i], $s); 1302 } 1303 } 1304 1305 $dir = ''; 1306 if (isset($icon['dir'])) $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1307 1308 $s = str_replace('$0', $dir, $s); 1309 1310 break; 1311 } 1312 } 1313 } else { 1314 $s = str_replace('$1', $matches[1], $icon['insert']); 1315 } 1316 } 1317 } 1318 1319 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1320 if ($count == 0) { 1321 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1322 } 1323 1324 return $s; 1325 }, 1326 $icons[0] 1327 ); 1328 }, $content); 1329 1330 if ($ACT == 'preview') { 1331 if (is_array($preview) && count($preview) > 0) { 1332 $preview[0]->innertext = $content; 1333 } 1334 1335 $str = $html->save(); 1336 $html->clear(); 1337 unset($html); 1338 } else { 1339 $str = $content; 1340 } 1341 } 1342 1343 return $str; 1344 } 1345 1346 /** 1347 * Parse HTML for theme 1348 * 1349 * @param string $content HTML content to parse 1350 * @return string Parsed content 1351 */ 1352 public function parseContent($content) 1353 { 1354 global $INPUT, $ACT; 1355 1356 // Add Mikio Section titles 1357 if ($INPUT->str('page') == 'config') { 1358 $admin_sections = array( 1359 // Section Insert Before Icon 1360 'navbar' => array('navbarUseTitleIcon', ''), 1361 'search' => array('searchButton', ''), 1362 'hero' => array('heroTitle', ''), 1363 'tags' => array('tagsConsolidate', ''), 1364 'breadcrumb' => array('breadcrumbHideHome', ''), 1365 'youarehere' => array('youareherePosition', ''), 1366 'sidebar' => array('sidebarShowLeft', ''), 1367 'toc' => array('tocFull', ''), 1368 'pagetools' => array('pageToolsFloating', ''), 1369 'footer' => array('footerCustomMenuText', ''), 1370 'license' => array('licenseType', ''), 1371 'acl' => array('includePageUseACL', ''), 1372 'sticky' => array('stickyTopHeader', ''), 1373 ); 1374 1375 foreach ($admin_sections as $section => $items) { 1376 $search = $items[0]; 1377 $icon = $items[1]; 1378 1379 // $content = preg_replace('/<tr(.*)>\s+<td(.*)>\s+<span(.*)>(tpl»mikio»' . $search . ')<\/span>/', 1380 // '<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); 1381 1382 $content = preg_replace( 1383 '/<tr(.*)>\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1384 '<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>', 1385 $content 1386 ); 1387 } 1388 } 1389 1390 if ($ACT == 'admin' && !isset($_GET['page'])) { 1391 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1392 } 1393 1394 // Page Revisions - Table Fix 1395 if (strpos($content, 'id="page__revisions"') !== FALSE) { 1396 $content = preg_replace('/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', '<span>$1</span>', $content); 1397 } 1398 1399 $html = new \simple_html_dom; 1400 $html->stripRNAttrValues = false; 1401 $html->load($content, true, false); 1402 1403 if (!$html) return $content; 1404 1405 /* Buttons */ 1406 foreach ($html->find('#config__manager button') as $node) { 1407 $c = explode(' ', $node->class); 1408 if (!in_array('mikio-button', $c)) $c[] = 'mikio-button'; 1409 $node->class = implode(' ', $c); 1410 } 1411 1412 1413 /* Buttons - Primary */ 1414 foreach ($html->find('#config__manager [type=submit]') as $node) { 1415 $c = explode(' ', $node->class); 1416 if (!in_array('mikio-primary', $c)) $c[] = 'mikio-primary'; 1417 $node->class = implode(' ', $c); 1418 } 1419 1420 /* Hide page title if hero is enabled */ 1421 if ($this->getConf('heroTitle') && $ACT != 'preview') { 1422 $pageTitle = $this->parsePageTitle(); 1423 1424 foreach ($html->find('h1,h2,h3,h4') as $elm) { 1425 if ($elm->innertext == $pageTitle) { 1426 // $elm->innertext = ''; 1427 $elm->setAttribute('style', 'display:none'); 1428 1429 break; 1430 } 1431 } 1432 } 1433 1434 /* Hero subtitle */ 1435 foreach ($html->find('p') as $elm) { 1436 $i = stripos($elm->innertext, '~~hero-subtitle'); 1437 if ($i !== false) { 1438 $j = strpos($elm->innertext, '~~', $i + 2); 1439 if ($j !== false) { 1440 if ($j > $i + 16) { 1441 $subtitle = substr($elm->innertext, $i + 16, $j - $i - 16); 1442 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle . '\')'; 1443 1444 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1445 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1446 } 1447 1448 break; 1449 } 1450 } 1451 } 1452 1453 /* Hero image */ 1454 foreach ($html->find('p') as $elm) { 1455 $image = ''; 1456 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1457 if (count($matches) > 0) { 1458 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1459 if (count($imageTagMatches) > 0) { 1460 $image = $imageTagMatches[1]; 1461 } else { 1462 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1463 if (count($imageTagMatches) > 0) { 1464 $image = $imageTagMatches[1]; 1465 } else { 1466 $image = strip_tags($matches[1]); 1467 if (stripos($image, ':') === FALSE) { 1468 $image = str_replace(array('{', '}'), '', $image); 1469 $i = stripos($image, '?'); 1470 if ($i !== FALSE) { 1471 $image = substr($image, 0, $i); 1472 } 1473 1474 $image = ml($image, '', true, '', false); 1475 } 1476 } 1477 } 1478 1479 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image . '\')'; 1480 1481 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1482 } 1483 } 1484 1485 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1486 foreach ($html->find('p') as $elm) { 1487 $i = stripos($elm->innertext, '~~hero-colors'); 1488 if ($i !== false) { 1489 $j = strpos($elm->innertext, '~~', $i + 2); 1490 if ($j !== false) { 1491 if ($j > $i + 14) { 1492 $color = substr($elm->innertext, $i + 14, $j - $i - 14); 1493 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color . '\')'; 1494 1495 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1496 } 1497 1498 break; 1499 } 1500 } 1501 } 1502 1503 /* Hide parts - ~~hide-parts [parts]~~ */ 1504 foreach ($html->find('p') as $elm) { 1505 $i = stripos($elm->innertext, '~~hide-parts'); 1506 if ($i !== false) { 1507 $j = strpos($elm->innertext, '~~', $i + 2); 1508 if ($j !== false) { 1509 if ($j > $i + 13) { 1510 $parts = explode(' ', substr($elm->innertext, $i + 13, $j - $i - 13)); 1511 $script = ''; 1512 1513 foreach ($parts as $part) { 1514 // $part = trim($part); 1515 if (strlen($part) > 0) { 1516 $script .= 'mikio.hidePart(\'' . $part . '\');'; 1517 } 1518 } 1519 1520 if (strlen($script) > 0) { 1521 $this->footerScript['hide-parts'] = $script; 1522 } 1523 1524 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1525 } 1526 1527 break; 1528 } 1529 } 1530 } 1531 1532 1533 /* Page Tags (tag plugin) */ 1534 if ($this->getConf('tagsConsolidate')) { 1535 $tags = ''; 1536 foreach ($html->find('div.tags a') as $elm) { 1537 $tags .= $elm->outertext; 1538 } 1539 1540 foreach ($html->find('div.tags') as $elm) { 1541 $elm->innertext = ''; 1542 $elm->setAttribute('style', 'display:none'); 1543 } 1544 1545 if ($tags != '') { 1546 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1547 } 1548 } 1549 1550 // Configuration Manager 1551 if ($INPUT->str('page') == 'config') { 1552 1553 // Additional save buttons 1554 foreach ($html->find('#config__manager') as $cm) { 1555 $saveButtons = ''; 1556 1557 foreach ($cm->find('p') as $elm) { 1558 $saveButtons = $elm->outertext; 1559 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1560 $elm->outertext = ''; 1561 } 1562 1563 foreach ($cm->find('fieldset') as $elm) { 1564 $elm->innertext .= $saveButtons; 1565 } 1566 } 1567 } 1568 1569 $content = $html->save(); 1570 $html->clear(); 1571 unset($html); 1572 1573 return $content; 1574 } 1575 1576 1577 /** 1578 * Get DokuWiki namespace/page/URI as link 1579 * 1580 * @param string $str string to parse 1581 * @return string parsed uri 1582 */ 1583 public function getLink($str) 1584 { 1585 $i = strpos($str, '://'); 1586 if ($i !== false) return $str; 1587 1588 return wl($str); 1589 } 1590 1591 1592 /** 1593 * Check if the user can edit current namespace/page 1594 * 1595 * @return boolean user can edit 1596 */ 1597 public function userCanEdit() 1598 { 1599 global $INFO; 1600 global $ID; 1601 1602 $wiki_file = wikiFN($ID); 1603 if (@!file_exists($wiki_file)) return true; 1604 if ($INFO['isadmin'] || $INFO['ismanager']) return true; 1605 // $meta_file = metaFN($ID, '.meta'); 1606 if (!$INFO['meta']['user']) return true; 1607 if ($INFO['client'] == $INFO['meta']['user']) return true; 1608 1609 return false; 1610 } 1611 1612 1613 /** 1614 * Search for and return the uri of a media file 1615 * 1616 * @param string $image image name to search for (without extension) 1617 * @param bool $searchCurrentNS search the current namespace 1618 * @return string uri of the found media file 1619 */ 1620 public function getMediaFile($image, $searchCurrentNS = TRUE, $propagate = TRUE) 1621 { 1622 global $INFO; 1623 1624 $ext = array('png', 'jpg', 'gif', 'svg'); 1625 1626 if ($searchCurrentNS) $prefix[] = ':' . $INFO['namespace'] . ':'; 1627 if ($propagate) { 1628 $prefix[] = ':'; 1629 $prefix[] = ':wiki:'; 1630 } 1631 $theme = $this->getConf('customTheme'); 1632 if ($theme != '') $prefix[] = $this->tplDir . 'themes/' . $theme . '/images/'; 1633 $prefix[] = 'images/'; 1634 1635 $search = array(); 1636 foreach ($prefix as $pitem) { 1637 foreach ($ext as $eitem) { 1638 $search[] = $pitem . $image . '.' . $eitem; 1639 } 1640 } 1641 1642 $img = ''; 1643 $file = ''; 1644 $url = ''; 1645 $ismedia = false; 1646 $found = false; 1647 1648 foreach ($search as $img) { 1649 if (substr($img, 0, 1) == ':') { 1650 $file = mediaFN($img); 1651 $ismedia = true; 1652 } else { 1653 $file = tpl_incdir() . $img; 1654 $ismedia = false; 1655 } 1656 1657 if (file_exists($file)) { 1658 $found = true; 1659 break; 1660 } 1661 } 1662 1663 if (!$found) return false; 1664 1665 if ($ismedia) { 1666 $url = ml($img, '', true, '', false); 1667 } else { 1668 $url = tpl_basedir() . $img; 1669 } 1670 1671 return $url; 1672 } 1673 1674 1675 /** 1676 * Print or return the page title 1677 * 1678 * @param string $page page id or empty string for current page 1679 * @return string generated content 1680 */ 1681 public function getPageTitle($page = '') 1682 { 1683 global $ID, $conf; 1684 1685 $html = ''; 1686 1687 if ($page == '') $page = $ID; 1688 1689 $html = p_get_first_heading($page); 1690 $html = strip_tags($html); 1691 $html = preg_replace('/\s+/', ' ', $html); 1692 $html .= ' [' . strip_tags($conf['title']) . ']'; 1693 $html = trim($html); 1694 1695 return $html; 1696 } 1697 1698 1699 /** 1700 * Return inline theme icon 1701 * 1702 * @param string $type icon to retreive 1703 * @return string html icon content 1704 */ 1705 public function mikioInlineIcon($type) 1706 { 1707 switch ($type) { 1708 case 'wrench': 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,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>'; 1710 case 'file': 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,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>'; 1712 case 'gear': 1713 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>'; 1714 case 'user': 1715 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>'; 1716 case 'search': 1717 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>'; 1718 case 'home': 1719 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>'; 1720 } 1721 1722 return ''; 1723 } 1724 1725 /** 1726 * Finalize theme 1727 */ 1728 public function finalize() 1729 { 1730 } 1731 1732 /** 1733 * Show Messages 1734 */ 1735 public function showMessages() 1736 { 1737 global $ACT; 1738 1739 if ($this->lessIgnored) { 1740 msg('useLESS is enabled on the Mikio template, however is not supported on this server', 2, '', '', MSG_ADMINS_ONLY); 1741 } 1742 1743 $show = $this->getConf('showNotifications'); 1744 if ($show == 'always' || ($show == 'admin' && $ACT == 'admin')) { 1745 global $MSG, $MSG_shown; 1746 1747 if (!isset($MSG)) { 1748 return; 1749 } 1750 1751 if (!isset($MSG_shown)) { 1752 $MSG_shown = array(); 1753 } 1754 1755 foreach ($MSG as $msg) { 1756 1757 $hash = md5($msg['msg']); 1758 if (isset($MSG_shown[$hash])) { 1759 continue; 1760 } 1761 // skip double messages 1762 1763 if (info_msg_allowed($msg)) { 1764 1765 print '<div class="' . $msg['lvl'] . '">'; 1766 print $msg['msg']; 1767 print '</div>'; 1768 } 1769 1770 $MSG_shown[$hash] = true; 1771 } 1772 1773 unset($GLOBALS['MSG']); 1774 } 1775 } 1776 1777 /** 1778 * Dokuwiki version 1779 * 1780 * @return string the dw version name 1781 */ 1782 public function dwVersion() { 1783 if(function_exists('getVersionData')) { 1784 $version_data = getVersionData(); 1785 if(is_array($version_data) && array_key_exists('date', $version_data)) { 1786 $version_items = explode(' ', $version_data['date']); 1787 if(count($version_items) >= 2) { 1788 return preg_replace('/[^a-zA-Z0-9 ]+/', '', strtolower($version_items[1])); 1789 } 1790 } 1791 } 1792 1793 return 'unknown'; 1794 } 1795 1796 /** 1797 * Dokuwiki version number 1798 * 1799 * @return string the dw version date converted to integer 1800 */ 1801 public function dwVersionNumber() { 1802 if(function_exists('getVersionData')) { 1803 $version_data = getVersionData(); 1804 if(is_array($version_data) && array_key_exists('date', $version_data)) { 1805 $version_items = explode(' ', $version_data['date']); 1806 if(count($version_items) >= 1) { 1807 return intval(preg_replace('/[^0-9]+/', '', strtolower($version_items[0]))); 1808 } 1809 } 1810 } 1811 1812 return 0; 1813 } 1814} 1815 1816global $TEMPLATE; 1817$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 1818