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