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