1<?php
2
3/**
4 * Check if the colour scheme has changed
5 */
6function rb_checkTheme() {//func
7
8/******  get theme file names  ******/
9  $theme = tpl_getConf('rb_theme');
10  $file  = tpl_incdir().'style.ini';
11  $file2 = tpl_incdir().'themes/'.$theme.'/style.ini';
12
13/******  get current theme name  ******/
14  $ini   = parse_ini_file($file);
15
16/******  switch themes  ******/
17  if ($ini['__theme__'] != $theme) {//do
18
19  /******  switch themes  ******/
20    if ((@file_exists($file2)) && (@unlink($file)) && (@copy($file2, $file))) {//do
21      global $conf;
22      if ($conf['fperm']) chmod($file, $conf['fperm']);
23      echo '<meta http-equiv="Refresh" content=0 />';
24      }//if ((@file_exists($file2)) && (@unlink($file)) && (@copy($file2, $file)))
25
26  /******  theme not found  ******/
27    else
28      msg('Could not set correct style.ini file for your chosen theme.', -1);
29
30    }//if ($ini['__theme__'] != $theme)
31
32  }//function rb_checkTheme()
33
34
35/**
36 * get user name and groups
37 * Works around bug in DokuWiki <= 2009-09-22 and also appends
38 * 'ALL' to list of groups to facilitate group access checking
39 *
40 * @author Chris Arndt <chris@chrisarndt.de>
41 */
42function rb_get_user_info() {//func
43
44/******  declare global variables  ******/
45  global $INFO;
46
47/******  set user array  ******/
48  $user = array();
49
50/******  no valid user  ******/
51  if ($_REQUEST['do'] == 'logout' or !isset($INFO['userinfo']))
52    $user['groups'] = array();
53
54/******  set user information  ******/
55  else {//do
56    $user['groups'] = $INFO['userinfo']['grps'];
57    $user['name'] = $_SERVER['REMOTE_USER'];
58    }//else do
59
60/******  add ALL  ******/
61  array_push($user['groups'], 'ALL');
62
63/******  return user  ******/
64  return $user;
65
66  }//function rb_get_user_info()
67
68
69/**
70 * check if current user should have access to given action
71 * Relies on certain configuration parameters to be present
72 *
73 * @author Chris Arndt <chris@chrisarndt.de>
74 */
75function rb_check_action_perms($action, $perms, $user) {//func
76
77/******  declare global variables  ******/
78  global $conf;
79
80/******  set access control variables  ******/
81  $ac_lvls = tpl_getConf('rb_act_ac_lvl');
82  $ac_users = tpl_getConf('rb_act_users');
83  $ac_lvl = $ac_lvls[$action];
84
85/******  set default access level  ******/
86  if (!isset($ac_lvl) or $ac_lvl == '')
87    $ac_lvl = 255;
88
89/******  access level is ok  ******/
90  if ($perms >= $ac_lvl)
91    return true;
92
93/******  check access level  ******/
94  elseif (!empty($ac_users[$action])) {//do
95    $speclist = explode(',', $ac_users[$action]);
96    $allowed_users = array();
97    $allowed_groups = array();
98
99    foreach ($speclist as $spec) {//do
100      $spec = trim($spec);
101      if (substr($spec, 0, 1) == '@')
102        array_push($allowed_groups, substr($spec, 1));
103      else
104        array_push($allowed_users, $spec);
105      }//foreach ($speclist as $spec)
106
107    if (!empty($info['user']) and
108        in_array($user['name'], $allowed_users))
109      return true;
110
111    foreach ($user['groups'] as $group) {//do
112      if (in_array($group, $allowed_groups))
113        return true;
114      }//foreach ($user['groups'] as $group)
115
116    }//if (!empty($ac_users[$action]))
117
118/******  refuse access  ******/
119  return false;
120
121  }//function rb_check_action_perms($action, $perms, $user)
122
123
124/**
125 * show button or link for given action depending on visibility settings
126 *
127 * @author Chris Arndt <chris@chrisarndt.de>
128 */
129function rb_button($action, $perms, $user) {//func
130
131/******  declare global variables  ******/
132  global $conf;
133
134/******  generate button/link if allowed  ******/
135  if (rb_check_action_perms($action, $perms, $user)) {//do
136
137  /******  generate link  ******/
138    if (tpl_getConf('rb_uselinks')) {//do
139      if (tpl_get_action($action)) {//do}
140        ptln('<li class="level1">');
141        tpl_actionlink($action);
142        ptln('</li>');
143        }//if (tpl_get_action($action))
144      }//if (tpl_getConf('rb_uselinks'))
145
146  /******  generate button  ******/
147    else {//if not (tpl_getConf('rb_uselinks'))
148      tpl_button($action);
149      ptln('<br>');
150      }//if not (tpl_getConf('rb_uselinks'))
151
152    }//if (rb_check_action_perms($action, $perms, $user))
153
154  }//function rb_button($action, $perms, $user)
155
156
157/**
158 * prints the contents of the command box in the sidebar
159 *
160 * @author Chris Arndt <chris@chrisarndt.de>
161 */
162function rb_sitecmds($perms, $user) {//func
163
164/******  declare global variables  ******/
165  global $conf;
166
167/******  start list of links  ******/
168  if (tpl_getConf('rb_uselinks'))
169    ptln('<ul>');
170
171/******  start button box  ******/
172  else
173    ptln('<div class="buttonbox">');
174
175/******  generate buttons/links  ******/
176  foreach (tpl_getConf('rb_actions') as $command) {//do
177
178  /******  generate break  ******/
179    if ($command == '-') {//do
180      if (tpl_getConf('rb_uselinks')) {//do
181        ptln('</ul>');
182        ptln('<ul>');
183        }//if (tpl_getConf('rb_uselinks'))
184      else //if not (tpl_getConf('rb_uselinks'))
185        ptln('<br>');
186      }//if ($command == '-')
187
188  /******  generate button/link  ******/
189    else
190      rb_button($command, $perms, $user);
191
192    }//foreach (tpl_getConf('rb_actions') as $command)
193
194/******  finish list of links  ******/
195  if (tpl_getConf('rb_uselinks'))
196    ptln('</ul>');
197
198/******  finish button box  ******/
199  else
200    ptln('</div>');
201
202  }//function rb_sitecmds($perms, $user)
203
204
205/**
206 * replacement for tpl_youarehere()
207 * Links namespaces to <namespace>:index
208 *
209 * taken from:
210 * <http://wiki.splitbrain.org/wiki:tips:breadcrumb_namespace_index_links>
211 */
212function rb_youarehere() {//func
213
214/******  declare global variables  ******/
215  global $conf;
216  global $ID;
217  global $lang;
218
219/******  break id into parts  ******/
220  $parts = explode(':', $ID);
221
222/******  show line header  ******/
223  echo hsc($lang['youarehere']).': ';
224
225/******  always show start page  ******/
226  if ($a_part[0] != $conf['start']) {//do
227    tpl_link(wl($conf['start']), $conf['start'],
228        'title="'.$conf['start'].'"');
229    }//if ($a_part[0] != $conf['start'])
230
231/******  set variables  ******/
232  $page = '';
233  $last = count($parts);
234  $count = 1;
235
236/******  process each part  ******/
237  foreach ($parts as $part) {//do
238
239  /******  process part  ******/
240    if ($count != $last || $part != tpl_getConf('rb_index')) {//do
241
242    /******  skip start page if already done  ******/
243      if ($part == $conf['start'])
244        continue;
245
246    /******  show separator  ******/
247      echo tpl_getConf('rb_crumbsep');
248
249    /******  edit page  ******/
250      $page .= $part;
251
252    /******  remove underscores  ******/
253      if (tpl_getConf('rb_removeunderscores') == 1)
254        $part = str_replace('_', ' ', $part);
255
256    /******  set link variable  ******/
257      if ($count == $last)
258        $link = $page;
259      else
260        $link = "$page:" . tpl_getConf('rb_index');
261
262    /******  show link if page exists  ******/
263      if (file_exists(wikiFN($link)))
264        tpl_link(wl($link), $part, 'title="'.$link.'"');
265
266    /******  show link, but mark as not-existing  ******/
267      else
268        tpl_link(wl($link), $part, 'title="'.$link.'" class="wikilink2"');
269
270    /******  add namespace separator  ******/
271      $page .= ':';
272
273      }//if ($count != $last || $part != tpl_getConf('rb_index'))
274
275  /******  increment count  ******/
276    $count++;
277
278    }//foreach ($parts as $part)
279
280  }//function rb_youarehere()
281
282
283/**
284 * Show meta information for images
285 *
286 * @author Chris Arndt <chris@chrisarndt.de>
287 */
288function rb_img_meta($debug=false) {//func
289
290/******  declare global variables  ******/
291  global $conf;
292  global $lang;
293  global $IMG;
294
295/* change the order of fields in this array to change the order in which
296 * the image information tags are listed
297 */
298  $tags = array(
299    'img_caption' => array('IPTC.Caption', 'EXIF.UserComment',
300        'EXIF.TIFFImageDescription', 'EXIF.TIFFUserComment'),
301    'img_artist' => array('Iptc.Byline', 'Exif.TIFFArtist', 'Exif.Artist',
302        'Iptc.Credit'),
303    'img_keywords' => array('IPTC.Keywords','IPTC.Category'),
304    'img_copyr' => array('Iptc.CopyrightNotice', 'Exif.TIFFCopyright',
305        'Exif.Copyright'),
306    'img_camera' => 'Simple.Camera',
307    'img_fname' => 'File.Name',
308    'img_format' => 'File.Format',
309    'img_dimen'=> null, // built from File.Width and File.Height
310    'img_date' => 'Date.EarliestTime',
311    'img_fsize'=> 'File.NiceSize',
312    );
313
314/******  start table  ******/
315  ptln('<table class="img_tags">');
316
317/******  show caption  ******/
318  ptln('<caption>', 2);
319  ptln($lang['img_metaheading'], 4);
320//  if (tpl_img_getTag('File.Mime') == 'image/jpeg')
321    rb_btn_img_meta_edit($IMG, true);
322  ptln('</caption>', 2);
323
324/******  show column headers  ******/
325  ptln('<thead>', 2);
326  ptln('<tr>', 4);
327  ptln('<th class="label">' . $lang['colfield'] . '</th>', 6);
328  ptln('<th class="value">' . $lang['colvalue'] . '</th>', 6);
329  ptln('</tr>', 4);
330  ptln('</thead>', 2);
331
332/******  generate table  ******/
333  ptln('<tbody>', 2);
334
335  foreach ($tags as $tagname => $meta) {//do
336
337    if ($tagname == 'img_dimen') {//do
338      $info = tpl_img_getTag('File.Width') . '&#215;' .
339          tpl_img_getTag('File.Height');
340      }//if ($tagname == 'img_dimen')
341
342    else {//if not ($tagname == 'img_dimen')
343      $info = tpl_img_getTag($meta);
344      if ($info && $tagname == 'img_date')
345        $info = dformat($info, $conf['dformat']);
346      else
347        $info = nl2br(hsc($info));
348      }//if not ($tagname == 'img_dimen')
349
350    if ($info) {//do
351      ptln('<tr>', 4);
352      ptln('<td class="label">' . hsc($lang[$tagname]) . '</td>', 6);
353      ptln('<td class="value">' . $info . '</td>', 6);
354      ptln('</tr>', 4);
355      }//if ($info)
356    }//foreach ($tags as $tagname => $meta)
357
358  ptln('</tbody>', 2);
359  ptln('</table>');
360
361/******  debug  ******/
362  if ($debug)
363    dbg(tpl_img_getTag('Simple.Raw'));
364
365  }//function rb_img_meta($debug=false)
366
367/**
368 * Show link to mediaedit page
369 *
370 * @author Chris Arndt <chris@chrisarndt.de>
371 */
372function rb_btn_img_meta_edit($id, $newwin=false) {//func
373
374/******  declare global variables  ******/
375  global $AUTH;
376  global $lang;
377
378/******  show link  ******/
379  if ($AUTH >= AUTH_UPLOAD) {//do
380    echo '<a href="' . DOKU_BASE . 'lib/exe/mediamanager.php?edit=' .
381        urlencode($id) . '"';
382    if ($newwin)
383      echo ' onclick="return metaedit(\'' . urlencode($id) .
384          '\');" target="mediaselect"';
385    echo '>';
386    echo '<img src="' . DOKU_BASE . 'lib/images/edit.gif" alt="' .
387        $lang['metaedit'] . '" title="' . $lang['metaedit'] . '" />';
388    ptln('</a>');
389    }//if ($AUTH >= AUTH_UPLOAD)
390
391  }//function rb_btn_img_meta_edit($id, $newwin=false)
392
393?>
394