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 $html = ''; 579 580 $html .= '<nav class="mikio-navbar">'; 581 $html .= '<a class="mikio-navbar-brand" href="' . wl() . '">'; 582 if($this->getConf('navbarUseTitleIcon') || $this->getConf('navbarUseTitleText')) { 583 584 // Brand image 585 if($this->getConf('navbarUseTitleIcon')) { 586 $logo = $this->getMediaFile('logo', FALSE);; 587 if($logo != '') { 588 $html .= '<img src="' . $logo . '" class="mikio-navbar-brand-image">'; 589 } 590 } 591 592 // Brand title 593 if($this->getConf('navbarUseTitleText')) { 594 $html .= '<div class="mikio-navbar-brand-title">'; 595 $html .= '<h1 class="mikio-navbar-brand-title-text">' . $conf['title'] . '</h1>'; 596 if($this->getConf('navbarUseTaglineText')) { 597 $html .= '<p class="claim mikio-navbar-brand-title-tagline">' . $conf['tagline'] . '</p>'; 598 } 599 $html .= '</div>'; 600 } 601 } 602 $html .= '</a>'; 603 $html .= '<div class="mikio-navbar-toggle"></div>'; 604 605 // Menus 606 $html .= '<div class="mikio-navbar-collapse">'; 607 608 $menus = array($this->getConf('navbarPosLeft', 'none'), $this->getConf('navbarPosMiddle', 'none'), $this->getConf('navbarPosRight', 'none')); 609 foreach($menus as $menuType) { 610 switch($menuType) { 611 case 'custom': 612 $html .= $this->stringToNav($this->getConf('navbarCustomMenuText', '')); 613 break; 614 case 'search': 615 $html .= '<div class="mikio-nav-item">'; 616 $html .= $this->includeSearch(false); 617 $html .= '</div>'; 618 break; 619 case 'dokuwiki': 620 $html .= $this->includeDWMenu(FALSE); 621 break; 622 } 623 } 624 625 $html .= '</div>'; 626 627 $html .= '</nav>'; 628 629 // Sub Navbar 630 if($showSub) { 631 $sub = $this->includePage('submenu', FALSE); 632 if($sub != '') $html .= '<nav class="mikio-navbar mikio-sub-navbar">' . $sub . '</nav>'; 633 } 634 635 if($print) echo $html; 636 return $html; 637 } 638 639 640 /** 641 * Is there a sidebar 642 * 643 * @param string $prefix sidebar prefix to use when searching 644 * @return boolean if sidebar exists 645 */ 646 public function sidebarExists($prefix = '') { 647 global $conf; 648 649 if($prefix == 'left') $prefix = ''; 650 651 return $this->pageExists($conf['sidebar' . $prefix]); 652 } 653 654 655 /** 656 * Print or return the sidebar content 657 * 658 * @param string $prefix sidebar prefix to use when searching 659 * @param boolean $print print the generated content to the output buffer 660 * @param boolean $parse parse the content 661 * @return string generated content 662 */ 663 public function includeSidebar($prefix = '', $print = TRUE, $parse = TRUE) { 664 global $conf, $ID; 665 666 $html = ''; 667 $confPrefix = preg_replace('/[^a-zA-Z0-9]/', '', ucwords($prefix)); 668 $prefix = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($prefix)); 669 670 if($confPrefix == '') $confPrefix = 'Left'; 671 if($prefix == 'Left') $prefix = ''; 672 673 $sidebarPage = $conf[$prefix . 'sidebar'] == '' ? $prefix . 'sidebar' : $conf[$prefix . 'sidebar']; 674 675 if($this->getConf('sidebarShow' . $confPrefix) && page_findnearest($sidebarPage) != FALSE && p_get_metadata($ID, 'nosidebar', FALSE) == FALSE) { 676 $content = $this->includePage($sidebarPage . 'header', FALSE); 677 if($content != '') $html .= '<div class="mikio-sidebar-header">' . $content . '</div>'; 678 679 if($prefix == '') { 680 $rows = array($this->getConf('sidebarLeftRow1'), $this->getConf('sidebarLeftRow2'), $this->getConf('sidebarLeftRow3'), $this->getConf('sidebarLeftRow4')); 681 682 foreach($rows as $row) { 683 switch($row) { 684 case 'search': 685 $html .= $this->includeSearch(FALSE); 686 break; 687 case 'logged in user': 688 $html .= $this->includeLoggedIn(FALSE); 689 break; 690 case 'content': 691 $content = $this->includePage($sidebarPage, FALSE); 692 if($content != '') $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 693 break; 694 case 'tags': 695 $html .= '<div class="mikio-tags"></div>'; 696 } 697 } 698 } else { 699 $content = $this->includePage($sidebarPage, FALSE); 700 if($content != '') $html .= '<div class="mikio-sidebar-content">' . $content . '</div>'; 701 } 702 703 $content = $this->includePage($sidebarPage . 'footer', FALSE); 704 if($content != '') $html .= '<div class="mikio-sidebar-footer">' . $content . '</div>'; 705 } 706 707 if($html == '') { 708 if($prefix == '' && $this->getConf('sidebarAlwaysShowLeft')) $html = ' '; 709 if($this->getConf('sidebarAlwaysShow' . ucfirst($prefix))) $html = ' '; 710 } 711 712 if($html != '') { 713 $html = '<aside class="mikio-sidebar mikio-sidebar-' . ($prefix == '' ? 'left' : $prefix) . '"><a class="mikio-sidebar-toggle' . ($this->getConf('sidebarMobileDefaultCollapse') ? ' closed' : '') . '" href="#">' . tpl_getLang('sidebar-title') . '</a><div class="mikio-sidebar-collapse">'. $html . '</div></aside>'; 714 } 715 716 if($parse) $html = $this->includeIcons($html); 717 if($print) echo $html; 718 return $html; 719 } 720 721 722 /** 723 * Print or return the page tools content 724 * 725 * @param boolean $print print the generated content to the output buffer 726 * @param boolean $includeId include the dw__pagetools id in the element 727 * @return string generated content 728 */ 729 public function includePageTools($print = TRUE, $includeId = FALSE) { 730 $html = ''; 731 732 $html .= '<nav' . ($includeId ? ' id="dw__pagetools"' : '') . ' class="hidden-print dw__pagetools">'; 733 $html .= '<ul>'; 734 735 $items = (new \dokuwiki\Menu\PageMenu())->getItems(); 736 foreach($items as $item) { 737 $classes = array(); 738 $classes[] = $item->getType(); 739 $attr = $item->getLinkAttributes(); 740 741 if(!empty($attr['class'])) { 742 $classes = array_merge($classes, explode(' ', $attr['class'])); 743 } 744 745 $classes = array_unique($classes); 746 747 $html .= '<li class="'.implode(' ', $classes).'">'; 748 $html .= '<a href="'.$item->getLink().'" title="'.$item->getTitle().'"><span class="icon">'.inlineSVG($item->getSvg()).'</span><span class="a11y">'.$item->getLabel().'</span></a>'; 749 $html .= '</li>'; 750 } 751 752 $html .= '</ul>'; 753 $html .= '</nav>'; 754 755 if($print) echo $html; 756 return $html; 757 } 758 759 760 /** 761 * Print or return the search bar 762 * 763 * @param boolean $print print content 764 * @return string contents of the search bar 765 */ 766 public function includeSearch($print = TRUE) { 767 global $lang, $ID; 768 $html = ''; 769 770 $html .= '<form class="mikio-search search" action="' . wl() . '" accept-charset="utf-8" method="get" role="search">'; 771 $html .= '<input type="hidden" name="do" value="search">'; 772 $html .= '<input type="hidden" name="id" value="' . $ID . '">'; 773 $html .= '<input name="q" autocomplete="off" type="search" placeholder="' . $lang['btn_search'] . '" value="' . (($ACT == 'search') ? htmlspecialchars($QUERY) : '') . '" accesskey="f" title="[F]" />'; 774 $html .= '<button type="submit" title="' . $lang['btn_search'] . '">'; 775 if($this->getConf('searchButton') == 'icon') { 776 $html .= $this->mikioInlineIcon('search'); 777 } else { 778 $html .= $lang['btn_search']; 779 } 780 $html .= '</button>'; 781 $html .= '</form>'; 782 783 784 785 if($print) print $html; 786 return $html; 787 } 788 789 790 /** 791 * Print or return content 792 * 793 * @param boolean $print print content 794 * @return string contents 795 */ 796 public function includeContent($print = TRUE) { 797 ob_start(); 798 tpl_content(FALSE); 799 $html = ob_get_contents(); 800 ob_end_clean(); 801 802 $html = $this->includeIcons($html); 803 $html = $this->parseContent($html); 804 805 $html .= '<div style="clear:both"></div>'; 806 807 if(!$this->getConf('heroTitle')) $html = '<div class="mikio-tags"></div>' . $html; 808 809 $html = '<div class="mikio-article-content">' . $html . '</div>'; 810 811 if($print) echo $html; 812 return $html; 813 } 814 815 /** 816 * Print or return footer 817 * 818 * @param boolean $print print footer 819 * @return string html string containing footer 820 */ 821 public function includeFooter($print = TRUE) { 822 global $ACT; 823 824 $html = ''; 825 826 $html .= '<footer class="mikio-footer">'; 827 $html .= '<div class="doc">' . tpl_pageinfo(TRUE) . '</div>'; 828 $html .= $this->includePage('footer', FALSE); 829 830 $html .= $this->stringToNav($this->getConf('footerCustomMenuText')); 831 832 if($this->getConf('footerSearch')) { 833 $html .= '<div class="mikio-footer-search">'; 834 $html .= $this->includeSearch(FALSE); 835 $html .= '</div>'; 836 } 837 838 $showPageTools = $this->getConf('pageToolsFooter'); 839 if ($ACT == 'show' && ($showPageTools == 'always' || $this->userCanEdit() && $showPageTools == 'page editors')) $html .= $this->includePageTools(FALSE); 840 841 $meta['licenseType'] = array('multichoice', '_choices' => array('none', 'badge', 'button')); 842 $meta['licenseImageOnly'] = array('onoff'); 843 844 $licenseType = $this->getConf('licenseType'); 845 if($licenseType != 'none') { 846 $html .= tpl_license($licenseType, $this->getConf('licenseImageOnly'), TRUE, TRUE); 847 } 848 849 $html .= '</footer>'; 850 851 if($print) echo $html; 852 return $html; 853 } 854 855 856 /** 857 * Print or return breadcrumb trail 858 * 859 * @param boolean $print print out trail 860 * @param boolean $parse parse trail before printing 861 * @return string html string containing breadcrumbs 862 */ 863 public function includeBreadcrumbs($print = TRUE, $parse = TRUE) { 864 global $conf, $ID, $lang, $ACT; 865 866 if($this->getConf('breadcrumbHideHome') && $ID == 'start' && $ACT == 'show' || $ACT == 'showtag') return ''; 867 868 $html = '<div class="mikio-breadcrumbs">'; 869 if($ACT == 'show') { 870 if($conf['breadcrumbs']) { 871 if(!$this->getConf('breadcrumbPrefix') && !$this->getConf('breadcrumbSep')) { 872 ob_start(); 873 tpl_breadcrumbs(); 874 $html .= ob_get_contents(); 875 ob_end_clean(); 876 } else { 877 $sep = '•'; 878 $prefix = $lang['breadcrumb']; 879 880 if($this->getConf('breadcrumbSep')) { 881 $sep = $this->getConf('breadcrumbSepText'); 882 $img = $this->getMediaFile('breadcrumb-sep', FALSE); 883 884 if($img !== FALSE) { 885 $sep = '<img src="' . $img . '">'; 886 } 887 } 888 889 if($this->getConf('breadcrumbPrefix')) { 890 $prefix = $this->getConf('breadcrumbPrefixText'); 891 $img = $this->getMediaFile('breadcrumb-prefix', FALSE); 892 893 if($img !== FALSE) { 894 $prefix = '<img src="' . $img . '">'; 895 } 896 } 897 898 $crumbs = breadcrumbs(); 899 900 $html .= '<ul>'; 901 if($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 902 903 $last = count($crumbs); 904 $i = 0; 905 foreach($crumbs as $id => $name) { 906 $i++; 907 $html .= '<li class="sep">' . $sep . '</li>'; 908 $html .= '<li' . ($i == $last ? ' class="curid"' : '') . '>'; 909 $html .= tpl_pagelink($id, NULL, TRUE); 910 $html .= '</li>'; 911 } 912 913 $html .= '</ul>'; 914 } 915 } else if($conf['youarehere']) { 916 if(!$this->getConf('breadcrumbPrefix') && !$this->getConf('breadcrumbSep')) { 917 ob_start(); 918 tpl_youarehere(); 919 $html .= ob_get_contents(); 920 ob_end_clean(); 921 } else { 922 $sep = ' » '; 923 $prefix = $lang['youarehere']; 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 $html .= '<ul>'; 944 if($prefix != '') $html .= '<li class="prefix">' . $prefix . '</li>'; 945 $html .= '<li>' . tpl_pagelink(':'.$conf['start'], NULL, TRUE) . '</li>'; 946 947 $parts = explode(':', $ID); 948 $count = count($parts); 949 950 $part = ''; 951 for($i = 0; $i < $count - 1; $i++) { 952 $part .= $parts[$i].':'; 953 $page = $part; 954 if($page == $conf['start']) continue; 955 956 $html .= '<li class="sep">' . $sep . '</li>'; 957 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 958 } 959 960 resolve_pageid('', $page, $exists); 961 if(!(isset($page) && $page == $part.$parts[$i])) { 962 $page = $part.$parts[$i]; 963 if($page != $conf['start']) { 964 $html .= '<li class="sep">' . $sep . '</li>'; 965 $html .= '<li>' . tpl_pagelink($page, NULL, TRUE) . '</li>'; 966 } 967 } 968 969 $html .= '</ul>'; 970 } 971 } 972 973 $showLast = $this->getConf('breadcrumbShowLast'); 974 if($showLast != 0) { 975 preg_match_all('/(<li[^>]*>.+?<\/li>)/', $html, $matches); 976 if(count($matches) > 0 && count($matches[0]) > ($showLast * 2) + 2) { 977 $count = count($matches[0]); 978 $list = ''; 979 980 // Show Home 981 $list .= $matches[0][0] . $matches[0][1]; 982 983 $list .= '<li>...</li>'; 984 for($i = $count - ($showLast * 2); $i <= $count; $i++) { 985 $list .= $matches[0][$i]; 986 } 987 988 $html = preg_replace('/<ul>.*<\/ul>/', '<ul>'.$list.'</ul>', $html); 989 } 990 } 991 992 switch($this->getConf('breadcrumbHome')) { 993 case 'none': 994 $html = preg_replace('/<li[^>]*>.+?<\/li>/', '', $html, 2); 995 break; 996 case 'home': 997 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1'.tpl_getlang('home').'$3', $html, 1); 998 break; 999 case 'icon': 1000 $html = preg_replace('/(<a[^>]*>)(.+?)(<\/a>)/', '$1'.$this->mikioInlineIcon('home').'$3', $html, 1); 1001 break; 1002 } 1003 } else { 1004 $html .= '≪ '; 1005 if(isset($_GET['page'])) { 1006 $html .= '<a href="' . wl($ID, array('do' => $ACT)) . '">Back</a> / '; 1007 } 1008 $html .= '<a href="' . wl($ID) . '">View Page</a>'; 1009 } 1010 1011 $html .= '</div>'; 1012 1013 if($parse) $html = $this->includeIcons($html); 1014 if($print) echo $html; 1015 return $html; 1016 } 1017 1018 /** 1019 * Get Page Title 1020 */ 1021 public function parsePageTitle() { 1022 global $ID; 1023 1024 $title = p_get_first_heading($ID); 1025 if(strlen($title) <= 0) $title = tpl_pagetitle(null, TRUE); 1026 $title = $this->includeIcons($title); 1027 1028 return $title; 1029 } 1030 1031 1032 /** 1033 * Print or return hero block 1034 * 1035 * @param boolean $print print content 1036 * @return string contents of hero 1037 */ 1038 public function includeHero($print = TRUE) { 1039 $html = ''; 1040 1041 if($this->getConf('heroTitle')) { 1042 $html .= '<div class="mikio-hero">'; 1043 $html .= '<div class="mikio-hero-text">'; 1044 if ($this->getConf('breadcrumbPosition') == 'hero') $html .= $this->includeBreadcrumbs(FALSE); 1045 1046 $html .= '<h1 class="mikio-hero-title">'; 1047 $html .= $this->parsePageTitle(); // No idea why this requires a blank space afterwards to work? 1048 $html .= '</h1>'; 1049 $html .= '<h2 class="mikio-hero-subtitle"></h2>'; 1050 $html .= '</div>'; 1051 1052 $hero_image = $this->getMediaFile('hero', TRUE, $this->getConf('heroImagePropagation', TRUE)); 1053 $hero_image_resize_class = ''; 1054 if($hero_image != '') { 1055 $hero_image = ' style="background-image:url(\''.$hero_image.'\');"'; 1056 $hero_image_resize_class = ' mikio-hero-image-resize'; 1057 } 1058 1059 $html .= '<div class="mikio-hero-image'. $hero_image_resize_class . '"' . $hero_image . '><div class="mikio-tags"></div></div>'; 1060 1061 $html .= '</div>'; 1062 } 1063 1064 if($print) echo $html; 1065 1066 return $html; 1067 } 1068 1069 1070 /** 1071 * Print or return out TOC 1072 * 1073 * @param boolean $print print TOC 1074 * @return string contents of TOC 1075 */ 1076 public function includeTOC($parse = TRUE) { 1077 $html = ''; 1078 1079 $tocHtml = tpl_toc(true); 1080 1081 if($tocHtml != '') { 1082 $tocHtml = preg_replace('/<li.*><div.*><a.*><\/a><\/div><\/li>\s*/', '', $tocHtml); 1083 $tocHtml = preg_replace('/<ul.*>\s*<\/ul>\s*/', '', $tocHtml); 1084 1085 $html .= '<div class="mikio-toc">'; 1086 $html .= $tocHtml; 1087 $html .= '</div>'; 1088 } 1089 1090 if($parse) $html = $this->includeIcons($html); 1091 echo $html; 1092 } 1093 1094 1095 /** 1096 * Parse the string and replace icon elements with included icon libraries 1097 * 1098 * @param string $str content to parse 1099 * @return string parsed string 1100 */ 1101 public function includeIcons($str) { 1102 global $ACT, $MIKIO_ICONS; 1103 1104 $iconTag = $this->getConf('iconTag', 'icon'); 1105 if($iconTag == '') return $str; 1106 1107 if($ACT == 'show' || $ACT == 'admin' && count($MIKIO_ICONS) > 0 || $ACT == 'showtag' || $ACT == 'revisions' || $ACT == 'index' || $ACT == 'preview') { 1108 $content = $str; 1109 $preview = null; 1110 1111 if($ACT == 'preview') { 1112 $html = new \simple_html_dom; 1113 $html->stripRNAttrValues = false; 1114 $html->load($str, true, false); 1115 1116 $preview = $html->find('div.preview'); 1117 if(is_array($preview) && count($preview) > 0) { 1118 $content = $preview[0]->innertext; 1119 } 1120 } 1121 1122 $page_regex = '/(.*)/'; 1123 if(stripos($str, '<pre')) { 1124 $page_regex = '/<(?!pre|\/).*?>(.*)[^<]*/'; 1125 } 1126 1127 $content = preg_replace_callback($page_regex, function($icons) { 1128 $iconTag = $this->getConf('iconTag', 'icon'); 1129 1130 return preg_replace_callback('/<' . $iconTag . ' ([\w\- #]*)>(?=[^>]*(<|$))/', 1131 function ($matches) { 1132 global $MIKIO_ICONS; 1133 1134 $s = $matches[0]; 1135 1136 if(count($MIKIO_ICONS) > 0) { 1137 $icon = $MIKIO_ICONS[0]; 1138 1139 if(count($matches) > 1) { 1140 $e = explode(' ', $matches[1]); 1141 1142 if(count($e) > 1) { 1143 foreach($MIKIO_ICONS as $iconItem) { 1144 if(strcasecmp($iconItem['name'], $e[0]) == 0) { 1145 $icon = $iconItem; 1146 1147 $s = $icon['insert']; 1148 for($i = 1; $i < 9; $i++) { 1149 if(count($e) < $i || $e[$i] == '') { 1150 if(isset($icon['$'.$i])) { 1151 $s = str_replace('$' . $i, $icon['$'.$i], $s); 1152 } 1153 } else { 1154 $s = str_replace('$' . $i, $e[$i], $s); 1155 } 1156 } 1157 1158 $dir = ''; 1159 if(isset($icon['dir'])) $dir = $this->baseDir . 'icons/' . $icon['dir'] . '/'; 1160 1161 $s = str_replace('$0', $dir, $s); 1162 1163 break; 1164 } 1165 } 1166 } else { 1167 $s = str_replace('$1', $matches[1], $icon['insert']); 1168 } 1169 } 1170 } 1171 1172 $s = preg_replace('/(class=")(.*)"/', '$1mikio-icon $2"', $s, -1, $count); 1173 if($count == 0) { 1174 $s = preg_replace('/(<\w* )/', '$1class="mikio-icon" ', $s); 1175 } 1176 1177 return $s; 1178 }, 1179 $icons[0]); 1180 1181 }, $content); 1182 1183 if($ACT == 'preview') { 1184 if(is_array($preview) && count($preview) > 0) { 1185 $preview[0]->innertext = $content; 1186 } 1187 1188 $str = $html->save(); 1189 $html->clear(); 1190 unset($html); 1191 } else { 1192 $str = $content; 1193 } 1194 } 1195 1196 return $str; 1197 } 1198 1199 /** 1200 * Parse HTML for theme 1201 * 1202 * @param string $content HTML content to parse 1203 * @return string Parsed content 1204 */ 1205 public function parseContent($content) { 1206 global $INPUT, $ACT; 1207 1208 // Add Mikio Section titles 1209 if($INPUT->str('page') == 'config') { 1210 $admin_sections = array( 1211 // Section Insert Before Icon 1212 'navbar' => array('navbarUseTitleIcon', ''), 1213 'search' => array('searchButton', ''), 1214 'hero' => array('heroTitle', ''), 1215 'tags' => array('tagsConsolidate', ''), 1216 'breadcrumb' => array('breadcrumbHideHome', ''), 1217 'sidebar' => array('sidebarShowLeft', ''), 1218 'toc' => array('tocFull', ''), 1219 'pagetools' => array('pageToolsFloating', ''), 1220 'footer' => array('footerCustomMenuText', ''), 1221 'license' => array('licenseType', ''), 1222 'acl' => array('includePageUseACL', ''), 1223 ); 1224 1225 foreach ($admin_sections as $section => $items) { 1226 $search = $items[0]; 1227 $icon = $items[1]; 1228 1229 // $content = preg_replace('/<tr(.*)>\s+<td(.*)>\s+<span(.*)>(tpl»mikio»' . $search . ')<\/span>/', 1230 // '<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); 1231 1232 $content = preg_replace('/<tr class="default">\s*<td class="label">\s*<span class="outkey">(tpl»mikio»' . $search . ')<\/span>/', 1233 '<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); 1234 1235 } 1236 } 1237 1238 if($ACT == 'admin' && !isset($_GET['page'])) { 1239 $content = preg_replace('/(<ul.*?>.*?)<\/ul>.*?<ul.*?>(.*?<\/ul>)/s', '$1$2', $content); 1240 } 1241 1242 // Page Revisions - Table Fix 1243 if(strpos($content, 'id="page__revisions"') !== FALSE) { 1244 $content = preg_replace('/(<span class="sum">\s.*<\/span>\s.*<span class="user">\s.*<\/span>)/', '<span>$1</span>', $content); 1245 } 1246 1247 $html = new \simple_html_dom; 1248 $html->stripRNAttrValues = false; 1249 $html->load($content, true, false); 1250 1251 if (!$html) return $content; 1252 1253 /* Buttons */ 1254 foreach($html->find('#config__manager button') as $node) { 1255 $c = explode(' ', $node->class); 1256 if(!in_array('mikio-button', $c)) $c[] = 'mikio-button'; 1257 $node->class = implode(' ', $c); 1258 } 1259 1260 1261 /* Buttons - Primary */ 1262 foreach($html->find('#config__manager [type=submit]') as $node) { 1263 $c = explode(' ', $node->class); 1264 if(!in_array('mikio-primary', $c)) $c[] = 'mikio-primary'; 1265 $node->class = implode(' ', $c); 1266 } 1267 1268 /* Hide page title if hero is enabled */ 1269 if($this->getConf('heroTitle') && $ACT != 'preview') { 1270 $pageTitle = $this->parsePageTitle(); 1271 1272 foreach($html->find('h1,h2,h3,h4') as $elm) { 1273 if($elm->innertext == $pageTitle) { 1274 // $elm->innertext = ''; 1275 $elm->setAttribute('style', 'display:none'); 1276 1277 break; 1278 } 1279 } 1280 } 1281 1282 /* Hero subtitle */ 1283 foreach($html->find('p') as $elm) { 1284 $i = stripos($elm->innertext, '~~hero-subtitle'); 1285 if($i !== false) { 1286 $j = strpos($elm->innertext, '~~', $i + 2); 1287 if($j !== false) { 1288 if($j > $i + 16) { 1289 $subtitle = substr($elm->innertext, $i + 16, $j - $i - 16); 1290 $this->footerScript['hero-subtitle'] = 'mikio.setHeroSubTitle(\'' . $subtitle .'\')'; 1291 1292 // $elm->innertext = substr($elm->innertext, 0, $i + 2) . substr($elm->innertext, $j + 2); 1293 $elm->innertext = preg_replace('/~~hero-subtitle (.+?)~~.*/ui', '', $elm->innertext); 1294 } 1295 1296 break; 1297 } 1298 } 1299 } 1300 1301 /* Hero image */ 1302 foreach($html->find('p') as $elm) { 1303 $image = ''; 1304 preg_match('/~~hero-image (.+?)~~(?!.?")/ui', $elm->innertext, $matches); 1305 if(count($matches) > 0) { 1306 preg_match('/<img.*src="(.+?)"/ui', $matches[1], $imageTagMatches); 1307 if(count($imageTagMatches) > 0) { 1308 $image = $imageTagMatches[1]; 1309 } else { 1310 preg_match('/<a.+?>(.+?)[~<]/ui', $matches[1], $imageTagMatches); 1311 if(count($imageTagMatches) > 0) { 1312 $image = $imageTagMatches[1]; 1313 } else { 1314 $image = strip_tags($matches[1]); 1315 if(stripos($image, ':') === FALSE) { 1316 $image = str_replace(array('{', '}'), '', $image); 1317 $i = stripos($image, '?'); 1318 if($i !== FALSE) { 1319 $image = substr($image, 0, $i); 1320 } 1321 1322 $image = ml($image, '', true, '', false); 1323 } 1324 } 1325 } 1326 1327 $this->footerScript['hero-image'] = 'mikio.setHeroImage(\'' . $image .'\')'; 1328 1329 $elm->innertext = preg_replace('/~~hero-image (.+?)~~.*/ui', '', $elm->innertext); 1330 1331 } 1332 } 1333 1334 /* Hero colors - ~~hero-colors [background-color] [hero-title-color] [hero-subtitle-color] [breadcrumb-text-color] [breadcrumb-hover-color] (use 'initial' for original color) */ 1335 foreach($html->find('p') as $elm) { 1336 $i = stripos($elm->innertext, '~~hero-colors'); 1337 if($i !== false) { 1338 $j = strpos($elm->innertext, '~~', $i + 2); 1339 if($j !== false) { 1340 if($j > $i + 14) { 1341 $color = substr($elm->innertext, $i + 14, $j - $i - 14); 1342 $this->footerScript['hero-colors'] = 'mikio.setHeroColor(\'' . $color .'\')'; 1343 1344 $elm->innertext = preg_replace('/~~hero-colors (.+?)~~.*/ui', '', $elm->innertext); 1345 } 1346 1347 break; 1348 } 1349 } 1350 } 1351 1352 /* Hide parts - ~~hide-parts [parts]~~ */ 1353 foreach($html->find('p') as $elm) { 1354 $i = stripos($elm->innertext, '~~hide-parts'); 1355 if($i !== false) { 1356 $j = strpos($elm->innertext, '~~', $i + 2); 1357 if($j !== false) { 1358 if($j > $i + 13) { 1359 $parts = explode(' ', substr($elm->innertext, $i + 13, $j - $i - 13)); 1360 $script = ''; 1361 1362 foreach($parts as $part) { 1363 // $part = trim($part); 1364 if(strlen($part) > 0) { 1365 $script .= 'mikio.hidePart(\'' . $part .'\');'; 1366 } 1367 } 1368 1369 if(strlen($script) > 0) { 1370 $this->footerScript['hide-parts'] = $script; 1371 } 1372 1373 $elm->innertext = preg_replace('/~~hide-parts (.+?)~~.*/ui', '', $elm->innertext); 1374 } 1375 1376 break; 1377 } 1378 } 1379 } 1380 1381 1382 /* Page Tags (tag plugin) */ 1383 if($this->getConf('tagsConsolidate')) { 1384 $tags = ''; 1385 foreach($html->find('div.tags a') as $elm) { 1386 $tags .= $elm->outertext; 1387 } 1388 1389 foreach($html->find('div.tags') as $elm) { 1390 $elm->innertext = ''; 1391 $elm->setAttribute('style', 'display:none'); 1392 } 1393 1394 if($tags != '') { 1395 $this->footerScript['tags'] = 'mikio.setTags(\'' . $tags . '\')'; 1396 } 1397 } 1398 1399 // Configuration Manager 1400 if($INPUT->str('page') == 'config') { 1401 1402 // Additional save buttons 1403 foreach ($html->find('#config__manager') as $cm) { 1404 $saveButtons = ''; 1405 1406 foreach($cm->find('p') as $elm) { 1407 $saveButtons = $elm->outertext; 1408 $saveButtons = str_replace('<p>', '<p style="text-align:right">', $saveButtons); 1409 $elm->outertext = ''; 1410 } 1411 1412 foreach($cm->find('fieldset') as $elm) { 1413 $elm->innertext .= $saveButtons; 1414 } 1415 } 1416 1417 } 1418 1419 $content = $html->save(); 1420 $html->clear(); 1421 unset($html); 1422 1423 return $content; 1424 } 1425 1426 1427 /** 1428 * Get DokuWiki namespace/page/URI as link 1429 * 1430 * @param string $str string to parse 1431 * @return string parsed uri 1432 */ 1433 public function getLink($str) { 1434 $i = strpos($str, '://'); 1435 if($i !== false) return $str; 1436 1437 return wl($str); 1438 } 1439 1440 1441 /** 1442 * Check if the user can edit current namespace/page 1443 * 1444 * @return boolean user can edit 1445 */ 1446 public function userCanEdit() { 1447 global $INFO; 1448 global $ID; 1449 1450 $wiki_file = wikiFN($ID); 1451 if (@!file_exists($wiki_file)) return true; 1452 if ($INFO['isadmin'] || $INFO['ismanager']) return true; 1453 // $meta_file = metaFN($ID, '.meta'); 1454 if (!$INFO['meta']['user']) return true; 1455 if ($INFO['client'] == $INFO['meta']['user']) return true; 1456 1457 return false; 1458 } 1459 1460 1461 /** 1462 * Search for and return the uri of a media file 1463 * 1464 * @param string $image image name to search for (without extension) 1465 * @param bool $searchCurrentNS search the current namespace 1466 * @return string uri of the found media file 1467 */ 1468 public function getMediaFile($image, $searchCurrentNS=TRUE, $propagate=TRUE) { 1469 global $INFO; 1470 1471 $ext = array('png', 'jpg', 'gif', 'svg'); 1472 1473 if($searchCurrentNS) $prefix[] = ':'.$INFO['namespace'].':'; 1474 if($propagate) { 1475 $prefix[] = ':'; 1476 $prefix[] = ':wiki:'; 1477 } 1478 $theme = $this->getConf('customTheme'); 1479 if($theme != '') $prefix[] = $this->tplDir . 'themes/' . $theme . '/images/'; 1480 $prefix[] = 'images/'; 1481 1482 $search = array(); 1483 foreach($prefix as $pitem) { 1484 foreach($ext as $eitem) { 1485 $search[] = $pitem . $image . '.' . $eitem; 1486 } 1487 } 1488 1489 $img = ''; 1490 $file = ''; 1491 $url = ''; 1492 $ismedia = false; 1493 $found = false; 1494 1495 foreach($search as $img) { 1496 if(substr($img, 0, 1) == ':') { 1497 $file = mediaFN($img); 1498 $ismedia = true; 1499 } else { 1500 $file = tpl_incdir().$img; 1501 $ismedia = false; 1502 } 1503 1504 if(file_exists($file)) { 1505 $found = true; 1506 break; 1507 } 1508 } 1509 1510 if(!$found) return false; 1511 1512 if($ismedia) { 1513 $url = ml($img, '', true, '', false); 1514 } else { 1515 $url = tpl_basedir().$img; 1516 } 1517 1518 return $url; 1519 } 1520 1521 1522 /** 1523 * Print or return the page title 1524 * 1525 * @param string $page page id or empty string for current page 1526 * @return string generated content 1527 */ 1528 public function getPageTitle($page = '') { 1529 global $ID, $conf; 1530 1531 $html = ''; 1532 1533 if($page == '') $page = $ID; 1534 1535 $html = p_get_first_heading($page); 1536 $html = strip_tags($html); 1537 $html = preg_replace('/\s+/', ' ', $html); 1538 $html .= ' [' . strip_tags($conf['title']) . ']'; 1539 $html = trim($html); 1540 1541 return $html; 1542 } 1543 1544 1545 /** 1546 * Return inline theme icon 1547 * 1548 * @param string $type icon to retreive 1549 * @return string html icon content 1550 */ 1551 public function mikioInlineIcon($type) { 1552 switch($type) { 1553 case 'wrench': 1554 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>'; 1555 case 'file': 1556 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>'; 1557 case 'gear': 1558 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>'; 1559 case 'user': 1560 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>'; 1561 case 'search': 1562 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>'; 1563 case 'home': 1564 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>'; 1565 } 1566 1567 return ''; 1568 } 1569 1570 /** 1571 * Finalize theme 1572 */ 1573 public function finalize() { 1574 1575 } 1576 1577 /** 1578 * Show Messages 1579 */ 1580 public function showMessages() { 1581 global $ACT; 1582 1583 if($this->lessIgnored) { 1584 msg('useLESS is enabled on the Mikio template, however is not supported on this server', 2, '', '', MSG_ADMINS_ONLY); 1585 } 1586 1587 $show = $this->getConf('showNotifications'); 1588 if($show == 'always' || ($show == 'admin' && $ACT == 'admin')) { 1589 global $MSG, $MSG_shown; 1590 1591 if (!isset($MSG)) { 1592 return; 1593 } 1594 1595 if (!isset($MSG_shown)) { 1596 $MSG_shown = array(); 1597 } 1598 1599 foreach ($MSG as $msg) { 1600 1601 $hash = md5($msg['msg']); 1602 if (isset($MSG_shown[$hash])) { 1603 continue; 1604 } 1605 // skip double messages 1606 1607 if (info_msg_allowed($msg)) { 1608 1609 print '<div class="' . $msg['lvl'] . '">'; 1610 print $msg['msg']; 1611 print '</div>'; 1612 1613 } 1614 1615 $MSG_shown[$hash] = true; 1616 1617 } 1618 1619 unset($GLOBALS['MSG']); 1620 } 1621 } 1622} 1623 1624global $TEMPLATE; 1625$TEMPLATE = \dokuwiki\template\mikio\Template::getInstance(); 1626