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 * @author Christopher Smith <chris@jalakai.co.uk>
8 * @author Don Bowman <don@lynsoft.co.uk>
9 */
10
11/******  sidebar configuration settings  ******/
12  tpl_loadConfig();
13
14/******  determine the sidebar class  ******/
15  $sidebar_class =
16      "sidebar sidebar_".tpl_getConf('layout').'_'.tpl_getConf('orientation');
17
18
19/*
20 * recursive function to establish best sidebar file to be used
21 */
22function getSidebarFN($ns, $file) {//func
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))
27    return $nsFile;
28
29/******  no namespace left, exit with no file found  ******/
30  if (!$ns)
31    return '';
32
33/******  remove deepest namespace level and call function recursively  ******/
34  $i = strrpos($ns, ":");
35  $ns = ($i) ? substr($ns, 0, $i) : false;
36  return getSidebarFN($ns, $file);
37
38  }//function getSidebarFN($ns, $file)
39
40
41/*
42 * print a sidebar edit button - if appropriate
43 */
44function tpl_sidebar_editbtn() {//func
45
46/******  declare global variables  ******/
47  global $ID, $conf, $lang;
48
49/******  check if button wanted  ******/
50  if (!tpl_getConf('rb_showeditbtn'))
51    return;
52
53/******  check if sidebar page exists  ******/
54  $fileSidebar = getSidebarFN(getNS($ID), 'sidebar');
55  if (!$fileSidebar)
56    return;
57
58/******  check if user has edit permission for the sidebar page  ******/
59  if (auth_quickaclcheck($fileSidebar) < AUTH_EDIT)
60    return;
61
62/******  generate button  ******/
63  ?>
64    <div class="secedit">
65      <form class="button" method="post" action="<?php echo wl($fileSidebar,'do=edit'); ?>"
66          onsubmit="return svchk()">
67        <input type="hidden" name="do" value="edit" />
68        <input type="hidden" name="rev" value="" />
69        <input type="hidden" name="id" value="<?php echo $fileSidebar; ?>" />
70        <input type="submit" value="<?php echo $lang['btn_sidebaredit']; ?>" class="button" />
71      </form>
72    </div>
73  <?php
74
75  }//function tpl_sidebar_editbtn()
76
77
78/*
79 * display the sidebar
80 */
81function tpl_sidebar_content() {//func
82
83/******  declare global variables  ******/
84  global $ID, $REV, $ACT, $conf;
85
86/******  save global variables  ******/
87  $saveID = $ID;
88  $saveREV = $REV;
89  $saveACT = $ACT;
90
91/******  find file to be displayed in navigation sidebar  ******/
92  $fileSidebar = '';
93  $fileSidebar = getSidebarFN(getNS($ID), 'sidebar');
94
95/******  show main sidebar if necessary  ******/
96  if (tpl_getConf('rb_main_sidebar')  &&
97      $fileSidebar != 'sidebar'       &&
98      file_exists(wikiFN('sidebar'))) {//do
99    $ID = 'sidebar';
100    $REV = '';
101    $ACT = 'show';
102    tpl_content(false);
103    if (tpl_getConf('rb_showeditbtn')) {//do
104      tpl_sidebar_editbtn();
105      echo "<br>";
106      }//if (tpl_getConf('rb_showeditbtn'))
107    echo "<hr>";
108    }//if (tpl_getConf('rb_main_sidebar')  && ...
109
110/******  show current sidebar  ******/
111  if ($fileSidebar) {//do
112    $ID = $fileSidebar;
113    $REV = '';
114    $ACT = 'show';
115    tpl_content(false);
116    if (tpl_getConf('rb_showeditbtn'))
117      tpl_sidebar_editbtn();
118    }//if ($fileSidebar)
119
120/******  show index  ******/
121  else {//if (!$fileSidebar)
122    $REV = '';
123    $ACT = 'index';
124    tpl_content(false);
125    }//if (!$fileSidebar)
126
127/******  restore global variables  ******/
128  $ID = $saveID;
129  $REV = $saveREV;
130  $ACT = $saveACT;
131
132  }//function tpl_sidebar_content()
133