1<?php 2/** 3 * DokuWiki Template Arctic Functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Michael Klier <chi@chimeric.de> 7 */ 8 9// must be run from within DokuWiki 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_LF')) define('DOKU_LF',"\n"); 12 13// load sidebar contents 14$sbl = explode(',',tpl_getConf('left_sidebar_content')); 15$sbr = explode(',',tpl_getConf('right_sidebar_content')); 16$sbpos = tpl_getConf('sidebar'); 17 18// set notoc option and toolbar regarding the sitebar setup 19switch($sbpos) { 20 case 'both': 21 $notoc = (in_array('toc',$sbl) || in_array('toc',$sbr)) ? true : false; 22 $toolb = (in_array('toolbox',$sbl) || in_array('toolbox',$sbr)) ? true : false; 23 break; 24 case 'left': 25 $notoc = (in_array('toc',$sbl)) ? true : false; 26 $toolb = (in_array('toolbox',$sbl)) ? true : false; 27 break; 28 case 'right': 29 $notoc = (in_array('toc',$sbr)) ? true : false; 30 $toolb = (in_array('toolbox',$sbr)) ? true : false; 31 break; 32 case 'none': 33 $notoc = false; 34 $toolb = false; 35 break; 36} 37 38/** 39 * Prints the sidebars 40 * 41 * @author Michael Klier <chi@chimeric.de> 42 */ 43function tpl_sidebar($pos) { 44 45 $sb_order = ($pos == 'left') ? explode(',', tpl_getConf('left_sidebar_order')) : explode(',', tpl_getConf('right_sidebar_order')); 46 $sb_content = ($pos == 'left') ? explode(',', tpl_getConf('left_sidebar_content')) : explode(',', tpl_getConf('right_sidebar_content')); 47 48 // process contents by given order 49 foreach($sb_order as $sb) { 50 if(in_array($sb,$sb_content)) { 51 $key = array_search($sb,$sb_content); 52 unset($sb_content[$key]); 53 tpl_sidebar_dispatch($sb,$pos); 54 } 55 } 56 57 // check for left content not specified by order 58 if(is_array($sb_content) && !empty($sb_content) > 0) { 59 foreach($sb_content as $sb) { 60 tpl_sidebar_dispatch($sb,$pos); 61 } 62 } 63} 64 65/** 66 * Dispatches the given sidebar type to return the right content 67 * 68 * @author Michael Klier <chi@chimeric.de> 69 */ 70function tpl_sidebar_dispatch($sb,$pos) { 71 global $lang; 72 global $conf; 73 global $ID; 74 global $REV; 75 global $INFO; 76 global $TOC; 77 78 $svID = $ID; // save current ID 79 $svREV = $REV; // save current REV 80 $svTOC = $TOC; // save current TOC 81 82 $pname = tpl_getConf('pagename'); 83 84 switch($sb) { 85 86 case 'main': 87 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 88 $main_sb = $pname; 89 90//translating the main sidebar 91 $translation = &plugin_load('helper','translation'); 92 if ($translation) { 93 $curlc = $translation->getLangPart($ID); 94 list($lc,$idpart) = $translation->getTransParts($main_sb); 95 list($main_sb,$name) = $translation->buildTransID($curlc,$idpart); 96 if(substr($main_sb,0,1)==":") $main_sb=substr($main_sb,1); 97 } 98 99 if(@page_exists($main_sb) && auth_quickaclcheck($main_sb) >= AUTH_READ) { 100 $always = tpl_getConf('main_sidebar_always'); 101 if($always or (!$always && !getNS($ID))) { 102 print '<div class="main_sidebar sidebar_box">' . DOKU_LF; 103 print p_sidebar_xhtml($main_sb,$pos) . DOKU_LF; 104 print '</div>' . DOKU_LF; 105 } 106 } elseif(!@page_exists($main_sb) && auth_quickaclcheck($main_sb) >= AUTH_CREATE) { 107 if(@file_exists(DOKU_TPLINC.'lang/'. $conf['lang'].'/nosidebar.txt')) { 108 $out = p_render('xhtml', p_get_instructions(io_readFile(DOKU_TPLINC.'lang/'.$conf['lang'].'/nosidebar.txt')), $info); 109 } else { 110 $out = p_render('xhtml', p_get_instructions(io_readFile(DOKU_TPLINC.'lang/en/nosidebar.txt')), $info); 111 } 112 $link = '<a href="' . wl($pname) . '" class="wikilink2">' . $pname . '</a>' . DOKU_LF; 113 print '<div class="main_sidebar sidebar_box">' . DOKU_LF; 114 print str_replace('LINK', $link, $out); 115 print '</div>' . DOKU_LF; 116 } 117 break; 118 119 case 'namespace': 120 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 121 $user_ns = tpl_getConf('user_sidebar_namespace'); 122 $group_ns = tpl_getConf('group_sidebar_namespace'); 123 if(!preg_match("/^".$user_ns.":.*?$|^".$group_ns.":.*?$/", $svID)) { // skip group/user sidebars and current ID 124 $ns_sb = _getNsSb($svID); 125 if($ns_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { 126 print '<div class="namespace_sidebar sidebar_box">' . DOKU_LF; 127 print p_sidebar_xhtml($ns_sb,$pos) . DOKU_LF; 128 print '</div>' . DOKU_LF; 129 } 130 } 131 break; 132 133 case 'user': 134 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 135 $user_ns = tpl_getConf('user_sidebar_namespace'); 136 if(isset($INFO['userinfo']['name'])) { 137 $user = $_SERVER['REMOTE_USER']; 138 $user_sb = $user_ns . ':' . $user . ':' . $pname; 139 if(@page_exists($user_sb)) { 140 $subst = array('pattern' => array('/@USER@/'), 'replace' => array($user)); 141 print '<div class="user_sidebar sidebar_box">' . DOKU_LF; 142 print p_sidebar_xhtml($user_sb,$pos,$subst) . DOKU_LF; 143 print '</div>'; 144 } 145 // check for namespace sidebars in user namespace too 146 if(preg_match('/'.$user_ns.':'.$user.':.*/', $svID)) { 147 $ns_sb = _getNsSb($svID); 148 if($ns_sb && $ns_sb != $user_sb && auth_quickaclcheck($ns_sb) >= AUTH_READ) { 149 print '<div class="namespace_sidebar sidebar_box">' . DOKU_LF; 150 print p_sidebar_xhtml($ns_sb,$pos) . DOKU_LF; 151 print '</div>' . DOKU_LF; 152 } 153 } 154 155 } 156 break; 157 158 case 'group': 159 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 160 $group_ns = tpl_getConf('group_sidebar_namespace'); 161 if(isset($INFO['userinfo']['name'], $INFO['userinfo']['grps'])) { 162 foreach($INFO['userinfo']['grps'] as $grp) { 163 $group_sb = $group_ns.':'.$grp.':'.$pname; 164 if(@page_exists($group_sb) && auth_quickaclcheck(cleanID($group_sb)) >= AUTH_READ) { 165 $subst = array('pattern' => array('/@GROUP@/'), 'replace' => array($grp)); 166 print '<div class="group_sidebar sidebar_box">' . DOKU_LF; 167 print p_sidebar_xhtml($group_sb,$pos,$subst) . DOKU_LF; 168 print '</div>' . DOKU_LF; 169 } 170 } 171 } 172 break; 173 174 case 'index': 175 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 176 print '<div class="index_sidebar sidebar_box">' . DOKU_LF; 177// print ' ' . p_index_xhtml($svID,$pos) . DOKU_LF; 178 mbo_html_index($ID); 179 print '</div>' . DOKU_LF; 180 break; 181 182 case 'toc': 183 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 184 if(auth_quickaclcheck($svID) >= AUTH_READ) { 185 $toc = tpl_toc(true); 186 // replace ids to keep XHTML compliance 187 if(!empty($toc)) { 188// $toc = preg_replace('/id="(.*?)"/', 'id="sb__' . $pos . '__\1"', $toc); 189 print '<div class="toc_sidebar sidebar_box">' . DOKU_LF; 190 print ($toc); 191 print '</div>' . DOKU_LF; 192 } 193 } 194 break; 195 196 case 'toolbox': 197 198 if(tpl_getConf('hideactions') && !isset($_SERVER['REMOTE_USER'])) return; 199 200 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) { 201 print '<div class="toolbox_sidebar sidebar_box">' . DOKU_LF; 202 print ' <div class="level1">' . DOKU_LF; 203 print ' <ul>' . DOKU_LF; 204 print ' <li><div class="li">'; 205 tpl_actionlink('login'); 206 print ' </div></li>' . DOKU_LF; 207 print ' </ul>' . DOKU_LF; 208 print ' </div>' . DOKU_LF; 209 print '</div>' . DOKU_LF; 210 } else { 211 $actions = array('admin', 212 'revert', 213 'edit', 214 'history', 215 'recent', 216 'backlink', 217 'subscription', 218 'index', 219 'login', 220 'profile', 221 'top'); 222 223 print '<div class="toolbox_sidebar sidebar_box">' . DOKU_LF; 224 print ' <div class="level1">' . DOKU_LF; 225 print ' <ul>' . DOKU_LF; 226 227 foreach($actions as $action) { 228 if(!actionOK($action)) continue; 229 // start output buffering 230 if($action == 'edit') { 231 // check if new page button plugin is available 232 if(!plugin_isdisabled('npd') && ($npd =& plugin_load('helper', 'npd'))) { 233 $npb = $npd->html_new_page_button(true); 234 if($npb) { 235 print ' <li><div class="li">'; 236 print $npb; 237 print '</div></li>' . DOKU_LF; 238 } 239 } 240 } 241 ob_start(); 242 print ' <li><div class="li">'; 243 if(tpl_actionlink($action)) { 244 print '</div></li>' . DOKU_LF; 245 ob_end_flush(); 246 } else { 247 ob_end_clean(); 248 } 249 } 250 251 print ' </ul>' . DOKU_LF; 252 print ' </div>' . DOKU_LF; 253 print '</div>' . DOKU_LF; 254 } 255 256 break; 257 258 case 'trace': 259 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 260 print '<div class="trace_sidebar sidebar_box">' . DOKU_LF; 261 print ' <h1>'.$lang['breadcrumb'].'</h1>' . DOKU_LF; 262 print ' <div class="breadcrumbs">' . DOKU_LF; 263 ($conf['youarehere'] != 1) ? tpl_breadcrumbs() : tpl_youarehere(); 264 print ' </div>' . DOKU_LF; 265 print '</div>' . DOKU_LF; 266 break; 267 268 case 'extra': 269 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 270 print '<div class="extra_sidebar sidebar_box">' . DOKU_LF; 271 @include(dirname(__FILE__).'/' . $pos .'_sidebar.html'); 272 print '</div>' . DOKU_LF; 273 break; 274 275 default: 276 if(tpl_getConf('closedwiki') && !isset($_SERVER['REMOTE_USER'])) return; 277 // check for user defined sidebars 278 if(@file_exists(DOKU_TPLINC.'sidebars/'.$sb.'/sidebar.php')) { 279 print '<div class="'.$sb.'_sidebar sidebar_box">' . DOKU_LF; 280 @require_once(DOKU_TPLINC.'sidebars/'.$sb.'/sidebar.php'); 281 print '</div>' . DOKU_LF; 282 } 283 break; 284 } 285 286 // restore ID, REV and TOC 287 $ID = $svID; 288 $REV = $svREV; 289 $TOC = $svTOC; 290} 291 292/** 293 * Removes the TOC of the sidebar pages and 294 * shows a edit button if the user has enough rights 295 * 296 * TODO sidebar caching 297 * 298 * @author Michael Klier <chi@chimeric.de> 299 */ 300function p_sidebar_xhtml($sb,$pos,$subst=array()) { 301 $data = p_wiki_xhtml($sb,'',false); 302 if(!empty($subst)) { 303 $data = preg_replace($subst['pattern'], $subst['replace'], $data); 304 } 305 if(auth_quickaclcheck($sb) >= AUTH_EDIT) { 306 $data .= '<div class="secedit">'.html_btn('secedit',$sb,'',array('do'=>'edit','rev'=>'','post')).'</div>'; 307 } 308 // strip TOC 309 $data = preg_replace('/<div class="toc">.*?(<\/div>\n<\/div>)/s', '', $data); 310 // replace headline ids for XHTML compliance 311 $data = preg_replace('/(<h.*?><a.*?name=")(.*?)(".*?id=")(.*?)(">.*?<\/a><\/h.*?>)/','\1sb_'.$pos.'_\2\3sb_'.$pos.'_\4\5', $data); 312 return ($data); 313} 314 315/** 316 * Renders the Index 317 * 318 * copy of html_index located in /inc/html.php 319 * updated to the new index 320 * 321 * @author Matthieu Bouthors <matthieu@bouthors.fr> 322 */ 323 324function mbo_html_index($ns){ 325 global $conf; 326 global $ID; 327 $dir = $conf['datadir']; 328 $ns = cleanID($ns); 329 #fixme use appropriate function 330 if(empty($ns)){ 331 $ns = dirname(str_replace(':','/',$ID)); 332 if($ns == '.') $ns =''; 333 } 334 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 335 336// echo p_locale_xhtml('index'); 337 echo '<h1>Index</h1>'; 338 echo '<div id="index__tree">'; 339 340 $data = array(); 341 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 342 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 343 344 echo '</div>'; 345} 346 347 348/** 349 * searches for namespace sidebars 350 * 351 * @author Michael Klier <chi@chimeric.de> 352 */ 353function _getNsSb($id) { 354 $pname = tpl_getConf('pagename'); 355 $ns_sb = ''; 356 $path = explode(':', $id); 357 $found = false; 358 array_pop($path); //remove the page from the path 359 $min_path_depth=0; 360//load translation plugin 361 $translation = &plugin_load('helper','translation'); 362 if ($translation) { 363//if it's a translated page, we need to increase depth to exlude the namespace sidebar 364 $curlc = $translation->getLangPart($id); 365 if ($curlc) $min_path_depth=1; 366 } 367 368 while(count($path) > $min_path_depth) { 369 $ns_sb = implode(':', $path).':'.$pname; 370 if(@page_exists($ns_sb)) return $ns_sb; 371 array_pop($path); 372 } 373 374 // nothing found 375 return false; 376} 377 378/** 379 * Checks wether the sidebar should be hidden or not 380 * 381 * @author Michael Klier <chi@chimeric.de> 382 */ 383function tpl_sidebar_hide() { 384 global $ACT; 385// $act_hide = array( 'edit', 'preview', 'admin', 'conflict', 'draft', 'recover'); 386 $act_hide = explode(',',tpl_getConf('hidesidebar')); 387 if(in_array($ACT, $act_hide)) { 388 return true; 389 } else { 390 return false; 391 } 392} 393 394// vim:ts=4:sw=4:et:enc=utf-8: 395 396 397function tpl_arctic_mbo_pagename($sep=' » '){ 398 global $conf; 399 global $ID; 400 global $lang; 401 402 $parts = explode(':', $ID); 403 $count = count($parts); 404 405 if($GLOBALS['ACT'] == 'search') 406 { 407 $parts = array($conf['start']); 408 $count = 1; 409 } 410 411 // always print the site title 412 tpl_link(wl(),$conf['title'],'name="dokuwiki__top" id="dokuwiki__top" title="'.$conf['start'].'"'); 413 414 // print intermediate namespace links 415 $part = ''; 416 for($i=0; $i<$count - 1; $i++){ 417 $part .= $parts[$i].':'; 418 $page = $part; 419 resolve_pageid('',$page,$exists); 420 if ($page == $conf['start']) continue; // Skip startpage 421 422 // output 423 echo $sep; 424 if($exists && (auth_quickaclcheck($page) >= AUTH_READ)){ 425 $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; 426 tpl_link(wl($page),hsc($title),'title="'.$page.'"'); 427 }else{ 428 tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); 429 } 430 } 431 432 // print current page, skipping start page, skipping for namespace index 433 if(isset($page) && $page==$part.$parts[$i]) return; 434 $page = $part.$parts[$i]; 435 if($page == $conf['start']) return; 436 echo $sep; 437 if(page_exists($page) && (auth_quickaclcheck($page) >= AUTH_READ)){ 438 $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; 439 tpl_link(wl($page),hsc($title),'title="'.$page.'"'); 440 }else{ 441 tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); 442 } 443 return true; 444} 445 446 447?> 448