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 14*524be65dSBen Coburn * default one if the custom version doesn't exist. 15*524be65dSBen Coburn * Also enables gzip compression if configured. 165a892029SAndreas Gohr * 175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 185a892029SAndreas Gohr */ 195a892029SAndreas Gohrfunction template($tpl){ 205a892029SAndreas Gohr global $conf; 215a892029SAndreas Gohr 22*524be65dSBen Coburn if ($conf['gzip_output'] && extension_loaded('zlib') && preg_match('/gzip|deflate/', $_SERVER['HTTP_ACCEPT_ENCODING'])) { 23*524be65dSBen Coburn ob_start('ob_gzhandler'); 24*524be65dSBen Coburn } 25*524be65dSBen Coburn 265a892029SAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) 275a892029SAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; 285a892029SAndreas Gohr 295a892029SAndreas Gohr return DOKU_INC.'lib/tpl/default/'.$tpl; 305a892029SAndreas Gohr} 315a892029SAndreas Gohr 325a892029SAndreas Gohr/** 336b13307fSandi * Print the content 346b13307fSandi * 356b13307fSandi * This function is used for printing all the usual content 366b13307fSandi * (defined by the global $ACT var) by calling the appropriate 376b13307fSandi * outputfunction(s) from html.php 386b13307fSandi * 39ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 40ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 416b13307fSandi * 426b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 436b13307fSandi */ 446b13307fSandifunction tpl_content() { 457ea0913cSchris global $ACT; 467ea0913cSchris 477ea0913cSchris ob_start(); 487ea0913cSchris 4924bb549bSchris trigger_event('TPL_ACT_RENDER',$ACT,tpl_content_core); 507ea0913cSchris 517ea0913cSchris $html_output = ob_get_clean(); 527ea0913cSchris 5324bb549bSchris trigger_event('TPL_CONTENT_DISPLAY',$html_output,ptln); 547ea0913cSchris} 557ea0913cSchris 567ea0913cSchrisfunction tpl_content_core(){ 576b13307fSandi global $ACT; 586b13307fSandi global $TEXT; 596b13307fSandi global $PRE; 606b13307fSandi global $SUF; 616b13307fSandi global $SUM; 626b13307fSandi global $IDX; 636b13307fSandi 646b13307fSandi switch($ACT){ 656b13307fSandi case 'show': 666b13307fSandi html_show(); 676b13307fSandi break; 68ea67f144Sandi case 'preview': 696b13307fSandi html_edit($TEXT); 706b13307fSandi html_show($TEXT); 716b13307fSandi break; 72ee4c4a1bSAndreas Gohr case 'recover': 73ee4c4a1bSAndreas Gohr html_edit($TEXT); 74ee4c4a1bSAndreas Gohr break; 756b13307fSandi case 'edit': 766b13307fSandi html_edit(); 776b13307fSandi break; 78ee4c4a1bSAndreas Gohr case 'draft': 79ee4c4a1bSAndreas Gohr html_draft(); 80ee4c4a1bSAndreas Gohr break; 816b13307fSandi case 'wordblock': 826b13307fSandi html_edit($TEXT,'wordblock'); 836b13307fSandi break; 846b13307fSandi case 'search': 856b13307fSandi html_search(); 866b13307fSandi break; 876b13307fSandi case 'revisions': 886b13307fSandi html_revisions(); 896b13307fSandi break; 906b13307fSandi case 'diff': 916b13307fSandi html_diff(); 926b13307fSandi break; 936b13307fSandi case 'recent': 945749f1ceSmatthiasgrimm $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; 95a39955b0Smatthiasgrimm html_recent($first); 966b13307fSandi break; 976b13307fSandi case 'index': 986b13307fSandi html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? 996b13307fSandi break; 1006b13307fSandi case 'backlink': 1016b13307fSandi html_backlinks(); 1026b13307fSandi break; 1036b13307fSandi case 'conflict': 1046b13307fSandi html_conflict(con($PRE,$TEXT,$SUF),$SUM); 1056b13307fSandi html_diff(con($PRE,$TEXT,$SUF),false); 1066b13307fSandi break; 1076b13307fSandi case 'locked': 108ee20e7d1Sandi html_locked(); 1096b13307fSandi break; 1106b13307fSandi case 'login': 1116b13307fSandi html_login(); 1126b13307fSandi break; 1136b13307fSandi case 'register': 1146b13307fSandi html_register(); 1156b13307fSandi break; 1168b06d178Schris case 'resendpwd': 1178b06d178Schris html_resendpwd(); 1188b06d178Schris break; 119820fa24bSandi case 'denied': 1205e991bd8Sandi print p_locale_xhtml('denied'); 121820fa24bSandi break; 1228b06d178Schris case 'profile' : 1238b06d178Schris html_updateprofile(); 1248b06d178Schris break; 125c19fe9c0Sandi case 'admin': 126c19fe9c0Sandi tpl_admin(); 127c19fe9c0Sandi break; 1286b13307fSandi default: 12924bb549bSchris $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); 13024bb549bSchris if ($evt->advise_before()) 131ea67f144Sandi msg("Failed to handle command: ".hsc($ACT),-1); 13224bb549bSchris $evt->advise_after(); 13324bb549bSchris unset($evt); 1346b13307fSandi } 1356b13307fSandi} 1366b13307fSandi 137c19fe9c0Sandi/** 138c19fe9c0Sandi * Handle the admin page contents 139c19fe9c0Sandi * 140c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 141c19fe9c0Sandi */ 142c19fe9c0Sandifunction tpl_admin(){ 14311e2ce22Schris 14411e2ce22Schris $plugin = NULL; 14511e2ce22Schris if ($_REQUEST['page']) { 14611e2ce22Schris $pluginlist = plugin_list('admin'); 14711e2ce22Schris 14811e2ce22Schris if (in_array($_REQUEST['page'], $pluginlist)) { 14911e2ce22Schris 15011e2ce22Schris // attempt to load the plugin 15111e2ce22Schris $plugin =& plugin_load('admin',$_REQUEST['page']); 15211e2ce22Schris } 15311e2ce22Schris } 15411e2ce22Schris 15511e2ce22Schris if ($plugin !== NULL) 15611e2ce22Schris $plugin->html(); 15711e2ce22Schris else 15811e2ce22Schris html_admin(); 159c19fe9c0Sandi} 1606b13307fSandi 1616b13307fSandi/** 1626b13307fSandi * Print the correct HTML meta headers 1636b13307fSandi * 1646b13307fSandi * This has to go into the head section of your template. 1656b13307fSandi * 166f96fa415SAndreas Gohr * @param boolean $alt Should feeds and alternative format links be added? 1676b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 1686b13307fSandi */ 169f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){ 1706b13307fSandi global $ID; 1716b13307fSandi global $INFO; 1726b13307fSandi global $ACT; 1736b13307fSandi global $lang; 174dc57ef04Sandi global $conf; 1756b13307fSandi $it=2; 1766b13307fSandi 1776b13307fSandi // the usual stuff 1786b13307fSandi ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it); 1796b13307fSandi ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it); 1806b13307fSandi ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it); 181f96fa415SAndreas Gohr 182f96fa415SAndreas Gohr if($alt){ 1836b13307fSandi ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it); 1846b13307fSandi ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'].'" />',$it); 185f5c2808fSBen Coburn ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.exportlink($ID, 'xhtml').'" />',$it); 186f5c2808fSBen Coburn ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.exportlink($ID, 'raw').'" />',$it); 187f96fa415SAndreas Gohr } 1886b13307fSandi 1896b13307fSandi // setup robot tags apropriate for different modes 1904f2e0004STim Weber if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ 1916b13307fSandi if($INFO['exists']){ 1926b13307fSandi ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it); 1936b13307fSandi //delay indexing: 1946b13307fSandi if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ 1956b13307fSandi ptln('<meta name="robots" content="index,follow" />',$it); 1966b13307fSandi }else{ 1976b13307fSandi ptln('<meta name="robots" content="noindex,nofollow" />',$it); 1986b13307fSandi } 1996b13307fSandi }else{ 2006b13307fSandi ptln('<meta name="robots" content="noindex,follow" />',$it); 2016b13307fSandi } 2026b13307fSandi }else{ 2036b13307fSandi ptln('<meta name="robots" content="noindex,nofollow" />',$it); 2046b13307fSandi } 2056b13307fSandi 20678a6aeb1SAndreas Gohr // load stylesheets 20778a6aeb1SAndreas Gohr ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it); 20878a6aeb1SAndreas Gohr ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it); 209bad31ae9SAndreas Gohr 21078a6aeb1SAndreas Gohr // load javascript 211ee4c4a1bSAndreas Gohr $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0; 212bad31ae9SAndreas Gohr $js_write = ($INFO['writable']) ? 1 : 0; 213c591aabeSAndreas Gohr if($js_edit && $js_write){ 2144beabca9SAnika Henke ptln('<script type="text/javascript" charset="utf-8">',$it); 215c591aabeSAndreas Gohr ptln("NS='".$INFO['namespace']."';",$it+2); 216c591aabeSAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER']){ 217aeaccbf9SAndreas Gohr require_once(DOKU_INC.'inc/toolbar.php'); 218c591aabeSAndreas Gohr ptln("SIG='".toolbar_signature()."';",$it+2); 219c591aabeSAndreas Gohr } 220c591aabeSAndreas Gohr ptln('</script>',$it); 221c591aabeSAndreas Gohr } 2224beabca9SAnika Henke ptln('<script type="text/javascript" charset="utf-8" src="'. 223c591aabeSAndreas Gohr DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write.'"></script>',$it); 2246b13307fSandi} 2256b13307fSandi 2266b13307fSandi/** 2276b13307fSandi * Print a link 2286b13307fSandi * 2295e163278SAndreas Gohr * Just builds a link. 2306b13307fSandi * 2316b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 2326b13307fSandi */ 2336b13307fSandifunction tpl_link($url,$name,$more=''){ 2345e163278SAndreas Gohr print '<a href="'.$url.'" '; 2356b13307fSandi if ($more) print ' '.$more; 2366b13307fSandi print ">$name</a>"; 2376b13307fSandi} 2386b13307fSandi 2396b13307fSandi/** 24055efc227SAndreas Gohr * Prints a link to a WikiPage 24155efc227SAndreas Gohr * 24255efc227SAndreas Gohr * Wrapper around html_wikilink 24355efc227SAndreas Gohr * 24455efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 24555efc227SAndreas Gohr */ 24655efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){ 24755efc227SAndreas Gohr print html_wikilink($id,$name); 24855efc227SAndreas Gohr} 24955efc227SAndreas Gohr 25055efc227SAndreas Gohr/** 251a3ec5f4aSmatthiasgrimm * get the parent page 252a3ec5f4aSmatthiasgrimm * 253a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 254a3ec5f4aSmatthiasgrimm * returns false if none is available 255a3ec5f4aSmatthiasgrimm * 256a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 257a3ec5f4aSmatthiasgrimm */ 258a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){ 259a3ec5f4aSmatthiasgrimm global $conf; 260a3ec5f4aSmatthiasgrimm 261a3ec5f4aSmatthiasgrimm if ($ID != $conf['start']) { 262a3ec5f4aSmatthiasgrimm $idparts = explode(':', $ID); 263a3ec5f4aSmatthiasgrimm $pn = array_pop($idparts); // get the page name 264a3ec5f4aSmatthiasgrimm 265a3ec5f4aSmatthiasgrimm for ($n=0; $n < 2; $n++) { 266a3ec5f4aSmatthiasgrimm if (count($idparts) == 0) { 267a3ec5f4aSmatthiasgrimm $ID = $conf['start']; // go to topmost page 268a3ec5f4aSmatthiasgrimm break; 269a3ec5f4aSmatthiasgrimm }else{ 270a3ec5f4aSmatthiasgrimm $ns = array_pop($idparts); // get the last part of namespace 271a3ec5f4aSmatthiasgrimm if ($pn != $ns) { // are we already home? 272a3ec5f4aSmatthiasgrimm array_push($idparts, $ns, $ns); // no, then add a page with same name 273a3ec5f4aSmatthiasgrimm $ID = implode (':', $idparts); // as the namespace and recombine $ID 274a3ec5f4aSmatthiasgrimm break; 275a3ec5f4aSmatthiasgrimm } 276a3ec5f4aSmatthiasgrimm } 277a3ec5f4aSmatthiasgrimm } 278a3ec5f4aSmatthiasgrimm 279a3ec5f4aSmatthiasgrimm if (@file_exists(wikiFN($ID))) { 280a3ec5f4aSmatthiasgrimm return $ID; 281a3ec5f4aSmatthiasgrimm } 282a3ec5f4aSmatthiasgrimm } 283a3ec5f4aSmatthiasgrimm return false; 284a3ec5f4aSmatthiasgrimm} 285a3ec5f4aSmatthiasgrimm 286a3ec5f4aSmatthiasgrimm/** 2876b13307fSandi * Print one of the buttons 2886b13307fSandi * 2896b13307fSandi * Available Buttons are 2906b13307fSandi * 291ee4c4a1bSAndreas Gohr * edit - edit/create/show/draft button 2926b13307fSandi * history - old revisions 2936b13307fSandi * recent - recent changes 2946b13307fSandi * login - login/logout button - if ACL enabled 2956b13307fSandi * index - The index 296c19fe9c0Sandi * admin - admin page - if enough rights 2976b13307fSandi * top - a back to top button 298a3ec5f4aSmatthiasgrimm * back - a back to parent button - if available 299d67ca2c0Smatthiasgrimm * backtomedia - returns to the mediafile upload dialog 300d67ca2c0Smatthiasgrimm * after references have been displayed 301bbd37938SAndreas Gohr * backlink - links to the list of backlinks 3026b13307fSandi * 3036b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 304a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 3056b13307fSandi */ 3066b13307fSandifunction tpl_button($type){ 307b158d625SSteven Danz global $ACT; 3086b13307fSandi global $ID; 309d67ca2c0Smatthiasgrimm global $NS; 310c19fe9c0Sandi global $INFO; 3116b13307fSandi global $conf; 312cd52f92dSchris global $auth; 3136b13307fSandi 3146b13307fSandi switch($type){ 3156b13307fSandi case 'edit': 3166b13307fSandi print html_editbutton(); 3176b13307fSandi break; 3186b13307fSandi case 'history': 3195bc81eb9SAnders Betnér print html_btn('revs',$ID,'o',array('do' => 'revisions')); 3206b13307fSandi break; 3216b13307fSandi case 'recent': 3225bc81eb9SAnders Betnér print html_btn('recent','','r',array('do' => 'recent')); 3236b13307fSandi break; 3246b13307fSandi case 'index': 3255bc81eb9SAnders Betnér print html_btn('index',$ID,'x',array('do' => 'index')); 3266b13307fSandi break; 327a3ec5f4aSmatthiasgrimm case 'back': 3286222040cSmatthiasgrimm if ($parent = tpl_getparent($ID)) { 3296222040cSmatthiasgrimm print html_btn('back',$parent,'b',array('do' => 'show')); 330a3ec5f4aSmatthiasgrimm } 331a3ec5f4aSmatthiasgrimm break; 3326b13307fSandi case 'top': 3336b13307fSandi print html_topbtn(); 3346b13307fSandi break; 3356b13307fSandi case 'login': 3366b13307fSandi if($conf['useacl']){ 3376b13307fSandi if($_SERVER['REMOTE_USER']){ 3386b13307fSandi print html_btn('logout',$ID,'',array('do' => 'logout',)); 3396b13307fSandi }else{ 3406b13307fSandi print html_btn('login',$ID,'',array('do' => 'login')); 3416b13307fSandi } 3426b13307fSandi } 3436b13307fSandi break; 344c19fe9c0Sandi case 'admin': 345c19fe9c0Sandi if($INFO['perm'] == AUTH_ADMIN) 3465bc81eb9SAnders Betnér print html_btn('admin',$ID,'',array('do' => 'admin')); 347c19fe9c0Sandi break; 348d67ca2c0Smatthiasgrimm case 'backtomedia': 349d67ca2c0Smatthiasgrimm print html_backtomedia_button(array('ns' => $NS),'b'); 350d67ca2c0Smatthiasgrimm break; 3511380fc45SAndreas Gohr case 'subscription': 352f9eb5648Ssteven-danz if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 353b158d625SSteven Danz if($_SERVER['REMOTE_USER']){ 3541380fc45SAndreas Gohr if($INFO['subscribed']){ 3551380fc45SAndreas Gohr print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); 356b158d625SSteven Danz } else { 3571380fc45SAndreas Gohr print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); 358b158d625SSteven Danz } 359b158d625SSteven Danz } 360b158d625SSteven Danz } 361b158d625SSteven Danz break; 362f00151b4Schris case 'backlink': 363f00151b4Schris print html_btn('backlink',$ID,'',array('do' => 'backlink')); 364f00151b4Schris break; 3658b06d178Schris case 'profile': 36636223ba7SAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 36736223ba7SAndreas Gohr $auth->canDo('Profile') && ($ACT!='profile')){ 3688b06d178Schris print html_btn('profile',$ID,'',array('do' => 'profile')); 3698b06d178Schris } 3708b06d178Schris break; 371c19fe9c0Sandi default: 372c19fe9c0Sandi print '[unknown button type]'; 3736b13307fSandi } 3746b13307fSandi} 3756b13307fSandi 3766b13307fSandi/** 377ed630903Sandi * Like the action buttons but links 378ed630903Sandi * 379ed630903Sandi * Available links are 380ed630903Sandi * 381ed630903Sandi * edit - edit/create/show button 382ed630903Sandi * history - old revisions 383ed630903Sandi * recent - recent changes 384ed630903Sandi * login - login/logout button - if ACL enabled 385ed630903Sandi * index - The index 386ed630903Sandi * admin - admin page - if enough rights 387ed630903Sandi * top - a back to top button 388a3ec5f4aSmatthiasgrimm * back - a back to parent button - if available 389bbd37938SAndreas Gohr * backlink - links to the list of backlinks 390ed630903Sandi * 391ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 392a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 393ed630903Sandi * @see tpl_button 394ed630903Sandi */ 395ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){ 396ed630903Sandi global $ID; 397ed630903Sandi global $INFO; 398ed630903Sandi global $REV; 399ed630903Sandi global $ACT; 400ed630903Sandi global $conf; 401ed630903Sandi global $lang; 402cd52f92dSchris global $auth; 403ed630903Sandi 404ed630903Sandi switch($type){ 405ed630903Sandi case 'edit': 406ed630903Sandi #most complicated type - we need to decide on current action 407ed630903Sandi if($ACT == 'show' || $ACT == 'search'){ 408ed630903Sandi if($INFO['writable']){ 409ed630903Sandi if($INFO['exists']){ 410ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 411ed630903Sandi $pre.$lang['btn_edit'].$suf, 412b7af031cSsu 'class="action edit" accesskey="e" rel="nofollow"'); 413ed630903Sandi }else{ 414ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 415ed630903Sandi $pre.$lang['btn_create'].$suf, 416b7af031cSsu 'class="action create" accesskey="e" rel="nofollow"'); 417ed630903Sandi } 418ed630903Sandi }else{ 419ed630903Sandi tpl_link(wl($ID,'do=edit&rev='.$REV), 420ed630903Sandi $pre.$lang['btn_source'].$suf, 421b7af031cSsu 'class="action source" accesskey="v" rel="nofollow"'); 422ed630903Sandi } 423ed630903Sandi }else{ 424ed630903Sandi tpl_link(wl($ID,'do=show'), 425ed630903Sandi $pre.$lang['btn_show'].$suf, 426b7af031cSsu 'class="action show" accesskey="v" rel="nofollow"'); 427ed630903Sandi } 428c059e1a6SAndreas Gohr return true; 429ed630903Sandi case 'history': 430b7af031cSsu tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"'); 431c059e1a6SAndreas Gohr return true; 432ed630903Sandi case 'recent': 433b7af031cSsu tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"'); 434c059e1a6SAndreas Gohr return true; 435ed630903Sandi case 'index': 436b7af031cSsu tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"'); 437c059e1a6SAndreas Gohr return true; 438ed630903Sandi case 'top': 43921a15207SAnika Henke print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>'; 440c059e1a6SAndreas Gohr return true; 441a3ec5f4aSmatthiasgrimm case 'back': 442a3ec5f4aSmatthiasgrimm if ($ID = tpl_getparent($ID)) { 443b7af031cSsu tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"'); 444c059e1a6SAndreas Gohr return true; 445a3ec5f4aSmatthiasgrimm } 446c059e1a6SAndreas Gohr return false; 447ed630903Sandi case 'login': 448ed630903Sandi if($conf['useacl']){ 449ed630903Sandi if($_SERVER['REMOTE_USER']){ 450b7af031cSsu tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"'); 451ed630903Sandi }else{ 452b7af031cSsu tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"'); 453ed630903Sandi } 454c059e1a6SAndreas Gohr return true; 455ed630903Sandi } 456c059e1a6SAndreas Gohr return false; 457ed630903Sandi case 'admin': 458c059e1a6SAndreas Gohr if($INFO['perm'] == AUTH_ADMIN){ 459b7af031cSsu tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"'); 460c059e1a6SAndreas Gohr return true; 461c059e1a6SAndreas Gohr } 462c059e1a6SAndreas Gohr return false; 463f9eb5648Ssteven-danz case 'subscribe': 464075f000fSChristopher Arndt case 'subscription': 465f9eb5648Ssteven-danz if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ 466b158d625SSteven Danz if($_SERVER['REMOTE_USER']){ 467075f000fSChristopher Arndt if($INFO['subscribed']) { 468b7af031cSsu tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"'); 469b158d625SSteven Danz } else { 470b7af031cSsu tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"'); 471b158d625SSteven Danz } 472c059e1a6SAndreas Gohr return true; 473b158d625SSteven Danz } 474b158d625SSteven Danz } 475c059e1a6SAndreas Gohr return false; 476f00151b4Schris case 'backlink': 477b7af031cSsu tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"'); 478c059e1a6SAndreas Gohr return true; 4798b06d178Schris case 'profile': 48036223ba7SAndreas Gohr if($conf['useacl'] && $_SERVER['REMOTE_USER'] && 48136223ba7SAndreas Gohr $auth->canDo('Profile') && ($ACT!='profile')){ 4828b06d178Schris tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"'); 483c059e1a6SAndreas Gohr return true; 4848b06d178Schris } 485c059e1a6SAndreas Gohr return false; 486ed630903Sandi default: 487ed630903Sandi print '[unknown link type]'; 488c059e1a6SAndreas Gohr return true; 489ed630903Sandi } 490ed630903Sandi} 491ed630903Sandi 492ed630903Sandi/** 4936b13307fSandi * Print the search form 4946b13307fSandi * 49572645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 49672645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 49772645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 49872645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 49972645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 50072645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 50172645b75SAndreas Gohr * 5026b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 5036b13307fSandi */ 50472645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){ 5056b13307fSandi global $lang; 506c1e3b7d9Smatthiasgrimm global $ACT; 507c1e3b7d9Smatthiasgrimm 5081dd0c202SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; 5096b13307fSandi print '<input type="hidden" name="do" value="search" />'; 510c1e3b7d9Smatthiasgrimm print '<input type="text" '; 511bad31ae9SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" '; 51272645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 51324a33b42SAndreas Gohr print 'id="qsearch__in" accesskey="f" name="id" class="edit" />'; 5146b13307fSandi print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />'; 51524a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 5164beabca9SAnika Henke print '</div></form>'; 5176b13307fSandi} 5186b13307fSandi 5196b13307fSandi/** 5206b13307fSandi * Print the breadcrumbs trace 5216b13307fSandi * 5226b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 5236b13307fSandi */ 5246b13307fSandifunction tpl_breadcrumbs(){ 5256b13307fSandi global $lang; 5266b13307fSandi global $conf; 5276b13307fSandi 5286b13307fSandi //check if enabled 5296b13307fSandi if(!$conf['breadcrumbs']) return; 5306b13307fSandi 5316b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 532265e3787Sandi 533265e3787Sandi //reverse crumborder in right-to-left mode 534265e3787Sandi if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); 535265e3787Sandi 53640eb54bbSjan //render crumbs, highlight the last one 5376b13307fSandi print $lang['breadcrumb'].':'; 53840eb54bbSjan $last = count($crumbs); 53940eb54bbSjan $i = 0; 540a77f5846Sjan foreach ($crumbs as $id => $name){ 54140eb54bbSjan $i++; 542265e3787Sandi print ' <span class="bcsep">»</span> '; 54392795d04Sandi if ($i == $last) print '<span class="curid">'; 544a77f5846Sjan tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); 54592795d04Sandi if ($i == $last) print '</span>'; 5466b13307fSandi } 5476b13307fSandi} 5486b13307fSandi 5496b13307fSandi/** 5501734437eSandi * Hierarchical breadcrumbs 5511734437eSandi * 55231e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 5531734437eSandi * It only makes sense with a deep site structure. 5541734437eSandi * 5551734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 5566bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 55731e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 5581734437eSandi * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs 5596bd812dfSNigel McNie * @todo May behave strangely in RTL languages 5601734437eSandi */ 5611734437eSandifunction tpl_youarehere(){ 5621734437eSandi global $conf; 5631734437eSandi global $ID; 5641734437eSandi global $lang; 5651734437eSandi 56631e187f8SSean Coates //check if enabled 56731e187f8SSean Coates if(!$conf['youarehere']) return; 5681734437eSandi 5691734437eSandi $parts = explode(':', $ID); 5701734437eSandi 57131e187f8SSean Coates print $lang['youarehere'].': '; 5721734437eSandi 5731734437eSandi //always print the startpage 57431e187f8SSean Coates if( $a_part[0] != $conf['start']){ 57531e187f8SSean Coates if($conf['useheading']){ 57631e187f8SSean Coates $pageName = p_get_first_heading($conf['start']); 57731e187f8SSean Coates }else{ 57831e187f8SSean Coates $pageName = $conf['start']; 57931e187f8SSean Coates } 58031e187f8SSean Coates tpl_link(wl($conf['start']),$pageName,'title="'.$pageName.'"'); 58131e187f8SSean Coates } 5821734437eSandi 5831734437eSandi $page = ''; 5841734437eSandi foreach ($parts as $part){ 5856bd812dfSNigel McNie // Skip startpage if already done 5866bd812dfSNigel McNie if ($part == $conf['start']) continue; 5876bd812dfSNigel McNie 5881734437eSandi print ' » '; 5891734437eSandi $page .= $part; 5901734437eSandi 5911734437eSandi if(file_exists(wikiFN($page))){ 59231e187f8SSean Coates if($conf['useheading']){ 59331e187f8SSean Coates $pageName = p_get_first_heading($page); 59431e187f8SSean Coates $partName = $pageName; 59531e187f8SSean Coates }else{ 59631e187f8SSean Coates $pageName = $page; 59731e187f8SSean Coates $partName = $part; 59831e187f8SSean Coates } 59931e187f8SSean Coates tpl_link(wl($page),$partName,'title="'.$pageName.'"'); 6001734437eSandi }else{ 6016bd812dfSNigel McNie // Print the link, but mark as not-existing, as for other non-existing links 6026bd812dfSNigel McNie tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"'); 6036bd812dfSNigel McNie //print $page; 6041734437eSandi } 6051734437eSandi 6061734437eSandi $page .= ':'; 6071734437eSandi } 6081734437eSandi} 6091734437eSandi 6101734437eSandi/** 6116b13307fSandi * Print info if the user is logged in 612a2488c3cSMatthias Grimm * and show full name in that case 6136b13307fSandi * 6146b13307fSandi * Could be enhanced with a profile link in future? 6156b13307fSandi * 6166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 6176b13307fSandi */ 6186b13307fSandifunction tpl_userinfo(){ 6196b13307fSandi global $lang; 620a2488c3cSMatthias Grimm global $INFO; 6216b13307fSandi if($_SERVER['REMOTE_USER']) 622a2488c3cSMatthias Grimm print $lang['loggedinas'].': '.$INFO['userinfo']['name']; 6236b13307fSandi} 6246b13307fSandi 6256b13307fSandi/** 6266b13307fSandi * Print some info about the current page 6276b13307fSandi * 6286b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 6296b13307fSandi */ 6306b13307fSandifunction tpl_pageinfo(){ 6316b13307fSandi global $conf; 6326b13307fSandi global $lang; 6336b13307fSandi global $INFO; 6346b13307fSandi global $REV; 6356b13307fSandi 6366b13307fSandi // prepare date and path 6376b13307fSandi $fn = $INFO['filepath']; 6386b13307fSandi if(!$conf['fullpath']){ 6396b13307fSandi if($REV){ 6406b13307fSandi $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); 6416b13307fSandi }else{ 6426b13307fSandi $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); 6436b13307fSandi } 6446b13307fSandi } 645bee6dc82Sandi $fn = utf8_decodeFN($fn); 6466b13307fSandi $date = date($conf['dformat'],$INFO['lastmod']); 6476b13307fSandi 6486b13307fSandi // print it 6496b13307fSandi if($INFO['exists']){ 6506b13307fSandi print $fn; 6516b13307fSandi print ' · '; 6526b13307fSandi print $lang['lastmod']; 6536b13307fSandi print ': '; 6546b13307fSandi print $date; 6556b13307fSandi if($INFO['editor']){ 6566b13307fSandi print ' '.$lang['by'].' '; 6576b13307fSandi print $INFO['editor']; 6586b13307fSandi } 6596b13307fSandi if($INFO['locked']){ 6606b13307fSandi print ' · '; 6616b13307fSandi print $lang['lockedby']; 6626b13307fSandi print ': '; 6636b13307fSandi print $INFO['locked']; 6646b13307fSandi } 6656b13307fSandi } 6666b13307fSandi} 6676b13307fSandi 668820fa24bSandi/** 669820fa24bSandi * Print a list of namespaces containing media files 670820fa24bSandi * 671820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 672820fa24bSandi */ 673820fa24bSandifunction tpl_medianamespaces(){ 674820fa24bSandi global $conf; 675820fa24bSandi 676820fa24bSandi $data = array(); 677820fa24bSandi search($data,$conf['mediadir'],'search_namespaces',array()); 678820fa24bSandi print html_buildlist($data,'idx',media_html_list_namespaces); 679820fa24bSandi} 680820fa24bSandi 681820fa24bSandi/** 682820fa24bSandi * Print a list of mediafiles in the current namespace 683820fa24bSandi * 684820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 685820fa24bSandi */ 686820fa24bSandifunction tpl_mediafilelist(){ 687820fa24bSandi global $conf; 688820fa24bSandi global $lang; 689820fa24bSandi global $NS; 6908ef6b7caSandi global $AUTH; 691820fa24bSandi $dir = utf8_encodeFN(str_replace(':','/',$NS)); 692820fa24bSandi 693820fa24bSandi $data = array(); 694820fa24bSandi search($data,$conf['mediadir'],'search_media',array(),$dir); 695820fa24bSandi 696820fa24bSandi if(!count($data)){ 6974b15e09dSAndreas Gohr ptln('<div class="nothing">'.$lang['nothingfound'].'</div>'); 698820fa24bSandi return; 699820fa24bSandi } 700820fa24bSandi 701820fa24bSandi ptln('<ul>',2); 702820fa24bSandi foreach($data as $item){ 703806d77a0SAndreas Gohr if(!$item['isimg']){ 704806d77a0SAndreas Gohr // add file icons 705806d77a0SAndreas Gohr list($ext,$mime) = mimetype($item['file']); 706806d77a0SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 70743650a18SAndreas Gohr $class = ' class="mediafile mf_'.$class.'"'; 7081512f40dSAndreas Gohr }else{ 7091512f40dSAndreas Gohr $class = ''; 710806d77a0SAndreas Gohr } 711806d77a0SAndreas Gohr 7120c6b58a8SAndreas Gohr ptln('<li><div class="li">',4); 713806d77a0SAndreas Gohr ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')"'.$class.'>'. 714820fa24bSandi utf8_decodeFN($item['file']). 715820fa24bSandi '</a>',6); 7168ef6b7caSandi 7178ef6b7caSandi //prepare deletion button 7188ef6b7caSandi if($AUTH >= AUTH_DELETE){ 7190699afe9SAndreas Gohr $ask = addslashes($lang['del_confirm']).'\\n'; 7200699afe9SAndreas Gohr $ask .= addslashes($item['id']); 7218ef6b7caSandi 722b6c6979fSAndreas Gohr $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.rawurlencode($item['id']).'" '. 7238ef6b7caSandi 'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'. 724f62ea8a1Sandi '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '. 7254beabca9SAnika Henke 'title="'.$lang['btn_delete'].'" /></a>'; 7268ef6b7caSandi }else{ 7278ef6b7caSandi $del = ''; 7288ef6b7caSandi } 7298ef6b7caSandi 730820fa24bSandi if($item['isimg']){ 73193c020acSAndreas Gohr $w = (int) $item['meta']->getField('File.Width'); 73293c020acSAndreas Gohr $h = (int) $item['meta']->getField('File.Height'); 733820fa24bSandi 7348ef6b7caSandi ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); 7358ef6b7caSandi ptln($del.'<br />',6); 736478cd997SAndreas Gohr ptln('<div class="imagemeta">',6); 7379fcd3d1dSandi 73823a34783SAndreas Gohr //build thumbnail 7390699afe9SAndreas Gohr print '<a href="javascript:mediaSelect(\':'.$item['id'].'\')">'; 74023a34783SAndreas Gohr 74123a34783SAndreas Gohr if($w>120 || $h>120){ 74223a34783SAndreas Gohr $ratio = $item['meta']->getResizeRatio(120); 74323a34783SAndreas Gohr $w = floor($w * $ratio); 74423a34783SAndreas Gohr $h = floor($h * $ratio); 7459fcd3d1dSandi } 74623a34783SAndreas Gohr 7476de3759aSAndreas Gohr $src = ml($item['id'],array('w'=>$w,'h'=>$h)); 74823a34783SAndreas Gohr 74923a34783SAndreas Gohr $p = array(); 75023a34783SAndreas Gohr $p['width'] = $w; 75123a34783SAndreas Gohr $p['height'] = $h; 75223a34783SAndreas Gohr $p['alt'] = $item['id']; 75323a34783SAndreas Gohr $p['class'] = 'thumb'; 75423a34783SAndreas Gohr $att = buildAttributes($p); 75523a34783SAndreas Gohr 75623a34783SAndreas Gohr print '<img src="'.$src.'" '.$att.' />'; 7579fcd3d1dSandi print '</a>'; 758820fa24bSandi 7596d861d12SAndreas Gohr //read EXIF/IPTC data 76023a34783SAndreas Gohr $t = $item['meta']->getField('IPTC.Headline'); 76193c020acSAndreas Gohr if($t) print '<strong>'.htmlspecialchars($t).'</strong><br />'; 7626d861d12SAndreas Gohr 76336df6fa3SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment', 76436df6fa3SAndreas Gohr 'EXIF.TIFFImageDescription', 76536df6fa3SAndreas Gohr 'EXIF.TIFFUserComment')); 76693c020acSAndreas Gohr if($t) print htmlspecialchars($t).'<br />'; 7676d861d12SAndreas Gohr 76823a34783SAndreas Gohr $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category')); 76993c020acSAndreas Gohr if($t) print '<em>'.htmlspecialchars($t).'</em><br />'; 7706d861d12SAndreas Gohr 77136df6fa3SAndreas Gohr //add edit button 77236df6fa3SAndreas Gohr if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){ 773b6c6979fSAndreas Gohr print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.rawurlencode($item['id']).'">'; 77436df6fa3SAndreas Gohr print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />'; 77536df6fa3SAndreas Gohr print '</a>'; 77636df6fa3SAndreas Gohr } 77736df6fa3SAndreas Gohr 7786d861d12SAndreas Gohr ptln('</div>',6); 779820fa24bSandi }else{ 780820fa24bSandi ptln ('('.filesize_h($item['size']).')',6); 7818ef6b7caSandi ptln($del,6); 782820fa24bSandi } 7830c6b58a8SAndreas Gohr ptln('</div></li>',4); 784820fa24bSandi } 785820fa24bSandi ptln('</ul>',2); 786820fa24bSandi} 787820fa24bSandi 788820fa24bSandi/** 789d67ca2c0Smatthiasgrimm * show references to a media file 790d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share 791d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links. 792d67ca2c0Smatthiasgrimm * 793d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 794d67ca2c0Smatthiasgrimm */ 795d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){ 796d67ca2c0Smatthiasgrimm global $lang; 797d67ca2c0Smatthiasgrimm 798d67ca2c0Smatthiasgrimm $hidden=0; //count of hits without read permission 799d67ca2c0Smatthiasgrimm 800d67ca2c0Smatthiasgrimm if(count($data)){ 801d67ca2c0Smatthiasgrimm usort($data,'sort_search_fulltext'); 802d67ca2c0Smatthiasgrimm foreach($data as $row){ 803d67ca2c0Smatthiasgrimm if(auth_quickaclcheck($row['id']) >= AUTH_READ){ 804d67ca2c0Smatthiasgrimm print '<div class="search_result">'; 805d67ca2c0Smatthiasgrimm print '<span class="mediaref_ref">'.$row['id'].'</span>'; 806d67ca2c0Smatthiasgrimm print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />'; 807d67ca2c0Smatthiasgrimm print '<div class="search_snippet">'.$row['snippet'].'</div>'; 808d67ca2c0Smatthiasgrimm print '</div>'; 809d67ca2c0Smatthiasgrimm }else 810d67ca2c0Smatthiasgrimm $hidden++; 811d67ca2c0Smatthiasgrimm } 812d67ca2c0Smatthiasgrimm if ($hidden){ 813d67ca2c0Smatthiasgrimm print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>'; 814d67ca2c0Smatthiasgrimm } 815d67ca2c0Smatthiasgrimm } 816d67ca2c0Smatthiasgrimm} 817d67ca2c0Smatthiasgrimm 818d67ca2c0Smatthiasgrimm/** 819820fa24bSandi * Print the media upload form if permissions are correct 820820fa24bSandi * 821820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org> 822820fa24bSandi */ 823820fa24bSandifunction tpl_mediauploadform(){ 824820fa24bSandi global $NS; 825820fa24bSandi global $UPLOADOK; 8268ef6b7caSandi global $AUTH; 827820fa24bSandi global $lang; 828820fa24bSandi 829820fa24bSandi if(!$UPLOADOK) return; 830820fa24bSandi 8311dd0c202SAnika Henke ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" id="dw__upload"'. 832820fa24bSandi ' method="post" enctype="multipart/form-data">',2); 833820fa24bSandi ptln($lang['txt_upload'].':<br />',4); 834820fa24bSandi ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4); 835820fa24bSandi ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4); 836820fa24bSandi ptln($lang['txt_filename'].'<br />',4); 837820fa24bSandi ptln('<input type="text" name="id" class="edit" />',4); 838820fa24bSandi ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4); 8398ef6b7caSandi if($AUTH >= AUTH_DELETE){ 84024a33b42SAndreas Gohr ptln('<label for="dw__ow"><input type="checkbox" name="ow" value="1" id="dw__ow" />'.$lang['txt_overwrt'].'</label>',4); 8418ef6b7caSandi } 842820fa24bSandi ptln('</form>',2); 843820fa24bSandi} 844820fa24bSandi 84587c434ceSAndreas Gohr/** 846a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 84787c434ceSAndreas Gohr * 84887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 849a6598f23SBen Coburn * the given ID is used. 85087c434ceSAndreas Gohr * 85187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 85287c434ceSAndreas Gohr */ 853a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){ 85487c434ceSAndreas Gohr global $conf; 85587c434ceSAndreas Gohr if(is_null($id)){ 85687c434ceSAndreas Gohr global $ID; 85787c434ceSAndreas Gohr $id = $ID; 85887c434ceSAndreas Gohr } 85987c434ceSAndreas Gohr 86087c434ceSAndreas Gohr $name = $id; 86187c434ceSAndreas Gohr if ($conf['useheading']) { 86287c434ceSAndreas Gohr $title = p_get_first_heading($id); 86387c434ceSAndreas Gohr if ($title) $name = $title; 86487c434ceSAndreas Gohr } 865a6598f23SBen Coburn 866a6598f23SBen Coburn if ($ret) { 867a6598f23SBen Coburn return hsc($name); 868a6598f23SBen Coburn } else { 86987c434ceSAndreas Gohr print hsc($name); 87087c434ceSAndreas Gohr } 871a6598f23SBen Coburn} 872340756e4Sandi 87355efc227SAndreas Gohr/** 87455efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 87555efc227SAndreas Gohr * 87655efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 87755efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 87855efc227SAndreas Gohr * 87955efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 88055efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 88155efc227SAndreas Gohr * to the names of the latter one) 88255efc227SAndreas Gohr * 88336df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php 88455efc227SAndreas Gohr * 88555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 88655efc227SAndreas Gohr */ 88755efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){ 88855efc227SAndreas Gohr // Init Exif Reader 88955efc227SAndreas Gohr global $SRC; 89055efc227SAndreas Gohr static $meta = null; 89155efc227SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($SRC); 89255efc227SAndreas Gohr if($meta === false) return $alt; 89355efc227SAndreas Gohr $info = $meta->getField($tags); 89455efc227SAndreas Gohr if($info == false) return $alt; 89555efc227SAndreas Gohr return $info; 89655efc227SAndreas Gohr} 89755efc227SAndreas Gohr 89855efc227SAndreas Gohr/** 89955efc227SAndreas Gohr * Prints the image with a link to the full sized version 90055efc227SAndreas Gohr * 90155efc227SAndreas Gohr * Only allowed in: detail.php 90255efc227SAndreas Gohr */ 903f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){ 90455efc227SAndreas Gohr global $IMG; 90555efc227SAndreas Gohr $w = tpl_img_getTag('File.Width'); 90655efc227SAndreas Gohr $h = tpl_img_getTag('File.Height'); 90755efc227SAndreas Gohr 90855efc227SAndreas Gohr //resize to given max values 90923a34783SAndreas Gohr $ratio = 1; 91023a34783SAndreas Gohr if($w >= $h){ 911f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth){ 91255efc227SAndreas Gohr $ratio = $maxwidth/$w; 913f8925855Sjoe.lapp }elseif($maxheight && $h > $maxheight){ 91455efc227SAndreas Gohr $ratio = $maxheight/$h; 91555efc227SAndreas Gohr } 91655efc227SAndreas Gohr }else{ 917f8925855Sjoe.lapp if($maxheight && $h >= $maxheight){ 91855efc227SAndreas Gohr $ratio = $maxheight/$h; 919f8925855Sjoe.lapp }elseif($maxwidth && $w > $maxwidth){ 92055efc227SAndreas Gohr $ratio = $maxwidth/$w; 92155efc227SAndreas Gohr } 92255efc227SAndreas Gohr } 92355efc227SAndreas Gohr if($ratio){ 92455efc227SAndreas Gohr $w = floor($ratio*$w); 92555efc227SAndreas Gohr $h = floor($ratio*$h); 92655efc227SAndreas Gohr } 92755efc227SAndreas Gohr 9286de3759aSAndreas Gohr //prepare URLs 9296de3759aSAndreas Gohr $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); 9306de3759aSAndreas Gohr $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); 93155efc227SAndreas Gohr 9322684e50aSAndreas Gohr //prepare attributes 93355efc227SAndreas Gohr $alt=tpl_img_getTag('Simple.Title'); 9342684e50aSAndreas Gohr $p = array(); 9352684e50aSAndreas Gohr if($w) $p['width'] = $w; 9362684e50aSAndreas Gohr if($h) $p['height'] = $h; 9372684e50aSAndreas Gohr $p['class'] = 'img_detail'; 9382684e50aSAndreas Gohr if($alt){ 9392684e50aSAndreas Gohr $p['alt'] = $alt; 9402684e50aSAndreas Gohr $p['title'] = $alt; 9412684e50aSAndreas Gohr }else{ 9422684e50aSAndreas Gohr $p['alt'] = ''; 9432684e50aSAndreas Gohr } 9442684e50aSAndreas Gohr $p = buildAttributes($p); 94555efc227SAndreas Gohr 94655efc227SAndreas Gohr print '<a href="'.$url.'">'; 9476de3759aSAndreas Gohr print '<img src="'.$src.'" '.$p.'/>'; 94855efc227SAndreas Gohr print '</a>'; 94955efc227SAndreas Gohr} 95055efc227SAndreas Gohr 9517367b368SAndreas Gohr/** 9527367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality 9537367b368SAndreas Gohr * is the inexer function. 9547367b368SAndreas Gohr * 9557367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 9567367b368SAndreas Gohr * template 9577367b368SAndreas Gohr */ 9587367b368SAndreas Gohrfunction tpl_indexerWebBug(){ 9597367b368SAndreas Gohr global $ID; 9601dad36f5SAndreas Gohr global $INFO; 9611dad36f5SAndreas Gohr if(!$INFO['exists']) return; 9621dad36f5SAndreas Gohr 9630dc92c6fSAndreas Gohr if(isHiddenPage($ID)) return; //no need to index hidden pages 9640dc92c6fSAndreas Gohr 9657367b368SAndreas Gohr $p = array(); 966b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 967e68c51baSAndreas Gohr '&'.time(); 9687367b368SAndreas Gohr $p['width'] = 1; 9697367b368SAndreas Gohr $p['height'] = 1; 9707367b368SAndreas Gohr $p['alt'] = ''; 9717367b368SAndreas Gohr $att = buildAttributes($p); 9727367b368SAndreas Gohr print "<img $att />"; 9737367b368SAndreas Gohr} 9747367b368SAndreas Gohr 97578d4e784SEsther Brunner// configuration methods 97678d4e784SEsther Brunner/** 97778d4e784SEsther Brunner * tpl_getConf($id) 97878d4e784SEsther Brunner * 97978d4e784SEsther Brunner * use this function to access template configuration variables 98078d4e784SEsther Brunner */ 98178d4e784SEsther Brunnerfunction tpl_getConf($id){ 98278d4e784SEsther Brunner global $conf; 98378d4e784SEsther Brunner global $tpl_configloaded; 98478d4e784SEsther Brunner 98578d4e784SEsther Brunner $tpl = $conf['template']; 98678d4e784SEsther Brunner 98778d4e784SEsther Brunner if (!$tpl_configloaded){ 98878d4e784SEsther Brunner $tconf = tpl_loadConfig(); 98978d4e784SEsther Brunner if ($tconf !== false){ 99078d4e784SEsther Brunner foreach ($tconf as $key => $value){ 99178d4e784SEsther Brunner if (isset($conf['tpl'][$tpl][$key])) continue; 99278d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 99378d4e784SEsther Brunner } 99478d4e784SEsther Brunner $tpl_configloaded = true; 99578d4e784SEsther Brunner } 99678d4e784SEsther Brunner } 99778d4e784SEsther Brunner 99878d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 99978d4e784SEsther Brunner} 100078d4e784SEsther Brunner 100178d4e784SEsther Brunner/** 100278d4e784SEsther Brunner * tpl_loadConfig() 100378d4e784SEsther Brunner * reads all template configuration variables 100478d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 100578d4e784SEsther Brunner */ 100678d4e784SEsther Brunnerfunction tpl_loadConfig(){ 100778d4e784SEsther Brunner 100878d4e784SEsther Brunner $file = DOKU_TPLINC.'/conf/default.php'; 100978d4e784SEsther Brunner $conf = array(); 101078d4e784SEsther Brunner 101178d4e784SEsther Brunner if (!@file_exists($file)) return false; 101278d4e784SEsther Brunner 101378d4e784SEsther Brunner // load default config file 101478d4e784SEsther Brunner include($file); 101578d4e784SEsther Brunner 101678d4e784SEsther Brunner return $conf; 101778d4e784SEsther Brunner} 101878d4e784SEsther Brunner 1019340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 1020