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 */
10
11// sidebar configuration settings
12$conf['sidebar']['enable'] = 1;               // 1 or true to enable sidebar functionality, 0 or false to disable it
13$conf['sidebar']['page'] = tpl_getConf('btl_sidebar_name');         // name of sidebar page
14$conf['sidebar']['layout'] = 'inside';        // inside (between button bars) or outside (full height of dokuwiki)
15$conf['sidebar']['orientation'] = 'right';     // left or right
16
17// determine the sidebar class
18$sidebar_class = "sidebar_{$conf['sidebar']['layout']}_{$conf['sidebar']['orientation']}";
19
20// recursive function to establish best sidebar file to be used
21function getSidebarFN($ns, $file) {
22
23	// check for wiki page = $ns:$file (or $file where no namespace)
24	$nsFile = ($ns) ? "$ns:$file" : $file;
25	if (file_exists(wikiFN($nsFile)) && auth_quickaclcheck($nsFile)) return $nsFile;
26
27// remove deepest namespace level and call function recursively
28
29	// no namespace left, exit with no file found
30	if (!$ns) return '';
31
32	$i = strrpos($ns, ":");
33	$ns = ($i) ? substr($ns, 0, $i) : false;
34	return getSidebarFN($ns, $file);
35}
36
37// display the sidebar
38function tpl_sidebar() {
39	global $ID, $REV, $conf;
40
41	// save globals
42	$saveID = $ID;
43	$saveREV = $REV;
44
45	// discover file to be displayed in navigation sidebar
46	$fileSidebar = '';
47
48	if (isset($conf['sidebar']['page'])) {
49		$fileSidebar = getSidebarFN(getNS($ID), $conf['sidebar']['page']);
50	}
51
52	// determine what to display
53	if ($fileSidebar) {
54		$ID = $fileSidebar;
55		$REV = '';
56		print p_wiki_xhtml($ID,$REV,false);
57	}
58	else {
59        global $IDX;
60        html_index($IDX);
61	}
62
63	// restore globals
64	$ID = $saveID;
65	$REV = $saveREV;
66}
67
68if (!function_exists('tpl_pagename')) {
69
70	require_once(DOKU_INC.'inc/parserutils.php');
71
72    /**
73     * Returns the name of the given page (current one if none given).
74     *
75     * If useheading is enabled this will use the first headline else
76     * the given ID is printed.
77     *
78     * based on tpl_pagetitle in inc/template.php
79     */
80    function tpl_pagename($id=null){
81      global $conf;
82      if(is_null($id)){
83        global $ID;
84        $id = $ID;
85      }
86
87      $name = $id;
88      if ($conf['useheading']) {
89        $title = p_get_first_heading($id);
90        if ($title) $name = $title;
91      }
92      return hsc($name);
93    }
94
95}
96
97?>
98