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