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