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> 7142ea7f44SGerrit Uitslag * 72ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 73ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 74ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 75ac7a515fSAndreas Gohr * @return bool true if any output 766b13307fSandi */ 77b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 787ea0913cSchris global $ACT; 79b8595a66SAndreas Gohr global $INFO; 80b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 817ea0913cSchris 827ea0913cSchris ob_start(); 83746855cfSBen Coburn trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 847ea0913cSchris $html_output = ob_get_clean(); 85746855cfSBen Coburn trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8654e95700STom N Harris 8754e95700STom N Harris return !empty($html_output); 887ea0913cSchris} 897ea0913cSchris 90ac7a515fSAndreas Gohr/** 91ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 92ac7a515fSAndreas Gohr * 93ac7a515fSAndreas Gohr * @return bool 94ac7a515fSAndreas Gohr */ 957ea0913cSchrisfunction tpl_content_core() { 966b13307fSandi global $ACT; 976b13307fSandi global $TEXT; 986b13307fSandi global $PRE; 996b13307fSandi global $SUF; 1006b13307fSandi global $SUM; 1016b13307fSandi global $IDX; 102ac7a515fSAndreas Gohr global $INPUT; 1036b13307fSandi 1046b13307fSandi switch($ACT) { 1056b13307fSandi case 'show': 1066b13307fSandi html_show(); 1076b13307fSandi break; 108ac7a515fSAndreas Gohr /** @noinspection PhpMissingBreakStatementInspection */ 10945a99335SAdrian Lang case 'locked': 11045a99335SAdrian Lang html_locked(); 1116b13307fSandi case 'edit': 11245a99335SAdrian Lang case 'recover': 1136b13307fSandi html_edit(); 1146b13307fSandi break; 11545a99335SAdrian Lang case 'preview': 11645a99335SAdrian Lang html_edit(); 11745a99335SAdrian Lang html_show($TEXT); 11845a99335SAdrian Lang break; 119ee4c4a1bSAndreas Gohr case 'draft': 120ee4c4a1bSAndreas Gohr html_draft(); 121ee4c4a1bSAndreas Gohr break; 1226b13307fSandi case 'search': 1236b13307fSandi html_search(); 1246b13307fSandi break; 1256b13307fSandi case 'revisions': 126ac7a515fSAndreas Gohr html_revisions($INPUT->int('first')); 1276b13307fSandi break; 1286b13307fSandi case 'diff': 1296b13307fSandi html_diff(); 1306b13307fSandi break; 1316b13307fSandi case 'recent': 1323c94d07bSAnika Henke $show_changes = $INPUT->str('show_changes'); 1333c94d07bSAnika Henke if (empty($show_changes)) { 1343c94d07bSAnika Henke $show_changes = get_doku_pref('show_changes', $show_changes); 1353c94d07bSAnika Henke } 1363c94d07bSAnika Henke html_recent($INPUT->extract('first')->int('first'), $show_changes); 1376b13307fSandi break; 1386b13307fSandi case 'index': 1396b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 1406b13307fSandi break; 1416b13307fSandi case 'backlink': 1426b13307fSandi html_backlinks(); 1436b13307fSandi break; 1446b13307fSandi case 'conflict': 1456b13307fSandi html_conflict(con($PRE, $TEXT, $SUF), $SUM); 1466b13307fSandi html_diff(con($PRE, $TEXT, $SUF), false); 1476b13307fSandi break; 1486b13307fSandi case 'login': 1496b13307fSandi html_login(); 1506b13307fSandi break; 1516b13307fSandi case 'register': 1526b13307fSandi html_register(); 1536b13307fSandi break; 1548b06d178Schris case 'resendpwd': 1558b06d178Schris html_resendpwd(); 1568b06d178Schris break; 157820fa24bSandi case 'denied': 1582f2c518cSGerrit Uitslag html_denied(); 159820fa24bSandi break; 1608b06d178Schris case 'profile' : 1618b06d178Schris html_updateprofile(); 1628b06d178Schris break; 163c19fe9c0Sandi case 'admin': 164c19fe9c0Sandi tpl_admin(); 165c19fe9c0Sandi break; 1665b75cd1fSAdrian Lang case 'subscribe': 1675b75cd1fSAdrian Lang tpl_subscribe(); 1685b75cd1fSAdrian Lang break; 169d9162c6cSKate Arzamastseva case 'media': 170d9162c6cSKate Arzamastseva tpl_media(); 171d9162c6cSKate Arzamastseva break; 1726b13307fSandi default: 17324bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); 174a85f63deSGerrit Uitslag if($evt->advise_before()) { 175ea67f144Sandi msg("Failed to handle command: ".hsc($ACT), -1); 176a85f63deSGerrit Uitslag } 17724bb549bSchris $evt->advise_after(); 17824bb549bSchris unset($evt); 17954e95700STom N Harris return false; 1806b13307fSandi } 18154e95700STom N Harris return true; 1826b13307fSandi} 1836b13307fSandi 184c19fe9c0Sandi/** 185b8595a66SAndreas Gohr * Places the TOC where the function is called 186b8595a66SAndreas Gohr * 187b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 188b8595a66SAndreas Gohr * a false argument 189b8595a66SAndreas Gohr * 190b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 19142ea7f44SGerrit Uitslag * 192ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 193ac7a515fSAndreas Gohr * @return string 194b8595a66SAndreas Gohr */ 195b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 196b8595a66SAndreas Gohr global $TOC; 197b8595a66SAndreas Gohr global $ACT; 198b8595a66SAndreas Gohr global $ID; 199b8595a66SAndreas Gohr global $REV; 200b8595a66SAndreas Gohr global $INFO; 201851f2e89SAnika Henke global $conf; 202ac7a515fSAndreas Gohr global $INPUT; 203b8595a66SAndreas Gohr $toc = array(); 204b8595a66SAndreas Gohr 205b8595a66SAndreas Gohr if(is_array($TOC)) { 206b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 207b8595a66SAndreas Gohr $toc = $TOC; 2083c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 209b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 210e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 211b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 212b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 213b8595a66SAndreas Gohr } else { 2142bb0d541Schris $tocok = true; 215b8595a66SAndreas Gohr } 216f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 217851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 218b8595a66SAndreas Gohr $toc = array(); 219b8595a66SAndreas Gohr } 220b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 221a61966c5SChristopher Smith // try to load admin plugin TOC 222ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 223a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 224b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 225b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 226b8595a66SAndreas Gohr } 227b8595a66SAndreas Gohr } 228b8595a66SAndreas Gohr 2290b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 230b8595a66SAndreas Gohr $html = html_TOC($toc); 231b8595a66SAndreas Gohr if($return) return $html; 232b8595a66SAndreas Gohr echo $html; 233ac7a515fSAndreas Gohr return ''; 234b8595a66SAndreas Gohr} 235b8595a66SAndreas Gohr 236b8595a66SAndreas Gohr/** 237c19fe9c0Sandi * Handle the admin page contents 238c19fe9c0Sandi * 239c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 24042ea7f44SGerrit Uitslag * 24142ea7f44SGerrit Uitslag * @return bool 242c19fe9c0Sandi */ 243c19fe9c0Sandifunction tpl_admin() { 244f8cc712eSAndreas Gohr global $INFO; 245b8595a66SAndreas Gohr global $TOC; 246ac7a515fSAndreas Gohr global $INPUT; 24711e2ce22Schris 248b8595a66SAndreas Gohr $plugin = null; 249ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 250ac7a515fSAndreas Gohr if(!empty($class)) { 25111e2ce22Schris $pluginlist = plugin_list('admin'); 25211e2ce22Schris 253ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 25411e2ce22Schris // attempt to load the plugin 255ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 256a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 25711e2ce22Schris } 25811e2ce22Schris } 25911e2ce22Schris 260b8595a66SAndreas Gohr if($plugin !== null) { 261b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 262b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 263f8cc712eSAndreas Gohr $plugin->html(); 264f8cc712eSAndreas Gohr } else { 265f8cc712eSAndreas Gohr html_admin(); 266f8cc712eSAndreas Gohr } 26754e95700STom N Harris return true; 268c19fe9c0Sandi} 2696b13307fSandi 2706b13307fSandi/** 2716b13307fSandi * Print the correct HTML meta headers 2726b13307fSandi * 2736b13307fSandi * This has to go into the head section of your template. 2746b13307fSandi * 2756b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 27642ea7f44SGerrit Uitslag * 277ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 278ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 279ac7a515fSAndreas Gohr * @return bool 2806b13307fSandi */ 281f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2826b13307fSandi global $ID; 283d98d4540SBen Coburn global $REV; 2846b13307fSandi global $INFO; 28572e0dc37SAndreas Gohr global $JSINFO; 2866b13307fSandi global $ACT; 2874bb1b5aeSAndreas Gohr global $QUERY; 2886b13307fSandi global $lang; 289dc57ef04Sandi global $conf; 2909c438d6cSMichael Hamann global $updateVersion; 291585bf44eSChristopher Smith /** @var Input $INPUT */ 292585bf44eSChristopher Smith global $INPUT; 2936b13307fSandi 2947bff22c0SAndreas Gohr // prepare the head array 2957bff22c0SAndreas Gohr $head = array(); 2967bff22c0SAndreas Gohr 297202ac28bSMichael Klier // prepare seed for js and css 298cd997f93SAndreas Gohr $tseed = $updateVersion; 299202ac28bSMichael Klier $depends = getConfigFiles('main'); 30084e76a7eSAndreas Gohr $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; 301cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 302cd997f93SAndreas Gohr $tseed = md5($tseed); 3037bff22c0SAndreas Gohr 3046b13307fSandi // the usual stuff 3053f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 30663cf4192Ssarehag if(actionOK('search')) { 307ac7a515fSAndreas Gohr $head['link'][] = array( 308ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 309ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 310ac7a515fSAndreas Gohr ); 31163cf4192Ssarehag } 31263cf4192Ssarehag 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', 400e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($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 41261537d47SAndreas Gohr // load jquery 413*fa078663SAndreas Gohr $jquery = getCdnUrls(); 414*fa078663SAndreas Gohr foreach($jquery as $src) { 41561537d47SAndreas Gohr $head['script'][] = array( 416*fa078663SAndreas Gohr 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src 41761537d47SAndreas Gohr ); 41861537d47SAndreas Gohr } 41961537d47SAndreas Gohr 42061537d47SAndreas Gohr // load our javascript dispatcher 421ac7a515fSAndreas Gohr $head['script'][] = array( 422ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 423e283bd6cSAnika Henke 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 424ac7a515fSAndreas Gohr ); 4257bff22c0SAndreas Gohr 4267bff22c0SAndreas Gohr // trigger event here 427016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 42854e95700STom N Harris return true; 4297bff22c0SAndreas Gohr} 4307bff22c0SAndreas Gohr 4317bff22c0SAndreas Gohr/** 4327bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4337bff22c0SAndreas Gohr * 4347bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4357bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4367bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4377bff22c0SAndreas Gohr * 43842ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4391304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4407bff22c0SAndreas Gohr * 4417bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 44242ea7f44SGerrit Uitslag * 44342ea7f44SGerrit Uitslag * @param array $data 4447bff22c0SAndreas Gohr */ 4457bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4467bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 4477bff22c0SAndreas Gohr foreach($inst as $attr) { 4487bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 44926afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 450e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 45109f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 452e226efe1SAndreas Gohr $attr['_data']. 45309f791c4SDominik Eckelmann "\n/*!]]>*/"; 454e226efe1SAndreas Gohr 4551304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4567bff22c0SAndreas Gohr } else { 4577bff22c0SAndreas Gohr echo '/>'; 4587bff22c0SAndreas Gohr } 4597bff22c0SAndreas Gohr echo "\n"; 4607bff22c0SAndreas Gohr } 4617bff22c0SAndreas Gohr } 4626b13307fSandi} 4636b13307fSandi 4646b13307fSandi/** 4656b13307fSandi * Print a link 4666b13307fSandi * 4675e163278SAndreas Gohr * Just builds a link. 4686b13307fSandi * 4696b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 47042ea7f44SGerrit Uitslag * 47142ea7f44SGerrit Uitslag * @param string $url 47242ea7f44SGerrit Uitslag * @param string $name 47342ea7f44SGerrit Uitslag * @param string $more 47421d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 47521d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4766b13307fSandi */ 4771af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 47801f17825SAnika Henke $out = '<a href="'.$url.'" '; 4791af98a77SAnika Henke if($more) $out .= ' '.$more; 4801af98a77SAnika Henke $out .= ">$name</a>"; 4811af98a77SAnika Henke if($return) return $out; 4821af98a77SAnika Henke print $out; 48354e95700STom N Harris return true; 4846b13307fSandi} 4856b13307fSandi 4866b13307fSandi/** 48755efc227SAndreas Gohr * Prints a link to a WikiPage 48855efc227SAndreas Gohr * 48955efc227SAndreas Gohr * Wrapper around html_wikilink 49055efc227SAndreas Gohr * 49155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 49242ea7f44SGerrit Uitslag * 49342ea7f44SGerrit Uitslag * @param string $id page id 49442ea7f44SGerrit Uitslag * @param string|null $name the name of the link 49521d806cdSGerrit Uitslag * @return bool true 49655efc227SAndreas Gohr */ 4970b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 498d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 49954e95700STom N Harris return true; 50055efc227SAndreas Gohr} 50155efc227SAndreas Gohr 50255efc227SAndreas Gohr/** 503a3ec5f4aSmatthiasgrimm * get the parent page 504a3ec5f4aSmatthiasgrimm * 505a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 506a3ec5f4aSmatthiasgrimm * returns false if none is available 507a3ec5f4aSmatthiasgrimm * 508377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 50942ea7f44SGerrit Uitslag * 51042ea7f44SGerrit Uitslag * @param string $id page id 51142ea7f44SGerrit Uitslag * @return false|string 512a3ec5f4aSmatthiasgrimm */ 513377f9e97SAndreas Gohrfunction tpl_getparent($id) { 514377f9e97SAndreas Gohr $parent = getNS($id).':'; 515377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 516a197105eSmatthiasgrimm if($parent == $id) { 517a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 518a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 519a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 520377f9e97SAndreas Gohr if($parent == $id) return false; 521a197105eSmatthiasgrimm } 522377f9e97SAndreas Gohr return $parent; 523a3ec5f4aSmatthiasgrimm} 524a3ec5f4aSmatthiasgrimm 525a3ec5f4aSmatthiasgrimm/** 5266b13307fSandi * Print one of the buttons 5276b13307fSandi * 528a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 529a453d131SAdrian Lang * @see tpl_get_action 530e0c26282SGerrit Uitslag * 531e0c26282SGerrit Uitslag * @param string $type 532e0c26282SGerrit Uitslag * @param bool $return 533e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5346b13307fSandi */ 5351af98a77SAnika Henkefunction tpl_button($type, $return = false) { 536a453d131SAdrian Lang $data = tpl_get_action($type); 537a453d131SAdrian Lang if($data === false) { 538a453d131SAdrian Lang return false; 539a453d131SAdrian Lang } elseif(!is_array($data)) { 540a453d131SAdrian Lang $out = sprintf($data, 'button'); 541409d7af7SAndreas Gohr } else { 542ac7a515fSAndreas Gohr /** 543ac7a515fSAndreas Gohr * @var string $accesskey 544ac7a515fSAndreas Gohr * @var string $id 545ac7a515fSAndreas Gohr * @var string $method 546ac7a515fSAndreas Gohr * @var array $params 547ac7a515fSAndreas Gohr */ 548a453d131SAdrian Lang extract($data); 549a453d131SAdrian Lang if($id === '#dokuwiki__top') { 550a453d131SAdrian Lang $out = html_topbtn(); 551409d7af7SAndreas Gohr } else { 552a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 553409d7af7SAndreas Gohr } 554409d7af7SAndreas Gohr } 5551af98a77SAnika Henke if($return) return $out; 556a453d131SAdrian Lang echo $out; 557a453d131SAdrian Lang return true; 5586b13307fSandi} 5596b13307fSandi 5606b13307fSandi/** 561ed630903Sandi * Like the action buttons but links 562ed630903Sandi * 563a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 564a453d131SAdrian Lang * @see tpl_get_action 565e0c26282SGerrit Uitslag * 56642ea7f44SGerrit Uitslag * @param string $type action command 567e0c26282SGerrit Uitslag * @param string $pre prefix of link 568e0c26282SGerrit Uitslag * @param string $suf suffix of link 569e0c26282SGerrit Uitslag * @param string $inner innerHML of link 57021d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 571e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 572a453d131SAdrian Lang */ 573a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 574a453d131SAdrian Lang global $lang; 575a453d131SAdrian Lang $data = tpl_get_action($type); 576a453d131SAdrian Lang if($data === false) { 577a453d131SAdrian Lang return false; 578a453d131SAdrian Lang } elseif(!is_array($data)) { 579a453d131SAdrian Lang $out = sprintf($data, 'link'); 580a453d131SAdrian Lang } else { 581ac7a515fSAndreas Gohr /** 582ac7a515fSAndreas Gohr * @var string $accesskey 583ac7a515fSAndreas Gohr * @var string $id 584ac7a515fSAndreas Gohr * @var string $method 585b1af9014SChristopher Smith * @var bool $nofollow 586ac7a515fSAndreas Gohr * @var array $params 587becfa414SGerrit Uitslag * @var string $replacement 588ac7a515fSAndreas Gohr */ 589a453d131SAdrian Lang extract($data); 590a453d131SAdrian Lang if(strpos($id, '#') === 0) { 591a453d131SAdrian Lang $linktarget = $id; 592a453d131SAdrian Lang } else { 593a453d131SAdrian Lang $linktarget = wl($id, $params); 594a453d131SAdrian Lang } 595a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 596becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 597becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 598becfa414SGerrit Uitslag } 599c7e90e3fSAnika Henke $akey = $addTitle = ''; 600c7e90e3fSAnika Henke if($accesskey) { 601c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 602c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 603c7e90e3fSAnika Henke } 604b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 605ac7a515fSAndreas Gohr $out = tpl_link( 606ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 607a453d131SAdrian Lang 'class="action '.$type.'" '. 608b1af9014SChristopher Smith $akey.$rel. 609e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 610ac7a515fSAndreas Gohr ); 611a453d131SAdrian Lang } 612a453d131SAdrian Lang if($return) return $out; 613a453d131SAdrian Lang echo $out; 614a453d131SAdrian Lang return true; 615a453d131SAdrian Lang} 616a453d131SAdrian Lang 617a453d131SAdrian Lang/** 618a453d131SAdrian Lang * Check the actions and get data for buttons and links 619ed630903Sandi * 620a453d131SAdrian Lang * Available actions are 621a453d131SAdrian Lang * 622a453d131SAdrian Lang * edit - edit/create/show/draft 623ed630903Sandi * history - old revisions 624ed630903Sandi * recent - recent changes 625a453d131SAdrian Lang * login - login/logout - if ACL enabled 626a453d131SAdrian Lang * profile - user profile (if logged in) 627ed630903Sandi * index - The index 628ed630903Sandi * admin - admin page - if enough rights 629a453d131SAdrian Lang * top - back to top 630a453d131SAdrian Lang * back - back to parent - if available 631bbd37938SAndreas Gohr * backlink - links to the list of backlinks 632a453d131SAdrian Lang * subscribe/subscription- subscribe/unsubscribe 633ed630903Sandi * 634ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 635a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 636a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 637e0c26282SGerrit Uitslag * 638ac7a515fSAndreas Gohr * @param string $type 639ac7a515fSAndreas Gohr * @return array|bool|string 640ed630903Sandi */ 641a453d131SAdrian Langfunction tpl_get_action($type) { 642ed630903Sandi global $ID; 643ed630903Sandi global $INFO; 644ed630903Sandi global $REV; 645ed630903Sandi global $ACT; 646b1af9014SChristopher Smith global $conf; 647585bf44eSChristopher Smith /** @var Input $INPUT */ 648585bf44eSChristopher Smith global $INPUT; 649ed630903Sandi 65075e487e9SAndreas Gohr // check disabled actions and fix the badly named ones 651a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6524c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 653a453d131SAdrian Lang if(!actionOK($type)) return false; 654409d7af7SAndreas Gohr 655a453d131SAdrian Lang $accesskey = null; 6566709e843SAdrian Lang $id = $ID; 657a453d131SAdrian Lang $method = 'get'; 658a453d131SAdrian Lang $params = array('do' => $type); 659b1af9014SChristopher Smith $nofollow = true; 660becfa414SGerrit Uitslag $replacement = ''; 6617b4365a7SGerrit Uitslag 6627b4365a7SGerrit Uitslag $unknown = false; 663ed630903Sandi switch($type) { 664ed630903Sandi case 'edit': 6650b17fdc6SAndreas Gohr // most complicated type - we need to decide on current action 666ed630903Sandi if($ACT == 'show' || $ACT == 'search') { 667a453d131SAdrian Lang $method = 'post'; 668ed630903Sandi if($INFO['writable']) { 669a453d131SAdrian Lang $accesskey = 'e'; 670b8a111f5SMichael Klier if(!empty($INFO['draft'])) { 6716709e843SAdrian Lang $type = 'draft'; 672a453d131SAdrian Lang $params['do'] = 'draft'; 673b8a111f5SMichael Klier } else { 674a453d131SAdrian Lang $params['rev'] = $REV; 675a453d131SAdrian Lang if(!$INFO['exists']) { 6766709e843SAdrian Lang $type = 'create'; 677ed630903Sandi } 678b8a111f5SMichael Klier } 679ed630903Sandi } else { 680a453d131SAdrian Lang if(!actionOK('source')) return false; //pseudo action 681a453d131SAdrian Lang $params['rev'] = $REV; 6826709e843SAdrian Lang $type = 'source'; 683a453d131SAdrian Lang $accesskey = 'v'; 684ed630903Sandi } 685ed630903Sandi } else { 686d30d4913SChristopher Smith $params = array('do' => ''); 6876709e843SAdrian Lang $type = 'show'; 688a453d131SAdrian Lang $accesskey = 'v'; 689ed630903Sandi } 6901af98a77SAnika Henke break; 691a453d131SAdrian Lang case 'revisions': 6926709e843SAdrian Lang $type = 'revs'; 693a453d131SAdrian Lang $accesskey = 'o'; 6941af98a77SAnika Henke break; 695ed630903Sandi case 'recent': 696a453d131SAdrian Lang $accesskey = 'r'; 6971af98a77SAnika Henke break; 698ed630903Sandi case 'index': 699a453d131SAdrian Lang $accesskey = 'x'; 700b1af9014SChristopher Smith // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 701b1af9014SChristopher Smith if ($conf['start'] == $ID && !$conf['sitemap']) { 702b1af9014SChristopher Smith $nofollow = false; 703b1af9014SChristopher Smith } 7041af98a77SAnika Henke break; 705ed630903Sandi case 'top': 706076f0d72SAnika Henke $accesskey = 't'; 707d30d4913SChristopher Smith $params = array('do' => ''); 708a453d131SAdrian Lang $id = '#dokuwiki__top'; 7091af98a77SAnika Henke break; 710a3ec5f4aSmatthiasgrimm case 'back': 711a453d131SAdrian Lang $parent = tpl_getparent($ID); 712a453d131SAdrian Lang if(!$parent) { 713a453d131SAdrian Lang return false; 714a3ec5f4aSmatthiasgrimm } 715a453d131SAdrian Lang $id = $parent; 716d30d4913SChristopher Smith $params = array('do' => ''); 717a453d131SAdrian Lang $accesskey = 'b'; 7181af98a77SAnika Henke break; 719becfa414SGerrit Uitslag case 'img_backto': 720becfa414SGerrit Uitslag $params = array(); 721becfa414SGerrit Uitslag $accesskey = 'b'; 722becfa414SGerrit Uitslag $replacement = $ID; 723becfa414SGerrit Uitslag break; 724ed630903Sandi case 'login': 725a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 726585bf44eSChristopher Smith if($INPUT->server->has('REMOTE_USER')) { 7273a48618aSAnika Henke if(!actionOK('logout')) { 7282380e8a8SAdrian Lang return false; 7292380e8a8SAdrian Lang } 730a453d131SAdrian Lang $params['do'] = 'logout'; 731a453d131SAdrian Lang $type = 'logout'; 732bf413a4eSAnika Henke } 733bf413a4eSAnika Henke break; 734bf413a4eSAnika Henke case 'register': 735585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 736bf413a4eSAnika Henke return false; 737bf413a4eSAnika Henke } 738bf413a4eSAnika Henke break; 739bf413a4eSAnika Henke case 'resendpwd': 740585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 741bf413a4eSAnika Henke return false; 742ed630903Sandi } 7431af98a77SAnika Henke break; 744ed630903Sandi case 'admin': 745a453d131SAdrian Lang if(!$INFO['ismanager']) { 746a453d131SAdrian Lang return false; 747c059e1a6SAndreas Gohr } 7481af98a77SAnika Henke break; 7491246e016SAndreas Gohr case 'revert': 750a453d131SAdrian Lang if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 751a453d131SAdrian Lang return false; 7521246e016SAndreas Gohr } 753a453d131SAdrian Lang $params['rev'] = $REV; 754a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 7551246e016SAndreas Gohr break; 7566709e843SAdrian Lang case 'subscribe': 757585bf44eSChristopher Smith if(!$INPUT->server->str('REMOTE_USER')) { 758a453d131SAdrian Lang return false; 759b158d625SSteven Danz } 7601af98a77SAnika Henke break; 761f00151b4Schris case 'backlink': 7621af98a77SAnika Henke break; 7638b06d178Schris case 'profile': 764585bf44eSChristopher Smith if(!$INPUT->server->has('REMOTE_USER')) { 765a453d131SAdrian Lang return false; 7668b06d178Schris } 7671af98a77SAnika Henke break; 768b9eb2e61SKate Arzamastseva case 'media': 769d08527abSAnika Henke $params['ns'] = getNS($ID); 770b9eb2e61SKate Arzamastseva break; 771becfa414SGerrit Uitslag case 'mediaManager': 772becfa414SGerrit Uitslag // View image in media manager 773becfa414SGerrit Uitslag global $IMG; 774becfa414SGerrit Uitslag $imgNS = getNS($IMG); 775becfa414SGerrit Uitslag $authNS = auth_quickaclcheck("$imgNS:*"); 776becfa414SGerrit Uitslag if ($authNS < AUTH_UPLOAD) { 777becfa414SGerrit Uitslag return false; 778becfa414SGerrit Uitslag } 779becfa414SGerrit Uitslag $params = array( 780becfa414SGerrit Uitslag 'ns' => $imgNS, 781becfa414SGerrit Uitslag 'image' => $IMG, 782becfa414SGerrit Uitslag 'do' => 'media' 783becfa414SGerrit Uitslag ); 784becfa414SGerrit Uitslag //$type = 'media'; 785becfa414SGerrit Uitslag break; 786ed630903Sandi default: 7877b4365a7SGerrit Uitslag //unknown type 7887b4365a7SGerrit Uitslag $unknown = true; 789ed630903Sandi } 7907b4365a7SGerrit Uitslag 7917b4365a7SGerrit Uitslag $data = compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); 7927b4365a7SGerrit Uitslag 7933131073dSGerrit Uitslag $evt = new Doku_Event('TPL_ACTION_GET', $data); 7947b4365a7SGerrit Uitslag if($evt->advise_before()) { 7957b4365a7SGerrit Uitslag //handle unknown types 7967b4365a7SGerrit Uitslag if($unknown) { 79738d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 7987b4365a7SGerrit Uitslag } 7997b4365a7SGerrit Uitslag } 8007b4365a7SGerrit Uitslag $evt->advise_after(); 8017b4365a7SGerrit Uitslag unset($evt); 8027b4365a7SGerrit Uitslag 8037b4365a7SGerrit Uitslag return $data; 804ed630903Sandi} 805ed630903Sandi 806ed630903Sandi/** 80701f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 80801f17825SAnika Henke * 80901f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 81042ea7f44SGerrit Uitslag * 81142ea7f44SGerrit Uitslag * @param string $type action command 812ac7a515fSAndreas Gohr * @param bool $link link or form button? 813e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 814ac7a515fSAndreas Gohr * @param bool $return return or print 815ac7a515fSAndreas Gohr * @param string $pre prefix for links 816ac7a515fSAndreas Gohr * @param string $suf suffix for links 817ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 818ac7a515fSAndreas Gohr * @return bool|string 81901f17825SAnika Henke */ 820ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 82101f17825SAnika Henke $out = ''; 822ac7a515fSAndreas Gohr if($link) { 823e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 824ac7a515fSAndreas Gohr } else { 825e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 826ac7a515fSAndreas Gohr } 82701f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 82801f17825SAnika Henke 82901f17825SAnika Henke if($return) return $out; 83001f17825SAnika Henke print $out; 83101f17825SAnika Henke return $out ? true : false; 83201f17825SAnika Henke} 83301f17825SAnika Henke 83401f17825SAnika Henke/** 8356b13307fSandi * Print the search form 8366b13307fSandi * 83772645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 83872645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 83972645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 84072645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 84172645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 84272645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 84372645b75SAndreas Gohr * 8446b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 84542ea7f44SGerrit Uitslag * 846ac7a515fSAndreas Gohr * @param bool $ajax 847ac7a515fSAndreas Gohr * @param bool $autocomplete 848ac7a515fSAndreas Gohr * @return bool 8496b13307fSandi */ 85072645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 8516b13307fSandi global $lang; 852c1e3b7d9Smatthiasgrimm global $ACT; 853ad4aaef7SAndreas Gohr global $QUERY; 854c1e3b7d9Smatthiasgrimm 855670ff54eSchris // don't print the search form if search action has been disabled 85664276bbcSarbrk1 if(!actionOK('search')) return false; 857670ff54eSchris 8589805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 8596b13307fSandi print '<input type="hidden" name="do" value="search" />'; 860c1e3b7d9Smatthiasgrimm print '<input type="text" '; 861ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 862001ea14eSRainbow Spike print 'placeholder="'.$lang['btn_search'].'" '; 86372645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 86407493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 865ae614416SAnika Henke print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>'; 86624a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 8674beabca9SAnika Henke print '</div></form>'; 86854e95700STom N Harris return true; 8696b13307fSandi} 8706b13307fSandi 8716b13307fSandi/** 8726b13307fSandi * Print the breadcrumbs trace 8736b13307fSandi * 8746b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 87542ea7f44SGerrit Uitslag * 876ac7a515fSAndreas Gohr * @param string $sep Separator between entries 877ac7a515fSAndreas Gohr * @return bool 8786b13307fSandi */ 879e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 8806b13307fSandi global $lang; 8816b13307fSandi global $conf; 8826b13307fSandi 8836b13307fSandi //check if enabled 884359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 8856b13307fSandi 8866b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 887265e3787Sandi 8882979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 889265e3787Sandi 89040eb54bbSjan //render crumbs, highlight the last one 891fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 89240eb54bbSjan $last = count($crumbs); 89340eb54bbSjan $i = 0; 894a77f5846Sjan foreach($crumbs as $id => $name) { 89540eb54bbSjan $i++; 8962979a10bSKatriel Traum echo $crumbs_sep; 89792795d04Sandi if($i == $last) print '<span class="curid">'; 898d317fb5dSAnika Henke print '<bdi>'; 899e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 900d317fb5dSAnika Henke print '</bdi>'; 90192795d04Sandi if($i == $last) print '</span>'; 9026b13307fSandi } 90354e95700STom N Harris return true; 9046b13307fSandi} 9056b13307fSandi 9066b13307fSandi/** 9071734437eSandi * Hierarchical breadcrumbs 9081734437eSandi * 90931e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 9101734437eSandi * It only makes sense with a deep site structure. 9111734437eSandi * 9121734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 9136bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 91431e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 915f46c9e83SAnika Henke * @author <fredrik@averpil.com> 91608d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 91742ea7f44SGerrit Uitslag * 918ac7a515fSAndreas Gohr * @param string $sep Separator between entries 919ac7a515fSAndreas Gohr * @return bool 9201734437eSandi */ 92108d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') { 9221734437eSandi global $conf; 9231734437eSandi global $ID; 9241734437eSandi global $lang; 9251734437eSandi 92631e187f8SSean Coates // check if enabled 92754e95700STom N Harris if(!$conf['youarehere']) return false; 9281734437eSandi 9291734437eSandi $parts = explode(':', $ID); 930796bafb3SAndreas Gohr $count = count($parts); 9311734437eSandi 93208d7a575SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 9333940c519SMark 93408d7a575SAndreas Gohr // always print the startpage 93508d7a575SAndreas Gohr echo '<span class="home">'; 93608d7a575SAndreas Gohr tpl_pagelink(':'.$conf['start']); 93708d7a575SAndreas Gohr echo '</span>'; 938796bafb3SAndreas Gohr 939796bafb3SAndreas Gohr // print intermediate namespace links 940796bafb3SAndreas Gohr $part = ''; 941796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 942796bafb3SAndreas Gohr $part .= $parts[$i].':'; 943796bafb3SAndreas Gohr $page = $part; 944796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 945796bafb3SAndreas Gohr 94608d7a575SAndreas Gohr // output 94708d7a575SAndreas Gohr echo $sep; 94808d7a575SAndreas Gohr tpl_pagelink($page); 94931e187f8SSean Coates } 9501734437eSandi 951796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 952e013f48dSAnika Henke resolve_pageid('', $page, $exists); 95308d7a575SAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 954796bafb3SAndreas Gohr $page = $part.$parts[$i]; 95508d7a575SAndreas Gohr if($page == $conf['start']) return true; 95608d7a575SAndreas Gohr echo $sep; 95708d7a575SAndreas Gohr tpl_pagelink($page); 95854e95700STom N Harris return true; 9591734437eSandi} 9601734437eSandi 9611734437eSandi/** 9626b13307fSandi * Print info if the user is logged in 963a2488c3cSMatthias Grimm * and show full name in that case 9646b13307fSandi * 9656b13307fSandi * Could be enhanced with a profile link in future? 9666b13307fSandi * 9676b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 96842ea7f44SGerrit Uitslag * 969ac7a515fSAndreas Gohr * @return bool 9706b13307fSandi */ 9716b13307fSandifunction tpl_userinfo() { 9726b13307fSandi global $lang; 973585bf44eSChristopher Smith /** @var Input $INPUT */ 974585bf44eSChristopher Smith global $INPUT; 975585bf44eSChristopher Smith 976585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 977fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 97854e95700STom N Harris return true; 97954e95700STom N Harris } 98054e95700STom N Harris return false; 9816b13307fSandi} 9826b13307fSandi 9836b13307fSandi/** 9846b13307fSandi * Print some info about the current page 9856b13307fSandi * 9866b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 98742ea7f44SGerrit Uitslag * 988ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 989ac7a515fSAndreas Gohr * @return bool|string 9906b13307fSandi */ 9914b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 9926b13307fSandi global $conf; 9936b13307fSandi global $lang; 9946b13307fSandi global $INFO; 995c6e92a3cSDavid Lorentsen global $ID; 996c6e92a3cSDavid Lorentsen 997c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 998ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 999ac7a515fSAndreas Gohr return false; 1000ac7a515fSAndreas Gohr } 10016b13307fSandi 10026b13307fSandi // prepare date and path 10036b13307fSandi $fn = $INFO['filepath']; 10046b13307fSandi if(!$conf['fullpath']) { 1005613bca54SAndreas Gohr if($INFO['rev']) { 100650fbebceSGina Haeussge $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 10076b13307fSandi } else { 100850fbebceSGina Haeussge $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 10096b13307fSandi } 10106b13307fSandi } 1011bee6dc82Sandi $fn = utf8_decodeFN($fn); 1012f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 10136b13307fSandi 1014faecdfdfSAndreas Gohr // print it 1015faecdfdfSAndreas Gohr if($INFO['exists']) { 10164b0d3916SAndreas Gohr $out = ''; 1017d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 1018e260f93bSAnika Henke $out .= ' · '; 10194b0d3916SAndreas Gohr $out .= $lang['lastmod']; 1020fde860beSGerrit Uitslag $out .= ' '; 10214b0d3916SAndreas Gohr $out .= $date; 10226b13307fSandi if($INFO['editor']) { 10234b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 1024d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 10255aa52fafSBen Coburn } else { 10264b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 10276b13307fSandi } 10286b13307fSandi if($INFO['locked']) { 1029e260f93bSAnika Henke $out .= ' · '; 10304b0d3916SAndreas Gohr $out .= $lang['lockedby']; 1031fde860beSGerrit Uitslag $out .= ' '; 1032d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 10336b13307fSandi } 10344b0d3916SAndreas Gohr if($ret) { 10354b0d3916SAndreas Gohr return $out; 10364b0d3916SAndreas Gohr } else { 10374b0d3916SAndreas Gohr echo $out; 103854e95700STom N Harris return true; 10396b13307fSandi } 10404b0d3916SAndreas Gohr } 104154e95700STom N Harris return false; 10426b13307fSandi} 10436b13307fSandi 1044820fa24bSandi/** 1045a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 104687c434ceSAndreas Gohr * 104787c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 1048a6598f23SBen Coburn * the given ID is used. 104987c434ceSAndreas Gohr * 105087c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 105142ea7f44SGerrit Uitslag * 1052ac7a515fSAndreas Gohr * @param string $id page id 1053ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 1054ac7a515fSAndreas Gohr * @return bool|string 105587c434ceSAndreas Gohr */ 1056a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 1057c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 1058fffeeafeSChristopher Smith 105987c434ceSAndreas Gohr if(is_null($id)) { 106087c434ceSAndreas Gohr global $ID; 106187c434ceSAndreas Gohr $id = $ID; 106287c434ceSAndreas Gohr } 106387c434ceSAndreas Gohr 106487c434ceSAndreas Gohr $name = $id; 1065fe9ec250SChris Smith if(useHeading('navigation')) { 1066fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 1067fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 1068fffeeafeSChristopher Smith } 1069fffeeafeSChristopher Smith 1070fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 1071fffeeafeSChristopher Smith switch ($ACT) { 1072fffeeafeSChristopher Smith // admin functions 1073fffeeafeSChristopher Smith case 'admin' : 1074fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 1075fffeeafeSChristopher Smith // try to get the plugin name 1076a61966c5SChristopher Smith /** @var $plugin DokuWiki_Admin_Plugin */ 1077a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 1078c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 1079a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 1080fffeeafeSChristopher Smith } 1081fffeeafeSChristopher Smith break; 1082fffeeafeSChristopher Smith 1083fffeeafeSChristopher Smith // user functions 1084fffeeafeSChristopher Smith case 'login' : 1085fffeeafeSChristopher Smith case 'profile' : 1086fffeeafeSChristopher Smith case 'register' : 1087fffeeafeSChristopher Smith case 'resendpwd' : 1088fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1089fffeeafeSChristopher Smith break; 1090fffeeafeSChristopher Smith 1091fffeeafeSChristopher Smith // wiki functions 1092fffeeafeSChristopher Smith case 'search' : 1093fffeeafeSChristopher Smith case 'index' : 1094fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1095fffeeafeSChristopher Smith break; 1096fffeeafeSChristopher Smith 1097fffeeafeSChristopher Smith // page functions 1098fffeeafeSChristopher Smith case 'edit' : 1099fffeeafeSChristopher Smith $page_title = "✎ ".$name; 1100fffeeafeSChristopher Smith break; 1101fffeeafeSChristopher Smith 1102fffeeafeSChristopher Smith case 'revisions' : 1103fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 1104fffeeafeSChristopher Smith break; 1105fffeeafeSChristopher Smith 1106fffeeafeSChristopher Smith case 'backlink' : 1107fffeeafeSChristopher Smith case 'recent' : 1108fffeeafeSChristopher Smith case 'subscribe' : 1109fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 1110fffeeafeSChristopher Smith break; 1111fffeeafeSChristopher Smith 1112fffeeafeSChristopher Smith default : // SHOW and anything else not included 1113fffeeafeSChristopher Smith $page_title = $name; 111487c434ceSAndreas Gohr } 1115a6598f23SBen Coburn 1116a6598f23SBen Coburn if($ret) { 1117fffeeafeSChristopher Smith return hsc($page_title); 1118a6598f23SBen Coburn } else { 1119fffeeafeSChristopher Smith print hsc($page_title); 112054e95700STom N Harris return true; 112187c434ceSAndreas Gohr } 1122a6598f23SBen Coburn} 1123340756e4Sandi 112455efc227SAndreas Gohr/** 112555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 112655efc227SAndreas Gohr * 112755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 112855efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 112955efc227SAndreas Gohr * 113055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 113155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 113255efc227SAndreas Gohr * to the names of the latter one) 113355efc227SAndreas Gohr * 11343df72098SAndreas Gohr * Only allowed in: detail.php 113555efc227SAndreas Gohr * 113655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 113742ea7f44SGerrit Uitslag * 113821d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1139ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1140e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1141ac7a515fSAndreas Gohr * @return string 114255efc227SAndreas Gohr */ 11433df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 114455efc227SAndreas Gohr // Init Exif Reader 114555efc227SAndreas Gohr global $SRC; 11463df72098SAndreas Gohr 11473df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 11483df72098SAndreas Gohr 114955efc227SAndreas Gohr static $meta = null; 11503df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 115155efc227SAndreas Gohr if($meta === false) return $alt; 115288945224SChristopher Smith $info = cleanText($meta->getField($tags)); 115355efc227SAndreas Gohr if($info == false) return $alt; 115455efc227SAndreas Gohr return $info; 115555efc227SAndreas Gohr} 115655efc227SAndreas Gohr 115755efc227SAndreas Gohr/** 1158becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1159becfa414SGerrit Uitslag * 1160becfa414SGerrit Uitslag * @return string html of description list 1161becfa414SGerrit Uitslag */ 1162becfa414SGerrit Uitslagfunction tpl_img_meta() { 1163becfa414SGerrit Uitslag global $lang; 1164becfa414SGerrit Uitslag 1165becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1166becfa414SGerrit Uitslag 1167becfa414SGerrit Uitslag echo '<dl>'; 1168becfa414SGerrit Uitslag foreach($tags as $tag) { 1169becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1170fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1171becfa414SGerrit Uitslag 1172fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1173becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1174becfa414SGerrit Uitslag echo dformat($tag['value']); 1175becfa414SGerrit Uitslag } else { 1176becfa414SGerrit Uitslag echo hsc($tag['value']); 1177becfa414SGerrit Uitslag } 1178becfa414SGerrit Uitslag echo '</dd>'; 1179becfa414SGerrit Uitslag } 1180becfa414SGerrit Uitslag echo '</dl>'; 1181becfa414SGerrit Uitslag} 1182becfa414SGerrit Uitslag 1183becfa414SGerrit Uitslag/** 1184becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1185becfa414SGerrit Uitslag * 1186becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1187becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1188becfa414SGerrit Uitslag * - string type type of value 1189becfa414SGerrit Uitslag * - string value tag value (unescaped) 1190becfa414SGerrit Uitslag */ 1191becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1192becfa414SGerrit Uitslag 1193becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1194becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 119579e79377SAndreas Gohr if(file_exists($config_file)) { 1196becfa414SGerrit Uitslag include($config_file); 1197becfa414SGerrit Uitslag } 1198becfa414SGerrit Uitslag } 1199becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1200becfa414SGerrit Uitslag 1201becfa414SGerrit Uitslag $tags = array(); 1202becfa414SGerrit Uitslag foreach($fields as $tag){ 1203becfa414SGerrit Uitslag $t = array(); 1204becfa414SGerrit Uitslag if (!empty($tag[0])) { 1205becfa414SGerrit Uitslag $t = array($tag[0]); 1206becfa414SGerrit Uitslag } 1207becfa414SGerrit Uitslag if(is_array($tag[3])) { 1208becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1209becfa414SGerrit Uitslag } 1210becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1211becfa414SGerrit Uitslag if ($value) { 1212becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1213becfa414SGerrit Uitslag } 1214becfa414SGerrit Uitslag } 1215becfa414SGerrit Uitslag return $tags; 1216becfa414SGerrit Uitslag} 1217becfa414SGerrit Uitslag 1218becfa414SGerrit Uitslag/** 121955efc227SAndreas Gohr * Prints the image with a link to the full sized version 122055efc227SAndreas Gohr * 122155efc227SAndreas Gohr * Only allowed in: detail.php 1222a02d2933SAndreas Gohr * 1223ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1224a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1225a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1226a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1227a02d2933SAndreas Gohr * @param $params array - additional image attributes 122842ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 122955efc227SAndreas Gohr */ 1230a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 123155efc227SAndreas Gohr global $IMG; 1232585bf44eSChristopher Smith /** @var Input $INPUT */ 1233ac7a515fSAndreas Gohr global $INPUT; 12345c2eed9aSlisps global $REV; 123565d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 123665d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 123755efc227SAndreas Gohr 123855efc227SAndreas Gohr //resize to given max values 123923a34783SAndreas Gohr $ratio = 1; 124023a34783SAndreas Gohr if($w >= $h) { 1241f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 124255efc227SAndreas Gohr $ratio = $maxwidth / $w; 1243f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 124455efc227SAndreas Gohr $ratio = $maxheight / $h; 124555efc227SAndreas Gohr } 124655efc227SAndreas Gohr } else { 1247f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 124855efc227SAndreas Gohr $ratio = $maxheight / $h; 1249f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 125055efc227SAndreas Gohr $ratio = $maxwidth / $w; 125155efc227SAndreas Gohr } 125255efc227SAndreas Gohr } 125355efc227SAndreas Gohr if($ratio) { 125455efc227SAndreas Gohr $w = floor($ratio * $w); 125555efc227SAndreas Gohr $h = floor($ratio * $h); 125655efc227SAndreas Gohr } 125755efc227SAndreas Gohr 12586de3759aSAndreas Gohr //prepare URLs 12595c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 12605c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 126155efc227SAndreas Gohr 12622684e50aSAndreas Gohr //prepare attributes 126355efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1264a02d2933SAndreas Gohr if(is_null($params)) { 12652684e50aSAndreas Gohr $p = array(); 1266a02d2933SAndreas Gohr } else { 1267a02d2933SAndreas Gohr $p = $params; 1268a02d2933SAndreas Gohr } 12692684e50aSAndreas Gohr if($w) $p['width'] = $w; 12702684e50aSAndreas Gohr if($h) $p['height'] = $h; 12712684e50aSAndreas Gohr $p['class'] = 'img_detail'; 12722684e50aSAndreas Gohr if($alt) { 12732684e50aSAndreas Gohr $p['alt'] = $alt; 12742684e50aSAndreas Gohr $p['title'] = $alt; 12752684e50aSAndreas Gohr } else { 12762684e50aSAndreas Gohr $p['alt'] = ''; 12772684e50aSAndreas Gohr } 1278a02d2933SAndreas Gohr $p['src'] = $src; 127955efc227SAndreas Gohr 1280a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1281a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1282a02d2933SAndreas Gohr} 1283a02d2933SAndreas Gohr 1284a02d2933SAndreas Gohr/** 1285a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1286ac7a515fSAndreas Gohr * 1287ac7a515fSAndreas Gohr * @param array $data 1288ac7a515fSAndreas Gohr * @return bool 1289a02d2933SAndreas Gohr */ 1290ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 129159f3611bSAnika Henke global $lang; 1292a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1293a02d2933SAndreas Gohr 129459f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1295a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1296a02d2933SAndreas Gohr if($data['url']) print '</a>'; 129754e95700STom N Harris return true; 129855efc227SAndreas Gohr} 129955efc227SAndreas Gohr 13007367b368SAndreas Gohr/** 1301881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 13027367b368SAndreas Gohr * 13037367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 13047367b368SAndreas Gohr * template 1305ac7a515fSAndreas Gohr * 1306ac7a515fSAndreas Gohr * @return bool 13077367b368SAndreas Gohr */ 13087367b368SAndreas Gohrfunction tpl_indexerWebBug() { 13097367b368SAndreas Gohr global $ID; 13101dad36f5SAndreas Gohr 13117367b368SAndreas Gohr $p = array(); 1312b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1313e68c51baSAndreas Gohr '&'.time(); 1314881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 13157367b368SAndreas Gohr $p['height'] = 1; 13167367b368SAndreas Gohr $p['alt'] = ''; 13177367b368SAndreas Gohr $att = buildAttributes($p); 13187367b368SAndreas Gohr print "<img $att />"; 131954e95700STom N Harris return true; 13207367b368SAndreas Gohr} 13217367b368SAndreas Gohr 132278d4e784SEsther Brunner/** 132378d4e784SEsther Brunner * tpl_getConf($id) 132478d4e784SEsther Brunner * 132578d4e784SEsther Brunner * use this function to access template configuration variables 1326ac7a515fSAndreas Gohr * 132717448fb8SChristopher Smith * @param string $id name of the value to access 132817448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 132917448fb8SChristopher Smith * @return mixed 133078d4e784SEsther Brunner */ 133117448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 133278d4e784SEsther Brunner global $conf; 133317566ac6SAdrian Lang static $tpl_configloaded = false; 133478d4e784SEsther Brunner 133578d4e784SEsther Brunner $tpl = $conf['template']; 133678d4e784SEsther Brunner 133778d4e784SEsther Brunner if(!$tpl_configloaded) { 133878d4e784SEsther Brunner $tconf = tpl_loadConfig(); 133978d4e784SEsther Brunner if($tconf !== false) { 134078d4e784SEsther Brunner foreach($tconf as $key => $value) { 134178d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 134278d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 134378d4e784SEsther Brunner } 134478d4e784SEsther Brunner $tpl_configloaded = true; 134578d4e784SEsther Brunner } 134678d4e784SEsther Brunner } 134778d4e784SEsther Brunner 134817448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 134978d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 135078d4e784SEsther Brunner } 135178d4e784SEsther Brunner 135217448fb8SChristopher Smith return $notset; 135317448fb8SChristopher Smith} 135417448fb8SChristopher Smith 135578d4e784SEsther Brunner/** 135678d4e784SEsther Brunner * tpl_loadConfig() 1357ac7a515fSAndreas Gohr * 135878d4e784SEsther Brunner * reads all template configuration variables 135978d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1360ac7a515fSAndreas Gohr * 1361ac7a515fSAndreas Gohr * @return array 136278d4e784SEsther Brunner */ 136378d4e784SEsther Brunnerfunction tpl_loadConfig() { 136478d4e784SEsther Brunner 1365c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 136678d4e784SEsther Brunner $conf = array(); 136778d4e784SEsther Brunner 136879e79377SAndreas Gohr if(!file_exists($file)) return false; 136978d4e784SEsther Brunner 137078d4e784SEsther Brunner // load default config file 137178d4e784SEsther Brunner include($file); 137278d4e784SEsther Brunner 137378d4e784SEsther Brunner return $conf; 137478d4e784SEsther Brunner} 137578d4e784SEsther Brunner 137617566ac6SAdrian Lang// language methods 137717566ac6SAdrian Lang/** 137817566ac6SAdrian Lang * tpl_getLang($id) 137917566ac6SAdrian Lang * 138017566ac6SAdrian Lang * use this function to access template language variables 138142ea7f44SGerrit Uitslag * 138242ea7f44SGerrit Uitslag * @param string $id key of language string 138342ea7f44SGerrit Uitslag * @return string 138417566ac6SAdrian Lang */ 138517566ac6SAdrian Langfunction tpl_getLang($id) { 138617566ac6SAdrian Lang static $lang = array(); 138717566ac6SAdrian Lang 138817566ac6SAdrian Lang if(count($lang) === 0) { 1389dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1390dd7a6159SGerrit Uitslag 1391c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 139217566ac6SAdrian Lang 139317566ac6SAdrian Lang $lang = array(); 139417566ac6SAdrian Lang 139517566ac6SAdrian Lang // don't include once 139617566ac6SAdrian Lang @include($path . 'en/lang.php'); 1397dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 139879e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1399dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1400dd7a6159SGerrit Uitslag } 140117566ac6SAdrian Lang } 140217566ac6SAdrian Lang 1403dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1404dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1405dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 140679e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1407dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1408dd7a6159SGerrit Uitslag } 1409dd7a6159SGerrit Uitslag } 1410dd7a6159SGerrit Uitslag } 141117566ac6SAdrian Lang } 141217566ac6SAdrian Lang return $lang[$id]; 141317566ac6SAdrian Lang} 141417566ac6SAdrian Lang 14153df72098SAndreas Gohr/** 1416c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1417e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1418e8ec13b9SKlap-in * 1419e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1420e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1421e8ec13b9SKlap-in */ 1422e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1423c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1424e8ec13b9SKlap-in} 1425e8ec13b9SKlap-in 1426e8ec13b9SKlap-in/** 1427c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 142842ea7f44SGerrit Uitslag * 142942ea7f44SGerrit Uitslag * @param string $id id of localized text 143042ea7f44SGerrit Uitslag * @return string wiki text 1431e8ec13b9SKlap-in */ 1432c5c17fdaSKlap-infunction tpl_localeFN($id) { 1433e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1434e8ec13b9SKlap-in global $conf; 143538fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 143679e79377SAndreas Gohr if (!file_exists($file)){ 1437e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 143879e79377SAndreas Gohr if(!file_exists($file)){ 1439e8ec13b9SKlap-in //fall back to english 1440e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1441e8ec13b9SKlap-in } 1442e8ec13b9SKlap-in } 1443e8ec13b9SKlap-in return $file; 1444e8ec13b9SKlap-in} 1445e8ec13b9SKlap-in 1446e8ec13b9SKlap-in/** 14477abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 14483df72098SAndreas Gohr * 14493df72098SAndreas Gohr * Depending on the user's actions this may be a list of 14503df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 14513df72098SAndreas Gohr * a message of referencing pages 14523df72098SAndreas Gohr * 14533df72098SAndreas Gohr * Only allowed in mediamanager.php 14543df72098SAndreas Gohr * 1455c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1456c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 145742ea7f44SGerrit Uitslag * @param string $sort 14588702de7fSGerrit Uitslag * 14593df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14603df72098SAndreas Gohr */ 146100e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 14623df72098SAndreas Gohr global $IMG; 14633df72098SAndreas Gohr global $AUTH; 14643df72098SAndreas Gohr global $INUSE; 14653df72098SAndreas Gohr global $NS; 14663df72098SAndreas Gohr global $JUMPTO; 1467585bf44eSChristopher Smith /** @var Input $INPUT */ 1468ac7a515fSAndreas Gohr global $INPUT; 14693df72098SAndreas Gohr 1470ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1471c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1472c182313eSAndreas Gohr 1473c182313eSAndreas Gohr if(!$do) { 1474ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1475c182313eSAndreas Gohr $do = 'metaform'; 1476c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1477c182313eSAndreas Gohr $do = 'filesinuse'; 1478c182313eSAndreas Gohr } else { 1479c182313eSAndreas Gohr $do = 'filelist'; 1480c182313eSAndreas Gohr } 1481c182313eSAndreas Gohr } 1482c182313eSAndreas Gohr 1483c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1484c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1485c182313eSAndreas Gohr $data = array('do' => $do); 1486c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1487c182313eSAndreas Gohr if($evt->advise_before()) { 1488c182313eSAndreas Gohr $do = $data['do']; 148930fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1490c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1491c182313eSAndreas Gohr } elseif($do == 'filelist') { 149200e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1493c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1494ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1495c182313eSAndreas Gohr } else { 1496c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1497c182313eSAndreas Gohr } 1498c182313eSAndreas Gohr } 1499c182313eSAndreas Gohr $evt->advise_after(); 1500c182313eSAndreas Gohr unset($evt); 1501c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1502c182313eSAndreas Gohr 15033df72098SAndreas Gohr} 15043df72098SAndreas Gohr 15053df72098SAndreas Gohr/** 1506d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1507d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1508d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1509d9162c6cSKate Arzamastseva * 1510d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1511d9162c6cSKate Arzamastseva */ 1512035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1513d9162c6cSKate Arzamastseva global $AUTH; 1514d9162c6cSKate Arzamastseva global $NS; 1515d9162c6cSKate Arzamastseva global $JUMPTO; 151695b451bcSAdrian Lang global $lang; 1517585bf44eSChristopher Smith /** @var Input $INPUT */ 1518ac7a515fSAndreas Gohr global $INPUT; 1519d9162c6cSKate Arzamastseva 1520ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1521e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1522ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1523d9162c6cSKate Arzamastseva 152494add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 152595b451bcSAdrian Lang 1526ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 152723846a98SKate Arzamastseva 152894add303SAnika Henke echo '<div class="panelHeader">'.NL; 152995b451bcSAdrian Lang echo '<h3>'; 1530026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1531c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 153294add303SAnika Henke echo '</h3>'.NL; 153395b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 153495b451bcSAdrian Lang media_tab_files_options(); 153523846a98SKate Arzamastseva } 153694add303SAnika Henke echo '</div>'.NL; 1537d9162c6cSKate Arzamastseva 153894add303SAnika Henke echo '<div class="panelContent">'.NL; 153995b451bcSAdrian Lang if($opened_tab == 'files') { 154095b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 154195b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 154295b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 154395b451bcSAdrian Lang } elseif($opened_tab == 'search') { 154495b451bcSAdrian Lang media_tab_search($NS, $AUTH); 154595b451bcSAdrian Lang } 154694add303SAnika Henke echo '</div>'.NL; 1547d9162c6cSKate Arzamastseva} 1548d9162c6cSKate Arzamastseva 1549d9162c6cSKate Arzamastseva/** 1550d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1551d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1552d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1553d9162c6cSKate Arzamastseva * list of file revisions 1554d9162c6cSKate Arzamastseva * 1555d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1556d9162c6cSKate Arzamastseva */ 1557035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1558e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1559585bf44eSChristopher Smith /** @var Input $INPUT */ 1560585bf44eSChristopher Smith global $INPUT; 1561d9162c6cSKate Arzamastseva 156292cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1563ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 15646dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1565e8a2a143SMichael Hamann $ns = getNS($image); 1566ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 15671eeeced2SKate Arzamastseva 1568ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1569e5d185e1SKate Arzamastseva 1570e5d185e1SKate Arzamastseva $tab_array = array('view'); 1571ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1572e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1573e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1574e5d185e1SKate Arzamastseva } 1575e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1576e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1577e5d185e1SKate Arzamastseva } 1578e5d185e1SKate Arzamastseva 1579e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1580ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 158123846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1582d9162c6cSKate Arzamastseva 1583ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 158423846a98SKate Arzamastseva 158559f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1586ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 158795b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 158895b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 158900c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 159008317413SAdrian Lang if($opened_tab === 'view' && $rev) { 159108317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 159208317413SAdrian Lang } else { 1593026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 159408317413SAdrian Lang } 1595b8a84c03SAndreas Gohr 159694add303SAnika Henke echo '</h3></div>'.NL; 159795b451bcSAdrian Lang 159894add303SAnika Henke echo '<div class="panelContent">'.NL; 159995b451bcSAdrian Lang 160023846a98SKate Arzamastseva if($opened_tab == 'view') { 1601e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 160223846a98SKate Arzamastseva 160392cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1604e8a2a143SMichael Hamann media_tab_edit($image, $ns); 160523846a98SKate Arzamastseva 1606e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1607e8a2a143SMichael Hamann media_tab_history($image, $ns); 160823846a98SKate Arzamastseva } 160995b451bcSAdrian Lang 161094add303SAnika Henke echo '</div>'.NL; 1611d9162c6cSKate Arzamastseva} 1612d9162c6cSKate Arzamastseva 1613d9162c6cSKate Arzamastseva/** 16147abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 16153df72098SAndreas Gohr * 16163df72098SAndreas Gohr * Only allowed in mediamanager.php 16173df72098SAndreas Gohr * 16183df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 16193df72098SAndreas Gohr */ 1620fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 16213df72098SAndreas Gohr global $NS; 162223846a98SKate Arzamastseva ptln('<div id="media__tree">'); 16233df72098SAndreas Gohr media_nstree($NS); 16243df72098SAndreas Gohr ptln('</div>'); 16253df72098SAndreas Gohr} 16263df72098SAndreas Gohr 1627a00de5b5SAndreas Gohr/** 1628a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1629a00de5b5SAndreas Gohr * 1630a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1631a00de5b5SAndreas Gohr * 1632a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 163342ea7f44SGerrit Uitslag * 163442ea7f44SGerrit Uitslag * @param string $empty empty option label 163542ea7f44SGerrit Uitslag * @param string $button submit button label 1636a00de5b5SAndreas Gohr */ 1637a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1638a00de5b5SAndreas Gohr global $ID; 1639a00de5b5SAndreas Gohr global $REV; 1640a00de5b5SAndreas Gohr global $lang; 1641585bf44eSChristopher Smith /** @var Input $INPUT */ 1642585bf44eSChristopher Smith global $INPUT; 1643a00de5b5SAndreas Gohr 1644768d1852SAnika Henke $action_structure = array( 1645768d1852SAnika Henke 'page_tools' => array('edit', 'revert', 'revisions', 'backlink', 'subscribe'), 1646768d1852SAnika Henke 'site_tools' => array('recent', 'media', 'index'), 1647768d1852SAnika Henke 'user_tools' => array('login', 'register', 'profile', 'admin'), 1648768d1852SAnika Henke ); 1649768d1852SAnika Henke 1650e63eccffSAndreas Gohr echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 16513b9a3b55SAnika Henke echo '<div class="no">'; 1652a00de5b5SAndreas Gohr echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1653a00de5b5SAndreas Gohr if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1654585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 1655a00de5b5SAndreas Gohr echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 165661efcda1SChristopher Smith } 1657a00de5b5SAndreas Gohr 16585f17c394SAnika Henke echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1659a00de5b5SAndreas Gohr echo '<option value="">'.$empty.'</option>'; 1660a00de5b5SAndreas Gohr 1661768d1852SAnika Henke foreach($action_structure as $tools => $actions) { 1662768d1852SAnika Henke echo '<optgroup label="'.$lang[$tools].'">'; 1663768d1852SAnika Henke foreach($actions as $action) { 1664768d1852SAnika Henke $act = tpl_get_action($action); 1665396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1666768d1852SAnika Henke } 1667a00de5b5SAndreas Gohr echo '</optgroup>'; 1668768d1852SAnika Henke } 1669a00de5b5SAndreas Gohr 1670a00de5b5SAndreas Gohr echo '</select>'; 1671ae614416SAnika Henke echo '<button type="submit">'.$button.'</button>'; 16723b9a3b55SAnika Henke echo '</div>'; 1673a00de5b5SAndreas Gohr echo '</form>'; 1674a00de5b5SAndreas Gohr} 1675a00de5b5SAndreas Gohr 1676066fee30SAndreas Gohr/** 1677066fee30SAndreas Gohr * Print a informational line about the used license 1678066fee30SAndreas Gohr * 1679066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1680ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1681ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1682ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1683ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1684ac7a515fSAndreas Gohr * @return string 1685066fee30SAndreas Gohr */ 168680083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1687066fee30SAndreas Gohr global $license; 1688066fee30SAndreas Gohr global $conf; 1689066fee30SAndreas Gohr global $lang; 1690066fee30SAndreas Gohr if(!$conf['license']) return ''; 1691066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1692066fee30SAndreas Gohr $lic = $license[$conf['license']]; 169353e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1694066fee30SAndreas Gohr 169580083a41SAndreas Gohr $out = ''; 169680083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1697066fee30SAndreas Gohr if($img) { 1698066fee30SAndreas Gohr $src = license_img($img); 1699066fee30SAndreas Gohr if($src) { 170053e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 170153e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 170253e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1703066fee30SAndreas Gohr } 1704066fee30SAndreas Gohr } 17054cefd216SMichael Klier if(!$imgonly) { 170653e15c8bSAnika Henke $out .= $lang['license'].' '; 1707d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1708d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 17094cefd216SMichael Klier } 171080083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1711066fee30SAndreas Gohr 1712066fee30SAndreas Gohr if($return) return $out; 1713066fee30SAndreas Gohr echo $out; 1714ac7a515fSAndreas Gohr return ''; 1715066fee30SAndreas Gohr} 1716066fee30SAndreas Gohr 1717a81910eeSAndreas Gohr/** 1718835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1719a81910eeSAndreas Gohr * 1720a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1721a81910eeSAndreas Gohr * template 1722e0c26282SGerrit Uitslag * 17237a112df5SAndreas Gohr * @param string $pageid The page name you want to include 17247a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 17257a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 17267c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1727e0c26282SGerrit Uitslag * @return bool|null|string 1728a81910eeSAndreas Gohr */ 17297c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 17307a112df5SAndreas Gohr if($propagate) { 17317c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 17327c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 17337a112df5SAndreas Gohr return false; 17347a112df5SAndreas Gohr } 1735c786a1b6SAnika Henke if(!$pageid) return false; 1736835dfcaeSAnika Henke 1737c786a1b6SAnika Henke global $TOC; 17389a2e250aSAndreas Gohr $oldtoc = $TOC; 1739a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 17409a2e250aSAndreas Gohr $TOC = $oldtoc; 1741a81910eeSAndreas Gohr 1742a2e03c82SAndreas Gohr if($print) echo $html; 1743e66d3e6dSAndreas Gohr return $html; 1744e66d3e6dSAndreas Gohr} 1745e66d3e6dSAndreas Gohr 1746e66d3e6dSAndreas Gohr/** 17475b75cd1fSAdrian Lang * Display the subscribe form 17485b75cd1fSAdrian Lang * 17495b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 17505b75cd1fSAdrian Lang */ 17515b75cd1fSAdrian Langfunction tpl_subscribe() { 17525b75cd1fSAdrian Lang global $INFO; 17535b75cd1fSAdrian Lang global $ID; 17545b75cd1fSAdrian Lang global $lang; 17556b8f02cfSAdrian Lang global $conf; 175640c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 17575b75cd1fSAdrian Lang 17585b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 17595b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 176015741132SAndreas Gohr echo '<div class="level2">'; 17615b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 17625b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 17635b75cd1fSAdrian Lang } else { 17645b75cd1fSAdrian Lang echo '<ul>'; 17655b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1766056c2049SAndreas Gohr echo '<li><div class="li">'; 17675b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1768056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17695b75cd1fSAdrian Lang } else { 1770056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17715b75cd1fSAdrian Lang } 177240c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 177315741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1774056c2049SAndreas Gohr echo ' ('.$sstl.') '; 177515741132SAndreas Gohr 1776ac7a515fSAndreas Gohr echo '<a href="'.wl( 1777ac7a515fSAndreas Gohr $ID, 1778ac7a515fSAndreas Gohr array( 1779ac7a515fSAndreas Gohr 'do' => 'subscribe', 178066d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 178166d2bed9SAdrian Lang 'sub_style' => $sub['style'], 178266d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1783ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1784ac7a515fSAndreas Gohr ) 1785ac7a515fSAndreas Gohr ). 178666d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 178766d2bed9SAdrian Lang '</a></div></li>'; 17885b75cd1fSAdrian Lang } 17895b75cd1fSAdrian Lang echo '</ul>'; 17905b75cd1fSAdrian Lang } 179115741132SAndreas Gohr echo '</div>'; 17925b75cd1fSAdrian Lang 179315741132SAndreas Gohr // Add new subscription form 17945b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 179515741132SAndreas Gohr echo '<div class="level2">'; 17965b75cd1fSAdrian Lang $ns = getNS($ID).':'; 179715741132SAndreas Gohr $targets = array( 179815741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 179915741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 180015741132SAndreas Gohr ); 180115741132SAndreas Gohr $styles = array( 180215741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 18036b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 18046b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 180515741132SAndreas Gohr ); 180615741132SAndreas Gohr 1807056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1808056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1809056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1810056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1811056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1812056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1813056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1814056c2049SAndreas Gohr $form->addHidden('id', $ID); 1815056c2049SAndreas Gohr $form->endFieldset(); 18165b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 18175b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 181815741132SAndreas Gohr echo '</div>'; 18195b75cd1fSAdrian Lang} 18205b75cd1fSAdrian Lang 1821d059ba9bSAndreas Gohr/** 1822d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1823d059ba9bSAndreas Gohr * 1824d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1825d059ba9bSAndreas Gohr * 1826d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1827d059ba9bSAndreas Gohr */ 1828d059ba9bSAndreas Gohrfunction tpl_flush() { 1829d059ba9bSAndreas Gohr ob_flush(); 1830d059ba9bSAndreas Gohr flush(); 1831d059ba9bSAndreas Gohr} 1832d059ba9bSAndreas Gohr 1833afca7e7eSAnika Henke/** 1834378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1835afca7e7eSAnika Henke * 1836378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1837378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1838378325f9SAndreas Gohr * 183942ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1840378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1841ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1842ac7a515fSAndreas Gohr * @return string 184342ea7f44SGerrit Uitslag * 1844378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1845afca7e7eSAnika Henke */ 1846378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1847ac7a515fSAndreas Gohr $img = ''; 1848ac7a515fSAndreas Gohr $file = ''; 1849ac7a515fSAndreas Gohr $ismedia = false; 1850378325f9SAndreas Gohr // loop through candidates until a match was found: 1851378325f9SAndreas Gohr foreach($search as $img) { 1852378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1853378325f9SAndreas Gohr $file = mediaFN($img); 1854378325f9SAndreas Gohr $ismedia = true; 1855378325f9SAndreas Gohr } else { 1856c4766956SAndreas Gohr $file = tpl_incdir().$img; 1857378325f9SAndreas Gohr $ismedia = false; 18581f13e33dSAnika Henke } 18590f747863Slupo49 1860378325f9SAndreas Gohr if(file_exists($file)) break; 1861872a6d29SAnika Henke } 1862378325f9SAndreas Gohr 1863378325f9SAndreas Gohr // fetch image data if requested 1864378325f9SAndreas Gohr if(!is_null($imginfo)) { 1865378325f9SAndreas Gohr $imginfo = getimagesize($file); 1866378325f9SAndreas Gohr } 1867378325f9SAndreas Gohr 1868378325f9SAndreas Gohr // build URL 1869378325f9SAndreas Gohr if($ismedia) { 1870378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1871378325f9SAndreas Gohr } else { 1872c4766956SAndreas Gohr $url = tpl_basedir().$img; 1873378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1874378325f9SAndreas Gohr } 1875378325f9SAndreas Gohr 1876378325f9SAndreas Gohr return $url; 1877a7e5f74cSlupo49} 18781f13e33dSAnika Henke 1879872a6d29SAnika Henke/** 1880e5d4768dSAndreas Gohr * PHP include a file 1881e5d4768dSAndreas Gohr * 1882e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1883e5d4768dSAndreas Gohr * file in the template's root directory. 1884e5d4768dSAndreas Gohr * 1885e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1886e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1887e5d4768dSAndreas Gohr * default. 1888e5d4768dSAndreas Gohr * 1889e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1890e5d4768dSAndreas Gohr * to this function! 1891e5d4768dSAndreas Gohr * 1892e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1893e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 189442ea7f44SGerrit Uitslag * 189542ea7f44SGerrit Uitslag * @param string $file 1896e5d4768dSAndreas Gohr */ 1897e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1898e5d4768dSAndreas Gohr global $config_cascade; 1899e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1900e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1901e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1902e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1903e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1904f3a1225fSAnika Henke include("$dir/$file"); 1905e5d4768dSAndreas Gohr return; 1906e5d4768dSAndreas Gohr } 1907e5d4768dSAndreas Gohr } 1908e5d4768dSAndreas Gohr } 1909e5d4768dSAndreas Gohr 1910e5d4768dSAndreas Gohr // still here? try the template dir 1911e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1912e5d4768dSAndreas Gohr if(file_exists($file)) { 1913f3a1225fSAnika Henke include($file); 1914e5d4768dSAndreas Gohr } 1915e5d4768dSAndreas Gohr} 1916e5d4768dSAndreas Gohr 1917e5d4768dSAndreas Gohr/** 1918872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1919872a6d29SAnika Henke * 1920872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 192142ea7f44SGerrit Uitslag * 1922ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1923ac7a515fSAndreas Gohr * @return string 1924872a6d29SAnika Henke */ 1925872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1926872a6d29SAnika Henke 1927872a6d29SAnika Henke $return = ''; 1928872a6d29SAnika Henke 1929872a6d29SAnika Henke foreach($types as $type) { 1930872a6d29SAnika Henke switch($type) { 1931872a6d29SAnika Henke case 'favicon': 1932378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1933378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1934872a6d29SAnika Henke break; 1935872a6d29SAnika Henke case 'mobile': 1936cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1937378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1938872a6d29SAnika Henke break; 1939872a6d29SAnika Henke case 'generic': 1940872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1941378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1942378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1943872a6d29SAnika Henke break; 1944872a6d29SAnika Henke } 1945872a6d29SAnika Henke } 1946872a6d29SAnika Henke 1947872a6d29SAnika Henke return $return; 1948afca7e7eSAnika Henke} 1949afca7e7eSAnika Henke 1950d9162c6cSKate Arzamastseva/** 1951d9162c6cSKate Arzamastseva * Prints full-screen media manager 1952d9162c6cSKate Arzamastseva * 1953d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1954d9162c6cSKate Arzamastseva */ 1955d9162c6cSKate Arzamastsevafunction tpl_media() { 1956ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 195788a71175SKate Arzamastseva $fullscreen = true; 195895b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1959d9162c6cSKate Arzamastseva 1960ac7a515fSAndreas Gohr $rev = ''; 1961ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 196298f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 196398f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 19649c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 196598f03b57SKate Arzamastseva 196694add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1967bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1968d9162c6cSKate Arzamastseva html_msgarea(); 196994add303SAnika Henke 197094add303SAnika Henke echo '<div class="panel namespaces">'.NL; 197194add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 197295b451bcSAdrian Lang echo '<div class="panelHeader">'; 1973ba340a70SAnika Henke echo $lang['media_namespaces']; 197494add303SAnika Henke echo '</div>'.NL; 197595b451bcSAdrian Lang 197694add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 197795b451bcSAdrian Lang media_nstree($NS); 197894add303SAnika Henke echo '</div>'.NL; 197994add303SAnika Henke echo '</div>'.NL; 1980fa8e5c77SKate Arzamastseva 198194add303SAnika Henke echo '<div class="panel filelist">'.NL; 1982035e07f1SKate Arzamastseva tpl_mediaFileList(); 198394add303SAnika Henke echo '</div>'.NL; 1984fa8e5c77SKate Arzamastseva 198594add303SAnika Henke echo '<div class="panel file">'.NL; 198694add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1987035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 198894add303SAnika Henke echo '</div>'.NL; 1989ba340a70SAnika Henke 199094add303SAnika Henke echo '</div>'.NL; 1991d9162c6cSKate Arzamastseva} 1992afca7e7eSAnika Henke 1993c71db656SAnika Henke/** 1994c71db656SAnika Henke * Return useful layout classes 1995c71db656SAnika Henke * 1996c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 199742ea7f44SGerrit Uitslag * 199842ea7f44SGerrit Uitslag * @return string 1999c71db656SAnika Henke */ 2000c71db656SAnika Henkefunction tpl_classes() { 2001c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 2002585bf44eSChristopher Smith /** @var Input $INPUT */ 2003585bf44eSChristopher Smith global $INPUT; 2004585bf44eSChristopher Smith 2005c71db656SAnika Henke $classes = array( 2006c71db656SAnika Henke 'dokuwiki', 2007c71db656SAnika Henke 'mode_'.$ACT, 2008c71db656SAnika Henke 'tpl_'.$conf['template'], 2009585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 201039f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 2011c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 2012c71db656SAnika Henke ); 2013c71db656SAnika Henke return join(' ', $classes); 2014c71db656SAnika Henke} 2015c71db656SAnika Henke 201684dd2b1aSGerrit Uitslag/** 201784dd2b1aSGerrit Uitslag * Create event for tools menues 201884dd2b1aSGerrit Uitslag * 201984dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 202084dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 202184dd2b1aSGerrit Uitslag * @param array $items 202284dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 202384dd2b1aSGerrit Uitslag */ 202484dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') { 202584dd2b1aSGerrit Uitslag $data = array( 202684dd2b1aSGerrit Uitslag 'view' => $view, 202784dd2b1aSGerrit Uitslag 'items' => $items 202884dd2b1aSGerrit Uitslag ); 202984dd2b1aSGerrit Uitslag 203084dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 203184dd2b1aSGerrit Uitslag $evt = new Doku_Event($hook, $data); 203284dd2b1aSGerrit Uitslag if($evt->advise_before()) { 203384dd2b1aSGerrit Uitslag foreach($evt->data['items'] as $k => $html) echo $html; 203484dd2b1aSGerrit Uitslag } 203584dd2b1aSGerrit Uitslag $evt->advise_after(); 203684dd2b1aSGerrit Uitslag} 203784dd2b1aSGerrit Uitslag 2038e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 2039a00de5b5SAndreas Gohr 2040