source: documentation/trunk/packages/dokuwiki-2011-05-25a/lib/tpl/greenstone/roundbox.php@ 25027

Last change on this file since 25027 was 25027, checked in by jmt12, 12 years ago

Adding the packages directory, and within it a configured version of dokuwiki all ready to run

File size: 14.9 KB
Line 
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 = DOKU_TPLINC.'style.ini';
11 $file2 = DOKU_TPLINC.'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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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($conf['dformat'], $info);
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 <[email protected]>
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/media.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/**
395 * Helper function for sorting media files with images first
396 *
397 * @author Chris Arndt <[email protected]>
398 */
399function mediacmp($a, $b) {//func
400
401/****** compare values ******/
402 if ($a['isimg'] && $b['isimg'])
403 return strcmp($a['file'], $b['file']);
404 elseif ($a['isimg'])
405 return -1;
406 elseif ($b['isimg'])
407 return 1;
408 else
409 return strcmp($a['file'], $b['file']);
410
411 }//function mediacmp($a, $b)
412
413
414/**
415 * Print a list of mediafiles in the current namespace
416 *
417 * @author Chris Arndt <[email protected]> (based on tpl_mediafilelist)
418 */
419function rb_mediafilelist($columns=4) {//func
420
421/****** declare global variables ******/
422 global $conf;
423 global $lang;
424 global $NS;
425 global $AUTH;
426
427/****** convert internal file name to directory ******/
428 $dir = utf8_encodeFN(str_replace(':', '/', $NS));
429
430/****** locate media ******/
431 $data = array();
432 search($data, $conf['mediadir'], 'search_media', array(), $dir);
433
434/****** nothing found ******/
435 if (!count($data)) {//do
436 ptln('<div class="nothing">'.$lang['nothingfound'].'</div>');
437 return;
438 }//if (!count($data))
439
440/****** sort ******/
441 usort($data, "mediacmp");
442
443/****** show list ******/
444 ptln('<table>');
445 ptln('<tbody>');
446 $i = 0;
447 foreach($data as $item) {//do
448 if ($i == 0)
449 { ptln('<tr>', 2); }
450 ptln('<td>', 4);
451
452 /****** prepare deletion button ******/
453 if ($AUTH >= AUTH_DELETE) {//do
454 $ask = $lang['del_confirm'].'\\n';
455 $ask .= $item['id'];
456 $del = '<a href="' . DOKU_BASE . 'lib/exe/media.php?delete='.
457 urlencode($item['id']) . '" ' . 'onclick="return confirm(\'' .
458 $ask . '\')" onkeypress="return confirm(\'' . $ask . '\')">' .
459 '<img src="' . DOKU_BASE . 'lib/images/del.png" alt="' .
460 $lang['btn_delete'] . '" ' . 'align="bottom" title="' .
461 $lang['btn_delete'] . '" /></a>';
462 }//if ($AUTH >= AUTH_DELETE)
463 else
464 $del = '';
465
466 /****** show thumbnail for images ******/
467 if ($item['isimg']) {//do
468 $w = $item['meta']->getField('File.Width');
469 $h = $item['meta']->getField('File.Height');
470
471 /****** prepare EXIF/IPTC data ******/
472 $caption = $item['meta']->getField('IPTC.Headline');
473 $meta = '';
474 $t = $item['meta']->getField(array('IPTC.Caption',
475 'EXIF.UserComment', 'EXIF.TIFFImageDescription',
476 'EXIF.TIFFUserComment'));
477 if ($t)
478 { $meta .= $t . '<br />'; }
479 $t = $item['meta']->getField(array('IPTC.Keywords',
480 'IPTC.Category'));
481 if ($t)
482 { $meta .= '<i>' . $t . '</i><br />'; }
483
484 /****** image thumbnail ******/
485 echo '<a href="javascript:mediaSelect(\'' . $item['id'] . '\')"';
486 echo ' onmouseover="domTT_activate(this, event, \'content\', ';
487 echo "'" . $meta . "', 'trail', true, 'styleClass', 'imagemeta'";
488 if ($caption)
489 echo ", 'caption', '" . $caption . "'";
490 echo ');">';
491 if ($w > 120 || $h > 120) {//do
492 $ratio = $item['meta']->getResizeRatio(120);
493 $tw = floor($w * $ratio);
494 $th = floor($h * $ratio);
495 }//if ($w > 120 || $h > 120)
496 $src = ml($item['id'],array('w'=>$w,'h'=>$h));
497
498 $p = array();
499 $p['width'] = $tw;
500 $p['height'] = $th;
501 $p['alt'] = $item['id'];
502 $p['class'] = 'thumb';
503 $att = buildAttributes($p);
504
505 echo '<img src="' . $src . '" ' . $att . ' />';
506 ptln('</a>');
507 ptln('<br />', 6);
508 }//if ($item['isimg'])
509
510 /****** link to select media file ******/
511 ptln('<a href="javascript:mediaSelect(\'' . $item['id'] . '\')">' .
512 utf8_decodeFN($item['file']) . '</a>', 6);
513
514 if ($item['isimg']) {//do
515 ptln('<br />', 6);
516 ptln('(' .$w. '&#215;' .$h. ' ' .filesize_h($item['size']). ')', 6);
517 }//if ($item['isimg'])
518 else {//if not ($item['isimg'])
519 ptln('<br />', 6);
520 ptln('(' . filesize_h($item['size']) . ')', 6);
521 }//if not ($item['isimg'])
522
523 /****** delete button ******/
524 ptln('<br />', 6);
525
526 /****** edit button ******/
527 if ($item['isimg'] &&
528 $item['meta']->getField('File.Mime') == 'image/jpeg')
529 rb_btn_img_meta_edit($item['id']);
530 ptln($del, 6);
531
532 /****** end of cell ******/
533 ptln('</td>', 4);
534 $i++;
535 if ($i == $columns) {//do
536 ptln('</tr>', 2);
537 $i = 0;
538 }//if ($i == $columns)
539
540 }//foreach($data as $item)
541
542 if ($i != 0) {//do
543 for (; $i < $columns; $i++) {//do
544 ptln('<td>&nbsp;</td>', 4);
545 }//for (; $i < $columns; $i++)
546 ptln('</tr>', 2);
547 }//if ($i != 0)
548
549 ptln('</tbody>');
550 ptln('</table>');
551
552 }//function rb_mediafilelist($columns=4)
553
554?>
Note: See TracBrowser for help on using the repository browser.