16b13307fSandi<?php 26b13307fSandi/** 36b13307fSandi * DokuWiki template functions 46b13307fSandi * 56b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 66b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 76b13307fSandi */ 86b13307fSandi 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 106b13307fSandi 116b13307fSandi/** 12ac7a515fSAndreas Gohr * Access a template file 13ac7a515fSAndreas Gohr * 14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 165a892029SAndreas Gohr * 175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18ac7a515fSAndreas Gohr * @param string $file 19ac7a515fSAndreas Gohr * @return string 205a892029SAndreas Gohr */ 21ac7a515fSAndreas Gohrfunction template($file) { 225a892029SAndreas Gohr global $conf; 235a892029SAndreas Gohr 24ac7a515fSAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 25ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 265a892029SAndreas Gohr 27ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 285a892029SAndreas Gohr} 295a892029SAndreas Gohr 30c4766956SAndreas Gohr/** 31c4766956SAndreas Gohr * Convenience function to access template dir from local FS 32c4766956SAndreas Gohr * 33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 34c4766956SAndreas Gohr * 35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 37ac7a515fSAndreas Gohr * @return string 38c4766956SAndreas Gohr */ 39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') { 4075b14482SAndreas Gohr global $conf; 41afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 42afb2c082SAndreas Gohr return DOKU_INC.'lib/tpl/'.$tpl.'/'; 43c4766956SAndreas Gohr} 44c4766956SAndreas Gohr 45c4766956SAndreas Gohr/** 46c4766956SAndreas Gohr * Convenience function to access template dir from web 47c4766956SAndreas Gohr * 48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 49c4766956SAndreas Gohr * 50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 52ac7a515fSAndreas Gohr * @return string 53c4766956SAndreas Gohr */ 5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') { 5575b14482SAndreas Gohr global $conf; 56afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 57dcd4911eSMichael Hamann return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 58c4766956SAndreas Gohr} 59c4766956SAndreas Gohr 605a892029SAndreas Gohr/** 616b13307fSandi * Print the content 626b13307fSandi * 636b13307fSandi * This function is used for printing all the usual content 646b13307fSandi * (defined by the global $ACT var) by calling the appropriate 656b13307fSandi * outputfunction(s) from html.php 666b13307fSandi * 67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 696b13307fSandi * 706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 7142ea7f44SGerrit Uitslag * 72ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 73ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 74ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 75ac7a515fSAndreas Gohr * @return bool true if any output 766b13307fSandi */ 77b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 787ea0913cSchris global $ACT; 79b8595a66SAndreas Gohr global $INFO; 80b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 817ea0913cSchris 827ea0913cSchris ob_start(); 83746855cfSBen Coburn trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 847ea0913cSchris $html_output = ob_get_clean(); 85746855cfSBen Coburn trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8654e95700STom N Harris 8754e95700STom N Harris return !empty($html_output); 887ea0913cSchris} 897ea0913cSchris 90ac7a515fSAndreas Gohr/** 91ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 92ac7a515fSAndreas Gohr * 93ac7a515fSAndreas Gohr * @return bool 94ac7a515fSAndreas Gohr */ 957ea0913cSchrisfunction tpl_content_core() { 966b13307fSandi global $ACT; 976b13307fSandi global $TEXT; 986b13307fSandi global $PRE; 996b13307fSandi global $SUF; 1006b13307fSandi global $SUM; 1016b13307fSandi global $IDX; 102ac7a515fSAndreas Gohr global $INPUT; 1036b13307fSandi 1046b13307fSandi switch($ACT) { 1056b13307fSandi case 'show': 1066b13307fSandi html_show(); 1076b13307fSandi break; 108ac7a515fSAndreas Gohr /** @noinspection PhpMissingBreakStatementInspection */ 10945a99335SAdrian Lang case 'locked': 11045a99335SAdrian Lang html_locked(); 1116b13307fSandi case 'edit': 11245a99335SAdrian Lang case 'recover': 1136b13307fSandi html_edit(); 1146b13307fSandi break; 11545a99335SAdrian Lang case 'preview': 11645a99335SAdrian Lang html_edit(); 11745a99335SAdrian Lang html_show($TEXT); 11845a99335SAdrian Lang break; 119ee4c4a1bSAndreas Gohr case 'draft': 120ee4c4a1bSAndreas Gohr html_draft(); 121ee4c4a1bSAndreas Gohr break; 1226b13307fSandi case 'search': 1236b13307fSandi html_search(); 1246b13307fSandi break; 1256b13307fSandi case 'revisions': 126ac7a515fSAndreas Gohr html_revisions($INPUT->int('first')); 1276b13307fSandi break; 1286b13307fSandi case 'diff': 1296b13307fSandi html_diff(); 1306b13307fSandi break; 1316b13307fSandi case 'recent': 1323c94d07bSAnika Henke $show_changes = $INPUT->str('show_changes'); 1333c94d07bSAnika Henke if (empty($show_changes)) { 1343c94d07bSAnika Henke $show_changes = get_doku_pref('show_changes', $show_changes); 1353c94d07bSAnika Henke } 1363c94d07bSAnika Henke html_recent($INPUT->extract('first')->int('first'), $show_changes); 1376b13307fSandi break; 1386b13307fSandi case 'index': 1396b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 1406b13307fSandi break; 1416b13307fSandi case 'backlink': 1426b13307fSandi html_backlinks(); 1436b13307fSandi break; 1446b13307fSandi case 'conflict': 1456b13307fSandi html_conflict(con($PRE, $TEXT, $SUF), $SUM); 1466b13307fSandi html_diff(con($PRE, $TEXT, $SUF), false); 1476b13307fSandi break; 1486b13307fSandi case 'login': 1496b13307fSandi html_login(); 1506b13307fSandi break; 1516b13307fSandi case 'register': 1526b13307fSandi html_register(); 1536b13307fSandi break; 1548b06d178Schris case 'resendpwd': 1558b06d178Schris html_resendpwd(); 1568b06d178Schris break; 157820fa24bSandi case 'denied': 1582f2c518cSGerrit Uitslag html_denied(); 159820fa24bSandi break; 1608b06d178Schris case 'profile' : 1618b06d178Schris html_updateprofile(); 1628b06d178Schris break; 163c19fe9c0Sandi case 'admin': 164c19fe9c0Sandi tpl_admin(); 165c19fe9c0Sandi break; 1665b75cd1fSAdrian Lang case 'subscribe': 1675b75cd1fSAdrian Lang tpl_subscribe(); 1685b75cd1fSAdrian Lang break; 169d9162c6cSKate Arzamastseva case 'media': 170d9162c6cSKate Arzamastseva tpl_media(); 171d9162c6cSKate Arzamastseva break; 1726b13307fSandi default: 17324bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); 174a85f63deSGerrit Uitslag if($evt->advise_before()) { 175ea67f144Sandi msg("Failed to handle command: ".hsc($ACT), -1); 176a85f63deSGerrit Uitslag } 17724bb549bSchris $evt->advise_after(); 17824bb549bSchris unset($evt); 17954e95700STom N Harris return false; 1806b13307fSandi } 18154e95700STom N Harris return true; 1826b13307fSandi} 1836b13307fSandi 184c19fe9c0Sandi/** 185b8595a66SAndreas Gohr * Places the TOC where the function is called 186b8595a66SAndreas Gohr * 187b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 188b8595a66SAndreas Gohr * a false argument 189b8595a66SAndreas Gohr * 190b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 19142ea7f44SGerrit Uitslag * 192ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 193ac7a515fSAndreas Gohr * @return string 194b8595a66SAndreas Gohr */ 195b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 196b8595a66SAndreas Gohr global $TOC; 197b8595a66SAndreas Gohr global $ACT; 198b8595a66SAndreas Gohr global $ID; 199b8595a66SAndreas Gohr global $REV; 200b8595a66SAndreas Gohr global $INFO; 201851f2e89SAnika Henke global $conf; 202ac7a515fSAndreas Gohr global $INPUT; 203b8595a66SAndreas Gohr $toc = array(); 204b8595a66SAndreas Gohr 205b8595a66SAndreas Gohr if(is_array($TOC)) { 206b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 207b8595a66SAndreas Gohr $toc = $TOC; 2083c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 209b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 210e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 211b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 212b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 213b8595a66SAndreas Gohr } else { 2142bb0d541Schris $tocok = true; 215b8595a66SAndreas Gohr } 216f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 217851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 218b8595a66SAndreas Gohr $toc = array(); 219b8595a66SAndreas Gohr } 220b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 221a61966c5SChristopher Smith // try to load admin plugin TOC 222ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 223a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 224b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 225b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 226b8595a66SAndreas Gohr } 227b8595a66SAndreas Gohr } 228b8595a66SAndreas Gohr 2290b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 230b8595a66SAndreas Gohr $html = html_TOC($toc); 231b8595a66SAndreas Gohr if($return) return $html; 232b8595a66SAndreas Gohr echo $html; 233ac7a515fSAndreas Gohr return ''; 234b8595a66SAndreas Gohr} 235b8595a66SAndreas Gohr 236b8595a66SAndreas Gohr/** 237c19fe9c0Sandi * Handle the admin page contents 238c19fe9c0Sandi * 239c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 24042ea7f44SGerrit Uitslag * 24142ea7f44SGerrit Uitslag * @return bool 242c19fe9c0Sandi */ 243c19fe9c0Sandifunction tpl_admin() { 244f8cc712eSAndreas Gohr global $INFO; 245b8595a66SAndreas Gohr global $TOC; 246ac7a515fSAndreas Gohr global $INPUT; 24711e2ce22Schris 248b8595a66SAndreas Gohr $plugin = null; 249ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 250ac7a515fSAndreas Gohr if(!empty($class)) { 25111e2ce22Schris $pluginlist = plugin_list('admin'); 25211e2ce22Schris 253ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 25411e2ce22Schris // attempt to load the plugin 255ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 256a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 25711e2ce22Schris } 25811e2ce22Schris } 25911e2ce22Schris 260b8595a66SAndreas Gohr if($plugin !== null) { 261b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 262b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 263f8cc712eSAndreas Gohr $plugin->html(); 264f8cc712eSAndreas Gohr } else { 265f8cc712eSAndreas Gohr html_admin(); 266f8cc712eSAndreas Gohr } 26754e95700STom N Harris return true; 268c19fe9c0Sandi} 2696b13307fSandi 2706b13307fSandi/** 2716b13307fSandi * Print the correct HTML meta headers 2726b13307fSandi * 2736b13307fSandi * This has to go into the head section of your template. 2746b13307fSandi * 2756b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 27642ea7f44SGerrit Uitslag * 277ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 278ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 279ac7a515fSAndreas Gohr * @return bool 2806b13307fSandi */ 281f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2826b13307fSandi global $ID; 283d98d4540SBen Coburn global $REV; 2846b13307fSandi global $INFO; 28572e0dc37SAndreas Gohr global $JSINFO; 2866b13307fSandi global $ACT; 2874bb1b5aeSAndreas Gohr global $QUERY; 2886b13307fSandi global $lang; 289dc57ef04Sandi global $conf; 2909c438d6cSMichael Hamann global $updateVersion; 291585bf44eSChristopher Smith /** @var Input $INPUT */ 292585bf44eSChristopher Smith global $INPUT; 2936b13307fSandi 2947bff22c0SAndreas Gohr // prepare the head array 2957bff22c0SAndreas Gohr $head = array(); 2967bff22c0SAndreas Gohr 297202ac28bSMichael Klier // prepare seed for js and css 298cd997f93SAndreas Gohr $tseed = $updateVersion; 299202ac28bSMichael Klier $depends = getConfigFiles('main'); 300cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 301cd997f93SAndreas Gohr $tseed = md5($tseed); 3027bff22c0SAndreas Gohr 3036b13307fSandi // the usual stuff 3043f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 305ac7a515fSAndreas Gohr $head['link'][] = array( 306ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 307ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 308ac7a515fSAndreas Gohr ); 309f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 3107aedde2eSGina Haeussge if(actionOK('index')) { 311ac7a515fSAndreas Gohr $head['link'][] = array( 312ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 313ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 314ac7a515fSAndreas Gohr ); 3157aedde2eSGina Haeussge } 316f96fa415SAndreas Gohr 317f96fa415SAndreas Gohr if($alt) { 31854be1338SGerrit Uitslag if(actionOK('rss')) { 319ac7a515fSAndreas Gohr $head['link'][] = array( 320ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 321a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 322ac7a515fSAndreas Gohr ); 323ac7a515fSAndreas Gohr $head['link'][] = array( 324ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 325a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 326ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 327ac7a515fSAndreas Gohr ); 32854be1338SGerrit Uitslag } 329c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 330ac7a515fSAndreas Gohr $head['link'][] = array( 331ac7a515fSAndreas Gohr 'rel' => 'edit', 332715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 333ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 334ac7a515fSAndreas Gohr ); 335c35f3875SAndreas Gohr } 336c35f3875SAndreas Gohr 33754be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 338ac7a515fSAndreas Gohr $head['link'][] = array( 339ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 340a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 341ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 342ac7a515fSAndreas Gohr ); 3434bb1b5aeSAndreas Gohr } 344bae36d94SAndreas Gohr 345bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 346ac7a515fSAndreas Gohr $head['link'][] = array( 347a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 348ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 349ac7a515fSAndreas Gohr ); 350bae36d94SAndreas Gohr } 351bae36d94SAndreas Gohr 352bae36d94SAndreas Gohr if(actionOK('export_raw')) { 353ac7a515fSAndreas Gohr $head['link'][] = array( 354a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 355ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 356ac7a515fSAndreas Gohr ); 357f96fa415SAndreas Gohr } 358bae36d94SAndreas Gohr } 3596b13307fSandi 3606b13307fSandi // setup robot tags apropriate for different modes 3614f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3626b13307fSandi if($INFO['exists']) { 3636b13307fSandi //delay indexing: 3646b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 3657bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3666b13307fSandi } else { 3677bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3686b13307fSandi } 36901f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 37001f9be51SAnika Henke if ($ID == $conf['start']) { 37101f9be51SAnika Henke $canonicalUrl = DOKU_URL; 37201f9be51SAnika Henke } 37301f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3746b13307fSandi } else { 3757bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3766b13307fSandi } 3777a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3787bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3796b13307fSandi } else { 3807bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3816b13307fSandi } 3826b13307fSandi 383831800b8SAndreas Gohr // set metadata 384831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 385831800b8SAndreas Gohr // keywords (explicit or implicit) 386bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3877bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 388831800b8SAndreas Gohr } else { 3897bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 390831800b8SAndreas Gohr } 391831800b8SAndreas Gohr } 392831800b8SAndreas Gohr 39378a6aeb1SAndreas Gohr // load stylesheets 394ac7a515fSAndreas Gohr $head['link'][] = array( 395ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 396e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 397ac7a515fSAndreas Gohr ); 398bad31ae9SAndreas Gohr 3998bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 400463d4a65SAndreas Gohr $json = new JSON(); 40172e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 402585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 40372e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 404c591aabeSAndreas Gohr } 40572e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 40685f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 4078bbcb611SAndreas Gohr 4088bbcb611SAndreas Gohr // load external javascript 409ac7a515fSAndreas Gohr $head['script'][] = array( 410ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 411e283bd6cSAnika Henke 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 412ac7a515fSAndreas Gohr ); 4137bff22c0SAndreas Gohr 4147bff22c0SAndreas Gohr // trigger event here 415016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 41654e95700STom N Harris return true; 4177bff22c0SAndreas Gohr} 4187bff22c0SAndreas Gohr 4197bff22c0SAndreas Gohr/** 4207bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4217bff22c0SAndreas Gohr * 4227bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4237bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4247bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4257bff22c0SAndreas Gohr * 42642ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4271304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4287bff22c0SAndreas Gohr * 4297bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 43042ea7f44SGerrit Uitslag * 43142ea7f44SGerrit Uitslag * @param array $data 4327bff22c0SAndreas Gohr */ 4337bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4347bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 4357bff22c0SAndreas Gohr foreach($inst as $attr) { 4367bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 43726afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 438e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 43909f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 440e226efe1SAndreas Gohr $attr['_data']. 44109f791c4SDominik Eckelmann "\n/*!]]>*/"; 442e226efe1SAndreas Gohr 4431304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4447bff22c0SAndreas Gohr } else { 4457bff22c0SAndreas Gohr echo '/>'; 4467bff22c0SAndreas Gohr } 4477bff22c0SAndreas Gohr echo "\n"; 4487bff22c0SAndreas Gohr } 4497bff22c0SAndreas Gohr } 4506b13307fSandi} 4516b13307fSandi 4526b13307fSandi/** 4536b13307fSandi * Print a link 4546b13307fSandi * 4555e163278SAndreas Gohr * Just builds a link. 4566b13307fSandi * 4576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 45842ea7f44SGerrit Uitslag * 45942ea7f44SGerrit Uitslag * @param string $url 46042ea7f44SGerrit Uitslag * @param string $name 46142ea7f44SGerrit Uitslag * @param string $more 46221d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 46321d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4646b13307fSandi */ 4651af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 46601f17825SAnika Henke $out = '<a href="'.$url.'" '; 4671af98a77SAnika Henke if($more) $out .= ' '.$more; 4681af98a77SAnika Henke $out .= ">$name</a>"; 4691af98a77SAnika Henke if($return) return $out; 4701af98a77SAnika Henke print $out; 47154e95700STom N Harris return true; 4726b13307fSandi} 4736b13307fSandi 4746b13307fSandi/** 47555efc227SAndreas Gohr * Prints a link to a WikiPage 47655efc227SAndreas Gohr * 47755efc227SAndreas Gohr * Wrapper around html_wikilink 47855efc227SAndreas Gohr * 47955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 48042ea7f44SGerrit Uitslag * 48142ea7f44SGerrit Uitslag * @param string $id page id 48242ea7f44SGerrit Uitslag * @param string|null $name the name of the link 48321d806cdSGerrit Uitslag * @return bool true 48455efc227SAndreas Gohr */ 4850b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 486d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 48754e95700STom N Harris return true; 48855efc227SAndreas Gohr} 48955efc227SAndreas Gohr 49055efc227SAndreas Gohr/** 491a3ec5f4aSmatthiasgrimm * get the parent page 492a3ec5f4aSmatthiasgrimm * 493a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 494a3ec5f4aSmatthiasgrimm * returns false if none is available 495a3ec5f4aSmatthiasgrimm * 496377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 49742ea7f44SGerrit Uitslag * 49842ea7f44SGerrit Uitslag * @param string $id page id 49942ea7f44SGerrit Uitslag * @return false|string 500a3ec5f4aSmatthiasgrimm */ 501377f9e97SAndreas Gohrfunction tpl_getparent($id) { 502377f9e97SAndreas Gohr $parent = getNS($id).':'; 503377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 504a197105eSmatthiasgrimm if($parent == $id) { 505a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 506a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 507a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 508377f9e97SAndreas Gohr if($parent == $id) return false; 509a197105eSmatthiasgrimm } 510377f9e97SAndreas Gohr return $parent; 511a3ec5f4aSmatthiasgrimm} 512a3ec5f4aSmatthiasgrimm 513a3ec5f4aSmatthiasgrimm/** 5146b13307fSandi * Print one of the buttons 5156b13307fSandi * 516a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 517a453d131SAdrian Lang * @see tpl_get_action 518e0c26282SGerrit Uitslag * 519e0c26282SGerrit Uitslag * @param string $type 520e0c26282SGerrit Uitslag * @param bool $return 521e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5226b13307fSandi */ 5231af98a77SAnika Henkefunction tpl_button($type, $return = false) { 524a453d131SAdrian Lang $data = tpl_get_action($type); 525a453d131SAdrian Lang if($data === false) { 526a453d131SAdrian Lang return false; 527a453d131SAdrian Lang } elseif(!is_array($data)) { 528a453d131SAdrian Lang $out = sprintf($data, 'button'); 529409d7af7SAndreas Gohr } else { 530ac7a515fSAndreas Gohr /** 531ac7a515fSAndreas Gohr * @var string $accesskey 532ac7a515fSAndreas Gohr * @var string $id 533ac7a515fSAndreas Gohr * @var string $method 534ac7a515fSAndreas Gohr * @var array $params 535ac7a515fSAndreas Gohr */ 536a453d131SAdrian Lang extract($data); 537a453d131SAdrian Lang if($id === '#dokuwiki__top') { 538a453d131SAdrian Lang $out = html_topbtn(); 539409d7af7SAndreas Gohr } else { 540a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 541409d7af7SAndreas Gohr } 542409d7af7SAndreas Gohr } 5431af98a77SAnika Henke if($return) return $out; 544a453d131SAdrian Lang echo $out; 545a453d131SAdrian Lang return true; 5466b13307fSandi} 5476b13307fSandi 5486b13307fSandi/** 549ed630903Sandi * Like the action buttons but links 550ed630903Sandi * 551a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 552a453d131SAdrian Lang * @see tpl_get_action 553e0c26282SGerrit Uitslag * 55442ea7f44SGerrit Uitslag * @param string $type action command 555e0c26282SGerrit Uitslag * @param string $pre prefix of link 556e0c26282SGerrit Uitslag * @param string $suf suffix of link 557e0c26282SGerrit Uitslag * @param string $inner innerHML of link 55821d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 559e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 560a453d131SAdrian Lang */ 561a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 562a453d131SAdrian Lang global $lang; 563a453d131SAdrian Lang $data = tpl_get_action($type); 564a453d131SAdrian Lang if($data === false) { 565a453d131SAdrian Lang return false; 566a453d131SAdrian Lang } elseif(!is_array($data)) { 567a453d131SAdrian Lang $out = sprintf($data, 'link'); 568a453d131SAdrian Lang } else { 569ac7a515fSAndreas Gohr /** 570ac7a515fSAndreas Gohr * @var string $accesskey 571ac7a515fSAndreas Gohr * @var string $id 572ac7a515fSAndreas Gohr * @var string $method 573b1af9014SChristopher Smith * @var bool $nofollow 574ac7a515fSAndreas Gohr * @var array $params 575becfa414SGerrit Uitslag * @var string $replacement 576ac7a515fSAndreas Gohr */ 577a453d131SAdrian Lang extract($data); 578a453d131SAdrian Lang if(strpos($id, '#') === 0) { 579a453d131SAdrian Lang $linktarget = $id; 580a453d131SAdrian Lang } else { 581a453d131SAdrian Lang $linktarget = wl($id, $params); 582a453d131SAdrian Lang } 583a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 584becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 585becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 586becfa414SGerrit Uitslag } 587c7e90e3fSAnika Henke $akey = $addTitle = ''; 588c7e90e3fSAnika Henke if($accesskey) { 589c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 590c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 591c7e90e3fSAnika Henke } 592b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 593ac7a515fSAndreas Gohr $out = tpl_link( 594ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 595a453d131SAdrian Lang 'class="action '.$type.'" '. 596b1af9014SChristopher Smith $akey.$rel. 597e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 598ac7a515fSAndreas Gohr ); 599a453d131SAdrian Lang } 600a453d131SAdrian Lang if($return) return $out; 601a453d131SAdrian Lang echo $out; 602a453d131SAdrian Lang return true; 603a453d131SAdrian Lang} 604a453d131SAdrian Lang 605a453d131SAdrian Lang/** 606a453d131SAdrian Lang * Check the actions and get data for buttons and links 607ed630903Sandi * 608a453d131SAdrian Lang * Available actions are 609a453d131SAdrian Lang * 610a453d131SAdrian Lang * edit - edit/create/show/draft 611ed630903Sandi * history - old revisions 612ed630903Sandi * recent - recent changes 613a453d131SAdrian Lang * login - login/logout - if ACL enabled 614a453d131SAdrian Lang * profile - user profile (if logged in) 615ed630903Sandi * index - The index 616ed630903Sandi * admin - admin page - if enough rights 617a453d131SAdrian Lang * top - back to top 618a453d131SAdrian Lang * back - back to parent - if available 619bbd37938SAndreas Gohr * backlink - links to the list of backlinks 620a453d131SAdrian Lang * subscribe/subscription- subscribe/unsubscribe 621ed630903Sandi * 622ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 623a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 624a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 625e0c26282SGerrit Uitslag * 626ac7a515fSAndreas Gohr * @param string $type 627ac7a515fSAndreas Gohr * @return array|bool|string 628ed630903Sandi */ 629a453d131SAdrian Langfunction tpl_get_action($type) { 630ed630903Sandi global $ID; 631ed630903Sandi global $INFO; 632ed630903Sandi global $REV; 633ed630903Sandi global $ACT; 634b1af9014SChristopher Smith global $conf; 635585bf44eSChristopher Smith /** @var Input $INPUT */ 636585bf44eSChristopher Smith global $INPUT; 637ed630903Sandi 63875e487e9SAndreas Gohr // check disabled actions and fix the badly named ones 639a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6404c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 641a453d131SAdrian Lang if(!actionOK($type)) return false; 642409d7af7SAndreas Gohr 643a453d131SAdrian Lang $accesskey = null; 6446709e843SAdrian Lang $id = $ID; 645a453d131SAdrian Lang $method = 'get'; 646a453d131SAdrian Lang $params = array('do' => $type); 647b1af9014SChristopher Smith $nofollow = true; 648becfa414SGerrit Uitslag $replacement = ''; 649ed630903Sandi switch($type) { 650ed630903Sandi case 'edit': 6510b17fdc6SAndreas Gohr // most complicated type - we need to decide on current action 652ed630903Sandi if($ACT == 'show' || $ACT == 'search') { 653a453d131SAdrian Lang $method = 'post'; 654ed630903Sandi if($INFO['writable']) { 655a453d131SAdrian Lang $accesskey = 'e'; 656b8a111f5SMichael Klier if(!empty($INFO['draft'])) { 6576709e843SAdrian Lang $type = 'draft'; 658a453d131SAdrian Lang $params['do'] = 'draft'; 659b8a111f5SMichael Klier } else { 660a453d131SAdrian Lang $params['rev'] = $REV; 661a453d131SAdrian Lang if(!$INFO['exists']) { 6626709e843SAdrian Lang $type = 'create'; 663ed630903Sandi } 664b8a111f5SMichael Klier } 665ed630903Sandi } else { 666a453d131SAdrian Lang if(!actionOK('source')) return false; //pseudo action 667a453d131SAdrian Lang $params['rev'] = $REV; 6686709e843SAdrian Lang $type = 'source'; 669a453d131SAdrian Lang $accesskey = 'v'; 670ed630903Sandi } 671ed630903Sandi } else { 672d30d4913SChristopher Smith $params = array('do' => ''); 6736709e843SAdrian Lang $type = 'show'; 674a453d131SAdrian Lang $accesskey = 'v'; 675ed630903Sandi } 6761af98a77SAnika Henke break; 677a453d131SAdrian Lang case 'revisions': 6786709e843SAdrian Lang $type = 'revs'; 679a453d131SAdrian Lang $accesskey = 'o'; 6801af98a77SAnika Henke break; 681ed630903Sandi case 'recent': 682a453d131SAdrian Lang $accesskey = 'r'; 6831af98a77SAnika Henke break; 684ed630903Sandi case 'index': 685a453d131SAdrian Lang $accesskey = 'x'; 686b1af9014SChristopher Smith // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 687b1af9014SChristopher Smith if ($conf['start'] == $ID && !$conf['sitemap']) { 688b1af9014SChristopher Smith $nofollow = false; 689b1af9014SChristopher Smith } 6901af98a77SAnika Henke break; 691ed630903Sandi case 'top': 692076f0d72SAnika Henke $accesskey = 't'; 693d30d4913SChristopher Smith $params = array('do' => ''); 694a453d131SAdrian Lang $id = '#dokuwiki__top'; 6951af98a77SAnika Henke break; 696a3ec5f4aSmatthiasgrimm case 'back': 697a453d131SAdrian Lang $parent = tpl_getparent($ID); 698a453d131SAdrian Lang if(!$parent) { 699a453d131SAdrian Lang return false; 700a3ec5f4aSmatthiasgrimm } 701a453d131SAdrian Lang $id = $parent; 702d30d4913SChristopher Smith $params = array('do' => ''); 703a453d131SAdrian Lang $accesskey = 'b'; 7041af98a77SAnika Henke break; 705becfa414SGerrit Uitslag case 'img_backto': 706becfa414SGerrit Uitslag $params = array(); 707becfa414SGerrit Uitslag $accesskey = 'b'; 708becfa414SGerrit Uitslag $replacement = $ID; 709becfa414SGerrit Uitslag break; 710ed630903Sandi case 'login': 711a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 712585bf44eSChristopher Smith if($INPUT->server->has('REMOTE_USER')) { 7133a48618aSAnika Henke if(!actionOK('logout')) { 7142380e8a8SAdrian Lang return false; 7152380e8a8SAdrian Lang } 716a453d131SAdrian Lang $params['do'] = 'logout'; 717a453d131SAdrian Lang $type = 'logout'; 718bf413a4eSAnika Henke } 719bf413a4eSAnika Henke break; 720bf413a4eSAnika Henke case 'register': 721585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 722bf413a4eSAnika Henke return false; 723bf413a4eSAnika Henke } 724bf413a4eSAnika Henke break; 725bf413a4eSAnika Henke case 'resendpwd': 726585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 727bf413a4eSAnika Henke return false; 728ed630903Sandi } 7291af98a77SAnika Henke break; 730ed630903Sandi case 'admin': 731a453d131SAdrian Lang if(!$INFO['ismanager']) { 732a453d131SAdrian Lang return false; 733c059e1a6SAndreas Gohr } 7341af98a77SAnika Henke break; 7351246e016SAndreas Gohr case 'revert': 736a453d131SAdrian Lang if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 737a453d131SAdrian Lang return false; 7381246e016SAndreas Gohr } 739a453d131SAdrian Lang $params['rev'] = $REV; 740a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 7411246e016SAndreas Gohr break; 7426709e843SAdrian Lang case 'subscribe': 743585bf44eSChristopher Smith if(!$INPUT->server->str('REMOTE_USER')) { 744a453d131SAdrian Lang return false; 745b158d625SSteven Danz } 7461af98a77SAnika Henke break; 747f00151b4Schris case 'backlink': 7481af98a77SAnika Henke break; 7498b06d178Schris case 'profile': 750585bf44eSChristopher Smith if(!$INPUT->server->has('REMOTE_USER')) { 751a453d131SAdrian Lang return false; 7528b06d178Schris } 7531af98a77SAnika Henke break; 754b9eb2e61SKate Arzamastseva case 'media': 755d08527abSAnika Henke $params['ns'] = getNS($ID); 756b9eb2e61SKate Arzamastseva break; 757becfa414SGerrit Uitslag case 'mediaManager': 758becfa414SGerrit Uitslag // View image in media manager 759becfa414SGerrit Uitslag global $IMG; 760becfa414SGerrit Uitslag $imgNS = getNS($IMG); 761becfa414SGerrit Uitslag $authNS = auth_quickaclcheck("$imgNS:*"); 762becfa414SGerrit Uitslag if ($authNS < AUTH_UPLOAD) { 763becfa414SGerrit Uitslag return false; 764becfa414SGerrit Uitslag } 765becfa414SGerrit Uitslag $params = array( 766becfa414SGerrit Uitslag 'ns' => $imgNS, 767becfa414SGerrit Uitslag 'image' => $IMG, 768becfa414SGerrit Uitslag 'do' => 'media' 769becfa414SGerrit Uitslag ); 770becfa414SGerrit Uitslag //$type = 'media'; 771becfa414SGerrit Uitslag break; 772ed630903Sandi default: 773a453d131SAdrian Lang return '[unknown %s type]'; 774ed630903Sandi } 775becfa414SGerrit Uitslag return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); 776ed630903Sandi} 777ed630903Sandi 778ed630903Sandi/** 77901f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 78001f17825SAnika Henke * 78101f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 78242ea7f44SGerrit Uitslag * 78342ea7f44SGerrit Uitslag * @param string $type action command 784ac7a515fSAndreas Gohr * @param bool $link link or form button? 785e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 786ac7a515fSAndreas Gohr * @param bool $return return or print 787ac7a515fSAndreas Gohr * @param string $pre prefix for links 788ac7a515fSAndreas Gohr * @param string $suf suffix for links 789ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 790ac7a515fSAndreas Gohr * @return bool|string 79101f17825SAnika Henke */ 792ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 79301f17825SAnika Henke $out = ''; 794ac7a515fSAndreas Gohr if($link) { 795e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 796ac7a515fSAndreas Gohr } else { 797e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 798ac7a515fSAndreas Gohr } 79901f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 80001f17825SAnika Henke 80101f17825SAnika Henke if($return) return $out; 80201f17825SAnika Henke print $out; 80301f17825SAnika Henke return $out ? true : false; 80401f17825SAnika Henke} 80501f17825SAnika Henke 80601f17825SAnika Henke/** 8076b13307fSandi * Print the search form 8086b13307fSandi * 80972645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 81072645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 81172645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 81272645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 81372645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 81472645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 81572645b75SAndreas Gohr * 8166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 81742ea7f44SGerrit Uitslag * 818ac7a515fSAndreas Gohr * @param bool $ajax 819ac7a515fSAndreas Gohr * @param bool $autocomplete 820ac7a515fSAndreas Gohr * @return bool 8216b13307fSandi */ 82272645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 8236b13307fSandi global $lang; 824c1e3b7d9Smatthiasgrimm global $ACT; 825ad4aaef7SAndreas Gohr global $QUERY; 826c1e3b7d9Smatthiasgrimm 827670ff54eSchris // don't print the search form if search action has been disabled 82864276bbcSarbrk1 if(!actionOK('search')) return false; 829670ff54eSchris 8309805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 8316b13307fSandi print '<input type="hidden" name="do" value="search" />'; 832c1e3b7d9Smatthiasgrimm print '<input type="text" '; 833ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 834001ea14eSRainbow Spike print 'placeholder="'.$lang['btn_search'].'" '; 83572645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 83607493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 837ae614416SAnika Henke print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>'; 83824a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 8394beabca9SAnika Henke print '</div></form>'; 84054e95700STom N Harris return true; 8416b13307fSandi} 8426b13307fSandi 8436b13307fSandi/** 8446b13307fSandi * Print the breadcrumbs trace 8456b13307fSandi * 8466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 84742ea7f44SGerrit Uitslag * 848ac7a515fSAndreas Gohr * @param string $sep Separator between entries 849ac7a515fSAndreas Gohr * @return bool 8506b13307fSandi */ 851e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 8526b13307fSandi global $lang; 8536b13307fSandi global $conf; 8546b13307fSandi 8556b13307fSandi //check if enabled 856359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 8576b13307fSandi 8586b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 859265e3787Sandi 8602979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 861265e3787Sandi 86240eb54bbSjan //render crumbs, highlight the last one 863fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 86440eb54bbSjan $last = count($crumbs); 86540eb54bbSjan $i = 0; 866a77f5846Sjan foreach($crumbs as $id => $name) { 86740eb54bbSjan $i++; 8682979a10bSKatriel Traum echo $crumbs_sep; 86992795d04Sandi if($i == $last) print '<span class="curid">'; 870d317fb5dSAnika Henke print '<bdi>'; 871e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 872d317fb5dSAnika Henke print '</bdi>'; 87392795d04Sandi if($i == $last) print '</span>'; 8746b13307fSandi } 87554e95700STom N Harris return true; 8766b13307fSandi} 8776b13307fSandi 8786b13307fSandi/** 8791734437eSandi * Hierarchical breadcrumbs 8801734437eSandi * 88131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8821734437eSandi * It only makes sense with a deep site structure. 8831734437eSandi * 8841734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 8856bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 88631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 887f46c9e83SAnika Henke * @author <fredrik@averpil.com> 88808d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 88942ea7f44SGerrit Uitslag * 890ac7a515fSAndreas Gohr * @param string $sep Separator between entries 891ac7a515fSAndreas Gohr * @return bool 8921734437eSandi */ 89308d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') { 8941734437eSandi global $conf; 8951734437eSandi global $ID; 8961734437eSandi global $lang; 8971734437eSandi 89831e187f8SSean Coates // check if enabled 89954e95700STom N Harris if(!$conf['youarehere']) return false; 9001734437eSandi 9011734437eSandi $parts = explode(':', $ID); 902796bafb3SAndreas Gohr $count = count($parts); 9031734437eSandi 90408d7a575SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 9053940c519SMark 90608d7a575SAndreas Gohr // always print the startpage 90708d7a575SAndreas Gohr echo '<span class="home">'; 90808d7a575SAndreas Gohr tpl_pagelink(':'.$conf['start']); 90908d7a575SAndreas Gohr echo '</span>'; 910796bafb3SAndreas Gohr 911796bafb3SAndreas Gohr // print intermediate namespace links 912796bafb3SAndreas Gohr $part = ''; 913796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 914796bafb3SAndreas Gohr $part .= $parts[$i].':'; 915796bafb3SAndreas Gohr $page = $part; 916796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 917796bafb3SAndreas Gohr 91808d7a575SAndreas Gohr // output 91908d7a575SAndreas Gohr echo $sep; 92008d7a575SAndreas Gohr tpl_pagelink($page); 92131e187f8SSean Coates } 9221734437eSandi 923796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 924e013f48dSAnika Henke resolve_pageid('', $page, $exists); 92508d7a575SAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 926796bafb3SAndreas Gohr $page = $part.$parts[$i]; 92708d7a575SAndreas Gohr if($page == $conf['start']) return true; 92808d7a575SAndreas Gohr echo $sep; 92908d7a575SAndreas Gohr tpl_pagelink($page); 93054e95700STom N Harris return true; 9311734437eSandi} 9321734437eSandi 9331734437eSandi/** 9346b13307fSandi * Print info if the user is logged in 935a2488c3cSMatthias Grimm * and show full name in that case 9366b13307fSandi * 9376b13307fSandi * Could be enhanced with a profile link in future? 9386b13307fSandi * 9396b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 94042ea7f44SGerrit Uitslag * 941ac7a515fSAndreas Gohr * @return bool 9426b13307fSandi */ 9436b13307fSandifunction tpl_userinfo() { 9446b13307fSandi global $lang; 945585bf44eSChristopher Smith /** @var Input $INPUT */ 946585bf44eSChristopher Smith global $INPUT; 947585bf44eSChristopher Smith 948585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 949fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 95054e95700STom N Harris return true; 95154e95700STom N Harris } 95254e95700STom N Harris return false; 9536b13307fSandi} 9546b13307fSandi 9556b13307fSandi/** 9566b13307fSandi * Print some info about the current page 9576b13307fSandi * 9586b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 95942ea7f44SGerrit Uitslag * 960ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 961ac7a515fSAndreas Gohr * @return bool|string 9626b13307fSandi */ 9634b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 9646b13307fSandi global $conf; 9656b13307fSandi global $lang; 9666b13307fSandi global $INFO; 967c6e92a3cSDavid Lorentsen global $ID; 968c6e92a3cSDavid Lorentsen 969c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 970ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 971ac7a515fSAndreas Gohr return false; 972ac7a515fSAndreas Gohr } 9736b13307fSandi 9746b13307fSandi // prepare date and path 9756b13307fSandi $fn = $INFO['filepath']; 9766b13307fSandi if(!$conf['fullpath']) { 977613bca54SAndreas Gohr if($INFO['rev']) { 97850fbebceSGina Haeussge $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 9796b13307fSandi } else { 98050fbebceSGina Haeussge $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 9816b13307fSandi } 9826b13307fSandi } 983bee6dc82Sandi $fn = utf8_decodeFN($fn); 984f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 9856b13307fSandi 986faecdfdfSAndreas Gohr // print it 987faecdfdfSAndreas Gohr if($INFO['exists']) { 9884b0d3916SAndreas Gohr $out = ''; 989d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 990e260f93bSAnika Henke $out .= ' · '; 9914b0d3916SAndreas Gohr $out .= $lang['lastmod']; 992fde860beSGerrit Uitslag $out .= ' '; 9934b0d3916SAndreas Gohr $out .= $date; 9946b13307fSandi if($INFO['editor']) { 9954b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 996d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 9975aa52fafSBen Coburn } else { 9984b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 9996b13307fSandi } 10006b13307fSandi if($INFO['locked']) { 1001e260f93bSAnika Henke $out .= ' · '; 10024b0d3916SAndreas Gohr $out .= $lang['lockedby']; 1003fde860beSGerrit Uitslag $out .= ' '; 1004d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 10056b13307fSandi } 10064b0d3916SAndreas Gohr if($ret) { 10074b0d3916SAndreas Gohr return $out; 10084b0d3916SAndreas Gohr } else { 10094b0d3916SAndreas Gohr echo $out; 101054e95700STom N Harris return true; 10116b13307fSandi } 10124b0d3916SAndreas Gohr } 101354e95700STom N Harris return false; 10146b13307fSandi} 10156b13307fSandi 1016820fa24bSandi/** 1017a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 101887c434ceSAndreas Gohr * 101987c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 1020a6598f23SBen Coburn * the given ID is used. 102187c434ceSAndreas Gohr * 102287c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 102342ea7f44SGerrit Uitslag * 1024ac7a515fSAndreas Gohr * @param string $id page id 1025ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 1026ac7a515fSAndreas Gohr * @return bool|string 102787c434ceSAndreas Gohr */ 1028a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 1029c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 1030fffeeafeSChristopher Smith 103187c434ceSAndreas Gohr if(is_null($id)) { 103287c434ceSAndreas Gohr global $ID; 103387c434ceSAndreas Gohr $id = $ID; 103487c434ceSAndreas Gohr } 103587c434ceSAndreas Gohr 103687c434ceSAndreas Gohr $name = $id; 1037fe9ec250SChris Smith if(useHeading('navigation')) { 1038fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 1039fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 1040fffeeafeSChristopher Smith } 1041fffeeafeSChristopher Smith 1042fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 1043fffeeafeSChristopher Smith switch ($ACT) { 1044fffeeafeSChristopher Smith // admin functions 1045fffeeafeSChristopher Smith case 'admin' : 1046fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 1047fffeeafeSChristopher Smith // try to get the plugin name 1048a61966c5SChristopher Smith /** @var $plugin DokuWiki_Admin_Plugin */ 1049a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 1050c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 1051a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 1052fffeeafeSChristopher Smith } 1053fffeeafeSChristopher Smith break; 1054fffeeafeSChristopher Smith 1055fffeeafeSChristopher Smith // user functions 1056fffeeafeSChristopher Smith case 'login' : 1057fffeeafeSChristopher Smith case 'profile' : 1058fffeeafeSChristopher Smith case 'register' : 1059fffeeafeSChristopher Smith case 'resendpwd' : 1060fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1061fffeeafeSChristopher Smith break; 1062fffeeafeSChristopher Smith 1063fffeeafeSChristopher Smith // wiki functions 1064fffeeafeSChristopher Smith case 'search' : 1065fffeeafeSChristopher Smith case 'index' : 1066fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1067fffeeafeSChristopher Smith break; 1068fffeeafeSChristopher Smith 1069fffeeafeSChristopher Smith // page functions 1070fffeeafeSChristopher Smith case 'edit' : 1071fffeeafeSChristopher Smith $page_title = "✎ ".$name; 1072fffeeafeSChristopher Smith break; 1073fffeeafeSChristopher Smith 1074fffeeafeSChristopher Smith case 'revisions' : 1075fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 1076fffeeafeSChristopher Smith break; 1077fffeeafeSChristopher Smith 1078fffeeafeSChristopher Smith case 'backlink' : 1079fffeeafeSChristopher Smith case 'recent' : 1080fffeeafeSChristopher Smith case 'subscribe' : 1081fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 1082fffeeafeSChristopher Smith break; 1083fffeeafeSChristopher Smith 1084fffeeafeSChristopher Smith default : // SHOW and anything else not included 1085fffeeafeSChristopher Smith $page_title = $name; 108687c434ceSAndreas Gohr } 1087a6598f23SBen Coburn 1088a6598f23SBen Coburn if($ret) { 1089fffeeafeSChristopher Smith return hsc($page_title); 1090a6598f23SBen Coburn } else { 1091fffeeafeSChristopher Smith print hsc($page_title); 109254e95700STom N Harris return true; 109387c434ceSAndreas Gohr } 1094a6598f23SBen Coburn} 1095340756e4Sandi 109655efc227SAndreas Gohr/** 109755efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 109855efc227SAndreas Gohr * 109955efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 110055efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 110155efc227SAndreas Gohr * 110255efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 110355efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 110455efc227SAndreas Gohr * to the names of the latter one) 110555efc227SAndreas Gohr * 11063df72098SAndreas Gohr * Only allowed in: detail.php 110755efc227SAndreas Gohr * 110855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 110942ea7f44SGerrit Uitslag * 111021d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1111ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1112e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1113ac7a515fSAndreas Gohr * @return string 111455efc227SAndreas Gohr */ 11153df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 111655efc227SAndreas Gohr // Init Exif Reader 111755efc227SAndreas Gohr global $SRC; 11183df72098SAndreas Gohr 11193df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 11203df72098SAndreas Gohr 112155efc227SAndreas Gohr static $meta = null; 11223df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 112355efc227SAndreas Gohr if($meta === false) return $alt; 112488945224SChristopher Smith $info = cleanText($meta->getField($tags)); 112555efc227SAndreas Gohr if($info == false) return $alt; 112655efc227SAndreas Gohr return $info; 112755efc227SAndreas Gohr} 112855efc227SAndreas Gohr 112955efc227SAndreas Gohr/** 1130becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1131becfa414SGerrit Uitslag * 1132becfa414SGerrit Uitslag * @return string html of description list 1133becfa414SGerrit Uitslag */ 1134becfa414SGerrit Uitslagfunction tpl_img_meta() { 1135becfa414SGerrit Uitslag global $lang; 1136becfa414SGerrit Uitslag 1137becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1138becfa414SGerrit Uitslag 1139becfa414SGerrit Uitslag echo '<dl>'; 1140becfa414SGerrit Uitslag foreach($tags as $tag) { 1141becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1142fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1143becfa414SGerrit Uitslag 1144fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1145becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1146becfa414SGerrit Uitslag echo dformat($tag['value']); 1147becfa414SGerrit Uitslag } else { 1148becfa414SGerrit Uitslag echo hsc($tag['value']); 1149becfa414SGerrit Uitslag } 1150becfa414SGerrit Uitslag echo '</dd>'; 1151becfa414SGerrit Uitslag } 1152becfa414SGerrit Uitslag echo '</dl>'; 1153becfa414SGerrit Uitslag} 1154becfa414SGerrit Uitslag 1155becfa414SGerrit Uitslag/** 1156becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1157becfa414SGerrit Uitslag * 1158becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1159becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1160becfa414SGerrit Uitslag * - string type type of value 1161becfa414SGerrit Uitslag * - string value tag value (unescaped) 1162becfa414SGerrit Uitslag */ 1163becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1164becfa414SGerrit Uitslag 1165becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1166becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 116779e79377SAndreas Gohr if(file_exists($config_file)) { 1168becfa414SGerrit Uitslag include($config_file); 1169becfa414SGerrit Uitslag } 1170becfa414SGerrit Uitslag } 1171becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1172becfa414SGerrit Uitslag 1173becfa414SGerrit Uitslag $tags = array(); 1174becfa414SGerrit Uitslag foreach($fields as $tag){ 1175becfa414SGerrit Uitslag $t = array(); 1176becfa414SGerrit Uitslag if (!empty($tag[0])) { 1177becfa414SGerrit Uitslag $t = array($tag[0]); 1178becfa414SGerrit Uitslag } 1179becfa414SGerrit Uitslag if(is_array($tag[3])) { 1180becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1181becfa414SGerrit Uitslag } 1182becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1183becfa414SGerrit Uitslag if ($value) { 1184becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1185becfa414SGerrit Uitslag } 1186becfa414SGerrit Uitslag } 1187becfa414SGerrit Uitslag return $tags; 1188becfa414SGerrit Uitslag} 1189becfa414SGerrit Uitslag 1190becfa414SGerrit Uitslag/** 119155efc227SAndreas Gohr * Prints the image with a link to the full sized version 119255efc227SAndreas Gohr * 119355efc227SAndreas Gohr * Only allowed in: detail.php 1194a02d2933SAndreas Gohr * 1195ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1196a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1197a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1198a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1199a02d2933SAndreas Gohr * @param $params array - additional image attributes 120042ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 120155efc227SAndreas Gohr */ 1202a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 120355efc227SAndreas Gohr global $IMG; 1204585bf44eSChristopher Smith /** @var Input $INPUT */ 1205ac7a515fSAndreas Gohr global $INPUT; 12065c2eed9aSlisps global $REV; 120755efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 120855efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 120955efc227SAndreas Gohr 121055efc227SAndreas Gohr //resize to given max values 121123a34783SAndreas Gohr $ratio = 1; 121223a34783SAndreas Gohr if($w >= $h) { 1213f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 121455efc227SAndreas Gohr $ratio = $maxwidth / $w; 1215f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 121655efc227SAndreas Gohr $ratio = $maxheight / $h; 121755efc227SAndreas Gohr } 121855efc227SAndreas Gohr } else { 1219f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 122055efc227SAndreas Gohr $ratio = $maxheight / $h; 1221f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 122255efc227SAndreas Gohr $ratio = $maxwidth / $w; 122355efc227SAndreas Gohr } 122455efc227SAndreas Gohr } 122555efc227SAndreas Gohr if($ratio) { 122655efc227SAndreas Gohr $w = floor($ratio * $w); 122755efc227SAndreas Gohr $h = floor($ratio * $h); 122855efc227SAndreas Gohr } 122955efc227SAndreas Gohr 12306de3759aSAndreas Gohr //prepare URLs 12315c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 12325c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 123355efc227SAndreas Gohr 12342684e50aSAndreas Gohr //prepare attributes 123555efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1236a02d2933SAndreas Gohr if(is_null($params)) { 12372684e50aSAndreas Gohr $p = array(); 1238a02d2933SAndreas Gohr } else { 1239a02d2933SAndreas Gohr $p = $params; 1240a02d2933SAndreas Gohr } 12412684e50aSAndreas Gohr if($w) $p['width'] = $w; 12422684e50aSAndreas Gohr if($h) $p['height'] = $h; 12432684e50aSAndreas Gohr $p['class'] = 'img_detail'; 12442684e50aSAndreas Gohr if($alt) { 12452684e50aSAndreas Gohr $p['alt'] = $alt; 12462684e50aSAndreas Gohr $p['title'] = $alt; 12472684e50aSAndreas Gohr } else { 12482684e50aSAndreas Gohr $p['alt'] = ''; 12492684e50aSAndreas Gohr } 1250a02d2933SAndreas Gohr $p['src'] = $src; 125155efc227SAndreas Gohr 1252a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1253a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1254a02d2933SAndreas Gohr} 1255a02d2933SAndreas Gohr 1256a02d2933SAndreas Gohr/** 1257a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1258ac7a515fSAndreas Gohr * 1259ac7a515fSAndreas Gohr * @param array $data 1260ac7a515fSAndreas Gohr * @return bool 1261a02d2933SAndreas Gohr */ 1262ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 126359f3611bSAnika Henke global $lang; 1264a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1265a02d2933SAndreas Gohr 126659f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1267a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1268a02d2933SAndreas Gohr if($data['url']) print '</a>'; 126954e95700STom N Harris return true; 127055efc227SAndreas Gohr} 127155efc227SAndreas Gohr 12727367b368SAndreas Gohr/** 1273881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12747367b368SAndreas Gohr * 12757367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 12767367b368SAndreas Gohr * template 1277ac7a515fSAndreas Gohr * 1278ac7a515fSAndreas Gohr * @return bool 12797367b368SAndreas Gohr */ 12807367b368SAndreas Gohrfunction tpl_indexerWebBug() { 12817367b368SAndreas Gohr global $ID; 12821dad36f5SAndreas Gohr 12837367b368SAndreas Gohr $p = array(); 1284b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1285e68c51baSAndreas Gohr '&'.time(); 1286881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12877367b368SAndreas Gohr $p['height'] = 1; 12887367b368SAndreas Gohr $p['alt'] = ''; 12897367b368SAndreas Gohr $att = buildAttributes($p); 12907367b368SAndreas Gohr print "<img $att />"; 129154e95700STom N Harris return true; 12927367b368SAndreas Gohr} 12937367b368SAndreas Gohr 129478d4e784SEsther Brunner/** 129578d4e784SEsther Brunner * tpl_getConf($id) 129678d4e784SEsther Brunner * 129778d4e784SEsther Brunner * use this function to access template configuration variables 1298ac7a515fSAndreas Gohr * 129917448fb8SChristopher Smith * @param string $id name of the value to access 130017448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 130117448fb8SChristopher Smith * @return mixed 130278d4e784SEsther Brunner */ 130317448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 130478d4e784SEsther Brunner global $conf; 130517566ac6SAdrian Lang static $tpl_configloaded = false; 130678d4e784SEsther Brunner 130778d4e784SEsther Brunner $tpl = $conf['template']; 130878d4e784SEsther Brunner 130978d4e784SEsther Brunner if(!$tpl_configloaded) { 131078d4e784SEsther Brunner $tconf = tpl_loadConfig(); 131178d4e784SEsther Brunner if($tconf !== false) { 131278d4e784SEsther Brunner foreach($tconf as $key => $value) { 131378d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 131478d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 131578d4e784SEsther Brunner } 131678d4e784SEsther Brunner $tpl_configloaded = true; 131778d4e784SEsther Brunner } 131878d4e784SEsther Brunner } 131978d4e784SEsther Brunner 132017448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 132178d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 132278d4e784SEsther Brunner } 132378d4e784SEsther Brunner 132417448fb8SChristopher Smith return $notset; 132517448fb8SChristopher Smith} 132617448fb8SChristopher Smith 132778d4e784SEsther Brunner/** 132878d4e784SEsther Brunner * tpl_loadConfig() 1329ac7a515fSAndreas Gohr * 133078d4e784SEsther Brunner * reads all template configuration variables 133178d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1332ac7a515fSAndreas Gohr * 1333ac7a515fSAndreas Gohr * @return array 133478d4e784SEsther Brunner */ 133578d4e784SEsther Brunnerfunction tpl_loadConfig() { 133678d4e784SEsther Brunner 1337c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 133878d4e784SEsther Brunner $conf = array(); 133978d4e784SEsther Brunner 134079e79377SAndreas Gohr if(!file_exists($file)) return false; 134178d4e784SEsther Brunner 134278d4e784SEsther Brunner // load default config file 134378d4e784SEsther Brunner include($file); 134478d4e784SEsther Brunner 134578d4e784SEsther Brunner return $conf; 134678d4e784SEsther Brunner} 134778d4e784SEsther Brunner 134817566ac6SAdrian Lang// language methods 134917566ac6SAdrian Lang/** 135017566ac6SAdrian Lang * tpl_getLang($id) 135117566ac6SAdrian Lang * 135217566ac6SAdrian Lang * use this function to access template language variables 135342ea7f44SGerrit Uitslag * 135442ea7f44SGerrit Uitslag * @param string $id key of language string 135542ea7f44SGerrit Uitslag * @return string 135617566ac6SAdrian Lang */ 135717566ac6SAdrian Langfunction tpl_getLang($id) { 135817566ac6SAdrian Lang static $lang = array(); 135917566ac6SAdrian Lang 136017566ac6SAdrian Lang if(count($lang) === 0) { 1361dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1362dd7a6159SGerrit Uitslag 1363c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 136417566ac6SAdrian Lang 136517566ac6SAdrian Lang $lang = array(); 136617566ac6SAdrian Lang 136717566ac6SAdrian Lang // don't include once 136817566ac6SAdrian Lang @include($path . 'en/lang.php'); 1369dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 137079e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1371dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1372dd7a6159SGerrit Uitslag } 137317566ac6SAdrian Lang } 137417566ac6SAdrian Lang 1375dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1376dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1377dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 137879e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1379dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1380dd7a6159SGerrit Uitslag } 1381dd7a6159SGerrit Uitslag } 1382dd7a6159SGerrit Uitslag } 138317566ac6SAdrian Lang } 138417566ac6SAdrian Lang return $lang[$id]; 138517566ac6SAdrian Lang} 138617566ac6SAdrian Lang 13873df72098SAndreas Gohr/** 1388c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1389e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1390e8ec13b9SKlap-in * 1391e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1392e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1393e8ec13b9SKlap-in */ 1394e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1395c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1396e8ec13b9SKlap-in} 1397e8ec13b9SKlap-in 1398e8ec13b9SKlap-in/** 1399c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 140042ea7f44SGerrit Uitslag * 140142ea7f44SGerrit Uitslag * @param string $id id of localized text 140242ea7f44SGerrit Uitslag * @return string wiki text 1403e8ec13b9SKlap-in */ 1404c5c17fdaSKlap-infunction tpl_localeFN($id) { 1405e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1406e8ec13b9SKlap-in global $conf; 140738fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 140879e79377SAndreas Gohr if (!file_exists($file)){ 1409e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 141079e79377SAndreas Gohr if(!file_exists($file)){ 1411e8ec13b9SKlap-in //fall back to english 1412e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1413e8ec13b9SKlap-in } 1414e8ec13b9SKlap-in } 1415e8ec13b9SKlap-in return $file; 1416e8ec13b9SKlap-in} 1417e8ec13b9SKlap-in 1418e8ec13b9SKlap-in/** 14193df72098SAndreas Gohr * prints the "main content" in the mediamanger popup 14203df72098SAndreas Gohr * 14213df72098SAndreas Gohr * Depending on the user's actions this may be a list of 14223df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 14233df72098SAndreas Gohr * a message of referencing pages 14243df72098SAndreas Gohr * 14253df72098SAndreas Gohr * Only allowed in mediamanager.php 14263df72098SAndreas Gohr * 1427c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1428c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 142942ea7f44SGerrit Uitslag * @param string $sort 14308702de7fSGerrit Uitslag * 14313df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14323df72098SAndreas Gohr */ 143300e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 14343df72098SAndreas Gohr global $IMG; 14353df72098SAndreas Gohr global $AUTH; 14363df72098SAndreas Gohr global $INUSE; 14373df72098SAndreas Gohr global $NS; 14383df72098SAndreas Gohr global $JUMPTO; 1439585bf44eSChristopher Smith /** @var Input $INPUT */ 1440ac7a515fSAndreas Gohr global $INPUT; 14413df72098SAndreas Gohr 1442ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1443c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1444c182313eSAndreas Gohr 1445c182313eSAndreas Gohr if(!$do) { 1446ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1447c182313eSAndreas Gohr $do = 'metaform'; 1448c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1449c182313eSAndreas Gohr $do = 'filesinuse'; 1450c182313eSAndreas Gohr } else { 1451c182313eSAndreas Gohr $do = 'filelist'; 1452c182313eSAndreas Gohr } 1453c182313eSAndreas Gohr } 1454c182313eSAndreas Gohr 1455c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1456c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1457c182313eSAndreas Gohr $data = array('do' => $do); 1458c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1459c182313eSAndreas Gohr if($evt->advise_before()) { 1460c182313eSAndreas Gohr $do = $data['do']; 146130fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1462c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1463c182313eSAndreas Gohr } elseif($do == 'filelist') { 146400e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1465c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1466ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1467c182313eSAndreas Gohr } else { 1468c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1469c182313eSAndreas Gohr } 1470c182313eSAndreas Gohr } 1471c182313eSAndreas Gohr $evt->advise_after(); 1472c182313eSAndreas Gohr unset($evt); 1473c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1474c182313eSAndreas Gohr 14753df72098SAndreas Gohr} 14763df72098SAndreas Gohr 14773df72098SAndreas Gohr/** 1478d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1479d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1480d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1481d9162c6cSKate Arzamastseva * 1482d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1483d9162c6cSKate Arzamastseva */ 1484035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1485d9162c6cSKate Arzamastseva global $AUTH; 1486d9162c6cSKate Arzamastseva global $NS; 1487d9162c6cSKate Arzamastseva global $JUMPTO; 148895b451bcSAdrian Lang global $lang; 1489585bf44eSChristopher Smith /** @var Input $INPUT */ 1490ac7a515fSAndreas Gohr global $INPUT; 1491d9162c6cSKate Arzamastseva 1492ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1493e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1494ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1495d9162c6cSKate Arzamastseva 149694add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 149795b451bcSAdrian Lang 1498ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 149923846a98SKate Arzamastseva 150094add303SAnika Henke echo '<div class="panelHeader">'.NL; 150195b451bcSAdrian Lang echo '<h3>'; 1502026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1503c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 150494add303SAnika Henke echo '</h3>'.NL; 150595b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 150695b451bcSAdrian Lang media_tab_files_options(); 150723846a98SKate Arzamastseva } 150894add303SAnika Henke echo '</div>'.NL; 1509d9162c6cSKate Arzamastseva 151094add303SAnika Henke echo '<div class="panelContent">'.NL; 151195b451bcSAdrian Lang if($opened_tab == 'files') { 151295b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 151395b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 151495b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 151595b451bcSAdrian Lang } elseif($opened_tab == 'search') { 151695b451bcSAdrian Lang media_tab_search($NS, $AUTH); 151795b451bcSAdrian Lang } 151894add303SAnika Henke echo '</div>'.NL; 1519d9162c6cSKate Arzamastseva} 1520d9162c6cSKate Arzamastseva 1521d9162c6cSKate Arzamastseva/** 1522d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1523d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1524d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1525d9162c6cSKate Arzamastseva * list of file revisions 1526d9162c6cSKate Arzamastseva * 1527d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1528d9162c6cSKate Arzamastseva */ 1529035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1530e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1531585bf44eSChristopher Smith /** @var Input $INPUT */ 1532585bf44eSChristopher Smith global $INPUT; 1533d9162c6cSKate Arzamastseva 153492cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1535ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 15366dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1537e8a2a143SMichael Hamann $ns = getNS($image); 1538ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 15391eeeced2SKate Arzamastseva 1540ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1541e5d185e1SKate Arzamastseva 1542e5d185e1SKate Arzamastseva $tab_array = array('view'); 1543ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1544e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1545e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1546e5d185e1SKate Arzamastseva } 1547e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1548e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1549e5d185e1SKate Arzamastseva } 1550e5d185e1SKate Arzamastseva 1551e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1552ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 155323846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1554d9162c6cSKate Arzamastseva 1555ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 155623846a98SKate Arzamastseva 155759f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1558ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 155995b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 156095b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 156100c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 156208317413SAdrian Lang if($opened_tab === 'view' && $rev) { 156308317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 156408317413SAdrian Lang } else { 1565026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 156608317413SAdrian Lang } 1567b8a84c03SAndreas Gohr 156894add303SAnika Henke echo '</h3></div>'.NL; 156995b451bcSAdrian Lang 157094add303SAnika Henke echo '<div class="panelContent">'.NL; 157195b451bcSAdrian Lang 157223846a98SKate Arzamastseva if($opened_tab == 'view') { 1573e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 157423846a98SKate Arzamastseva 157592cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1576e8a2a143SMichael Hamann media_tab_edit($image, $ns); 157723846a98SKate Arzamastseva 1578e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1579e8a2a143SMichael Hamann media_tab_history($image, $ns); 158023846a98SKate Arzamastseva } 158195b451bcSAdrian Lang 158294add303SAnika Henke echo '</div>'.NL; 1583d9162c6cSKate Arzamastseva} 1584d9162c6cSKate Arzamastseva 1585d9162c6cSKate Arzamastseva/** 15863df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup 15873df72098SAndreas Gohr * 15883df72098SAndreas Gohr * Only allowed in mediamanager.php 15893df72098SAndreas Gohr * 15903df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15913df72098SAndreas Gohr */ 1592fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 15933df72098SAndreas Gohr global $NS; 159423846a98SKate Arzamastseva ptln('<div id="media__tree">'); 15953df72098SAndreas Gohr media_nstree($NS); 15963df72098SAndreas Gohr ptln('</div>'); 15973df72098SAndreas Gohr} 15983df72098SAndreas Gohr 1599a00de5b5SAndreas Gohr/** 1600a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1601a00de5b5SAndreas Gohr * 1602a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1603a00de5b5SAndreas Gohr * 1604a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 160542ea7f44SGerrit Uitslag * 160642ea7f44SGerrit Uitslag * @param string $empty empty option label 160742ea7f44SGerrit Uitslag * @param string $button submit button label 1608a00de5b5SAndreas Gohr */ 1609a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1610a00de5b5SAndreas Gohr global $ID; 1611a00de5b5SAndreas Gohr global $REV; 1612a00de5b5SAndreas Gohr global $lang; 1613585bf44eSChristopher Smith /** @var Input $INPUT */ 1614585bf44eSChristopher Smith global $INPUT; 1615a00de5b5SAndreas Gohr 1616*768d1852SAnika Henke $action_structure = array( 1617*768d1852SAnika Henke 'page_tools' => array('edit', 'revert', 'revisions', 'backlink', 'subscribe'), 1618*768d1852SAnika Henke 'site_tools' => array('recent', 'media', 'index'), 1619*768d1852SAnika Henke 'user_tools' => array('login', 'register', 'profile', 'admin'), 1620*768d1852SAnika Henke ); 1621*768d1852SAnika Henke 1622e63eccffSAndreas Gohr echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 16233b9a3b55SAnika Henke echo '<div class="no">'; 1624a00de5b5SAndreas Gohr echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1625a00de5b5SAndreas Gohr if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 1626585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 1627a00de5b5SAndreas Gohr echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 162861efcda1SChristopher Smith } 1629a00de5b5SAndreas Gohr 16305f17c394SAnika Henke echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1631a00de5b5SAndreas Gohr echo '<option value="">'.$empty.'</option>'; 1632a00de5b5SAndreas Gohr 1633*768d1852SAnika Henke foreach($action_structure as $tools => $actions) { 1634*768d1852SAnika Henke echo '<optgroup label="'.$lang[$tools].'">'; 1635*768d1852SAnika Henke foreach($actions as $action) { 1636*768d1852SAnika Henke $act = tpl_get_action($action); 1637396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1638*768d1852SAnika Henke } 1639a00de5b5SAndreas Gohr echo '</optgroup>'; 1640*768d1852SAnika Henke } 1641a00de5b5SAndreas Gohr 1642a00de5b5SAndreas Gohr echo '</select>'; 1643ae614416SAnika Henke echo '<button type="submit">'.$button.'</button>'; 16443b9a3b55SAnika Henke echo '</div>'; 1645a00de5b5SAndreas Gohr echo '</form>'; 1646a00de5b5SAndreas Gohr} 1647a00de5b5SAndreas Gohr 1648066fee30SAndreas Gohr/** 1649066fee30SAndreas Gohr * Print a informational line about the used license 1650066fee30SAndreas Gohr * 1651066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1652ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1653ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1654ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1655ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1656ac7a515fSAndreas Gohr * @return string 1657066fee30SAndreas Gohr */ 165880083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1659066fee30SAndreas Gohr global $license; 1660066fee30SAndreas Gohr global $conf; 1661066fee30SAndreas Gohr global $lang; 1662066fee30SAndreas Gohr if(!$conf['license']) return ''; 1663066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1664066fee30SAndreas Gohr $lic = $license[$conf['license']]; 166553e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1666066fee30SAndreas Gohr 166780083a41SAndreas Gohr $out = ''; 166880083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1669066fee30SAndreas Gohr if($img) { 1670066fee30SAndreas Gohr $src = license_img($img); 1671066fee30SAndreas Gohr if($src) { 167253e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 167353e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 167453e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1675066fee30SAndreas Gohr } 1676066fee30SAndreas Gohr } 16774cefd216SMichael Klier if(!$imgonly) { 167853e15c8bSAnika Henke $out .= $lang['license'].' '; 1679d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1680d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 16814cefd216SMichael Klier } 168280083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1683066fee30SAndreas Gohr 1684066fee30SAndreas Gohr if($return) return $out; 1685066fee30SAndreas Gohr echo $out; 1686ac7a515fSAndreas Gohr return ''; 1687066fee30SAndreas Gohr} 1688066fee30SAndreas Gohr 1689a81910eeSAndreas Gohr/** 1690835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1691a81910eeSAndreas Gohr * 1692a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1693a81910eeSAndreas Gohr * template 1694e0c26282SGerrit Uitslag * 1695e0c26282SGerrit Uitslag * @param string $pageid 1696e0c26282SGerrit Uitslag * @param bool $print 1697e0c26282SGerrit Uitslag * @param bool $propagate 1698e0c26282SGerrit Uitslag * @return bool|null|string 1699a81910eeSAndreas Gohr */ 1700835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) { 1701c786a1b6SAnika Henke if (!$pageid) return false; 1702835dfcaeSAnika Henke if ($propagate) $pageid = page_findnearest($pageid); 1703835dfcaeSAnika Henke 1704c786a1b6SAnika Henke global $TOC; 17059a2e250aSAndreas Gohr $oldtoc = $TOC; 1706a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 17079a2e250aSAndreas Gohr $TOC = $oldtoc; 1708a81910eeSAndreas Gohr 1709a81910eeSAndreas Gohr if(!$print) return $html; 1710a81910eeSAndreas Gohr echo $html; 1711e66d3e6dSAndreas Gohr return $html; 1712e66d3e6dSAndreas Gohr} 1713e66d3e6dSAndreas Gohr 1714e66d3e6dSAndreas Gohr/** 17155b75cd1fSAdrian Lang * Display the subscribe form 17165b75cd1fSAdrian Lang * 17175b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 17185b75cd1fSAdrian Lang */ 17195b75cd1fSAdrian Langfunction tpl_subscribe() { 17205b75cd1fSAdrian Lang global $INFO; 17215b75cd1fSAdrian Lang global $ID; 17225b75cd1fSAdrian Lang global $lang; 17236b8f02cfSAdrian Lang global $conf; 172440c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 17255b75cd1fSAdrian Lang 17265b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 17275b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 172815741132SAndreas Gohr echo '<div class="level2">'; 17295b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 17305b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 17315b75cd1fSAdrian Lang } else { 17325b75cd1fSAdrian Lang echo '<ul>'; 17335b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1734056c2049SAndreas Gohr echo '<li><div class="li">'; 17355b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1736056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17375b75cd1fSAdrian Lang } else { 1738056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 17395b75cd1fSAdrian Lang } 174040c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 174115741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1742056c2049SAndreas Gohr echo ' ('.$sstl.') '; 174315741132SAndreas Gohr 1744ac7a515fSAndreas Gohr echo '<a href="'.wl( 1745ac7a515fSAndreas Gohr $ID, 1746ac7a515fSAndreas Gohr array( 1747ac7a515fSAndreas Gohr 'do' => 'subscribe', 174866d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 174966d2bed9SAdrian Lang 'sub_style' => $sub['style'], 175066d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1751ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1752ac7a515fSAndreas Gohr ) 1753ac7a515fSAndreas Gohr ). 175466d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 175566d2bed9SAdrian Lang '</a></div></li>'; 17565b75cd1fSAdrian Lang } 17575b75cd1fSAdrian Lang echo '</ul>'; 17585b75cd1fSAdrian Lang } 175915741132SAndreas Gohr echo '</div>'; 17605b75cd1fSAdrian Lang 176115741132SAndreas Gohr // Add new subscription form 17625b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 176315741132SAndreas Gohr echo '<div class="level2">'; 17645b75cd1fSAdrian Lang $ns = getNS($ID).':'; 176515741132SAndreas Gohr $targets = array( 176615741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 176715741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 176815741132SAndreas Gohr ); 176915741132SAndreas Gohr $styles = array( 177015741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 17716b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 17726b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 177315741132SAndreas Gohr ); 177415741132SAndreas Gohr 1775056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1776056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1777056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1778056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1779056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1780056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1781056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1782056c2049SAndreas Gohr $form->addHidden('id', $ID); 1783056c2049SAndreas Gohr $form->endFieldset(); 17845b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 17855b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 178615741132SAndreas Gohr echo '</div>'; 17875b75cd1fSAdrian Lang} 17885b75cd1fSAdrian Lang 1789d059ba9bSAndreas Gohr/** 1790d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1791d059ba9bSAndreas Gohr * 1792d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1793d059ba9bSAndreas Gohr * 1794d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1795d059ba9bSAndreas Gohr */ 1796d059ba9bSAndreas Gohrfunction tpl_flush() { 1797d059ba9bSAndreas Gohr ob_flush(); 1798d059ba9bSAndreas Gohr flush(); 1799d059ba9bSAndreas Gohr} 1800d059ba9bSAndreas Gohr 1801afca7e7eSAnika Henke/** 1802378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1803afca7e7eSAnika Henke * 1804378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1805378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1806378325f9SAndreas Gohr * 180742ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1808378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1809ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1810ac7a515fSAndreas Gohr * @return string 181142ea7f44SGerrit Uitslag * 1812378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1813afca7e7eSAnika Henke */ 1814378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1815ac7a515fSAndreas Gohr $img = ''; 1816ac7a515fSAndreas Gohr $file = ''; 1817ac7a515fSAndreas Gohr $ismedia = false; 1818378325f9SAndreas Gohr // loop through candidates until a match was found: 1819378325f9SAndreas Gohr foreach($search as $img) { 1820378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1821378325f9SAndreas Gohr $file = mediaFN($img); 1822378325f9SAndreas Gohr $ismedia = true; 1823378325f9SAndreas Gohr } else { 1824c4766956SAndreas Gohr $file = tpl_incdir().$img; 1825378325f9SAndreas Gohr $ismedia = false; 18261f13e33dSAnika Henke } 18270f747863Slupo49 1828378325f9SAndreas Gohr if(file_exists($file)) break; 1829872a6d29SAnika Henke } 1830378325f9SAndreas Gohr 1831378325f9SAndreas Gohr // fetch image data if requested 1832378325f9SAndreas Gohr if(!is_null($imginfo)) { 1833378325f9SAndreas Gohr $imginfo = getimagesize($file); 1834378325f9SAndreas Gohr } 1835378325f9SAndreas Gohr 1836378325f9SAndreas Gohr // build URL 1837378325f9SAndreas Gohr if($ismedia) { 1838378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1839378325f9SAndreas Gohr } else { 1840c4766956SAndreas Gohr $url = tpl_basedir().$img; 1841378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1842378325f9SAndreas Gohr } 1843378325f9SAndreas Gohr 1844378325f9SAndreas Gohr return $url; 1845a7e5f74cSlupo49} 18461f13e33dSAnika Henke 1847872a6d29SAnika Henke/** 1848e5d4768dSAndreas Gohr * PHP include a file 1849e5d4768dSAndreas Gohr * 1850e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1851e5d4768dSAndreas Gohr * file in the template's root directory. 1852e5d4768dSAndreas Gohr * 1853e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1854e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1855e5d4768dSAndreas Gohr * default. 1856e5d4768dSAndreas Gohr * 1857e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1858e5d4768dSAndreas Gohr * to this function! 1859e5d4768dSAndreas Gohr * 1860e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1861e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 186242ea7f44SGerrit Uitslag * 186342ea7f44SGerrit Uitslag * @param string $file 1864e5d4768dSAndreas Gohr */ 1865e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1866e5d4768dSAndreas Gohr global $config_cascade; 1867e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1868e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1869e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1870e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1871e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1872f3a1225fSAnika Henke include("$dir/$file"); 1873e5d4768dSAndreas Gohr return; 1874e5d4768dSAndreas Gohr } 1875e5d4768dSAndreas Gohr } 1876e5d4768dSAndreas Gohr } 1877e5d4768dSAndreas Gohr 1878e5d4768dSAndreas Gohr // still here? try the template dir 1879e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1880e5d4768dSAndreas Gohr if(file_exists($file)) { 1881f3a1225fSAnika Henke include($file); 1882e5d4768dSAndreas Gohr } 1883e5d4768dSAndreas Gohr} 1884e5d4768dSAndreas Gohr 1885e5d4768dSAndreas Gohr/** 1886872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1887872a6d29SAnika Henke * 1888872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 188942ea7f44SGerrit Uitslag * 1890ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1891ac7a515fSAndreas Gohr * @return string 1892872a6d29SAnika Henke */ 1893872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1894872a6d29SAnika Henke 1895872a6d29SAnika Henke $return = ''; 1896872a6d29SAnika Henke 1897872a6d29SAnika Henke foreach($types as $type) { 1898872a6d29SAnika Henke switch($type) { 1899872a6d29SAnika Henke case 'favicon': 1900378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1901378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1902872a6d29SAnika Henke break; 1903872a6d29SAnika Henke case 'mobile': 1904cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1905378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1906872a6d29SAnika Henke break; 1907872a6d29SAnika Henke case 'generic': 1908872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1909378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1910378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1911872a6d29SAnika Henke break; 1912872a6d29SAnika Henke } 1913872a6d29SAnika Henke } 1914872a6d29SAnika Henke 1915872a6d29SAnika Henke return $return; 1916afca7e7eSAnika Henke} 1917afca7e7eSAnika Henke 1918d9162c6cSKate Arzamastseva/** 1919d9162c6cSKate Arzamastseva * Prints full-screen media manager 1920d9162c6cSKate Arzamastseva * 1921d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1922d9162c6cSKate Arzamastseva */ 1923d9162c6cSKate Arzamastsevafunction tpl_media() { 1924ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 192588a71175SKate Arzamastseva $fullscreen = true; 192695b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1927d9162c6cSKate Arzamastseva 1928ac7a515fSAndreas Gohr $rev = ''; 1929ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 193098f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 193198f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 19329c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 193398f03b57SKate Arzamastseva 193494add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1935bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1936d9162c6cSKate Arzamastseva html_msgarea(); 193794add303SAnika Henke 193894add303SAnika Henke echo '<div class="panel namespaces">'.NL; 193994add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 194095b451bcSAdrian Lang echo '<div class="panelHeader">'; 1941ba340a70SAnika Henke echo $lang['media_namespaces']; 194294add303SAnika Henke echo '</div>'.NL; 194395b451bcSAdrian Lang 194494add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 194595b451bcSAdrian Lang media_nstree($NS); 194694add303SAnika Henke echo '</div>'.NL; 194794add303SAnika Henke echo '</div>'.NL; 1948fa8e5c77SKate Arzamastseva 194994add303SAnika Henke echo '<div class="panel filelist">'.NL; 1950035e07f1SKate Arzamastseva tpl_mediaFileList(); 195194add303SAnika Henke echo '</div>'.NL; 1952fa8e5c77SKate Arzamastseva 195394add303SAnika Henke echo '<div class="panel file">'.NL; 195494add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1955035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 195694add303SAnika Henke echo '</div>'.NL; 1957ba340a70SAnika Henke 195894add303SAnika Henke echo '</div>'.NL; 1959d9162c6cSKate Arzamastseva} 1960afca7e7eSAnika Henke 1961c71db656SAnika Henke/** 1962c71db656SAnika Henke * Return useful layout classes 1963c71db656SAnika Henke * 1964c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 196542ea7f44SGerrit Uitslag * 196642ea7f44SGerrit Uitslag * @return string 1967c71db656SAnika Henke */ 1968c71db656SAnika Henkefunction tpl_classes() { 1969c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1970585bf44eSChristopher Smith /** @var Input $INPUT */ 1971585bf44eSChristopher Smith global $INPUT; 1972585bf44eSChristopher Smith 1973c71db656SAnika Henke $classes = array( 1974c71db656SAnika Henke 'dokuwiki', 1975c71db656SAnika Henke 'mode_'.$ACT, 1976c71db656SAnika Henke 'tpl_'.$conf['template'], 1977585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 197839f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1979c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1980c71db656SAnika Henke ); 1981c71db656SAnika Henke return join(' ', $classes); 1982c71db656SAnika Henke} 1983c71db656SAnika Henke 1984e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1985a00de5b5SAndreas Gohr 1986