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