*/ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); require_once(DOKU_INC.'conf/dokuwiki.php'); /** * Wrapper around htmlspecialchars() * * @author Andreas Gohr * @see htmlspecialchars() */ function hsc($string){ return htmlspecialchars($string); } /** * print a newline terminated string * * You can give an indention as optional parameter * * @author Andreas Gohr */ function ptln($string,$intend=0){ for($i=0; $i<$intend; $i++) print ' '; print"$string\n"; } /** * 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 default template isn't * handled by this function. ACL stuff is not done either. * * @author Andreas Gohr */ function tpl_content(){ 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 'edit': html_edit(); 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 'denied': print p_locale_xhtml('denied'); break; case 'admin': tpl_admin(); break; default: msg("Failed to handle command: ".hsc($ACT),-1); } } /** * Handle the admin page contents * * @author Andreas Gohr */ function tpl_admin(){ switch($_REQUEST['page']){ case 'acl': admin_acl_html(); break; default: html_admin(); } } /** * Print the correct HTML meta headers * * This has to go into the head section of your template. * * @author Andreas Gohr */ function tpl_metaheaders(){ global $ID; global $INFO; global $ACT; global $lang; global $conf; $it=2; // the usual stuff ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); ptln('',$it); // setup robot tags apropriate for different modes if( ($ACT=='show' || $ACT=='export_html') && !$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); } // include some JavaScript language strings ptln('',$it); // load the default JavaScript files ptln('',$it); ptln('',$it); ptln('',$it); // load spellchecker script if wanted if($conf['spellchecker'] && ($ACT=='edit' || $ACT=='preview')){ ptln('',$it); } //FIXME include some default CSS ? IE FIX? } /** * Print a link * * Just builds a link but adds additional JavaScript needed for * the unsaved data check needed in the edit form. * * @author Andreas Gohr */ function tpl_link($url,$name,$more=''){ print '$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 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 * * @author Andreas Gohr * @author Matthias Grimm */ function tpl_button($type){ global $ID; global $NS; global $INFO; global $conf; 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 ($ID = tpl_getparent($ID)) { print html_btn(back,$ID,'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; 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 * * @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; 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" accesskey="e" rel="nofollow"'); }else{ tpl_link(wl($ID,'do=edit&rev='.$REV), $pre.$lang['btn_create'].$suf, 'class="action" accesskey="e" rel="nofollow"'); } }else{ tpl_link(wl($ID,'do=edit&rev='.$REV), $pre.$lang['btn_source'].$suf, 'class="action" accesskey="v" rel="nofollow"'); } }else{ tpl_link(wl($ID,'do=show'), $pre.$lang['btn_show'].$suf, 'class="action" accesskey="v" rel="nofollow"'); } break; case 'history': tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action" accesskey="o"'); break; case 'recent': tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action" accesskey="r"'); break; case 'index': tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action" accesskey="x"'); break; case 'top': print ''.$pre.$lang['btn_top'].$suf.''; break; case 'back': if ($ID = tpl_getparent($ID)) { tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action" accesskey="b"'); } break; case 'login': if($conf['useacl']){ if($_SERVER['REMOTE_USER']){ tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action"'); }else{ tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action"'); } } break; case 'admin': if($INFO['perm'] == AUTH_ADMIN) tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action"'); break; default: print '[unknown link type]'; } } /** * Print the search form * * @author Andreas Gohr */ function tpl_searchform(){ 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 * trail in the Wiki and was modified by me. * It only makes sense with a deep site structure. * * @author Andreas Gohr * @link http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs * @todo May behave starngely in RTL languages */ function tpl_youarehere(){ global $conf; global $ID; global $lang; $parts = explode(':', $ID); print $lang['breadcrumb'].': '; //always print the startpage if( $a_part[0] != $conf['start'] ) tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"'); $page = ''; foreach ($parts as $part){ print ' » '; $page .= $part; if(file_exists(wikiFN($page))){ tpl_link(wl($page),$part,'title="'.$page.'"'); }else{ 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']; } } } /** * Print a list of namespaces containing media files * * @author Andreas Gohr */ function tpl_medianamespaces(){ global $conf; $data = array(); search($data,$conf['mediadir'],'search_namespaces',array()); print html_buildlist($data,'idx',media_html_list_namespaces); } /** * Print a list of mediafiles in the current namespace * * @author Andreas Gohr */ function tpl_mediafilelist(){ global $conf; global $lang; global $NS; global $AUTH; $dir = utf8_encodeFN(str_replace(':','/',$NS)); $data = array(); search($data,$conf['mediadir'],'search_media',array(),$dir); if(!count($data)){ ptln('
'.$lang['nothingfound'].'
'); return; } ptln('
    ',2); foreach($data as $item){ ptln('
  • ',4); ptln(''. utf8_decodeFN($item['file']). '',6); //prepare deletion button if($AUTH >= AUTH_DELETE){ $ask = $lang['del_confirm'].'\\n'; $ask .= $item['id']; $del = ''. ''.$lang['btn_delete'].''; }else{ $del = ''; } if($item['isimg']){ $w = $item['info'][0]; $h = $item['info'][1]; ptln('('.$w.'×'.$h.' '.filesize_h($item['size']).')',6); ptln($del.'
    ',6); ptln(''); if($w>120){ print ''; }else{ print ''; } print ''; }else{ ptln ('('.filesize_h($item['size']).')',6); ptln($del,6); } ptln('
  • ',4); } ptln('
',2); } /** * show references to a media file * References uses the same visual as search results and share * their CSS tags except pagenames won't be links. * * @author Matthias Grimm */ function tpl_showreferences(&$data){ global $lang; $hidden=0; //count of hits without read permission if(count($data)){ usort($data,'sort_search_fulltext'); foreach($data as $row){ if(auth_quickaclcheck($row['id']) >= AUTH_READ){ print '
'; print ''.$row['id'].''; print ': '.$row['count'].' '.$lang['hits'].'
'; print '
'.$row['snippet'].'
'; print '
'; }else $hidden++; } if ($hidden){ print '
'.$lang['ref_hidden'].'
'; } } } /** * Print the media upload form if permissions are correct * * @author Andreas Gohr */ function tpl_mediauploadform(){ global $NS; global $UPLOADOK; global $AUTH; global $lang; if(!$UPLOADOK) return; ptln('
',2); ptln($lang['txt_upload'].':
',4); ptln('',4); ptln('
',4); ptln($lang['txt_filename'].'
',4); ptln('',4); ptln('',4); if($AUTH >= AUTH_DELETE){ ptln('',4); } ptln('
',2); } //Setup VIM: ex: et ts=2 enc=utf-8 :