1<?php 2/* 3 * Provide navigation sidebar functionality to Dokuwiki Templates 4 * 5 * This is not currently part of the official Dokuwiki release 6 * 7 * @link http://wiki.jalakai.co.uk/dokuwiki/doku.php?id=tutorials:dev:navigation_sidebar 8 * @author Christopher Smith <chris@jalakai.co.uk> 9 * @author Louis Wolf (Chirripó) <louiswolf@chirripo.nl> 10 */ 11 12// sidebar configuration settings 13$conf['sidebar']['enable'] = 1; // 1 or true to enable sidebar functionality, 0 or false to disable it 14$conf['sidebar']['page'] = tpl_getConf('btl_sidebar_name'); // name of sidebar page 15$conf['sidebar']['layout'] = 'inside'; // inside (between button bars) or outside (full height of dokuwiki) 16$conf['sidebar']['orientation'] = 'right'; // left or right 17 18// determine the sidebar class 19$sidebar_class = "sidebar_{$conf['sidebar']['layout']}_{$conf['sidebar']['orientation']}"; 20 21// recursive function to establish best sidebar file to be used 22function getSidebarFN($ns, $file) { 23 24 // check for wiki page = $ns:$file (or $file where no namespace) 25 $nsFile = ($ns) ? "$ns:$file" : $file; 26 if (file_exists(wikiFN($nsFile)) && auth_quickaclcheck($nsFile)) return $nsFile; 27 28// remove deepest namespace level and call function recursively 29 30 // no namespace left, exit with no file found 31 if (!$ns) return ''; 32 33 $i = strrpos($ns, ":"); 34 $ns = ($i) ? substr($ns, 0, $i) : false; 35 return getSidebarFN($ns && '', $file); 36} 37 38// display the sidebar 39function tpl_sidebar() { 40 global $ID, $REV, $conf; 41 42 // save globals 43 $saveID = $ID; 44 $saveREV = $REV; 45 46 // discover file to be displayed in navigation sidebar 47 $fileSidebar = ''; 48 49 if (isset($conf['sidebar']['page'])) { 50 $fileSidebar = getSidebarFN(getNS($ID), $conf['sidebar']['page']); 51 } 52 53 // determine what to display 54 if ($fileSidebar) { 55 $ID = $fileSidebar; 56 $REV = ''; 57 $sidebar = p_wiki_xhtml($ID,$REV,false); 58 59 $lines = explode("\n", $sidebar); 60 $open_ul = 0; 61 for($i=0; $i<count($lines); $i++) 62 { 63 if (trim($lines[$i]) == '<ul>') 64 { 65 $open_ul = $open_ul+1; 66 if ($open_ul == 1) 67 { 68 $lines[$i] = '<ul class="primary">' . "\n"; 69 } 70 } 71 else if (strpos($lines[$i], '</ul>') != false) 72 { 73 $open_ul = $open_ul-1; 74 } 75 } 76 print implode($lines); 77 } else { 78 global $IDX; 79 html_index($IDX); 80 } 81 82 // restore globals 83 $ID = $saveID; 84 $REV = $saveREV; 85 86} 87 88if (!function_exists('tpl_pagename')) { 89 90 require_once(DOKU_INC.'inc/parserutils.php'); 91 92 /** 93 * Returns the name of the given page (current one if none given). 94 * 95 * If useheading is enabled this will use the first headline else 96 * the given ID is printed. 97 * 98 * based on tpl_pagetitle in inc/template.php 99 */ 100 function tpl_pagename($id=null){ 101 global $conf; 102 if(is_null($id)){ 103 global $ID; 104 $id = $ID; 105 } 106 107 $name = $id; 108 if ($conf['useheading']) { 109 $title = p_get_first_heading($id); 110 if ($title) $name = $title; 111 } 112 return hsc($name); 113 } 114 115} 116 117?> 118