1<?php 2/** 3 * Template functions for DokuBook template 4 * 5 * @license: GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author: Michael Klier <chi@chimeric.de> 7 */ 8// must be run within DokuWiki 9if(!defined('DOKU_INC')) die(); 10if(!defined('DOKU_LF')) define('DOKU_LF', "\n"); 11 12// load language files 13require_once(DOKU_TPLINC.'lang/en/lang.php'); 14if(@file_exists(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php')) { 15 require_once(DOKU_TPLINC.'lang/'.$conf['lang'].'/lang.php'); 16} 17 18/** 19 * checks if a file called logo.png or logo.jpg exists 20 * and uses it as logo, uses the dokuwiki logo by default 21 * 22 * @author Michael Klier <chi@chimeric.de> 23 */ 24function tpl_logo() { 25 global $conf; 26 global $INFO; 27 28 $out = ''; 29 30 switch(true) { 31 case(@file_exists(DOKU_TPLINC.'images/logo.jpg')): 32 $logo = DOKU_TPL.'images/logo.jpg'; 33 break; 34 case(@file_exists(DOKU_TPLINC.'images/logo.jpeg')): 35 $logo = DOKU_TPL.'images/logo.jpeg'; 36 break; 37 case(@file_exists(DOKU_TPLINC.'images/logo.png')): 38 $logo = DOKU_TPL.'images/logo.png'; 39 break; 40 default: 41 $logo = DOKU_TPL.'images/dokuwiki-128.png'; 42 break; 43 } 44 $lang_specific_start_string = 'doku.php/' . $conf['lang'].':'.$conf['start']; 45 $out .= '<a href="' . DOKU_BASE . '" name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[ALT+H]">'; 46 $out .= ' <img class="logo" src="' . $logo . '" alt="' . $conf['title'] . '" /></a>' . DOKU_LF; 47 48 print ($out); 49} 50 51/** 52 * generates the sidebar contents 53 * 54 * @author Michael Klier <chi@chimeric.de> 55 */ 56function tpl_sidebar() { 57 global $lang; 58 global $ID; 59 global $INFO; 60 61 if(tpl_getConf('closedwiki') && empty($INFO['userinfo'])) { 62 print '<div id="toolbox" class="sidebar_box">' . DOKU_LF; 63 print '<h1>Toolbox</h1>' . DOKU_LF; 64 tpl_actionlink('login'); 65 print '</div>' . DOKU_LF; 66 return; 67 } 68 69 // main navigation 70 // print '<span class="sb_label">' . $lang['navigation'] . '</span>' . DOKU_LF; 71 print '<div id="navigation" class="sidebar_box">' . DOKU_LF; 72 print '<h1>' . $lang['Navigation'] . '</h1>' . DOKU_LF; 73 print '<hr style="text-align: left; width:90%; margin: -0.2ex 0 0.9ex 0;" />' . DOKU_LF; 74 $USER_INFO=$INFO['userinfo']; 75 $USER_NAME=$USER_INFO['name']; 76 $USER_STRING=str_replace(" ","_",strtolower($USER_NAME)); 77 $USER_HOME=DOKU_BASE . 'doku.php/en:user:' . $USER_NAME . ':' . $USER_NAME; 78 $URL_HELP=DOKU_BASE . 'doku.php/en:help:help'; 79 $URL_USERS=DOKU_BASE . 'doku.php/en:user:user'; 80 //$URL_BLOG=DOKU_BASE . 'doku.php/blog:blog'; 81 $doku_src = DOKU_TPL.'images/sidebar_logo.png'; 82 $user_src = DOKU_TPL.'images/user.gif'; 83 $users_src = DOKU_TPL.'images/sidebar_users.png'; 84 $blog_src = DOKU_TPL.'images/sidebar_blog.png'; 85 $help_src = DOKU_TPL.'images/sidebar_help.png'; 86 87 print '<a class="sidebar_nav_link" href="' . DOKU_BASE . '">'.DOKU_LF; 88 print ' <img style="vertical-align: middle;" src="' . $doku_src . '" />' . $lang['Doku Doodles'].DOKU_LF; 89 print '</a>'.DOKU_LF; 90 print '<br/>'.DOKU_LF; 91 $userhomepage_plugin = &plugin_load('action','userhomepage'); 92 if ( $userhomepage_plugin ) { 93 if ( plugin_isdisabled($userhomepage_plugin->getPluginName() ) ) { 94 $userhomepage_plugin == NULL; 95 } 96 97 } 98 if ( ( strlen($USER_NAME) != 0 ) && ( $userhomepage_plugin != NULL ) ) { 99 print '<a class="sidebar_nav_link" href="' . $USER_HOME . '">'.DOKU_LF; 100 //print ' <img style="vertical-align: middle;" src="' . $user_src . '" />' . $lang['${USER_NAME}']; 101 print ' <img style="vertical-align: middle;" src="' . $user_src . '" />' . $USER_NAME.DOKU_LF; 102 print '</a>'.DOKU_LF; 103 print '<br/>'.DOKU_LF; 104 print '<a class="sidebar_nav_link" href="' . $URL_USERS . '">'.DOKU_LF; 105 print ' <img style="vertical-align: middle;" src="' . $users_src . '" />' . $lang['Users'].DOKU_LF; 106 print '</a>'.DOKU_LF; 107 print '<br/>'.DOKU_LF; 108 } 109 //print '<a class="sidebar_nav_link" href="' . $URL_BLOG . '">'; 110 //print ' <img style="vertical-align: middle;" src="' . $blog_src . '" />' . $lang['Blog']; 111 //print '</a>'; 112 //print '<br/>'; 113 print '<a class="sidebar_nav_link" href="' . $URL_HELP . '">'.DOKU_LF; 114 print ' <img style="vertical-align: middle;" src="' . $help_src . '" />' . $lang['Help'].DOKU_LF; 115 print '</a>'.DOKU_LF; 116 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />' . DOKU_LF; 117 118 $svID = cleanID($ID); 119 $navpn = tpl_getConf('sb_pagename'); 120 121 // Get the user's custom navigation page. 122 123 124 if ( strlen($USER_NAME) != 0 ) { 125 $users_namespace = tpl_getConf('users_namespace'); 126 $user_navpn = $users_namespace.':'.$USER_STRING.':custom_' . $navpn; 127 $found = @file_exists(wikiFN($user_navpn)); 128 129 if($found && auth_quickaclcheck($user_navpn) >= AUTH_READ) { 130 print '<h1>' . $lang['bookmarks'] . '</h1>' . DOKU_LF; 131 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />' . DOKU_LF; 132 print p_dokubook_xhtml($user_navpn); 133 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />' . DOKU_LF; 134 } else { // make the page 135 $user_navpn_file = DOKU_INC.'data/pages/'.str_replace(":","/",$user_navpn).'.txt'; 136 $handle = fopen($user_navpn_file,'w'); 137 $content = ' * [['.$USER_STRING.'|Home Page]]'; 138 fwrite($handle,$content); 139 } 140 } 141 142 /************************************************************************** 143 * Check for the local language's navigation page 144 *************************************************************************/ 145 // Get the closest navigation page or else print the index. 146 147 // $svID is the current wiki page path + filename, e.g. 148 // programming:cpp:topics:bitwise 149 global $conf; 150 151 $path = explode(':',$svID); 152 array_pop($path); // remove the page name, just get the path 153 $found = false; 154 $sb = ''; 155 156 // Dont want to go all the way back, just to the iso_lang embedded ns 157 // as we consider these the 'root', hence below is > 1, not 0 158 while(!$found && count($path) > 1) { 159 $sb = implode(':', $path) . ':' . $navpn; 160 if(@file_exists(wikiFN($sb)) && auth_quickaclcheck($sb) >= AUTH_READ) { 161 print '<h1>' . $lang['localmap'] . '</h1>' . DOKU_LF; 162 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />'; 163 print p_dokubook_xhtml($sb); 164 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />'; 165 $found = true; 166 continue; 167 } else { 168 //print p_index_xhtml(cleanID($svID)); 169 } 170 //$found = @file_exists(wikiFN($sb)); 171 array_pop($path); 172 } 173 174 /************************************************************************** 175 * Check for the root language's navigation page 176 *************************************************************************/ 177 $la_navpn = $conf['lang'].":".$navpn; 178 $found = @file_exists(wikiFN($la_navpn)); 179 if ( $found ) { 180 $sb = $la_navpn; 181 } 182 /************************************************************************** 183 * If lang root failed, check for the default root navigation page 184 *************************************************************************/ 185 if ( !$found ) { 186 $found = @file_exists(wikiFN($navpn)); 187 if ( $found ) { 188 $sb = $navpn; 189 } 190 } 191 192 if(@file_exists(wikiFN($sb)) && auth_quickaclcheck($sb) >= AUTH_READ) { 193 print '<h1>' . $lang['globalmap'] . '</h1>' . DOKU_LF; 194 print '<hr style="text-align: left; width:90%; margin: 0.3ex 0 0.5ex 0;" />'; 195 print p_dokubook_xhtml($sb); 196 } else { 197 print p_index_xhtml(cleanID($svID)); 198 } 199 200 print '</div>' . DOKU_LF; 201 202 // generate the searchbox 203 //print '<span class="sb_label">' . strtolower($lang['btn_search']) . '</span>' . DOKU_LF; 204 //print '<div id="search">' . DOKU_LF; 205 //tpl_searchform(); 206 //print '</div>' . DOKU_LF; 207 208 // generate the toolbox 209 print '<div id="toolbox" class="sidebar_box">' . DOKU_LF; 210 print '<h1>' . $lang['Toolbox'] . '</h1>' . DOKU_LF; 211 print '<hr style="text-align: left; width:90%; margin: -0.2ex 0 0.9ex 0;" />'; 212 tpl_actionlink('admin'); 213 tpl_actionlink('index'); 214 tpl_actionlink('recent'); 215 tpl_actionlink('backlink'); 216 tpl_actionlink('profile'); 217 tpl_actionlink('login'); 218 print '</div>' . DOKU_LF; 219 220 // restore ID just in case 221 $Id = $svID; 222} 223 224/** 225 * prints a custom page footer 226 * 227 * @author Michael Klier <chi@chimeric.de> 228 */ 229function tpl_footer() { 230 global $ID; 231 232 $svID = $ID; 233 $ftpn = tpl_getConf('ft_pagename'); 234 $path = explode(':',$svID); 235 $found = false; 236 $ft = ''; 237 238 while(!$found && count($path) > 0) { 239 $ft = implode(':', $path) . ':' . $ftpn; 240 $found = @file_exists(wikiFN($ft)); 241 array_pop($path); 242 } 243 244 if(!$found && @file_exists(wikiFN($ftpn))) $ft = $ftpn; 245 246 if(@file_exists(wikiFN($ft)) && auth_quickaclcheck($ft) >= AUTH_READ) { 247 print '<div id="footer">' . DOKU_LF; 248 print p_dokubook_xhtml($ft); 249 print '</div>' . DOKU_LF; 250 } 251 252 // restore ID just in case 253 $ID = $svID; 254} 255 256/** 257 * removes the TOC of the sidebar-pages and shows 258 * a edit-button if user has enough rights 259 * 260 * @author Michael Klier <chi@chimeric.de> 261 */ 262function p_dokubook_xhtml($wp) { 263 if(auth_quickaclcheck($wp) >= AUTH_EDIT) { 264 $data = '<div class="sidebar-secedit">' . html_btn('secedit',$wp,'',array('do'=>'edit','rev'=>'','post')) . '</div>'; 265 } 266 $data .= p_wiki_xhtml($wp,'',false); 267 // strip TOC 268 $data = preg_replace('/<div class="toc">.*?(<\/div>\n<\/div>)/s', '', $data); 269 // replace headline ids for XHTML compliance 270 $data = preg_replace('/(<h.*?><a.*?id=")(.*?)(">.*?<\/a><\/h.*?>)/','\1sb_\2\3', $data); 271 return ($data); 272} 273 274/** 275 * Renders the Index 276 * 277 * copy of html_index located in /inc/html.php 278 * 279 * @author Andreas Gohr <andi@splitbrain.org> 280 * @author Michael Klier <chi@chimeric.de> 281 */ 282function p_index_xhtml($ns) { 283 require_once(DOKU_INC.'inc/search.php'); 284 global $conf; 285 global $ID; 286 $dir = $conf['datadir']; 287 $ns = cleanID($ns); 288 #fixme use appropriate function 289 if(empty($ns)){ 290 $ns = dirname(str_replace(':','/',$ID)); 291 if($ns == '.') $ns =''; 292 } 293 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 294 295 // only extract headline 296 preg_match('/<h1>.*?<\/h1>/', p_locale_xhtml('index'), $match); 297 print $match[0]; 298 299 $data = array(); 300 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 301 302 print '<div id="sb__index__tree">' . DOKU_LF; 303 print html_buildlist($data,'idx','html_list_index','html_li_index'); 304 print '</div>' . DOKU_LF; 305} 306 307// vim:ts=2:sw=2:enc=utf-8: 308