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