1<?php 2/** 3 * DokuWiki template functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9if(!defined('DOKU_INC')) die('meh.'); 10 11/** 12 * Access a template file 13 * 14 * Returns the path to the given file inside the current template, uses 15 * default template if the custom version doesn't exist. 16 * 17 * @author Andreas Gohr <andi@splitbrain.org> 18 * @param string $file 19 * @return string 20 */ 21function template($file) { 22 global $conf; 23 24 if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 25 return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 26 27 return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 28} 29 30/** 31 * Convenience function to access template dir from local FS 32 * 33 * This replaces the deprecated DOKU_TPLINC constant 34 * 35 * @author Andreas Gohr <andi@splitbrain.org> 36 * @param string $tpl The template to use, default to current one 37 * @return string 38 */ 39function tpl_incdir($tpl='') { 40 global $conf; 41 if(!$tpl) $tpl = $conf['template']; 42 return DOKU_INC.'lib/tpl/'.$tpl.'/'; 43} 44 45/** 46 * Convenience function to access template dir from web 47 * 48 * This replaces the deprecated DOKU_TPL constant 49 * 50 * @author Andreas Gohr <andi@splitbrain.org> 51 * @param string $tpl The template to use, default to current one 52 * @return string 53 */ 54function tpl_basedir($tpl='') { 55 global $conf; 56 if(!$tpl) $tpl = $conf['template']; 57 return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 58} 59 60/** 61 * Print the content 62 * 63 * This function is used for printing all the usual content 64 * (defined by the global $ACT var) by calling the appropriate 65 * outputfunction(s) from html.php 66 * 67 * Everything that doesn't use the main template file isn't 68 * handled by this function. ACL stuff is not done here either. 69 * 70 * @author Andreas Gohr <andi@splitbrain.org> 71 * 72 * @triggers TPL_ACT_RENDER 73 * @triggers TPL_CONTENT_DISPLAY 74 * @param bool $prependTOC should the TOC be displayed here? 75 * @return bool true if any output 76 */ 77function tpl_content($prependTOC = true) { 78 global $ACT; 79 global $INFO; 80 $INFO['prependTOC'] = $prependTOC; 81 82 ob_start(); 83 trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 84 $html_output = ob_get_clean(); 85 trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 86 87 return !empty($html_output); 88} 89 90/** 91 * Default Action of TPL_ACT_RENDER 92 * 93 * @return bool 94 */ 95function tpl_content_core() { 96 global $ACT; 97 global $TEXT; 98 global $PRE; 99 global $SUF; 100 global $SUM; 101 global $IDX; 102 global $INPUT; 103 104 switch($ACT) { 105 case 'show': 106 html_show(); 107 break; 108 /** @noinspection PhpMissingBreakStatementInspection */ 109 case 'locked': 110 html_locked(); 111 case 'edit': 112 case 'recover': 113 html_edit(); 114 break; 115 case 'preview': 116 html_edit(); 117 html_show($TEXT); 118 break; 119 case 'draft': 120 html_draft(); 121 break; 122 case 'search': 123 html_search(); 124 break; 125 case 'revisions': 126 html_revisions($INPUT->int('first')); 127 break; 128 case 'diff': 129 html_diff(); 130 break; 131 case 'recent': 132 $show_changes = $INPUT->str('show_changes'); 133 if (empty($show_changes)) { 134 $show_changes = get_doku_pref('show_changes', $show_changes); 135 } 136 html_recent($INPUT->extract('first')->int('first'), $show_changes); 137 break; 138 case 'index': 139 html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 140 break; 141 case 'backlink': 142 html_backlinks(); 143 break; 144 case 'conflict': 145 html_conflict(con($PRE, $TEXT, $SUF), $SUM); 146 html_diff(con($PRE, $TEXT, $SUF), false); 147 break; 148 case 'login': 149 html_login(); 150 break; 151 case 'register': 152 html_register(); 153 break; 154 case 'resendpwd': 155 html_resendpwd(); 156 break; 157 case 'denied': 158 html_denied(); 159 break; 160 case 'profile' : 161 html_updateprofile(); 162 break; 163 case 'admin': 164 tpl_admin(); 165 break; 166 case 'subscribe': 167 tpl_subscribe(); 168 break; 169 case 'media': 170 tpl_media(); 171 break; 172 default: 173 $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); 174 if($evt->advise_before()) { 175 msg("Failed to handle command: ".hsc($ACT), -1); 176 } 177 $evt->advise_after(); 178 unset($evt); 179 return false; 180 } 181 return true; 182} 183 184/** 185 * Places the TOC where the function is called 186 * 187 * If you use this you most probably want to call tpl_content with 188 * a false argument 189 * 190 * @author Andreas Gohr <andi@splitbrain.org> 191 * 192 * @param bool $return Should the TOC be returned instead to be printed? 193 * @return string 194 */ 195function tpl_toc($return = false) { 196 global $TOC; 197 global $ACT; 198 global $ID; 199 global $REV; 200 global $INFO; 201 global $conf; 202 global $INPUT; 203 $toc = array(); 204 205 if(is_array($TOC)) { 206 // if a TOC was prepared in global scope, always use it 207 $toc = $TOC; 208 } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 209 // get TOC from metadata, render if neccessary 210 $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 211 if(isset($meta['internal']['toc'])) { 212 $tocok = $meta['internal']['toc']; 213 } else { 214 $tocok = true; 215 } 216 $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 217 if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 218 $toc = array(); 219 } 220 } elseif($ACT == 'admin') { 221 // try to load admin plugin TOC FIXME: duplicates code from tpl_admin 222 $plugin = null; 223 $class = $INPUT->str('page'); 224 if(!empty($class)) { 225 $pluginlist = plugin_list('admin'); 226 if(in_array($class, $pluginlist)) { 227 // attempt to load the plugin 228 /** @var $plugin DokuWiki_Admin_Plugin */ 229 $plugin = plugin_load('admin', $class); 230 } 231 } 232 if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { 233 $toc = $plugin->getTOC(); 234 $TOC = $toc; // avoid later rebuild 235 } 236 } 237 238 trigger_event('TPL_TOC_RENDER', $toc, null, false); 239 $html = html_TOC($toc); 240 if($return) return $html; 241 echo $html; 242 return ''; 243} 244 245/** 246 * Handle the admin page contents 247 * 248 * @author Andreas Gohr <andi@splitbrain.org> 249 * 250 * @return bool 251 */ 252function tpl_admin() { 253 global $INFO; 254 global $TOC; 255 global $INPUT; 256 257 $plugin = null; 258 $class = $INPUT->str('page'); 259 if(!empty($class)) { 260 $pluginlist = plugin_list('admin'); 261 262 if(in_array($class, $pluginlist)) { 263 // attempt to load the plugin 264 /** @var $plugin DokuWiki_Admin_Plugin */ 265 $plugin = plugin_load('admin', $class); 266 } 267 } 268 269 if($plugin !== null) { 270 if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 271 if($INFO['prependTOC']) tpl_toc(); 272 $plugin->html(); 273 } else { 274 html_admin(); 275 } 276 return true; 277} 278 279/** 280 * Print the correct HTML meta headers 281 * 282 * This has to go into the head section of your template. 283 * 284 * @author Andreas Gohr <andi@splitbrain.org> 285 * 286 * @triggers TPL_METAHEADER_OUTPUT 287 * @param bool $alt Should feeds and alternative format links be added? 288 * @return bool 289 */ 290function tpl_metaheaders($alt = true) { 291 global $ID; 292 global $REV; 293 global $INFO; 294 global $JSINFO; 295 global $ACT; 296 global $QUERY; 297 global $lang; 298 global $conf; 299 global $updateVersion; 300 /** @var Input $INPUT */ 301 global $INPUT; 302 303 // prepare the head array 304 $head = array(); 305 306 // prepare seed for js and css 307 $tseed = $updateVersion; 308 $depends = getConfigFiles('main'); 309 foreach($depends as $f) $tseed .= @filemtime($f); 310 $tseed = md5($tseed); 311 312 // the usual stuff 313 $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 314 $head['link'][] = array( 315 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 316 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 317 ); 318 $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 319 if(actionOK('index')) { 320 $head['link'][] = array( 321 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 322 'title'=> $lang['btn_index'] 323 ); 324 } 325 326 if($alt) { 327 if(actionOK('rss')) { 328 $head['link'][] = array( 329 'rel' => 'alternate', 'type'=> 'application/rss+xml', 330 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 331 ); 332 $head['link'][] = array( 333 'rel' => 'alternate', 'type'=> 'application/rss+xml', 334 'title'=> $lang['currentns'], 335 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 336 ); 337 } 338 if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 339 $head['link'][] = array( 340 'rel' => 'edit', 341 'title'=> $lang['btn_edit'], 342 'href' => wl($ID, 'do=edit', false, '&') 343 ); 344 } 345 346 if(actionOK('rss') && $ACT == 'search') { 347 $head['link'][] = array( 348 'rel' => 'alternate', 'type'=> 'application/rss+xml', 349 'title'=> $lang['searchresult'], 350 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 351 ); 352 } 353 354 if(actionOK('export_xhtml')) { 355 $head['link'][] = array( 356 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 357 'href'=> exportlink($ID, 'xhtml', '', false, '&') 358 ); 359 } 360 361 if(actionOK('export_raw')) { 362 $head['link'][] = array( 363 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 364 'href'=> exportlink($ID, 'raw', '', false, '&') 365 ); 366 } 367 } 368 369 // setup robot tags apropriate for different modes 370 if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 371 if($INFO['exists']) { 372 //delay indexing: 373 if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 374 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 375 } else { 376 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 377 } 378 $canonicalUrl = wl($ID, '', true, '&'); 379 if ($ID == $conf['start']) { 380 $canonicalUrl = DOKU_URL; 381 } 382 $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 383 } else { 384 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 385 } 386 } elseif(defined('DOKU_MEDIADETAIL')) { 387 $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 388 } else { 389 $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 390 } 391 392 // set metadata 393 if($ACT == 'show' || $ACT == 'export_xhtml') { 394 // keywords (explicit or implicit) 395 if(!empty($INFO['meta']['subject'])) { 396 $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 397 } else { 398 $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 399 } 400 } 401 402 // load stylesheets 403 $head['link'][] = array( 404 'rel' => 'stylesheet', 'type'=> 'text/css', 405 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed 406 ); 407 408 // make $INFO and other vars available to JavaScripts 409 $json = new JSON(); 410 $script = "var NS='".$INFO['namespace']."';"; 411 if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 412 $script .= "var SIG='".toolbar_signature()."';"; 413 } 414 $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 415 $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 416 417 // load external javascript 418 $head['script'][] = array( 419 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 420 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed 421 ); 422 423 // trigger event here 424 trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 425 return true; 426} 427 428/** 429 * prints the array build by tpl_metaheaders 430 * 431 * $data is an array of different header tags. Each tag can have multiple 432 * instances. Attributes are given as key value pairs. Values will be HTML 433 * encoded automatically so they should be provided as is in the $data array. 434 * 435 * For tags having a body attribute specify the body data in the special 436 * attribute '_data'. This field will NOT BE ESCAPED automatically. 437 * 438 * @author Andreas Gohr <andi@splitbrain.org> 439 * 440 * @param array $data 441 */ 442function _tpl_metaheaders_action($data) { 443 foreach($data as $tag => $inst) { 444 foreach($inst as $attr) { 445 echo '<', $tag, ' ', buildAttributes($attr); 446 if(isset($attr['_data']) || $tag == 'script') { 447 if($tag == 'script' && $attr['_data']) 448 $attr['_data'] = "/*<![CDATA[*/". 449 $attr['_data']. 450 "\n/*!]]>*/"; 451 452 echo '>', $attr['_data'], '</', $tag, '>'; 453 } else { 454 echo '/>'; 455 } 456 echo "\n"; 457 } 458 } 459} 460 461/** 462 * Print a link 463 * 464 * Just builds a link. 465 * 466 * @author Andreas Gohr <andi@splitbrain.org> 467 * 468 * @param string $url 469 * @param string $name 470 * @param string $more 471 * @param bool $return if true return the link html, otherwise print 472 * @return bool|string html of the link, or true if printed 473 */ 474function tpl_link($url, $name, $more = '', $return = false) { 475 $out = '<a href="'.$url.'" '; 476 if($more) $out .= ' '.$more; 477 $out .= ">$name</a>"; 478 if($return) return $out; 479 print $out; 480 return true; 481} 482 483/** 484 * Prints a link to a WikiPage 485 * 486 * Wrapper around html_wikilink 487 * 488 * @author Andreas Gohr <andi@splitbrain.org> 489 * 490 * @param string $id page id 491 * @param string|null $name the name of the link 492 * @return bool true 493 */ 494function tpl_pagelink($id, $name = null) { 495 print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 496 return true; 497} 498 499/** 500 * get the parent page 501 * 502 * Tries to find out which page is parent. 503 * returns false if none is available 504 * 505 * @author Andreas Gohr <andi@splitbrain.org> 506 * 507 * @param string $id page id 508 * @return false|string 509 */ 510function tpl_getparent($id) { 511 $parent = getNS($id).':'; 512 resolve_pageid('', $parent, $exists); 513 if($parent == $id) { 514 $pos = strrpos(getNS($id), ':'); 515 $parent = substr($parent, 0, $pos).':'; 516 resolve_pageid('', $parent, $exists); 517 if($parent == $id) return false; 518 } 519 return $parent; 520} 521 522/** 523 * Print one of the buttons 524 * 525 * @author Adrian Lang <mail@adrianlang.de> 526 * @see tpl_get_action 527 * 528 * @param string $type 529 * @param bool $return 530 * @return bool|string html, or false if no data, true if printed 531 */ 532function tpl_button($type, $return = false) { 533 $data = tpl_get_action($type); 534 if($data === false) { 535 return false; 536 } elseif(!is_array($data)) { 537 $out = sprintf($data, 'button'); 538 } else { 539 /** 540 * @var string $accesskey 541 * @var string $id 542 * @var string $method 543 * @var array $params 544 */ 545 extract($data); 546 if($id === '#dokuwiki__top') { 547 $out = html_topbtn(); 548 } else { 549 $out = html_btn($type, $id, $accesskey, $params, $method); 550 } 551 } 552 if($return) return $out; 553 echo $out; 554 return true; 555} 556 557/** 558 * Like the action buttons but links 559 * 560 * @author Adrian Lang <mail@adrianlang.de> 561 * @see tpl_get_action 562 * 563 * @param string $type action command 564 * @param string $pre prefix of link 565 * @param string $suf suffix of link 566 * @param string $inner innerHML of link 567 * @param bool $return if true it returns html, otherwise prints 568 * @return bool|string html or false if no data, true if printed 569 */ 570function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 571 global $lang; 572 $data = tpl_get_action($type); 573 if($data === false) { 574 return false; 575 } elseif(!is_array($data)) { 576 $out = sprintf($data, 'link'); 577 } else { 578 /** 579 * @var string $accesskey 580 * @var string $id 581 * @var string $method 582 * @var bool $nofollow 583 * @var array $params 584 * @var string $replacement 585 */ 586 extract($data); 587 if(strpos($id, '#') === 0) { 588 $linktarget = $id; 589 } else { 590 $linktarget = wl($id, $params); 591 } 592 $caption = $lang['btn_'.$type]; 593 if(strpos($caption, '%s')){ 594 $caption = sprintf($caption, $replacement); 595 } 596 $akey = $addTitle = ''; 597 if($accesskey) { 598 $akey = 'accesskey="'.$accesskey.'" '; 599 $addTitle = ' ['.strtoupper($accesskey).']'; 600 } 601 $rel = $nofollow ? 'rel="nofollow" ' : ''; 602 $out = tpl_link( 603 $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 604 'class="action '.$type.'" '. 605 $akey.$rel. 606 'title="'.hsc($caption).$addTitle.'"', true 607 ); 608 } 609 if($return) return $out; 610 echo $out; 611 return true; 612} 613 614/** 615 * Check the actions and get data for buttons and links 616 * 617 * Available actions are 618 * 619 * edit - edit/create/show/draft 620 * history - old revisions 621 * recent - recent changes 622 * login - login/logout - if ACL enabled 623 * profile - user profile (if logged in) 624 * index - The index 625 * admin - admin page - if enough rights 626 * top - back to top 627 * back - back to parent - if available 628 * backlink - links to the list of backlinks 629 * subscribe/subscription- subscribe/unsubscribe 630 * 631 * @author Andreas Gohr <andi@splitbrain.org> 632 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 633 * @author Adrian Lang <mail@adrianlang.de> 634 * 635 * @param string $type 636 * @return array|bool|string 637 */ 638function tpl_get_action($type) { 639 global $ID; 640 global $INFO; 641 global $REV; 642 global $ACT; 643 global $conf; 644 /** @var Input $INPUT */ 645 global $INPUT; 646 647 // check disabled actions and fix the badly named ones 648 if($type == 'history') $type = 'revisions'; 649 if ($type == 'subscription') $type = 'subscribe'; 650 if(!actionOK($type)) return false; 651 652 $accesskey = null; 653 $id = $ID; 654 $method = 'get'; 655 $params = array('do' => $type); 656 $nofollow = true; 657 $replacement = ''; 658 switch($type) { 659 case 'edit': 660 // most complicated type - we need to decide on current action 661 if($ACT == 'show' || $ACT == 'search') { 662 $method = 'post'; 663 if($INFO['writable']) { 664 $accesskey = 'e'; 665 if(!empty($INFO['draft'])) { 666 $type = 'draft'; 667 $params['do'] = 'draft'; 668 } else { 669 $params['rev'] = $REV; 670 if(!$INFO['exists']) { 671 $type = 'create'; 672 } 673 } 674 } else { 675 if(!actionOK('source')) return false; //pseudo action 676 $params['rev'] = $REV; 677 $type = 'source'; 678 $accesskey = 'v'; 679 } 680 } else { 681 $params = array('do' => ''); 682 $type = 'show'; 683 $accesskey = 'v'; 684 } 685 break; 686 case 'revisions': 687 $type = 'revs'; 688 $accesskey = 'o'; 689 break; 690 case 'recent': 691 $accesskey = 'r'; 692 break; 693 case 'index': 694 $accesskey = 'x'; 695 // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 696 if ($conf['start'] == $ID && !$conf['sitemap']) { 697 $nofollow = false; 698 } 699 break; 700 case 'top': 701 $accesskey = 't'; 702 $params = array('do' => ''); 703 $id = '#dokuwiki__top'; 704 break; 705 case 'back': 706 $parent = tpl_getparent($ID); 707 if(!$parent) { 708 return false; 709 } 710 $id = $parent; 711 $params = array('do' => ''); 712 $accesskey = 'b'; 713 break; 714 case 'img_backto': 715 $params = array(); 716 $accesskey = 'b'; 717 $replacement = $ID; 718 break; 719 case 'login': 720 $params['sectok'] = getSecurityToken(); 721 if($INPUT->server->has('REMOTE_USER')) { 722 if(!actionOK('logout')) { 723 return false; 724 } 725 $params['do'] = 'logout'; 726 $type = 'logout'; 727 } 728 break; 729 case 'register': 730 if($INPUT->server->str('REMOTE_USER')) { 731 return false; 732 } 733 break; 734 case 'resendpwd': 735 if($INPUT->server->str('REMOTE_USER')) { 736 return false; 737 } 738 break; 739 case 'admin': 740 if(!$INFO['ismanager']) { 741 return false; 742 } 743 break; 744 case 'revert': 745 if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 746 return false; 747 } 748 $params['rev'] = $REV; 749 $params['sectok'] = getSecurityToken(); 750 break; 751 case 'subscribe': 752 if(!$INPUT->server->str('REMOTE_USER')) { 753 return false; 754 } 755 break; 756 case 'backlink': 757 break; 758 case 'profile': 759 if(!$INPUT->server->has('REMOTE_USER')) { 760 return false; 761 } 762 break; 763 case 'media': 764 $params['ns'] = getNS($ID); 765 break; 766 case 'mediaManager': 767 // View image in media manager 768 global $IMG; 769 $imgNS = getNS($IMG); 770 $authNS = auth_quickaclcheck("$imgNS:*"); 771 if ($authNS < AUTH_UPLOAD) { 772 return false; 773 } 774 $params = array( 775 'ns' => $imgNS, 776 'image' => $IMG, 777 'do' => 'media' 778 ); 779 //$type = 'media'; 780 break; 781 default: 782 return '[unknown %s type]'; 783 } 784 return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); 785} 786 787/** 788 * Wrapper around tpl_button() and tpl_actionlink() 789 * 790 * @author Anika Henke <anika@selfthinker.org> 791 * 792 * @param string $type action command 793 * @param bool $link link or form button? 794 * @param string|bool $wrapper HTML element wrapper 795 * @param bool $return return or print 796 * @param string $pre prefix for links 797 * @param string $suf suffix for links 798 * @param string $inner inner HTML for links 799 * @return bool|string 800 */ 801function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 802 $out = ''; 803 if($link) { 804 $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 805 } else { 806 $out .= tpl_button($type, true); 807 } 808 if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 809 810 if($return) return $out; 811 print $out; 812 return $out ? true : false; 813} 814 815/** 816 * Print the search form 817 * 818 * If the first parameter is given a div with the ID 'qsearch_out' will 819 * be added which instructs the ajax pagequicksearch to kick in and place 820 * its output into this div. The second parameter controls the propritary 821 * attribute autocomplete. If set to false this attribute will be set with an 822 * value of "off" to instruct the browser to disable it's own built in 823 * autocompletion feature (MSIE and Firefox) 824 * 825 * @author Andreas Gohr <andi@splitbrain.org> 826 * 827 * @param bool $ajax 828 * @param bool $autocomplete 829 * @return bool 830 */ 831function tpl_searchform($ajax = true, $autocomplete = true) { 832 global $lang; 833 global $ACT; 834 global $QUERY; 835 836 // don't print the search form if search action has been disabled 837 if(!actionOK('search')) return false; 838 839 print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 840 print '<input type="hidden" name="do" value="search" />'; 841 print '<input type="text" '; 842 if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 843 if(!$autocomplete) print 'autocomplete="off" '; 844 print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 845 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 846 if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 847 print '</div></form>'; 848 return true; 849} 850 851/** 852 * Print the breadcrumbs trace 853 * 854 * @author Andreas Gohr <andi@splitbrain.org> 855 * 856 * @param string $sep Separator between entries 857 * @return bool 858 */ 859function tpl_breadcrumbs($sep = '•') { 860 global $lang; 861 global $conf; 862 863 //check if enabled 864 if(!$conf['breadcrumbs']) return false; 865 866 $crumbs = breadcrumbs(); //setup crumb trace 867 868 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 869 870 //render crumbs, highlight the last one 871 print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 872 $last = count($crumbs); 873 $i = 0; 874 foreach($crumbs as $id => $name) { 875 $i++; 876 echo $crumbs_sep; 877 if($i == $last) print '<span class="curid">'; 878 print '<bdi>'; 879 tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 880 print '</bdi>'; 881 if($i == $last) print '</span>'; 882 } 883 return true; 884} 885 886/** 887 * Hierarchical breadcrumbs 888 * 889 * This code was suggested as replacement for the usual breadcrumbs. 890 * It only makes sense with a deep site structure. 891 * 892 * @author Andreas Gohr <andi@splitbrain.org> 893 * @author Nigel McNie <oracle.shinoda@gmail.com> 894 * @author Sean Coates <sean@caedmon.net> 895 * @author <fredrik@averpil.com> 896 * @author Mark C. Prins <mprins@users.sf.net> 897 * 898 * @param string $sep Separator between entries 899 * @return bool 900 */ 901function tpl_youarehere($sep = ' → ') { 902 global $conf; 903 global $ID; 904 global $lang; 905 906 // check if enabled 907 if(!$conf['youarehere']) return false; 908 909 $parts = explode(':', $ID); 910 $count = count($parts); 911 912 echo '<nav><h2 class="bchead">'.$lang['youarehere'].': </h2>'; 913 echo '<ul class="navlist">'; 914 // always print the startpage 915 if ($count > 1) { 916 echo '<li class="home">'.html_wikilink(':'.$conf['start']).$sep.'</li>'; 917 } else { 918 echo '<li class="home">'.$conf['start'].'</li>'; 919 } 920 921 922 // print intermediate namespace links 923 $part = ''; 924 for($i = 0; $i < $count - 1; $i++) { 925 $part .= $parts[$i].':'; 926 $page = $part; 927 if($page == $conf['start']) continue; // Skip startpage 928 929 echo '<li>'.html_wikilink($page); 930 if ($i < $count - 2) { 931 echo $sep.'</li>'; 932 } else { 933 echo '</li>'; 934 } 935 } 936 937 // print current page, skipping start page, skipping for namespace index 938 resolve_pageid('', $page, $exists); 939 if(isset($page) && $page == $part.$parts[$i]) { 940 echo '</li></ul></nav>'; 941 return true; 942 } 943 944 $page = $part.$parts[$i]; 945 if($page == $conf['start']) { 946 echo '</li></ul></nav>'; 947 return true; 948 } 949 950 echo $sep.'</li><li class="curid">'.noNSorNS($page).'</li></ul></nav>'; 951 return true; 952} 953 954/** 955 * Print info if the user is logged in 956 * and show full name in that case 957 * 958 * Could be enhanced with a profile link in future? 959 * 960 * @author Andreas Gohr <andi@splitbrain.org> 961 * 962 * @return bool 963 */ 964function tpl_userinfo() { 965 global $lang; 966 /** @var Input $INPUT */ 967 global $INPUT; 968 969 if($INPUT->server->str('REMOTE_USER')) { 970 print $lang['loggedinas'].' '.userlink(); 971 return true; 972 } 973 return false; 974} 975 976/** 977 * Print some info about the current page 978 * 979 * @author Andreas Gohr <andi@splitbrain.org> 980 * 981 * @param bool $ret return content instead of printing it 982 * @return bool|string 983 */ 984function tpl_pageinfo($ret = false) { 985 global $conf; 986 global $lang; 987 global $INFO; 988 global $ID; 989 990 // return if we are not allowed to view the page 991 if(!auth_quickaclcheck($ID)) { 992 return false; 993 } 994 995 // prepare date and path 996 $fn = $INFO['filepath']; 997 if(!$conf['fullpath']) { 998 if($INFO['rev']) { 999 $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 1000 } else { 1001 $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 1002 } 1003 } 1004 $fn = utf8_decodeFN($fn); 1005 $date = dformat($INFO['lastmod']); 1006 1007 // print it 1008 if($INFO['exists']) { 1009 $out = ''; 1010 $out .= '<bdi>'.$fn.'</bdi>'; 1011 $out .= ' · '; 1012 $out .= $lang['lastmod']; 1013 $out .= ' '; 1014 $out .= $date; 1015 if($INFO['editor']) { 1016 $out .= ' '.$lang['by'].' '; 1017 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 1018 } else { 1019 $out .= ' ('.$lang['external_edit'].')'; 1020 } 1021 if($INFO['locked']) { 1022 $out .= ' · '; 1023 $out .= $lang['lockedby']; 1024 $out .= ' '; 1025 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 1026 } 1027 if($ret) { 1028 return $out; 1029 } else { 1030 echo $out; 1031 return true; 1032 } 1033 } 1034 return false; 1035} 1036 1037/** 1038 * Prints or returns the name of the given page (current one if none given). 1039 * 1040 * If useheading is enabled this will use the first headline else 1041 * the given ID is used. 1042 * 1043 * @author Andreas Gohr <andi@splitbrain.org> 1044 * 1045 * @param string $id page id 1046 * @param bool $ret return content instead of printing 1047 * @return bool|string 1048 */ 1049function tpl_pagetitle($id = null, $ret = false) { 1050 if(is_null($id)) { 1051 global $ID; 1052 $id = $ID; 1053 } 1054 1055 $name = $id; 1056 if(useHeading('navigation')) { 1057 $title = p_get_first_heading($id); 1058 if($title) $name = $title; 1059 } 1060 1061 if($ret) { 1062 return hsc($name); 1063 } else { 1064 print hsc($name); 1065 return true; 1066 } 1067} 1068 1069/** 1070 * Returns the requested EXIF/IPTC tag from the current image 1071 * 1072 * If $tags is an array all given tags are tried until a 1073 * value is found. If no value is found $alt is returned. 1074 * 1075 * Which texts are known is defined in the functions _exifTagNames 1076 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 1077 * to the names of the latter one) 1078 * 1079 * Only allowed in: detail.php 1080 * 1081 * @author Andreas Gohr <andi@splitbrain.org> 1082 * 1083 * @param array|string $tags tag or array of tags to try 1084 * @param string $alt alternative output if no data was found 1085 * @param null|string $src the image src, uses global $SRC if not given 1086 * @return string 1087 */ 1088function tpl_img_getTag($tags, $alt = '', $src = null) { 1089 // Init Exif Reader 1090 global $SRC; 1091 1092 if(is_null($src)) $src = $SRC; 1093 1094 static $meta = null; 1095 if(is_null($meta)) $meta = new JpegMeta($src); 1096 if($meta === false) return $alt; 1097 $info = cleanText($meta->getField($tags)); 1098 if($info == false) return $alt; 1099 return $info; 1100} 1101 1102/** 1103 * Returns a description list of the metatags of the current image 1104 * 1105 * @return string html of description list 1106 */ 1107function tpl_img_meta() { 1108 global $lang; 1109 1110 $tags = tpl_get_img_meta(); 1111 1112 echo '<dl>'; 1113 foreach($tags as $tag) { 1114 $label = $lang[$tag['langkey']]; 1115 if(!$label) $label = $tag['langkey'] . ':'; 1116 1117 echo '<dt>'.$label.'</dt><dd>'; 1118 if ($tag['type'] == 'date') { 1119 echo dformat($tag['value']); 1120 } else { 1121 echo hsc($tag['value']); 1122 } 1123 echo '</dd>'; 1124 } 1125 echo '</dl>'; 1126} 1127 1128/** 1129 * Returns metadata as configured in mediameta config file, ready for creating html 1130 * 1131 * @return array with arrays containing the entries: 1132 * - string langkey key to lookup in the $lang var, if not found printed as is 1133 * - string type type of value 1134 * - string value tag value (unescaped) 1135 */ 1136function tpl_get_img_meta() { 1137 1138 $config_files = getConfigFiles('mediameta'); 1139 foreach ($config_files as $config_file) { 1140 if(file_exists($config_file)) { 1141 include($config_file); 1142 } 1143 } 1144 /** @var array $fields the included array with metadata */ 1145 1146 $tags = array(); 1147 foreach($fields as $tag){ 1148 $t = array(); 1149 if (!empty($tag[0])) { 1150 $t = array($tag[0]); 1151 } 1152 if(is_array($tag[3])) { 1153 $t = array_merge($t,$tag[3]); 1154 } 1155 $value = tpl_img_getTag($t); 1156 if ($value) { 1157 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1158 } 1159 } 1160 return $tags; 1161} 1162 1163/** 1164 * Prints the image with a link to the full sized version 1165 * 1166 * Only allowed in: detail.php 1167 * 1168 * @triggers TPL_IMG_DISPLAY 1169 * @param $maxwidth int - maximal width of the image 1170 * @param $maxheight int - maximal height of the image 1171 * @param $link bool - link to the orginal size? 1172 * @param $params array - additional image attributes 1173 * @return bool Result of TPL_IMG_DISPLAY 1174 */ 1175function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 1176 global $IMG; 1177 /** @var Input $INPUT */ 1178 global $INPUT; 1179 global $REV; 1180 $w = tpl_img_getTag('File.Width'); 1181 $h = tpl_img_getTag('File.Height'); 1182 1183 //resize to given max values 1184 $ratio = 1; 1185 if($w >= $h) { 1186 if($maxwidth && $w >= $maxwidth) { 1187 $ratio = $maxwidth / $w; 1188 } elseif($maxheight && $h > $maxheight) { 1189 $ratio = $maxheight / $h; 1190 } 1191 } else { 1192 if($maxheight && $h >= $maxheight) { 1193 $ratio = $maxheight / $h; 1194 } elseif($maxwidth && $w > $maxwidth) { 1195 $ratio = $maxwidth / $w; 1196 } 1197 } 1198 if($ratio) { 1199 $w = floor($ratio * $w); 1200 $h = floor($ratio * $h); 1201 } 1202 1203 //prepare URLs 1204 $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 1205 $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 1206 1207 //prepare attributes 1208 $alt = tpl_img_getTag('Simple.Title'); 1209 if(is_null($params)) { 1210 $p = array(); 1211 } else { 1212 $p = $params; 1213 } 1214 if($w) $p['width'] = $w; 1215 if($h) $p['height'] = $h; 1216 $p['class'] = 'img_detail'; 1217 if($alt) { 1218 $p['alt'] = $alt; 1219 $p['title'] = $alt; 1220 } else { 1221 $p['alt'] = ''; 1222 } 1223 $p['src'] = $src; 1224 1225 $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1226 return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1227} 1228 1229/** 1230 * Default action for TPL_IMG_DISPLAY 1231 * 1232 * @param array $data 1233 * @return bool 1234 */ 1235function _tpl_img_action($data) { 1236 global $lang; 1237 $p = buildAttributes($data['params']); 1238 1239 if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1240 print '<img '.$p.'/>'; 1241 if($data['url']) print '</a>'; 1242 return true; 1243} 1244 1245/** 1246 * This function inserts a small gif which in reality is the indexer function. 1247 * 1248 * Should be called somewhere at the very end of the main.php 1249 * template 1250 * 1251 * @return bool 1252 */ 1253function tpl_indexerWebBug() { 1254 global $ID; 1255 1256 $p = array(); 1257 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1258 '&'.time(); 1259 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 1260 $p['height'] = 1; 1261 $p['alt'] = ''; 1262 $att = buildAttributes($p); 1263 print "<img $att />"; 1264 return true; 1265} 1266 1267/** 1268 * tpl_getConf($id) 1269 * 1270 * use this function to access template configuration variables 1271 * 1272 * @param string $id name of the value to access 1273 * @param mixed $notset what to return if the setting is not available 1274 * @return mixed 1275 */ 1276function tpl_getConf($id, $notset=false) { 1277 global $conf; 1278 static $tpl_configloaded = false; 1279 1280 $tpl = $conf['template']; 1281 1282 if(!$tpl_configloaded) { 1283 $tconf = tpl_loadConfig(); 1284 if($tconf !== false) { 1285 foreach($tconf as $key => $value) { 1286 if(isset($conf['tpl'][$tpl][$key])) continue; 1287 $conf['tpl'][$tpl][$key] = $value; 1288 } 1289 $tpl_configloaded = true; 1290 } 1291 } 1292 1293 if(isset($conf['tpl'][$tpl][$id])){ 1294 return $conf['tpl'][$tpl][$id]; 1295 } 1296 1297 return $notset; 1298} 1299 1300/** 1301 * tpl_loadConfig() 1302 * 1303 * reads all template configuration variables 1304 * this function is automatically called by tpl_getConf() 1305 * 1306 * @return array 1307 */ 1308function tpl_loadConfig() { 1309 1310 $file = tpl_incdir().'/conf/default.php'; 1311 $conf = array(); 1312 1313 if(!file_exists($file)) return false; 1314 1315 // load default config file 1316 include($file); 1317 1318 return $conf; 1319} 1320 1321// language methods 1322/** 1323 * tpl_getLang($id) 1324 * 1325 * use this function to access template language variables 1326 * 1327 * @param string $id key of language string 1328 * @return string 1329 */ 1330function tpl_getLang($id) { 1331 static $lang = array(); 1332 1333 if(count($lang) === 0) { 1334 global $conf, $config_cascade; // definitely don't invoke "global $lang" 1335 1336 $path = tpl_incdir() . 'lang/'; 1337 1338 $lang = array(); 1339 1340 // don't include once 1341 @include($path . 'en/lang.php'); 1342 foreach($config_cascade['lang']['template'] as $config_file) { 1343 if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1344 include($config_file . $conf['template'] . '/en/lang.php'); 1345 } 1346 } 1347 1348 if($conf['lang'] != 'en') { 1349 @include($path . $conf['lang'] . '/lang.php'); 1350 foreach($config_cascade['lang']['template'] as $config_file) { 1351 if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1352 include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1353 } 1354 } 1355 } 1356 } 1357 return $lang[$id]; 1358} 1359 1360/** 1361 * Retrieve a language dependent file and pass to xhtml renderer for display 1362 * template equivalent of p_locale_xhtml() 1363 * 1364 * @param string $id id of language dependent wiki page 1365 * @return string parsed contents of the wiki page in xhtml format 1366 */ 1367function tpl_locale_xhtml($id) { 1368 return p_cached_output(tpl_localeFN($id)); 1369} 1370 1371/** 1372 * Prepends appropriate path for a language dependent filename 1373 * 1374 * @param string $id id of localized text 1375 * @return string wiki text 1376 */ 1377function tpl_localeFN($id) { 1378 $path = tpl_incdir().'lang/'; 1379 global $conf; 1380 $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 1381 if (!file_exists($file)){ 1382 $file = $path.$conf['lang'].'/'.$id.'.txt'; 1383 if(!file_exists($file)){ 1384 //fall back to english 1385 $file = $path.'en/'.$id.'.txt'; 1386 } 1387 } 1388 return $file; 1389} 1390 1391/** 1392 * prints the "main content" in the mediamanger popup 1393 * 1394 * Depending on the user's actions this may be a list of 1395 * files in a namespace, the meta editing dialog or 1396 * a message of referencing pages 1397 * 1398 * Only allowed in mediamanager.php 1399 * 1400 * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1401 * @param bool $fromajax - set true when calling this function via ajax 1402 * @param string $sort 1403 * 1404 * @author Andreas Gohr <andi@splitbrain.org> 1405 */ 1406function tpl_mediaContent($fromajax = false, $sort='natural') { 1407 global $IMG; 1408 global $AUTH; 1409 global $INUSE; 1410 global $NS; 1411 global $JUMPTO; 1412 /** @var Input $INPUT */ 1413 global $INPUT; 1414 1415 $do = $INPUT->extract('do')->str('do'); 1416 if(in_array($do, array('save', 'cancel'))) $do = ''; 1417 1418 if(!$do) { 1419 if($INPUT->bool('edit')) { 1420 $do = 'metaform'; 1421 } elseif(is_array($INUSE)) { 1422 $do = 'filesinuse'; 1423 } else { 1424 $do = 'filelist'; 1425 } 1426 } 1427 1428 // output the content pane, wrapped in an event. 1429 if(!$fromajax) ptln('<div id="media__content">'); 1430 $data = array('do' => $do); 1431 $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1432 if($evt->advise_before()) { 1433 $do = $data['do']; 1434 if($do == 'filesinuse') { 1435 media_filesinuse($INUSE, $IMG); 1436 } elseif($do == 'filelist') { 1437 media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1438 } elseif($do == 'searchlist') { 1439 media_searchlist($INPUT->str('q'), $NS, $AUTH); 1440 } else { 1441 msg('Unknown action '.hsc($do), -1); 1442 } 1443 } 1444 $evt->advise_after(); 1445 unset($evt); 1446 if(!$fromajax) ptln('</div>'); 1447 1448} 1449 1450/** 1451 * Prints the central column in full-screen media manager 1452 * Depending on the opened tab this may be a list of 1453 * files in a namespace, upload form or search form 1454 * 1455 * @author Kate Arzamastseva <pshns@ukr.net> 1456 */ 1457function tpl_mediaFileList() { 1458 global $AUTH; 1459 global $NS; 1460 global $JUMPTO; 1461 global $lang; 1462 /** @var Input $INPUT */ 1463 global $INPUT; 1464 1465 $opened_tab = $INPUT->str('tab_files'); 1466 if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1467 if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1468 1469 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 1470 1471 media_tabs_files($opened_tab); 1472 1473 echo '<div class="panelHeader">'.NL; 1474 echo '<h3>'; 1475 $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1476 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 1477 echo '</h3>'.NL; 1478 if($opened_tab === 'search' || $opened_tab === 'files') { 1479 media_tab_files_options(); 1480 } 1481 echo '</div>'.NL; 1482 1483 echo '<div class="panelContent">'.NL; 1484 if($opened_tab == 'files') { 1485 media_tab_files($NS, $AUTH, $JUMPTO); 1486 } elseif($opened_tab == 'upload') { 1487 media_tab_upload($NS, $AUTH, $JUMPTO); 1488 } elseif($opened_tab == 'search') { 1489 media_tab_search($NS, $AUTH); 1490 } 1491 echo '</div>'.NL; 1492} 1493 1494/** 1495 * Prints the third column in full-screen media manager 1496 * Depending on the opened tab this may be details of the 1497 * selected file, the meta editing dialog or 1498 * list of file revisions 1499 * 1500 * @author Kate Arzamastseva <pshns@ukr.net> 1501 */ 1502function tpl_mediaFileDetails($image, $rev) { 1503 global $conf, $DEL, $lang; 1504 /** @var Input $INPUT */ 1505 global $INPUT; 1506 1507 $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1508 if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 1509 if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1510 $ns = getNS($image); 1511 $do = $INPUT->str('mediado'); 1512 1513 $opened_tab = $INPUT->str('tab_details'); 1514 1515 $tab_array = array('view'); 1516 list(, $mime) = mimetype($image); 1517 if($mime == 'image/jpeg') { 1518 $tab_array[] = 'edit'; 1519 } 1520 if($conf['mediarevisions']) { 1521 $tab_array[] = 'history'; 1522 } 1523 1524 if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1525 if($INPUT->bool('edit')) $opened_tab = 'edit'; 1526 if($do == 'restore') $opened_tab = 'view'; 1527 1528 media_tabs_details($image, $opened_tab); 1529 1530 echo '<div class="panelHeader"><h3>'; 1531 list($ext) = mimetype($image, false); 1532 $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 1533 $class = 'select mediafile mf_'.$class; 1534 $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 1535 if($opened_tab === 'view' && $rev) { 1536 printf($lang['media_viewold'], $tabTitle, dformat($rev)); 1537 } else { 1538 printf($lang['media_'.$opened_tab], $tabTitle); 1539 } 1540 1541 echo '</h3></div>'.NL; 1542 1543 echo '<div class="panelContent">'.NL; 1544 1545 if($opened_tab == 'view') { 1546 media_tab_view($image, $ns, null, $rev); 1547 1548 } elseif($opened_tab == 'edit' && !$removed) { 1549 media_tab_edit($image, $ns); 1550 1551 } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1552 media_tab_history($image, $ns); 1553 } 1554 1555 echo '</div>'.NL; 1556} 1557 1558/** 1559 * prints the namespace tree in the mediamanger popup 1560 * 1561 * Only allowed in mediamanager.php 1562 * 1563 * @author Andreas Gohr <andi@splitbrain.org> 1564 */ 1565function tpl_mediaTree() { 1566 global $NS; 1567 ptln('<div id="media__tree">'); 1568 media_nstree($NS); 1569 ptln('</div>'); 1570} 1571 1572/** 1573 * Print a dropdown menu with all DokuWiki actions 1574 * 1575 * Note: this will not use any pretty URLs 1576 * 1577 * @author Andreas Gohr <andi@splitbrain.org> 1578 * 1579 * @param string $empty empty option label 1580 * @param string $button submit button label 1581 */ 1582function tpl_actiondropdown($empty = '', $button = '>') { 1583 global $ID; 1584 global $REV; 1585 global $lang; 1586 /** @var Input $INPUT */ 1587 global $INPUT; 1588 1589 echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 1590 echo '<div class="no">'; 1591 echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1592 if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1593 if ($INPUT->server->str('REMOTE_USER')) { 1594 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 1595 } 1596 1597 echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1598 echo '<option value="">'.$empty.'</option>'; 1599 1600 echo '<optgroup label="'.$lang['page_tools'].'">'; 1601 $act = tpl_get_action('edit'); 1602 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1603 1604 $act = tpl_get_action('revert'); 1605 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1606 1607 $act = tpl_get_action('revisions'); 1608 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1609 1610 $act = tpl_get_action('backlink'); 1611 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1612 1613 $act = tpl_get_action('subscribe'); 1614 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1615 echo '</optgroup>'; 1616 1617 echo '<optgroup label="'.$lang['site_tools'].'">'; 1618 $act = tpl_get_action('recent'); 1619 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1620 1621 $act = tpl_get_action('media'); 1622 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1623 1624 $act = tpl_get_action('index'); 1625 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1626 echo '</optgroup>'; 1627 1628 echo '<optgroup label="'.$lang['user_tools'].'">'; 1629 $act = tpl_get_action('login'); 1630 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1631 1632 $act = tpl_get_action('register'); 1633 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1634 1635 $act = tpl_get_action('profile'); 1636 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1637 1638 $act = tpl_get_action('admin'); 1639 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1640 echo '</optgroup>'; 1641 1642 echo '</select>'; 1643 echo '<input type="submit" value="'.$button.'" />'; 1644 echo '</div>'; 1645 echo '</form>'; 1646} 1647 1648/** 1649 * Print a informational line about the used license 1650 * 1651 * @author Andreas Gohr <andi@splitbrain.org> 1652 * @param string $img print image? (|button|badge) 1653 * @param bool $imgonly skip the textual description? 1654 * @param bool $return when true don't print, but return HTML 1655 * @param bool $wrap wrap in div with class="license"? 1656 * @return string 1657 */ 1658function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1659 global $license; 1660 global $conf; 1661 global $lang; 1662 if(!$conf['license']) return ''; 1663 if(!is_array($license[$conf['license']])) return ''; 1664 $lic = $license[$conf['license']]; 1665 $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1666 1667 $out = ''; 1668 if($wrap) $out .= '<div class="license">'; 1669 if($img) { 1670 $src = license_img($img); 1671 if($src) { 1672 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 1673 $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 1674 if(!$imgonly) $out .= ' '; 1675 } 1676 } 1677 if(!$imgonly) { 1678 $out .= $lang['license'].' '; 1679 $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1680 $out .= '>'.$lic['name'].'</a></bdi>'; 1681 } 1682 if($wrap) $out .= '</div>'; 1683 1684 if($return) return $out; 1685 echo $out; 1686 return ''; 1687} 1688 1689/** 1690 * Includes the rendered HTML of a given page 1691 * 1692 * This function is useful to populate sidebars or similar features in a 1693 * template 1694 * 1695 * @param string $pageid 1696 * @param bool $print 1697 * @param bool $propagate 1698 * @return bool|null|string 1699 */ 1700function tpl_include_page($pageid, $print = true, $propagate = false) { 1701 if (!$pageid) return false; 1702 if ($propagate) $pageid = page_findnearest($pageid); 1703 1704 global $TOC; 1705 $oldtoc = $TOC; 1706 $html = p_wiki_xhtml($pageid, '', false); 1707 $TOC = $oldtoc; 1708 1709 if(!$print) return $html; 1710 echo $html; 1711 return $html; 1712} 1713 1714/** 1715 * Display the subscribe form 1716 * 1717 * @author Adrian Lang <lang@cosmocode.de> 1718 */ 1719function tpl_subscribe() { 1720 global $INFO; 1721 global $ID; 1722 global $lang; 1723 global $conf; 1724 $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 1725 1726 echo p_locale_xhtml('subscr_form'); 1727 echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 1728 echo '<div class="level2">'; 1729 if($INFO['subscribed'] === false) { 1730 echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 1731 } else { 1732 echo '<ul>'; 1733 foreach($INFO['subscribed'] as $sub) { 1734 echo '<li><div class="li">'; 1735 if($sub['target'] !== $ID) { 1736 echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 1737 } else { 1738 echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 1739 } 1740 $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 1741 if(!$sstl) $sstl = hsc($sub['style']); 1742 echo ' ('.$sstl.') '; 1743 1744 echo '<a href="'.wl( 1745 $ID, 1746 array( 1747 'do' => 'subscribe', 1748 'sub_target'=> $sub['target'], 1749 'sub_style' => $sub['style'], 1750 'sub_action'=> 'unsubscribe', 1751 'sectok' => getSecurityToken() 1752 ) 1753 ). 1754 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 1755 '</a></div></li>'; 1756 } 1757 echo '</ul>'; 1758 } 1759 echo '</div>'; 1760 1761 // Add new subscription form 1762 echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 1763 echo '<div class="level2">'; 1764 $ns = getNS($ID).':'; 1765 $targets = array( 1766 $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 1767 $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 1768 ); 1769 $styles = array( 1770 'every' => $lang['subscr_style_every'], 1771 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 1772 'list' => sprintf($lang['subscr_style_list'], $stime_days), 1773 ); 1774 1775 $form = new Doku_Form(array('id' => 'subscribe__form')); 1776 $form->startFieldset($lang['subscr_m_subscribe']); 1777 $form->addRadioSet('sub_target', $targets); 1778 $form->startFieldset($lang['subscr_m_receive']); 1779 $form->addRadioSet('sub_style', $styles); 1780 $form->addHidden('sub_action', 'subscribe'); 1781 $form->addHidden('do', 'subscribe'); 1782 $form->addHidden('id', $ID); 1783 $form->endFieldset(); 1784 $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 1785 html_form('SUBSCRIBE', $form); 1786 echo '</div>'; 1787} 1788 1789/** 1790 * Tries to send already created content right to the browser 1791 * 1792 * Wraps around ob_flush() and flush() 1793 * 1794 * @author Andreas Gohr <andi@splitbrain.org> 1795 */ 1796function tpl_flush() { 1797 ob_flush(); 1798 flush(); 1799} 1800 1801/** 1802 * Tries to find a ressource file in the given locations. 1803 * 1804 * If a given location starts with a colon it is assumed to be a media 1805 * file, otherwise it is assumed to be relative to the current template 1806 * 1807 * @param string[] $search locations to look at 1808 * @param bool $abs if to use absolute URL 1809 * @param array &$imginfo filled with getimagesize() 1810 * @return string 1811 * 1812 * @author Andreas Gohr <andi@splitbrain.org> 1813 */ 1814function tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1815 $img = ''; 1816 $file = ''; 1817 $ismedia = false; 1818 // loop through candidates until a match was found: 1819 foreach($search as $img) { 1820 if(substr($img, 0, 1) == ':') { 1821 $file = mediaFN($img); 1822 $ismedia = true; 1823 } else { 1824 $file = tpl_incdir().$img; 1825 $ismedia = false; 1826 } 1827 1828 if(file_exists($file)) break; 1829 } 1830 1831 // fetch image data if requested 1832 if(!is_null($imginfo)) { 1833 $imginfo = getimagesize($file); 1834 } 1835 1836 // build URL 1837 if($ismedia) { 1838 $url = ml($img, '', true, '', $abs); 1839 } else { 1840 $url = tpl_basedir().$img; 1841 if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1842 } 1843 1844 return $url; 1845} 1846 1847/** 1848 * PHP include a file 1849 * 1850 * either from the conf directory if it exists, otherwise use 1851 * file in the template's root directory. 1852 * 1853 * The function honours config cascade settings and looks for the given 1854 * file next to the ´main´ config files, in the order protected, local, 1855 * default. 1856 * 1857 * Note: no escaping or sanity checking is done here. Never pass user input 1858 * to this function! 1859 * 1860 * @author Anika Henke <anika@selfthinker.org> 1861 * @author Andreas Gohr <andi@splitbrain.org> 1862 * 1863 * @param string $file 1864 */ 1865function tpl_includeFile($file) { 1866 global $config_cascade; 1867 foreach(array('protected', 'local', 'default') as $config_group) { 1868 if(empty($config_cascade['main'][$config_group])) continue; 1869 foreach($config_cascade['main'][$config_group] as $conf_file) { 1870 $dir = dirname($conf_file); 1871 if(file_exists("$dir/$file")) { 1872 include("$dir/$file"); 1873 return; 1874 } 1875 } 1876 } 1877 1878 // still here? try the template dir 1879 $file = tpl_incdir().$file; 1880 if(file_exists($file)) { 1881 include($file); 1882 } 1883} 1884 1885/** 1886 * Returns <link> tag for various icon types (favicon|mobile|generic) 1887 * 1888 * @author Anika Henke <anika@selfthinker.org> 1889 * 1890 * @param array $types - list of icon types to display (favicon|mobile|generic) 1891 * @return string 1892 */ 1893function tpl_favicon($types = array('favicon')) { 1894 1895 $return = ''; 1896 1897 foreach($types as $type) { 1898 switch($type) { 1899 case 'favicon': 1900 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1901 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1902 break; 1903 case 'mobile': 1904 $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1905 $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1906 break; 1907 case 'generic': 1908 // ideal world solution, which doesn't work in any browser yet 1909 $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1910 $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1911 break; 1912 } 1913 } 1914 1915 return $return; 1916} 1917 1918/** 1919 * Prints full-screen media manager 1920 * 1921 * @author Kate Arzamastseva <pshns@ukr.net> 1922 */ 1923function tpl_media() { 1924 global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 1925 $fullscreen = true; 1926 require_once DOKU_INC.'lib/exe/mediamanager.php'; 1927 1928 $rev = ''; 1929 $image = cleanID($INPUT->str('image')); 1930 if(isset($IMG)) $image = $IMG; 1931 if(isset($JUMPTO)) $image = $JUMPTO; 1932 if(isset($REV) && !$JUMPTO) $rev = $REV; 1933 1934 echo '<div id="mediamanager__page">'.NL; 1935 echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1936 html_msgarea(); 1937 1938 echo '<div class="panel namespaces">'.NL; 1939 echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 1940 echo '<div class="panelHeader">'; 1941 echo $lang['media_namespaces']; 1942 echo '</div>'.NL; 1943 1944 echo '<div class="panelContent" id="media__tree">'.NL; 1945 media_nstree($NS); 1946 echo '</div>'.NL; 1947 echo '</div>'.NL; 1948 1949 echo '<div class="panel filelist">'.NL; 1950 tpl_mediaFileList(); 1951 echo '</div>'.NL; 1952 1953 echo '<div class="panel file">'.NL; 1954 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1955 tpl_mediaFileDetails($image, $rev); 1956 echo '</div>'.NL; 1957 1958 echo '</div>'.NL; 1959} 1960 1961/** 1962 * Return useful layout classes 1963 * 1964 * @author Anika Henke <anika@selfthinker.org> 1965 * 1966 * @return string 1967 */ 1968function tpl_classes() { 1969 global $ACT, $conf, $ID, $INFO; 1970 /** @var Input $INPUT */ 1971 global $INPUT; 1972 1973 $classes = array( 1974 'dokuwiki', 1975 'mode_'.$ACT, 1976 'tpl_'.$conf['template'], 1977 $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 1978 $INFO['exists'] ? '' : 'notFound', 1979 ($ID == $conf['start']) ? 'home' : '', 1980 ); 1981 return join(' ', $classes); 1982} 1983 1984//Setup VIM: ex: et ts=4 : 1985 1986