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 96b13307fSandi if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10e7cb32dcSAndreas Gohr require_once(DOKU_CONF.'dokuwiki.php'); 116b13307fSandi 126b13307fSandi/** 135a892029SAndreas Gohr * Returns the path to the given template, uses 145a892029SAndreas Gohr * default one if the custom version doesn't exist 155a892029SAndreas Gohr * 165a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 175a892029SAndreas Gohr */ 185a892029SAndreas Gohrfunction template($tpl){ 195a892029SAndreas Gohr global $conf; 205a892029SAndreas Gohr 215a892029SAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) 225a892029SAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; 235a892029SAndreas Gohr 245a892029SAndreas Gohr return DOKU_INC.'lib/tpl/default/'.$tpl; 255a892029SAndreas Gohr} 265a892029SAndreas Gohr 275a892029SAndreas Gohr/** 286b13307fSandi * Print the content 296b13307fSandi * 306b13307fSandi * This function is used for printing all the usual content 316b13307fSandi * (defined by the global $ACT var) by calling the appropriate 326b13307fSandi * outputfunction(s) from html.php 336b13307fSandi * 34ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 35ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 366b13307fSandi * 376b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 386b13307fSandi */ 396b13307fSandifunction tpl_content() { 407ea0913cSchris global $ACT; 417ea0913cSchris 427ea0913cSchris ob_start(); 437ea0913cSchris 44*24bb549bSchris trigger_event('TPL_ACT_RENDER',$ACT,tpl_content_core); 457ea0913cSchris 467ea0913cSchris $html_output = ob_get_clean(); 477ea0913cSchris 48*24bb549bSchris trigger_event('TPL_CONTENT_DISPLAY',$html_output,ptln); 497ea0913cSchris} 507ea0913cSchris 517ea0913cSchrisfunction tpl_content_core(){ 526b13307fSandi global $ACT; 536b13307fSandi global $TEXT; 546b13307fSandi global $PRE; 556b13307fSandi global $SUF; 566b13307fSandi global $SUM; 576b13307fSandi global $IDX; 586b13307fSandi 596b13307fSandi switch($ACT){ 606b13307fSandi case 'show': 616b13307fSandi html_show(); 626b13307fSandi break; 63ea67f144Sandi case 'preview': 646b13307fSandi html_edit($TEXT); 656b13307fSandi html_show($TEXT); 666b13307fSandi break; 67ee4c4a1bSAndreas Gohr case 'recover': 68ee4c4a1bSAndreas Gohr html_edit($TEXT); 69ee4c4a1bSAndreas Gohr break; 706b13307fSandi case 'edit': 716b13307fSandi html_edit(); 726b13307fSandi break; 73ee4c4a1bSAndreas Gohr case 'draft': 74ee4c4a1bSAndreas Gohr html_draft(); 75ee4c4a1bSAndreas Gohr break; 766b13307fSandi case 'wordblock': 776b13307fSandi html_edit($TEXT,'wordblock'); 786b13307fSandi break; 796b13307fSandi case 'search': 806b13307fSandi html_search(); 816b13307fSandi break; 826b13307fSandi case 'revisions': 836b13307fSandi html_revisions(); 846b13307fSandi break; 856b13307fSandi case 'diff': 866b13307fSandi html_diff(); 876b13307fSandi break; 886b13307fSandi case 'recent': 895749f1ceSmatthiasgrimm $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 90a39955b0Smatthiasgrimm html_recent($first); 916b13307fSandi break; 926b13307fSandi case 'index': 936b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 946b13307fSandi break; 956b13307fSandi case 'backlink': 966b13307fSandi html_backlinks(); 976b13307fSandi break; 986b13307fSandi case 'conflict': 996b13307fSandi html_conflict(con($PRE,$TEXT,$SUF),$SUM); 1006b13307fSandi html_diff(con($PRE,$TEXT,$SUF),false); 1016b13307fSandi break; 1026b13307fSandi case 'locked': 103ee20e7d1Sandi html_locked(); 1046b13307fSandi break; 1056b13307fSandi case 'login': 1066b13307fSandi html_login(); 1076b13307fSandi break; 1086b13307fSandi case 'register': 1096b13307fSandi html_register(); 1106b13307fSandi break; 1118b06d178Schris case 'resendpwd': 1128b06d178Schris html_resendpwd(); 1138b06d178Schris break; 114820fa24bSandi case 'denied': 1155e991bd8Sandi print p_locale_xhtml('denied'); 116820fa24bSandi break; 1178b06d178Schris case 'profile' : 1188b06d178Schris html_updateprofile(); 1198b06d178Schris break; 120c19fe9c0Sandi case 'admin': 121c19fe9c0Sandi tpl_admin(); 122c19fe9c0Sandi break; 1236b13307fSandi default: 124*24bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); 125*24bb549bSchris if ($evt->advise_before()) 126ea67f144Sandi msg("Failed to handle command: ".hsc($ACT),-1); 127*24bb549bSchris $evt->advise_after(); 128*24bb549bSchris unset($evt); 1296b13307fSandi } 1306b13307fSandi} 1316b13307fSandi 132c19fe9c0Sandi/** 133c19fe9c0Sandi * Handle the admin page contents 134c19fe9c0Sandi * 135c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 136c19fe9c0Sandi */ 137c19fe9c0Sandifunction tpl_admin(){ 13811e2ce22Schris 13911e2ce22Schris $plugin = NULL; 14011e2ce22Schris if ($_REQUEST['page']) { 14111e2ce22Schris $pluginlist = plugin_list('admin'); 14211e2ce22Schris 14311e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 14411e2ce22Schris 14511e2ce22Schris // attempt to load the plugin 14611e2ce22Schris $plugin =& plugin_load('admin',$_REQUEST['page']); 14711e2ce22Schris } 14811e2ce22Schris } 14911e2ce22Schris 15011e2ce22Schris if ($plugin !== NULL) 15111e2ce22Schris $plugin->html(); 15211e2ce22Schris else 15311e2ce22Schris html_admin(); 154c19fe9c0Sandi} 1556b13307fSandi 1566b13307fSandi/** 1576b13307fSandi * Print the correct HTML meta headers 1586b13307fSandi * 1596b13307fSandi * This has to go into the head section of your template. 1606b13307fSandi * 161f96fa415SAndreas Gohr * @param boolean $alt Should feeds and alternative format links be added? 1626b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 1636b13307fSandi */ 164f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){ 1656b13307fSandi global $ID; 1666b13307fSandi global $INFO; 1676b13307fSandi global $ACT; 1686b13307fSandi global $lang; 169dc57ef04Sandi global $conf; 1706b13307fSandi $it=2; 1716b13307fSandi 1726b13307fSandi // the usual stuff 1736b13307fSandi ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 1746b13307fSandi ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 1756b13307fSandi ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 176f96fa415SAndreas Gohr 177f96fa415SAndreas Gohr if($alt){ 1786b13307fSandi ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 1796b13307fSandi ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 180f5c2808fSBen Coburn ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.exportlink($ID, 'xhtml').'" />',$it); 181f5c2808fSBen Coburn ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.exportlink($ID, 'raw').'" />',$it); 182f96fa415SAndreas Gohr } 1836b13307fSandi 1846b13307fSandi // setup robot tags apropriate for different modes 1854f2e0004STim Weber if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ 1866b13307fSandi if($INFO['exists']){ 1876b13307fSandi ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 1886b13307fSandi //delay indexing: 1896b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 1906b13307fSandi ptln('<meta name="robots" content="index,follow" />',$it); 1916b13307fSandi }else{ 1926b13307fSandi ptln('<meta name="robots" content="noindex,nofollow" />',$it); 1936b13307fSandi } 1946b13307fSandi }else{ 1956b13307fSandi ptln('<meta name="robots" content="noindex,follow" />',$it); 1966b13307fSandi } 1976b13307fSandi }else{ 1986b13307fSandi ptln('<meta name="robots" content="noindex,nofollow" />',$it); 1996b13307fSandi } 2006b13307fSandi 20178a6aeb1SAndreas Gohr // load stylesheets 20278a6aeb1SAndreas Gohr ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it); 20378a6aeb1SAndreas Gohr ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it); 204bad31ae9SAndreas Gohr 20578a6aeb1SAndreas Gohr // load javascript 206ee4c4a1bSAndreas Gohr $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0; 207bad31ae9SAndreas Gohr $js_write = ($INFO['writable']) ? 1 : 0; 208c591aabeSAndreas Gohr if($js_edit && $js_write){ 2094beabca9SAnika Henke ptln('<script type="text/javascript" charset="utf-8">',$it); 210c591aabeSAndreas Gohr ptln("NS='".$INFO['namespace']."';",$it+2); 211c591aabeSAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 212aeaccbf9SAndreas Gohr require_once(DOKU_INC.'inc/toolbar.php'); 213c591aabeSAndreas Gohr ptln("SIG='".toolbar_signature()."';",$it+2); 214c591aabeSAndreas Gohr } 215c591aabeSAndreas Gohr ptln('</script>',$it); 216c591aabeSAndreas Gohr } 2174beabca9SAnika Henke ptln('<script type="text/javascript" charset="utf-8" src="'. 218c591aabeSAndreas Gohr DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write.'"></script>',$it); 2196b13307fSandi} 2206b13307fSandi 2216b13307fSandi/** 2226b13307fSandi * Print a link 2236b13307fSandi * 2245e163278SAndreas Gohr * Just builds a link. 2256b13307fSandi * 2266b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2276b13307fSandi */ 2286b13307fSandifunction tpl_link($url,$name,$more=''){ 2295e163278SAndreas Gohr print '<a href="'.$url.'" '; 2306b13307fSandi if ($more) print ' '.$more; 2316b13307fSandi print ">$name</a>"; 2326b13307fSandi} 2336b13307fSandi 2346b13307fSandi/** 23555efc227SAndreas Gohr * Prints a link to a WikiPage 23655efc227SAndreas Gohr * 23755efc227SAndreas Gohr * Wrapper around html_wikilink 23855efc227SAndreas Gohr * 23955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 24055efc227SAndreas Gohr */ 24155efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){ 24255efc227SAndreas Gohr print html_wikilink($id,$name); 24355efc227SAndreas Gohr} 24455efc227SAndreas Gohr 24555efc227SAndreas Gohr/** 246a3ec5f4aSmatthiasgrimm * get the parent page 247a3ec5f4aSmatthiasgrimm * 248a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 249a3ec5f4aSmatthiasgrimm * returns false if none is available 250a3ec5f4aSmatthiasgrimm * 251a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 252a3ec5f4aSmatthiasgrimm */ 253a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){ 254a3ec5f4aSmatthiasgrimm global $conf; 255a3ec5f4aSmatthiasgrimm 256a3ec5f4aSmatthiasgrimm if ($ID != $conf['start']) { 257a3ec5f4aSmatthiasgrimm $idparts = explode(':', $ID); 258a3ec5f4aSmatthiasgrimm $pn = array_pop($idparts); // get the page name 259a3ec5f4aSmatthiasgrimm 260a3ec5f4aSmatthiasgrimm for ($n=0; $n < 2; $n++) { 261a3ec5f4aSmatthiasgrimm if (count($idparts) == 0) { 262a3ec5f4aSmatthiasgrimm $ID = $conf['start']; // go to topmost page 263a3ec5f4aSmatthiasgrimm break; 264a3ec5f4aSmatthiasgrimm }else{ 265a3ec5f4aSmatthiasgrimm $ns = array_pop($idparts); // get the last part of namespace 266a3ec5f4aSmatthiasgrimm if ($pn != $ns) { // are we already home? 267a3ec5f4aSmatthiasgrimm array_push($idparts, $ns, $ns); // no, then add a page with same name 268a3ec5f4aSmatthiasgrimm $ID = implode (':', $idparts); // as the namespace and recombine $ID 269a3ec5f4aSmatthiasgrimm break; 270a3ec5f4aSmatthiasgrimm } 271a3ec5f4aSmatthiasgrimm } 272a3ec5f4aSmatthiasgrimm } 273a3ec5f4aSmatthiasgrimm 274a3ec5f4aSmatthiasgrimm if (@file_exists(wikiFN($ID))) { 275a3ec5f4aSmatthiasgrimm return $ID; 276a3ec5f4aSmatthiasgrimm } 277a3ec5f4aSmatthiasgrimm } 278a3ec5f4aSmatthiasgrimm return false; 279a3ec5f4aSmatthiasgrimm} 280a3ec5f4aSmatthiasgrimm 281a3ec5f4aSmatthiasgrimm/** 2826b13307fSandi * Print one of the buttons 2836b13307fSandi * 2846b13307fSandi * Available Buttons are 2856b13307fSandi * 286ee4c4a1bSAndreas Gohr * edit - edit/create/show/draft button 2876b13307fSandi * history - old revisions 2886b13307fSandi * recent - recent changes 2896b13307fSandi * login - login/logout button - if ACL enabled 2906b13307fSandi * index - The index 291c19fe9c0Sandi * admin - admin page - if enough rights 2926b13307fSandi * top - a back to top button 293a3ec5f4aSmatthiasgrimm * back - a back to parent button - if available 294d67ca2c0Smatthiasgrimm * backtomedia - returns to the mediafile upload dialog 295d67ca2c0Smatthiasgrimm * after references have been displayed 296bbd37938SAndreas Gohr * backlink - links to the list of backlinks 2976b13307fSandi * 2986b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 299a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 3006b13307fSandi */ 3016b13307fSandifunction tpl_button($type){ 302b158d625SSteven Danz global $ACT; 3036b13307fSandi global $ID; 304d67ca2c0Smatthiasgrimm global $NS; 305c19fe9c0Sandi global $INFO; 3066b13307fSandi global $conf; 307cd52f92dSchris global $auth; 3086b13307fSandi 3096b13307fSandi switch($type){ 3106b13307fSandi case 'edit': 3116b13307fSandi print html_editbutton(); 3126b13307fSandi break; 3136b13307fSandi case 'history': 3145bc81eb9SAnders Betnér print html_btn('revs',$ID,'o',array('do' => 'revisions')); 3156b13307fSandi break; 3166b13307fSandi case 'recent': 3175bc81eb9SAnders Betnér print html_btn('recent','','r',array('do' => 'recent')); 3186b13307fSandi break; 3196b13307fSandi case 'index': 3205bc81eb9SAnders Betnér print html_btn('index',$ID,'x',array('do' => 'index')); 3216b13307fSandi break; 322a3ec5f4aSmatthiasgrimm case 'back': 3236222040cSmatthiasgrimm if ($parent = tpl_getparent($ID)) { 3246222040cSmatthiasgrimm print html_btn('back',$parent,'b',array('do' => 'show')); 325a3ec5f4aSmatthiasgrimm } 326a3ec5f4aSmatthiasgrimm break; 3276b13307fSandi case 'top': 3286b13307fSandi print html_topbtn(); 3296b13307fSandi break; 3306b13307fSandi case 'login': 3316b13307fSandi if($conf['useacl']){ 3326b13307fSandi if($_SERVER['REMOTE_USER']){ 3336b13307fSandi print html_btn('logout',$ID,'',array('do' => 'logout',)); 3346b13307fSandi }else{ 3356b13307fSandi print html_btn('login',$ID,'',array('do' => 'login')); 3366b13307fSandi } 3376b13307fSandi } 3386b13307fSandi break; 339c19fe9c0Sandi case 'admin': 340c19fe9c0Sandi if($INFO['perm'] == AUTH_ADMIN) 3415bc81eb9SAnders Betnér print html_btn('admin',$ID,'',array('do' => 'admin')); 342c19fe9c0Sandi break; 343d67ca2c0Smatthiasgrimm case 'backtomedia': 344d67ca2c0Smatthiasgrimm print html_backtomedia_button(array('ns' => $NS),'b'); 345d67ca2c0Smatthiasgrimm break; 3461380fc45SAndreas Gohr case 'subscription': 347f9eb5648Ssteven-danz if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 348b158d625SSteven Danz if($_SERVER['REMOTE_USER']){ 3491380fc45SAndreas Gohr if($INFO['subscribed']){ 3501380fc45SAndreas Gohr print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); 351b158d625SSteven Danz } else { 3521380fc45SAndreas Gohr print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); 353b158d625SSteven Danz } 354b158d625SSteven Danz } 355b158d625SSteven Danz } 356b158d625SSteven Danz break; 357f00151b4Schris case 'backlink': 358f00151b4Schris print html_btn('backlink',$ID,'',array('do' => 'backlink')); 359f00151b4Schris break; 3608b06d178Schris case 'profile': 36136223ba7SAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 36236223ba7SAndreas Gohr $auth->canDo('Profile') && ($ACT!='profile')){ 3638b06d178Schris print html_btn('profile',$ID,'',array('do' => 'profile')); 3648b06d178Schris } 3658b06d178Schris break; 366c19fe9c0Sandi default: 367c19fe9c0Sandi print '[unknown button type]'; 3686b13307fSandi } 3696b13307fSandi} 3706b13307fSandi 3716b13307fSandi/** 372ed630903Sandi * Like the action buttons but links 373ed630903Sandi * 374ed630903Sandi * Available links are 375ed630903Sandi * 376ed630903Sandi * edit - edit/create/show button 377ed630903Sandi * history - old revisions 378ed630903Sandi * recent - recent changes 379ed630903Sandi * login - login/logout button - if ACL enabled 380ed630903Sandi * index - The index 381ed630903Sandi * admin - admin page - if enough rights 382ed630903Sandi * top - a back to top button 383a3ec5f4aSmatthiasgrimm * back - a back to parent button - if available 384bbd37938SAndreas Gohr * backlink - links to the list of backlinks 385ed630903Sandi * 386ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 387a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 388ed630903Sandi * @see tpl_button 389ed630903Sandi */ 390ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){ 391ed630903Sandi global $ID; 392ed630903Sandi global $INFO; 393ed630903Sandi global $REV; 394ed630903Sandi global $ACT; 395ed630903Sandi global $conf; 396ed630903Sandi global $lang; 397cd52f92dSchris global $auth; 398ed630903Sandi 399ed630903Sandi switch($type){ 400ed630903Sandi case 'edit': 401ed630903Sandi #most complicated type - we need to decide on current action 402ed630903Sandi if($ACT == 'show' || $ACT == 'search'){ 403ed630903Sandi if($INFO['writable']){ 404ed630903Sandi if($INFO['exists']){ 405ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 406ed630903Sandi $pre.$lang['btn_edit'].$suf, 407b7af031cSsu 'class="action edit" accesskey="e" rel="nofollow"'); 408ed630903Sandi }else{ 409ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 410ed630903Sandi $pre.$lang['btn_create'].$suf, 411b7af031cSsu 'class="action create" accesskey="e" rel="nofollow"'); 412ed630903Sandi } 413ed630903Sandi }else{ 414ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 415ed630903Sandi $pre.$lang['btn_source'].$suf, 416b7af031cSsu 'class="action source" accesskey="v" rel="nofollow"'); 417ed630903Sandi } 418ed630903Sandi }else{ 419ed630903Sandi tpl_link(wl($ID,'do=show'), 420ed630903Sandi $pre.$lang['btn_show'].$suf, 421b7af031cSsu 'class="action show" accesskey="v" rel="nofollow"'); 422ed630903Sandi } 423ed630903Sandi break; 424ed630903Sandi case 'history': 425b7af031cSsu tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"'); 426ed630903Sandi break; 427ed630903Sandi case 'recent': 428b7af031cSsu tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"'); 429ed630903Sandi break; 430ed630903Sandi case 'index': 431b7af031cSsu tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"'); 432ed630903Sandi break; 433ed630903Sandi case 'top': 43421a15207SAnika Henke print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 435ed630903Sandi break; 436a3ec5f4aSmatthiasgrimm case 'back': 437a3ec5f4aSmatthiasgrimm if ($ID = tpl_getparent($ID)) { 438b7af031cSsu tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"'); 439a3ec5f4aSmatthiasgrimm } 440a3ec5f4aSmatthiasgrimm break; 441ed630903Sandi case 'login': 442ed630903Sandi if($conf['useacl']){ 443ed630903Sandi if($_SERVER['REMOTE_USER']){ 444b7af031cSsu tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"'); 445ed630903Sandi }else{ 446b7af031cSsu tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"'); 447ed630903Sandi } 448ed630903Sandi } 449ed630903Sandi break; 450ed630903Sandi case 'admin': 451ed630903Sandi if($INFO['perm'] == AUTH_ADMIN) 452b7af031cSsu tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"'); 453ed630903Sandi break; 454f9eb5648Ssteven-danz case 'subscribe': 455075f000fSChristopher Arndt case 'subscription': 456f9eb5648Ssteven-danz if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 457b158d625SSteven Danz if($_SERVER['REMOTE_USER']){ 458075f000fSChristopher Arndt if($INFO['subscribed']) { 459b7af031cSsu tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"'); 460b158d625SSteven Danz } else { 461b7af031cSsu tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"'); 462b158d625SSteven Danz } 463b158d625SSteven Danz } 464b158d625SSteven Danz } 465b158d625SSteven Danz break; 466f00151b4Schris case 'backlink': 467b7af031cSsu tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"'); 468f00151b4Schris break; 4698b06d178Schris case 'profile': 47036223ba7SAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 47136223ba7SAndreas Gohr $auth->canDo('Profile') && ($ACT!='profile')){ 4728b06d178Schris tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"'); 4738b06d178Schris } 4748b06d178Schris break; 475ed630903Sandi default: 476ed630903Sandi print '[unknown link type]'; 477ed630903Sandi } 478ed630903Sandi} 479ed630903Sandi 480ed630903Sandi/** 4816b13307fSandi * Print the search form 4826b13307fSandi * 48372645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 48472645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 48572645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 48672645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 48772645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 48872645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 48972645b75SAndreas Gohr * 4906b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 4916b13307fSandi */ 49272645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){ 4936b13307fSandi global $lang; 494c1e3b7d9Smatthiasgrimm global $ACT; 495c1e3b7d9Smatthiasgrimm 4961dd0c202SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; 4976b13307fSandi print '<input type="hidden" name="do" value="search" />'; 498c1e3b7d9Smatthiasgrimm print '<input type="text" '; 499bad31ae9SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" '; 50072645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 50124a33b42SAndreas Gohr print 'id="qsearch__in" accesskey="f" name="id" class="edit" />'; 5026b13307fSandi print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 50324a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 5044beabca9SAnika Henke print '</div></form>'; 5056b13307fSandi} 5066b13307fSandi 5076b13307fSandi/** 5086b13307fSandi * Print the breadcrumbs trace 5096b13307fSandi * 5106b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 5116b13307fSandi */ 5126b13307fSandifunction tpl_breadcrumbs(){ 5136b13307fSandi global $lang; 5146b13307fSandi global $conf; 5156b13307fSandi 5166b13307fSandi //check if enabled 5176b13307fSandi if(!$conf['breadcrumbs']) return; 5186b13307fSandi 5196b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 520265e3787Sandi 521265e3787Sandi //reverse crumborder in right-to-left mode 522265e3787Sandi if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 523265e3787Sandi 52440eb54bbSjan //render crumbs, highlight the last one 5256b13307fSandi print $lang['breadcrumb'].':'; 52640eb54bbSjan $last = count($crumbs); 52740eb54bbSjan $i = 0; 528a77f5846Sjan foreach ($crumbs as $id => $name){ 52940eb54bbSjan $i++; 530265e3787Sandi print ' <span class="bcsep">»</span> '; 53192795d04Sandi if ($i == $last) print '<span class="curid">'; 532a77f5846Sjan tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 53392795d04Sandi if ($i == $last) print '</span>'; 5346b13307fSandi } 5356b13307fSandi} 5366b13307fSandi 5376b13307fSandi/** 5381734437eSandi * Hierarchical breadcrumbs 5391734437eSandi * 54031e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 5411734437eSandi * It only makes sense with a deep site structure. 5421734437eSandi * 5431734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 5446bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 54531e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 5461734437eSandi * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 5476bd812dfSNigel McNie * @todo May behave strangely in RTL languages 5481734437eSandi */ 5491734437eSandifunction tpl_youarehere(){ 5501734437eSandi global $conf; 5511734437eSandi global $ID; 5521734437eSandi global $lang; 5531734437eSandi 55431e187f8SSean Coates //check if enabled 55531e187f8SSean Coates if(!$conf['youarehere']) return; 5561734437eSandi 5571734437eSandi $parts = explode(':', $ID); 5581734437eSandi 55931e187f8SSean Coates print $lang['youarehere'].': '; 5601734437eSandi 5611734437eSandi //always print the startpage 56231e187f8SSean Coates if( $a_part[0] != $conf['start']){ 56331e187f8SSean Coates if($conf['useheading']){ 56431e187f8SSean Coates $pageName = p_get_first_heading($conf['start']); 56531e187f8SSean Coates }else{ 56631e187f8SSean Coates $pageName = $conf['start']; 56731e187f8SSean Coates } 56831e187f8SSean Coates tpl_link(wl($conf['start']),$pageName,'title="'.$pageName.'"'); 56931e187f8SSean Coates } 5701734437eSandi 5711734437eSandi $page = ''; 5721734437eSandi foreach ($parts as $part){ 5736bd812dfSNigel McNie // Skip startpage if already done 5746bd812dfSNigel McNie if ($part == $conf['start']) continue; 5756bd812dfSNigel McNie 5761734437eSandi print ' » '; 5771734437eSandi $page .= $part; 5781734437eSandi 5791734437eSandi if(file_exists(wikiFN($page))){ 58031e187f8SSean Coates if($conf['useheading']){ 58131e187f8SSean Coates $pageName = p_get_first_heading($page); 58231e187f8SSean Coates $partName = $pageName; 58331e187f8SSean Coates }else{ 58431e187f8SSean Coates $pageName = $page; 58531e187f8SSean Coates $partName = $part; 58631e187f8SSean Coates } 58731e187f8SSean Coates tpl_link(wl($page),$partName,'title="'.$pageName.'"'); 5881734437eSandi }else{ 5896bd812dfSNigel McNie // Print the link, but mark as not-existing, as for other non-existing links 5906bd812dfSNigel McNie tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"'); 5916bd812dfSNigel McNie //print $page; 5921734437eSandi } 5931734437eSandi 5941734437eSandi $page .= ':'; 5951734437eSandi } 5961734437eSandi} 5971734437eSandi 5981734437eSandi/** 5996b13307fSandi * Print info if the user is logged in 600a2488c3cSMatthias Grimm * and show full name in that case 6016b13307fSandi * 6026b13307fSandi * Could be enhanced with a profile link in future? 6036b13307fSandi * 6046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 6056b13307fSandi */ 6066b13307fSandifunction tpl_userinfo(){ 6076b13307fSandi global $lang; 608a2488c3cSMatthias Grimm global $INFO; 6096b13307fSandi if($_SERVER['REMOTE_USER']) 610a2488c3cSMatthias Grimm print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 6116b13307fSandi} 6126b13307fSandi 6136b13307fSandi/** 6146b13307fSandi * Print some info about the current page 6156b13307fSandi * 6166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 6176b13307fSandi */ 6186b13307fSandifunction tpl_pageinfo(){ 6196b13307fSandi global $conf; 6206b13307fSandi global $lang; 6216b13307fSandi global $INFO; 6226b13307fSandi global $REV; 6236b13307fSandi 6246b13307fSandi // prepare date and path 6256b13307fSandi $fn = $INFO['filepath']; 6266b13307fSandi if(!$conf['fullpath']){ 6276b13307fSandi if($REV){ 6286b13307fSandi $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 6296b13307fSandi }else{ 6306b13307fSandi $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 6316b13307fSandi } 6326b13307fSandi } 633bee6dc82Sandi $fn = utf8_decodeFN($fn); 6346b13307fSandi $date = date($conf['dformat'],$INFO['lastmod']); 6356b13307fSandi 6366b13307fSandi // print it 6376b13307fSandi if($INFO['exists']){ 6386b13307fSandi print $fn; 6396b13307fSandi print ' · '; 6406b13307fSandi print $lang['lastmod']; 6416b13307fSandi print ': '; 6426b13307fSandi print $date; 6436b13307fSandi if($INFO['editor']){ 6446b13307fSandi print ' '.$lang['by'].' '; 6456b13307fSandi print $INFO['editor']; 6466b13307fSandi } 6476b13307fSandi if($INFO['locked']){ 6486b13307fSandi print ' · '; 6496b13307fSandi print $lang['lockedby']; 6506b13307fSandi print ': '; 6516b13307fSandi print $INFO['locked']; 6526b13307fSandi } 6536b13307fSandi } 6546b13307fSandi} 6556b13307fSandi 656820fa24bSandi/** 657820fa24bSandi * Print a list of namespaces containing media files 658820fa24bSandi * 659820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 660820fa24bSandi */ 661820fa24bSandifunction tpl_medianamespaces(){ 662820fa24bSandi global $conf; 663820fa24bSandi 664820fa24bSandi $data = array(); 665820fa24bSandi search($data,$conf['mediadir'],'search_namespaces',array()); 666820fa24bSandi print html_buildlist($data,'idx',media_html_list_namespaces); 667820fa24bSandi} 668820fa24bSandi 669820fa24bSandi/** 670820fa24bSandi * Print a list of mediafiles in the current namespace 671820fa24bSandi * 672820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 673820fa24bSandi */ 674820fa24bSandifunction tpl_mediafilelist(){ 675820fa24bSandi global $conf; 676820fa24bSandi global $lang; 677820fa24bSandi global $NS; 6788ef6b7caSandi global $AUTH; 679820fa24bSandi $dir = utf8_encodeFN(str_replace(':','/',$NS)); 680820fa24bSandi 681820fa24bSandi $data = array(); 682820fa24bSandi search($data,$conf['mediadir'],'search_media',array(),$dir); 683820fa24bSandi 684820fa24bSandi if(!count($data)){ 6854b15e09dSAndreas Gohr ptln('<div class="nothing">'.$lang['nothingfound'].'</div>'); 686820fa24bSandi return; 687820fa24bSandi } 688820fa24bSandi 689820fa24bSandi ptln('<ul>',2); 690820fa24bSandi foreach($data as $item){ 691806d77a0SAndreas Gohr if(!$item['isimg']){ 692806d77a0SAndreas Gohr // add file icons 693806d77a0SAndreas Gohr list($ext,$mime) = mimetype($item['file']); 694806d77a0SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 69543650a18SAndreas Gohr $class = ' class="mediafile mf_'.$class.'"'; 6961512f40dSAndreas Gohr }else{ 6971512f40dSAndreas Gohr $class = ''; 698806d77a0SAndreas Gohr } 699806d77a0SAndreas Gohr 7000c6b58a8SAndreas Gohr ptln('<li><div class="li">',4); 701806d77a0SAndreas Gohr ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')"'.$class.'>'. 702820fa24bSandi utf8_decodeFN($item['file']). 703820fa24bSandi '</a>',6); 7048ef6b7caSandi 7058ef6b7caSandi //prepare deletion button 7068ef6b7caSandi if($AUTH >= AUTH_DELETE){ 7070699afe9SAndreas Gohr $ask = addslashes($lang['del_confirm']).'\\n'; 7080699afe9SAndreas Gohr $ask .= addslashes($item['id']); 7098ef6b7caSandi 710b6c6979fSAndreas Gohr $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.rawurlencode($item['id']).'" '. 7118ef6b7caSandi 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 712f62ea8a1Sandi '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 7134beabca9SAnika Henke 'title="'.$lang['btn_delete'].'" /></a>'; 7148ef6b7caSandi }else{ 7158ef6b7caSandi $del = ''; 7168ef6b7caSandi } 7178ef6b7caSandi 718820fa24bSandi if($item['isimg']){ 71993c020acSAndreas Gohr $w = (int) $item['meta']->getField('File.Width'); 72093c020acSAndreas Gohr $h = (int) $item['meta']->getField('File.Height'); 721820fa24bSandi 7228ef6b7caSandi ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 7238ef6b7caSandi ptln($del.'<br />',6); 724478cd997SAndreas Gohr ptln('<div class="imagemeta">',6); 7259fcd3d1dSandi 72623a34783SAndreas Gohr //build thumbnail 7270699afe9SAndreas Gohr print '<a href="javascript:mediaSelect(\':'.$item['id'].'\')">'; 72823a34783SAndreas Gohr 72923a34783SAndreas Gohr if($w>120 || $h>120){ 73023a34783SAndreas Gohr $ratio = $item['meta']->getResizeRatio(120); 73123a34783SAndreas Gohr $w = floor($w * $ratio); 73223a34783SAndreas Gohr $h = floor($h * $ratio); 7339fcd3d1dSandi } 73423a34783SAndreas Gohr 7356de3759aSAndreas Gohr $src = ml($item['id'],array('w'=>$w,'h'=>$h)); 73623a34783SAndreas Gohr 73723a34783SAndreas Gohr $p = array(); 73823a34783SAndreas Gohr $p['width'] = $w; 73923a34783SAndreas Gohr $p['height'] = $h; 74023a34783SAndreas Gohr $p['alt'] = $item['id']; 74123a34783SAndreas Gohr $p['class'] = 'thumb'; 74223a34783SAndreas Gohr $att = buildAttributes($p); 74323a34783SAndreas Gohr 74423a34783SAndreas Gohr print '<img src="'.$src.'" '.$att.' />'; 7459fcd3d1dSandi print '</a>'; 746820fa24bSandi 7476d861d12SAndreas Gohr //read EXIF/IPTC data 74823a34783SAndreas Gohr $t = $item['meta']->getField('IPTC.Headline'); 74993c020acSAndreas Gohr if($t) print '<strong>'.htmlspecialchars($t).'</strong><br />'; 7506d861d12SAndreas Gohr 75136df6fa3SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment', 75236df6fa3SAndreas Gohr 'EXIF.TIFFImageDescription', 75336df6fa3SAndreas Gohr 'EXIF.TIFFUserComment')); 75493c020acSAndreas Gohr if($t) print htmlspecialchars($t).'<br />'; 7556d861d12SAndreas Gohr 75623a34783SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category')); 75793c020acSAndreas Gohr if($t) print '<em>'.htmlspecialchars($t).'</em><br />'; 7586d861d12SAndreas Gohr 75936df6fa3SAndreas Gohr //add edit button 76036df6fa3SAndreas Gohr if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){ 761b6c6979fSAndreas Gohr print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.rawurlencode($item['id']).'">'; 76236df6fa3SAndreas Gohr print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />'; 76336df6fa3SAndreas Gohr print '</a>'; 76436df6fa3SAndreas Gohr } 76536df6fa3SAndreas Gohr 7666d861d12SAndreas Gohr ptln('</div>',6); 767820fa24bSandi }else{ 768820fa24bSandi ptln ('('.filesize_h($item['size']).')',6); 7698ef6b7caSandi ptln($del,6); 770820fa24bSandi } 7710c6b58a8SAndreas Gohr ptln('</div></li>',4); 772820fa24bSandi } 773820fa24bSandi ptln('</ul>',2); 774820fa24bSandi} 775820fa24bSandi 776820fa24bSandi/** 777d67ca2c0Smatthiasgrimm * show references to a media file 778d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share 779d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links. 780d67ca2c0Smatthiasgrimm * 781d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 782d67ca2c0Smatthiasgrimm */ 783d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){ 784d67ca2c0Smatthiasgrimm global $lang; 785d67ca2c0Smatthiasgrimm 786d67ca2c0Smatthiasgrimm $hidden=0; //count of hits without read permission 787d67ca2c0Smatthiasgrimm 788d67ca2c0Smatthiasgrimm if(count($data)){ 789d67ca2c0Smatthiasgrimm usort($data,'sort_search_fulltext'); 790d67ca2c0Smatthiasgrimm foreach($data as $row){ 791d67ca2c0Smatthiasgrimm if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 792d67ca2c0Smatthiasgrimm print '<div class="search_result">'; 793d67ca2c0Smatthiasgrimm print '<span class="mediaref_ref">'.$row['id'].'</span>'; 794d67ca2c0Smatthiasgrimm print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 795d67ca2c0Smatthiasgrimm print '<div class="search_snippet">'.$row['snippet'].'</div>'; 796d67ca2c0Smatthiasgrimm print '</div>'; 797d67ca2c0Smatthiasgrimm }else 798d67ca2c0Smatthiasgrimm $hidden++; 799d67ca2c0Smatthiasgrimm } 800d67ca2c0Smatthiasgrimm if ($hidden){ 801d67ca2c0Smatthiasgrimm print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 802d67ca2c0Smatthiasgrimm } 803d67ca2c0Smatthiasgrimm } 804d67ca2c0Smatthiasgrimm} 805d67ca2c0Smatthiasgrimm 806d67ca2c0Smatthiasgrimm/** 807820fa24bSandi * Print the media upload form if permissions are correct 808820fa24bSandi * 809820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 810820fa24bSandi */ 811820fa24bSandifunction tpl_mediauploadform(){ 812820fa24bSandi global $NS; 813820fa24bSandi global $UPLOADOK; 8148ef6b7caSandi global $AUTH; 815820fa24bSandi global $lang; 816820fa24bSandi 817820fa24bSandi if(!$UPLOADOK) return; 818820fa24bSandi 8191dd0c202SAnika Henke ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" id="dw__upload"'. 820820fa24bSandi ' method="post" enctype="multipart/form-data">',2); 821820fa24bSandi ptln($lang['txt_upload'].':<br />',4); 822820fa24bSandi ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 823820fa24bSandi ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 824820fa24bSandi ptln($lang['txt_filename'].'<br />',4); 825820fa24bSandi ptln('<input type="text" name="id" class="edit" />',4); 826820fa24bSandi ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 8278ef6b7caSandi if($AUTH >= AUTH_DELETE){ 82824a33b42SAndreas Gohr ptln('<label for="dw__ow"><input type="checkbox" name="ow" value="1" id="dw__ow" />'.$lang['txt_overwrt'].'</label>',4); 8298ef6b7caSandi } 830820fa24bSandi ptln('</form>',2); 831820fa24bSandi} 832820fa24bSandi 83387c434ceSAndreas Gohr/** 834a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 83587c434ceSAndreas Gohr * 83687c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 837a6598f23SBen Coburn * the given ID is used. 83887c434ceSAndreas Gohr * 83987c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 84087c434ceSAndreas Gohr */ 841a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){ 84287c434ceSAndreas Gohr global $conf; 84387c434ceSAndreas Gohr if(is_null($id)){ 84487c434ceSAndreas Gohr global $ID; 84587c434ceSAndreas Gohr $id = $ID; 84687c434ceSAndreas Gohr } 84787c434ceSAndreas Gohr 84887c434ceSAndreas Gohr $name = $id; 84987c434ceSAndreas Gohr if ($conf['useheading']) { 85087c434ceSAndreas Gohr $title = p_get_first_heading($id); 85187c434ceSAndreas Gohr if ($title) $name = $title; 85287c434ceSAndreas Gohr } 853a6598f23SBen Coburn 854a6598f23SBen Coburn if ($ret) { 855a6598f23SBen Coburn return hsc($name); 856a6598f23SBen Coburn } else { 85787c434ceSAndreas Gohr print hsc($name); 85887c434ceSAndreas Gohr } 859a6598f23SBen Coburn} 860340756e4Sandi 86155efc227SAndreas Gohr/** 86255efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 86355efc227SAndreas Gohr * 86455efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 86555efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 86655efc227SAndreas Gohr * 86755efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 86855efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 86955efc227SAndreas Gohr * to the names of the latter one) 87055efc227SAndreas Gohr * 87136df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php 87255efc227SAndreas Gohr * 87355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 87455efc227SAndreas Gohr */ 87555efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){ 87655efc227SAndreas Gohr // Init Exif Reader 87755efc227SAndreas Gohr global $SRC; 87855efc227SAndreas Gohr static $meta = null; 87955efc227SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($SRC); 88055efc227SAndreas Gohr if($meta === false) return $alt; 88155efc227SAndreas Gohr $info = $meta->getField($tags); 88255efc227SAndreas Gohr if($info == false) return $alt; 88355efc227SAndreas Gohr return $info; 88455efc227SAndreas Gohr} 88555efc227SAndreas Gohr 88655efc227SAndreas Gohr/** 88755efc227SAndreas Gohr * Prints the image with a link to the full sized version 88855efc227SAndreas Gohr * 88955efc227SAndreas Gohr * Only allowed in: detail.php 89055efc227SAndreas Gohr */ 891f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){ 89255efc227SAndreas Gohr global $IMG; 89355efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 89455efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 89555efc227SAndreas Gohr 89655efc227SAndreas Gohr //resize to given max values 89723a34783SAndreas Gohr $ratio = 1; 89823a34783SAndreas Gohr if($w >= $h){ 899f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth){ 90055efc227SAndreas Gohr $ratio = $maxwidth/$w; 901f8925855Sjoe.lapp }elseif($maxheight && $h > $maxheight){ 90255efc227SAndreas Gohr $ratio = $maxheight/$h; 90355efc227SAndreas Gohr } 90455efc227SAndreas Gohr }else{ 905f8925855Sjoe.lapp if($maxheight && $h >= $maxheight){ 90655efc227SAndreas Gohr $ratio = $maxheight/$h; 907f8925855Sjoe.lapp }elseif($maxwidth && $w > $maxwidth){ 90855efc227SAndreas Gohr $ratio = $maxwidth/$w; 90955efc227SAndreas Gohr } 91055efc227SAndreas Gohr } 91155efc227SAndreas Gohr if($ratio){ 91255efc227SAndreas Gohr $w = floor($ratio*$w); 91355efc227SAndreas Gohr $h = floor($ratio*$h); 91455efc227SAndreas Gohr } 91555efc227SAndreas Gohr 9166de3759aSAndreas Gohr //prepare URLs 9176de3759aSAndreas Gohr $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 9186de3759aSAndreas Gohr $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 91955efc227SAndreas Gohr 9202684e50aSAndreas Gohr //prepare attributes 92155efc227SAndreas Gohr $alt=tpl_img_getTag('Simple.Title'); 9222684e50aSAndreas Gohr $p = array(); 9232684e50aSAndreas Gohr if($w) $p['width'] = $w; 9242684e50aSAndreas Gohr if($h) $p['height'] = $h; 9252684e50aSAndreas Gohr $p['class'] = 'img_detail'; 9262684e50aSAndreas Gohr if($alt){ 9272684e50aSAndreas Gohr $p['alt'] = $alt; 9282684e50aSAndreas Gohr $p['title'] = $alt; 9292684e50aSAndreas Gohr }else{ 9302684e50aSAndreas Gohr $p['alt'] = ''; 9312684e50aSAndreas Gohr } 9322684e50aSAndreas Gohr $p = buildAttributes($p); 93355efc227SAndreas Gohr 93455efc227SAndreas Gohr print '<a href="'.$url.'">'; 9356de3759aSAndreas Gohr print '<img src="'.$src.'" '.$p.'/>'; 93655efc227SAndreas Gohr print '</a>'; 93755efc227SAndreas Gohr} 93855efc227SAndreas Gohr 9397367b368SAndreas Gohr/** 9407367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality 9417367b368SAndreas Gohr * is the inexer function. 9427367b368SAndreas Gohr * 9437367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 9447367b368SAndreas Gohr * template 9457367b368SAndreas Gohr */ 9467367b368SAndreas Gohrfunction tpl_indexerWebBug(){ 9477367b368SAndreas Gohr global $ID; 9481dad36f5SAndreas Gohr global $INFO; 9491dad36f5SAndreas Gohr if(!$INFO['exists']) return; 9501dad36f5SAndreas Gohr 9510dc92c6fSAndreas Gohr if(isHiddenPage($ID)) return; //no need to index hidden pages 9520dc92c6fSAndreas Gohr 9537367b368SAndreas Gohr $p = array(); 954b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 955e68c51baSAndreas Gohr '&'.time(); 9567367b368SAndreas Gohr $p['width'] = 1; 9577367b368SAndreas Gohr $p['height'] = 1; 9587367b368SAndreas Gohr $p['alt'] = ''; 9597367b368SAndreas Gohr $att = buildAttributes($p); 9607367b368SAndreas Gohr print "<img $att />"; 9617367b368SAndreas Gohr} 9627367b368SAndreas Gohr 96378d4e784SEsther Brunner// configuration methods 96478d4e784SEsther Brunner/** 96578d4e784SEsther Brunner * tpl_getConf($id) 96678d4e784SEsther Brunner * 96778d4e784SEsther Brunner * use this function to access template configuration variables 96878d4e784SEsther Brunner */ 96978d4e784SEsther Brunnerfunction tpl_getConf($id){ 97078d4e784SEsther Brunner global $conf; 97178d4e784SEsther Brunner global $tpl_configloaded; 97278d4e784SEsther Brunner 97378d4e784SEsther Brunner $tpl = $conf['template']; 97478d4e784SEsther Brunner 97578d4e784SEsther Brunner if (!$tpl_configloaded){ 97678d4e784SEsther Brunner $tconf = tpl_loadConfig(); 97778d4e784SEsther Brunner if ($tconf !== false){ 97878d4e784SEsther Brunner foreach ($tconf as $key => $value){ 97978d4e784SEsther Brunner if (isset($conf['tpl'][$tpl][$key])) continue; 98078d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 98178d4e784SEsther Brunner } 98278d4e784SEsther Brunner $tpl_configloaded = true; 98378d4e784SEsther Brunner } 98478d4e784SEsther Brunner } 98578d4e784SEsther Brunner 98678d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 98778d4e784SEsther Brunner} 98878d4e784SEsther Brunner 98978d4e784SEsther Brunner/** 99078d4e784SEsther Brunner * tpl_loadConfig() 99178d4e784SEsther Brunner * reads all template configuration variables 99278d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 99378d4e784SEsther Brunner */ 99478d4e784SEsther Brunnerfunction tpl_loadConfig(){ 99578d4e784SEsther Brunner 99678d4e784SEsther Brunner $file = DOKU_TPLINC.'/conf/default.php'; 99778d4e784SEsther Brunner $conf = array(); 99878d4e784SEsther Brunner 99978d4e784SEsther Brunner if (!@file_exists($file)) return false; 100078d4e784SEsther Brunner 100178d4e784SEsther Brunner // load default config file 100278d4e784SEsther Brunner include($file); 100378d4e784SEsther Brunner 100478d4e784SEsther Brunner return $conf; 100578d4e784SEsther Brunner} 100678d4e784SEsther Brunner 1007340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 1008