*/ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_CONF.'dokuwiki.php'); /** * Returns the path to the given template, uses * default one if the custom version doesn't exist. * Also enables gzip compression if configured. * * @author Andreas Gohr */ function template($tpl){ global $conf; if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; return DOKU_INC.'lib/tpl/default/'.$tpl; } /** * Print the content * * This function is used for printing all the usual content * (defined by the global $ACT var) by calling the appropriate * outputfunction(s) from html.php * * Everything that doesn't use the main template file isn't * handled by this function. ACL stuff is not done here either. * * @author Andreas Gohr */ function tpl_content() { global $ACT; ob_start(); trigger_event('TPL_ACT_RENDER',$ACT,tpl_content_core); $html_output = ob_get_clean(); trigger_event('TPL_CONTENT_DISPLAY',$html_output,ptln); } function tpl_content_core(){ global $ACT; global $TEXT; global $PRE; global $SUF; global $SUM; global $IDX; switch($ACT){ case 'show': html_show(); break; case 'preview': html_edit($TEXT); html_show($TEXT); break; case 'recover': html_edit($TEXT); break; case 'edit': html_edit(); break; case 'draft': html_draft(); break; case 'wordblock': html_edit($TEXT,'wordblock'); break; case 'search': html_search(); break; case 'revisions': html_revisions(); break; case 'diff': html_diff(); break; case 'recent': $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; html_recent($first); break; case 'index': html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? break; case 'backlink': html_backlinks(); break; case 'conflict': html_conflict(con($PRE,$TEXT,$SUF),$SUM); html_diff(con($PRE,$TEXT,$SUF),false); break; case 'locked': html_locked(); break; case 'login': html_login(); break; case 'register': html_register(); break; case 'resendpwd': html_resendpwd(); break; case 'denied': print p_locale_xhtml('denied'); break; case 'profile' : html_updateprofile(); break; case 'admin': tpl_admin(); break; default: $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); if ($evt->advise_before()) msg("Failed to handle command: ".hsc($ACT),-1); $evt->advise_after(); unset($evt); } } /** * Handle the admin page contents * * @author Andreas Gohr */ function tpl_admin(){ $plugin = NULL; if ($_REQUEST['page']) { $pluginlist = plugin_list('admin'); if (in_array($_REQUEST['page'], $pluginlist)) { // attempt to load the plugin $plugin =& plugin_load('admin',$_REQUEST['page']); } } if ($plugin !== NULL) $plugin->html(); else html_admin(); } /** * Print the correct HTML meta headers * * This has to go into the head section of your template. * * @param boolean $alt Should feeds and alternative format links be added? * @author Andreas Gohr */ function tpl_metaheaders($alt=true){ global $ID; global $INFO; global $ACT; global $lang; global $conf; $it=2; // the usual stuff ptln('',$it); ptln('',$it); ptln('',$it); if($alt){ ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); } // setup robot tags apropriate for different modes if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ if($INFO['exists']){ ptln('',$it); //delay indexing: if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ ptln('',$it); }else{ ptln('',$it); } }else{ ptln('',$it); } }else{ ptln('',$it); } // load stylesheets ptln('',$it); ptln('',$it); // load javascript $js_edit = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0; $js_write = ($INFO['writable']) ? 1 : 0; if(defined('DOKU_MEDIAMANAGER')){ $js_edit = 1; $js_write = 0; } if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){ ptln('',$it); } ptln('',$it); } /** * Print a link * * Just builds a link. * * @author Andreas Gohr */ function tpl_link($url,$name,$more=''){ print '$name"; } /** * Prints a link to a WikiPage * * Wrapper around html_wikilink * * @author Andreas Gohr */ function tpl_pagelink($id,$name=NULL){ print html_wikilink($id,$name); } /** * get the parent page * * Tries to find out which page is parent. * returns false if none is available * * @author Matthias Grimm */ function tpl_getparent($ID){ global $conf; if ($ID != $conf['start']) { $idparts = explode(':', $ID); $pn = array_pop($idparts); // get the page name for ($n=0; $n < 2; $n++) { if (count($idparts) == 0) { $ID = $conf['start']; // go to topmost page break; }else{ $ns = array_pop($idparts); // get the last part of namespace if ($pn != $ns) { // are we already home? array_push($idparts, $ns, $ns); // no, then add a page with same name $ID = implode (':', $idparts); // as the namespace and recombine $ID break; } } } if (@file_exists(wikiFN($ID))) { return $ID; } } return false; } /** * Print one of the buttons * * Available Buttons are * * edit - edit/create/show/draft button * history - old revisions * recent - recent changes * login - login/logout button - if ACL enabled * index - The index * admin - admin page - if enough rights * top - a back to top button * back - a back to parent button - if available * backtomedia - returns to the mediafile upload dialog * after references have been displayed * backlink - links to the list of backlinks * * @author Andreas Gohr * @author Matthias Grimm */ function tpl_button($type){ global $ACT; global $ID; global $NS; global $INFO; global $conf; global $auth; switch($type){ case 'edit': print html_editbutton(); break; case 'history': print html_btn('revs',$ID,'o',array('do' => 'revisions')); break; case 'recent': print html_btn('recent','','r',array('do' => 'recent')); break; case 'index': print html_btn('index',$ID,'x',array('do' => 'index')); break; case 'back': if ($parent = tpl_getparent($ID)) { print html_btn('back',$parent,'b',array('do' => 'show')); } break; case 'top': print html_topbtn(); break; case 'login': if($conf['useacl']){ if($_SERVER['REMOTE_USER']){ print html_btn('logout',$ID,'',array('do' => 'logout',)); }else{ print html_btn('login',$ID,'',array('do' => 'login')); } } break; case 'admin': if($INFO['perm'] == AUTH_ADMIN) print html_btn('admin',$ID,'',array('do' => 'admin')); break; case 'backtomedia': print html_backtomedia_button(array('ns' => $NS),'b'); break; case 'subscription': if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ if($_SERVER['REMOTE_USER']){ if($INFO['subscribed']){ print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',)); } else { print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); } } } break; case 'backlink': print html_btn('backlink',$ID,'',array('do' => 'backlink')); break; case 'profile': if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth->canDo('Profile') && ($ACT!='profile')){ print html_btn('profile',$ID,'',array('do' => 'profile')); } break; default: print '[unknown button type]'; } } /** * Like the action buttons but links * * Available links are * * edit - edit/create/show button * history - old revisions * recent - recent changes * login - login/logout button - if ACL enabled * index - The index * admin - admin page - if enough rights * top - a back to top button * back - a back to parent button - if available * backlink - links to the list of backlinks * * @author Andreas Gohr * @author Matthias Grimm * @see tpl_button */ function tpl_actionlink($type,$pre='',$suf=''){ global $ID; global $INFO; global $REV; global $ACT; global $conf; global $lang; global $auth; switch($type){ case 'edit': #most complicated type - we need to decide on current action if($ACT == 'show' || $ACT == 'search'){ if($INFO['writable']){ if($INFO['exists']){ tpl_link(wl($ID,'do=edit&rev='.$REV), $pre.$lang['btn_edit'].$suf, 'class="action edit" accesskey="e" rel="nofollow"'); }else{ tpl_link(wl($ID,'do=edit&rev='.$REV), $pre.$lang['btn_create'].$suf, 'class="action create" accesskey="e" rel="nofollow"'); } }else{ tpl_link(wl($ID,'do=edit&rev='.$REV), $pre.$lang['btn_source'].$suf, 'class="action source" accesskey="v" rel="nofollow"'); } }else{ tpl_link(wl($ID,'do=show'), $pre.$lang['btn_show'].$suf, 'class="action show" accesskey="v" rel="nofollow"'); } return true; case 'history': tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"'); return true; case 'recent': tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"'); return true; case 'index': tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"'); return true; case 'top': print ''.$pre.$lang['btn_top'].$suf.''; return true; case 'back': if ($ID = tpl_getparent($ID)) { tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"'); return true; } return false; case 'login': if($conf['useacl']){ if($_SERVER['REMOTE_USER']){ tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"'); }else{ tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"'); } return true; } return false; case 'admin': if($INFO['perm'] == AUTH_ADMIN){ tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"'); return true; } return false; case 'subscribe': case 'subscription': if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){ if($_SERVER['REMOTE_USER']){ if($INFO['subscribed']) { tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"'); } else { tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"'); } return true; } } return false; case 'backlink': tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"'); return true; case 'profile': if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth->canDo('Profile') && ($ACT!='profile')){ tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"'); return true; } return false; default: print '[unknown link type]'; return true; } } /** * Print the search form * * If the first parameter is given a div with the ID 'qsearch_out' will * be added which instructs the ajax pagequicksearch to kick in and place * its output into this div. The second parameter controls the propritary * attribute autocomplete. If set to false this attribute will be set with an * value of "off" to instruct the browser to disable it's own built in * autocompletion feature (MSIE and Firefox) * * @author Andreas Gohr */ function tpl_searchform($ajax=true,$autocomplete=true){ global $lang; global $ACT; print ''; } /** * Print the breadcrumbs trace * * @author Andreas Gohr */ function tpl_breadcrumbs(){ global $lang; global $conf; //check if enabled if(!$conf['breadcrumbs']) return; $crumbs = breadcrumbs(); //setup crumb trace //reverse crumborder in right-to-left mode if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true); //render crumbs, highlight the last one print $lang['breadcrumb'].':'; $last = count($crumbs); $i = 0; foreach ($crumbs as $id => $name){ $i++; print ' » '; if ($i == $last) print ''; tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"'); if ($i == $last) print ''; } } /** * Hierarchical breadcrumbs * * This code was suggested as replacement for the usual breadcrumbs. * It only makes sense with a deep site structure. * * @author Andreas Gohr * @author Nigel McNie * @author Sean Coates * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs * @todo May behave strangely in RTL languages */ function tpl_youarehere(){ global $conf; global $ID; global $lang; //check if enabled if(!$conf['youarehere']) return; $parts = explode(':', $ID); print $lang['youarehere'].': '; //always print the startpage if( $a_part[0] != $conf['start']){ if($conf['useheading']){ $pageName = p_get_first_heading($conf['start']); }else{ $pageName = $conf['start']; } tpl_link(wl($conf['start']),$pageName,'title="'.$pageName.'"'); } $page = ''; foreach ($parts as $part){ // Skip startpage if already done if ($part == $conf['start']) continue; print ' » '; $page .= $part; if(file_exists(wikiFN($page))){ if($conf['useheading']){ $pageName = p_get_first_heading($page); $partName = $pageName; }else{ $pageName = $page; $partName = $part; } tpl_link(wl($page),$partName,'title="'.$pageName.'"'); }else{ // Print the link, but mark as not-existing, as for other non-existing links tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"'); //print $page; } $page .= ':'; } } /** * Print info if the user is logged in * and show full name in that case * * Could be enhanced with a profile link in future? * * @author Andreas Gohr */ function tpl_userinfo(){ global $lang; global $INFO; if($_SERVER['REMOTE_USER']) print $lang['loggedinas'].': '.$INFO['userinfo']['name']; } /** * Print some info about the current page * * @author Andreas Gohr */ function tpl_pageinfo(){ global $conf; global $lang; global $INFO; global $REV; // prepare date and path $fn = $INFO['filepath']; if(!$conf['fullpath']){ if($REV){ $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn); }else{ $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn); } } $fn = utf8_decodeFN($fn); $date = date($conf['dformat'],$INFO['lastmod']); // print it if($INFO['exists']){ print $fn; print ' · '; print $lang['lastmod']; print ': '; print $date; if($INFO['editor']){ print ' '.$lang['by'].' '; print $INFO['editor']; } if($INFO['locked']){ print ' · '; print $lang['lockedby']; print ': '; print $INFO['locked']; } } } /** * Prints or returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is used. * * @author Andreas Gohr */ function tpl_pagetitle($id=null, $ret=false){ global $conf; if(is_null($id)){ global $ID; $id = $ID; } $name = $id; if ($conf['useheading']) { $title = p_get_first_heading($id); if ($title) $name = $title; } if ($ret) { return hsc($name); } else { print hsc($name); } } /** * Returns the requested EXIF/IPTC tag from the current image * * If $tags is an array all given tags are tried until a * value is found. If no value is found $alt is returned. * * Which texts are known is defined in the functions _exifTagNames * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC * to the names of the latter one) * * Only allowed in: detail.php * * @author Andreas Gohr */ function tpl_img_getTag($tags,$alt='',$src=null){ // Init Exif Reader global $SRC; if(is_null($src)) $src = $SRC; static $meta = null; if(is_null($meta)) $meta = new JpegMeta($src); if($meta === false) return $alt; $info = $meta->getField($tags); if($info == false) return $alt; return $info; } /** * Prints the image with a link to the full sized version * * Only allowed in: detail.php */ function tpl_img($maxwidth=0,$maxheight=0){ global $IMG; $w = tpl_img_getTag('File.Width'); $h = tpl_img_getTag('File.Height'); //resize to given max values $ratio = 1; if($w >= $h){ if($maxwidth && $w >= $maxwidth){ $ratio = $maxwidth/$w; }elseif($maxheight && $h > $maxheight){ $ratio = $maxheight/$h; } }else{ if($maxheight && $h >= $maxheight){ $ratio = $maxheight/$h; }elseif($maxwidth && $w > $maxwidth){ $ratio = $maxwidth/$w; } } if($ratio){ $w = floor($ratio*$w); $h = floor($ratio*$h); } //prepare URLs $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); //prepare attributes $alt=tpl_img_getTag('Simple.Title'); $p = array(); if($w) $p['width'] = $w; if($h) $p['height'] = $h; $p['class'] = 'img_detail'; if($alt){ $p['alt'] = $alt; $p['title'] = $alt; }else{ $p['alt'] = ''; } $p = buildAttributes($p); print ''; print ''; print ''; } /** * This function inserts a 1x1 pixel gif which in reality * is the inexer function. * * Should be called somewhere at the very end of the main.php * template */ function tpl_indexerWebBug(){ global $ID; global $INFO; if(!$INFO['exists']) return; if(isHiddenPage($ID)) return; //no need to index hidden pages $p = array(); $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). '&'.time(); $p['width'] = 1; $p['height'] = 1; $p['alt'] = ''; $att = buildAttributes($p); print ""; } // configuration methods /** * tpl_getConf($id) * * use this function to access template configuration variables */ function tpl_getConf($id){ global $conf; global $tpl_configloaded; $tpl = $conf['template']; if (!$tpl_configloaded){ $tconf = tpl_loadConfig(); if ($tconf !== false){ foreach ($tconf as $key => $value){ if (isset($conf['tpl'][$tpl][$key])) continue; $conf['tpl'][$tpl][$key] = $value; } $tpl_configloaded = true; } } return $conf['tpl'][$tpl][$id]; } /** * tpl_loadConfig() * reads all template configuration variables * this function is automatically called by tpl_getConf() */ function tpl_loadConfig(){ $file = DOKU_TPLINC.'/conf/default.php'; $conf = array(); if (!@file_exists($file)) return false; // load default config file include($file); return $conf; } /** * prints the "main content" in the mediamanger popup * * Depending on the user's actions this may be a list of * files in a namespace, the meta editing dialog or * a message of referencing pages * * Only allowed in mediamanager.php * * @author Andreas Gohr */ function tpl_mediaContent(){ global $IMG; global $AUTH; global $INUSE; global $NS; global $JUMPTO; ptln('
'); if($_REQUEST['edit']){ media_metaform($IMG,$AUTH); }elseif($INUSE){ media_filesinuse($INUSE,$IMG); }else{ media_filelist($NS,$AUTH,$JUMPTO); } ptln('
'); } /** * prints the namespace tree in the mediamanger popup * * Only allowed in mediamanager.php * * @author Andreas Gohr */ function tpl_mediaTree(){ global $NS; ptln('
'); media_nstree($NS); ptln('
'); } //Setup VIM: ex: et ts=2 enc=utf-8 :