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 print 'placeholder="'.$lang['btn_search'].'" '; 844 if(!$autocomplete) print 'autocomplete="off" '; 845 print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 846 print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 847 if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 848 print '</div></form>'; 849 return true; 850} 851 852/** 853 * Print the breadcrumbs trace 854 * 855 * @author Andreas Gohr <andi@splitbrain.org> 856 * 857 * @param string $sep Separator between entries 858 * @return bool 859 */ 860function tpl_breadcrumbs($sep = '•') { 861 global $lang; 862 global $conf; 863 864 //check if enabled 865 if(!$conf['breadcrumbs']) return false; 866 867 $crumbs = breadcrumbs(); //setup crumb trace 868 869 $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 870 871 //render crumbs, highlight the last one 872 print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 873 $last = count($crumbs); 874 $i = 0; 875 foreach($crumbs as $id => $name) { 876 $i++; 877 echo $crumbs_sep; 878 if($i == $last) print '<span class="curid">'; 879 print '<bdi>'; 880 tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 881 print '</bdi>'; 882 if($i == $last) print '</span>'; 883 } 884 return true; 885} 886 887/** 888 * Hierarchical breadcrumbs 889 * 890 * This code was suggested as replacement for the usual breadcrumbs. 891 * It only makes sense with a deep site structure. 892 * 893 * @author Andreas Gohr <andi@splitbrain.org> 894 * @author Nigel McNie <oracle.shinoda@gmail.com> 895 * @author Sean Coates <sean@caedmon.net> 896 * @author <fredrik@averpil.com> 897 * @author Mark C. Prins <mprins@users.sf.net> 898 * 899 * @param string $sep Separator between entries 900 * @return bool 901 */ 902function tpl_youarehere($sep = ' → ') { 903 global $conf; 904 global $ID; 905 global $lang; 906 907 // check if enabled 908 if(!$conf['youarehere']) return false; 909 910 $parts = explode(':', $ID); 911 $count = count($parts); 912 913 echo '<nav><h2 class="bchead">'.$lang['youarehere'].': </h2>'; 914 echo '<ul class="navlist">'; 915 // always print the startpage 916 if ($count > 1) { 917 echo '<li class="home">'.html_wikilink(':'.$conf['start']).$sep.'</li>'; 918 } else { 919 echo '<li class="home">'.$conf['start'].'</li>'; 920 } 921 922 923 // print intermediate namespace links 924 $part = ''; 925 for($i = 0; $i < $count - 1; $i++) { 926 $part .= $parts[$i].':'; 927 $page = $part; 928 if($page == $conf['start']) continue; // Skip startpage 929 930 echo '<li>'.html_wikilink($page); 931 if ($i < $count - 2) { 932 echo $sep.'</li>'; 933 } else { 934 echo '</li>'; 935 } 936 } 937 938 // print current page, skipping start page, skipping for namespace index 939 resolve_pageid('', $page, $exists); 940 if(isset($page) && $page == $part.$parts[$i]) { 941 echo '</li></ul></nav>'; 942 return true; 943 } 944 945 $page = $part.$parts[$i]; 946 if($page == $conf['start']) { 947 echo '</li></ul></nav>'; 948 return true; 949 } 950 951 echo $sep.'</li><li class="curid">'.noNSorNS($page).'</li></ul></nav>'; 952 return true; 953} 954 955/** 956 * Print info if the user is logged in 957 * and show full name in that case 958 * 959 * Could be enhanced with a profile link in future? 960 * 961 * @author Andreas Gohr <andi@splitbrain.org> 962 * 963 * @return bool 964 */ 965function tpl_userinfo() { 966 global $lang; 967 /** @var Input $INPUT */ 968 global $INPUT; 969 970 if($INPUT->server->str('REMOTE_USER')) { 971 print $lang['loggedinas'].' '.userlink(); 972 return true; 973 } 974 return false; 975} 976 977/** 978 * Print some info about the current page 979 * 980 * @author Andreas Gohr <andi@splitbrain.org> 981 * 982 * @param bool $ret return content instead of printing it 983 * @return bool|string 984 */ 985function tpl_pageinfo($ret = false) { 986 global $conf; 987 global $lang; 988 global $INFO; 989 global $ID; 990 991 // return if we are not allowed to view the page 992 if(!auth_quickaclcheck($ID)) { 993 return false; 994 } 995 996 // prepare date and path 997 $fn = $INFO['filepath']; 998 if(!$conf['fullpath']) { 999 if($INFO['rev']) { 1000 $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 1001 } else { 1002 $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 1003 } 1004 } 1005 $fn = utf8_decodeFN($fn); 1006 $date = dformat($INFO['lastmod']); 1007 1008 // print it 1009 if($INFO['exists']) { 1010 $out = ''; 1011 $out .= '<bdi>'.$fn.'</bdi>'; 1012 $out .= ' · '; 1013 $out .= $lang['lastmod']; 1014 $out .= ' '; 1015 $out .= $date; 1016 if($INFO['editor']) { 1017 $out .= ' '.$lang['by'].' '; 1018 $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 1019 } else { 1020 $out .= ' ('.$lang['external_edit'].')'; 1021 } 1022 if($INFO['locked']) { 1023 $out .= ' · '; 1024 $out .= $lang['lockedby']; 1025 $out .= ' '; 1026 $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 1027 } 1028 if($ret) { 1029 return $out; 1030 } else { 1031 echo $out; 1032 return true; 1033 } 1034 } 1035 return false; 1036} 1037 1038/** 1039 * Prints or returns the name of the given page (current one if none given). 1040 * 1041 * If useheading is enabled this will use the first headline else 1042 * the given ID is used. 1043 * 1044 * @author Andreas Gohr <andi@splitbrain.org> 1045 * 1046 * @param string $id page id 1047 * @param bool $ret return content instead of printing 1048 * @return bool|string 1049 */ 1050function tpl_pagetitle($id = null, $ret = false) { 1051 if(is_null($id)) { 1052 global $ID; 1053 $id = $ID; 1054 } 1055 1056 $name = $id; 1057 if(useHeading('navigation')) { 1058 $title = p_get_first_heading($id); 1059 if($title) $name = $title; 1060 } 1061 1062 if($ret) { 1063 return hsc($name); 1064 } else { 1065 print hsc($name); 1066 return true; 1067 } 1068} 1069 1070/** 1071 * Returns the requested EXIF/IPTC tag from the current image 1072 * 1073 * If $tags is an array all given tags are tried until a 1074 * value is found. If no value is found $alt is returned. 1075 * 1076 * Which texts are known is defined in the functions _exifTagNames 1077 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 1078 * to the names of the latter one) 1079 * 1080 * Only allowed in: detail.php 1081 * 1082 * @author Andreas Gohr <andi@splitbrain.org> 1083 * 1084 * @param array|string $tags tag or array of tags to try 1085 * @param string $alt alternative output if no data was found 1086 * @param null|string $src the image src, uses global $SRC if not given 1087 * @return string 1088 */ 1089function tpl_img_getTag($tags, $alt = '', $src = null) { 1090 // Init Exif Reader 1091 global $SRC; 1092 1093 if(is_null($src)) $src = $SRC; 1094 1095 static $meta = null; 1096 if(is_null($meta)) $meta = new JpegMeta($src); 1097 if($meta === false) return $alt; 1098 $info = cleanText($meta->getField($tags)); 1099 if($info == false) return $alt; 1100 return $info; 1101} 1102 1103/** 1104 * Returns a description list of the metatags of the current image 1105 * 1106 * @return string html of description list 1107 */ 1108function tpl_img_meta() { 1109 global $lang; 1110 1111 $tags = tpl_get_img_meta(); 1112 1113 echo '<dl>'; 1114 foreach($tags as $tag) { 1115 $label = $lang[$tag['langkey']]; 1116 if(!$label) $label = $tag['langkey'] . ':'; 1117 1118 echo '<dt>'.$label.'</dt><dd>'; 1119 if ($tag['type'] == 'date') { 1120 echo dformat($tag['value']); 1121 } else { 1122 echo hsc($tag['value']); 1123 } 1124 echo '</dd>'; 1125 } 1126 echo '</dl>'; 1127} 1128 1129/** 1130 * Returns metadata as configured in mediameta config file, ready for creating html 1131 * 1132 * @return array with arrays containing the entries: 1133 * - string langkey key to lookup in the $lang var, if not found printed as is 1134 * - string type type of value 1135 * - string value tag value (unescaped) 1136 */ 1137function tpl_get_img_meta() { 1138 1139 $config_files = getConfigFiles('mediameta'); 1140 foreach ($config_files as $config_file) { 1141 if(file_exists($config_file)) { 1142 include($config_file); 1143 } 1144 } 1145 /** @var array $fields the included array with metadata */ 1146 1147 $tags = array(); 1148 foreach($fields as $tag){ 1149 $t = array(); 1150 if (!empty($tag[0])) { 1151 $t = array($tag[0]); 1152 } 1153 if(is_array($tag[3])) { 1154 $t = array_merge($t,$tag[3]); 1155 } 1156 $value = tpl_img_getTag($t); 1157 if ($value) { 1158 $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1159 } 1160 } 1161 return $tags; 1162} 1163 1164/** 1165 * Prints the image with a link to the full sized version 1166 * 1167 * Only allowed in: detail.php 1168 * 1169 * @triggers TPL_IMG_DISPLAY 1170 * @param $maxwidth int - maximal width of the image 1171 * @param $maxheight int - maximal height of the image 1172 * @param $link bool - link to the orginal size? 1173 * @param $params array - additional image attributes 1174 * @return bool Result of TPL_IMG_DISPLAY 1175 */ 1176function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 1177 global $IMG; 1178 /** @var Input $INPUT */ 1179 global $INPUT; 1180 global $REV; 1181 $w = tpl_img_getTag('File.Width'); 1182 $h = tpl_img_getTag('File.Height'); 1183 1184 //resize to given max values 1185 $ratio = 1; 1186 if($w >= $h) { 1187 if($maxwidth && $w >= $maxwidth) { 1188 $ratio = $maxwidth / $w; 1189 } elseif($maxheight && $h > $maxheight) { 1190 $ratio = $maxheight / $h; 1191 } 1192 } else { 1193 if($maxheight && $h >= $maxheight) { 1194 $ratio = $maxheight / $h; 1195 } elseif($maxwidth && $w > $maxwidth) { 1196 $ratio = $maxwidth / $w; 1197 } 1198 } 1199 if($ratio) { 1200 $w = floor($ratio * $w); 1201 $h = floor($ratio * $h); 1202 } 1203 1204 //prepare URLs 1205 $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 1206 $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 1207 1208 //prepare attributes 1209 $alt = tpl_img_getTag('Simple.Title'); 1210 if(is_null($params)) { 1211 $p = array(); 1212 } else { 1213 $p = $params; 1214 } 1215 if($w) $p['width'] = $w; 1216 if($h) $p['height'] = $h; 1217 $p['class'] = 'img_detail'; 1218 if($alt) { 1219 $p['alt'] = $alt; 1220 $p['title'] = $alt; 1221 } else { 1222 $p['alt'] = ''; 1223 } 1224 $p['src'] = $src; 1225 1226 $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1227 return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1228} 1229 1230/** 1231 * Default action for TPL_IMG_DISPLAY 1232 * 1233 * @param array $data 1234 * @return bool 1235 */ 1236function _tpl_img_action($data) { 1237 global $lang; 1238 $p = buildAttributes($data['params']); 1239 1240 if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1241 print '<img '.$p.'/>'; 1242 if($data['url']) print '</a>'; 1243 return true; 1244} 1245 1246/** 1247 * This function inserts a small gif which in reality is the indexer function. 1248 * 1249 * Should be called somewhere at the very end of the main.php 1250 * template 1251 * 1252 * @return bool 1253 */ 1254function tpl_indexerWebBug() { 1255 global $ID; 1256 1257 $p = array(); 1258 $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1259 '&'.time(); 1260 $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 1261 $p['height'] = 1; 1262 $p['alt'] = ''; 1263 $att = buildAttributes($p); 1264 print "<img $att />"; 1265 return true; 1266} 1267 1268/** 1269 * tpl_getConf($id) 1270 * 1271 * use this function to access template configuration variables 1272 * 1273 * @param string $id name of the value to access 1274 * @param mixed $notset what to return if the setting is not available 1275 * @return mixed 1276 */ 1277function tpl_getConf($id, $notset=false) { 1278 global $conf; 1279 static $tpl_configloaded = false; 1280 1281 $tpl = $conf['template']; 1282 1283 if(!$tpl_configloaded) { 1284 $tconf = tpl_loadConfig(); 1285 if($tconf !== false) { 1286 foreach($tconf as $key => $value) { 1287 if(isset($conf['tpl'][$tpl][$key])) continue; 1288 $conf['tpl'][$tpl][$key] = $value; 1289 } 1290 $tpl_configloaded = true; 1291 } 1292 } 1293 1294 if(isset($conf['tpl'][$tpl][$id])){ 1295 return $conf['tpl'][$tpl][$id]; 1296 } 1297 1298 return $notset; 1299} 1300 1301/** 1302 * tpl_loadConfig() 1303 * 1304 * reads all template configuration variables 1305 * this function is automatically called by tpl_getConf() 1306 * 1307 * @return array 1308 */ 1309function tpl_loadConfig() { 1310 1311 $file = tpl_incdir().'/conf/default.php'; 1312 $conf = array(); 1313 1314 if(!file_exists($file)) return false; 1315 1316 // load default config file 1317 include($file); 1318 1319 return $conf; 1320} 1321 1322// language methods 1323/** 1324 * tpl_getLang($id) 1325 * 1326 * use this function to access template language variables 1327 * 1328 * @param string $id key of language string 1329 * @return string 1330 */ 1331function tpl_getLang($id) { 1332 static $lang = array(); 1333 1334 if(count($lang) === 0) { 1335 global $conf, $config_cascade; // definitely don't invoke "global $lang" 1336 1337 $path = tpl_incdir() . 'lang/'; 1338 1339 $lang = array(); 1340 1341 // don't include once 1342 @include($path . 'en/lang.php'); 1343 foreach($config_cascade['lang']['template'] as $config_file) { 1344 if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1345 include($config_file . $conf['template'] . '/en/lang.php'); 1346 } 1347 } 1348 1349 if($conf['lang'] != 'en') { 1350 @include($path . $conf['lang'] . '/lang.php'); 1351 foreach($config_cascade['lang']['template'] as $config_file) { 1352 if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1353 include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1354 } 1355 } 1356 } 1357 } 1358 return $lang[$id]; 1359} 1360 1361/** 1362 * Retrieve a language dependent file and pass to xhtml renderer for display 1363 * template equivalent of p_locale_xhtml() 1364 * 1365 * @param string $id id of language dependent wiki page 1366 * @return string parsed contents of the wiki page in xhtml format 1367 */ 1368function tpl_locale_xhtml($id) { 1369 return p_cached_output(tpl_localeFN($id)); 1370} 1371 1372/** 1373 * Prepends appropriate path for a language dependent filename 1374 * 1375 * @param string $id id of localized text 1376 * @return string wiki text 1377 */ 1378function tpl_localeFN($id) { 1379 $path = tpl_incdir().'lang/'; 1380 global $conf; 1381 $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 1382 if (!file_exists($file)){ 1383 $file = $path.$conf['lang'].'/'.$id.'.txt'; 1384 if(!file_exists($file)){ 1385 //fall back to english 1386 $file = $path.'en/'.$id.'.txt'; 1387 } 1388 } 1389 return $file; 1390} 1391 1392/** 1393 * prints the "main content" in the mediamanger popup 1394 * 1395 * Depending on the user's actions this may be a list of 1396 * files in a namespace, the meta editing dialog or 1397 * a message of referencing pages 1398 * 1399 * Only allowed in mediamanager.php 1400 * 1401 * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1402 * @param bool $fromajax - set true when calling this function via ajax 1403 * @param string $sort 1404 * 1405 * @author Andreas Gohr <andi@splitbrain.org> 1406 */ 1407function tpl_mediaContent($fromajax = false, $sort='natural') { 1408 global $IMG; 1409 global $AUTH; 1410 global $INUSE; 1411 global $NS; 1412 global $JUMPTO; 1413 /** @var Input $INPUT */ 1414 global $INPUT; 1415 1416 $do = $INPUT->extract('do')->str('do'); 1417 if(in_array($do, array('save', 'cancel'))) $do = ''; 1418 1419 if(!$do) { 1420 if($INPUT->bool('edit')) { 1421 $do = 'metaform'; 1422 } elseif(is_array($INUSE)) { 1423 $do = 'filesinuse'; 1424 } else { 1425 $do = 'filelist'; 1426 } 1427 } 1428 1429 // output the content pane, wrapped in an event. 1430 if(!$fromajax) ptln('<div id="media__content">'); 1431 $data = array('do' => $do); 1432 $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1433 if($evt->advise_before()) { 1434 $do = $data['do']; 1435 if($do == 'filesinuse') { 1436 media_filesinuse($INUSE, $IMG); 1437 } elseif($do == 'filelist') { 1438 media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1439 } elseif($do == 'searchlist') { 1440 media_searchlist($INPUT->str('q'), $NS, $AUTH); 1441 } else { 1442 msg('Unknown action '.hsc($do), -1); 1443 } 1444 } 1445 $evt->advise_after(); 1446 unset($evt); 1447 if(!$fromajax) ptln('</div>'); 1448 1449} 1450 1451/** 1452 * Prints the central column in full-screen media manager 1453 * Depending on the opened tab this may be a list of 1454 * files in a namespace, upload form or search form 1455 * 1456 * @author Kate Arzamastseva <pshns@ukr.net> 1457 */ 1458function tpl_mediaFileList() { 1459 global $AUTH; 1460 global $NS; 1461 global $JUMPTO; 1462 global $lang; 1463 /** @var Input $INPUT */ 1464 global $INPUT; 1465 1466 $opened_tab = $INPUT->str('tab_files'); 1467 if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1468 if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1469 1470 echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 1471 1472 media_tabs_files($opened_tab); 1473 1474 echo '<div class="panelHeader">'.NL; 1475 echo '<h3>'; 1476 $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1477 printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 1478 echo '</h3>'.NL; 1479 if($opened_tab === 'search' || $opened_tab === 'files') { 1480 media_tab_files_options(); 1481 } 1482 echo '</div>'.NL; 1483 1484 echo '<div class="panelContent">'.NL; 1485 if($opened_tab == 'files') { 1486 media_tab_files($NS, $AUTH, $JUMPTO); 1487 } elseif($opened_tab == 'upload') { 1488 media_tab_upload($NS, $AUTH, $JUMPTO); 1489 } elseif($opened_tab == 'search') { 1490 media_tab_search($NS, $AUTH); 1491 } 1492 echo '</div>'.NL; 1493} 1494 1495/** 1496 * Prints the third column in full-screen media manager 1497 * Depending on the opened tab this may be details of the 1498 * selected file, the meta editing dialog or 1499 * list of file revisions 1500 * 1501 * @author Kate Arzamastseva <pshns@ukr.net> 1502 */ 1503function tpl_mediaFileDetails($image, $rev) { 1504 global $conf, $DEL, $lang; 1505 /** @var Input $INPUT */ 1506 global $INPUT; 1507 1508 $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1509 if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 1510 if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1511 $ns = getNS($image); 1512 $do = $INPUT->str('mediado'); 1513 1514 $opened_tab = $INPUT->str('tab_details'); 1515 1516 $tab_array = array('view'); 1517 list(, $mime) = mimetype($image); 1518 if($mime == 'image/jpeg') { 1519 $tab_array[] = 'edit'; 1520 } 1521 if($conf['mediarevisions']) { 1522 $tab_array[] = 'history'; 1523 } 1524 1525 if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1526 if($INPUT->bool('edit')) $opened_tab = 'edit'; 1527 if($do == 'restore') $opened_tab = 'view'; 1528 1529 media_tabs_details($image, $opened_tab); 1530 1531 echo '<div class="panelHeader"><h3>'; 1532 list($ext) = mimetype($image, false); 1533 $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 1534 $class = 'select mediafile mf_'.$class; 1535 $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 1536 if($opened_tab === 'view' && $rev) { 1537 printf($lang['media_viewold'], $tabTitle, dformat($rev)); 1538 } else { 1539 printf($lang['media_'.$opened_tab], $tabTitle); 1540 } 1541 1542 echo '</h3></div>'.NL; 1543 1544 echo '<div class="panelContent">'.NL; 1545 1546 if($opened_tab == 'view') { 1547 media_tab_view($image, $ns, null, $rev); 1548 1549 } elseif($opened_tab == 'edit' && !$removed) { 1550 media_tab_edit($image, $ns); 1551 1552 } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1553 media_tab_history($image, $ns); 1554 } 1555 1556 echo '</div>'.NL; 1557} 1558 1559/** 1560 * prints the namespace tree in the mediamanger popup 1561 * 1562 * Only allowed in mediamanager.php 1563 * 1564 * @author Andreas Gohr <andi@splitbrain.org> 1565 */ 1566function tpl_mediaTree() { 1567 global $NS; 1568 ptln('<div id="media__tree">'); 1569 media_nstree($NS); 1570 ptln('</div>'); 1571} 1572 1573/** 1574 * Print a dropdown menu with all DokuWiki actions 1575 * 1576 * Note: this will not use any pretty URLs 1577 * 1578 * @author Andreas Gohr <andi@splitbrain.org> 1579 * 1580 * @param string $empty empty option label 1581 * @param string $button submit button label 1582 */ 1583function tpl_actiondropdown($empty = '', $button = '>') { 1584 global $ID; 1585 global $REV; 1586 global $lang; 1587 /** @var Input $INPUT */ 1588 global $INPUT; 1589 1590 echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 1591 echo '<div class="no">'; 1592 echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1593 if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1594 if ($INPUT->server->str('REMOTE_USER')) { 1595 echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 1596 } 1597 1598 echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1599 echo '<option value="">'.$empty.'</option>'; 1600 1601 echo '<optgroup label="'.$lang['page_tools'].'">'; 1602 $act = tpl_get_action('edit'); 1603 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1604 1605 $act = tpl_get_action('revert'); 1606 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1607 1608 $act = tpl_get_action('revisions'); 1609 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1610 1611 $act = tpl_get_action('backlink'); 1612 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1613 1614 $act = tpl_get_action('subscribe'); 1615 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1616 echo '</optgroup>'; 1617 1618 echo '<optgroup label="'.$lang['site_tools'].'">'; 1619 $act = tpl_get_action('recent'); 1620 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1621 1622 $act = tpl_get_action('media'); 1623 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1624 1625 $act = tpl_get_action('index'); 1626 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1627 echo '</optgroup>'; 1628 1629 echo '<optgroup label="'.$lang['user_tools'].'">'; 1630 $act = tpl_get_action('login'); 1631 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1632 1633 $act = tpl_get_action('register'); 1634 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1635 1636 $act = tpl_get_action('profile'); 1637 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1638 1639 $act = tpl_get_action('admin'); 1640 if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1641 echo '</optgroup>'; 1642 1643 echo '</select>'; 1644 echo '<input type="submit" value="'.$button.'" />'; 1645 echo '</div>'; 1646 echo '</form>'; 1647} 1648 1649/** 1650 * Print a informational line about the used license 1651 * 1652 * @author Andreas Gohr <andi@splitbrain.org> 1653 * @param string $img print image? (|button|badge) 1654 * @param bool $imgonly skip the textual description? 1655 * @param bool $return when true don't print, but return HTML 1656 * @param bool $wrap wrap in div with class="license"? 1657 * @return string 1658 */ 1659function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1660 global $license; 1661 global $conf; 1662 global $lang; 1663 if(!$conf['license']) return ''; 1664 if(!is_array($license[$conf['license']])) return ''; 1665 $lic = $license[$conf['license']]; 1666 $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1667 1668 $out = ''; 1669 if($wrap) $out .= '<div class="license">'; 1670 if($img) { 1671 $src = license_img($img); 1672 if($src) { 1673 $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 1674 $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 1675 if(!$imgonly) $out .= ' '; 1676 } 1677 } 1678 if(!$imgonly) { 1679 $out .= $lang['license'].' '; 1680 $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1681 $out .= '>'.$lic['name'].'</a></bdi>'; 1682 } 1683 if($wrap) $out .= '</div>'; 1684 1685 if($return) return $out; 1686 echo $out; 1687 return ''; 1688} 1689 1690/** 1691 * Includes the rendered HTML of a given page 1692 * 1693 * This function is useful to populate sidebars or similar features in a 1694 * template 1695 * 1696 * @param string $pageid 1697 * @param bool $print 1698 * @param bool $propagate 1699 * @return bool|null|string 1700 */ 1701function tpl_include_page($pageid, $print = true, $propagate = false) { 1702 if (!$pageid) return false; 1703 if ($propagate) $pageid = page_findnearest($pageid); 1704 1705 global $TOC; 1706 $oldtoc = $TOC; 1707 $html = p_wiki_xhtml($pageid, '', false); 1708 $TOC = $oldtoc; 1709 1710 if(!$print) return $html; 1711 echo $html; 1712 return $html; 1713} 1714 1715/** 1716 * Display the subscribe form 1717 * 1718 * @author Adrian Lang <lang@cosmocode.de> 1719 */ 1720function tpl_subscribe() { 1721 global $INFO; 1722 global $ID; 1723 global $lang; 1724 global $conf; 1725 $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 1726 1727 echo p_locale_xhtml('subscr_form'); 1728 echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 1729 echo '<div class="level2">'; 1730 if($INFO['subscribed'] === false) { 1731 echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 1732 } else { 1733 echo '<ul>'; 1734 foreach($INFO['subscribed'] as $sub) { 1735 echo '<li><div class="li">'; 1736 if($sub['target'] !== $ID) { 1737 echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 1738 } else { 1739 echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 1740 } 1741 $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 1742 if(!$sstl) $sstl = hsc($sub['style']); 1743 echo ' ('.$sstl.') '; 1744 1745 echo '<a href="'.wl( 1746 $ID, 1747 array( 1748 'do' => 'subscribe', 1749 'sub_target'=> $sub['target'], 1750 'sub_style' => $sub['style'], 1751 'sub_action'=> 'unsubscribe', 1752 'sectok' => getSecurityToken() 1753 ) 1754 ). 1755 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 1756 '</a></div></li>'; 1757 } 1758 echo '</ul>'; 1759 } 1760 echo '</div>'; 1761 1762 // Add new subscription form 1763 echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 1764 echo '<div class="level2">'; 1765 $ns = getNS($ID).':'; 1766 $targets = array( 1767 $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 1768 $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 1769 ); 1770 $styles = array( 1771 'every' => $lang['subscr_style_every'], 1772 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 1773 'list' => sprintf($lang['subscr_style_list'], $stime_days), 1774 ); 1775 1776 $form = new Doku_Form(array('id' => 'subscribe__form')); 1777 $form->startFieldset($lang['subscr_m_subscribe']); 1778 $form->addRadioSet('sub_target', $targets); 1779 $form->startFieldset($lang['subscr_m_receive']); 1780 $form->addRadioSet('sub_style', $styles); 1781 $form->addHidden('sub_action', 'subscribe'); 1782 $form->addHidden('do', 'subscribe'); 1783 $form->addHidden('id', $ID); 1784 $form->endFieldset(); 1785 $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 1786 html_form('SUBSCRIBE', $form); 1787 echo '</div>'; 1788} 1789 1790/** 1791 * Tries to send already created content right to the browser 1792 * 1793 * Wraps around ob_flush() and flush() 1794 * 1795 * @author Andreas Gohr <andi@splitbrain.org> 1796 */ 1797function tpl_flush() { 1798 ob_flush(); 1799 flush(); 1800} 1801 1802/** 1803 * Tries to find a ressource file in the given locations. 1804 * 1805 * If a given location starts with a colon it is assumed to be a media 1806 * file, otherwise it is assumed to be relative to the current template 1807 * 1808 * @param string[] $search locations to look at 1809 * @param bool $abs if to use absolute URL 1810 * @param array &$imginfo filled with getimagesize() 1811 * @return string 1812 * 1813 * @author Andreas Gohr <andi@splitbrain.org> 1814 */ 1815function tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1816 $img = ''; 1817 $file = ''; 1818 $ismedia = false; 1819 // loop through candidates until a match was found: 1820 foreach($search as $img) { 1821 if(substr($img, 0, 1) == ':') { 1822 $file = mediaFN($img); 1823 $ismedia = true; 1824 } else { 1825 $file = tpl_incdir().$img; 1826 $ismedia = false; 1827 } 1828 1829 if(file_exists($file)) break; 1830 } 1831 1832 // fetch image data if requested 1833 if(!is_null($imginfo)) { 1834 $imginfo = getimagesize($file); 1835 } 1836 1837 // build URL 1838 if($ismedia) { 1839 $url = ml($img, '', true, '', $abs); 1840 } else { 1841 $url = tpl_basedir().$img; 1842 if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1843 } 1844 1845 return $url; 1846} 1847 1848/** 1849 * PHP include a file 1850 * 1851 * either from the conf directory if it exists, otherwise use 1852 * file in the template's root directory. 1853 * 1854 * The function honours config cascade settings and looks for the given 1855 * file next to the ´main´ config files, in the order protected, local, 1856 * default. 1857 * 1858 * Note: no escaping or sanity checking is done here. Never pass user input 1859 * to this function! 1860 * 1861 * @author Anika Henke <anika@selfthinker.org> 1862 * @author Andreas Gohr <andi@splitbrain.org> 1863 * 1864 * @param string $file 1865 */ 1866function tpl_includeFile($file) { 1867 global $config_cascade; 1868 foreach(array('protected', 'local', 'default') as $config_group) { 1869 if(empty($config_cascade['main'][$config_group])) continue; 1870 foreach($config_cascade['main'][$config_group] as $conf_file) { 1871 $dir = dirname($conf_file); 1872 if(file_exists("$dir/$file")) { 1873 include("$dir/$file"); 1874 return; 1875 } 1876 } 1877 } 1878 1879 // still here? try the template dir 1880 $file = tpl_incdir().$file; 1881 if(file_exists($file)) { 1882 include($file); 1883 } 1884} 1885 1886/** 1887 * Returns <link> tag for various icon types (favicon|mobile|generic) 1888 * 1889 * @author Anika Henke <anika@selfthinker.org> 1890 * 1891 * @param array $types - list of icon types to display (favicon|mobile|generic) 1892 * @return string 1893 */ 1894function tpl_favicon($types = array('favicon')) { 1895 1896 $return = ''; 1897 1898 foreach($types as $type) { 1899 switch($type) { 1900 case 'favicon': 1901 $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1902 $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1903 break; 1904 case 'mobile': 1905 $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1906 $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1907 break; 1908 case 'generic': 1909 // ideal world solution, which doesn't work in any browser yet 1910 $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1911 $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1912 break; 1913 } 1914 } 1915 1916 return $return; 1917} 1918 1919/** 1920 * Prints full-screen media manager 1921 * 1922 * @author Kate Arzamastseva <pshns@ukr.net> 1923 */ 1924function tpl_media() { 1925 global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 1926 $fullscreen = true; 1927 require_once DOKU_INC.'lib/exe/mediamanager.php'; 1928 1929 $rev = ''; 1930 $image = cleanID($INPUT->str('image')); 1931 if(isset($IMG)) $image = $IMG; 1932 if(isset($JUMPTO)) $image = $JUMPTO; 1933 if(isset($REV) && !$JUMPTO) $rev = $REV; 1934 1935 echo '<div id="mediamanager__page">'.NL; 1936 echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1937 html_msgarea(); 1938 1939 echo '<div class="panel namespaces">'.NL; 1940 echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 1941 echo '<div class="panelHeader">'; 1942 echo $lang['media_namespaces']; 1943 echo '</div>'.NL; 1944 1945 echo '<div class="panelContent" id="media__tree">'.NL; 1946 media_nstree($NS); 1947 echo '</div>'.NL; 1948 echo '</div>'.NL; 1949 1950 echo '<div class="panel filelist">'.NL; 1951 tpl_mediaFileList(); 1952 echo '</div>'.NL; 1953 1954 echo '<div class="panel file">'.NL; 1955 echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1956 tpl_mediaFileDetails($image, $rev); 1957 echo '</div>'.NL; 1958 1959 echo '</div>'.NL; 1960} 1961 1962/** 1963 * Return useful layout classes 1964 * 1965 * @author Anika Henke <anika@selfthinker.org> 1966 * 1967 * @return string 1968 */ 1969function tpl_classes() { 1970 global $ACT, $conf, $ID, $INFO; 1971 /** @var Input $INPUT */ 1972 global $INPUT; 1973 1974 $classes = array( 1975 'dokuwiki', 1976 'mode_'.$ACT, 1977 'tpl_'.$conf['template'], 1978 $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 1979 $INFO['exists'] ? '' : 'notFound', 1980 ($ID == $conf['start']) ? 'home' : '', 1981 ); 1982 return join(' ', $classes); 1983} 1984 1985//Setup VIM: ex: et ts=4 : 1986 1987