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