1<?php 2/** 3 * DokuWiki Template DoKubrick Functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Michael Klier <chi@chimeric.de> 7 */ 8 9if(!defined('DOKU_LF')) define('DOKU_LF',"\n"); 10 11// load sidebar contents 12$sbl = explode(',',tpl_getConf('sidebar_content')); 13 14/** 15 * Prints the sidebars 16 * 17 * @author Michael Klier <chi@chimeric.de> 18 */ 19function tpl_sidebar() { 20 21 $sb_order = explode(',', tpl_getConf('sidebar_order')); 22 $sb_content = explode(',', tpl_getConf('sidebar_content')); 23 24 // add toolbox and toc to sidebar contents 25 array_push($sb_content, 'toolbox'); 26 27 // process contents by given order 28 foreach($sb_order as $sb) { 29 if(in_array($sb,$sb_content)) { 30 $key = array_search($sb,$sb_content); 31 unset($sb_content[$key]); 32 tpl_sidebar_dispatch($sb); 33 } 34 } 35 36 // check for left content not specified by order 37 if(is_array($sb_content) && !empty($sb_content) > 0) { 38 foreach($sb_content as $sb) { 39 tpl_sidebar_dispatch($sb); 40 } 41 } 42} 43 44/** 45 * Dispatches the given sidebar type to return the right content 46 * 47 * @author Michael Klier <chi@chimeric.de> 48 */ 49function tpl_sidebar_dispatch($sb) { 50 global $lang; 51 global $conf; 52 global $ID; 53 global $REV; 54 global $INFO; 55 56 $svID = $ID; // save current ID 57 $svREV = $REV; // save current REV 58 59 $pname = tpl_getConf('pagename'); 60 61 switch($sb) { 62 63 case 'main': 64 $main_sb = $pname; 65 if(@file_exists(wikiFN($main_sb)) && auth_quickaclcheck($main_sb) >= AUTH_READ) { 66 print '<div class="main_sidebar sidebar_box">' . DOKU_LF; 67 print p_sidebar_xhtml($main_sb) . DOKU_LF; 68 print '</div>' . DOKU_LF; 69 } 70 break; 71 72 case 'namespace': 73 $user_ns = tpl_getConf('user_sidebar_namespace'); 74 $group_ns = tpl_getConf('group_sidebar_namespace'); 75 if(!preg_match("/^".$user_ns.":.*?$|^".$group_ns.":.*?$/", $svID)) { // skip group/user sidebars and current ID 76 $ns_sb = _getNsSb($svID); 77 if($ns_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { 78 print '<div class="namespace_sidebar sidebar_box">' . DOKU_LF; 79 print p_sidebar_xhtml($ns_sb) . DOKU_LF; 80 print '</div>' . DOKU_LF; 81 } 82 } 83 break; 84 85 case 'user': 86 $user_ns = tpl_getConf('user_sidebar_namespace'); 87 if(isset($INFO['userinfo']['name'])) { 88 $user = $_SERVER['REMOTE_USER']; 89 $user_sb = $user_ns . ':' . $user . ':' . $pname; 90 if(@file_exists(wikiFN($user_sb))) { 91 print '<div class="user_sidebar sidebar_box">' . DOKU_LF; 92 print p_sidebar_xhtml($user_sb) . DOKU_LF; 93 print '</div>'; 94 } 95 // check for namespace sidebars in user namespace too 96 if(preg_match('/'.$user_ns.':'.$user.':.*/', $svID)) { 97 $ns_sb = _getNsSb($svID); 98 if($ns_sb && $ns_sb != $user_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { 99 print '<div class="namespace_sidebar sidebar_box">' . DOKU_LF; 100 print p_sidebar_xhtml($ns_sb) . DOKU_LF; 101 print '</div>' . DOKU_LF; 102 } 103 } 104 105 } 106 break; 107 108 case 'group': 109 $group_ns = tpl_getConf('group_sidebar_namespace'); 110 if(isset($INFO['userinfo']['name'], $INFO['userinfo']['grps'])) { 111 foreach($INFO['userinfo']['grps'] as $grp) { 112 $group_sb = $group_ns.':'.$grp.':'.$pname; 113 if(@file_exists(wikiFN($group_sb)) && auth_quickaclcheck($group_sb) >= AUTH_READ) { 114 print '<div class="group_sidebar sidebar_box">' . DOKU_LF; 115 print p_sidebar_xhtml($group_sb) . DOKU_LF; 116 print '</div>' . DOKU_LF; 117 } 118 } 119 } 120 break; 121 122 case 'index': 123 print '<div class="index_sidebar sidebar_box">' . DOKU_LF; 124 print ' ' . p_index_xhtml($svID) . DOKU_LF; 125 print '</div>' . DOKU_LF; 126 break; 127 128 case 'toc': 129 if(auth_quickaclcheck($svID) >= AUTH_READ) { 130 $toc = tpl_toc(true); 131 // replace ids to keep XHTML compliance 132 if(!empty($toc)) { 133 $toc = preg_replace('/id="(.*?)"/', 'id="sb__\1"', $toc); 134 print '<div class="toc_sidebar sidebar_box">' . DOKU_LF; 135 print ($toc); 136 print '</div>' . DOKU_LF; 137 } 138 } 139 break; 140 141 case 'toolbox': 142 $actions = array('admin', 'edit', 'history', 'recent', 'backlink', 'subscription', 'index', 'login', 'profile'); 143 144 print '<div class="toolbox_sidebar sidebar_box">' . DOKU_LF; 145 print ' <div class="level1">' . DOKU_LF; 146 print ' <ul>' . DOKU_LF; 147 148 foreach($actions as $action) { 149 if($action == 'edit') { 150 // check if new page button plugin is available 151 if(!plugin_isdisabled('npd') && ($npd =& plugin_load('helper', 'npd'))) { 152 $npb = $npd->html_new_page_button(true); 153 if($npb) { 154 print ' <li><div class="li">'; 155 print $npb; 156 print '</div></li>' . DOKU_LF; 157 } 158 } 159 } 160 if(!actionOK($action)) continue; 161 ob_start(); 162 print ' <li><div class="li">'; 163 if(tpl_actionlink($action)) { 164 ob_end_flush(); 165 print ' </div></li>' . DOKU_LF; 166 } else { 167 ob_end_clean(); 168 } 169 } 170 171 print ' </ul>' . DOKU_LF; 172 print ' </div>' . DOKU_LF; 173 print '</div>' . DOKU_LF; 174 break; 175 176 case 'trace': 177 print '<div class="trace_sidebar sidebar_box">' . DOKU_LF; 178 print ' <h1>'.$lang['breadcrumb'].'</h1>' . DOKU_LF; 179 print ' <div class="breadcrumbs">' . DOKU_LF; 180 ($conf['youarehere'] != 1) ? tpl_breadcrumbs() : tpl_youarehere(); 181 print ' </div>' . DOKU_LF; 182 print '</div>' . DOKU_LF; 183 break; 184 185 case 'extra': 186 print '<div class="extra_sidebar sidebar_box">' . DOKU_LF; 187 @include(dirname(__FILE__).'/sidebar.html'); 188 print '</div>' . DOKU_LF; 189 break; 190 191 default: 192 // check for user defined sidebars 193 if(@file_exists(DOKU_TPLINC.'sidebars/'.$sb.'/sidebar.php')) { 194 print '<div class="'.$sb.'_sidebar sidebar_box">' . DOKU_LF; 195 @require_once(DOKU_TPLINC.'sidebars/'.$sb.'/sidebar.php'); 196 print '</div>' . DOKU_LF; 197 } 198 break; 199 } 200 201 // restore ID and REV 202 $ID = $svID; 203 $REV = $svREV; 204} 205 206/** 207 * Removes the TOC of the sidebar pages and 208 * shows a edit button if the user has enough rights 209 * 210 * @author Michael Klier <chi@chimeric.de> 211 */ 212function p_sidebar_xhtml($sb) { 213 $data = p_wiki_xhtml($sb,'',false); 214 if(auth_quickaclcheck($sb) >= AUTH_EDIT) { 215 $data .= '<div class="secedit">'.html_btn('secedit',$sb,'',array('do'=>'edit','rev'=>'','post')).'</div>'; 216 } 217 // strip TOC 218 $data = preg_replace('/<div class="toc">.*?(<\/div>\n<\/div>)/s', '', $data); 219 // replace headline ids for XHTML compliance 220 $data = preg_replace('/(<h.*?><a.*?name=")(.*?)(".*?id=")(.*?)(">.*?<\/a><\/h.*?>)/','\1sb_\2\3sb_\4\5', $data); 221 return ($data); 222} 223 224/** 225 * Renders the Index 226 * 227 * copy of html_index located in /inc/html.php 228 * 229 * @author Andreas Gohr <andi@splitbrain.org> 230 * @author Michael Klier <chi@chimeric.de> 231 */ 232function p_index_xhtml($ns) { 233 require_once(DOKU_INC.'inc/search.php'); 234 global $conf; 235 global $ID; 236 $dir = $conf['datadir']; 237 $ns = cleanID($ns); 238 #fixme use appropriate function 239 if(empty($ns)){ 240 $ns = dirname(str_replace(':','/',$ID)); 241 if($ns == '.') $ns =''; 242 } 243 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 244 245 // only extract headline 246 preg_match('/<h1>.*?<\/h1>/', p_locale_xhtml('index'), $match); 247 print $match[0]; 248 249 $data = array(); 250 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 251 252 print '<div id="sb__index__tree">' . DOKU_LF; 253 print html_buildlist($data,'idx','html_list_index','html_li_index'); 254 print '</div>' . DOKU_LF; 255} 256 257/** 258 * searches for namespace sidebars 259 * 260 * @author Michael Klier <chi@chimeric.de> 261 */ 262function _getNsSb($id) { 263 $pname = tpl_getConf('pagename'); 264 $ns_sb = ''; 265 $path = explode(':', $id); 266 $found = false; 267 268 while(count($path) > 0) { 269 $ns_sb = implode(':', $path).':'.$pname; 270 if(@file_exists(wikiFN($ns_sb))) return $ns_sb; 271 array_pop($path); 272 } 273 274 // nothing found 275 return false; 276} 277 278//Setup vim: ts=4 sw=4: 279?> 280