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