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