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> 71*42ea7f44SGerrit 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); 17424bb549bSchris if($evt->advise_before()) 175ea67f144Sandi msg("Failed to handle command: ".hsc($ACT), -1); 17624bb549bSchris $evt->advise_after(); 17724bb549bSchris unset($evt); 17854e95700STom N Harris return false; 1796b13307fSandi } 18054e95700STom N Harris return true; 1816b13307fSandi} 1826b13307fSandi 183c19fe9c0Sandi/** 184b8595a66SAndreas Gohr * Places the TOC where the function is called 185b8595a66SAndreas Gohr * 186b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 187b8595a66SAndreas Gohr * a false argument 188b8595a66SAndreas Gohr * 189b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 190*42ea7f44SGerrit Uitslag * 191ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 192ac7a515fSAndreas Gohr * @return string 193b8595a66SAndreas Gohr */ 194b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 195b8595a66SAndreas Gohr global $TOC; 196b8595a66SAndreas Gohr global $ACT; 197b8595a66SAndreas Gohr global $ID; 198b8595a66SAndreas Gohr global $REV; 199b8595a66SAndreas Gohr global $INFO; 200851f2e89SAnika Henke global $conf; 201ac7a515fSAndreas Gohr global $INPUT; 202b8595a66SAndreas Gohr $toc = array(); 203b8595a66SAndreas Gohr 204b8595a66SAndreas Gohr if(is_array($TOC)) { 205b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 206b8595a66SAndreas Gohr $toc = $TOC; 2073c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 208b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 209e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 210b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 211b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 212b8595a66SAndreas Gohr } else { 2132bb0d541Schris $tocok = true; 214b8595a66SAndreas Gohr } 215f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 216851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 217b8595a66SAndreas Gohr $toc = array(); 218b8595a66SAndreas Gohr } 219b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 220b8595a66SAndreas Gohr // try to load admin plugin TOC FIXME: duplicates code from tpl_admin 221b8595a66SAndreas Gohr $plugin = null; 222ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 223ac7a515fSAndreas Gohr if(!empty($class)) { 224b8595a66SAndreas Gohr $pluginlist = plugin_list('admin'); 225ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 226b8595a66SAndreas Gohr // attempt to load the plugin 227ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 228a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 229b8595a66SAndreas Gohr } 230b8595a66SAndreas Gohr } 231ac7a515fSAndreas Gohr if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { 232b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 233b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 234b8595a66SAndreas Gohr } 235b8595a66SAndreas Gohr } 236b8595a66SAndreas Gohr 2370b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 238b8595a66SAndreas Gohr $html = html_TOC($toc); 239b8595a66SAndreas Gohr if($return) return $html; 240b8595a66SAndreas Gohr echo $html; 241ac7a515fSAndreas Gohr return ''; 242b8595a66SAndreas Gohr} 243b8595a66SAndreas Gohr 244b8595a66SAndreas Gohr/** 245c19fe9c0Sandi * Handle the admin page contents 246c19fe9c0Sandi * 247c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 248*42ea7f44SGerrit Uitslag * 249*42ea7f44SGerrit Uitslag * @return bool 250c19fe9c0Sandi */ 251c19fe9c0Sandifunction tpl_admin() { 252f8cc712eSAndreas Gohr global $INFO; 253b8595a66SAndreas Gohr global $TOC; 254ac7a515fSAndreas Gohr global $INPUT; 25511e2ce22Schris 256b8595a66SAndreas Gohr $plugin = null; 257ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 258ac7a515fSAndreas Gohr if(!empty($class)) { 25911e2ce22Schris $pluginlist = plugin_list('admin'); 26011e2ce22Schris 261ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 26211e2ce22Schris // attempt to load the plugin 263ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 264a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 26511e2ce22Schris } 26611e2ce22Schris } 26711e2ce22Schris 268b8595a66SAndreas Gohr if($plugin !== null) { 269b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 270b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 271f8cc712eSAndreas Gohr $plugin->html(); 272f8cc712eSAndreas Gohr } else { 273f8cc712eSAndreas Gohr html_admin(); 274f8cc712eSAndreas Gohr } 27554e95700STom N Harris return true; 276c19fe9c0Sandi} 2776b13307fSandi 2786b13307fSandi/** 2796b13307fSandi * Print the correct HTML meta headers 2806b13307fSandi * 2816b13307fSandi * This has to go into the head section of your template. 2826b13307fSandi * 2836b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 284*42ea7f44SGerrit Uitslag * 285ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 286ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 287ac7a515fSAndreas Gohr * @return bool 2886b13307fSandi */ 289f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2906b13307fSandi global $ID; 291d98d4540SBen Coburn global $REV; 2926b13307fSandi global $INFO; 29372e0dc37SAndreas Gohr global $JSINFO; 2946b13307fSandi global $ACT; 2954bb1b5aeSAndreas Gohr global $QUERY; 2966b13307fSandi global $lang; 297dc57ef04Sandi global $conf; 2989c438d6cSMichael Hamann global $updateVersion; 299585bf44eSChristopher Smith /** @var Input $INPUT */ 300585bf44eSChristopher Smith global $INPUT; 3016b13307fSandi 3027bff22c0SAndreas Gohr // prepare the head array 3037bff22c0SAndreas Gohr $head = array(); 3047bff22c0SAndreas Gohr 305202ac28bSMichael Klier // prepare seed for js and css 306cd997f93SAndreas Gohr $tseed = $updateVersion; 307202ac28bSMichael Klier $depends = getConfigFiles('main'); 308cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 309cd997f93SAndreas Gohr $tseed = md5($tseed); 3107bff22c0SAndreas Gohr 3116b13307fSandi // the usual stuff 3123f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 313ac7a515fSAndreas Gohr $head['link'][] = array( 314ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 315ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 316ac7a515fSAndreas Gohr ); 317f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 3187aedde2eSGina Haeussge if(actionOK('index')) { 319ac7a515fSAndreas Gohr $head['link'][] = array( 320ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 321ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 322ac7a515fSAndreas Gohr ); 3237aedde2eSGina Haeussge } 324f96fa415SAndreas Gohr 325f96fa415SAndreas Gohr if($alt) { 32654be1338SGerrit Uitslag if(actionOK('rss')) { 327ac7a515fSAndreas Gohr $head['link'][] = array( 328ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 329a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 330ac7a515fSAndreas Gohr ); 331ac7a515fSAndreas Gohr $head['link'][] = array( 332ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 333a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 334ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 335ac7a515fSAndreas Gohr ); 33654be1338SGerrit Uitslag } 337c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 338ac7a515fSAndreas Gohr $head['link'][] = array( 339ac7a515fSAndreas Gohr 'rel' => 'edit', 340715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 341ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 342ac7a515fSAndreas Gohr ); 343c35f3875SAndreas Gohr } 344c35f3875SAndreas Gohr 34554be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 346ac7a515fSAndreas Gohr $head['link'][] = array( 347ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 348a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 349ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 350ac7a515fSAndreas Gohr ); 3514bb1b5aeSAndreas Gohr } 352bae36d94SAndreas Gohr 353bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 354ac7a515fSAndreas Gohr $head['link'][] = array( 355a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 356ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 357ac7a515fSAndreas Gohr ); 358bae36d94SAndreas Gohr } 359bae36d94SAndreas Gohr 360bae36d94SAndreas Gohr if(actionOK('export_raw')) { 361ac7a515fSAndreas Gohr $head['link'][] = array( 362a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 363ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 364ac7a515fSAndreas Gohr ); 365f96fa415SAndreas Gohr } 366bae36d94SAndreas Gohr } 3676b13307fSandi 3686b13307fSandi // setup robot tags apropriate for different modes 3694f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3706b13307fSandi if($INFO['exists']) { 3716b13307fSandi //delay indexing: 3726b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 3737bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3746b13307fSandi } else { 3757bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3766b13307fSandi } 37701f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 37801f9be51SAnika Henke if ($ID == $conf['start']) { 37901f9be51SAnika Henke $canonicalUrl = DOKU_URL; 38001f9be51SAnika Henke } 38101f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3826b13307fSandi } else { 3837bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3846b13307fSandi } 3857a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3867bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3876b13307fSandi } else { 3887bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3896b13307fSandi } 3906b13307fSandi 391831800b8SAndreas Gohr // set metadata 392831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 393831800b8SAndreas Gohr // keywords (explicit or implicit) 394bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3957bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 396831800b8SAndreas Gohr } else { 3977bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 398831800b8SAndreas Gohr } 399831800b8SAndreas Gohr } 400831800b8SAndreas Gohr 40178a6aeb1SAndreas Gohr // load stylesheets 402ac7a515fSAndreas Gohr $head['link'][] = array( 403ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 404ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed 405ac7a515fSAndreas Gohr ); 406bad31ae9SAndreas Gohr 4078bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 408463d4a65SAndreas Gohr $json = new JSON(); 40972e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 410585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 41172e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 412c591aabeSAndreas Gohr } 41372e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 41485f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 4158bbcb611SAndreas Gohr 4168bbcb611SAndreas Gohr // load external javascript 417ac7a515fSAndreas Gohr $head['script'][] = array( 418ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 419ac7a515fSAndreas Gohr 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed 420ac7a515fSAndreas Gohr ); 4217bff22c0SAndreas Gohr 4227bff22c0SAndreas Gohr // trigger event here 423016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 42454e95700STom N Harris return true; 4257bff22c0SAndreas Gohr} 4267bff22c0SAndreas Gohr 4277bff22c0SAndreas Gohr/** 4287bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4297bff22c0SAndreas Gohr * 4307bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4317bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4327bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4337bff22c0SAndreas Gohr * 434*42ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4351304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4367bff22c0SAndreas Gohr * 4377bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 438*42ea7f44SGerrit Uitslag * 439*42ea7f44SGerrit Uitslag * @param array $data 4407bff22c0SAndreas Gohr */ 4417bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4427bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 4437bff22c0SAndreas Gohr foreach($inst as $attr) { 4447bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 44526afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 446e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 44709f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 448e226efe1SAndreas Gohr $attr['_data']. 44909f791c4SDominik Eckelmann "\n/*!]]>*/"; 450e226efe1SAndreas Gohr 4511304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4527bff22c0SAndreas Gohr } else { 4537bff22c0SAndreas Gohr echo '/>'; 4547bff22c0SAndreas Gohr } 4557bff22c0SAndreas Gohr echo "\n"; 4567bff22c0SAndreas Gohr } 4577bff22c0SAndreas Gohr } 4586b13307fSandi} 4596b13307fSandi 4606b13307fSandi/** 4616b13307fSandi * Print a link 4626b13307fSandi * 4635e163278SAndreas Gohr * Just builds a link. 4646b13307fSandi * 4656b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 466*42ea7f44SGerrit Uitslag * 467*42ea7f44SGerrit Uitslag * @param string $url 468*42ea7f44SGerrit Uitslag * @param string $name 469*42ea7f44SGerrit Uitslag * @param string $more 470*42ea7f44SGerrit Uitslag * @param bool $return return html 471*42ea7f44SGerrit Uitslag * @return bool|string html or true 4726b13307fSandi */ 4731af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 47401f17825SAnika Henke $out = '<a href="'.$url.'" '; 4751af98a77SAnika Henke if($more) $out .= ' '.$more; 4761af98a77SAnika Henke $out .= ">$name</a>"; 4771af98a77SAnika Henke if($return) return $out; 4781af98a77SAnika Henke print $out; 47954e95700STom N Harris return true; 4806b13307fSandi} 4816b13307fSandi 4826b13307fSandi/** 48355efc227SAndreas Gohr * Prints a link to a WikiPage 48455efc227SAndreas Gohr * 48555efc227SAndreas Gohr * Wrapper around html_wikilink 48655efc227SAndreas Gohr * 48755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 488*42ea7f44SGerrit Uitslag * 489*42ea7f44SGerrit Uitslag * @param string $id page id 490*42ea7f44SGerrit Uitslag * @param string|null $name the name of the link 491*42ea7f44SGerrit Uitslag * @return bool 49255efc227SAndreas Gohr */ 4930b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 494d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 49554e95700STom N Harris return true; 49655efc227SAndreas Gohr} 49755efc227SAndreas Gohr 49855efc227SAndreas Gohr/** 499a3ec5f4aSmatthiasgrimm * get the parent page 500a3ec5f4aSmatthiasgrimm * 501a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 502a3ec5f4aSmatthiasgrimm * returns false if none is available 503a3ec5f4aSmatthiasgrimm * 504377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 505*42ea7f44SGerrit Uitslag * 506*42ea7f44SGerrit Uitslag * @param string $id page id 507*42ea7f44SGerrit Uitslag * @return false|string 508a3ec5f4aSmatthiasgrimm */ 509377f9e97SAndreas Gohrfunction tpl_getparent($id) { 510377f9e97SAndreas Gohr $parent = getNS($id).':'; 511377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 512a197105eSmatthiasgrimm if($parent == $id) { 513a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 514a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 515a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 516377f9e97SAndreas Gohr if($parent == $id) return false; 517a197105eSmatthiasgrimm } 518377f9e97SAndreas Gohr return $parent; 519a3ec5f4aSmatthiasgrimm} 520a3ec5f4aSmatthiasgrimm 521a3ec5f4aSmatthiasgrimm/** 5226b13307fSandi * Print one of the buttons 5236b13307fSandi * 524a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 525a453d131SAdrian Lang * @see tpl_get_action 526e0c26282SGerrit Uitslag * 527e0c26282SGerrit Uitslag * @param string $type 528e0c26282SGerrit Uitslag * @param bool $return 529e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5306b13307fSandi */ 5311af98a77SAnika Henkefunction tpl_button($type, $return = false) { 532a453d131SAdrian Lang $data = tpl_get_action($type); 533a453d131SAdrian Lang if($data === false) { 534a453d131SAdrian Lang return false; 535a453d131SAdrian Lang } elseif(!is_array($data)) { 536a453d131SAdrian Lang $out = sprintf($data, 'button'); 537409d7af7SAndreas Gohr } else { 538ac7a515fSAndreas Gohr /** 539ac7a515fSAndreas Gohr * @var string $accesskey 540ac7a515fSAndreas Gohr * @var string $id 541ac7a515fSAndreas Gohr * @var string $method 542ac7a515fSAndreas Gohr * @var array $params 543ac7a515fSAndreas Gohr */ 544a453d131SAdrian Lang extract($data); 545a453d131SAdrian Lang if($id === '#dokuwiki__top') { 546a453d131SAdrian Lang $out = html_topbtn(); 547409d7af7SAndreas Gohr } else { 548a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 549409d7af7SAndreas Gohr } 550409d7af7SAndreas Gohr } 5511af98a77SAnika Henke if($return) return $out; 552a453d131SAdrian Lang echo $out; 553a453d131SAdrian Lang return true; 5546b13307fSandi} 5556b13307fSandi 5566b13307fSandi/** 557ed630903Sandi * Like the action buttons but links 558ed630903Sandi * 559a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 560a453d131SAdrian Lang * @see tpl_get_action 561e0c26282SGerrit Uitslag * 562*42ea7f44SGerrit Uitslag * @param string $type action command 563e0c26282SGerrit Uitslag * @param string $pre prefix of link 564e0c26282SGerrit Uitslag * @param string $suf suffix of link 565e0c26282SGerrit Uitslag * @param string $inner innerHML of link 566e0c26282SGerrit Uitslag * @param bool $return 567e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 568a453d131SAdrian Lang */ 569a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 570a453d131SAdrian Lang global $lang; 571a453d131SAdrian Lang $data = tpl_get_action($type); 572a453d131SAdrian Lang if($data === false) { 573a453d131SAdrian Lang return false; 574a453d131SAdrian Lang } elseif(!is_array($data)) { 575a453d131SAdrian Lang $out = sprintf($data, 'link'); 576a453d131SAdrian Lang } else { 577ac7a515fSAndreas Gohr /** 578ac7a515fSAndreas Gohr * @var string $accesskey 579ac7a515fSAndreas Gohr * @var string $id 580ac7a515fSAndreas Gohr * @var string $method 581b1af9014SChristopher Smith * @var bool $nofollow 582ac7a515fSAndreas Gohr * @var array $params 583becfa414SGerrit Uitslag * @var string $replacement 584ac7a515fSAndreas Gohr */ 585a453d131SAdrian Lang extract($data); 586a453d131SAdrian Lang if(strpos($id, '#') === 0) { 587a453d131SAdrian Lang $linktarget = $id; 588a453d131SAdrian Lang } else { 589a453d131SAdrian Lang $linktarget = wl($id, $params); 590a453d131SAdrian Lang } 591a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 592becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 593becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 594becfa414SGerrit Uitslag } 595c7e90e3fSAnika Henke $akey = $addTitle = ''; 596c7e90e3fSAnika Henke if($accesskey) { 597c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 598c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 599c7e90e3fSAnika Henke } 600b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 601ac7a515fSAndreas Gohr $out = tpl_link( 602ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 603a453d131SAdrian Lang 'class="action '.$type.'" '. 604b1af9014SChristopher Smith $akey.$rel. 605e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 606ac7a515fSAndreas Gohr ); 607a453d131SAdrian Lang } 608a453d131SAdrian Lang if($return) return $out; 609a453d131SAdrian Lang echo $out; 610a453d131SAdrian Lang return true; 611a453d131SAdrian Lang} 612a453d131SAdrian Lang 613a453d131SAdrian Lang/** 614a453d131SAdrian Lang * Check the actions and get data for buttons and links 615ed630903Sandi * 616a453d131SAdrian Lang * Available actions are 617a453d131SAdrian Lang * 618a453d131SAdrian Lang * edit - edit/create/show/draft 619ed630903Sandi * history - old revisions 620ed630903Sandi * recent - recent changes 621a453d131SAdrian Lang * login - login/logout - if ACL enabled 622a453d131SAdrian Lang * profile - user profile (if logged in) 623ed630903Sandi * index - The index 624ed630903Sandi * admin - admin page - if enough rights 625a453d131SAdrian Lang * top - back to top 626a453d131SAdrian Lang * back - back to parent - if available 627bbd37938SAndreas Gohr * backlink - links to the list of backlinks 628a453d131SAdrian Lang * subscribe/subscription- subscribe/unsubscribe 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) { 638ed630903Sandi global $ID; 639ed630903Sandi global $INFO; 640ed630903Sandi global $REV; 641ed630903Sandi global $ACT; 642b1af9014SChristopher Smith global $conf; 643585bf44eSChristopher Smith /** @var Input $INPUT */ 644585bf44eSChristopher Smith global $INPUT; 645ed630903Sandi 64675e487e9SAndreas Gohr // check disabled actions and fix the badly named ones 647a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6484c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 649a453d131SAdrian Lang if(!actionOK($type)) return false; 650409d7af7SAndreas Gohr 651a453d131SAdrian Lang $accesskey = null; 6526709e843SAdrian Lang $id = $ID; 653a453d131SAdrian Lang $method = 'get'; 654a453d131SAdrian Lang $params = array('do' => $type); 655b1af9014SChristopher Smith $nofollow = true; 656becfa414SGerrit Uitslag $replacement = ''; 657ed630903Sandi switch($type) { 658ed630903Sandi case 'edit': 6590b17fdc6SAndreas Gohr // most complicated type - we need to decide on current action 660ed630903Sandi if($ACT == 'show' || $ACT == 'search') { 661a453d131SAdrian Lang $method = 'post'; 662ed630903Sandi if($INFO['writable']) { 663a453d131SAdrian Lang $accesskey = 'e'; 664b8a111f5SMichael Klier if(!empty($INFO['draft'])) { 6656709e843SAdrian Lang $type = 'draft'; 666a453d131SAdrian Lang $params['do'] = 'draft'; 667b8a111f5SMichael Klier } else { 668a453d131SAdrian Lang $params['rev'] = $REV; 669a453d131SAdrian Lang if(!$INFO['exists']) { 6706709e843SAdrian Lang $type = 'create'; 671ed630903Sandi } 672b8a111f5SMichael Klier } 673ed630903Sandi } else { 674a453d131SAdrian Lang if(!actionOK('source')) return false; //pseudo action 675a453d131SAdrian Lang $params['rev'] = $REV; 6766709e843SAdrian Lang $type = 'source'; 677a453d131SAdrian Lang $accesskey = 'v'; 678ed630903Sandi } 679ed630903Sandi } else { 680d30d4913SChristopher Smith $params = array('do' => ''); 6816709e843SAdrian Lang $type = 'show'; 682a453d131SAdrian Lang $accesskey = 'v'; 683ed630903Sandi } 6841af98a77SAnika Henke break; 685a453d131SAdrian Lang case 'revisions': 6866709e843SAdrian Lang $type = 'revs'; 687a453d131SAdrian Lang $accesskey = 'o'; 6881af98a77SAnika Henke break; 689ed630903Sandi case 'recent': 690a453d131SAdrian Lang $accesskey = 'r'; 6911af98a77SAnika Henke break; 692ed630903Sandi case 'index': 693a453d131SAdrian Lang $accesskey = 'x'; 694b1af9014SChristopher Smith // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 695b1af9014SChristopher Smith if ($conf['start'] == $ID && !$conf['sitemap']) { 696b1af9014SChristopher Smith $nofollow = false; 697b1af9014SChristopher Smith } 6981af98a77SAnika Henke break; 699ed630903Sandi case 'top': 700076f0d72SAnika Henke $accesskey = 't'; 701d30d4913SChristopher Smith $params = array('do' => ''); 702a453d131SAdrian Lang $id = '#dokuwiki__top'; 7031af98a77SAnika Henke break; 704a3ec5f4aSmatthiasgrimm case 'back': 705a453d131SAdrian Lang $parent = tpl_getparent($ID); 706a453d131SAdrian Lang if(!$parent) { 707a453d131SAdrian Lang return false; 708a3ec5f4aSmatthiasgrimm } 709a453d131SAdrian Lang $id = $parent; 710d30d4913SChristopher Smith $params = array('do' => ''); 711a453d131SAdrian Lang $accesskey = 'b'; 7121af98a77SAnika Henke break; 713becfa414SGerrit Uitslag case 'img_backto': 714becfa414SGerrit Uitslag $params = array(); 715becfa414SGerrit Uitslag $accesskey = 'b'; 716becfa414SGerrit Uitslag $replacement = $ID; 717becfa414SGerrit Uitslag break; 718ed630903Sandi case 'login': 719a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 720585bf44eSChristopher Smith if($INPUT->server->has('REMOTE_USER')) { 7213a48618aSAnika Henke if(!actionOK('logout')) { 7222380e8a8SAdrian Lang return false; 7232380e8a8SAdrian Lang } 724a453d131SAdrian Lang $params['do'] = 'logout'; 725a453d131SAdrian Lang $type = 'logout'; 726bf413a4eSAnika Henke } 727bf413a4eSAnika Henke break; 728bf413a4eSAnika Henke case 'register': 729585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 730bf413a4eSAnika Henke return false; 731bf413a4eSAnika Henke } 732bf413a4eSAnika Henke break; 733bf413a4eSAnika Henke case 'resendpwd': 734585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 735bf413a4eSAnika Henke return false; 736ed630903Sandi } 7371af98a77SAnika Henke break; 738ed630903Sandi case 'admin': 739a453d131SAdrian Lang if(!$INFO['ismanager']) { 740a453d131SAdrian Lang return false; 741c059e1a6SAndreas Gohr } 7421af98a77SAnika Henke break; 7431246e016SAndreas Gohr case 'revert': 744a453d131SAdrian Lang if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 745a453d131SAdrian Lang return false; 7461246e016SAndreas Gohr } 747a453d131SAdrian Lang $params['rev'] = $REV; 748a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 7491246e016SAndreas Gohr break; 7506709e843SAdrian Lang case 'subscribe': 751585bf44eSChristopher Smith if(!$INPUT->server->str('REMOTE_USER')) { 752a453d131SAdrian Lang return false; 753b158d625SSteven Danz } 7541af98a77SAnika Henke break; 755f00151b4Schris case 'backlink': 7561af98a77SAnika Henke break; 7578b06d178Schris case 'profile': 758585bf44eSChristopher Smith if(!$INPUT->server->has('REMOTE_USER')) { 759a453d131SAdrian Lang return false; 7608b06d178Schris } 7611af98a77SAnika Henke break; 762b9eb2e61SKate Arzamastseva case 'media': 763d08527abSAnika Henke $params['ns'] = getNS($ID); 764b9eb2e61SKate Arzamastseva break; 765becfa414SGerrit Uitslag case 'mediaManager': 766becfa414SGerrit Uitslag // View image in media manager 767becfa414SGerrit Uitslag global $IMG; 768becfa414SGerrit Uitslag $imgNS = getNS($IMG); 769becfa414SGerrit Uitslag $authNS = auth_quickaclcheck("$imgNS:*"); 770becfa414SGerrit Uitslag if ($authNS < AUTH_UPLOAD) { 771becfa414SGerrit Uitslag return false; 772becfa414SGerrit Uitslag } 773becfa414SGerrit Uitslag $params = array( 774becfa414SGerrit Uitslag 'ns' => $imgNS, 775becfa414SGerrit Uitslag 'image' => $IMG, 776becfa414SGerrit Uitslag 'do' => 'media' 777becfa414SGerrit Uitslag ); 778becfa414SGerrit Uitslag //$type = 'media'; 779becfa414SGerrit Uitslag break; 780ed630903Sandi default: 781a453d131SAdrian Lang return '[unknown %s type]'; 782ed630903Sandi } 783becfa414SGerrit Uitslag return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); 784ed630903Sandi} 785ed630903Sandi 786ed630903Sandi/** 78701f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 78801f17825SAnika Henke * 78901f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 790*42ea7f44SGerrit Uitslag * 791*42ea7f44SGerrit Uitslag * @param string $type action command 792ac7a515fSAndreas Gohr * @param bool $link link or form button? 793e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 794ac7a515fSAndreas Gohr * @param bool $return return or print 795ac7a515fSAndreas Gohr * @param string $pre prefix for links 796ac7a515fSAndreas Gohr * @param string $suf suffix for links 797ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 798ac7a515fSAndreas Gohr * @return bool|string 79901f17825SAnika Henke */ 800ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 80101f17825SAnika Henke $out = ''; 802ac7a515fSAndreas Gohr if($link) { 803e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 804ac7a515fSAndreas Gohr } else { 805e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 806ac7a515fSAndreas Gohr } 80701f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 80801f17825SAnika Henke 80901f17825SAnika Henke if($return) return $out; 81001f17825SAnika Henke print $out; 81101f17825SAnika Henke return $out ? true : false; 81201f17825SAnika Henke} 81301f17825SAnika Henke 81401f17825SAnika Henke/** 8156b13307fSandi * Print the search form 8166b13307fSandi * 81772645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 81872645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 81972645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 82072645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 82172645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 82272645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 82372645b75SAndreas Gohr * 8246b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 825*42ea7f44SGerrit Uitslag * 826ac7a515fSAndreas Gohr * @param bool $ajax 827ac7a515fSAndreas Gohr * @param bool $autocomplete 828ac7a515fSAndreas Gohr * @return bool 8296b13307fSandi */ 83072645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 8316b13307fSandi global $lang; 832c1e3b7d9Smatthiasgrimm global $ACT; 833ad4aaef7SAndreas Gohr global $QUERY; 834c1e3b7d9Smatthiasgrimm 835670ff54eSchris // don't print the search form if search action has been disabled 83664276bbcSarbrk1 if(!actionOK('search')) return false; 837670ff54eSchris 8389805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 8396b13307fSandi print '<input type="hidden" name="do" value="search" />'; 840c1e3b7d9Smatthiasgrimm print '<input type="text" '; 841ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 84272645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 84307493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 84411ea018fSAndreas Gohr print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 84524a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 8464beabca9SAnika Henke print '</div></form>'; 84754e95700STom N Harris return true; 8486b13307fSandi} 8496b13307fSandi 8506b13307fSandi/** 8516b13307fSandi * Print the breadcrumbs trace 8526b13307fSandi * 8536b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 854*42ea7f44SGerrit Uitslag * 855ac7a515fSAndreas Gohr * @param string $sep Separator between entries 856ac7a515fSAndreas Gohr * @return bool 8576b13307fSandi */ 858e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 8596b13307fSandi global $lang; 8606b13307fSandi global $conf; 8616b13307fSandi 8626b13307fSandi //check if enabled 863359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 8646b13307fSandi 8656b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 866265e3787Sandi 8672979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 868265e3787Sandi 86940eb54bbSjan //render crumbs, highlight the last one 870fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 87140eb54bbSjan $last = count($crumbs); 87240eb54bbSjan $i = 0; 873a77f5846Sjan foreach($crumbs as $id => $name) { 87440eb54bbSjan $i++; 8752979a10bSKatriel Traum echo $crumbs_sep; 87692795d04Sandi if($i == $last) print '<span class="curid">'; 877d317fb5dSAnika Henke print '<bdi>'; 878e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 879d317fb5dSAnika Henke print '</bdi>'; 88092795d04Sandi if($i == $last) print '</span>'; 8816b13307fSandi } 88254e95700STom N Harris return true; 8836b13307fSandi} 8846b13307fSandi 8856b13307fSandi/** 8861734437eSandi * Hierarchical breadcrumbs 8871734437eSandi * 88831e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8891734437eSandi * It only makes sense with a deep site structure. 8901734437eSandi * 8911734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 8926bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 89331e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 894f46c9e83SAnika Henke * @author <fredrik@averpil.com> 8956bd812dfSNigel McNie * @todo May behave strangely in RTL languages 896*42ea7f44SGerrit Uitslag * 897ac7a515fSAndreas Gohr * @param string $sep Separator between entries 898ac7a515fSAndreas Gohr * @return bool 8991734437eSandi */ 900e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') { 9011734437eSandi global $conf; 9021734437eSandi global $ID; 9031734437eSandi global $lang; 9041734437eSandi 90531e187f8SSean Coates // check if enabled 90654e95700STom N Harris if(!$conf['youarehere']) return false; 9071734437eSandi 9081734437eSandi $parts = explode(':', $ID); 909796bafb3SAndreas Gohr $count = count($parts); 9101734437eSandi 911fde860beSGerrit Uitslag echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 9121734437eSandi 9131734437eSandi // always print the startpage 914fca4df27SAnika Henke echo '<span class="home">'; 915e013f48dSAnika Henke tpl_pagelink(':'.$conf['start']); 916fca4df27SAnika Henke echo '</span>'; 917796bafb3SAndreas Gohr 918796bafb3SAndreas Gohr // print intermediate namespace links 919796bafb3SAndreas Gohr $part = ''; 920796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 921796bafb3SAndreas Gohr $part .= $parts[$i].':'; 922796bafb3SAndreas Gohr $page = $part; 923796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 924796bafb3SAndreas Gohr 925796bafb3SAndreas Gohr // output 926796bafb3SAndreas Gohr echo $sep; 927e013f48dSAnika Henke tpl_pagelink($page); 92831e187f8SSean Coates } 9291734437eSandi 930796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 931e013f48dSAnika Henke resolve_pageid('', $page, $exists); 932ac7a515fSAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 933796bafb3SAndreas Gohr $page = $part.$parts[$i]; 934ac7a515fSAndreas Gohr if($page == $conf['start']) return true; 935796bafb3SAndreas Gohr echo $sep; 936e013f48dSAnika Henke tpl_pagelink($page); 93754e95700STom N Harris return true; 9381734437eSandi} 9391734437eSandi 9401734437eSandi/** 9416b13307fSandi * Print info if the user is logged in 942a2488c3cSMatthias Grimm * and show full name in that case 9436b13307fSandi * 9446b13307fSandi * Could be enhanced with a profile link in future? 9456b13307fSandi * 9466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 947*42ea7f44SGerrit Uitslag * 948ac7a515fSAndreas Gohr * @return bool 9496b13307fSandi */ 9506b13307fSandifunction tpl_userinfo() { 9516b13307fSandi global $lang; 952585bf44eSChristopher Smith /** @var Input $INPUT */ 953585bf44eSChristopher Smith global $INPUT; 954585bf44eSChristopher Smith 955585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 956fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 95754e95700STom N Harris return true; 95854e95700STom N Harris } 95954e95700STom N Harris return false; 9606b13307fSandi} 9616b13307fSandi 9626b13307fSandi/** 9636b13307fSandi * Print some info about the current page 9646b13307fSandi * 9656b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 966*42ea7f44SGerrit Uitslag * 967ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 968ac7a515fSAndreas Gohr * @return bool|string 9696b13307fSandi */ 9704b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 9716b13307fSandi global $conf; 9726b13307fSandi global $lang; 9736b13307fSandi global $INFO; 974c6e92a3cSDavid Lorentsen global $ID; 975c6e92a3cSDavid Lorentsen 976c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 977ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 978ac7a515fSAndreas Gohr return false; 979ac7a515fSAndreas Gohr } 9806b13307fSandi 9816b13307fSandi // prepare date and path 9826b13307fSandi $fn = $INFO['filepath']; 9836b13307fSandi if(!$conf['fullpath']) { 984613bca54SAndreas Gohr if($INFO['rev']) { 98550fbebceSGina Haeussge $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 9866b13307fSandi } else { 98750fbebceSGina Haeussge $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 9886b13307fSandi } 9896b13307fSandi } 990bee6dc82Sandi $fn = utf8_decodeFN($fn); 991f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 9926b13307fSandi 993faecdfdfSAndreas Gohr // print it 994faecdfdfSAndreas Gohr if($INFO['exists']) { 9954b0d3916SAndreas Gohr $out = ''; 996d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 997e260f93bSAnika Henke $out .= ' · '; 9984b0d3916SAndreas Gohr $out .= $lang['lastmod']; 999fde860beSGerrit Uitslag $out .= ' '; 10004b0d3916SAndreas Gohr $out .= $date; 10016b13307fSandi if($INFO['editor']) { 10024b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 1003d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 10045aa52fafSBen Coburn } else { 10054b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 10066b13307fSandi } 10076b13307fSandi if($INFO['locked']) { 1008e260f93bSAnika Henke $out .= ' · '; 10094b0d3916SAndreas Gohr $out .= $lang['lockedby']; 1010fde860beSGerrit Uitslag $out .= ' '; 1011d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 10126b13307fSandi } 10134b0d3916SAndreas Gohr if($ret) { 10144b0d3916SAndreas Gohr return $out; 10154b0d3916SAndreas Gohr } else { 10164b0d3916SAndreas Gohr echo $out; 101754e95700STom N Harris return true; 10186b13307fSandi } 10194b0d3916SAndreas Gohr } 102054e95700STom N Harris return false; 10216b13307fSandi} 10226b13307fSandi 1023820fa24bSandi/** 1024a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 102587c434ceSAndreas Gohr * 102687c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 1027a6598f23SBen Coburn * the given ID is used. 102887c434ceSAndreas Gohr * 102987c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1030*42ea7f44SGerrit Uitslag * 1031ac7a515fSAndreas Gohr * @param string $id page id 1032ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 1033ac7a515fSAndreas Gohr * @return bool|string 103487c434ceSAndreas Gohr */ 1035a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 103687c434ceSAndreas Gohr if(is_null($id)) { 103787c434ceSAndreas Gohr global $ID; 103887c434ceSAndreas Gohr $id = $ID; 103987c434ceSAndreas Gohr } 104087c434ceSAndreas Gohr 104187c434ceSAndreas Gohr $name = $id; 1042fe9ec250SChris Smith if(useHeading('navigation')) { 104387c434ceSAndreas Gohr $title = p_get_first_heading($id); 104487c434ceSAndreas Gohr if($title) $name = $title; 104587c434ceSAndreas Gohr } 1046a6598f23SBen Coburn 1047a6598f23SBen Coburn if($ret) { 1048a6598f23SBen Coburn return hsc($name); 1049a6598f23SBen Coburn } else { 105087c434ceSAndreas Gohr print hsc($name); 105154e95700STom N Harris return true; 105287c434ceSAndreas Gohr } 1053a6598f23SBen Coburn} 1054340756e4Sandi 105555efc227SAndreas Gohr/** 105655efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 105755efc227SAndreas Gohr * 105855efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 105955efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 106055efc227SAndreas Gohr * 106155efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 106255efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 106355efc227SAndreas Gohr * to the names of the latter one) 106455efc227SAndreas Gohr * 10653df72098SAndreas Gohr * Only allowed in: detail.php 106655efc227SAndreas Gohr * 106755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1068*42ea7f44SGerrit Uitslag * 1069ac7a515fSAndreas Gohr * @param array $tags tags to try 1070ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1071e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1072ac7a515fSAndreas Gohr * @return string 107355efc227SAndreas Gohr */ 10743df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 107555efc227SAndreas Gohr // Init Exif Reader 107655efc227SAndreas Gohr global $SRC; 10773df72098SAndreas Gohr 10783df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10793df72098SAndreas Gohr 108055efc227SAndreas Gohr static $meta = null; 10813df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 108255efc227SAndreas Gohr if($meta === false) return $alt; 108388945224SChristopher Smith $info = cleanText($meta->getField($tags)); 108455efc227SAndreas Gohr if($info == false) return $alt; 108555efc227SAndreas Gohr return $info; 108655efc227SAndreas Gohr} 108755efc227SAndreas Gohr 108855efc227SAndreas Gohr/** 1089becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1090becfa414SGerrit Uitslag * 1091becfa414SGerrit Uitslag * @return string html of description list 1092becfa414SGerrit Uitslag */ 1093becfa414SGerrit Uitslagfunction tpl_img_meta() { 1094becfa414SGerrit Uitslag global $lang; 1095becfa414SGerrit Uitslag 1096becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1097becfa414SGerrit Uitslag 1098becfa414SGerrit Uitslag echo '<dl>'; 1099becfa414SGerrit Uitslag foreach($tags as $tag) { 1100becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1101fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1102becfa414SGerrit Uitslag 1103fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1104becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1105becfa414SGerrit Uitslag echo dformat($tag['value']); 1106becfa414SGerrit Uitslag } else { 1107becfa414SGerrit Uitslag echo hsc($tag['value']); 1108becfa414SGerrit Uitslag } 1109becfa414SGerrit Uitslag echo '</dd>'; 1110becfa414SGerrit Uitslag } 1111becfa414SGerrit Uitslag echo '</dl>'; 1112becfa414SGerrit Uitslag} 1113becfa414SGerrit Uitslag 1114becfa414SGerrit Uitslag/** 1115becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1116becfa414SGerrit Uitslag * 1117becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1118becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1119becfa414SGerrit Uitslag * - string type type of value 1120becfa414SGerrit Uitslag * - string value tag value (unescaped) 1121becfa414SGerrit Uitslag */ 1122becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1123becfa414SGerrit Uitslag 1124becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1125becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 1126becfa414SGerrit Uitslag if(@file_exists($config_file)) { 1127becfa414SGerrit Uitslag include($config_file); 1128becfa414SGerrit Uitslag } 1129becfa414SGerrit Uitslag } 1130becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1131becfa414SGerrit Uitslag 1132becfa414SGerrit Uitslag $tags = array(); 1133becfa414SGerrit Uitslag foreach($fields as $tag){ 1134becfa414SGerrit Uitslag $t = array(); 1135becfa414SGerrit Uitslag if (!empty($tag[0])) { 1136becfa414SGerrit Uitslag $t = array($tag[0]); 1137becfa414SGerrit Uitslag } 1138becfa414SGerrit Uitslag if(is_array($tag[3])) { 1139becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1140becfa414SGerrit Uitslag } 1141becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1142becfa414SGerrit Uitslag if ($value) { 1143becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1144becfa414SGerrit Uitslag } 1145becfa414SGerrit Uitslag } 1146becfa414SGerrit Uitslag return $tags; 1147becfa414SGerrit Uitslag} 1148becfa414SGerrit Uitslag 1149becfa414SGerrit Uitslag/** 115055efc227SAndreas Gohr * Prints the image with a link to the full sized version 115155efc227SAndreas Gohr * 115255efc227SAndreas Gohr * Only allowed in: detail.php 1153a02d2933SAndreas Gohr * 1154ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1155a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1156a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1157a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1158a02d2933SAndreas Gohr * @param $params array - additional image attributes 1159*42ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 116055efc227SAndreas Gohr */ 1161a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 116255efc227SAndreas Gohr global $IMG; 1163585bf44eSChristopher Smith /** @var Input $INPUT */ 1164ac7a515fSAndreas Gohr global $INPUT; 116555efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 116655efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 116755efc227SAndreas Gohr 116855efc227SAndreas Gohr //resize to given max values 116923a34783SAndreas Gohr $ratio = 1; 117023a34783SAndreas Gohr if($w >= $h) { 1171f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 117255efc227SAndreas Gohr $ratio = $maxwidth / $w; 1173f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 117455efc227SAndreas Gohr $ratio = $maxheight / $h; 117555efc227SAndreas Gohr } 117655efc227SAndreas Gohr } else { 1177f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 117855efc227SAndreas Gohr $ratio = $maxheight / $h; 1179f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 118055efc227SAndreas Gohr $ratio = $maxwidth / $w; 118155efc227SAndreas Gohr } 118255efc227SAndreas Gohr } 118355efc227SAndreas Gohr if($ratio) { 118455efc227SAndreas Gohr $w = floor($ratio * $w); 118555efc227SAndreas Gohr $h = floor($ratio * $h); 118655efc227SAndreas Gohr } 118755efc227SAndreas Gohr 11886de3759aSAndreas Gohr //prepare URLs 1189ac7a515fSAndreas Gohr $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&'); 1190ac7a515fSAndreas Gohr $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&'); 119155efc227SAndreas Gohr 11922684e50aSAndreas Gohr //prepare attributes 119355efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1194a02d2933SAndreas Gohr if(is_null($params)) { 11952684e50aSAndreas Gohr $p = array(); 1196a02d2933SAndreas Gohr } else { 1197a02d2933SAndreas Gohr $p = $params; 1198a02d2933SAndreas Gohr } 11992684e50aSAndreas Gohr if($w) $p['width'] = $w; 12002684e50aSAndreas Gohr if($h) $p['height'] = $h; 12012684e50aSAndreas Gohr $p['class'] = 'img_detail'; 12022684e50aSAndreas Gohr if($alt) { 12032684e50aSAndreas Gohr $p['alt'] = $alt; 12042684e50aSAndreas Gohr $p['title'] = $alt; 12052684e50aSAndreas Gohr } else { 12062684e50aSAndreas Gohr $p['alt'] = ''; 12072684e50aSAndreas Gohr } 1208a02d2933SAndreas Gohr $p['src'] = $src; 120955efc227SAndreas Gohr 1210a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1211a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1212a02d2933SAndreas Gohr} 1213a02d2933SAndreas Gohr 1214a02d2933SAndreas Gohr/** 1215a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1216ac7a515fSAndreas Gohr * 1217ac7a515fSAndreas Gohr * @param array $data 1218ac7a515fSAndreas Gohr * @return bool 1219a02d2933SAndreas Gohr */ 1220ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 122159f3611bSAnika Henke global $lang; 1222a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1223a02d2933SAndreas Gohr 122459f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1225a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1226a02d2933SAndreas Gohr if($data['url']) print '</a>'; 122754e95700STom N Harris return true; 122855efc227SAndreas Gohr} 122955efc227SAndreas Gohr 12307367b368SAndreas Gohr/** 1231881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12327367b368SAndreas Gohr * 12337367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 12347367b368SAndreas Gohr * template 1235ac7a515fSAndreas Gohr * 1236ac7a515fSAndreas Gohr * @return bool 12377367b368SAndreas Gohr */ 12387367b368SAndreas Gohrfunction tpl_indexerWebBug() { 12397367b368SAndreas Gohr global $ID; 12401dad36f5SAndreas Gohr 12417367b368SAndreas Gohr $p = array(); 1242b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1243e68c51baSAndreas Gohr '&'.time(); 1244881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12457367b368SAndreas Gohr $p['height'] = 1; 12467367b368SAndreas Gohr $p['alt'] = ''; 12477367b368SAndreas Gohr $att = buildAttributes($p); 12487367b368SAndreas Gohr print "<img $att />"; 124954e95700STom N Harris return true; 12507367b368SAndreas Gohr} 12517367b368SAndreas Gohr 125278d4e784SEsther Brunner/** 125378d4e784SEsther Brunner * tpl_getConf($id) 125478d4e784SEsther Brunner * 125578d4e784SEsther Brunner * use this function to access template configuration variables 1256ac7a515fSAndreas Gohr * 125717448fb8SChristopher Smith * @param string $id name of the value to access 125817448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 125917448fb8SChristopher Smith * @return mixed 126078d4e784SEsther Brunner */ 126117448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 126278d4e784SEsther Brunner global $conf; 126317566ac6SAdrian Lang static $tpl_configloaded = false; 126478d4e784SEsther Brunner 126578d4e784SEsther Brunner $tpl = $conf['template']; 126678d4e784SEsther Brunner 126778d4e784SEsther Brunner if(!$tpl_configloaded) { 126878d4e784SEsther Brunner $tconf = tpl_loadConfig(); 126978d4e784SEsther Brunner if($tconf !== false) { 127078d4e784SEsther Brunner foreach($tconf as $key => $value) { 127178d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 127278d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 127378d4e784SEsther Brunner } 127478d4e784SEsther Brunner $tpl_configloaded = true; 127578d4e784SEsther Brunner } 127678d4e784SEsther Brunner } 127778d4e784SEsther Brunner 127817448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 127978d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 128078d4e784SEsther Brunner } 128178d4e784SEsther Brunner 128217448fb8SChristopher Smith return $notset; 128317448fb8SChristopher Smith} 128417448fb8SChristopher Smith 128578d4e784SEsther Brunner/** 128678d4e784SEsther Brunner * tpl_loadConfig() 1287ac7a515fSAndreas Gohr * 128878d4e784SEsther Brunner * reads all template configuration variables 128978d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1290ac7a515fSAndreas Gohr * 1291ac7a515fSAndreas Gohr * @return array 129278d4e784SEsther Brunner */ 129378d4e784SEsther Brunnerfunction tpl_loadConfig() { 129478d4e784SEsther Brunner 1295c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 129678d4e784SEsther Brunner $conf = array(); 129778d4e784SEsther Brunner 129878d4e784SEsther Brunner if(!@file_exists($file)) return false; 129978d4e784SEsther Brunner 130078d4e784SEsther Brunner // load default config file 130178d4e784SEsther Brunner include($file); 130278d4e784SEsther Brunner 130378d4e784SEsther Brunner return $conf; 130478d4e784SEsther Brunner} 130578d4e784SEsther Brunner 130617566ac6SAdrian Lang// language methods 130717566ac6SAdrian Lang/** 130817566ac6SAdrian Lang * tpl_getLang($id) 130917566ac6SAdrian Lang * 131017566ac6SAdrian Lang * use this function to access template language variables 1311*42ea7f44SGerrit Uitslag * 1312*42ea7f44SGerrit Uitslag * @param string $id key of language string 1313*42ea7f44SGerrit Uitslag * @return string 131417566ac6SAdrian Lang */ 131517566ac6SAdrian Langfunction tpl_getLang($id) { 131617566ac6SAdrian Lang static $lang = array(); 131717566ac6SAdrian Lang 131817566ac6SAdrian Lang if(count($lang) === 0) { 1319c4766956SAndreas Gohr $path = tpl_incdir().'lang/'; 132017566ac6SAdrian Lang 132117566ac6SAdrian Lang $lang = array(); 132217566ac6SAdrian Lang 132317566ac6SAdrian Lang global $conf; // definitely don't invoke "global $lang" 132417566ac6SAdrian Lang // don't include once 132517566ac6SAdrian Lang @include($path.'en/lang.php'); 132617566ac6SAdrian Lang if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); 132717566ac6SAdrian Lang } 132817566ac6SAdrian Lang 132917566ac6SAdrian Lang return $lang[$id]; 133017566ac6SAdrian Lang} 133117566ac6SAdrian Lang 13323df72098SAndreas Gohr/** 1333c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1334e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1335e8ec13b9SKlap-in * 1336e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1337e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1338e8ec13b9SKlap-in */ 1339e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1340c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1341e8ec13b9SKlap-in} 1342e8ec13b9SKlap-in 1343e8ec13b9SKlap-in/** 1344c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 1345*42ea7f44SGerrit Uitslag * 1346*42ea7f44SGerrit Uitslag * @param string $id id of localized text 1347*42ea7f44SGerrit Uitslag * @return string wiki text 1348e8ec13b9SKlap-in */ 1349c5c17fdaSKlap-infunction tpl_localeFN($id) { 1350e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1351e8ec13b9SKlap-in global $conf; 1352e8ec13b9SKlap-in $file = DOKU_CONF.'/template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 1353e8ec13b9SKlap-in if (!@file_exists($file)){ 1354e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 1355e8ec13b9SKlap-in if(!@file_exists($file)){ 1356e8ec13b9SKlap-in //fall back to english 1357e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1358e8ec13b9SKlap-in } 1359e8ec13b9SKlap-in } 1360e8ec13b9SKlap-in return $file; 1361e8ec13b9SKlap-in} 1362e8ec13b9SKlap-in 1363e8ec13b9SKlap-in/** 13643df72098SAndreas Gohr * prints the "main content" in the mediamanger popup 13653df72098SAndreas Gohr * 13663df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13673df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13683df72098SAndreas Gohr * a message of referencing pages 13693df72098SAndreas Gohr * 13703df72098SAndreas Gohr * Only allowed in mediamanager.php 13713df72098SAndreas Gohr * 1372c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1373c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 1374*42ea7f44SGerrit Uitslag * @param string $sort 1375*42ea7f44SGerrit Uitslag 13763df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13773df72098SAndreas Gohr */ 137800e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 13793df72098SAndreas Gohr global $IMG; 13803df72098SAndreas Gohr global $AUTH; 13813df72098SAndreas Gohr global $INUSE; 13823df72098SAndreas Gohr global $NS; 13833df72098SAndreas Gohr global $JUMPTO; 1384585bf44eSChristopher Smith /** @var Input $INPUT */ 1385ac7a515fSAndreas Gohr global $INPUT; 13863df72098SAndreas Gohr 1387ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1388c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1389c182313eSAndreas Gohr 1390c182313eSAndreas Gohr if(!$do) { 1391ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1392c182313eSAndreas Gohr $do = 'metaform'; 1393c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1394c182313eSAndreas Gohr $do = 'filesinuse'; 1395c182313eSAndreas Gohr } else { 1396c182313eSAndreas Gohr $do = 'filelist'; 1397c182313eSAndreas Gohr } 1398c182313eSAndreas Gohr } 1399c182313eSAndreas Gohr 1400c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1401c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1402c182313eSAndreas Gohr $data = array('do' => $do); 1403c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1404c182313eSAndreas Gohr if($evt->advise_before()) { 1405c182313eSAndreas Gohr $do = $data['do']; 140630fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1407c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1408c182313eSAndreas Gohr } elseif($do == 'filelist') { 140900e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1410c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1411ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1412c182313eSAndreas Gohr } else { 1413c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1414c182313eSAndreas Gohr } 1415c182313eSAndreas Gohr } 1416c182313eSAndreas Gohr $evt->advise_after(); 1417c182313eSAndreas Gohr unset($evt); 1418c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1419c182313eSAndreas Gohr 14203df72098SAndreas Gohr} 14213df72098SAndreas Gohr 14223df72098SAndreas Gohr/** 1423d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1424d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1425d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1426d9162c6cSKate Arzamastseva * 1427d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1428d9162c6cSKate Arzamastseva */ 1429035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1430d9162c6cSKate Arzamastseva global $AUTH; 1431d9162c6cSKate Arzamastseva global $NS; 1432d9162c6cSKate Arzamastseva global $JUMPTO; 143395b451bcSAdrian Lang global $lang; 1434585bf44eSChristopher Smith /** @var Input $INPUT */ 1435ac7a515fSAndreas Gohr global $INPUT; 1436d9162c6cSKate Arzamastseva 1437ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1438e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1439ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1440d9162c6cSKate Arzamastseva 144194add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 144295b451bcSAdrian Lang 1443ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 144423846a98SKate Arzamastseva 144594add303SAnika Henke echo '<div class="panelHeader">'.NL; 144695b451bcSAdrian Lang echo '<h3>'; 1447026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1448c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 144994add303SAnika Henke echo '</h3>'.NL; 145095b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 145195b451bcSAdrian Lang media_tab_files_options(); 145223846a98SKate Arzamastseva } 145394add303SAnika Henke echo '</div>'.NL; 1454d9162c6cSKate Arzamastseva 145594add303SAnika Henke echo '<div class="panelContent">'.NL; 145695b451bcSAdrian Lang if($opened_tab == 'files') { 145795b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 145895b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 145995b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 146095b451bcSAdrian Lang } elseif($opened_tab == 'search') { 146195b451bcSAdrian Lang media_tab_search($NS, $AUTH); 146295b451bcSAdrian Lang } 146394add303SAnika Henke echo '</div>'.NL; 1464d9162c6cSKate Arzamastseva} 1465d9162c6cSKate Arzamastseva 1466d9162c6cSKate Arzamastseva/** 1467d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1468d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1469d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1470d9162c6cSKate Arzamastseva * list of file revisions 1471d9162c6cSKate Arzamastseva * 1472d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1473d9162c6cSKate Arzamastseva */ 1474035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1475e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1476585bf44eSChristopher Smith /** @var Input $INPUT */ 1477585bf44eSChristopher Smith global $INPUT; 1478d9162c6cSKate Arzamastseva 147992cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1480ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 14816dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1482e8a2a143SMichael Hamann $ns = getNS($image); 1483ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 14841eeeced2SKate Arzamastseva 1485ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1486e5d185e1SKate Arzamastseva 1487e5d185e1SKate Arzamastseva $tab_array = array('view'); 1488ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1489e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1490e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1491e5d185e1SKate Arzamastseva } 1492e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1493e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1494e5d185e1SKate Arzamastseva } 1495e5d185e1SKate Arzamastseva 1496e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1497ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 149823846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1499d9162c6cSKate Arzamastseva 1500ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 150123846a98SKate Arzamastseva 150259f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1503ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 150495b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 150595b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 150600c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 150708317413SAdrian Lang if($opened_tab === 'view' && $rev) { 150808317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 150908317413SAdrian Lang } else { 1510026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 151108317413SAdrian Lang } 1512b8a84c03SAndreas Gohr 151394add303SAnika Henke echo '</h3></div>'.NL; 151495b451bcSAdrian Lang 151594add303SAnika Henke echo '<div class="panelContent">'.NL; 151695b451bcSAdrian Lang 151723846a98SKate Arzamastseva if($opened_tab == 'view') { 1518e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 151923846a98SKate Arzamastseva 152092cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1521e8a2a143SMichael Hamann media_tab_edit($image, $ns); 152223846a98SKate Arzamastseva 1523e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1524e8a2a143SMichael Hamann media_tab_history($image, $ns); 152523846a98SKate Arzamastseva } 152695b451bcSAdrian Lang 152794add303SAnika Henke echo '</div>'.NL; 1528d9162c6cSKate Arzamastseva} 1529d9162c6cSKate Arzamastseva 1530d9162c6cSKate Arzamastseva/** 15313df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup 15323df72098SAndreas Gohr * 15333df72098SAndreas Gohr * Only allowed in mediamanager.php 15343df72098SAndreas Gohr * 15353df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15363df72098SAndreas Gohr */ 1537fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 15383df72098SAndreas Gohr global $NS; 153923846a98SKate Arzamastseva ptln('<div id="media__tree">'); 15403df72098SAndreas Gohr media_nstree($NS); 15413df72098SAndreas Gohr ptln('</div>'); 15423df72098SAndreas Gohr} 15433df72098SAndreas Gohr 1544a00de5b5SAndreas Gohr/** 1545a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1546a00de5b5SAndreas Gohr * 1547a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1548a00de5b5SAndreas Gohr * 1549a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1550*42ea7f44SGerrit Uitslag * 1551*42ea7f44SGerrit Uitslag * @param string $empty empty option label 1552*42ea7f44SGerrit Uitslag * @param string $button submit button label 1553a00de5b5SAndreas Gohr */ 1554a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1555a00de5b5SAndreas Gohr global $ID; 1556a00de5b5SAndreas Gohr global $REV; 1557a00de5b5SAndreas Gohr global $lang; 1558585bf44eSChristopher Smith /** @var Input $INPUT */ 1559585bf44eSChristopher Smith global $INPUT; 1560a00de5b5SAndreas Gohr 1561e63eccffSAndreas Gohr echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 15623b9a3b55SAnika Henke echo '<div class="no">'; 1563a00de5b5SAndreas Gohr echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1564a00de5b5SAndreas Gohr if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1565585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 1566a00de5b5SAndreas Gohr echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 156761efcda1SChristopher Smith } 1568a00de5b5SAndreas Gohr 15695f17c394SAnika Henke echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1570a00de5b5SAndreas Gohr echo '<option value="">'.$empty.'</option>'; 1571a00de5b5SAndreas Gohr 157261917024SAnika Henke echo '<optgroup label="'.$lang['page_tools'].'">'; 1573396c218fSAndreas Gohr $act = tpl_get_action('edit'); 1574396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1575a00de5b5SAndreas Gohr 1576396c218fSAndreas Gohr $act = tpl_get_action('revert'); 1577396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1578396c218fSAndreas Gohr 15793b9a3b55SAnika Henke $act = tpl_get_action('revisions'); 15803b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15813b9a3b55SAnika Henke 1582396c218fSAndreas Gohr $act = tpl_get_action('backlink'); 1583396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15843b9a3b55SAnika Henke 15853b9a3b55SAnika Henke $act = tpl_get_action('subscribe'); 15863b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1587a00de5b5SAndreas Gohr echo '</optgroup>'; 1588a00de5b5SAndreas Gohr 158961917024SAnika Henke echo '<optgroup label="'.$lang['site_tools'].'">'; 1590396c218fSAndreas Gohr $act = tpl_get_action('recent'); 1591396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1592396c218fSAndreas Gohr 15933b9a3b55SAnika Henke $act = tpl_get_action('media'); 15943b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 15953b9a3b55SAnika Henke 1596396c218fSAndreas Gohr $act = tpl_get_action('index'); 1597396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1598a00de5b5SAndreas Gohr echo '</optgroup>'; 1599a00de5b5SAndreas Gohr 160061917024SAnika Henke echo '<optgroup label="'.$lang['user_tools'].'">'; 1601396c218fSAndreas Gohr $act = tpl_get_action('login'); 1602396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1603a00de5b5SAndreas Gohr 16043b9a3b55SAnika Henke $act = tpl_get_action('register'); 1605396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1606a00de5b5SAndreas Gohr 16073b9a3b55SAnika Henke $act = tpl_get_action('profile'); 1608396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1609a00de5b5SAndreas Gohr 1610396c218fSAndreas Gohr $act = tpl_get_action('admin'); 1611396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1612a00de5b5SAndreas Gohr echo '</optgroup>'; 1613a00de5b5SAndreas Gohr 1614a00de5b5SAndreas Gohr echo '</select>'; 1615f22c1964SAndreas Gohr echo '<input type="submit" value="'.$button.'" />'; 16163b9a3b55SAnika Henke echo '</div>'; 1617a00de5b5SAndreas Gohr echo '</form>'; 1618a00de5b5SAndreas Gohr} 1619a00de5b5SAndreas Gohr 1620066fee30SAndreas Gohr/** 1621066fee30SAndreas Gohr * Print a informational line about the used license 1622066fee30SAndreas Gohr * 1623066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1624ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1625ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1626ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1627ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1628ac7a515fSAndreas Gohr * @return string 1629066fee30SAndreas Gohr */ 163080083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1631066fee30SAndreas Gohr global $license; 1632066fee30SAndreas Gohr global $conf; 1633066fee30SAndreas Gohr global $lang; 1634066fee30SAndreas Gohr if(!$conf['license']) return ''; 1635066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1636066fee30SAndreas Gohr $lic = $license[$conf['license']]; 163753e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1638066fee30SAndreas Gohr 163980083a41SAndreas Gohr $out = ''; 164080083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1641066fee30SAndreas Gohr if($img) { 1642066fee30SAndreas Gohr $src = license_img($img); 1643066fee30SAndreas Gohr if($src) { 164453e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 164553e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 164653e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1647066fee30SAndreas Gohr } 1648066fee30SAndreas Gohr } 16494cefd216SMichael Klier if(!$imgonly) { 165053e15c8bSAnika Henke $out .= $lang['license'].' '; 1651d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1652d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 16534cefd216SMichael Klier } 165480083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1655066fee30SAndreas Gohr 1656066fee30SAndreas Gohr if($return) return $out; 1657066fee30SAndreas Gohr echo $out; 1658ac7a515fSAndreas Gohr return ''; 1659066fee30SAndreas Gohr} 1660066fee30SAndreas Gohr 1661a81910eeSAndreas Gohr/** 1662835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1663a81910eeSAndreas Gohr * 1664a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1665a81910eeSAndreas Gohr * template 1666e0c26282SGerrit Uitslag * 1667e0c26282SGerrit Uitslag * @param string $pageid 1668e0c26282SGerrit Uitslag * @param bool $print 1669e0c26282SGerrit Uitslag * @param bool $propagate 1670e0c26282SGerrit Uitslag * @return bool|null|string 1671a81910eeSAndreas Gohr */ 1672835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) { 1673c786a1b6SAnika Henke if (!$pageid) return false; 1674835dfcaeSAnika Henke if ($propagate) $pageid = page_findnearest($pageid); 1675835dfcaeSAnika Henke 1676c786a1b6SAnika Henke global $TOC; 16779a2e250aSAndreas Gohr $oldtoc = $TOC; 1678a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 16799a2e250aSAndreas Gohr $TOC = $oldtoc; 1680a81910eeSAndreas Gohr 1681a81910eeSAndreas Gohr if(!$print) return $html; 1682a81910eeSAndreas Gohr echo $html; 1683e66d3e6dSAndreas Gohr return $html; 1684e66d3e6dSAndreas Gohr} 1685e66d3e6dSAndreas Gohr 1686e66d3e6dSAndreas Gohr/** 16875b75cd1fSAdrian Lang * Display the subscribe form 16885b75cd1fSAdrian Lang * 16895b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 16905b75cd1fSAdrian Lang */ 16915b75cd1fSAdrian Langfunction tpl_subscribe() { 16925b75cd1fSAdrian Lang global $INFO; 16935b75cd1fSAdrian Lang global $ID; 16945b75cd1fSAdrian Lang global $lang; 16956b8f02cfSAdrian Lang global $conf; 169640c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 16975b75cd1fSAdrian Lang 16985b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 16995b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 170015741132SAndreas Gohr echo '<div class="level2">'; 17015b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 17025b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 17035b75cd1fSAdrian Lang } else { 17045b75cd1fSAdrian Lang echo '<ul>'; 17055b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1706056c2049SAndreas Gohr echo '<li><div class="li">'; 17075b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1708056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17095b75cd1fSAdrian Lang } else { 1710056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17115b75cd1fSAdrian Lang } 171240c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 171315741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1714056c2049SAndreas Gohr echo ' ('.$sstl.') '; 171515741132SAndreas Gohr 1716ac7a515fSAndreas Gohr echo '<a href="'.wl( 1717ac7a515fSAndreas Gohr $ID, 1718ac7a515fSAndreas Gohr array( 1719ac7a515fSAndreas Gohr 'do' => 'subscribe', 172066d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 172166d2bed9SAdrian Lang 'sub_style' => $sub['style'], 172266d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1723ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1724ac7a515fSAndreas Gohr ) 1725ac7a515fSAndreas Gohr ). 172666d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 172766d2bed9SAdrian Lang '</a></div></li>'; 17285b75cd1fSAdrian Lang } 17295b75cd1fSAdrian Lang echo '</ul>'; 17305b75cd1fSAdrian Lang } 173115741132SAndreas Gohr echo '</div>'; 17325b75cd1fSAdrian Lang 173315741132SAndreas Gohr // Add new subscription form 17345b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 173515741132SAndreas Gohr echo '<div class="level2">'; 17365b75cd1fSAdrian Lang $ns = getNS($ID).':'; 173715741132SAndreas Gohr $targets = array( 173815741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 173915741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 174015741132SAndreas Gohr ); 174115741132SAndreas Gohr $styles = array( 174215741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 17436b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 17446b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 174515741132SAndreas Gohr ); 174615741132SAndreas Gohr 1747056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1748056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1749056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1750056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1751056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1752056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1753056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1754056c2049SAndreas Gohr $form->addHidden('id', $ID); 1755056c2049SAndreas Gohr $form->endFieldset(); 17565b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 17575b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 175815741132SAndreas Gohr echo '</div>'; 17595b75cd1fSAdrian Lang} 17605b75cd1fSAdrian Lang 1761d059ba9bSAndreas Gohr/** 1762d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1763d059ba9bSAndreas Gohr * 1764d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1765d059ba9bSAndreas Gohr * 1766d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1767d059ba9bSAndreas Gohr */ 1768d059ba9bSAndreas Gohrfunction tpl_flush() { 1769d059ba9bSAndreas Gohr ob_flush(); 1770d059ba9bSAndreas Gohr flush(); 1771d059ba9bSAndreas Gohr} 1772d059ba9bSAndreas Gohr 1773afca7e7eSAnika Henke/** 1774378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1775afca7e7eSAnika Henke * 1776378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1777378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1778378325f9SAndreas Gohr * 1779*42ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1780378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1781ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1782ac7a515fSAndreas Gohr * @return string 1783*42ea7f44SGerrit Uitslag * 1784378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1785afca7e7eSAnika Henke */ 1786378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1787ac7a515fSAndreas Gohr $img = ''; 1788ac7a515fSAndreas Gohr $file = ''; 1789ac7a515fSAndreas Gohr $ismedia = false; 1790378325f9SAndreas Gohr // loop through candidates until a match was found: 1791378325f9SAndreas Gohr foreach($search as $img) { 1792378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1793378325f9SAndreas Gohr $file = mediaFN($img); 1794378325f9SAndreas Gohr $ismedia = true; 1795378325f9SAndreas Gohr } else { 1796c4766956SAndreas Gohr $file = tpl_incdir().$img; 1797378325f9SAndreas Gohr $ismedia = false; 17981f13e33dSAnika Henke } 17990f747863Slupo49 1800378325f9SAndreas Gohr if(file_exists($file)) break; 1801872a6d29SAnika Henke } 1802378325f9SAndreas Gohr 1803378325f9SAndreas Gohr // fetch image data if requested 1804378325f9SAndreas Gohr if(!is_null($imginfo)) { 1805378325f9SAndreas Gohr $imginfo = getimagesize($file); 1806378325f9SAndreas Gohr } 1807378325f9SAndreas Gohr 1808378325f9SAndreas Gohr // build URL 1809378325f9SAndreas Gohr if($ismedia) { 1810378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1811378325f9SAndreas Gohr } else { 1812c4766956SAndreas Gohr $url = tpl_basedir().$img; 1813378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1814378325f9SAndreas Gohr } 1815378325f9SAndreas Gohr 1816378325f9SAndreas Gohr return $url; 1817a7e5f74cSlupo49} 18181f13e33dSAnika Henke 1819872a6d29SAnika Henke/** 1820e5d4768dSAndreas Gohr * PHP include a file 1821e5d4768dSAndreas Gohr * 1822e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1823e5d4768dSAndreas Gohr * file in the template's root directory. 1824e5d4768dSAndreas Gohr * 1825e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1826e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1827e5d4768dSAndreas Gohr * default. 1828e5d4768dSAndreas Gohr * 1829e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1830e5d4768dSAndreas Gohr * to this function! 1831e5d4768dSAndreas Gohr * 1832e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1833e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1834*42ea7f44SGerrit Uitslag * 1835*42ea7f44SGerrit Uitslag * @param string $file 1836e5d4768dSAndreas Gohr */ 1837e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1838e5d4768dSAndreas Gohr global $config_cascade; 1839e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1840e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1841e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1842e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1843e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1844f3a1225fSAnika Henke include("$dir/$file"); 1845e5d4768dSAndreas Gohr return; 1846e5d4768dSAndreas Gohr } 1847e5d4768dSAndreas Gohr } 1848e5d4768dSAndreas Gohr } 1849e5d4768dSAndreas Gohr 1850e5d4768dSAndreas Gohr // still here? try the template dir 1851e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1852e5d4768dSAndreas Gohr if(file_exists($file)) { 1853f3a1225fSAnika Henke include($file); 1854e5d4768dSAndreas Gohr } 1855e5d4768dSAndreas Gohr} 1856e5d4768dSAndreas Gohr 1857e5d4768dSAndreas Gohr/** 1858872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1859872a6d29SAnika Henke * 1860872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 1861*42ea7f44SGerrit Uitslag * 1862ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1863ac7a515fSAndreas Gohr * @return string 1864872a6d29SAnika Henke */ 1865872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1866872a6d29SAnika Henke 1867872a6d29SAnika Henke $return = ''; 1868872a6d29SAnika Henke 1869872a6d29SAnika Henke foreach($types as $type) { 1870872a6d29SAnika Henke switch($type) { 1871872a6d29SAnika Henke case 'favicon': 1872378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1873378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1874872a6d29SAnika Henke break; 1875872a6d29SAnika Henke case 'mobile': 1876cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1877378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1878872a6d29SAnika Henke break; 1879872a6d29SAnika Henke case 'generic': 1880872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1881378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1882378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1883872a6d29SAnika Henke break; 1884872a6d29SAnika Henke } 1885872a6d29SAnika Henke } 1886872a6d29SAnika Henke 1887872a6d29SAnika Henke return $return; 1888afca7e7eSAnika Henke} 1889afca7e7eSAnika Henke 1890d9162c6cSKate Arzamastseva/** 1891d9162c6cSKate Arzamastseva * Prints full-screen media manager 1892d9162c6cSKate Arzamastseva * 1893d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1894d9162c6cSKate Arzamastseva */ 1895d9162c6cSKate Arzamastsevafunction tpl_media() { 1896ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 189788a71175SKate Arzamastseva $fullscreen = true; 189895b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1899d9162c6cSKate Arzamastseva 1900ac7a515fSAndreas Gohr $rev = ''; 1901ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 190298f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 190398f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 19049c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 190598f03b57SKate Arzamastseva 190694add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1907bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1908d9162c6cSKate Arzamastseva html_msgarea(); 190994add303SAnika Henke 191094add303SAnika Henke echo '<div class="panel namespaces">'.NL; 191194add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 191295b451bcSAdrian Lang echo '<div class="panelHeader">'; 1913ba340a70SAnika Henke echo $lang['media_namespaces']; 191494add303SAnika Henke echo '</div>'.NL; 191595b451bcSAdrian Lang 191694add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 191795b451bcSAdrian Lang media_nstree($NS); 191894add303SAnika Henke echo '</div>'.NL; 191994add303SAnika Henke echo '</div>'.NL; 1920fa8e5c77SKate Arzamastseva 192194add303SAnika Henke echo '<div class="panel filelist">'.NL; 1922035e07f1SKate Arzamastseva tpl_mediaFileList(); 192394add303SAnika Henke echo '</div>'.NL; 1924fa8e5c77SKate Arzamastseva 192594add303SAnika Henke echo '<div class="panel file">'.NL; 192694add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1927035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 192894add303SAnika Henke echo '</div>'.NL; 1929ba340a70SAnika Henke 193094add303SAnika Henke echo '</div>'.NL; 1931d9162c6cSKate Arzamastseva} 1932afca7e7eSAnika Henke 1933c71db656SAnika Henke/** 1934c71db656SAnika Henke * Return useful layout classes 1935c71db656SAnika Henke * 1936c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 1937*42ea7f44SGerrit Uitslag * 1938*42ea7f44SGerrit Uitslag * @return string 1939c71db656SAnika Henke */ 1940c71db656SAnika Henkefunction tpl_classes() { 1941c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1942585bf44eSChristopher Smith /** @var Input $INPUT */ 1943585bf44eSChristopher Smith global $INPUT; 1944585bf44eSChristopher Smith 1945c71db656SAnika Henke $classes = array( 1946c71db656SAnika Henke 'dokuwiki', 1947c71db656SAnika Henke 'mode_'.$ACT, 1948c71db656SAnika Henke 'tpl_'.$conf['template'], 1949585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 195039f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1951c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1952c71db656SAnika Henke ); 1953c71db656SAnika Henke return join(' ', $classes); 1954c71db656SAnika Henke} 1955c71db656SAnika Henke 1956e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1957a00de5b5SAndreas Gohr 1958