aboutsummaryrefslogtreecommitdiff
path: root/mod/dokuwiki/vendors/dokuwiki/lib/tpl/default/tplfn_sidebar.php
blob: 6c378c38594d1f2a53544fa8912b631ba691857b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php 
/*
 * Provide navigation sidebar functionality to Dokuwiki Templates
 *
 * This is not currently part of the official Dokuwiki release
 *
 * @link   http://wiki.jalakai.co.uk/dokuwiki/doku.php?id=tutorials:dev:navigation_sidebar
 * @author Christopher Smith <chris@jalakai.co.uk>
 */

// sidebar configuration settings
tpl_loadConfig();

// determine the sidebar class
$sidebar_class = "sidebar sidebar_".tpl_getConf('layout').'_'.tpl_getConf('orientation');

// recursive function to establish best sidebar file to be used
function getSidebarFN($ns, $file) {

  // check for wiki page = $ns:$file (or $file where no namespace)
  $nsFile = ($ns) ? "$ns:$file" : $file;
  if (file_exists(wikiFN($nsFile)) && auth_quickaclcheck($nsFile)) return $nsFile;
  
// remove deepest namespace level and call function recursively
  
  // no namespace left, exit with no file found  
  if (!$ns) return '';
  
  $i = strrpos($ns, ":");
  $ns = ($i) ? substr($ns, 0, $i) : false;  
  return getSidebarFN($ns, $file);
}

// print a sidebar edit button - if appropriate
function tpl_sidebar_editbtn() {
    global $ID, $conf, $lang;

  // check sidebar configuration
    if (!tpl_getConf('showeditbtn') || !tpl_getConf('page')) return;
  
  // check sidebar page exists
  $fileSidebar = getSidebarFN(getNS($ID), tpl_getConf('page'));
  if (!$fileSidebar) return;
  
  // check user has edit permission for the sidebar page
  if (auth_quickaclcheck($fileSidebar) < AUTH_EDIT) return;
  
?>
    <div class="secedit">
      <form class="button" method="post" action="<?php echo wl($fileSidebar,'do=edit'); ?>" onsubmit="return svchk()">
        <input type="hidden" name="do" value="edit" />
        <input type="hidden" name="rev" value="" />
        <input type="hidden" name="id" value="<?php echo $fileSidebar; ?>" />
        <input type="submit" value="<?php echo $lang['btn_sidebaredit']; ?>" class="button" />
      </form>
    </div>
<?php
}

// display the sidebar
function tpl_sidebar_content() {
  global $ID, $REV, $ACT, $conf;
  
  // save globals
  $saveID = $ID;
  $saveREV = $REV;
  $saveACT = $ACT;

  // discover file to be displayed in navigation sidebar  
  $fileSidebar = '';
  
  if (tpl_getConf('page')) {
    $fileSidebar = getSidebarFN(getNS($ID), tpl_getConf('page'));
  }

  // determine what to display
  if ($fileSidebar) {
    $ID = $fileSidebar;
    $REV = '';
    $ACT = 'show';
#    print p_wiki_xhtml($fileSidebar,'',false);
    tpl_content();
  }
  else {
#    global $IDX;
#    html_index($IDX);
#    $ID = getNS($ID);
    $REV = '';
    $ACT = 'index';
    
    tpl_content();
  }
    
  // restore globals
  $ID = $saveID;
  $REV = $saveREV;
  $ACT = $saveACT;
}