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