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