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