16b13307fSandi<?php 26b13307fSandi/** 36b13307fSandi * DokuWiki template functions 46b13307fSandi * 56b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 66b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 76b13307fSandi */ 86b13307fSandi 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 106b13307fSandi 116b13307fSandi/** 12ac7a515fSAndreas Gohr * Access a template file 13ac7a515fSAndreas Gohr * 14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 165a892029SAndreas Gohr * 175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18ac7a515fSAndreas Gohr * @param string $file 19ac7a515fSAndreas Gohr * @return string 205a892029SAndreas Gohr */ 21ac7a515fSAndreas Gohrfunction template($file) { 225a892029SAndreas Gohr global $conf; 235a892029SAndreas Gohr 24ac7a515fSAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 25ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 265a892029SAndreas Gohr 27ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 285a892029SAndreas Gohr} 295a892029SAndreas Gohr 30c4766956SAndreas Gohr/** 31c4766956SAndreas Gohr * Convenience function to access template dir from local FS 32c4766956SAndreas Gohr * 33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 34c4766956SAndreas Gohr * 35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 37ac7a515fSAndreas Gohr * @return string 38c4766956SAndreas Gohr */ 39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') { 4075b14482SAndreas Gohr global $conf; 41afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 42afb2c082SAndreas Gohr return DOKU_INC.'lib/tpl/'.$tpl.'/'; 43c4766956SAndreas Gohr} 44c4766956SAndreas Gohr 45c4766956SAndreas Gohr/** 46c4766956SAndreas Gohr * Convenience function to access template dir from web 47c4766956SAndreas Gohr * 48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 49c4766956SAndreas Gohr * 50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 52ac7a515fSAndreas Gohr * @return string 53c4766956SAndreas Gohr */ 5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') { 5575b14482SAndreas Gohr global $conf; 56afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 57dcd4911eSMichael Hamann return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 58c4766956SAndreas Gohr} 59c4766956SAndreas Gohr 605a892029SAndreas Gohr/** 616b13307fSandi * Print the content 626b13307fSandi * 636b13307fSandi * This function is used for printing all the usual content 646b13307fSandi * (defined by the global $ACT var) by calling the appropriate 656b13307fSandi * outputfunction(s) from html.php 666b13307fSandi * 67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 696b13307fSandi * 706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 71ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 72ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 73ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 74ac7a515fSAndreas Gohr * @return bool true if any output 756b13307fSandi */ 76b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 777ea0913cSchris global $ACT; 78b8595a66SAndreas Gohr global $INFO; 79b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 807ea0913cSchris 817ea0913cSchris ob_start(); 82746855cfSBen Coburn trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 837ea0913cSchris $html_output = ob_get_clean(); 84746855cfSBen Coburn trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8554e95700STom N Harris 8654e95700STom N Harris return !empty($html_output); 877ea0913cSchris} 887ea0913cSchris 89ac7a515fSAndreas Gohr/** 90ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 91ac7a515fSAndreas Gohr * 92ac7a515fSAndreas Gohr * @return bool 93ac7a515fSAndreas Gohr */ 947ea0913cSchrisfunction tpl_content_core() { 956b13307fSandi global $ACT; 966b13307fSandi global $TEXT; 976b13307fSandi global $PRE; 986b13307fSandi global $SUF; 996b13307fSandi global $SUM; 1006b13307fSandi global $IDX; 101ac7a515fSAndreas Gohr global $INPUT; 1026b13307fSandi 1036b13307fSandi switch($ACT) { 1046b13307fSandi case 'show': 1056b13307fSandi html_show(); 1066b13307fSandi break; 107ac7a515fSAndreas Gohr /** @noinspection PhpMissingBreakStatementInspection */ 10845a99335SAdrian Lang case 'locked': 10945a99335SAdrian Lang html_locked(); 1106b13307fSandi case 'edit': 11145a99335SAdrian Lang case 'recover': 1126b13307fSandi html_edit(); 1136b13307fSandi break; 11445a99335SAdrian Lang case 'preview': 11545a99335SAdrian Lang html_edit(); 11645a99335SAdrian Lang html_show($TEXT); 11745a99335SAdrian Lang break; 118ee4c4a1bSAndreas Gohr case 'draft': 119ee4c4a1bSAndreas Gohr html_draft(); 120ee4c4a1bSAndreas Gohr break; 1216b13307fSandi case 'search': 1226b13307fSandi html_search(); 1236b13307fSandi break; 1246b13307fSandi case 'revisions': 125ac7a515fSAndreas Gohr html_revisions($INPUT->int('first')); 1266b13307fSandi break; 1276b13307fSandi case 'diff': 1286b13307fSandi html_diff(); 1296b13307fSandi break; 1306b13307fSandi case 'recent': 1313c94d07bSAnika Henke $show_changes = $INPUT->str('show_changes'); 1323c94d07bSAnika Henke if (empty($show_changes)) { 1333c94d07bSAnika Henke $show_changes = get_doku_pref('show_changes', $show_changes); 1343c94d07bSAnika Henke } 1353c94d07bSAnika Henke html_recent($INPUT->extract('first')->int('first'), $show_changes); 1366b13307fSandi break; 1376b13307fSandi case 'index': 1386b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 1396b13307fSandi break; 1406b13307fSandi case 'backlink': 1416b13307fSandi html_backlinks(); 1426b13307fSandi break; 1436b13307fSandi case 'conflict': 1446b13307fSandi html_conflict(con($PRE, $TEXT, $SUF), $SUM); 1456b13307fSandi html_diff(con($PRE, $TEXT, $SUF), false); 1466b13307fSandi break; 1476b13307fSandi case 'login': 1486b13307fSandi html_login(); 1496b13307fSandi break; 1506b13307fSandi case 'register': 1516b13307fSandi html_register(); 1526b13307fSandi break; 1538b06d178Schris case 'resendpwd': 1548b06d178Schris html_resendpwd(); 1558b06d178Schris break; 156820fa24bSandi case 'denied': 1572f2c518cSGerrit Uitslag html_denied(); 158820fa24bSandi break; 1598b06d178Schris case 'profile' : 1608b06d178Schris html_updateprofile(); 1618b06d178Schris break; 162c19fe9c0Sandi case 'admin': 163c19fe9c0Sandi tpl_admin(); 164c19fe9c0Sandi break; 1655b75cd1fSAdrian Lang case 'subscribe': 1665b75cd1fSAdrian Lang tpl_subscribe(); 1675b75cd1fSAdrian Lang break; 168d9162c6cSKate Arzamastseva case 'media': 169d9162c6cSKate Arzamastseva tpl_media(); 170d9162c6cSKate Arzamastseva break; 1716b13307fSandi default: 17224bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); 173*a85f63deSGerrit Uitslag if($evt->advise_before()) { 174ea67f144Sandi msg("Failed to handle command: ".hsc($ACT), -1); 175*a85f63deSGerrit Uitslag } 17624bb549bSchris $evt->advise_after(); 17724bb549bSchris unset($evt); 17854e95700STom N Harris return false; 1796b13307fSandi } 18054e95700STom N Harris return true; 1816b13307fSandi} 1826b13307fSandi 183c19fe9c0Sandi/** 184b8595a66SAndreas Gohr * Places the TOC where the function is called 185b8595a66SAndreas Gohr * 186b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 187b8595a66SAndreas Gohr * a false argument 188b8595a66SAndreas Gohr * 189b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 190ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 191ac7a515fSAndreas Gohr * @return string 192b8595a66SAndreas Gohr */ 193b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 194b8595a66SAndreas Gohr global $TOC; 195b8595a66SAndreas Gohr global $ACT; 196b8595a66SAndreas Gohr global $ID; 197b8595a66SAndreas Gohr global $REV; 198b8595a66SAndreas Gohr global $INFO; 199851f2e89SAnika Henke global $conf; 200ac7a515fSAndreas Gohr global $INPUT; 201b8595a66SAndreas Gohr $toc = array(); 202b8595a66SAndreas Gohr 203b8595a66SAndreas Gohr if(is_array($TOC)) { 204b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 205b8595a66SAndreas Gohr $toc = $TOC; 2063c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 207b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 20865aa8490SMichael Hamann $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE); 209b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 210b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 211b8595a66SAndreas Gohr } else { 2122bb0d541Schris $tocok = true; 213b8595a66SAndreas Gohr } 214f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 215851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 216b8595a66SAndreas Gohr $toc = array(); 217b8595a66SAndreas Gohr } 218b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 219b8595a66SAndreas Gohr // try to load admin plugin TOC FIXME: duplicates code from tpl_admin 220b8595a66SAndreas Gohr $plugin = null; 221ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 222ac7a515fSAndreas Gohr if(!empty($class)) { 223b8595a66SAndreas Gohr $pluginlist = plugin_list('admin'); 224ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 225b8595a66SAndreas Gohr // attempt to load the plugin 226ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 227a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 228b8595a66SAndreas Gohr } 229b8595a66SAndreas Gohr } 230ac7a515fSAndreas Gohr if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { 231b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 232b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 233b8595a66SAndreas Gohr } 234b8595a66SAndreas Gohr } 235b8595a66SAndreas Gohr 2360b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 237b8595a66SAndreas Gohr $html = html_TOC($toc); 238b8595a66SAndreas Gohr if($return) return $html; 239b8595a66SAndreas Gohr echo $html; 240ac7a515fSAndreas Gohr return ''; 241b8595a66SAndreas Gohr} 242b8595a66SAndreas Gohr 243b8595a66SAndreas Gohr/** 244c19fe9c0Sandi * Handle the admin page contents 245c19fe9c0Sandi * 246c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 247c19fe9c0Sandi */ 248c19fe9c0Sandifunction tpl_admin() { 249f8cc712eSAndreas Gohr global $INFO; 250b8595a66SAndreas Gohr global $TOC; 251ac7a515fSAndreas Gohr global $INPUT; 25211e2ce22Schris 253b8595a66SAndreas Gohr $plugin = null; 254ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 255ac7a515fSAndreas Gohr if(!empty($class)) { 25611e2ce22Schris $pluginlist = plugin_list('admin'); 25711e2ce22Schris 258ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 25911e2ce22Schris // attempt to load the plugin 260ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 261a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 26211e2ce22Schris } 26311e2ce22Schris } 26411e2ce22Schris 265b8595a66SAndreas Gohr if($plugin !== null) { 266b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 267b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 268f8cc712eSAndreas Gohr $plugin->html(); 269f8cc712eSAndreas Gohr } else { 270f8cc712eSAndreas Gohr html_admin(); 271f8cc712eSAndreas Gohr } 27254e95700STom N Harris return true; 273c19fe9c0Sandi} 2746b13307fSandi 2756b13307fSandi/** 2766b13307fSandi * Print the correct HTML meta headers 2776b13307fSandi * 2786b13307fSandi * This has to go into the head section of your template. 2796b13307fSandi * 2806b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 281ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 282ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 283ac7a515fSAndreas Gohr * @return bool 2846b13307fSandi */ 285f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2866b13307fSandi global $ID; 287d98d4540SBen Coburn global $REV; 2886b13307fSandi global $INFO; 28972e0dc37SAndreas Gohr global $JSINFO; 2906b13307fSandi global $ACT; 2914bb1b5aeSAndreas Gohr global $QUERY; 2926b13307fSandi global $lang; 293dc57ef04Sandi global $conf; 2949c438d6cSMichael Hamann global $updateVersion; 295585bf44eSChristopher Smith /** @var Input $INPUT */ 296585bf44eSChristopher Smith global $INPUT; 2976b13307fSandi 2987bff22c0SAndreas Gohr // prepare the head array 2997bff22c0SAndreas Gohr $head = array(); 3007bff22c0SAndreas Gohr 301202ac28bSMichael Klier // prepare seed for js and css 302cd997f93SAndreas Gohr $tseed = $updateVersion; 303202ac28bSMichael Klier $depends = getConfigFiles('main'); 304cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 305cd997f93SAndreas Gohr $tseed = md5($tseed); 3067bff22c0SAndreas Gohr 3076b13307fSandi // the usual stuff 3083f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 309ac7a515fSAndreas Gohr $head['link'][] = array( 310ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 311ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 312ac7a515fSAndreas Gohr ); 313f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 3147aedde2eSGina Haeussge if(actionOK('index')) { 315ac7a515fSAndreas Gohr $head['link'][] = array( 316ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 317ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 318ac7a515fSAndreas Gohr ); 3197aedde2eSGina Haeussge } 320f96fa415SAndreas Gohr 321f96fa415SAndreas Gohr if($alt) { 32254be1338SGerrit Uitslag if(actionOK('rss')) { 323ac7a515fSAndreas Gohr $head['link'][] = array( 324ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 325a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 326ac7a515fSAndreas Gohr ); 327ac7a515fSAndreas Gohr $head['link'][] = array( 328ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 329a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 330ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 331ac7a515fSAndreas Gohr ); 33254be1338SGerrit Uitslag } 333c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 334ac7a515fSAndreas Gohr $head['link'][] = array( 335ac7a515fSAndreas Gohr 'rel' => 'edit', 336715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 337ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 338ac7a515fSAndreas Gohr ); 339c35f3875SAndreas Gohr } 340c35f3875SAndreas Gohr 34154be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 342ac7a515fSAndreas Gohr $head['link'][] = array( 343ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 344a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 345ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 346ac7a515fSAndreas Gohr ); 3474bb1b5aeSAndreas Gohr } 348bae36d94SAndreas Gohr 349bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 350ac7a515fSAndreas Gohr $head['link'][] = array( 351a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 352ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 353ac7a515fSAndreas Gohr ); 354bae36d94SAndreas Gohr } 355bae36d94SAndreas Gohr 356bae36d94SAndreas Gohr if(actionOK('export_raw')) { 357ac7a515fSAndreas Gohr $head['link'][] = array( 358a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 359ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 360ac7a515fSAndreas Gohr ); 361f96fa415SAndreas Gohr } 362bae36d94SAndreas Gohr } 3636b13307fSandi 3646b13307fSandi // setup robot tags apropriate for different modes 3654f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3666b13307fSandi if($INFO['exists']) { 3676b13307fSandi //delay indexing: 3686b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 3697bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3706b13307fSandi } else { 3717bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3726b13307fSandi } 37301f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 37401f9be51SAnika Henke if ($ID == $conf['start']) { 37501f9be51SAnika Henke $canonicalUrl = DOKU_URL; 37601f9be51SAnika Henke } 37701f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3786b13307fSandi } else { 3797bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3806b13307fSandi } 3817a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3827bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3836b13307fSandi } else { 3847bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3856b13307fSandi } 3866b13307fSandi 387831800b8SAndreas Gohr // set metadata 388831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 389831800b8SAndreas Gohr // keywords (explicit or implicit) 390bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3917bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 392831800b8SAndreas Gohr } else { 3937bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 394831800b8SAndreas Gohr } 395831800b8SAndreas Gohr } 396831800b8SAndreas Gohr 39778a6aeb1SAndreas Gohr // load stylesheets 398ac7a515fSAndreas Gohr $head['link'][] = array( 399ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 400ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed 401ac7a515fSAndreas Gohr ); 402bad31ae9SAndreas Gohr 4038bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 404463d4a65SAndreas Gohr $json = new JSON(); 40572e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 406585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 40772e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 408c591aabeSAndreas Gohr } 40972e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 41085f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 4118bbcb611SAndreas Gohr 4128bbcb611SAndreas Gohr // load external javascript 413ac7a515fSAndreas Gohr $head['script'][] = array( 414ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 415ac7a515fSAndreas Gohr 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed 416ac7a515fSAndreas Gohr ); 4177bff22c0SAndreas Gohr 4187bff22c0SAndreas Gohr // trigger event here 419016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 42054e95700STom N Harris return true; 4217bff22c0SAndreas Gohr} 4227bff22c0SAndreas Gohr 4237bff22c0SAndreas Gohr/** 4247bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4257bff22c0SAndreas Gohr * 4267bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4277bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4287bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4297bff22c0SAndreas Gohr * 4307bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special 4311304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4327bff22c0SAndreas Gohr * 4337bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4347bff22c0SAndreas Gohr */ 4357bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4367bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 4377bff22c0SAndreas Gohr foreach($inst as $attr) { 4387bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 43926afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 440e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 44109f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 442e226efe1SAndreas Gohr $attr['_data']. 44309f791c4SDominik Eckelmann "\n/*!]]>*/"; 444e226efe1SAndreas Gohr 4451304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4467bff22c0SAndreas Gohr } else { 4477bff22c0SAndreas Gohr echo '/>'; 4487bff22c0SAndreas Gohr } 4497bff22c0SAndreas Gohr echo "\n"; 4507bff22c0SAndreas Gohr } 4517bff22c0SAndreas Gohr } 4526b13307fSandi} 4536b13307fSandi 4546b13307fSandi/** 4556b13307fSandi * Print a link 4566b13307fSandi * 4575e163278SAndreas Gohr * Just builds a link. 4586b13307fSandi * 4596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 46021d806cdSGerrit Uitslag * 46121d806cdSGerrit Uitslag * @param string $url 46221d806cdSGerrit Uitslag * @param string $name 46321d806cdSGerrit Uitslag * @param string $more 46421d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 46521d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4666b13307fSandi */ 4671af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 46801f17825SAnika Henke $out = '<a href="'.$url.'" '; 4691af98a77SAnika Henke if($more) $out .= ' '.$more; 4701af98a77SAnika Henke $out .= ">$name</a>"; 4711af98a77SAnika Henke if($return) return $out; 4721af98a77SAnika Henke print $out; 47354e95700STom N Harris return true; 4746b13307fSandi} 4756b13307fSandi 4766b13307fSandi/** 47755efc227SAndreas Gohr * Prints a link to a WikiPage 47855efc227SAndreas Gohr * 47955efc227SAndreas Gohr * Wrapper around html_wikilink 48055efc227SAndreas Gohr * 48155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 48221d806cdSGerrit Uitslag * 48321d806cdSGerrit Uitslag * @param string $id page id 48421d806cdSGerrit Uitslag * @param string|null $name link name 48521d806cdSGerrit Uitslag * @return bool true 48655efc227SAndreas Gohr */ 4870b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 488d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 48954e95700STom N Harris return true; 49055efc227SAndreas Gohr} 49155efc227SAndreas Gohr 49255efc227SAndreas Gohr/** 493a3ec5f4aSmatthiasgrimm * get the parent page 494a3ec5f4aSmatthiasgrimm * 495a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 496a3ec5f4aSmatthiasgrimm * returns false if none is available 497a3ec5f4aSmatthiasgrimm * 498377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 499a3ec5f4aSmatthiasgrimm */ 500377f9e97SAndreas Gohrfunction tpl_getparent($id) { 501377f9e97SAndreas Gohr $parent = getNS($id).':'; 502377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 503a197105eSmatthiasgrimm if($parent == $id) { 504a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 505a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 506a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 507377f9e97SAndreas Gohr if($parent == $id) return false; 508a197105eSmatthiasgrimm } 509377f9e97SAndreas Gohr return $parent; 510a3ec5f4aSmatthiasgrimm} 511a3ec5f4aSmatthiasgrimm 512a3ec5f4aSmatthiasgrimm/** 5136b13307fSandi * Print one of the buttons 5146b13307fSandi * 515a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 516a453d131SAdrian Lang * @see tpl_get_action 5176b13307fSandi */ 5181af98a77SAnika Henkefunction tpl_button($type, $return = false) { 519a453d131SAdrian Lang $data = tpl_get_action($type); 520a453d131SAdrian Lang if($data === false) { 521a453d131SAdrian Lang return false; 522a453d131SAdrian Lang } elseif(!is_array($data)) { 523a453d131SAdrian Lang $out = sprintf($data, 'button'); 524409d7af7SAndreas Gohr } else { 525ac7a515fSAndreas Gohr /** 526ac7a515fSAndreas Gohr * @var string $accesskey 527ac7a515fSAndreas Gohr * @var string $id 528ac7a515fSAndreas Gohr * @var string $method 529ac7a515fSAndreas Gohr * @var array $params 530ac7a515fSAndreas Gohr */ 531a453d131SAdrian Lang extract($data); 532a453d131SAdrian Lang if($id === '#dokuwiki__top') { 533a453d131SAdrian Lang $out = html_topbtn(); 534409d7af7SAndreas Gohr } else { 535a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 536409d7af7SAndreas Gohr } 537409d7af7SAndreas Gohr } 5381af98a77SAnika Henke if($return) return $out; 539a453d131SAdrian Lang echo $out; 540a453d131SAdrian Lang return true; 5416b13307fSandi} 5426b13307fSandi 5436b13307fSandi/** 544ed630903Sandi * Like the action buttons but links 545ed630903Sandi * 546a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 547a453d131SAdrian Lang * @see tpl_get_action 54821d806cdSGerrit Uitslag * 54921d806cdSGerrit Uitslag * @param string $type action name 55021d806cdSGerrit Uitslag * @param string $pre prefix of link 55121d806cdSGerrit Uitslag * @param string $suf suffix of link 55221d806cdSGerrit Uitslag * @param string $inner inner HTML for link 55321d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 55421d806cdSGerrit Uitslag * @return bool|string html of action link or false if nothing, or true if printed 555a453d131SAdrian Lang */ 556a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 557a453d131SAdrian Lang global $lang; 558a453d131SAdrian Lang $data = tpl_get_action($type); 559a453d131SAdrian Lang if($data === false) { 560a453d131SAdrian Lang return false; 561a453d131SAdrian Lang } elseif(!is_array($data)) { 562a453d131SAdrian Lang $out = sprintf($data, 'link'); 563a453d131SAdrian Lang } else { 564ac7a515fSAndreas Gohr /** 565ac7a515fSAndreas Gohr * @var string $accesskey 566ac7a515fSAndreas Gohr * @var string $id 567ac7a515fSAndreas Gohr * @var string $method 568b1af9014SChristopher Smith * @var bool $nofollow 569ac7a515fSAndreas Gohr * @var array $params 570becfa414SGerrit Uitslag * @var string $replacement 571ac7a515fSAndreas Gohr */ 572a453d131SAdrian Lang extract($data); 573a453d131SAdrian Lang if(strpos($id, '#') === 0) { 574a453d131SAdrian Lang $linktarget = $id; 575a453d131SAdrian Lang } else { 576a453d131SAdrian Lang $linktarget = wl($id, $params); 577a453d131SAdrian Lang } 578a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 579becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 580becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 581becfa414SGerrit Uitslag } 582c7e90e3fSAnika Henke $akey = $addTitle = ''; 583c7e90e3fSAnika Henke if($accesskey) { 584c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 585c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 586c7e90e3fSAnika Henke } 587b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 588ac7a515fSAndreas Gohr $out = tpl_link( 589ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 590a453d131SAdrian Lang 'class="action '.$type.'" '. 591b1af9014SChristopher Smith $akey.$rel. 59221d806cdSGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 593ac7a515fSAndreas Gohr ); 594a453d131SAdrian Lang } 595a453d131SAdrian Lang if($return) return $out; 596a453d131SAdrian Lang echo $out; 597a453d131SAdrian Lang return true; 598a453d131SAdrian Lang} 599a453d131SAdrian Lang 600a453d131SAdrian Lang/** 601a453d131SAdrian Lang * Check the actions and get data for buttons and links 602ed630903Sandi * 603a453d131SAdrian Lang * Available actions are 604a453d131SAdrian Lang * 605a453d131SAdrian Lang * edit - edit/create/show/draft 606ed630903Sandi * history - old revisions 607ed630903Sandi * recent - recent changes 608a453d131SAdrian Lang * login - login/logout - if ACL enabled 609a453d131SAdrian Lang * profile - user profile (if logged in) 610ed630903Sandi * index - The index 611ed630903Sandi * admin - admin page - if enough rights 612a453d131SAdrian Lang * top - back to top 613a453d131SAdrian Lang * back - back to parent - if available 614bbd37938SAndreas Gohr * backlink - links to the list of backlinks 615a453d131SAdrian Lang * subscribe/subscription- subscribe/unsubscribe 616ed630903Sandi * 617ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 618a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 619a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 620ac7a515fSAndreas Gohr * @param string $type 621ac7a515fSAndreas Gohr * @return array|bool|string 622ed630903Sandi */ 623a453d131SAdrian Langfunction tpl_get_action($type) { 624ed630903Sandi global $ID; 625ed630903Sandi global $INFO; 626ed630903Sandi global $REV; 627ed630903Sandi global $ACT; 628b1af9014SChristopher Smith global $conf; 629585bf44eSChristopher Smith /** @var Input $INPUT */ 630585bf44eSChristopher Smith global $INPUT; 631ed630903Sandi 63275e487e9SAndreas Gohr // check disabled actions and fix the badly named ones 633a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6344c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 635a453d131SAdrian Lang if(!actionOK($type)) return false; 636409d7af7SAndreas Gohr 637a453d131SAdrian Lang $accesskey = null; 6386709e843SAdrian Lang $id = $ID; 639a453d131SAdrian Lang $method = 'get'; 640a453d131SAdrian Lang $params = array('do' => $type); 641b1af9014SChristopher Smith $nofollow = true; 642becfa414SGerrit Uitslag $replacement = ''; 643ed630903Sandi switch($type) { 644ed630903Sandi case 'edit': 6450b17fdc6SAndreas Gohr // most complicated type - we need to decide on current action 646ed630903Sandi if($ACT == 'show' || $ACT == 'search') { 647a453d131SAdrian Lang $method = 'post'; 648ed630903Sandi if($INFO['writable']) { 649a453d131SAdrian Lang $accesskey = 'e'; 650b8a111f5SMichael Klier if(!empty($INFO['draft'])) { 6516709e843SAdrian Lang $type = 'draft'; 652a453d131SAdrian Lang $params['do'] = 'draft'; 653b8a111f5SMichael Klier } else { 654a453d131SAdrian Lang $params['rev'] = $REV; 655a453d131SAdrian Lang if(!$INFO['exists']) { 6566709e843SAdrian Lang $type = 'create'; 657ed630903Sandi } 658b8a111f5SMichael Klier } 659ed630903Sandi } else { 660a453d131SAdrian Lang if(!actionOK('source')) return false; //pseudo action 661a453d131SAdrian Lang $params['rev'] = $REV; 6626709e843SAdrian Lang $type = 'source'; 663a453d131SAdrian Lang $accesskey = 'v'; 664ed630903Sandi } 665ed630903Sandi } else { 666d30d4913SChristopher Smith $params = array('do' => ''); 6676709e843SAdrian Lang $type = 'show'; 668a453d131SAdrian Lang $accesskey = 'v'; 669ed630903Sandi } 6701af98a77SAnika Henke break; 671a453d131SAdrian Lang case 'revisions': 6726709e843SAdrian Lang $type = 'revs'; 673a453d131SAdrian Lang $accesskey = 'o'; 6741af98a77SAnika Henke break; 675ed630903Sandi case 'recent': 676a453d131SAdrian Lang $accesskey = 'r'; 6771af98a77SAnika Henke break; 678ed630903Sandi case 'index': 679a453d131SAdrian Lang $accesskey = 'x'; 680b1af9014SChristopher Smith // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 681b1af9014SChristopher Smith if ($conf['start'] == $ID && !$conf['sitemap']) { 682b1af9014SChristopher Smith $nofollow = false; 683b1af9014SChristopher Smith } 6841af98a77SAnika Henke break; 685ed630903Sandi case 'top': 686076f0d72SAnika Henke $accesskey = 't'; 687d30d4913SChristopher Smith $params = array('do' => ''); 688a453d131SAdrian Lang $id = '#dokuwiki__top'; 6891af98a77SAnika Henke break; 690a3ec5f4aSmatthiasgrimm case 'back': 691a453d131SAdrian Lang $parent = tpl_getparent($ID); 692a453d131SAdrian Lang if(!$parent) { 693a453d131SAdrian Lang return false; 694a3ec5f4aSmatthiasgrimm } 695a453d131SAdrian Lang $id = $parent; 696d30d4913SChristopher Smith $params = array('do' => ''); 697a453d131SAdrian Lang $accesskey = 'b'; 6981af98a77SAnika Henke break; 699becfa414SGerrit Uitslag case 'img_backto': 700a3ec5f4aSmatthiasgrimm $params = array(); 701a3ec5f4aSmatthiasgrimm $accesskey = 'b'; 702becfa414SGerrit Uitslag $replacement = $ID; 703c059e1a6SAndreas Gohr break; 704ed630903Sandi case 'login': 705a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 706585bf44eSChristopher Smith if($INPUT->server->has('REMOTE_USER')) { 7073a48618aSAnika Henke if(!actionOK('logout')) { 7082380e8a8SAdrian Lang return false; 7092380e8a8SAdrian Lang } 710a453d131SAdrian Lang $params['do'] = 'logout'; 711a453d131SAdrian Lang $type = 'logout'; 712bf413a4eSAnika Henke } 713bf413a4eSAnika Henke break; 714bf413a4eSAnika Henke case 'register': 715585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 716bf413a4eSAnika Henke return false; 717bf413a4eSAnika Henke } 718bf413a4eSAnika Henke break; 719bf413a4eSAnika Henke case 'resendpwd': 720585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 721bf413a4eSAnika Henke return false; 722ed630903Sandi } 7231af98a77SAnika Henke break; 724ed630903Sandi case 'admin': 725a453d131SAdrian Lang if(!$INFO['ismanager']) { 726a453d131SAdrian Lang return false; 727c059e1a6SAndreas Gohr } 7281af98a77SAnika Henke break; 7291246e016SAndreas Gohr case 'revert': 730a453d131SAdrian Lang if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 731a453d131SAdrian Lang return false; 7321246e016SAndreas Gohr } 733a453d131SAdrian Lang $params['rev'] = $REV; 734a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 7351246e016SAndreas Gohr break; 7366709e843SAdrian Lang case 'subscribe': 737585bf44eSChristopher Smith if(!$INPUT->server->str('REMOTE_USER')) { 738a453d131SAdrian Lang return false; 739b158d625SSteven Danz } 7401af98a77SAnika Henke break; 741f00151b4Schris case 'backlink': 7421af98a77SAnika Henke break; 7438b06d178Schris case 'profile': 744585bf44eSChristopher Smith if(!$INPUT->server->has('REMOTE_USER')) { 745a453d131SAdrian Lang return false; 7468b06d178Schris } 7471af98a77SAnika Henke break; 748b9eb2e61SKate Arzamastseva case 'media': 749d08527abSAnika Henke $params['ns'] = getNS($ID); 750b9eb2e61SKate Arzamastseva break; 751becfa414SGerrit Uitslag case 'mediaManager': 752becfa414SGerrit Uitslag // View image in media manager 753becfa414SGerrit Uitslag global $IMG; 754becfa414SGerrit Uitslag $imgNS = getNS($IMG); 755becfa414SGerrit Uitslag $authNS = auth_quickaclcheck("$imgNS:*"); 756becfa414SGerrit Uitslag if ($authNS < AUTH_UPLOAD) { 757becfa414SGerrit Uitslag return false; 758becfa414SGerrit Uitslag } 759becfa414SGerrit Uitslag $params = array( 760becfa414SGerrit Uitslag 'ns' => $imgNS, 761becfa414SGerrit Uitslag 'image' => $IMG, 762becfa414SGerrit Uitslag 'do' => 'media' 763becfa414SGerrit Uitslag ); 764becfa414SGerrit Uitslag //$type = 'media'; 765becfa414SGerrit Uitslag break; 766ed630903Sandi default: 767a453d131SAdrian Lang return '[unknown %s type]'; 768ed630903Sandi } 769becfa414SGerrit Uitslag return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); 770ed630903Sandi} 771ed630903Sandi 772ed630903Sandi/** 77301f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 77401f17825SAnika Henke * 77501f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 776ac7a515fSAndreas Gohr * @param 777ac7a515fSAndreas Gohr * @param bool $link link or form button? 778ac7a515fSAndreas Gohr * @param bool $wrapper HTML element wrapper 779ac7a515fSAndreas Gohr * @param bool $return return or print 780ac7a515fSAndreas Gohr * @param string $pre prefix for links 781ac7a515fSAndreas Gohr * @param string $suf suffix for links 782ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 783ac7a515fSAndreas Gohr * @return bool|string 78401f17825SAnika Henke */ 785ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 78601f17825SAnika Henke $out = ''; 787ac7a515fSAndreas Gohr if($link) { 78821d806cdSGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 789ac7a515fSAndreas Gohr } else { 79021d806cdSGerrit Uitslag $out .= tpl_button($type, true); 791ac7a515fSAndreas Gohr } 79201f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 79301f17825SAnika Henke 79401f17825SAnika Henke if($return) return $out; 79501f17825SAnika Henke print $out; 79601f17825SAnika Henke return $out ? true : false; 79701f17825SAnika Henke} 79801f17825SAnika Henke 79901f17825SAnika Henke/** 8006b13307fSandi * Print the search form 8016b13307fSandi * 80272645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 80372645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 80472645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 80572645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 80672645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 80772645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 80872645b75SAndreas Gohr * 8096b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 810ac7a515fSAndreas Gohr * @param bool $ajax 811ac7a515fSAndreas Gohr * @param bool $autocomplete 812ac7a515fSAndreas Gohr * @return bool 8136b13307fSandi */ 81472645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 8156b13307fSandi global $lang; 816c1e3b7d9Smatthiasgrimm global $ACT; 817ad4aaef7SAndreas Gohr global $QUERY; 818c1e3b7d9Smatthiasgrimm 819670ff54eSchris // don't print the search form if search action has been disabled 82064276bbcSarbrk1 if(!actionOK('search')) return false; 821670ff54eSchris 8229805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 8236b13307fSandi print '<input type="hidden" name="do" value="search" />'; 824c1e3b7d9Smatthiasgrimm print '<input type="text" '; 825ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 82672645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 82707493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 82811ea018fSAndreas Gohr print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 82924a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 8304beabca9SAnika Henke print '</div></form>'; 83154e95700STom N Harris return true; 8326b13307fSandi} 8336b13307fSandi 8346b13307fSandi/** 8356b13307fSandi * Print the breadcrumbs trace 8366b13307fSandi * 8376b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 838ac7a515fSAndreas Gohr * @param string $sep Separator between entries 839ac7a515fSAndreas Gohr * @return bool 8406b13307fSandi */ 841e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 8426b13307fSandi global $lang; 8436b13307fSandi global $conf; 8446b13307fSandi 8456b13307fSandi //check if enabled 846359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 8476b13307fSandi 8486b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 849265e3787Sandi 8502979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 851265e3787Sandi 85240eb54bbSjan //render crumbs, highlight the last one 853fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 85440eb54bbSjan $last = count($crumbs); 85540eb54bbSjan $i = 0; 856a77f5846Sjan foreach($crumbs as $id => $name) { 85740eb54bbSjan $i++; 8582979a10bSKatriel Traum echo $crumbs_sep; 85992795d04Sandi if($i == $last) print '<span class="curid">'; 860d317fb5dSAnika Henke print '<bdi>'; 861e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 862d317fb5dSAnika Henke print '</bdi>'; 86392795d04Sandi if($i == $last) print '</span>'; 8646b13307fSandi } 86554e95700STom N Harris return true; 8666b13307fSandi} 8676b13307fSandi 8686b13307fSandi/** 8691734437eSandi * Hierarchical breadcrumbs 8701734437eSandi * 87131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8721734437eSandi * It only makes sense with a deep site structure. 8731734437eSandi * 8741734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 8756bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 87631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 877f46c9e83SAnika Henke * @author <fredrik@averpil.com> 8786bd812dfSNigel McNie * @todo May behave strangely in RTL languages 879ac7a515fSAndreas Gohr * @param string $sep Separator between entries 880ac7a515fSAndreas Gohr * @return bool 8811734437eSandi */ 882e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') { 8831734437eSandi global $conf; 8841734437eSandi global $ID; 8851734437eSandi global $lang; 8861734437eSandi 88731e187f8SSean Coates // check if enabled 88854e95700STom N Harris if(!$conf['youarehere']) return false; 8891734437eSandi 8901734437eSandi $parts = explode(':', $ID); 891796bafb3SAndreas Gohr $count = count($parts); 8921734437eSandi 893fde860beSGerrit Uitslag echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 8941734437eSandi 8951734437eSandi // always print the startpage 896fca4df27SAnika Henke echo '<span class="home">'; 897e013f48dSAnika Henke tpl_pagelink(':'.$conf['start']); 898fca4df27SAnika Henke echo '</span>'; 899796bafb3SAndreas Gohr 900796bafb3SAndreas Gohr // print intermediate namespace links 901796bafb3SAndreas Gohr $part = ''; 902796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 903796bafb3SAndreas Gohr $part .= $parts[$i].':'; 904796bafb3SAndreas Gohr $page = $part; 905796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 906796bafb3SAndreas Gohr 907796bafb3SAndreas Gohr // output 908796bafb3SAndreas Gohr echo $sep; 909e013f48dSAnika Henke tpl_pagelink($page); 91031e187f8SSean Coates } 9111734437eSandi 912796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 913e013f48dSAnika Henke resolve_pageid('', $page, $exists); 914ac7a515fSAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 915796bafb3SAndreas Gohr $page = $part.$parts[$i]; 916ac7a515fSAndreas Gohr if($page == $conf['start']) return true; 917796bafb3SAndreas Gohr echo $sep; 918e013f48dSAnika Henke tpl_pagelink($page); 91954e95700STom N Harris return true; 9201734437eSandi} 9211734437eSandi 9221734437eSandi/** 9236b13307fSandi * Print info if the user is logged in 924a2488c3cSMatthias Grimm * and show full name in that case 9256b13307fSandi * 9266b13307fSandi * Could be enhanced with a profile link in future? 9276b13307fSandi * 9286b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 929ac7a515fSAndreas Gohr * @return bool 9306b13307fSandi */ 9316b13307fSandifunction tpl_userinfo() { 9326b13307fSandi global $lang; 933585bf44eSChristopher Smith /** @var Input $INPUT */ 934585bf44eSChristopher Smith global $INPUT; 935585bf44eSChristopher Smith 936585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 937fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 93854e95700STom N Harris return true; 93954e95700STom N Harris } 94054e95700STom N Harris return false; 9416b13307fSandi} 9426b13307fSandi 9436b13307fSandi/** 9446b13307fSandi * Print some info about the current page 9456b13307fSandi * 9466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 947ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 948ac7a515fSAndreas Gohr * @return bool|string 9496b13307fSandi */ 9504b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 9516b13307fSandi global $conf; 9526b13307fSandi global $lang; 9536b13307fSandi global $INFO; 954c6e92a3cSDavid Lorentsen global $ID; 955c6e92a3cSDavid Lorentsen 956c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 957ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 958ac7a515fSAndreas Gohr return false; 959ac7a515fSAndreas Gohr } 9606b13307fSandi 9616b13307fSandi // prepare date and path 9626b13307fSandi $fn = $INFO['filepath']; 9636b13307fSandi if(!$conf['fullpath']) { 964613bca54SAndreas Gohr if($INFO['rev']) { 96550fbebceSGina Haeussge $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 9666b13307fSandi } else { 96750fbebceSGina Haeussge $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 9686b13307fSandi } 9696b13307fSandi } 970bee6dc82Sandi $fn = utf8_decodeFN($fn); 971f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 9726b13307fSandi 973faecdfdfSAndreas Gohr // print it 974faecdfdfSAndreas Gohr if($INFO['exists']) { 9754b0d3916SAndreas Gohr $out = ''; 976d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 977e260f93bSAnika Henke $out .= ' · '; 9784b0d3916SAndreas Gohr $out .= $lang['lastmod']; 979fde860beSGerrit Uitslag $out .= ' '; 9804b0d3916SAndreas Gohr $out .= $date; 9816b13307fSandi if($INFO['editor']) { 9824b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 983d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 9845aa52fafSBen Coburn } else { 9854b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 9866b13307fSandi } 9876b13307fSandi if($INFO['locked']) { 988e260f93bSAnika Henke $out .= ' · '; 9894b0d3916SAndreas Gohr $out .= $lang['lockedby']; 990fde860beSGerrit Uitslag $out .= ' '; 991d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 9926b13307fSandi } 9934b0d3916SAndreas Gohr if($ret) { 9944b0d3916SAndreas Gohr return $out; 9954b0d3916SAndreas Gohr } else { 9964b0d3916SAndreas Gohr echo $out; 99754e95700STom N Harris return true; 9986b13307fSandi } 9994b0d3916SAndreas Gohr } 100054e95700STom N Harris return false; 10016b13307fSandi} 10026b13307fSandi 1003820fa24bSandi/** 1004a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 100587c434ceSAndreas Gohr * 100687c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 1007a6598f23SBen Coburn * the given ID is used. 100887c434ceSAndreas Gohr * 100987c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1010ac7a515fSAndreas Gohr * @param string $id page id 1011ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 1012ac7a515fSAndreas Gohr * @return bool|string 101387c434ceSAndreas Gohr */ 1014a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 101587c434ceSAndreas Gohr if(is_null($id)) { 101687c434ceSAndreas Gohr global $ID; 101787c434ceSAndreas Gohr $id = $ID; 101887c434ceSAndreas Gohr } 101987c434ceSAndreas Gohr 102087c434ceSAndreas Gohr $name = $id; 1021fe9ec250SChris Smith if(useHeading('navigation')) { 102287c434ceSAndreas Gohr $title = p_get_first_heading($id); 102387c434ceSAndreas Gohr if($title) $name = $title; 102487c434ceSAndreas Gohr } 1025a6598f23SBen Coburn 1026a6598f23SBen Coburn if($ret) { 1027a6598f23SBen Coburn return hsc($name); 1028a6598f23SBen Coburn } else { 102987c434ceSAndreas Gohr print hsc($name); 103054e95700STom N Harris return true; 103187c434ceSAndreas Gohr } 1032a6598f23SBen Coburn} 1033340756e4Sandi 103455efc227SAndreas Gohr/** 103555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 103655efc227SAndreas Gohr * 103755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 103855efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 103955efc227SAndreas Gohr * 104055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 104155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 104255efc227SAndreas Gohr * to the names of the latter one) 104355efc227SAndreas Gohr * 10443df72098SAndreas Gohr * Only allowed in: detail.php 104555efc227SAndreas Gohr * 104655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 104721d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1048ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1049ac7a515fSAndreas Gohr * @param null $src the image src, uses global $SRC if not given 1050ac7a515fSAndreas Gohr * @return string 105155efc227SAndreas Gohr */ 10523df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 105355efc227SAndreas Gohr // Init Exif Reader 105455efc227SAndreas Gohr global $SRC; 10553df72098SAndreas Gohr 10563df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10573df72098SAndreas Gohr 105855efc227SAndreas Gohr static $meta = null; 10593df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 106055efc227SAndreas Gohr if($meta === false) return $alt; 106188945224SChristopher Smith $info = cleanText($meta->getField($tags)); 106255efc227SAndreas Gohr if($info == false) return $alt; 106355efc227SAndreas Gohr return $info; 106455efc227SAndreas Gohr} 106555efc227SAndreas Gohr 106655efc227SAndreas Gohr/** 1067becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1068becfa414SGerrit Uitslag * 1069becfa414SGerrit Uitslag * @return string html of description list 1070becfa414SGerrit Uitslag */ 1071becfa414SGerrit Uitslagfunction tpl_img_meta() { 1072becfa414SGerrit Uitslag global $lang; 1073becfa414SGerrit Uitslag 1074becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1075becfa414SGerrit Uitslag 1076becfa414SGerrit Uitslag echo '<dl>'; 1077becfa414SGerrit Uitslag foreach($tags as $tag) { 1078becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1079fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1080becfa414SGerrit Uitslag 1081fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1082becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1083becfa414SGerrit Uitslag echo dformat($tag['value']); 1084becfa414SGerrit Uitslag } else { 1085becfa414SGerrit Uitslag echo hsc($tag['value']); 1086becfa414SGerrit Uitslag } 1087becfa414SGerrit Uitslag echo '</dd>'; 1088becfa414SGerrit Uitslag } 1089becfa414SGerrit Uitslag echo '</dl>'; 1090becfa414SGerrit Uitslag} 1091becfa414SGerrit Uitslag 1092becfa414SGerrit Uitslag/** 1093becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1094becfa414SGerrit Uitslag * 1095becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1096becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1097becfa414SGerrit Uitslag * - string type type of value 1098becfa414SGerrit Uitslag * - string value tag value (unescaped) 1099becfa414SGerrit Uitslag */ 1100becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1101becfa414SGerrit Uitslag 1102becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1103becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 1104becfa414SGerrit Uitslag if(@file_exists($config_file)) { 1105becfa414SGerrit Uitslag include($config_file); 1106becfa414SGerrit Uitslag } 1107becfa414SGerrit Uitslag } 1108becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1109becfa414SGerrit Uitslag 1110becfa414SGerrit Uitslag $tags = array(); 1111becfa414SGerrit Uitslag foreach($fields as $tag){ 1112becfa414SGerrit Uitslag $t = array(); 1113becfa414SGerrit Uitslag if (!empty($tag[0])) { 1114becfa414SGerrit Uitslag $t = array($tag[0]); 1115becfa414SGerrit Uitslag } 1116becfa414SGerrit Uitslag if(is_array($tag[3])) { 1117becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1118becfa414SGerrit Uitslag } 1119becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1120becfa414SGerrit Uitslag if ($value) { 1121becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1122becfa414SGerrit Uitslag } 1123becfa414SGerrit Uitslag } 1124becfa414SGerrit Uitslag return $tags; 1125becfa414SGerrit Uitslag} 1126becfa414SGerrit Uitslag 1127becfa414SGerrit Uitslag/** 112855efc227SAndreas Gohr * Prints the image with a link to the full sized version 112955efc227SAndreas Gohr * 113055efc227SAndreas Gohr * Only allowed in: detail.php 1131a02d2933SAndreas Gohr * 1132ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1133a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1134a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1135a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1136a02d2933SAndreas Gohr * @param $params array - additional image attributes 1137ac7a515fSAndreas Gohr * @return mixed Result of TPL_IMG_DISPLAY 113855efc227SAndreas Gohr */ 1139a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 114055efc227SAndreas Gohr global $IMG; 1141585bf44eSChristopher Smith /** @var Input $INPUT */ 1142ac7a515fSAndreas Gohr global $INPUT; 11435c2eed9aSlisps global $REV; 114455efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 114555efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 114655efc227SAndreas Gohr 114755efc227SAndreas Gohr //resize to given max values 114823a34783SAndreas Gohr $ratio = 1; 114923a34783SAndreas Gohr if($w >= $h) { 1150f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 115155efc227SAndreas Gohr $ratio = $maxwidth / $w; 1152f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 115355efc227SAndreas Gohr $ratio = $maxheight / $h; 115455efc227SAndreas Gohr } 115555efc227SAndreas Gohr } else { 1156f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 115755efc227SAndreas Gohr $ratio = $maxheight / $h; 1158f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 115955efc227SAndreas Gohr $ratio = $maxwidth / $w; 116055efc227SAndreas Gohr } 116155efc227SAndreas Gohr } 116255efc227SAndreas Gohr if($ratio) { 116355efc227SAndreas Gohr $w = floor($ratio * $w); 116455efc227SAndreas Gohr $h = floor($ratio * $h); 116555efc227SAndreas Gohr } 116655efc227SAndreas Gohr 11676de3759aSAndreas Gohr //prepare URLs 11685c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 11695c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 117055efc227SAndreas Gohr 11712684e50aSAndreas Gohr //prepare attributes 117255efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1173a02d2933SAndreas Gohr if(is_null($params)) { 11742684e50aSAndreas Gohr $p = array(); 1175a02d2933SAndreas Gohr } else { 1176a02d2933SAndreas Gohr $p = $params; 1177a02d2933SAndreas Gohr } 11782684e50aSAndreas Gohr if($w) $p['width'] = $w; 11792684e50aSAndreas Gohr if($h) $p['height'] = $h; 11802684e50aSAndreas Gohr $p['class'] = 'img_detail'; 11812684e50aSAndreas Gohr if($alt) { 11822684e50aSAndreas Gohr $p['alt'] = $alt; 11832684e50aSAndreas Gohr $p['title'] = $alt; 11842684e50aSAndreas Gohr } else { 11852684e50aSAndreas Gohr $p['alt'] = ''; 11862684e50aSAndreas Gohr } 1187a02d2933SAndreas Gohr $p['src'] = $src; 118855efc227SAndreas Gohr 1189a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1190a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1191a02d2933SAndreas Gohr} 1192a02d2933SAndreas Gohr 1193a02d2933SAndreas Gohr/** 1194a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1195ac7a515fSAndreas Gohr * 1196ac7a515fSAndreas Gohr * @param array $data 1197ac7a515fSAndreas Gohr * @return bool 1198a02d2933SAndreas Gohr */ 1199ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 120059f3611bSAnika Henke global $lang; 1201a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1202a02d2933SAndreas Gohr 120359f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1204a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1205a02d2933SAndreas Gohr if($data['url']) print '</a>'; 120654e95700STom N Harris return true; 120755efc227SAndreas Gohr} 120855efc227SAndreas Gohr 12097367b368SAndreas Gohr/** 1210881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12117367b368SAndreas Gohr * 12127367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 12137367b368SAndreas Gohr * template 1214ac7a515fSAndreas Gohr * 1215ac7a515fSAndreas Gohr * @return bool 12167367b368SAndreas Gohr */ 12177367b368SAndreas Gohrfunction tpl_indexerWebBug() { 12187367b368SAndreas Gohr global $ID; 12191dad36f5SAndreas Gohr 12207367b368SAndreas Gohr $p = array(); 1221b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1222e68c51baSAndreas Gohr '&'.time(); 1223881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12247367b368SAndreas Gohr $p['height'] = 1; 12257367b368SAndreas Gohr $p['alt'] = ''; 12267367b368SAndreas Gohr $att = buildAttributes($p); 12277367b368SAndreas Gohr print "<img $att />"; 122854e95700STom N Harris return true; 12297367b368SAndreas Gohr} 12307367b368SAndreas Gohr 123178d4e784SEsther Brunner/** 123278d4e784SEsther Brunner * tpl_getConf($id) 123378d4e784SEsther Brunner * 123478d4e784SEsther Brunner * use this function to access template configuration variables 1235ac7a515fSAndreas Gohr * 123617448fb8SChristopher Smith * @param string $id name of the value to access 123717448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 123817448fb8SChristopher Smith * @return mixed 123978d4e784SEsther Brunner */ 124017448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 124178d4e784SEsther Brunner global $conf; 124217566ac6SAdrian Lang static $tpl_configloaded = false; 124378d4e784SEsther Brunner 124478d4e784SEsther Brunner $tpl = $conf['template']; 124578d4e784SEsther Brunner 124678d4e784SEsther Brunner if(!$tpl_configloaded) { 124778d4e784SEsther Brunner $tconf = tpl_loadConfig(); 124878d4e784SEsther Brunner if($tconf !== false) { 124978d4e784SEsther Brunner foreach($tconf as $key => $value) { 125078d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 125178d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 125278d4e784SEsther Brunner } 125378d4e784SEsther Brunner $tpl_configloaded = true; 125478d4e784SEsther Brunner } 125578d4e784SEsther Brunner } 125678d4e784SEsther Brunner 125717448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 125878d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 125978d4e784SEsther Brunner } 126078d4e784SEsther Brunner 126117448fb8SChristopher Smith return $notset; 126217448fb8SChristopher Smith} 126317448fb8SChristopher Smith 126478d4e784SEsther Brunner/** 126578d4e784SEsther Brunner * tpl_loadConfig() 1266ac7a515fSAndreas Gohr * 126778d4e784SEsther Brunner * reads all template configuration variables 126878d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1269ac7a515fSAndreas Gohr * 1270ac7a515fSAndreas Gohr * @return array 127178d4e784SEsther Brunner */ 127278d4e784SEsther Brunnerfunction tpl_loadConfig() { 127378d4e784SEsther Brunner 1274c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 127578d4e784SEsther Brunner $conf = array(); 127678d4e784SEsther Brunner 127778d4e784SEsther Brunner if(!@file_exists($file)) return false; 127878d4e784SEsther Brunner 127978d4e784SEsther Brunner // load default config file 128078d4e784SEsther Brunner include($file); 128178d4e784SEsther Brunner 128278d4e784SEsther Brunner return $conf; 128378d4e784SEsther Brunner} 128478d4e784SEsther Brunner 128517566ac6SAdrian Lang// language methods 128617566ac6SAdrian Lang/** 128717566ac6SAdrian Lang * tpl_getLang($id) 128817566ac6SAdrian Lang * 128917566ac6SAdrian Lang * use this function to access template language variables 129017566ac6SAdrian Lang */ 129117566ac6SAdrian Langfunction tpl_getLang($id) { 129217566ac6SAdrian Lang static $lang = array(); 129317566ac6SAdrian Lang 129417566ac6SAdrian Lang if(count($lang) === 0) { 1295dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1296dd7a6159SGerrit Uitslag 1297c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 129817566ac6SAdrian Lang 129917566ac6SAdrian Lang $lang = array(); 130017566ac6SAdrian Lang 130117566ac6SAdrian Lang // don't include once 130217566ac6SAdrian Lang @include($path . 'en/lang.php'); 1303dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 1304dd7a6159SGerrit Uitslag if(@file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1305dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1306dd7a6159SGerrit Uitslag } 130717566ac6SAdrian Lang } 130817566ac6SAdrian Lang 1309dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1310dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1311dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 1312dd7a6159SGerrit Uitslag if(@file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1313dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1314dd7a6159SGerrit Uitslag } 1315dd7a6159SGerrit Uitslag } 1316dd7a6159SGerrit Uitslag } 131717566ac6SAdrian Lang } 131817566ac6SAdrian Lang return $lang[$id]; 131917566ac6SAdrian Lang} 132017566ac6SAdrian Lang 13213df72098SAndreas Gohr/** 1322c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1323e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1324e8ec13b9SKlap-in * 1325e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1326e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1327e8ec13b9SKlap-in */ 1328e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1329c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1330e8ec13b9SKlap-in} 1331e8ec13b9SKlap-in 1332e8ec13b9SKlap-in/** 1333c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 1334e8ec13b9SKlap-in */ 1335c5c17fdaSKlap-infunction tpl_localeFN($id) { 1336e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1337e8ec13b9SKlap-in global $conf; 133838fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 1339e8ec13b9SKlap-in if (!@file_exists($file)){ 1340e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 1341e8ec13b9SKlap-in if(!@file_exists($file)){ 1342e8ec13b9SKlap-in //fall back to english 1343e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1344e8ec13b9SKlap-in } 1345e8ec13b9SKlap-in } 1346e8ec13b9SKlap-in return $file; 1347e8ec13b9SKlap-in} 1348e8ec13b9SKlap-in 1349e8ec13b9SKlap-in/** 13503df72098SAndreas Gohr * prints the "main content" in the mediamanger popup 13513df72098SAndreas Gohr * 13523df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13533df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13543df72098SAndreas Gohr * a message of referencing pages 13553df72098SAndreas Gohr * 13563df72098SAndreas Gohr * Only allowed in mediamanager.php 13573df72098SAndreas Gohr * 1358c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1359c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 136038fb1fc7SGerrit Uitslag * @param string $sort 13613df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13623df72098SAndreas Gohr */ 136300e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 13643df72098SAndreas Gohr global $IMG; 13653df72098SAndreas Gohr global $AUTH; 13663df72098SAndreas Gohr global $INUSE; 13673df72098SAndreas Gohr global $NS; 13683df72098SAndreas Gohr global $JUMPTO; 1369585bf44eSChristopher Smith /** @var Input $INPUT */ 1370ac7a515fSAndreas Gohr global $INPUT; 13713df72098SAndreas Gohr 1372ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1373c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1374c182313eSAndreas Gohr 1375c182313eSAndreas Gohr if(!$do) { 1376ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1377c182313eSAndreas Gohr $do = 'metaform'; 1378c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1379c182313eSAndreas Gohr $do = 'filesinuse'; 1380c182313eSAndreas Gohr } else { 1381c182313eSAndreas Gohr $do = 'filelist'; 1382c182313eSAndreas Gohr } 1383c182313eSAndreas Gohr } 1384c182313eSAndreas Gohr 1385c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1386c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1387c182313eSAndreas Gohr $data = array('do' => $do); 1388c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1389c182313eSAndreas Gohr if($evt->advise_before()) { 1390c182313eSAndreas Gohr $do = $data['do']; 139130fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1392c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1393c182313eSAndreas Gohr } elseif($do == 'filelist') { 139400e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1395c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1396ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1397c182313eSAndreas Gohr } else { 1398c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1399c182313eSAndreas Gohr } 1400c182313eSAndreas Gohr } 1401c182313eSAndreas Gohr $evt->advise_after(); 1402c182313eSAndreas Gohr unset($evt); 1403c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1404c182313eSAndreas Gohr 14053df72098SAndreas Gohr} 14063df72098SAndreas Gohr 14073df72098SAndreas Gohr/** 1408d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1409d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1410d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1411d9162c6cSKate Arzamastseva * 1412d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1413d9162c6cSKate Arzamastseva */ 1414035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1415d9162c6cSKate Arzamastseva global $AUTH; 1416d9162c6cSKate Arzamastseva global $NS; 1417d9162c6cSKate Arzamastseva global $JUMPTO; 141895b451bcSAdrian Lang global $lang; 1419585bf44eSChristopher Smith /** @var Input $INPUT */ 1420ac7a515fSAndreas Gohr global $INPUT; 1421d9162c6cSKate Arzamastseva 1422ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1423e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1424ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1425d9162c6cSKate Arzamastseva 142694add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 142795b451bcSAdrian Lang 1428ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 142923846a98SKate Arzamastseva 143094add303SAnika Henke echo '<div class="panelHeader">'.NL; 143195b451bcSAdrian Lang echo '<h3>'; 1432026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1433c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 143494add303SAnika Henke echo '</h3>'.NL; 143595b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 143695b451bcSAdrian Lang media_tab_files_options(); 143723846a98SKate Arzamastseva } 143894add303SAnika Henke echo '</div>'.NL; 1439d9162c6cSKate Arzamastseva 144094add303SAnika Henke echo '<div class="panelContent">'.NL; 144195b451bcSAdrian Lang if($opened_tab == 'files') { 144295b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 144395b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 144495b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 144595b451bcSAdrian Lang } elseif($opened_tab == 'search') { 144695b451bcSAdrian Lang media_tab_search($NS, $AUTH); 144795b451bcSAdrian Lang } 144894add303SAnika Henke echo '</div>'.NL; 1449d9162c6cSKate Arzamastseva} 1450d9162c6cSKate Arzamastseva 1451d9162c6cSKate Arzamastseva/** 1452d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1453d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1454d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1455d9162c6cSKate Arzamastseva * list of file revisions 1456d9162c6cSKate Arzamastseva * 1457d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1458d9162c6cSKate Arzamastseva */ 1459035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1460e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1461585bf44eSChristopher Smith /** @var Input $INPUT */ 1462585bf44eSChristopher Smith global $INPUT; 1463d9162c6cSKate Arzamastseva 146492cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1465ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 14666dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1467e8a2a143SMichael Hamann $ns = getNS($image); 1468ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 14691eeeced2SKate Arzamastseva 1470ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1471e5d185e1SKate Arzamastseva 1472e5d185e1SKate Arzamastseva $tab_array = array('view'); 1473ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1474e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1475e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1476e5d185e1SKate Arzamastseva } 1477e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1478e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1479e5d185e1SKate Arzamastseva } 1480e5d185e1SKate Arzamastseva 1481e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1482ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 148323846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1484d9162c6cSKate Arzamastseva 1485ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 148623846a98SKate Arzamastseva 148759f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1488ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 148995b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 149095b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 149100c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 149208317413SAdrian Lang if($opened_tab === 'view' && $rev) { 149308317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 149408317413SAdrian Lang } else { 1495026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 149608317413SAdrian Lang } 1497b8a84c03SAndreas Gohr 149894add303SAnika Henke echo '</h3></div>'.NL; 149995b451bcSAdrian Lang 150094add303SAnika Henke echo '<div class="panelContent">'.NL; 150195b451bcSAdrian Lang 150223846a98SKate Arzamastseva if($opened_tab == 'view') { 1503e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 150423846a98SKate Arzamastseva 150592cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1506e8a2a143SMichael Hamann media_tab_edit($image, $ns); 150723846a98SKate Arzamastseva 1508e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1509e8a2a143SMichael Hamann media_tab_history($image, $ns); 151023846a98SKate Arzamastseva } 151195b451bcSAdrian Lang 151294add303SAnika Henke echo '</div>'.NL; 1513d9162c6cSKate Arzamastseva} 1514d9162c6cSKate Arzamastseva 1515d9162c6cSKate Arzamastseva/** 15163df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup 15173df72098SAndreas Gohr * 15183df72098SAndreas Gohr * Only allowed in mediamanager.php 15193df72098SAndreas Gohr * 15203df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15213df72098SAndreas Gohr */ 1522fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 15233df72098SAndreas Gohr global $NS; 152423846a98SKate Arzamastseva ptln('<div id="media__tree">'); 15253df72098SAndreas Gohr media_nstree($NS); 15263df72098SAndreas Gohr ptln('</div>'); 15273df72098SAndreas Gohr} 15283df72098SAndreas Gohr 1529a00de5b5SAndreas Gohr/** 1530a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1531a00de5b5SAndreas Gohr * 1532a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1533a00de5b5SAndreas Gohr * 1534a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1535a00de5b5SAndreas Gohr */ 1536a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1537a00de5b5SAndreas Gohr global $ID; 1538a00de5b5SAndreas Gohr global $REV; 1539a00de5b5SAndreas Gohr global $lang; 1540585bf44eSChristopher Smith /** @var Input $INPUT */ 1541585bf44eSChristopher Smith global $INPUT; 1542a00de5b5SAndreas Gohr 1543e63eccffSAndreas Gohr echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 15443b9a3b55SAnika Henke echo '<div class="no">'; 1545a00de5b5SAndreas Gohr echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1546a00de5b5SAndreas Gohr if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1547585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 1548a00de5b5SAndreas Gohr echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 154961efcda1SChristopher Smith } 1550a00de5b5SAndreas Gohr 15515f17c394SAnika Henke echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1552a00de5b5SAndreas Gohr echo '<option value="">'.$empty.'</option>'; 1553a00de5b5SAndreas Gohr 155461917024SAnika Henke echo '<optgroup label="'.$lang['page_tools'].'">'; 1555396c218fSAndreas Gohr $act = tpl_get_action('edit'); 1556396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1557a00de5b5SAndreas Gohr 1558396c218fSAndreas Gohr $act = tpl_get_action('revert'); 1559396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1560396c218fSAndreas Gohr 15613b9a3b55SAnika Henke $act = tpl_get_action('revisions'); 15623b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15633b9a3b55SAnika Henke 1564396c218fSAndreas Gohr $act = tpl_get_action('backlink'); 1565396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15663b9a3b55SAnika Henke 15673b9a3b55SAnika Henke $act = tpl_get_action('subscribe'); 15683b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1569a00de5b5SAndreas Gohr echo '</optgroup>'; 1570a00de5b5SAndreas Gohr 157161917024SAnika Henke echo '<optgroup label="'.$lang['site_tools'].'">'; 1572396c218fSAndreas Gohr $act = tpl_get_action('recent'); 1573396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1574396c218fSAndreas Gohr 15753b9a3b55SAnika Henke $act = tpl_get_action('media'); 15763b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15773b9a3b55SAnika Henke 1578396c218fSAndreas Gohr $act = tpl_get_action('index'); 1579396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1580a00de5b5SAndreas Gohr echo '</optgroup>'; 1581a00de5b5SAndreas Gohr 158261917024SAnika Henke echo '<optgroup label="'.$lang['user_tools'].'">'; 1583396c218fSAndreas Gohr $act = tpl_get_action('login'); 1584396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1585a00de5b5SAndreas Gohr 15863b9a3b55SAnika Henke $act = tpl_get_action('register'); 1587396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1588a00de5b5SAndreas Gohr 15893b9a3b55SAnika Henke $act = tpl_get_action('profile'); 1590396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1591a00de5b5SAndreas Gohr 1592396c218fSAndreas Gohr $act = tpl_get_action('admin'); 1593396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1594a00de5b5SAndreas Gohr echo '</optgroup>'; 1595a00de5b5SAndreas Gohr 1596a00de5b5SAndreas Gohr echo '</select>'; 1597f22c1964SAndreas Gohr echo '<input type="submit" value="'.$button.'" />'; 15983b9a3b55SAnika Henke echo '</div>'; 1599a00de5b5SAndreas Gohr echo '</form>'; 1600a00de5b5SAndreas Gohr} 1601a00de5b5SAndreas Gohr 1602066fee30SAndreas Gohr/** 1603066fee30SAndreas Gohr * Print a informational line about the used license 1604066fee30SAndreas Gohr * 1605066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1606ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1607ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1608ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1609ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1610ac7a515fSAndreas Gohr * @return string 1611066fee30SAndreas Gohr */ 161280083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1613066fee30SAndreas Gohr global $license; 1614066fee30SAndreas Gohr global $conf; 1615066fee30SAndreas Gohr global $lang; 1616066fee30SAndreas Gohr if(!$conf['license']) return ''; 1617066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1618066fee30SAndreas Gohr $lic = $license[$conf['license']]; 161953e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1620066fee30SAndreas Gohr 162180083a41SAndreas Gohr $out = ''; 162280083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1623066fee30SAndreas Gohr if($img) { 1624066fee30SAndreas Gohr $src = license_img($img); 1625066fee30SAndreas Gohr if($src) { 162653e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 162753e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 162853e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1629066fee30SAndreas Gohr } 1630066fee30SAndreas Gohr } 16314cefd216SMichael Klier if(!$imgonly) { 163253e15c8bSAnika Henke $out .= $lang['license'].' '; 1633d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1634d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 16354cefd216SMichael Klier } 163680083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1637066fee30SAndreas Gohr 1638066fee30SAndreas Gohr if($return) return $out; 1639066fee30SAndreas Gohr echo $out; 1640ac7a515fSAndreas Gohr return ''; 1641066fee30SAndreas Gohr} 1642066fee30SAndreas Gohr 1643a81910eeSAndreas Gohr/** 1644835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1645a81910eeSAndreas Gohr * 1646a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1647a81910eeSAndreas Gohr * template 1648a81910eeSAndreas Gohr */ 1649835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) { 1650c786a1b6SAnika Henke if (!$pageid) return false; 1651835dfcaeSAnika Henke if ($propagate) $pageid = page_findnearest($pageid); 1652835dfcaeSAnika Henke 1653c786a1b6SAnika Henke global $TOC; 16549a2e250aSAndreas Gohr $oldtoc = $TOC; 1655a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 16569a2e250aSAndreas Gohr $TOC = $oldtoc; 1657a81910eeSAndreas Gohr 1658a81910eeSAndreas Gohr if(!$print) return $html; 1659a81910eeSAndreas Gohr echo $html; 1660e66d3e6dSAndreas Gohr return $html; 1661e66d3e6dSAndreas Gohr} 1662e66d3e6dSAndreas Gohr 1663e66d3e6dSAndreas Gohr/** 16645b75cd1fSAdrian Lang * Display the subscribe form 16655b75cd1fSAdrian Lang * 16665b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 16675b75cd1fSAdrian Lang */ 16685b75cd1fSAdrian Langfunction tpl_subscribe() { 16695b75cd1fSAdrian Lang global $INFO; 16705b75cd1fSAdrian Lang global $ID; 16715b75cd1fSAdrian Lang global $lang; 16726b8f02cfSAdrian Lang global $conf; 167340c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 16745b75cd1fSAdrian Lang 16755b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 16765b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 167715741132SAndreas Gohr echo '<div class="level2">'; 16785b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 16795b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 16805b75cd1fSAdrian Lang } else { 16815b75cd1fSAdrian Lang echo '<ul>'; 16825b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1683056c2049SAndreas Gohr echo '<li><div class="li">'; 16845b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1685056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16865b75cd1fSAdrian Lang } else { 1687056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16885b75cd1fSAdrian Lang } 168940c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 169015741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1691056c2049SAndreas Gohr echo ' ('.$sstl.') '; 169215741132SAndreas Gohr 1693ac7a515fSAndreas Gohr echo '<a href="'.wl( 1694ac7a515fSAndreas Gohr $ID, 1695ac7a515fSAndreas Gohr array( 1696ac7a515fSAndreas Gohr 'do' => 'subscribe', 169766d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 169866d2bed9SAdrian Lang 'sub_style' => $sub['style'], 169966d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1700ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1701ac7a515fSAndreas Gohr ) 1702ac7a515fSAndreas Gohr ). 170366d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 170466d2bed9SAdrian Lang '</a></div></li>'; 17055b75cd1fSAdrian Lang } 17065b75cd1fSAdrian Lang echo '</ul>'; 17075b75cd1fSAdrian Lang } 170815741132SAndreas Gohr echo '</div>'; 17095b75cd1fSAdrian Lang 171015741132SAndreas Gohr // Add new subscription form 17115b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 171215741132SAndreas Gohr echo '<div class="level2">'; 17135b75cd1fSAdrian Lang $ns = getNS($ID).':'; 171415741132SAndreas Gohr $targets = array( 171515741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 171615741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 171715741132SAndreas Gohr ); 171815741132SAndreas Gohr $styles = array( 171915741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 17206b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 17216b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 172215741132SAndreas Gohr ); 172315741132SAndreas Gohr 1724056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1725056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1726056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1727056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1728056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1729056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1730056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1731056c2049SAndreas Gohr $form->addHidden('id', $ID); 1732056c2049SAndreas Gohr $form->endFieldset(); 17335b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 17345b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 173515741132SAndreas Gohr echo '</div>'; 17365b75cd1fSAdrian Lang} 17375b75cd1fSAdrian Lang 1738d059ba9bSAndreas Gohr/** 1739d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1740d059ba9bSAndreas Gohr * 1741d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1742d059ba9bSAndreas Gohr * 1743d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1744d059ba9bSAndreas Gohr */ 1745d059ba9bSAndreas Gohrfunction tpl_flush() { 1746d059ba9bSAndreas Gohr ob_flush(); 1747d059ba9bSAndreas Gohr flush(); 1748d059ba9bSAndreas Gohr} 1749d059ba9bSAndreas Gohr 1750afca7e7eSAnika Henke/** 1751378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1752afca7e7eSAnika Henke * 1753378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1754378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1755378325f9SAndreas Gohr * 1756378325f9SAndreas Gohr * @param array $search locations to look at 1757378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1758ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1759ac7a515fSAndreas Gohr * @return string 1760378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1761afca7e7eSAnika Henke */ 1762378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1763ac7a515fSAndreas Gohr $img = ''; 1764ac7a515fSAndreas Gohr $file = ''; 1765ac7a515fSAndreas Gohr $ismedia = false; 1766378325f9SAndreas Gohr // loop through candidates until a match was found: 1767378325f9SAndreas Gohr foreach($search as $img) { 1768378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1769378325f9SAndreas Gohr $file = mediaFN($img); 1770378325f9SAndreas Gohr $ismedia = true; 1771378325f9SAndreas Gohr } else { 1772c4766956SAndreas Gohr $file = tpl_incdir().$img; 1773378325f9SAndreas Gohr $ismedia = false; 17741f13e33dSAnika Henke } 17750f747863Slupo49 1776378325f9SAndreas Gohr if(file_exists($file)) break; 1777872a6d29SAnika Henke } 1778378325f9SAndreas Gohr 1779378325f9SAndreas Gohr // fetch image data if requested 1780378325f9SAndreas Gohr if(!is_null($imginfo)) { 1781378325f9SAndreas Gohr $imginfo = getimagesize($file); 1782378325f9SAndreas Gohr } 1783378325f9SAndreas Gohr 1784378325f9SAndreas Gohr // build URL 1785378325f9SAndreas Gohr if($ismedia) { 1786378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1787378325f9SAndreas Gohr } else { 1788c4766956SAndreas Gohr $url = tpl_basedir().$img; 1789378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1790378325f9SAndreas Gohr } 1791378325f9SAndreas Gohr 1792378325f9SAndreas Gohr return $url; 1793a7e5f74cSlupo49} 17941f13e33dSAnika Henke 1795872a6d29SAnika Henke/** 1796e5d4768dSAndreas Gohr * PHP include a file 1797e5d4768dSAndreas Gohr * 1798e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1799e5d4768dSAndreas Gohr * file in the template's root directory. 1800e5d4768dSAndreas Gohr * 1801e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1802e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1803e5d4768dSAndreas Gohr * default. 1804e5d4768dSAndreas Gohr * 1805e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1806e5d4768dSAndreas Gohr * to this function! 1807e5d4768dSAndreas Gohr * 1808e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1809e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1810e5d4768dSAndreas Gohr */ 1811e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1812e5d4768dSAndreas Gohr global $config_cascade; 1813e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1814e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1815e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1816e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1817e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1818f3a1225fSAnika Henke include("$dir/$file"); 1819e5d4768dSAndreas Gohr return; 1820e5d4768dSAndreas Gohr } 1821e5d4768dSAndreas Gohr } 1822e5d4768dSAndreas Gohr } 1823e5d4768dSAndreas Gohr 1824e5d4768dSAndreas Gohr // still here? try the template dir 1825e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1826e5d4768dSAndreas Gohr if(file_exists($file)) { 1827f3a1225fSAnika Henke include($file); 1828e5d4768dSAndreas Gohr } 1829e5d4768dSAndreas Gohr} 1830e5d4768dSAndreas Gohr 1831e5d4768dSAndreas Gohr/** 1832872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1833872a6d29SAnika Henke * 1834872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 1835ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1836ac7a515fSAndreas Gohr * @return string 1837872a6d29SAnika Henke */ 1838872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1839872a6d29SAnika Henke 1840872a6d29SAnika Henke $return = ''; 1841872a6d29SAnika Henke 1842872a6d29SAnika Henke foreach($types as $type) { 1843872a6d29SAnika Henke switch($type) { 1844872a6d29SAnika Henke case 'favicon': 1845378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1846378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1847872a6d29SAnika Henke break; 1848872a6d29SAnika Henke case 'mobile': 1849cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1850378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1851872a6d29SAnika Henke break; 1852872a6d29SAnika Henke case 'generic': 1853872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1854378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1855378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1856872a6d29SAnika Henke break; 1857872a6d29SAnika Henke } 1858872a6d29SAnika Henke } 1859872a6d29SAnika Henke 1860872a6d29SAnika Henke return $return; 1861afca7e7eSAnika Henke} 1862afca7e7eSAnika Henke 1863d9162c6cSKate Arzamastseva/** 1864d9162c6cSKate Arzamastseva * Prints full-screen media manager 1865d9162c6cSKate Arzamastseva * 1866d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1867d9162c6cSKate Arzamastseva */ 1868d9162c6cSKate Arzamastsevafunction tpl_media() { 1869ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 187088a71175SKate Arzamastseva $fullscreen = true; 187195b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1872d9162c6cSKate Arzamastseva 1873ac7a515fSAndreas Gohr $rev = ''; 1874ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 187598f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 187698f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 18779c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 187898f03b57SKate Arzamastseva 187994add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1880bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1881d9162c6cSKate Arzamastseva html_msgarea(); 188294add303SAnika Henke 188394add303SAnika Henke echo '<div class="panel namespaces">'.NL; 188494add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 188595b451bcSAdrian Lang echo '<div class="panelHeader">'; 1886ba340a70SAnika Henke echo $lang['media_namespaces']; 188794add303SAnika Henke echo '</div>'.NL; 188895b451bcSAdrian Lang 188994add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 189095b451bcSAdrian Lang media_nstree($NS); 189194add303SAnika Henke echo '</div>'.NL; 189294add303SAnika Henke echo '</div>'.NL; 1893fa8e5c77SKate Arzamastseva 189494add303SAnika Henke echo '<div class="panel filelist">'.NL; 1895035e07f1SKate Arzamastseva tpl_mediaFileList(); 189694add303SAnika Henke echo '</div>'.NL; 1897fa8e5c77SKate Arzamastseva 189894add303SAnika Henke echo '<div class="panel file">'.NL; 189994add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1900035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 190194add303SAnika Henke echo '</div>'.NL; 1902ba340a70SAnika Henke 190394add303SAnika Henke echo '</div>'.NL; 1904d9162c6cSKate Arzamastseva} 1905afca7e7eSAnika Henke 1906c71db656SAnika Henke/** 1907c71db656SAnika Henke * Return useful layout classes 1908c71db656SAnika Henke * 1909c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 1910c71db656SAnika Henke */ 1911c71db656SAnika Henkefunction tpl_classes() { 1912c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1913585bf44eSChristopher Smith /** @var Input $INPUT */ 1914585bf44eSChristopher Smith global $INPUT; 1915585bf44eSChristopher Smith 1916c71db656SAnika Henke $classes = array( 1917c71db656SAnika Henke 'dokuwiki', 1918c71db656SAnika Henke 'mode_'.$ACT, 1919c71db656SAnika Henke 'tpl_'.$conf['template'], 1920585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 192139f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1922c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1923c71db656SAnika Henke ); 1924c71db656SAnika Henke return join(' ', $classes); 1925c71db656SAnika Henke} 1926c71db656SAnika Henke 1927e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1928a00de5b5SAndreas Gohr 1929