1<?php
2/**
3 * Provide navigation sidebar functionality to Dokuwiki Templates
4 *
5 * @author Christopher Smith <chris@jalakai.co.uk>
6 * @author Esther Brunner <wikidesign@gmail.com>
7 * @author Don Bowman <don@lynsoft.co.uk>
8 */
9
10/**
11 * Recursive function to establish best sidebar file to be used
12 */
13function getSidebarFN($ns, $file) {//func
14
15/******  check for wiki page = $ns:$file (or $file where no namespace)  ******/
16  $nsFile = ($ns) ? "$ns:$file" : $file;
17  if (file_exists(wikiFN($nsFile)) && auth_quickaclcheck($nsFile))
18    return $nsFile;
19
20/******  no namespace left, exit with no file found  ******/
21  if (!$ns)
22    return '';
23
24/******  remove deepest namespace level and call function recursively  ******/
25  $i = strrpos($ns, ":");
26  $ns = ($i) ? substr($ns, 0, $i) : false;
27  return getSidebarFN($ns, $file);
28
29  }//function getSidebarFN($ns, $file)
30
31
32/**
33 * Display the sidebar
34 */
35function minima_sidebar() {//func
36
37/******  declare global variables  ******/
38	global $ID, $REV, $ACT, $conf;
39
40/******  save global variables  ******/
41	$saveID = $ID;
42	$saveREV = $REV;
43//	$saveACT = $ACT;
44
45/******  find file to be displayed in navigation sidebar  ******/
46  $sidebar = tpl_getConf('sidebar_page');
47  $fileSidebar = getSidebarFN(getNS($ID), $sidebar);
48
49/******  show main sidebar if necessary  ******/
50  if (tpl_getConf('minima_main_sidebar') && $fileSidebar != $sidebar) {//do
51    $ID = $sidebar;
52    $REV = '';
53		echo p_wiki_xhtml($ID, $REV, false);
54//    $ACT = 'show';
55//    tpl_content(false);
56    echo "<hr>";
57    }//if (tpl_getConf('minima_main_sidebar') && $fileSidebar != $sidebar)
58
59/******  show current sidebar  ******/
60  if ($fileSidebar) {//do
61    $ID = $fileSidebar;
62    $REV = '';
63		echo p_wiki_xhtml($ID, $REV, false);
64//    $ACT = 'show';
65//    tpl_content(false);
66    }//if ($fileSidebar)
67
68/******  show index  ******/
69  else {//if (!$fileSidebar)
70//    $REV = '';
71//    $ACT = 'index';
72    global $IDX;
73    html_index($IDX);
74//    tpl_content(false);
75    }//if (!$fileSidebar)
76
77/******  restore global variables  ******/
78  $ID = $saveID;
79  $REV = $saveREV;
80//  $ACT = $saveACT;
81
82  }//function minima_sidebar()
83
84
85/**
86 * Return the correct ID for <div class="dokuwiki">
87 */
88function minima_classID() {//func
89  echo 'minima__'.tpl_getConf('width').'_'.tpl_getConf('sidebar_position');
90  }//function minima_classID()
91
92
93/**
94 * Checks if the color scheme has changed
95 */
96function minima_checkColor() {//func
97
98/******  set local variables  ******/
99  $color = tpl_getConf('color');
100  $file  = tpl_incdir().'style.ini';
101  $file2 = tpl_incdir().'style_'.$color.'.ini';
102  $ini   = parse_ini_file($file);
103
104/******  change theme as requested  ******/
105  if ($ini['__theme__'] != '_'.$color) {//do
106
107    if ((@file_exists($file2)) && (@unlink($file)) && (@copy($file2, $file))) {//do
108      global $conf;
109      if ($conf['fperm']) chmod($file, $conf['fperm']);
110      }//if ((@file_exists($file2)) && (@unlink($file)) && (@copy($file2, $file)))
111
112    else {//if not ((@file_exists($file2)) && (@unlink($file)) && (@copy($file2, $file)))
113      msg('Could not set correct style.ini file for your chosen color scheme.', -1);
114      }//else {//if not ...
115
116    }//if ($ini['__theme__'] != '_'.$color)
117
118  }//function minima_checkColor()
119
120
121/**
122 * Display tabs for easy navigation
123 */
124function minima_tabs() {//func
125
126/******  declare global variables  ******/
127  global $ID;
128
129/******  set local variables  ******/
130  $out = '';
131
132/******  get tabs file name  ******/
133  $ns = getNS($ID);
134  $tabsFile = wikiFN(($ns).':'.tpl_getConf('tabs_page'));
135
136/******  show tabs  ******/
137  if ((@file_exists($tabsFile)) && (auth_quickaclcheck($tabs))) {//do
138    $ins = p_cached_instructions($tabsFile);
139
140  /******  process each tab  ******/
141    foreach ($ins as $in) {//do
142
143    /******  collect internal links to pages in same namespace  ******/
144      if ($in[0] == 'internallink') {//do
145        list($id, $hash) = explode('#', $in[1][0], 2);
146        resolve_pageid(getNS($ID), $id, $exists);
147
148      /******  ignore links to other namespaces  ******/
149        if (getNS($id) != $ns)
150          continue;
151
152      /******  ignore links to non-existent pages  ******/
153        if (!$exists)
154          continue;
155
156      /******  determine link title  ******/
157        $title = hsc($in[1][1]);
158        if (!$title)
159          $title = hsc(p_get_first_heading($id));
160        if (!$title)
161          $title = hsc(ucwords(noNS($id)));
162
163      /******  now construct the output link  ******/
164        if ($id == $ID)
165          $out .= '<span class="activetab">'.$title.'</span> ';
166        else
167          $out .= '<a href="'.wl($id).'" class="tab">'.$title.'</a> ';
168
169        }//if ($in[0] == 'internallink')
170
171    /******  first header of tabs.txt is heading for whole namespace  ******/
172      elseif (($in[0] == 'header') && (!$heading)) {//do
173        $heading = $in[1][0];
174        $level = $in[1][1];
175        }//if (($in[0] == 'header') && (!$heading))
176
177      }//foreach ($ins as $in)
178
179  /******  add heading to list  ******/
180    if ($heading)
181      $out = '<h'.$level.'>'.$heading.'</h'.$level.'>'.$out;
182
183  /******  show list  ******/
184    if ($out <> "")
185      echo '<div class="tabs">'.$out.'</div>';
186
187    }//if ((@file_exists($tabsFile)) && (auth_quickaclcheck($tabs)))
188
189  }//function minima_tabs()
190
191
192/**
193 * Outputs the namespace title
194 */
195function minima_nstitle() {//func
196
197/******  declare global variables  ******/
198  global $ID;
199
200/******  get namespace title  ******/
201  $title = p_get_metadata(getNS($ID).':'.tpl_getConf('tabs_page'), 'title');
202
203/******  show namespace title  ******/
204  if ($title)
205    echo $title.': ';
206
207  }//function minima_nstitle()
208