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