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