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