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