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> 36ac7a515fSAndreas Gohr * @return string 37c4766956SAndreas Gohr */ 38c4766956SAndreas Gohrfunction tpl_incdir() { 3975b14482SAndreas Gohr global $conf; 40c4766956SAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'; 41c4766956SAndreas Gohr} 42c4766956SAndreas Gohr 43c4766956SAndreas Gohr/** 44c4766956SAndreas Gohr * Convenience function to access template dir from web 45c4766956SAndreas Gohr * 46c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 47c4766956SAndreas Gohr * 48c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 49ac7a515fSAndreas Gohr * @return string 50c4766956SAndreas Gohr */ 51c4766956SAndreas Gohrfunction tpl_basedir() { 5275b14482SAndreas Gohr global $conf; 53c4766956SAndreas Gohr return DOKU_BASE.'lib/tpl/'.$conf['template'].'/'; 54c4766956SAndreas Gohr} 55c4766956SAndreas Gohr 565a892029SAndreas Gohr/** 576b13307fSandi * Print the content 586b13307fSandi * 596b13307fSandi * This function is used for printing all the usual content 606b13307fSandi * (defined by the global $ACT var) by calling the appropriate 616b13307fSandi * outputfunction(s) from html.php 626b13307fSandi * 63ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 64ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 656b13307fSandi * 666b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 67ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 68ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 69ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 70ac7a515fSAndreas Gohr * @return bool true if any output 716b13307fSandi */ 72b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 737ea0913cSchris global $ACT; 74b8595a66SAndreas Gohr global $INFO; 75b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 767ea0913cSchris 777ea0913cSchris ob_start(); 78746855cfSBen Coburn trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 797ea0913cSchris $html_output = ob_get_clean(); 80746855cfSBen Coburn trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8154e95700STom N Harris 8254e95700STom N Harris return !empty($html_output); 837ea0913cSchris} 847ea0913cSchris 85ac7a515fSAndreas Gohr/** 86ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 87ac7a515fSAndreas Gohr * 88ac7a515fSAndreas Gohr * @return bool 89ac7a515fSAndreas Gohr */ 907ea0913cSchrisfunction tpl_content_core() { 916b13307fSandi global $ACT; 926b13307fSandi global $TEXT; 936b13307fSandi global $PRE; 946b13307fSandi global $SUF; 956b13307fSandi global $SUM; 966b13307fSandi global $IDX; 97ac7a515fSAndreas Gohr global $INPUT; 986b13307fSandi 996b13307fSandi switch($ACT) { 1006b13307fSandi case 'show': 1016b13307fSandi html_show(); 1026b13307fSandi break; 103ac7a515fSAndreas Gohr /** @noinspection PhpMissingBreakStatementInspection */ 10445a99335SAdrian Lang case 'locked': 10545a99335SAdrian Lang html_locked(); 1066b13307fSandi case 'edit': 10745a99335SAdrian Lang case 'recover': 1086b13307fSandi html_edit(); 1096b13307fSandi break; 11045a99335SAdrian Lang case 'preview': 11145a99335SAdrian Lang html_edit(); 11245a99335SAdrian Lang html_show($TEXT); 11345a99335SAdrian Lang break; 114ee4c4a1bSAndreas Gohr case 'draft': 115ee4c4a1bSAndreas Gohr html_draft(); 116ee4c4a1bSAndreas Gohr break; 1176b13307fSandi case 'search': 1186b13307fSandi html_search(); 1196b13307fSandi break; 1206b13307fSandi case 'revisions': 121ac7a515fSAndreas Gohr html_revisions($INPUT->int('first')); 1226b13307fSandi break; 1236b13307fSandi case 'diff': 1246b13307fSandi html_diff(); 1256b13307fSandi break; 1266b13307fSandi case 'recent': 1273c94d07bSAnika Henke $show_changes = $INPUT->str('show_changes'); 1283c94d07bSAnika Henke if (empty($show_changes)) { 1293c94d07bSAnika Henke $show_changes = get_doku_pref('show_changes', $show_changes); 1303c94d07bSAnika Henke } 1313c94d07bSAnika Henke html_recent($INPUT->extract('first')->int('first'), $show_changes); 1326b13307fSandi break; 1336b13307fSandi case 'index': 1346b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 1356b13307fSandi break; 1366b13307fSandi case 'backlink': 1376b13307fSandi html_backlinks(); 1386b13307fSandi break; 1396b13307fSandi case 'conflict': 1406b13307fSandi html_conflict(con($PRE, $TEXT, $SUF), $SUM); 1416b13307fSandi html_diff(con($PRE, $TEXT, $SUF), false); 1426b13307fSandi break; 1436b13307fSandi case 'login': 1446b13307fSandi html_login(); 1456b13307fSandi break; 1466b13307fSandi case 'register': 1476b13307fSandi html_register(); 1486b13307fSandi break; 1498b06d178Schris case 'resendpwd': 1508b06d178Schris html_resendpwd(); 1518b06d178Schris break; 152820fa24bSandi case 'denied': 1535e991bd8Sandi print p_locale_xhtml('denied'); 154820fa24bSandi break; 1558b06d178Schris case 'profile' : 1568b06d178Schris html_updateprofile(); 1578b06d178Schris break; 158c19fe9c0Sandi case 'admin': 159c19fe9c0Sandi tpl_admin(); 160c19fe9c0Sandi break; 1615b75cd1fSAdrian Lang case 'subscribe': 1625b75cd1fSAdrian Lang tpl_subscribe(); 1635b75cd1fSAdrian Lang break; 164d9162c6cSKate Arzamastseva case 'media': 165d9162c6cSKate Arzamastseva tpl_media(); 166d9162c6cSKate Arzamastseva break; 1676b13307fSandi default: 16824bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); 16924bb549bSchris if($evt->advise_before()) 170ea67f144Sandi msg("Failed to handle command: ".hsc($ACT), -1); 17124bb549bSchris $evt->advise_after(); 17224bb549bSchris unset($evt); 17354e95700STom N Harris return false; 1746b13307fSandi } 17554e95700STom N Harris return true; 1766b13307fSandi} 1776b13307fSandi 178c19fe9c0Sandi/** 179b8595a66SAndreas Gohr * Places the TOC where the function is called 180b8595a66SAndreas Gohr * 181b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 182b8595a66SAndreas Gohr * a false argument 183b8595a66SAndreas Gohr * 184b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 185ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 186ac7a515fSAndreas Gohr * @return string 187b8595a66SAndreas Gohr */ 188b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 189b8595a66SAndreas Gohr global $TOC; 190b8595a66SAndreas Gohr global $ACT; 191b8595a66SAndreas Gohr global $ID; 192b8595a66SAndreas Gohr global $REV; 193b8595a66SAndreas Gohr global $INFO; 194851f2e89SAnika Henke global $conf; 195ac7a515fSAndreas Gohr global $INPUT; 196b8595a66SAndreas Gohr $toc = array(); 197b8595a66SAndreas Gohr 198b8595a66SAndreas Gohr if(is_array($TOC)) { 199b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 200b8595a66SAndreas Gohr $toc = $TOC; 2013c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 202b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 20365aa8490SMichael Hamann $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE); 204b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 205b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 206b8595a66SAndreas Gohr } else { 2072bb0d541Schris $tocok = true; 208b8595a66SAndreas Gohr } 209b8595a66SAndreas Gohr $toc = $meta['description']['tableofcontents']; 210851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 211b8595a66SAndreas Gohr $toc = array(); 212b8595a66SAndreas Gohr } 213b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 214b8595a66SAndreas Gohr // try to load admin plugin TOC FIXME: duplicates code from tpl_admin 215b8595a66SAndreas Gohr $plugin = null; 216ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 217ac7a515fSAndreas Gohr if(!empty($class)) { 218b8595a66SAndreas Gohr $pluginlist = plugin_list('admin'); 219ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 220b8595a66SAndreas Gohr // attempt to load the plugin 221ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 222ac7a515fSAndreas Gohr $plugin =& plugin_load('admin', $class); 223b8595a66SAndreas Gohr } 224b8595a66SAndreas Gohr } 225ac7a515fSAndreas Gohr if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { 226b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 227b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 228b8595a66SAndreas Gohr } 229b8595a66SAndreas Gohr } 230b8595a66SAndreas Gohr 2310b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 232b8595a66SAndreas Gohr $html = html_TOC($toc); 233b8595a66SAndreas Gohr if($return) return $html; 234b8595a66SAndreas Gohr echo $html; 235ac7a515fSAndreas Gohr return ''; 236b8595a66SAndreas Gohr} 237b8595a66SAndreas Gohr 238b8595a66SAndreas Gohr/** 239c19fe9c0Sandi * Handle the admin page contents 240c19fe9c0Sandi * 241c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 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 */ 256ac7a515fSAndreas Gohr $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> 276ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 277ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 278ac7a515fSAndreas Gohr * @return bool 2796b13307fSandi */ 280f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2816b13307fSandi global $ID; 282d98d4540SBen Coburn global $REV; 2836b13307fSandi global $INFO; 28472e0dc37SAndreas Gohr global $JSINFO; 2856b13307fSandi global $ACT; 2864bb1b5aeSAndreas Gohr global $QUERY; 2876b13307fSandi global $lang; 288dc57ef04Sandi global $conf; 2896b13307fSandi 2907bff22c0SAndreas Gohr // prepare the head array 2917bff22c0SAndreas Gohr $head = array(); 2927bff22c0SAndreas Gohr 293202ac28bSMichael Klier // prepare seed for js and css 294cd997f93SAndreas Gohr $tseed = $updateVersion; 295202ac28bSMichael Klier $depends = getConfigFiles('main'); 296cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 297cd997f93SAndreas Gohr $tseed = md5($tseed); 2987bff22c0SAndreas Gohr 2996b13307fSandi // the usual stuff 3003f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 301ac7a515fSAndreas Gohr $head['link'][] = array( 302ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 303ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 304ac7a515fSAndreas Gohr ); 305f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 3067aedde2eSGina Haeussge if(actionOK('index')) { 307ac7a515fSAndreas Gohr $head['link'][] = array( 308ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 309ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 310ac7a515fSAndreas Gohr ); 3117aedde2eSGina Haeussge } 312f96fa415SAndreas Gohr 313f96fa415SAndreas Gohr if($alt) { 314ac7a515fSAndreas Gohr $head['link'][] = array( 315ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 316ac7a515fSAndreas Gohr 'title'=> 'Recent Changes', 'href'=> DOKU_BASE.'feed.php' 317ac7a515fSAndreas Gohr ); 318ac7a515fSAndreas Gohr $head['link'][] = array( 319ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 3207bff22c0SAndreas Gohr 'title'=> 'Current Namespace', 321ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 322ac7a515fSAndreas Gohr ); 323c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 324ac7a515fSAndreas Gohr $head['link'][] = array( 325ac7a515fSAndreas Gohr 'rel' => 'edit', 326715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 327ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 328ac7a515fSAndreas Gohr ); 329c35f3875SAndreas Gohr } 330c35f3875SAndreas Gohr 3314bb1b5aeSAndreas Gohr if($ACT == 'search') { 332ac7a515fSAndreas Gohr $head['link'][] = array( 333ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 3344bb1b5aeSAndreas Gohr 'title'=> 'Search Result', 335ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 336ac7a515fSAndreas Gohr ); 3374bb1b5aeSAndreas Gohr } 338bae36d94SAndreas Gohr 339bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 340ac7a515fSAndreas Gohr $head['link'][] = array( 341ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> 'Plain HTML', 342ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 343ac7a515fSAndreas Gohr ); 344bae36d94SAndreas Gohr } 345bae36d94SAndreas Gohr 346bae36d94SAndreas Gohr if(actionOK('export_raw')) { 347ac7a515fSAndreas Gohr $head['link'][] = array( 348ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> 'Wiki Markup', 349ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 350ac7a515fSAndreas Gohr ); 351f96fa415SAndreas Gohr } 352bae36d94SAndreas Gohr } 3536b13307fSandi 3546b13307fSandi // setup robot tags apropriate for different modes 3554f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3566b13307fSandi if($INFO['exists']) { 3576b13307fSandi //delay indexing: 3586b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { 3597bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3606b13307fSandi } else { 3617bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3626b13307fSandi } 36369db0cafSAndreas Gohr $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&')); 3646b13307fSandi } else { 3657bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3666b13307fSandi } 3677a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3687bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3696b13307fSandi } else { 3707bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3716b13307fSandi } 3726b13307fSandi 373831800b8SAndreas Gohr // set metadata 374831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 375831800b8SAndreas Gohr // date of modification 376831800b8SAndreas Gohr if($REV) { 3777bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV)); 378831800b8SAndreas Gohr } else { 3797bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod'])); 380831800b8SAndreas Gohr } 381831800b8SAndreas Gohr 382831800b8SAndreas Gohr // keywords (explicit or implicit) 383bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3847bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 385831800b8SAndreas Gohr } else { 3867bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 387831800b8SAndreas Gohr } 388831800b8SAndreas Gohr } 389831800b8SAndreas Gohr 39078a6aeb1SAndreas Gohr // load stylesheets 391ac7a515fSAndreas Gohr $head['link'][] = array( 392ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 393ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed 394ac7a515fSAndreas Gohr ); 395bad31ae9SAndreas Gohr 3968bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 397463d4a65SAndreas Gohr $json = new JSON(); 39872e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 399c591aabeSAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER']) { 40072e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 401c591aabeSAndreas Gohr } 40272e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 40385f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 4048bbcb611SAndreas Gohr 4058bbcb611SAndreas Gohr // load external javascript 406ac7a515fSAndreas Gohr $head['script'][] = array( 407ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 408ac7a515fSAndreas Gohr 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed 409ac7a515fSAndreas Gohr ); 4107bff22c0SAndreas Gohr 4117bff22c0SAndreas Gohr // trigger event here 412016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 41354e95700STom N Harris return true; 4147bff22c0SAndreas Gohr} 4157bff22c0SAndreas Gohr 4167bff22c0SAndreas Gohr/** 4177bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4187bff22c0SAndreas Gohr * 4197bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4207bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4217bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4227bff22c0SAndreas Gohr * 4237bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special 4241304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4257bff22c0SAndreas Gohr * 4267bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4277bff22c0SAndreas Gohr */ 4287bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 4297bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 4307bff22c0SAndreas Gohr foreach($inst as $attr) { 4317bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 43226afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 433e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 43409f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 435e226efe1SAndreas Gohr $attr['_data']. 43609f791c4SDominik Eckelmann "\n/*!]]>*/"; 437e226efe1SAndreas Gohr 4381304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 4397bff22c0SAndreas Gohr } else { 4407bff22c0SAndreas Gohr echo '/>'; 4417bff22c0SAndreas Gohr } 4427bff22c0SAndreas Gohr echo "\n"; 4437bff22c0SAndreas Gohr } 4447bff22c0SAndreas Gohr } 4456b13307fSandi} 4466b13307fSandi 4476b13307fSandi/** 4486b13307fSandi * Print a link 4496b13307fSandi * 4505e163278SAndreas Gohr * Just builds a link. 4516b13307fSandi * 4526b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 4536b13307fSandi */ 4541af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 45501f17825SAnika Henke $out = '<a href="'.$url.'" '; 4561af98a77SAnika Henke if($more) $out .= ' '.$more; 4571af98a77SAnika Henke $out .= ">$name</a>"; 4581af98a77SAnika Henke if($return) return $out; 4591af98a77SAnika Henke print $out; 46054e95700STom N Harris return true; 4616b13307fSandi} 4626b13307fSandi 4636b13307fSandi/** 46455efc227SAndreas Gohr * Prints a link to a WikiPage 46555efc227SAndreas Gohr * 46655efc227SAndreas Gohr * Wrapper around html_wikilink 46755efc227SAndreas Gohr * 46855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 46955efc227SAndreas Gohr */ 4700b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 47155efc227SAndreas Gohr print html_wikilink($id, $name); 47254e95700STom N Harris return true; 47355efc227SAndreas Gohr} 47455efc227SAndreas Gohr 47555efc227SAndreas Gohr/** 476a3ec5f4aSmatthiasgrimm * get the parent page 477a3ec5f4aSmatthiasgrimm * 478a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 479a3ec5f4aSmatthiasgrimm * returns false if none is available 480a3ec5f4aSmatthiasgrimm * 481377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 482a3ec5f4aSmatthiasgrimm */ 483377f9e97SAndreas Gohrfunction tpl_getparent($id) { 484377f9e97SAndreas Gohr $parent = getNS($id).':'; 485377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 486a197105eSmatthiasgrimm if($parent == $id) { 487a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 488a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 489a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 490377f9e97SAndreas Gohr if($parent == $id) return false; 491a197105eSmatthiasgrimm } 492377f9e97SAndreas Gohr return $parent; 493a3ec5f4aSmatthiasgrimm} 494a3ec5f4aSmatthiasgrimm 495a3ec5f4aSmatthiasgrimm/** 4966b13307fSandi * Print one of the buttons 4976b13307fSandi * 498a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 499a453d131SAdrian Lang * @see tpl_get_action 5006b13307fSandi */ 5011af98a77SAnika Henkefunction tpl_button($type, $return = false) { 502a453d131SAdrian Lang $data = tpl_get_action($type); 503a453d131SAdrian Lang if($data === false) { 504a453d131SAdrian Lang return false; 505a453d131SAdrian Lang } elseif(!is_array($data)) { 506a453d131SAdrian Lang $out = sprintf($data, 'button'); 507409d7af7SAndreas Gohr } else { 508ac7a515fSAndreas Gohr /** 509ac7a515fSAndreas Gohr * @var string $accesskey 510ac7a515fSAndreas Gohr * @var string $id 511ac7a515fSAndreas Gohr * @var string $method 512ac7a515fSAndreas Gohr * @var array $params 513ac7a515fSAndreas Gohr */ 514a453d131SAdrian Lang extract($data); 515a453d131SAdrian Lang if($id === '#dokuwiki__top') { 516a453d131SAdrian Lang $out = html_topbtn(); 517409d7af7SAndreas Gohr } else { 518a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 519409d7af7SAndreas Gohr } 520409d7af7SAndreas Gohr } 5211af98a77SAnika Henke if($return) return $out; 522a453d131SAdrian Lang echo $out; 523a453d131SAdrian Lang return true; 5246b13307fSandi} 5256b13307fSandi 5266b13307fSandi/** 527ed630903Sandi * Like the action buttons but links 528ed630903Sandi * 529a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 530a453d131SAdrian Lang * @see tpl_get_action 531a453d131SAdrian Lang */ 532a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 533a453d131SAdrian Lang global $lang; 534a453d131SAdrian Lang $data = tpl_get_action($type); 535a453d131SAdrian Lang if($data === false) { 536a453d131SAdrian Lang return false; 537a453d131SAdrian Lang } elseif(!is_array($data)) { 538a453d131SAdrian Lang $out = sprintf($data, 'link'); 539a453d131SAdrian Lang } else { 540ac7a515fSAndreas Gohr /** 541ac7a515fSAndreas Gohr * @var string $accesskey 542ac7a515fSAndreas Gohr * @var string $id 543ac7a515fSAndreas Gohr * @var string $method 544*b1af9014SChristopher Smith * @var bool $nofollow 545ac7a515fSAndreas Gohr * @var array $params 546ac7a515fSAndreas Gohr */ 547a453d131SAdrian Lang extract($data); 548a453d131SAdrian Lang if(strpos($id, '#') === 0) { 549a453d131SAdrian Lang $linktarget = $id; 550a453d131SAdrian Lang } else { 551a453d131SAdrian Lang $linktarget = wl($id, $params); 552a453d131SAdrian Lang } 553a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 554c7e90e3fSAnika Henke $akey = $addTitle = ''; 555c7e90e3fSAnika Henke if($accesskey) { 556c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 557c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 558c7e90e3fSAnika Henke } 559*b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 560ac7a515fSAndreas Gohr $out = tpl_link( 561ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 562a453d131SAdrian Lang 'class="action '.$type.'" '. 563*b1af9014SChristopher Smith $akey.$rel. 564ac7a515fSAndreas Gohr 'title="'.hsc($caption).$addTitle.'"', 1 565ac7a515fSAndreas Gohr ); 566a453d131SAdrian Lang } 567a453d131SAdrian Lang if($return) return $out; 568a453d131SAdrian Lang echo $out; 569a453d131SAdrian Lang return true; 570a453d131SAdrian Lang} 571a453d131SAdrian Lang 572a453d131SAdrian Lang/** 573a453d131SAdrian Lang * Check the actions and get data for buttons and links 574ed630903Sandi * 575a453d131SAdrian Lang * Available actions are 576a453d131SAdrian Lang * 577a453d131SAdrian Lang * edit - edit/create/show/draft 578ed630903Sandi * history - old revisions 579ed630903Sandi * recent - recent changes 580a453d131SAdrian Lang * login - login/logout - if ACL enabled 581a453d131SAdrian Lang * profile - user profile (if logged in) 582ed630903Sandi * index - The index 583ed630903Sandi * admin - admin page - if enough rights 584a453d131SAdrian Lang * top - back to top 585a453d131SAdrian Lang * back - back to parent - if available 586bbd37938SAndreas Gohr * backlink - links to the list of backlinks 587a453d131SAdrian Lang * subscribe/subscription- subscribe/unsubscribe 588ed630903Sandi * 589ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 590a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 591a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 592ac7a515fSAndreas Gohr * @param string $type 593ac7a515fSAndreas Gohr * @return array|bool|string 594ed630903Sandi */ 595a453d131SAdrian Langfunction tpl_get_action($type) { 596ed630903Sandi global $ID; 597ed630903Sandi global $INFO; 598ed630903Sandi global $REV; 599ed630903Sandi global $ACT; 600*b1af9014SChristopher Smith global $conf; 601ed630903Sandi 60275e487e9SAndreas Gohr // check disabled actions and fix the badly named ones 603a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 604a453d131SAdrian Lang if(!actionOK($type)) return false; 605409d7af7SAndreas Gohr 606a453d131SAdrian Lang $accesskey = null; 6076709e843SAdrian Lang $id = $ID; 608a453d131SAdrian Lang $method = 'get'; 609a453d131SAdrian Lang $params = array('do' => $type); 610*b1af9014SChristopher Smith $nofollow = true; 611ed630903Sandi switch($type) { 612ed630903Sandi case 'edit': 6130b17fdc6SAndreas Gohr // most complicated type - we need to decide on current action 614ed630903Sandi if($ACT == 'show' || $ACT == 'search') { 615a453d131SAdrian Lang $method = 'post'; 616ed630903Sandi if($INFO['writable']) { 617a453d131SAdrian Lang $accesskey = 'e'; 618b8a111f5SMichael Klier if(!empty($INFO['draft'])) { 6196709e843SAdrian Lang $type = 'draft'; 620a453d131SAdrian Lang $params['do'] = 'draft'; 621b8a111f5SMichael Klier } else { 622a453d131SAdrian Lang $params['rev'] = $REV; 623a453d131SAdrian Lang if(!$INFO['exists']) { 6246709e843SAdrian Lang $type = 'create'; 625ed630903Sandi } 626b8a111f5SMichael Klier } 627ed630903Sandi } else { 628a453d131SAdrian Lang if(!actionOK('source')) return false; //pseudo action 629a453d131SAdrian Lang $params['rev'] = $REV; 6306709e843SAdrian Lang $type = 'source'; 631a453d131SAdrian Lang $accesskey = 'v'; 632ed630903Sandi } 633ed630903Sandi } else { 63484148531SMichael Hamann $params = array(); 6356709e843SAdrian Lang $type = 'show'; 636a453d131SAdrian Lang $accesskey = 'v'; 637ed630903Sandi } 6381af98a77SAnika Henke break; 639a453d131SAdrian Lang case 'revisions': 6406709e843SAdrian Lang $type = 'revs'; 641a453d131SAdrian Lang $accesskey = 'o'; 6421af98a77SAnika Henke break; 643ed630903Sandi case 'recent': 644a453d131SAdrian Lang $accesskey = 'r'; 6451af98a77SAnika Henke break; 646ed630903Sandi case 'index': 647a453d131SAdrian Lang $accesskey = 'x'; 648*b1af9014SChristopher Smith // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml) 649*b1af9014SChristopher Smith if ($conf['start'] == $ID && !$conf['sitemap']) { 650*b1af9014SChristopher Smith $nofollow = false; 651*b1af9014SChristopher Smith } 6521af98a77SAnika Henke break; 653ed630903Sandi case 'top': 654076f0d72SAnika Henke $accesskey = 't'; 65584148531SMichael Hamann $params = array(); 656a453d131SAdrian Lang $id = '#dokuwiki__top'; 6571af98a77SAnika Henke break; 658a3ec5f4aSmatthiasgrimm case 'back': 659a453d131SAdrian Lang $parent = tpl_getparent($ID); 660a453d131SAdrian Lang if(!$parent) { 661a453d131SAdrian Lang return false; 662a3ec5f4aSmatthiasgrimm } 663a453d131SAdrian Lang $id = $parent; 66484148531SMichael Hamann $params = array(); 665a453d131SAdrian Lang $accesskey = 'b'; 6661af98a77SAnika Henke break; 667ed630903Sandi case 'login': 668a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 6692380e8a8SAdrian Lang if(isset($_SERVER['REMOTE_USER'])) { 6703a48618aSAnika Henke if(!actionOK('logout')) { 6712380e8a8SAdrian Lang return false; 6722380e8a8SAdrian Lang } 673a453d131SAdrian Lang $params['do'] = 'logout'; 674a453d131SAdrian Lang $type = 'logout'; 675bf413a4eSAnika Henke } 676bf413a4eSAnika Henke break; 677bf413a4eSAnika Henke case 'register': 678bf413a4eSAnika Henke if($_SERVER['REMOTE_USER']) { 679bf413a4eSAnika Henke return false; 680bf413a4eSAnika Henke } 681bf413a4eSAnika Henke break; 682bf413a4eSAnika Henke case 'resendpwd': 683bf413a4eSAnika Henke if($_SERVER['REMOTE_USER']) { 684bf413a4eSAnika Henke return false; 685ed630903Sandi } 6861af98a77SAnika Henke break; 687ed630903Sandi case 'admin': 688a453d131SAdrian Lang if(!$INFO['ismanager']) { 689a453d131SAdrian Lang return false; 690c059e1a6SAndreas Gohr } 6911af98a77SAnika Henke break; 6921246e016SAndreas Gohr case 'revert': 693a453d131SAdrian Lang if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { 694a453d131SAdrian Lang return false; 6951246e016SAndreas Gohr } 696a453d131SAdrian Lang $params['rev'] = $REV; 697a453d131SAdrian Lang $params['sectok'] = getSecurityToken(); 6981246e016SAndreas Gohr break; 699ac7a515fSAndreas Gohr /** @noinspection PhpMissingBreakStatementInspection */ 700075f000fSChristopher Arndt case 'subscription': 7016709e843SAdrian Lang $type = 'subscribe'; 702a453d131SAdrian Lang $params['do'] = 'subscribe'; 7036709e843SAdrian Lang case 'subscribe': 7043a48618aSAnika Henke if(!$_SERVER['REMOTE_USER']) { 705a453d131SAdrian Lang return false; 706b158d625SSteven Danz } 7071af98a77SAnika Henke break; 708f00151b4Schris case 'backlink': 7091af98a77SAnika Henke break; 7108b06d178Schris case 'profile': 7113a48618aSAnika Henke if(!isset($_SERVER['REMOTE_USER'])) { 712a453d131SAdrian Lang return false; 7138b06d178Schris } 7141af98a77SAnika Henke break; 715b9eb2e61SKate Arzamastseva case 'media': 716d08527abSAnika Henke $params['ns'] = getNS($ID); 717b9eb2e61SKate Arzamastseva break; 718ed630903Sandi default: 719a453d131SAdrian Lang return '[unknown %s type]'; 7201af98a77SAnika Henke break; 721ed630903Sandi } 722*b1af9014SChristopher Smith return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow'); 723ed630903Sandi} 724ed630903Sandi 725ed630903Sandi/** 72601f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 72701f17825SAnika Henke * 72801f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 729ac7a515fSAndreas Gohr * @param 730ac7a515fSAndreas Gohr * @param bool $link link or form button? 731ac7a515fSAndreas Gohr * @param bool $wrapper HTML element wrapper 732ac7a515fSAndreas Gohr * @param bool $return return or print 733ac7a515fSAndreas Gohr * @param string $pre prefix for links 734ac7a515fSAndreas Gohr * @param string $suf suffix for links 735ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 736ac7a515fSAndreas Gohr * @return bool|string 73701f17825SAnika Henke */ 738ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 73901f17825SAnika Henke $out = ''; 740ac7a515fSAndreas Gohr if($link) { 741ac7a515fSAndreas Gohr $out .= tpl_actionlink($type, $pre, $suf, $inner, 1); 742ac7a515fSAndreas Gohr } else { 743ac7a515fSAndreas Gohr $out .= tpl_button($type, 1); 744ac7a515fSAndreas Gohr } 74501f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 74601f17825SAnika Henke 74701f17825SAnika Henke if($return) return $out; 74801f17825SAnika Henke print $out; 74901f17825SAnika Henke return $out ? true : false; 75001f17825SAnika Henke} 75101f17825SAnika Henke 75201f17825SAnika Henke/** 7536b13307fSandi * Print the search form 7546b13307fSandi * 75572645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 75672645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 75772645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 75872645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 75972645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 76072645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 76172645b75SAndreas Gohr * 7626b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 763ac7a515fSAndreas Gohr * @param bool $ajax 764ac7a515fSAndreas Gohr * @param bool $autocomplete 765ac7a515fSAndreas Gohr * @return bool 7666b13307fSandi */ 76772645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 7686b13307fSandi global $lang; 769c1e3b7d9Smatthiasgrimm global $ACT; 770ad4aaef7SAndreas Gohr global $QUERY; 771c1e3b7d9Smatthiasgrimm 772670ff54eSchris // don't print the search form if search action has been disabled 77364276bbcSarbrk1 if(!actionOK('search')) return false; 774670ff54eSchris 775156dbd62SGina Haeussge print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get"><div class="no">'; 7766b13307fSandi print '<input type="hidden" name="do" value="search" />'; 777c1e3b7d9Smatthiasgrimm print '<input type="text" '; 778ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 77972645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 78007493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 78111ea018fSAndreas Gohr print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; 78224a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 7834beabca9SAnika Henke print '</div></form>'; 78454e95700STom N Harris return true; 7856b13307fSandi} 7866b13307fSandi 7876b13307fSandi/** 7886b13307fSandi * Print the breadcrumbs trace 7896b13307fSandi * 7906b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 791ac7a515fSAndreas Gohr * @param string $sep Separator between entries 792ac7a515fSAndreas Gohr * @return bool 7936b13307fSandi */ 794e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 7956b13307fSandi global $lang; 7966b13307fSandi global $conf; 7976b13307fSandi 7986b13307fSandi //check if enabled 799359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 8006b13307fSandi 8016b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 802265e3787Sandi 8032979a10bSKatriel Traum //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups 8042979a10bSKatriel Traum if($lang['direction'] == 'rtl') { 8052979a10bSKatriel Traum $crumbs = array_reverse($crumbs, true); 8062979a10bSKatriel Traum $crumbs_sep = ' ‏<span class="bcsep">'.$sep.'</span>‏ '; 8072979a10bSKatriel Traum } else { 8082979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 8092979a10bSKatriel Traum } 810265e3787Sandi 81140eb54bbSjan //render crumbs, highlight the last one 8121b6f3a44SAndreas Gohr print '<span class="bchead">'.$lang['breadcrumb'].':</span>'; 81340eb54bbSjan $last = count($crumbs); 81440eb54bbSjan $i = 0; 815a77f5846Sjan foreach($crumbs as $id => $name) { 81640eb54bbSjan $i++; 8172979a10bSKatriel Traum echo $crumbs_sep; 81892795d04Sandi if($i == $last) print '<span class="curid">'; 819e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 82092795d04Sandi if($i == $last) print '</span>'; 8216b13307fSandi } 82254e95700STom N Harris return true; 8236b13307fSandi} 8246b13307fSandi 8256b13307fSandi/** 8261734437eSandi * Hierarchical breadcrumbs 8271734437eSandi * 82831e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8291734437eSandi * It only makes sense with a deep site structure. 8301734437eSandi * 8311734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 8326bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 83331e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 834f46c9e83SAnika Henke * @author <fredrik@averpil.com> 8356bd812dfSNigel McNie * @todo May behave strangely in RTL languages 836ac7a515fSAndreas Gohr * @param string $sep Separator between entries 837ac7a515fSAndreas Gohr * @return bool 8381734437eSandi */ 839e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') { 8401734437eSandi global $conf; 8411734437eSandi global $ID; 8421734437eSandi global $lang; 8431734437eSandi 84431e187f8SSean Coates // check if enabled 84554e95700STom N Harris if(!$conf['youarehere']) return false; 8461734437eSandi 8471734437eSandi $parts = explode(':', $ID); 848796bafb3SAndreas Gohr $count = count($parts); 8491734437eSandi 8501b6f3a44SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].': </span>'; 8511734437eSandi 8521734437eSandi // always print the startpage 853fca4df27SAnika Henke echo '<span class="home">'; 854e013f48dSAnika Henke tpl_pagelink(':'.$conf['start']); 855fca4df27SAnika Henke echo '</span>'; 856796bafb3SAndreas Gohr 857796bafb3SAndreas Gohr // print intermediate namespace links 858796bafb3SAndreas Gohr $part = ''; 859796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 860796bafb3SAndreas Gohr $part .= $parts[$i].':'; 861796bafb3SAndreas Gohr $page = $part; 862796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 863796bafb3SAndreas Gohr 864796bafb3SAndreas Gohr // output 865796bafb3SAndreas Gohr echo $sep; 866e013f48dSAnika Henke tpl_pagelink($page); 86731e187f8SSean Coates } 8681734437eSandi 869796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 870e013f48dSAnika Henke resolve_pageid('', $page, $exists); 871ac7a515fSAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 872796bafb3SAndreas Gohr $page = $part.$parts[$i]; 873ac7a515fSAndreas Gohr if($page == $conf['start']) return true; 874796bafb3SAndreas Gohr echo $sep; 875e013f48dSAnika Henke tpl_pagelink($page); 87654e95700STom N Harris return true; 8771734437eSandi} 8781734437eSandi 8791734437eSandi/** 8806b13307fSandi * Print info if the user is logged in 881a2488c3cSMatthias Grimm * and show full name in that case 8826b13307fSandi * 8836b13307fSandi * Could be enhanced with a profile link in future? 8846b13307fSandi * 8856b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 886ac7a515fSAndreas Gohr * @return bool 8876b13307fSandi */ 8886b13307fSandifunction tpl_userinfo() { 8896b13307fSandi global $lang; 8903e63b73bSMichael Klier global $INFO; 891c66972f2SAdrian Lang if(isset($_SERVER['REMOTE_USER'])) { 892d9e0d8dcSVadim Nevorotin print $lang['loggedinas'].': '.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')'; 89354e95700STom N Harris return true; 89454e95700STom N Harris } 89554e95700STom N Harris return false; 8966b13307fSandi} 8976b13307fSandi 8986b13307fSandi/** 8996b13307fSandi * Print some info about the current page 9006b13307fSandi * 9016b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 902ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 903ac7a515fSAndreas Gohr * @return bool|string 9046b13307fSandi */ 9054b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 9066b13307fSandi global $conf; 9076b13307fSandi global $lang; 9086b13307fSandi global $INFO; 909c6e92a3cSDavid Lorentsen global $ID; 910c6e92a3cSDavid Lorentsen 911c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 912ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 913ac7a515fSAndreas Gohr return false; 914ac7a515fSAndreas Gohr } 9156b13307fSandi 9166b13307fSandi // prepare date and path 9176b13307fSandi $fn = $INFO['filepath']; 9186b13307fSandi if(!$conf['fullpath']) { 919613bca54SAndreas Gohr if($INFO['rev']) { 92050fbebceSGina Haeussge $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn); 9216b13307fSandi } else { 92250fbebceSGina Haeussge $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn); 9236b13307fSandi } 9246b13307fSandi } 925bee6dc82Sandi $fn = utf8_decodeFN($fn); 926f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 9276b13307fSandi 928faecdfdfSAndreas Gohr // print it 929faecdfdfSAndreas Gohr if($INFO['exists']) { 9304b0d3916SAndreas Gohr $out = ''; 9314b0d3916SAndreas Gohr $out .= $fn; 932e260f93bSAnika Henke $out .= ' · '; 9334b0d3916SAndreas Gohr $out .= $lang['lastmod']; 9344b0d3916SAndreas Gohr $out .= ': '; 9354b0d3916SAndreas Gohr $out .= $date; 9366b13307fSandi if($INFO['editor']) { 9374b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 938dc58b6f4SAndy Webber $out .= editorinfo($INFO['editor']); 9395aa52fafSBen Coburn } else { 9404b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 9416b13307fSandi } 9426b13307fSandi if($INFO['locked']) { 943e260f93bSAnika Henke $out .= ' · '; 9444b0d3916SAndreas Gohr $out .= $lang['lockedby']; 9454b0d3916SAndreas Gohr $out .= ': '; 946dc58b6f4SAndy Webber $out .= editorinfo($INFO['locked']); 9476b13307fSandi } 9484b0d3916SAndreas Gohr if($ret) { 9494b0d3916SAndreas Gohr return $out; 9504b0d3916SAndreas Gohr } else { 9514b0d3916SAndreas Gohr echo $out; 95254e95700STom N Harris return true; 9536b13307fSandi } 9544b0d3916SAndreas Gohr } 95554e95700STom N Harris return false; 9566b13307fSandi} 9576b13307fSandi 958820fa24bSandi/** 959a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 96087c434ceSAndreas Gohr * 96187c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 962a6598f23SBen Coburn * the given ID is used. 96387c434ceSAndreas Gohr * 96487c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 965ac7a515fSAndreas Gohr * @param string $id page id 966ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 967ac7a515fSAndreas Gohr * @return bool|string 96887c434ceSAndreas Gohr */ 969a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 97087c434ceSAndreas Gohr if(is_null($id)) { 97187c434ceSAndreas Gohr global $ID; 97287c434ceSAndreas Gohr $id = $ID; 97387c434ceSAndreas Gohr } 97487c434ceSAndreas Gohr 97587c434ceSAndreas Gohr $name = $id; 976fe9ec250SChris Smith if(useHeading('navigation')) { 97787c434ceSAndreas Gohr $title = p_get_first_heading($id); 97887c434ceSAndreas Gohr if($title) $name = $title; 97987c434ceSAndreas Gohr } 980a6598f23SBen Coburn 981a6598f23SBen Coburn if($ret) { 982a6598f23SBen Coburn return hsc($name); 983a6598f23SBen Coburn } else { 98487c434ceSAndreas Gohr print hsc($name); 98554e95700STom N Harris return true; 98687c434ceSAndreas Gohr } 987a6598f23SBen Coburn} 988340756e4Sandi 98955efc227SAndreas Gohr/** 99055efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 99155efc227SAndreas Gohr * 99255efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 99355efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 99455efc227SAndreas Gohr * 99555efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 99655efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 99755efc227SAndreas Gohr * to the names of the latter one) 99855efc227SAndreas Gohr * 9993df72098SAndreas Gohr * Only allowed in: detail.php 100055efc227SAndreas Gohr * 100155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1002ac7a515fSAndreas Gohr * @param array $tags tags to try 1003ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1004ac7a515fSAndreas Gohr * @param null $src the image src, uses global $SRC if not given 1005ac7a515fSAndreas Gohr * @return string 100655efc227SAndreas Gohr */ 10073df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 100855efc227SAndreas Gohr // Init Exif Reader 100955efc227SAndreas Gohr global $SRC; 10103df72098SAndreas Gohr 10113df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10123df72098SAndreas Gohr 101355efc227SAndreas Gohr static $meta = null; 10143df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 101555efc227SAndreas Gohr if($meta === false) return $alt; 101655efc227SAndreas Gohr $info = $meta->getField($tags); 101755efc227SAndreas Gohr if($info == false) return $alt; 101855efc227SAndreas Gohr return $info; 101955efc227SAndreas Gohr} 102055efc227SAndreas Gohr 102155efc227SAndreas Gohr/** 102255efc227SAndreas Gohr * Prints the image with a link to the full sized version 102355efc227SAndreas Gohr * 102455efc227SAndreas Gohr * Only allowed in: detail.php 1025a02d2933SAndreas Gohr * 1026ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1027a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1028a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1029a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1030a02d2933SAndreas Gohr * @param $params array - additional image attributes 1031ac7a515fSAndreas Gohr * @return mixed Result of TPL_IMG_DISPLAY 103255efc227SAndreas Gohr */ 1033a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 103455efc227SAndreas Gohr global $IMG; 1035ac7a515fSAndreas Gohr global $INPUT; 103655efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 103755efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 103855efc227SAndreas Gohr 103955efc227SAndreas Gohr //resize to given max values 104023a34783SAndreas Gohr $ratio = 1; 104123a34783SAndreas Gohr if($w >= $h) { 1042f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 104355efc227SAndreas Gohr $ratio = $maxwidth / $w; 1044f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 104555efc227SAndreas Gohr $ratio = $maxheight / $h; 104655efc227SAndreas Gohr } 104755efc227SAndreas Gohr } else { 1048f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 104955efc227SAndreas Gohr $ratio = $maxheight / $h; 1050f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 105155efc227SAndreas Gohr $ratio = $maxwidth / $w; 105255efc227SAndreas Gohr } 105355efc227SAndreas Gohr } 105455efc227SAndreas Gohr if($ratio) { 105555efc227SAndreas Gohr $w = floor($ratio * $w); 105655efc227SAndreas Gohr $h = floor($ratio * $h); 105755efc227SAndreas Gohr } 105855efc227SAndreas Gohr 10596de3759aSAndreas Gohr //prepare URLs 1060ac7a515fSAndreas Gohr $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&'); 1061ac7a515fSAndreas Gohr $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&'); 106255efc227SAndreas Gohr 10632684e50aSAndreas Gohr //prepare attributes 106455efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1065a02d2933SAndreas Gohr if(is_null($params)) { 10662684e50aSAndreas Gohr $p = array(); 1067a02d2933SAndreas Gohr } else { 1068a02d2933SAndreas Gohr $p = $params; 1069a02d2933SAndreas Gohr } 10702684e50aSAndreas Gohr if($w) $p['width'] = $w; 10712684e50aSAndreas Gohr if($h) $p['height'] = $h; 10722684e50aSAndreas Gohr $p['class'] = 'img_detail'; 10732684e50aSAndreas Gohr if($alt) { 10742684e50aSAndreas Gohr $p['alt'] = $alt; 10752684e50aSAndreas Gohr $p['title'] = $alt; 10762684e50aSAndreas Gohr } else { 10772684e50aSAndreas Gohr $p['alt'] = ''; 10782684e50aSAndreas Gohr } 1079a02d2933SAndreas Gohr $p['src'] = $src; 108055efc227SAndreas Gohr 1081a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1082a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1083a02d2933SAndreas Gohr} 1084a02d2933SAndreas Gohr 1085a02d2933SAndreas Gohr/** 1086a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1087ac7a515fSAndreas Gohr * 1088ac7a515fSAndreas Gohr * @param array $data 1089ac7a515fSAndreas Gohr * @return bool 1090a02d2933SAndreas Gohr */ 1091ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 109259f3611bSAnika Henke global $lang; 1093a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1094a02d2933SAndreas Gohr 109559f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1096a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1097a02d2933SAndreas Gohr if($data['url']) print '</a>'; 109854e95700STom N Harris return true; 109955efc227SAndreas Gohr} 110055efc227SAndreas Gohr 11017367b368SAndreas Gohr/** 1102881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 11037367b368SAndreas Gohr * 11047367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 11057367b368SAndreas Gohr * template 1106ac7a515fSAndreas Gohr * 1107ac7a515fSAndreas Gohr * @return bool 11087367b368SAndreas Gohr */ 11097367b368SAndreas Gohrfunction tpl_indexerWebBug() { 11107367b368SAndreas Gohr global $ID; 11111dad36f5SAndreas Gohr 11127367b368SAndreas Gohr $p = array(); 1113b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1114e68c51baSAndreas Gohr '&'.time(); 1115881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 11167367b368SAndreas Gohr $p['height'] = 1; 11177367b368SAndreas Gohr $p['alt'] = ''; 11187367b368SAndreas Gohr $att = buildAttributes($p); 11197367b368SAndreas Gohr print "<img $att />"; 112054e95700STom N Harris return true; 11217367b368SAndreas Gohr} 11227367b368SAndreas Gohr 112378d4e784SEsther Brunner/** 112478d4e784SEsther Brunner * tpl_getConf($id) 112578d4e784SEsther Brunner * 112678d4e784SEsther Brunner * use this function to access template configuration variables 1127ac7a515fSAndreas Gohr * 1128ac7a515fSAndreas Gohr * @param string $id 1129ac7a515fSAndreas Gohr * @return string 113078d4e784SEsther Brunner */ 113178d4e784SEsther Brunnerfunction tpl_getConf($id) { 113278d4e784SEsther Brunner global $conf; 113317566ac6SAdrian Lang static $tpl_configloaded = false; 113478d4e784SEsther Brunner 113578d4e784SEsther Brunner $tpl = $conf['template']; 113678d4e784SEsther Brunner 113778d4e784SEsther Brunner if(!$tpl_configloaded) { 113878d4e784SEsther Brunner $tconf = tpl_loadConfig(); 113978d4e784SEsther Brunner if($tconf !== false) { 114078d4e784SEsther Brunner foreach($tconf as $key => $value) { 114178d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 114278d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 114378d4e784SEsther Brunner } 114478d4e784SEsther Brunner $tpl_configloaded = true; 114578d4e784SEsther Brunner } 114678d4e784SEsther Brunner } 114778d4e784SEsther Brunner 114878d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 114978d4e784SEsther Brunner} 115078d4e784SEsther Brunner 115178d4e784SEsther Brunner/** 115278d4e784SEsther Brunner * tpl_loadConfig() 1153ac7a515fSAndreas Gohr * 115478d4e784SEsther Brunner * reads all template configuration variables 115578d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1156ac7a515fSAndreas Gohr * 1157ac7a515fSAndreas Gohr * @return array 115878d4e784SEsther Brunner */ 115978d4e784SEsther Brunnerfunction tpl_loadConfig() { 116078d4e784SEsther Brunner 1161c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 116278d4e784SEsther Brunner $conf = array(); 116378d4e784SEsther Brunner 116478d4e784SEsther Brunner if(!@file_exists($file)) return false; 116578d4e784SEsther Brunner 116678d4e784SEsther Brunner // load default config file 116778d4e784SEsther Brunner include($file); 116878d4e784SEsther Brunner 116978d4e784SEsther Brunner return $conf; 117078d4e784SEsther Brunner} 117178d4e784SEsther Brunner 117217566ac6SAdrian Lang// language methods 117317566ac6SAdrian Lang/** 117417566ac6SAdrian Lang * tpl_getLang($id) 117517566ac6SAdrian Lang * 117617566ac6SAdrian Lang * use this function to access template language variables 117717566ac6SAdrian Lang */ 117817566ac6SAdrian Langfunction tpl_getLang($id) { 117917566ac6SAdrian Lang static $lang = array(); 118017566ac6SAdrian Lang 118117566ac6SAdrian Lang if(count($lang) === 0) { 1182c4766956SAndreas Gohr $path = tpl_incdir().'lang/'; 118317566ac6SAdrian Lang 118417566ac6SAdrian Lang $lang = array(); 118517566ac6SAdrian Lang 118617566ac6SAdrian Lang global $conf; // definitely don't invoke "global $lang" 118717566ac6SAdrian Lang // don't include once 118817566ac6SAdrian Lang @include($path.'en/lang.php'); 118917566ac6SAdrian Lang if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); 119017566ac6SAdrian Lang } 119117566ac6SAdrian Lang 119217566ac6SAdrian Lang return $lang[$id]; 119317566ac6SAdrian Lang} 119417566ac6SAdrian Lang 11953df72098SAndreas Gohr/** 11963df72098SAndreas Gohr * prints the "main content" in the mediamanger popup 11973df72098SAndreas Gohr * 11983df72098SAndreas Gohr * Depending on the user's actions this may be a list of 11993df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 12003df72098SAndreas Gohr * a message of referencing pages 12013df72098SAndreas Gohr * 12023df72098SAndreas Gohr * Only allowed in mediamanager.php 12033df72098SAndreas Gohr * 1204c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1205c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 12063df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 12073df72098SAndreas Gohr */ 1208c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax = false) { 12093df72098SAndreas Gohr global $IMG; 12103df72098SAndreas Gohr global $AUTH; 12113df72098SAndreas Gohr global $INUSE; 12123df72098SAndreas Gohr global $NS; 12133df72098SAndreas Gohr global $JUMPTO; 1214ac7a515fSAndreas Gohr global $INPUT; 12153df72098SAndreas Gohr 1216ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1217c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1218c182313eSAndreas Gohr 1219c182313eSAndreas Gohr if(!$do) { 1220ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1221c182313eSAndreas Gohr $do = 'metaform'; 1222c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1223c182313eSAndreas Gohr $do = 'filesinuse'; 1224c182313eSAndreas Gohr } else { 1225c182313eSAndreas Gohr $do = 'filelist'; 1226c182313eSAndreas Gohr } 1227c182313eSAndreas Gohr } 1228c182313eSAndreas Gohr 1229c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1230c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1231c182313eSAndreas Gohr $data = array('do' => $do); 1232c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1233c182313eSAndreas Gohr if($evt->advise_before()) { 1234c182313eSAndreas Gohr $do = $data['do']; 123530fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1236c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1237c182313eSAndreas Gohr } elseif($do == 'filelist') { 1238c182313eSAndreas Gohr media_filelist($NS, $AUTH, $JUMPTO); 1239c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1240ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1241c182313eSAndreas Gohr } else { 1242c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1243c182313eSAndreas Gohr } 1244c182313eSAndreas Gohr } 1245c182313eSAndreas Gohr $evt->advise_after(); 1246c182313eSAndreas Gohr unset($evt); 1247c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1248c182313eSAndreas Gohr 12493df72098SAndreas Gohr} 12503df72098SAndreas Gohr 12513df72098SAndreas Gohr/** 1252d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1253d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1254d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1255d9162c6cSKate Arzamastseva * 1256d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1257d9162c6cSKate Arzamastseva */ 1258035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1259d9162c6cSKate Arzamastseva global $AUTH; 1260d9162c6cSKate Arzamastseva global $NS; 1261d9162c6cSKate Arzamastseva global $JUMPTO; 126295b451bcSAdrian Lang global $lang; 1263ac7a515fSAndreas Gohr global $INPUT; 1264d9162c6cSKate Arzamastseva 1265ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1266e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1267ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1268d9162c6cSKate Arzamastseva 126994add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 127095b451bcSAdrian Lang 1271ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 127223846a98SKate Arzamastseva 127394add303SAnika Henke echo '<div class="panelHeader">'.NL; 127495b451bcSAdrian Lang echo '<h3>'; 1275026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1276c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 127794add303SAnika Henke echo '</h3>'.NL; 127895b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 127995b451bcSAdrian Lang media_tab_files_options(); 128023846a98SKate Arzamastseva } 128194add303SAnika Henke echo '</div>'.NL; 1282d9162c6cSKate Arzamastseva 128394add303SAnika Henke echo '<div class="panelContent">'.NL; 128495b451bcSAdrian Lang if($opened_tab == 'files') { 128595b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 128695b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 128795b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 128895b451bcSAdrian Lang } elseif($opened_tab == 'search') { 128995b451bcSAdrian Lang media_tab_search($NS, $AUTH); 129095b451bcSAdrian Lang } 129194add303SAnika Henke echo '</div>'.NL; 1292d9162c6cSKate Arzamastseva} 1293d9162c6cSKate Arzamastseva 1294d9162c6cSKate Arzamastseva/** 1295d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1296d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1297d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1298d9162c6cSKate Arzamastseva * list of file revisions 1299d9162c6cSKate Arzamastseva * 1300d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1301d9162c6cSKate Arzamastseva */ 1302035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1303ac7a515fSAndreas Gohr global $AUTH, $NS, $conf, $DEL, $lang, $INPUT; 1304d9162c6cSKate Arzamastseva 130592cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1306ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 13076dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1308ac7a515fSAndreas Gohr if(isset($NS) && getNS($image) != $NS) return; 1309ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 13101eeeced2SKate Arzamastseva 1311ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1312e5d185e1SKate Arzamastseva 1313e5d185e1SKate Arzamastseva $tab_array = array('view'); 1314ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1315e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1316e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1317e5d185e1SKate Arzamastseva } 1318e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1319e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1320e5d185e1SKate Arzamastseva } 1321e5d185e1SKate Arzamastseva 1322e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1323ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 132423846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1325d9162c6cSKate Arzamastseva 1326ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 132723846a98SKate Arzamastseva 132859f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1329ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 133095b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 133195b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 133200c2d4a9SAnika Henke $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 133308317413SAdrian Lang if($opened_tab === 'view' && $rev) { 133408317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 133508317413SAdrian Lang } else { 1336026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 133708317413SAdrian Lang } 1338b8a84c03SAndreas Gohr 133994add303SAnika Henke echo '</h3></div>'.NL; 134095b451bcSAdrian Lang 134194add303SAnika Henke echo '<div class="panelContent">'.NL; 134295b451bcSAdrian Lang 134323846a98SKate Arzamastseva if($opened_tab == 'view') { 134423846a98SKate Arzamastseva media_tab_view($image, $NS, $AUTH, $rev); 134523846a98SKate Arzamastseva 134692cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 134723846a98SKate Arzamastseva media_tab_edit($image, $NS, $AUTH); 134823846a98SKate Arzamastseva 1349e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 135010799f9cSKate Arzamastseva media_tab_history($image, $NS, $AUTH); 135123846a98SKate Arzamastseva } 135295b451bcSAdrian Lang 135394add303SAnika Henke echo '</div>'.NL; 1354d9162c6cSKate Arzamastseva} 1355d9162c6cSKate Arzamastseva 1356d9162c6cSKate Arzamastseva/** 13573df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup 13583df72098SAndreas Gohr * 13593df72098SAndreas Gohr * Only allowed in mediamanager.php 13603df72098SAndreas Gohr * 13613df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13623df72098SAndreas Gohr */ 1363fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 13643df72098SAndreas Gohr global $NS; 136523846a98SKate Arzamastseva ptln('<div id="media__tree">'); 13663df72098SAndreas Gohr media_nstree($NS); 13673df72098SAndreas Gohr ptln('</div>'); 13683df72098SAndreas Gohr} 13693df72098SAndreas Gohr 1370a00de5b5SAndreas Gohr/** 1371a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1372a00de5b5SAndreas Gohr * 1373a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1374a00de5b5SAndreas Gohr * 1375a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1376a00de5b5SAndreas Gohr */ 1377a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1378a00de5b5SAndreas Gohr global $ID; 1379a00de5b5SAndreas Gohr global $REV; 1380a00de5b5SAndreas Gohr global $lang; 1381a00de5b5SAndreas Gohr 1382e63eccffSAndreas Gohr echo '<form action="'.script().'" method="get" accept-charset="utf-8">'; 13833b9a3b55SAnika Henke echo '<div class="no">'; 1384a00de5b5SAndreas Gohr echo '<input type="hidden" name="id" value="'.$ID.'" />'; 1385a00de5b5SAndreas Gohr if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; 138661efcda1SChristopher Smith if ($_SERVER['REMOTE_USER']) { 1387a00de5b5SAndreas Gohr echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; 138861efcda1SChristopher Smith } 1389a00de5b5SAndreas Gohr 13905f17c394SAnika Henke echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">'; 1391a00de5b5SAndreas Gohr echo '<option value="">'.$empty.'</option>'; 1392a00de5b5SAndreas Gohr 139361917024SAnika Henke echo '<optgroup label="'.$lang['page_tools'].'">'; 1394396c218fSAndreas Gohr $act = tpl_get_action('edit'); 1395396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1396a00de5b5SAndreas Gohr 1397396c218fSAndreas Gohr $act = tpl_get_action('revert'); 1398396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1399396c218fSAndreas Gohr 14003b9a3b55SAnika Henke $act = tpl_get_action('revisions'); 14013b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 14023b9a3b55SAnika Henke 1403396c218fSAndreas Gohr $act = tpl_get_action('backlink'); 1404396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 14053b9a3b55SAnika Henke 14063b9a3b55SAnika Henke $act = tpl_get_action('subscribe'); 14073b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1408a00de5b5SAndreas Gohr echo '</optgroup>'; 1409a00de5b5SAndreas Gohr 141061917024SAnika Henke echo '<optgroup label="'.$lang['site_tools'].'">'; 1411396c218fSAndreas Gohr $act = tpl_get_action('recent'); 1412396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1413396c218fSAndreas Gohr 14143b9a3b55SAnika Henke $act = tpl_get_action('media'); 14153b9a3b55SAnika Henke if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 14163b9a3b55SAnika Henke 1417396c218fSAndreas Gohr $act = tpl_get_action('index'); 1418396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1419a00de5b5SAndreas Gohr echo '</optgroup>'; 1420a00de5b5SAndreas Gohr 142161917024SAnika Henke echo '<optgroup label="'.$lang['user_tools'].'">'; 1422396c218fSAndreas Gohr $act = tpl_get_action('login'); 1423396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1424a00de5b5SAndreas Gohr 14253b9a3b55SAnika Henke $act = tpl_get_action('register'); 1426396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1427a00de5b5SAndreas Gohr 14283b9a3b55SAnika Henke $act = tpl_get_action('profile'); 1429396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1430a00de5b5SAndreas Gohr 1431396c218fSAndreas Gohr $act = tpl_get_action('admin'); 1432396c218fSAndreas Gohr if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; 1433a00de5b5SAndreas Gohr echo '</optgroup>'; 1434a00de5b5SAndreas Gohr 1435a00de5b5SAndreas Gohr echo '</select>'; 1436f22c1964SAndreas Gohr echo '<input type="submit" value="'.$button.'" />'; 14373b9a3b55SAnika Henke echo '</div>'; 1438a00de5b5SAndreas Gohr echo '</form>'; 1439a00de5b5SAndreas Gohr} 1440a00de5b5SAndreas Gohr 1441066fee30SAndreas Gohr/** 1442066fee30SAndreas Gohr * Print a informational line about the used license 1443066fee30SAndreas Gohr * 1444066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1445ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1446ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1447ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1448ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1449ac7a515fSAndreas Gohr * @return string 1450066fee30SAndreas Gohr */ 145180083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1452066fee30SAndreas Gohr global $license; 1453066fee30SAndreas Gohr global $conf; 1454066fee30SAndreas Gohr global $lang; 1455066fee30SAndreas Gohr if(!$conf['license']) return ''; 1456066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1457066fee30SAndreas Gohr $lic = $license[$conf['license']]; 145853e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1459066fee30SAndreas Gohr 146080083a41SAndreas Gohr $out = ''; 146180083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1462066fee30SAndreas Gohr if($img) { 1463066fee30SAndreas Gohr $src = license_img($img); 1464066fee30SAndreas Gohr if($src) { 146553e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 146653e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 146753e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1468066fee30SAndreas Gohr } 1469066fee30SAndreas Gohr } 14704cefd216SMichael Klier if(!$imgonly) { 147153e15c8bSAnika Henke $out .= $lang['license'].' '; 147253e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1473066fee30SAndreas Gohr $out .= '>'.$lic['name'].'</a>'; 14744cefd216SMichael Klier } 147580083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1476066fee30SAndreas Gohr 1477066fee30SAndreas Gohr if($return) return $out; 1478066fee30SAndreas Gohr echo $out; 1479ac7a515fSAndreas Gohr return ''; 1480066fee30SAndreas Gohr} 1481066fee30SAndreas Gohr 1482a81910eeSAndreas Gohr/** 1483835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1484a81910eeSAndreas Gohr * 1485a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1486a81910eeSAndreas Gohr * template 1487a81910eeSAndreas Gohr */ 1488835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) { 1489c786a1b6SAnika Henke if (!$pageid) return false; 1490835dfcaeSAnika Henke if ($propagate) $pageid = page_findnearest($pageid); 1491835dfcaeSAnika Henke 1492c786a1b6SAnika Henke global $TOC; 14939a2e250aSAndreas Gohr $oldtoc = $TOC; 1494a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 14959a2e250aSAndreas Gohr $TOC = $oldtoc; 1496a81910eeSAndreas Gohr 1497a81910eeSAndreas Gohr if(!$print) return $html; 1498a81910eeSAndreas Gohr echo $html; 1499e66d3e6dSAndreas Gohr return $html; 1500e66d3e6dSAndreas Gohr} 1501e66d3e6dSAndreas Gohr 1502e66d3e6dSAndreas Gohr/** 15035b75cd1fSAdrian Lang * Display the subscribe form 15045b75cd1fSAdrian Lang * 15055b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15065b75cd1fSAdrian Lang */ 15075b75cd1fSAdrian Langfunction tpl_subscribe() { 15085b75cd1fSAdrian Lang global $INFO; 15095b75cd1fSAdrian Lang global $ID; 15105b75cd1fSAdrian Lang global $lang; 15116b8f02cfSAdrian Lang global $conf; 151240c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 15135b75cd1fSAdrian Lang 15145b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 15155b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 151615741132SAndreas Gohr echo '<div class="level2">'; 15175b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 15185b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 15195b75cd1fSAdrian Lang } else { 15205b75cd1fSAdrian Lang echo '<ul>'; 15215b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1522056c2049SAndreas Gohr echo '<li><div class="li">'; 15235b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1524056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15255b75cd1fSAdrian Lang } else { 1526056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15275b75cd1fSAdrian Lang } 152840c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 152915741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1530056c2049SAndreas Gohr echo ' ('.$sstl.') '; 153115741132SAndreas Gohr 1532ac7a515fSAndreas Gohr echo '<a href="'.wl( 1533ac7a515fSAndreas Gohr $ID, 1534ac7a515fSAndreas Gohr array( 1535ac7a515fSAndreas Gohr 'do' => 'subscribe', 153666d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 153766d2bed9SAdrian Lang 'sub_style' => $sub['style'], 153866d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1539ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1540ac7a515fSAndreas Gohr ) 1541ac7a515fSAndreas Gohr ). 154266d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 154366d2bed9SAdrian Lang '</a></div></li>'; 15445b75cd1fSAdrian Lang } 15455b75cd1fSAdrian Lang echo '</ul>'; 15465b75cd1fSAdrian Lang } 154715741132SAndreas Gohr echo '</div>'; 15485b75cd1fSAdrian Lang 154915741132SAndreas Gohr // Add new subscription form 15505b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 155115741132SAndreas Gohr echo '<div class="level2">'; 15525b75cd1fSAdrian Lang $ns = getNS($ID).':'; 155315741132SAndreas Gohr $targets = array( 155415741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 155515741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 155615741132SAndreas Gohr ); 155715741132SAndreas Gohr $styles = array( 155815741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 15596b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 15606b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 156115741132SAndreas Gohr ); 156215741132SAndreas Gohr 1563056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1564056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1565056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1566056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1567056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1568056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1569056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1570056c2049SAndreas Gohr $form->addHidden('id', $ID); 1571056c2049SAndreas Gohr $form->endFieldset(); 15725b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 15735b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 157415741132SAndreas Gohr echo '</div>'; 15755b75cd1fSAdrian Lang} 15765b75cd1fSAdrian Lang 1577d059ba9bSAndreas Gohr/** 1578d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1579d059ba9bSAndreas Gohr * 1580d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1581d059ba9bSAndreas Gohr * 1582d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1583d059ba9bSAndreas Gohr */ 1584d059ba9bSAndreas Gohrfunction tpl_flush() { 1585d059ba9bSAndreas Gohr ob_flush(); 1586d059ba9bSAndreas Gohr flush(); 1587d059ba9bSAndreas Gohr} 1588d059ba9bSAndreas Gohr 1589afca7e7eSAnika Henke/** 1590378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1591afca7e7eSAnika Henke * 1592378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1593378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1594378325f9SAndreas Gohr * 1595378325f9SAndreas Gohr * @param array $search locations to look at 1596378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1597ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1598ac7a515fSAndreas Gohr * @return string 1599378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1600afca7e7eSAnika Henke */ 1601378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1602ac7a515fSAndreas Gohr $img = ''; 1603ac7a515fSAndreas Gohr $file = ''; 1604ac7a515fSAndreas Gohr $ismedia = false; 1605378325f9SAndreas Gohr // loop through candidates until a match was found: 1606378325f9SAndreas Gohr foreach($search as $img) { 1607378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1608378325f9SAndreas Gohr $file = mediaFN($img); 1609378325f9SAndreas Gohr $ismedia = true; 1610378325f9SAndreas Gohr } else { 1611c4766956SAndreas Gohr $file = tpl_incdir().$img; 1612378325f9SAndreas Gohr $ismedia = false; 16131f13e33dSAnika Henke } 16140f747863Slupo49 1615378325f9SAndreas Gohr if(file_exists($file)) break; 1616872a6d29SAnika Henke } 1617378325f9SAndreas Gohr 1618378325f9SAndreas Gohr // fetch image data if requested 1619378325f9SAndreas Gohr if(!is_null($imginfo)) { 1620378325f9SAndreas Gohr $imginfo = getimagesize($file); 1621378325f9SAndreas Gohr } 1622378325f9SAndreas Gohr 1623378325f9SAndreas Gohr // build URL 1624378325f9SAndreas Gohr if($ismedia) { 1625378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1626378325f9SAndreas Gohr } else { 1627c4766956SAndreas Gohr $url = tpl_basedir().$img; 1628378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1629378325f9SAndreas Gohr } 1630378325f9SAndreas Gohr 1631378325f9SAndreas Gohr return $url; 1632a7e5f74cSlupo49} 16331f13e33dSAnika Henke 1634872a6d29SAnika Henke/** 1635e5d4768dSAndreas Gohr * PHP include a file 1636e5d4768dSAndreas Gohr * 1637e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1638e5d4768dSAndreas Gohr * file in the template's root directory. 1639e5d4768dSAndreas Gohr * 1640e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1641e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1642e5d4768dSAndreas Gohr * default. 1643e5d4768dSAndreas Gohr * 1644e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1645e5d4768dSAndreas Gohr * to this function! 1646e5d4768dSAndreas Gohr * 1647e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1648e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1649e5d4768dSAndreas Gohr */ 1650e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1651e5d4768dSAndreas Gohr global $config_cascade; 1652e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1653e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1654e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1655e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1656e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1657f3a1225fSAnika Henke include("$dir/$file"); 1658e5d4768dSAndreas Gohr return; 1659e5d4768dSAndreas Gohr } 1660e5d4768dSAndreas Gohr } 1661e5d4768dSAndreas Gohr } 1662e5d4768dSAndreas Gohr 1663e5d4768dSAndreas Gohr // still here? try the template dir 1664e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1665e5d4768dSAndreas Gohr if(file_exists($file)) { 1666f3a1225fSAnika Henke include($file); 1667e5d4768dSAndreas Gohr } 1668e5d4768dSAndreas Gohr} 1669e5d4768dSAndreas Gohr 1670e5d4768dSAndreas Gohr/** 167127833958SAnika Henke * Returns icon from data/media root directory if it exists, otherwise 167227833958SAnika Henke * the one in the template's image directory. 167327833958SAnika Henke * 167427833958SAnika Henke * @deprecated Use tpl_getMediaFile() instead 167527833958SAnika Henke * @author Anika Henke <anika@selfthinker.org> 167627833958SAnika Henke */ 167727833958SAnika Henkefunction tpl_getFavicon($abs = false, $fileName = 'favicon.ico') { 1678378325f9SAndreas Gohr $look = array(":wiki:$fileName", ":$fileName", "images/$fileName"); 1679378325f9SAndreas Gohr return tpl_getMediaFile($look, $abs); 168027833958SAnika Henke} 168127833958SAnika Henke 168227833958SAnika Henke/** 1683872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1684872a6d29SAnika Henke * 1685872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 1686ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1687ac7a515fSAndreas Gohr * @return string 1688872a6d29SAnika Henke */ 1689872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1690872a6d29SAnika Henke 1691872a6d29SAnika Henke $return = ''; 1692872a6d29SAnika Henke 1693872a6d29SAnika Henke foreach($types as $type) { 1694872a6d29SAnika Henke switch($type) { 1695872a6d29SAnika Henke case 'favicon': 1696378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1697378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1698872a6d29SAnika Henke break; 1699872a6d29SAnika Henke case 'mobile': 1700cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1701378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1702872a6d29SAnika Henke break; 1703872a6d29SAnika Henke case 'generic': 1704872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1705378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1706378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1707872a6d29SAnika Henke break; 1708872a6d29SAnika Henke } 1709872a6d29SAnika Henke } 1710872a6d29SAnika Henke 1711872a6d29SAnika Henke return $return; 1712afca7e7eSAnika Henke} 1713afca7e7eSAnika Henke 1714d9162c6cSKate Arzamastseva/** 1715d9162c6cSKate Arzamastseva * Prints full-screen media manager 1716d9162c6cSKate Arzamastseva * 1717d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1718d9162c6cSKate Arzamastseva */ 1719d9162c6cSKate Arzamastsevafunction tpl_media() { 1720ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 172188a71175SKate Arzamastseva $fullscreen = true; 172295b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1723d9162c6cSKate Arzamastseva 1724ac7a515fSAndreas Gohr $rev = ''; 1725ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 172698f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 172798f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 17289c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 172998f03b57SKate Arzamastseva 173094add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1731bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1732d9162c6cSKate Arzamastseva html_msgarea(); 173394add303SAnika Henke 173494add303SAnika Henke echo '<div class="panel namespaces">'.NL; 173594add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 173695b451bcSAdrian Lang echo '<div class="panelHeader">'; 1737ba340a70SAnika Henke echo $lang['media_namespaces']; 173894add303SAnika Henke echo '</div>'.NL; 173995b451bcSAdrian Lang 174094add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 174195b451bcSAdrian Lang media_nstree($NS); 174294add303SAnika Henke echo '</div>'.NL; 174394add303SAnika Henke echo '</div>'.NL; 1744fa8e5c77SKate Arzamastseva 174594add303SAnika Henke echo '<div class="panel filelist">'.NL; 1746035e07f1SKate Arzamastseva tpl_mediaFileList(); 174794add303SAnika Henke echo '</div>'.NL; 1748fa8e5c77SKate Arzamastseva 174994add303SAnika Henke echo '<div class="panel file">'.NL; 175094add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1751035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 175294add303SAnika Henke echo '</div>'.NL; 1753ba340a70SAnika Henke 175494add303SAnika Henke echo '</div>'.NL; 1755d9162c6cSKate Arzamastseva} 1756afca7e7eSAnika Henke 1757e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1758a00de5b5SAndreas Gohr 1759