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