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