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