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