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