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 { 2650470c28fSAndreas Gohr $admin = new dokuwiki\Ui\Admin(); 2660470c28fSAndreas Gohr $admin->show(); 267f8cc712eSAndreas Gohr } 26854e95700STom N Harris return true; 269c19fe9c0Sandi} 2706b13307fSandi 2716b13307fSandi/** 2726b13307fSandi * Print the correct HTML meta headers 2736b13307fSandi * 2746b13307fSandi * This has to go into the head section of your template. 2756b13307fSandi * 2766b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 27742ea7f44SGerrit Uitslag * 278ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 279ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 280ac7a515fSAndreas Gohr * @return bool 2816b13307fSandi */ 282f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2836b13307fSandi global $ID; 284d98d4540SBen Coburn global $REV; 2856b13307fSandi global $INFO; 28672e0dc37SAndreas Gohr global $JSINFO; 2876b13307fSandi global $ACT; 2884bb1b5aeSAndreas Gohr global $QUERY; 2896b13307fSandi global $lang; 290dc57ef04Sandi global $conf; 2919c438d6cSMichael Hamann global $updateVersion; 292585bf44eSChristopher Smith /** @var Input $INPUT */ 293585bf44eSChristopher Smith global $INPUT; 2946b13307fSandi 2957bff22c0SAndreas Gohr // prepare the head array 2967bff22c0SAndreas Gohr $head = array(); 2977bff22c0SAndreas Gohr 298202ac28bSMichael Klier // prepare seed for js and css 299cd997f93SAndreas Gohr $tseed = $updateVersion; 300202ac28bSMichael Klier $depends = getConfigFiles('main'); 30184e76a7eSAndreas Gohr $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; 302cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 303cd997f93SAndreas Gohr $tseed = md5($tseed); 3047bff22c0SAndreas Gohr 3056b13307fSandi // the usual stuff 3063f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 30763cf4192Ssarehag if(actionOK('search')) { 308ac7a515fSAndreas Gohr $head['link'][] = array( 309ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 310ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 311ac7a515fSAndreas Gohr ); 31263cf4192Ssarehag } 31363cf4192Ssarehag 314f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 3157aedde2eSGina Haeussge if(actionOK('index')) { 316ac7a515fSAndreas Gohr $head['link'][] = array( 317ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 318ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 319ac7a515fSAndreas Gohr ); 3207aedde2eSGina Haeussge } 321f96fa415SAndreas Gohr 322f96fa415SAndreas Gohr if($alt) { 32354be1338SGerrit Uitslag if(actionOK('rss')) { 324ac7a515fSAndreas Gohr $head['link'][] = array( 325ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 326a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 327ac7a515fSAndreas Gohr ); 328ac7a515fSAndreas Gohr $head['link'][] = array( 329ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 330a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 331ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 332ac7a515fSAndreas Gohr ); 33354be1338SGerrit Uitslag } 334c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 335ac7a515fSAndreas Gohr $head['link'][] = array( 336ac7a515fSAndreas Gohr 'rel' => 'edit', 337715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 338ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 339ac7a515fSAndreas Gohr ); 340c35f3875SAndreas Gohr } 341c35f3875SAndreas Gohr 34254be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 343ac7a515fSAndreas Gohr $head['link'][] = array( 344ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 345a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 346ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 347ac7a515fSAndreas Gohr ); 3484bb1b5aeSAndreas Gohr } 349bae36d94SAndreas Gohr 350bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 351ac7a515fSAndreas Gohr $head['link'][] = array( 352a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 353ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 354ac7a515fSAndreas Gohr ); 355bae36d94SAndreas Gohr } 356bae36d94SAndreas Gohr 357bae36d94SAndreas Gohr if(actionOK('export_raw')) { 358ac7a515fSAndreas Gohr $head['link'][] = array( 359a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 360ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 361ac7a515fSAndreas Gohr ); 362f96fa415SAndreas Gohr } 363bae36d94SAndreas Gohr } 3646b13307fSandi 3656b13307fSandi // setup robot tags apropriate for different modes 3664f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3676b13307fSandi if($INFO['exists']) { 3686b13307fSandi //delay indexing: 3696b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 3707bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3716b13307fSandi } else { 3727bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3736b13307fSandi } 37401f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 37501f9be51SAnika Henke if ($ID == $conf['start']) { 37601f9be51SAnika Henke $canonicalUrl = DOKU_URL; 37701f9be51SAnika Henke } 37801f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3796b13307fSandi } else { 3807bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3816b13307fSandi } 3827a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3837bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3846b13307fSandi } else { 3857bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3866b13307fSandi } 3876b13307fSandi 388831800b8SAndreas Gohr // set metadata 389831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 390831800b8SAndreas Gohr // keywords (explicit or implicit) 391bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3927bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 393831800b8SAndreas Gohr } else { 3947bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 395831800b8SAndreas Gohr } 396831800b8SAndreas Gohr } 397831800b8SAndreas Gohr 39878a6aeb1SAndreas Gohr // load stylesheets 399ac7a515fSAndreas Gohr $head['link'][] = array( 400ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 401e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 402ac7a515fSAndreas Gohr ); 403bad31ae9SAndreas Gohr 4048bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 405463d4a65SAndreas Gohr $json = new JSON(); 40672e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 407585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 40872e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 409c591aabeSAndreas Gohr } 41072e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 41185f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 4128bbcb611SAndreas Gohr 41361537d47SAndreas Gohr // load jquery 414fa078663SAndreas Gohr $jquery = getCdnUrls(); 415fa078663SAndreas Gohr foreach($jquery as $src) { 41661537d47SAndreas Gohr $head['script'][] = array( 417fa078663SAndreas Gohr 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src 41861537d47SAndreas Gohr ); 41961537d47SAndreas Gohr } 42061537d47SAndreas Gohr 42161537d47SAndreas Gohr // load our javascript dispatcher 422ac7a515fSAndreas Gohr $head['script'][] = array( 423ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 424e283bd6cSAnika Henke 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 425ac7a515fSAndreas Gohr ); 4267bff22c0SAndreas Gohr 4277bff22c0SAndreas Gohr // trigger event here 428016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 42954e95700STom N Harris return true; 4307bff22c0SAndreas Gohr} 4317bff22c0SAndreas Gohr 4327bff22c0SAndreas Gohr/** 4337bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4347bff22c0SAndreas Gohr * 4357bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4367bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4377bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4387bff22c0SAndreas Gohr * 43942ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4401304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4417bff22c0SAndreas Gohr * 4427bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 44342ea7f44SGerrit Uitslag * 44442ea7f44SGerrit Uitslag * @param array $data 4457bff22c0SAndreas Gohr */ 4467bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4477bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 448427bf9a2SAndreas Gohr if($tag == 'script') { 449427bf9a2SAndreas Gohr echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE 450427bf9a2SAndreas Gohr } 4517bff22c0SAndreas Gohr foreach($inst as $attr) { 4529b48e6a1SGerry Weißbach if ( empty($attr) ) { continue; } 4537bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 45426afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 455e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 45609f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 457e226efe1SAndreas Gohr $attr['_data']. 45809f791c4SDominik Eckelmann "\n/*!]]>*/"; 459e226efe1SAndreas Gohr 4601304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4617bff22c0SAndreas Gohr } else { 4627bff22c0SAndreas Gohr echo '/>'; 4637bff22c0SAndreas Gohr } 4647bff22c0SAndreas Gohr echo "\n"; 4657bff22c0SAndreas Gohr } 466427bf9a2SAndreas Gohr if($tag == 'script') { 467427bf9a2SAndreas Gohr echo "<!--<![endif]-->\n"; 468427bf9a2SAndreas Gohr } 4697bff22c0SAndreas Gohr } 4706b13307fSandi} 4716b13307fSandi 4726b13307fSandi/** 4736b13307fSandi * Print a link 4746b13307fSandi * 4755e163278SAndreas Gohr * Just builds a link. 4766b13307fSandi * 4776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 47842ea7f44SGerrit Uitslag * 47942ea7f44SGerrit Uitslag * @param string $url 48042ea7f44SGerrit Uitslag * @param string $name 48142ea7f44SGerrit Uitslag * @param string $more 48221d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 48321d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4846b13307fSandi */ 4851af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 48601f17825SAnika Henke $out = '<a href="'.$url.'" '; 4871af98a77SAnika Henke if($more) $out .= ' '.$more; 4881af98a77SAnika Henke $out .= ">$name</a>"; 4891af98a77SAnika Henke if($return) return $out; 4901af98a77SAnika Henke print $out; 49154e95700STom N Harris return true; 4926b13307fSandi} 4936b13307fSandi 4946b13307fSandi/** 49555efc227SAndreas Gohr * Prints a link to a WikiPage 49655efc227SAndreas Gohr * 49755efc227SAndreas Gohr * Wrapper around html_wikilink 49855efc227SAndreas Gohr * 49955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 50042ea7f44SGerrit Uitslag * 50142ea7f44SGerrit Uitslag * @param string $id page id 50242ea7f44SGerrit Uitslag * @param string|null $name the name of the link 50321d806cdSGerrit Uitslag * @return bool true 50455efc227SAndreas Gohr */ 5050b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 506d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 50754e95700STom N Harris return true; 50855efc227SAndreas Gohr} 50955efc227SAndreas Gohr 51055efc227SAndreas Gohr/** 511a3ec5f4aSmatthiasgrimm * get the parent page 512a3ec5f4aSmatthiasgrimm * 513a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 514a3ec5f4aSmatthiasgrimm * returns false if none is available 515a3ec5f4aSmatthiasgrimm * 516377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 51742ea7f44SGerrit Uitslag * 51842ea7f44SGerrit Uitslag * @param string $id page id 51942ea7f44SGerrit Uitslag * @return false|string 520a3ec5f4aSmatthiasgrimm */ 521377f9e97SAndreas Gohrfunction tpl_getparent($id) { 522377f9e97SAndreas Gohr $parent = getNS($id).':'; 523377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 524a197105eSmatthiasgrimm if($parent == $id) { 525a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 526a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 527a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 528377f9e97SAndreas Gohr if($parent == $id) return false; 529a197105eSmatthiasgrimm } 530377f9e97SAndreas Gohr return $parent; 531a3ec5f4aSmatthiasgrimm} 532a3ec5f4aSmatthiasgrimm 533a3ec5f4aSmatthiasgrimm/** 5346b13307fSandi * Print one of the buttons 5356b13307fSandi * 536a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 537a453d131SAdrian Lang * @see tpl_get_action 538e0c26282SGerrit Uitslag * 539e0c26282SGerrit Uitslag * @param string $type 540e0c26282SGerrit Uitslag * @param bool $return 541e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5426b13307fSandi */ 5431af98a77SAnika Henkefunction tpl_button($type, $return = false) { 544a453d131SAdrian Lang $data = tpl_get_action($type); 545a453d131SAdrian Lang if($data === false) { 546a453d131SAdrian Lang return false; 547a453d131SAdrian Lang } elseif(!is_array($data)) { 548a453d131SAdrian Lang $out = sprintf($data, 'button'); 549409d7af7SAndreas Gohr } else { 550ac7a515fSAndreas Gohr /** 551ac7a515fSAndreas Gohr * @var string $accesskey 552ac7a515fSAndreas Gohr * @var string $id 553ac7a515fSAndreas Gohr * @var string $method 554ac7a515fSAndreas Gohr * @var array $params 555ac7a515fSAndreas Gohr */ 556a453d131SAdrian Lang extract($data); 557a453d131SAdrian Lang if($id === '#dokuwiki__top') { 558a453d131SAdrian Lang $out = html_topbtn(); 559409d7af7SAndreas Gohr } else { 560a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 561409d7af7SAndreas Gohr } 562409d7af7SAndreas Gohr } 5631af98a77SAnika Henke if($return) return $out; 564a453d131SAdrian Lang echo $out; 565a453d131SAdrian Lang return true; 5666b13307fSandi} 5676b13307fSandi 5686b13307fSandi/** 569ed630903Sandi * Like the action buttons but links 570ed630903Sandi * 571a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 572a453d131SAdrian Lang * @see tpl_get_action 573e0c26282SGerrit Uitslag * 57442ea7f44SGerrit Uitslag * @param string $type action command 575e0c26282SGerrit Uitslag * @param string $pre prefix of link 576e0c26282SGerrit Uitslag * @param string $suf suffix of link 577e0c26282SGerrit Uitslag * @param string $inner innerHML of link 57821d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 579e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 580a453d131SAdrian Lang */ 581a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 582a453d131SAdrian Lang global $lang; 583a453d131SAdrian Lang $data = tpl_get_action($type); 584a453d131SAdrian Lang if($data === false) { 585a453d131SAdrian Lang return false; 586a453d131SAdrian Lang } elseif(!is_array($data)) { 587a453d131SAdrian Lang $out = sprintf($data, 'link'); 588a453d131SAdrian Lang } else { 589ac7a515fSAndreas Gohr /** 590ac7a515fSAndreas Gohr * @var string $accesskey 591ac7a515fSAndreas Gohr * @var string $id 592ac7a515fSAndreas Gohr * @var string $method 593b1af9014SChristopher Smith * @var bool $nofollow 594ac7a515fSAndreas Gohr * @var array $params 595becfa414SGerrit Uitslag * @var string $replacement 596ac7a515fSAndreas Gohr */ 597a453d131SAdrian Lang extract($data); 598a453d131SAdrian Lang if(strpos($id, '#') === 0) { 599a453d131SAdrian Lang $linktarget = $id; 600a453d131SAdrian Lang } else { 601a453d131SAdrian Lang $linktarget = wl($id, $params); 602a453d131SAdrian Lang } 603a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 604becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 605becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 606becfa414SGerrit Uitslag } 607c7e90e3fSAnika Henke $akey = $addTitle = ''; 608c7e90e3fSAnika Henke if($accesskey) { 609c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 610c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 611c7e90e3fSAnika Henke } 612b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 613ac7a515fSAndreas Gohr $out = tpl_link( 614ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 615a453d131SAdrian Lang 'class="action '.$type.'" '. 616b1af9014SChristopher Smith $akey.$rel. 617e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 618ac7a515fSAndreas Gohr ); 619a453d131SAdrian Lang } 620a453d131SAdrian Lang if($return) return $out; 621a453d131SAdrian Lang echo $out; 622a453d131SAdrian Lang return true; 623a453d131SAdrian Lang} 624a453d131SAdrian Lang 625a453d131SAdrian Lang/** 626a453d131SAdrian Lang * Check the actions and get data for buttons and links 627ed630903Sandi * 628*4887c154SAndreas Gohr * @deprecated use \dokuwiki\Menu\Item\AbstractItem descendants instead 629ed630903Sandi * 630ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 631a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 632a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 633e0c26282SGerrit Uitslag * 634ac7a515fSAndreas Gohr * @param string $type 635ac7a515fSAndreas Gohr * @return array|bool|string 636ed630903Sandi */ 637a453d131SAdrian Langfunction tpl_get_action($type) { 638a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6394c4b65c8SMichael Hamann if($type == 'subscription') $type = 'subscribe'; 640*4887c154SAndreas Gohr if($type == 'img_backto') $type = 'imgBackto'; 641409d7af7SAndreas Gohr 642*4887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 643*4887c154SAndreas Gohr if(class_exists($class)) { 644*4887c154SAndreas Gohr try { 645*4887c154SAndreas Gohr /** @var \dokuwiki\Menu\Item\AbstractItem $item */ 646*4887c154SAndreas Gohr $item = new $class; 647*4887c154SAndreas Gohr $data = $item->getLegacyData(); 6487b4365a7SGerrit Uitslag $unknown = false; 649*4887c154SAndreas Gohr } catch(\RuntimeException $ignored) { 650*4887c154SAndreas Gohr return false; 651b8a111f5SMichael Klier } 652ed630903Sandi } else { 653*4887c154SAndreas Gohr global $ID; 654*4887c154SAndreas Gohr $data = array( 655*4887c154SAndreas Gohr 'accesskey' => null, 656*4887c154SAndreas Gohr 'type' => $type, 657*4887c154SAndreas Gohr 'id' => $ID, 658*4887c154SAndreas Gohr 'method' => 'get', 659*4887c154SAndreas Gohr 'params' => array('do' => $type), 660*4887c154SAndreas Gohr 'nofollow' => true, 661*4887c154SAndreas Gohr 'replacement' => '', 662becfa414SGerrit Uitslag ); 6637b4365a7SGerrit Uitslag $unknown = true; 664ed630903Sandi } 6657b4365a7SGerrit Uitslag 6663131073dSGerrit Uitslag $evt = new Doku_Event('TPL_ACTION_GET', $data); 6677b4365a7SGerrit Uitslag if($evt->advise_before()) { 6687b4365a7SGerrit Uitslag //handle unknown types 6697b4365a7SGerrit Uitslag if($unknown) { 67038d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6717b4365a7SGerrit Uitslag } 6727b4365a7SGerrit Uitslag } 6737b4365a7SGerrit Uitslag $evt->advise_after(); 6747b4365a7SGerrit Uitslag unset($evt); 6757b4365a7SGerrit Uitslag 6767b4365a7SGerrit Uitslag return $data; 677ed630903Sandi} 678ed630903Sandi 679ed630903Sandi/** 68001f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 68101f17825SAnika Henke * 68201f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 68342ea7f44SGerrit Uitslag * 68442ea7f44SGerrit Uitslag * @param string $type action command 685ac7a515fSAndreas Gohr * @param bool $link link or form button? 686e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 687ac7a515fSAndreas Gohr * @param bool $return return or print 688ac7a515fSAndreas Gohr * @param string $pre prefix for links 689ac7a515fSAndreas Gohr * @param string $suf suffix for links 690ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 691ac7a515fSAndreas Gohr * @return bool|string 69201f17825SAnika Henke */ 693ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 69401f17825SAnika Henke $out = ''; 695ac7a515fSAndreas Gohr if($link) { 696e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 697ac7a515fSAndreas Gohr } else { 698e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 699ac7a515fSAndreas Gohr } 70001f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 70101f17825SAnika Henke 70201f17825SAnika Henke if($return) return $out; 70301f17825SAnika Henke print $out; 70401f17825SAnika Henke return $out ? true : false; 70501f17825SAnika Henke} 70601f17825SAnika Henke 70701f17825SAnika Henke/** 7086b13307fSandi * Print the search form 7096b13307fSandi * 71072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 71172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 71272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 71372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 71472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 71572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 71672645b75SAndreas Gohr * 7176b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 71842ea7f44SGerrit Uitslag * 719ac7a515fSAndreas Gohr * @param bool $ajax 720ac7a515fSAndreas Gohr * @param bool $autocomplete 721ac7a515fSAndreas Gohr * @return bool 7226b13307fSandi */ 72372645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 7246b13307fSandi global $lang; 725c1e3b7d9Smatthiasgrimm global $ACT; 726ad4aaef7SAndreas Gohr global $QUERY; 727c1e3b7d9Smatthiasgrimm 728670ff54eSchris // don't print the search form if search action has been disabled 72964276bbcSarbrk1 if(!actionOK('search')) return false; 730670ff54eSchris 7319805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 7326b13307fSandi print '<input type="hidden" name="do" value="search" />'; 733c1e3b7d9Smatthiasgrimm print '<input type="text" '; 734ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 735001ea14eSRainbow Spike print 'placeholder="'.$lang['btn_search'].'" '; 73672645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 73707493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 738ae614416SAnika Henke print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>'; 73924a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 7404beabca9SAnika Henke print '</div></form>'; 74154e95700STom N Harris return true; 7426b13307fSandi} 7436b13307fSandi 7446b13307fSandi/** 7456b13307fSandi * Print the breadcrumbs trace 7466b13307fSandi * 7476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 74842ea7f44SGerrit Uitslag * 749ac7a515fSAndreas Gohr * @param string $sep Separator between entries 750ac7a515fSAndreas Gohr * @return bool 7516b13307fSandi */ 752e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 7536b13307fSandi global $lang; 7546b13307fSandi global $conf; 7556b13307fSandi 7566b13307fSandi //check if enabled 757359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 7586b13307fSandi 7596b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 760265e3787Sandi 7612979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 762265e3787Sandi 76340eb54bbSjan //render crumbs, highlight the last one 764fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 76540eb54bbSjan $last = count($crumbs); 76640eb54bbSjan $i = 0; 767a77f5846Sjan foreach($crumbs as $id => $name) { 76840eb54bbSjan $i++; 7692979a10bSKatriel Traum echo $crumbs_sep; 77092795d04Sandi if($i == $last) print '<span class="curid">'; 771d317fb5dSAnika Henke print '<bdi>'; 772e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 773d317fb5dSAnika Henke print '</bdi>'; 77492795d04Sandi if($i == $last) print '</span>'; 7756b13307fSandi } 77654e95700STom N Harris return true; 7776b13307fSandi} 7786b13307fSandi 7796b13307fSandi/** 7801734437eSandi * Hierarchical breadcrumbs 7811734437eSandi * 78231e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 7831734437eSandi * It only makes sense with a deep site structure. 7841734437eSandi * 7851734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 7866bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 78731e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 788f46c9e83SAnika Henke * @author <fredrik@averpil.com> 78908d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 79042ea7f44SGerrit Uitslag * 791ac7a515fSAndreas Gohr * @param string $sep Separator between entries 792ac7a515fSAndreas Gohr * @return bool 7931734437eSandi */ 79408d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') { 7951734437eSandi global $conf; 7961734437eSandi global $ID; 7971734437eSandi global $lang; 7981734437eSandi 79931e187f8SSean Coates // check if enabled 80054e95700STom N Harris if(!$conf['youarehere']) return false; 8011734437eSandi 8021734437eSandi $parts = explode(':', $ID); 803796bafb3SAndreas Gohr $count = count($parts); 8041734437eSandi 80508d7a575SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 8063940c519SMark 80708d7a575SAndreas Gohr // always print the startpage 80808d7a575SAndreas Gohr echo '<span class="home">'; 80908d7a575SAndreas Gohr tpl_pagelink(':'.$conf['start']); 81008d7a575SAndreas Gohr echo '</span>'; 811796bafb3SAndreas Gohr 812796bafb3SAndreas Gohr // print intermediate namespace links 813796bafb3SAndreas Gohr $part = ''; 814796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 815796bafb3SAndreas Gohr $part .= $parts[$i].':'; 816796bafb3SAndreas Gohr $page = $part; 817796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 818796bafb3SAndreas Gohr 81908d7a575SAndreas Gohr // output 82008d7a575SAndreas Gohr echo $sep; 82108d7a575SAndreas Gohr tpl_pagelink($page); 82231e187f8SSean Coates } 8231734437eSandi 824796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 825e013f48dSAnika Henke resolve_pageid('', $page, $exists); 82608d7a575SAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 827796bafb3SAndreas Gohr $page = $part.$parts[$i]; 82808d7a575SAndreas Gohr if($page == $conf['start']) return true; 82908d7a575SAndreas Gohr echo $sep; 83008d7a575SAndreas Gohr tpl_pagelink($page); 83154e95700STom N Harris return true; 8321734437eSandi} 8331734437eSandi 8341734437eSandi/** 8356b13307fSandi * Print info if the user is logged in 836a2488c3cSMatthias Grimm * and show full name in that case 8376b13307fSandi * 8386b13307fSandi * Could be enhanced with a profile link in future? 8396b13307fSandi * 8406b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 84142ea7f44SGerrit Uitslag * 842ac7a515fSAndreas Gohr * @return bool 8436b13307fSandi */ 8446b13307fSandifunction tpl_userinfo() { 8456b13307fSandi global $lang; 846585bf44eSChristopher Smith /** @var Input $INPUT */ 847585bf44eSChristopher Smith global $INPUT; 848585bf44eSChristopher Smith 849585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 850fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 85154e95700STom N Harris return true; 85254e95700STom N Harris } 85354e95700STom N Harris return false; 8546b13307fSandi} 8556b13307fSandi 8566b13307fSandi/** 8576b13307fSandi * Print some info about the current page 8586b13307fSandi * 8596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 86042ea7f44SGerrit Uitslag * 861ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 862ac7a515fSAndreas Gohr * @return bool|string 8636b13307fSandi */ 8644b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 8656b13307fSandi global $conf; 8666b13307fSandi global $lang; 8676b13307fSandi global $INFO; 868c6e92a3cSDavid Lorentsen global $ID; 869c6e92a3cSDavid Lorentsen 870c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 871ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 872ac7a515fSAndreas Gohr return false; 873ac7a515fSAndreas Gohr } 8746b13307fSandi 8756b13307fSandi // prepare date and path 8766b13307fSandi $fn = $INFO['filepath']; 8776b13307fSandi if(!$conf['fullpath']) { 878613bca54SAndreas Gohr if($INFO['rev']) { 879c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'].'/', '', $fn); 8806b13307fSandi } else { 881c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'].'/', '', $fn); 8826b13307fSandi } 8836b13307fSandi } 884bee6dc82Sandi $fn = utf8_decodeFN($fn); 885f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 8866b13307fSandi 887faecdfdfSAndreas Gohr // print it 888faecdfdfSAndreas Gohr if($INFO['exists']) { 8894b0d3916SAndreas Gohr $out = ''; 890d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 891e260f93bSAnika Henke $out .= ' · '; 8924b0d3916SAndreas Gohr $out .= $lang['lastmod']; 893fde860beSGerrit Uitslag $out .= ' '; 8944b0d3916SAndreas Gohr $out .= $date; 8956b13307fSandi if($INFO['editor']) { 8964b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 897d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 8985aa52fafSBen Coburn } else { 8994b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 9006b13307fSandi } 9016b13307fSandi if($INFO['locked']) { 902e260f93bSAnika Henke $out .= ' · '; 9034b0d3916SAndreas Gohr $out .= $lang['lockedby']; 904fde860beSGerrit Uitslag $out .= ' '; 905d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 9066b13307fSandi } 9074b0d3916SAndreas Gohr if($ret) { 9084b0d3916SAndreas Gohr return $out; 9094b0d3916SAndreas Gohr } else { 9104b0d3916SAndreas Gohr echo $out; 91154e95700STom N Harris return true; 9126b13307fSandi } 9134b0d3916SAndreas Gohr } 91454e95700STom N Harris return false; 9156b13307fSandi} 9166b13307fSandi 917820fa24bSandi/** 918a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 91987c434ceSAndreas Gohr * 92087c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 921a6598f23SBen Coburn * the given ID is used. 92287c434ceSAndreas Gohr * 92387c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 92442ea7f44SGerrit Uitslag * 925ac7a515fSAndreas Gohr * @param string $id page id 926ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 927ac7a515fSAndreas Gohr * @return bool|string 92887c434ceSAndreas Gohr */ 929a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 930c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 931fffeeafeSChristopher Smith 93287c434ceSAndreas Gohr if(is_null($id)) { 93387c434ceSAndreas Gohr global $ID; 93487c434ceSAndreas Gohr $id = $ID; 93587c434ceSAndreas Gohr } 93687c434ceSAndreas Gohr 93787c434ceSAndreas Gohr $name = $id; 938fe9ec250SChris Smith if(useHeading('navigation')) { 939fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 940fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 941fffeeafeSChristopher Smith } 942fffeeafeSChristopher Smith 943fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 944fffeeafeSChristopher Smith switch ($ACT) { 945fffeeafeSChristopher Smith // admin functions 946fffeeafeSChristopher Smith case 'admin' : 947fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 948fffeeafeSChristopher Smith // try to get the plugin name 949a61966c5SChristopher Smith /** @var $plugin DokuWiki_Admin_Plugin */ 950a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 951c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 952a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 953fffeeafeSChristopher Smith } 954fffeeafeSChristopher Smith break; 955fffeeafeSChristopher Smith 956fffeeafeSChristopher Smith // user functions 957fffeeafeSChristopher Smith case 'login' : 958fffeeafeSChristopher Smith case 'profile' : 959fffeeafeSChristopher Smith case 'register' : 960fffeeafeSChristopher Smith case 'resendpwd' : 961fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 962fffeeafeSChristopher Smith break; 963fffeeafeSChristopher Smith 964fffeeafeSChristopher Smith // wiki functions 965fffeeafeSChristopher Smith case 'search' : 966fffeeafeSChristopher Smith case 'index' : 967fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 968fffeeafeSChristopher Smith break; 969fffeeafeSChristopher Smith 970fffeeafeSChristopher Smith // page functions 971fffeeafeSChristopher Smith case 'edit' : 972fffeeafeSChristopher Smith $page_title = "✎ ".$name; 973fffeeafeSChristopher Smith break; 974fffeeafeSChristopher Smith 975fffeeafeSChristopher Smith case 'revisions' : 976fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 977fffeeafeSChristopher Smith break; 978fffeeafeSChristopher Smith 979fffeeafeSChristopher Smith case 'backlink' : 980fffeeafeSChristopher Smith case 'recent' : 981fffeeafeSChristopher Smith case 'subscribe' : 982fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 983fffeeafeSChristopher Smith break; 984fffeeafeSChristopher Smith 985fffeeafeSChristopher Smith default : // SHOW and anything else not included 986fffeeafeSChristopher Smith $page_title = $name; 98787c434ceSAndreas Gohr } 988a6598f23SBen Coburn 989a6598f23SBen Coburn if($ret) { 990fffeeafeSChristopher Smith return hsc($page_title); 991a6598f23SBen Coburn } else { 992fffeeafeSChristopher Smith print hsc($page_title); 99354e95700STom N Harris return true; 99487c434ceSAndreas Gohr } 995a6598f23SBen Coburn} 996340756e4Sandi 99755efc227SAndreas Gohr/** 99855efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 99955efc227SAndreas Gohr * 100055efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 100155efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 100255efc227SAndreas Gohr * 100355efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 100455efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 100555efc227SAndreas Gohr * to the names of the latter one) 100655efc227SAndreas Gohr * 10073df72098SAndreas Gohr * Only allowed in: detail.php 100855efc227SAndreas Gohr * 100955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 101042ea7f44SGerrit Uitslag * 101121d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1012ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1013e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1014ac7a515fSAndreas Gohr * @return string 101555efc227SAndreas Gohr */ 10163df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 101755efc227SAndreas Gohr // Init Exif Reader 101855efc227SAndreas Gohr global $SRC; 10193df72098SAndreas Gohr 10203df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10213df72098SAndreas Gohr 102255efc227SAndreas Gohr static $meta = null; 10233df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 102455efc227SAndreas Gohr if($meta === false) return $alt; 102588945224SChristopher Smith $info = cleanText($meta->getField($tags)); 102655efc227SAndreas Gohr if($info == false) return $alt; 102755efc227SAndreas Gohr return $info; 102855efc227SAndreas Gohr} 102955efc227SAndreas Gohr 103055efc227SAndreas Gohr/** 1031becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1032becfa414SGerrit Uitslag * 1033becfa414SGerrit Uitslag * @return string html of description list 1034becfa414SGerrit Uitslag */ 1035becfa414SGerrit Uitslagfunction tpl_img_meta() { 1036becfa414SGerrit Uitslag global $lang; 1037becfa414SGerrit Uitslag 1038becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1039becfa414SGerrit Uitslag 1040becfa414SGerrit Uitslag echo '<dl>'; 1041becfa414SGerrit Uitslag foreach($tags as $tag) { 1042becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1043fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1044becfa414SGerrit Uitslag 1045fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1046becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1047becfa414SGerrit Uitslag echo dformat($tag['value']); 1048becfa414SGerrit Uitslag } else { 1049becfa414SGerrit Uitslag echo hsc($tag['value']); 1050becfa414SGerrit Uitslag } 1051becfa414SGerrit Uitslag echo '</dd>'; 1052becfa414SGerrit Uitslag } 1053becfa414SGerrit Uitslag echo '</dl>'; 1054becfa414SGerrit Uitslag} 1055becfa414SGerrit Uitslag 1056becfa414SGerrit Uitslag/** 1057becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1058becfa414SGerrit Uitslag * 1059becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1060becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1061becfa414SGerrit Uitslag * - string type type of value 1062becfa414SGerrit Uitslag * - string value tag value (unescaped) 1063becfa414SGerrit Uitslag */ 1064becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1065becfa414SGerrit Uitslag 1066becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1067becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 106879e79377SAndreas Gohr if(file_exists($config_file)) { 1069becfa414SGerrit Uitslag include($config_file); 1070becfa414SGerrit Uitslag } 1071becfa414SGerrit Uitslag } 1072becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1073becfa414SGerrit Uitslag 1074becfa414SGerrit Uitslag $tags = array(); 1075becfa414SGerrit Uitslag foreach($fields as $tag){ 1076becfa414SGerrit Uitslag $t = array(); 1077becfa414SGerrit Uitslag if (!empty($tag[0])) { 1078becfa414SGerrit Uitslag $t = array($tag[0]); 1079becfa414SGerrit Uitslag } 1080becfa414SGerrit Uitslag if(is_array($tag[3])) { 1081becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1082becfa414SGerrit Uitslag } 1083becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1084becfa414SGerrit Uitslag if ($value) { 1085becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1086becfa414SGerrit Uitslag } 1087becfa414SGerrit Uitslag } 1088becfa414SGerrit Uitslag return $tags; 1089becfa414SGerrit Uitslag} 1090becfa414SGerrit Uitslag 1091becfa414SGerrit Uitslag/** 109255efc227SAndreas Gohr * Prints the image with a link to the full sized version 109355efc227SAndreas Gohr * 109455efc227SAndreas Gohr * Only allowed in: detail.php 1095a02d2933SAndreas Gohr * 1096ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1097a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1098a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1099a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1100a02d2933SAndreas Gohr * @param $params array - additional image attributes 110142ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 110255efc227SAndreas Gohr */ 1103a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 110455efc227SAndreas Gohr global $IMG; 1105585bf44eSChristopher Smith /** @var Input $INPUT */ 1106ac7a515fSAndreas Gohr global $INPUT; 11075c2eed9aSlisps global $REV; 110865d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 110965d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 111055efc227SAndreas Gohr 111155efc227SAndreas Gohr //resize to given max values 111223a34783SAndreas Gohr $ratio = 1; 111323a34783SAndreas Gohr if($w >= $h) { 1114f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 111555efc227SAndreas Gohr $ratio = $maxwidth / $w; 1116f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 111755efc227SAndreas Gohr $ratio = $maxheight / $h; 111855efc227SAndreas Gohr } 111955efc227SAndreas Gohr } else { 1120f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 112155efc227SAndreas Gohr $ratio = $maxheight / $h; 1122f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 112355efc227SAndreas Gohr $ratio = $maxwidth / $w; 112455efc227SAndreas Gohr } 112555efc227SAndreas Gohr } 112655efc227SAndreas Gohr if($ratio) { 112755efc227SAndreas Gohr $w = floor($ratio * $w); 112855efc227SAndreas Gohr $h = floor($ratio * $h); 112955efc227SAndreas Gohr } 113055efc227SAndreas Gohr 11316de3759aSAndreas Gohr //prepare URLs 11325c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 11335c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 113455efc227SAndreas Gohr 11352684e50aSAndreas Gohr //prepare attributes 113655efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1137a02d2933SAndreas Gohr if(is_null($params)) { 11382684e50aSAndreas Gohr $p = array(); 1139a02d2933SAndreas Gohr } else { 1140a02d2933SAndreas Gohr $p = $params; 1141a02d2933SAndreas Gohr } 11422684e50aSAndreas Gohr if($w) $p['width'] = $w; 11432684e50aSAndreas Gohr if($h) $p['height'] = $h; 11442684e50aSAndreas Gohr $p['class'] = 'img_detail'; 11452684e50aSAndreas Gohr if($alt) { 11462684e50aSAndreas Gohr $p['alt'] = $alt; 11472684e50aSAndreas Gohr $p['title'] = $alt; 11482684e50aSAndreas Gohr } else { 11492684e50aSAndreas Gohr $p['alt'] = ''; 11502684e50aSAndreas Gohr } 1151a02d2933SAndreas Gohr $p['src'] = $src; 115255efc227SAndreas Gohr 1153a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1154a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1155a02d2933SAndreas Gohr} 1156a02d2933SAndreas Gohr 1157a02d2933SAndreas Gohr/** 1158a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1159ac7a515fSAndreas Gohr * 1160ac7a515fSAndreas Gohr * @param array $data 1161ac7a515fSAndreas Gohr * @return bool 1162a02d2933SAndreas Gohr */ 1163ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 116459f3611bSAnika Henke global $lang; 1165a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1166a02d2933SAndreas Gohr 116759f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1168a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1169a02d2933SAndreas Gohr if($data['url']) print '</a>'; 117054e95700STom N Harris return true; 117155efc227SAndreas Gohr} 117255efc227SAndreas Gohr 11737367b368SAndreas Gohr/** 1174881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 11757367b368SAndreas Gohr * 11767367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 11777367b368SAndreas Gohr * template 1178ac7a515fSAndreas Gohr * 1179ac7a515fSAndreas Gohr * @return bool 11807367b368SAndreas Gohr */ 11817367b368SAndreas Gohrfunction tpl_indexerWebBug() { 11827367b368SAndreas Gohr global $ID; 11831dad36f5SAndreas Gohr 11847367b368SAndreas Gohr $p = array(); 1185b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1186e68c51baSAndreas Gohr '&'.time(); 1187881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 11887367b368SAndreas Gohr $p['height'] = 1; 11897367b368SAndreas Gohr $p['alt'] = ''; 11907367b368SAndreas Gohr $att = buildAttributes($p); 11917367b368SAndreas Gohr print "<img $att />"; 119254e95700STom N Harris return true; 11937367b368SAndreas Gohr} 11947367b368SAndreas Gohr 119578d4e784SEsther Brunner/** 119678d4e784SEsther Brunner * tpl_getConf($id) 119778d4e784SEsther Brunner * 119878d4e784SEsther Brunner * use this function to access template configuration variables 1199ac7a515fSAndreas Gohr * 120017448fb8SChristopher Smith * @param string $id name of the value to access 120117448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 120217448fb8SChristopher Smith * @return mixed 120378d4e784SEsther Brunner */ 120417448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 120578d4e784SEsther Brunner global $conf; 120617566ac6SAdrian Lang static $tpl_configloaded = false; 120778d4e784SEsther Brunner 120878d4e784SEsther Brunner $tpl = $conf['template']; 120978d4e784SEsther Brunner 121078d4e784SEsther Brunner if(!$tpl_configloaded) { 121178d4e784SEsther Brunner $tconf = tpl_loadConfig(); 121278d4e784SEsther Brunner if($tconf !== false) { 121378d4e784SEsther Brunner foreach($tconf as $key => $value) { 121478d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 121578d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 121678d4e784SEsther Brunner } 121778d4e784SEsther Brunner $tpl_configloaded = true; 121878d4e784SEsther Brunner } 121978d4e784SEsther Brunner } 122078d4e784SEsther Brunner 122117448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 122278d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 122378d4e784SEsther Brunner } 122478d4e784SEsther Brunner 122517448fb8SChristopher Smith return $notset; 122617448fb8SChristopher Smith} 122717448fb8SChristopher Smith 122878d4e784SEsther Brunner/** 122978d4e784SEsther Brunner * tpl_loadConfig() 1230ac7a515fSAndreas Gohr * 123178d4e784SEsther Brunner * reads all template configuration variables 123278d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1233ac7a515fSAndreas Gohr * 1234ac7a515fSAndreas Gohr * @return array 123578d4e784SEsther Brunner */ 123678d4e784SEsther Brunnerfunction tpl_loadConfig() { 123778d4e784SEsther Brunner 1238c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 123978d4e784SEsther Brunner $conf = array(); 124078d4e784SEsther Brunner 124179e79377SAndreas Gohr if(!file_exists($file)) return false; 124278d4e784SEsther Brunner 124378d4e784SEsther Brunner // load default config file 124478d4e784SEsther Brunner include($file); 124578d4e784SEsther Brunner 124678d4e784SEsther Brunner return $conf; 124778d4e784SEsther Brunner} 124878d4e784SEsther Brunner 124917566ac6SAdrian Lang// language methods 125017566ac6SAdrian Lang/** 125117566ac6SAdrian Lang * tpl_getLang($id) 125217566ac6SAdrian Lang * 125317566ac6SAdrian Lang * use this function to access template language variables 125442ea7f44SGerrit Uitslag * 125542ea7f44SGerrit Uitslag * @param string $id key of language string 125642ea7f44SGerrit Uitslag * @return string 125717566ac6SAdrian Lang */ 125817566ac6SAdrian Langfunction tpl_getLang($id) { 125917566ac6SAdrian Lang static $lang = array(); 126017566ac6SAdrian Lang 126117566ac6SAdrian Lang if(count($lang) === 0) { 1262dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1263dd7a6159SGerrit Uitslag 1264c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 126517566ac6SAdrian Lang 126617566ac6SAdrian Lang $lang = array(); 126717566ac6SAdrian Lang 126817566ac6SAdrian Lang // don't include once 126917566ac6SAdrian Lang @include($path . 'en/lang.php'); 1270dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 127179e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1272dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1273dd7a6159SGerrit Uitslag } 127417566ac6SAdrian Lang } 127517566ac6SAdrian Lang 1276dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1277dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1278dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 127979e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1280dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1281dd7a6159SGerrit Uitslag } 1282dd7a6159SGerrit Uitslag } 1283dd7a6159SGerrit Uitslag } 128417566ac6SAdrian Lang } 128517566ac6SAdrian Lang return $lang[$id]; 128617566ac6SAdrian Lang} 128717566ac6SAdrian Lang 12883df72098SAndreas Gohr/** 1289c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1290e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1291e8ec13b9SKlap-in * 1292e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1293e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1294e8ec13b9SKlap-in */ 1295e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1296c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1297e8ec13b9SKlap-in} 1298e8ec13b9SKlap-in 1299e8ec13b9SKlap-in/** 1300c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 130142ea7f44SGerrit Uitslag * 130242ea7f44SGerrit Uitslag * @param string $id id of localized text 130342ea7f44SGerrit Uitslag * @return string wiki text 1304e8ec13b9SKlap-in */ 1305c5c17fdaSKlap-infunction tpl_localeFN($id) { 1306e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1307e8ec13b9SKlap-in global $conf; 130838fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 130979e79377SAndreas Gohr if (!file_exists($file)){ 1310e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 131179e79377SAndreas Gohr if(!file_exists($file)){ 1312e8ec13b9SKlap-in //fall back to english 1313e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1314e8ec13b9SKlap-in } 1315e8ec13b9SKlap-in } 1316e8ec13b9SKlap-in return $file; 1317e8ec13b9SKlap-in} 1318e8ec13b9SKlap-in 1319e8ec13b9SKlap-in/** 13207abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 13213df72098SAndreas Gohr * 13223df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13233df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13243df72098SAndreas Gohr * a message of referencing pages 13253df72098SAndreas Gohr * 13263df72098SAndreas Gohr * Only allowed in mediamanager.php 13273df72098SAndreas Gohr * 1328c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1329c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 133042ea7f44SGerrit Uitslag * @param string $sort 13318702de7fSGerrit Uitslag * 13323df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13333df72098SAndreas Gohr */ 133400e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 13353df72098SAndreas Gohr global $IMG; 13363df72098SAndreas Gohr global $AUTH; 13373df72098SAndreas Gohr global $INUSE; 13383df72098SAndreas Gohr global $NS; 13393df72098SAndreas Gohr global $JUMPTO; 1340585bf44eSChristopher Smith /** @var Input $INPUT */ 1341ac7a515fSAndreas Gohr global $INPUT; 13423df72098SAndreas Gohr 1343ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1344c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1345c182313eSAndreas Gohr 1346c182313eSAndreas Gohr if(!$do) { 1347ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1348c182313eSAndreas Gohr $do = 'metaform'; 1349c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1350c182313eSAndreas Gohr $do = 'filesinuse'; 1351c182313eSAndreas Gohr } else { 1352c182313eSAndreas Gohr $do = 'filelist'; 1353c182313eSAndreas Gohr } 1354c182313eSAndreas Gohr } 1355c182313eSAndreas Gohr 1356c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1357c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1358c182313eSAndreas Gohr $data = array('do' => $do); 1359c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1360c182313eSAndreas Gohr if($evt->advise_before()) { 1361c182313eSAndreas Gohr $do = $data['do']; 136230fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1363c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1364c182313eSAndreas Gohr } elseif($do == 'filelist') { 136500e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1366c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1367ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1368c182313eSAndreas Gohr } else { 1369c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1370c182313eSAndreas Gohr } 1371c182313eSAndreas Gohr } 1372c182313eSAndreas Gohr $evt->advise_after(); 1373c182313eSAndreas Gohr unset($evt); 1374c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1375c182313eSAndreas Gohr 13763df72098SAndreas Gohr} 13773df72098SAndreas Gohr 13783df72098SAndreas Gohr/** 1379d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1380d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1381d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1382d9162c6cSKate Arzamastseva * 1383d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1384d9162c6cSKate Arzamastseva */ 1385035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1386d9162c6cSKate Arzamastseva global $AUTH; 1387d9162c6cSKate Arzamastseva global $NS; 1388d9162c6cSKate Arzamastseva global $JUMPTO; 138995b451bcSAdrian Lang global $lang; 1390585bf44eSChristopher Smith /** @var Input $INPUT */ 1391ac7a515fSAndreas Gohr global $INPUT; 1392d9162c6cSKate Arzamastseva 1393ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1394e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1395ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1396d9162c6cSKate Arzamastseva 139794add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 139895b451bcSAdrian Lang 1399ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 140023846a98SKate Arzamastseva 140194add303SAnika Henke echo '<div class="panelHeader">'.NL; 140295b451bcSAdrian Lang echo '<h3>'; 1403026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1404c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 140594add303SAnika Henke echo '</h3>'.NL; 140695b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 140795b451bcSAdrian Lang media_tab_files_options(); 140823846a98SKate Arzamastseva } 140994add303SAnika Henke echo '</div>'.NL; 1410d9162c6cSKate Arzamastseva 141194add303SAnika Henke echo '<div class="panelContent">'.NL; 141295b451bcSAdrian Lang if($opened_tab == 'files') { 141395b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 141495b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 141595b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 141695b451bcSAdrian Lang } elseif($opened_tab == 'search') { 141795b451bcSAdrian Lang media_tab_search($NS, $AUTH); 141895b451bcSAdrian Lang } 141994add303SAnika Henke echo '</div>'.NL; 1420d9162c6cSKate Arzamastseva} 1421d9162c6cSKate Arzamastseva 1422d9162c6cSKate Arzamastseva/** 1423d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1424d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1425d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1426d9162c6cSKate Arzamastseva * list of file revisions 1427d9162c6cSKate Arzamastseva * 1428d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1429f50a239bSTakamura * 1430f50a239bSTakamura * @param string $image 1431f50a239bSTakamura * @param boolean $rev 1432d9162c6cSKate Arzamastseva */ 1433035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1434e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1435585bf44eSChristopher Smith /** @var Input $INPUT */ 1436585bf44eSChristopher Smith global $INPUT; 1437d9162c6cSKate Arzamastseva 143892cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1439ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 14406dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1441e8a2a143SMichael Hamann $ns = getNS($image); 1442ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 14431eeeced2SKate Arzamastseva 1444ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1445e5d185e1SKate Arzamastseva 1446e5d185e1SKate Arzamastseva $tab_array = array('view'); 1447ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1448e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1449e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1450e5d185e1SKate Arzamastseva } 1451e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1452e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1453e5d185e1SKate Arzamastseva } 1454e5d185e1SKate Arzamastseva 1455e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1456ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 145723846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1458d9162c6cSKate Arzamastseva 1459ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 146023846a98SKate Arzamastseva 146159f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1462ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 146395b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 146495b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 146500c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 146608317413SAdrian Lang if($opened_tab === 'view' && $rev) { 146708317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 146808317413SAdrian Lang } else { 1469026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 147008317413SAdrian Lang } 1471b8a84c03SAndreas Gohr 147294add303SAnika Henke echo '</h3></div>'.NL; 147395b451bcSAdrian Lang 147494add303SAnika Henke echo '<div class="panelContent">'.NL; 147595b451bcSAdrian Lang 147623846a98SKate Arzamastseva if($opened_tab == 'view') { 1477e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 147823846a98SKate Arzamastseva 147992cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1480e8a2a143SMichael Hamann media_tab_edit($image, $ns); 148123846a98SKate Arzamastseva 1482e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1483e8a2a143SMichael Hamann media_tab_history($image, $ns); 148423846a98SKate Arzamastseva } 148595b451bcSAdrian Lang 148694add303SAnika Henke echo '</div>'.NL; 1487d9162c6cSKate Arzamastseva} 1488d9162c6cSKate Arzamastseva 1489d9162c6cSKate Arzamastseva/** 14907abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 14913df72098SAndreas Gohr * 14923df72098SAndreas Gohr * Only allowed in mediamanager.php 14933df72098SAndreas Gohr * 14943df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14953df72098SAndreas Gohr */ 1496fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 14973df72098SAndreas Gohr global $NS; 149823846a98SKate Arzamastseva ptln('<div id="media__tree">'); 14993df72098SAndreas Gohr media_nstree($NS); 15003df72098SAndreas Gohr ptln('</div>'); 15013df72098SAndreas Gohr} 15023df72098SAndreas Gohr 1503a00de5b5SAndreas Gohr/** 1504a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1505a00de5b5SAndreas Gohr * 1506a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1507a00de5b5SAndreas Gohr * 1508a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 150942ea7f44SGerrit Uitslag * 151042ea7f44SGerrit Uitslag * @param string $empty empty option label 151142ea7f44SGerrit Uitslag * @param string $button submit button label 1512a00de5b5SAndreas Gohr */ 1513a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 15141e875dcdSAndreas Gohr $menu = new \dokuwiki\Menu\MobileMenu(); 15151e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1516a00de5b5SAndreas Gohr} 1517a00de5b5SAndreas Gohr 1518066fee30SAndreas Gohr/** 1519066fee30SAndreas Gohr * Print a informational line about the used license 1520066fee30SAndreas Gohr * 1521066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1522ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1523ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1524ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1525ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1526ac7a515fSAndreas Gohr * @return string 1527066fee30SAndreas Gohr */ 152880083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1529066fee30SAndreas Gohr global $license; 1530066fee30SAndreas Gohr global $conf; 1531066fee30SAndreas Gohr global $lang; 1532066fee30SAndreas Gohr if(!$conf['license']) return ''; 1533066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1534066fee30SAndreas Gohr $lic = $license[$conf['license']]; 153553e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1536066fee30SAndreas Gohr 153780083a41SAndreas Gohr $out = ''; 153880083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1539066fee30SAndreas Gohr if($img) { 1540066fee30SAndreas Gohr $src = license_img($img); 1541066fee30SAndreas Gohr if($src) { 154253e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 154353e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 154453e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1545066fee30SAndreas Gohr } 1546066fee30SAndreas Gohr } 15474cefd216SMichael Klier if(!$imgonly) { 154853e15c8bSAnika Henke $out .= $lang['license'].' '; 1549d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1550d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 15514cefd216SMichael Klier } 155280083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1553066fee30SAndreas Gohr 1554066fee30SAndreas Gohr if($return) return $out; 1555066fee30SAndreas Gohr echo $out; 1556ac7a515fSAndreas Gohr return ''; 1557066fee30SAndreas Gohr} 1558066fee30SAndreas Gohr 1559a81910eeSAndreas Gohr/** 1560835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1561a81910eeSAndreas Gohr * 1562a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1563a81910eeSAndreas Gohr * template 1564e0c26282SGerrit Uitslag * 15657a112df5SAndreas Gohr * @param string $pageid The page name you want to include 15667a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 15677a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 15687c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1569e0c26282SGerrit Uitslag * @return bool|null|string 1570a81910eeSAndreas Gohr */ 15717c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 15727a112df5SAndreas Gohr if($propagate) { 15737c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 15747c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 15757a112df5SAndreas Gohr return false; 15767a112df5SAndreas Gohr } 1577c786a1b6SAnika Henke if(!$pageid) return false; 1578835dfcaeSAnika Henke 1579c786a1b6SAnika Henke global $TOC; 15809a2e250aSAndreas Gohr $oldtoc = $TOC; 1581a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 15829a2e250aSAndreas Gohr $TOC = $oldtoc; 1583a81910eeSAndreas Gohr 1584a2e03c82SAndreas Gohr if($print) echo $html; 1585e66d3e6dSAndreas Gohr return $html; 1586e66d3e6dSAndreas Gohr} 1587e66d3e6dSAndreas Gohr 1588e66d3e6dSAndreas Gohr/** 15895b75cd1fSAdrian Lang * Display the subscribe form 15905b75cd1fSAdrian Lang * 15915b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15925b75cd1fSAdrian Lang */ 15935b75cd1fSAdrian Langfunction tpl_subscribe() { 15945b75cd1fSAdrian Lang global $INFO; 15955b75cd1fSAdrian Lang global $ID; 15965b75cd1fSAdrian Lang global $lang; 15976b8f02cfSAdrian Lang global $conf; 159840c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 15995b75cd1fSAdrian Lang 16005b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 16015b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 160215741132SAndreas Gohr echo '<div class="level2">'; 16035b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 16045b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 16055b75cd1fSAdrian Lang } else { 16065b75cd1fSAdrian Lang echo '<ul>'; 16075b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1608056c2049SAndreas Gohr echo '<li><div class="li">'; 16095b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1610056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16115b75cd1fSAdrian Lang } else { 1612056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16135b75cd1fSAdrian Lang } 161440c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 161515741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1616056c2049SAndreas Gohr echo ' ('.$sstl.') '; 161715741132SAndreas Gohr 1618ac7a515fSAndreas Gohr echo '<a href="'.wl( 1619ac7a515fSAndreas Gohr $ID, 1620ac7a515fSAndreas Gohr array( 1621ac7a515fSAndreas Gohr 'do' => 'subscribe', 162266d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 162366d2bed9SAdrian Lang 'sub_style' => $sub['style'], 162466d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1625ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1626ac7a515fSAndreas Gohr ) 1627ac7a515fSAndreas Gohr ). 162866d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 162966d2bed9SAdrian Lang '</a></div></li>'; 16305b75cd1fSAdrian Lang } 16315b75cd1fSAdrian Lang echo '</ul>'; 16325b75cd1fSAdrian Lang } 163315741132SAndreas Gohr echo '</div>'; 16345b75cd1fSAdrian Lang 163515741132SAndreas Gohr // Add new subscription form 16365b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 163715741132SAndreas Gohr echo '<div class="level2">'; 16385b75cd1fSAdrian Lang $ns = getNS($ID).':'; 163915741132SAndreas Gohr $targets = array( 164015741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 164115741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 164215741132SAndreas Gohr ); 164315741132SAndreas Gohr $styles = array( 164415741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 16456b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 16466b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 164715741132SAndreas Gohr ); 164815741132SAndreas Gohr 1649056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1650056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1651056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1652056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1653056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1654056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1655056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1656056c2049SAndreas Gohr $form->addHidden('id', $ID); 1657056c2049SAndreas Gohr $form->endFieldset(); 16585b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 16595b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 166015741132SAndreas Gohr echo '</div>'; 16615b75cd1fSAdrian Lang} 16625b75cd1fSAdrian Lang 1663d059ba9bSAndreas Gohr/** 1664d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1665d059ba9bSAndreas Gohr * 1666d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1667d059ba9bSAndreas Gohr * 1668d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1669d059ba9bSAndreas Gohr */ 1670d059ba9bSAndreas Gohrfunction tpl_flush() { 1671d059ba9bSAndreas Gohr ob_flush(); 1672d059ba9bSAndreas Gohr flush(); 1673d059ba9bSAndreas Gohr} 1674d059ba9bSAndreas Gohr 1675afca7e7eSAnika Henke/** 1676378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1677afca7e7eSAnika Henke * 1678378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1679378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1680378325f9SAndreas Gohr * 168142ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1682378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1683ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1684ac7a515fSAndreas Gohr * @return string 168542ea7f44SGerrit Uitslag * 1686378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1687afca7e7eSAnika Henke */ 1688378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1689ac7a515fSAndreas Gohr $img = ''; 1690ac7a515fSAndreas Gohr $file = ''; 1691ac7a515fSAndreas Gohr $ismedia = false; 1692378325f9SAndreas Gohr // loop through candidates until a match was found: 1693378325f9SAndreas Gohr foreach($search as $img) { 1694378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1695378325f9SAndreas Gohr $file = mediaFN($img); 1696378325f9SAndreas Gohr $ismedia = true; 1697378325f9SAndreas Gohr } else { 1698c4766956SAndreas Gohr $file = tpl_incdir().$img; 1699378325f9SAndreas Gohr $ismedia = false; 17001f13e33dSAnika Henke } 17010f747863Slupo49 1702378325f9SAndreas Gohr if(file_exists($file)) break; 1703872a6d29SAnika Henke } 1704378325f9SAndreas Gohr 1705378325f9SAndreas Gohr // fetch image data if requested 1706378325f9SAndreas Gohr if(!is_null($imginfo)) { 1707378325f9SAndreas Gohr $imginfo = getimagesize($file); 1708378325f9SAndreas Gohr } 1709378325f9SAndreas Gohr 1710378325f9SAndreas Gohr // build URL 1711378325f9SAndreas Gohr if($ismedia) { 1712378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1713378325f9SAndreas Gohr } else { 1714c4766956SAndreas Gohr $url = tpl_basedir().$img; 1715378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1716378325f9SAndreas Gohr } 1717378325f9SAndreas Gohr 1718378325f9SAndreas Gohr return $url; 1719a7e5f74cSlupo49} 17201f13e33dSAnika Henke 1721872a6d29SAnika Henke/** 1722e5d4768dSAndreas Gohr * PHP include a file 1723e5d4768dSAndreas Gohr * 1724e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1725e5d4768dSAndreas Gohr * file in the template's root directory. 1726e5d4768dSAndreas Gohr * 1727e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1728e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1729e5d4768dSAndreas Gohr * default. 1730e5d4768dSAndreas Gohr * 1731e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1732e5d4768dSAndreas Gohr * to this function! 1733e5d4768dSAndreas Gohr * 1734e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1735e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 173642ea7f44SGerrit Uitslag * 173742ea7f44SGerrit Uitslag * @param string $file 1738e5d4768dSAndreas Gohr */ 1739e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1740e5d4768dSAndreas Gohr global $config_cascade; 1741e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1742e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1743e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1744e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1745e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1746f3a1225fSAnika Henke include("$dir/$file"); 1747e5d4768dSAndreas Gohr return; 1748e5d4768dSAndreas Gohr } 1749e5d4768dSAndreas Gohr } 1750e5d4768dSAndreas Gohr } 1751e5d4768dSAndreas Gohr 1752e5d4768dSAndreas Gohr // still here? try the template dir 1753e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1754e5d4768dSAndreas Gohr if(file_exists($file)) { 1755f3a1225fSAnika Henke include($file); 1756e5d4768dSAndreas Gohr } 1757e5d4768dSAndreas Gohr} 1758e5d4768dSAndreas Gohr 1759e5d4768dSAndreas Gohr/** 1760872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1761872a6d29SAnika Henke * 1762872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 176342ea7f44SGerrit Uitslag * 1764ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1765ac7a515fSAndreas Gohr * @return string 1766872a6d29SAnika Henke */ 1767872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1768872a6d29SAnika Henke 1769872a6d29SAnika Henke $return = ''; 1770872a6d29SAnika Henke 1771872a6d29SAnika Henke foreach($types as $type) { 1772872a6d29SAnika Henke switch($type) { 1773872a6d29SAnika Henke case 'favicon': 1774378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1775378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1776872a6d29SAnika Henke break; 1777872a6d29SAnika Henke case 'mobile': 1778cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1779378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1780872a6d29SAnika Henke break; 1781872a6d29SAnika Henke case 'generic': 1782872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1783378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1784378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1785872a6d29SAnika Henke break; 1786872a6d29SAnika Henke } 1787872a6d29SAnika Henke } 1788872a6d29SAnika Henke 1789872a6d29SAnika Henke return $return; 1790afca7e7eSAnika Henke} 1791afca7e7eSAnika Henke 1792d9162c6cSKate Arzamastseva/** 1793d9162c6cSKate Arzamastseva * Prints full-screen media manager 1794d9162c6cSKate Arzamastseva * 1795d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1796d9162c6cSKate Arzamastseva */ 1797d9162c6cSKate Arzamastsevafunction tpl_media() { 1798ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 179988a71175SKate Arzamastseva $fullscreen = true; 180095b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1801d9162c6cSKate Arzamastseva 1802ac7a515fSAndreas Gohr $rev = ''; 1803ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 180498f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 180598f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 18069c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 180798f03b57SKate Arzamastseva 180894add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1809bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1810d9162c6cSKate Arzamastseva html_msgarea(); 181194add303SAnika Henke 181294add303SAnika Henke echo '<div class="panel namespaces">'.NL; 181394add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 181495b451bcSAdrian Lang echo '<div class="panelHeader">'; 1815ba340a70SAnika Henke echo $lang['media_namespaces']; 181694add303SAnika Henke echo '</div>'.NL; 181795b451bcSAdrian Lang 181894add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 181995b451bcSAdrian Lang media_nstree($NS); 182094add303SAnika Henke echo '</div>'.NL; 182194add303SAnika Henke echo '</div>'.NL; 1822fa8e5c77SKate Arzamastseva 182394add303SAnika Henke echo '<div class="panel filelist">'.NL; 1824035e07f1SKate Arzamastseva tpl_mediaFileList(); 182594add303SAnika Henke echo '</div>'.NL; 1826fa8e5c77SKate Arzamastseva 182794add303SAnika Henke echo '<div class="panel file">'.NL; 182894add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1829035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 183094add303SAnika Henke echo '</div>'.NL; 1831ba340a70SAnika Henke 183294add303SAnika Henke echo '</div>'.NL; 1833d9162c6cSKate Arzamastseva} 1834afca7e7eSAnika Henke 1835c71db656SAnika Henke/** 1836c71db656SAnika Henke * Return useful layout classes 1837c71db656SAnika Henke * 1838c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 183942ea7f44SGerrit Uitslag * 184042ea7f44SGerrit Uitslag * @return string 1841c71db656SAnika Henke */ 1842c71db656SAnika Henkefunction tpl_classes() { 1843c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1844585bf44eSChristopher Smith /** @var Input $INPUT */ 1845585bf44eSChristopher Smith global $INPUT; 1846585bf44eSChristopher Smith 1847c71db656SAnika Henke $classes = array( 1848c71db656SAnika Henke 'dokuwiki', 1849c71db656SAnika Henke 'mode_'.$ACT, 1850c71db656SAnika Henke 'tpl_'.$conf['template'], 1851585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 185239f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1853c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1854c71db656SAnika Henke ); 1855c71db656SAnika Henke return join(' ', $classes); 1856c71db656SAnika Henke} 1857c71db656SAnika Henke 185884dd2b1aSGerrit Uitslag/** 185984dd2b1aSGerrit Uitslag * Create event for tools menues 186084dd2b1aSGerrit Uitslag * 186184dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 186284dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 186384dd2b1aSGerrit Uitslag * @param array $items 186484dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 186584dd2b1aSGerrit Uitslag */ 186684dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') { 186784dd2b1aSGerrit Uitslag $data = array( 186884dd2b1aSGerrit Uitslag 'view' => $view, 186984dd2b1aSGerrit Uitslag 'items' => $items 187084dd2b1aSGerrit Uitslag ); 187184dd2b1aSGerrit Uitslag 187284dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 187384dd2b1aSGerrit Uitslag $evt = new Doku_Event($hook, $data); 187484dd2b1aSGerrit Uitslag if($evt->advise_before()) { 187584dd2b1aSGerrit Uitslag foreach($evt->data['items'] as $k => $html) echo $html; 187684dd2b1aSGerrit Uitslag } 187784dd2b1aSGerrit Uitslag $evt->advise_after(); 187884dd2b1aSGerrit Uitslag} 187984dd2b1aSGerrit Uitslag 1880e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1881a00de5b5SAndreas Gohr 1882