fix a warning when a barrel's menu is empty
[diogenes.git] / include / Barrel / Events.php
1 <?php
2 /*
3 * Copyright (C) 2003-2006 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 define('EVENT_FLAG_NONE', 0);
22 define('EVENT_FLAG_PUBLIC', 1);
23
24 /** This class is used to generate the menu of a Diogenes barrel page.
25 */
26 class Diogenes_Barrel_Events
27 {
28 /** The barrel we are watching */
29 var $barrel;
30
31 /** Constructor.
32 */
33 function Diogenes_Barrel_Events(&$barrel)
34 {
35 $this->barrel = $barrel;
36 }
37
38
39 /** Filename transformations.
40 */
41 function makeFileLoc($log_file, &$caller)
42 {
43 $homepage = $this->barrel->getPID('');
44 if (stristr($log_file, '/') == FALSE ) {
45 // this is a directory
46 $mydir = $log_file;
47 $myfile = '';
48 } else {
49 $myfile = basename($log_file);
50 $mydir = dirname($log_file);
51 }
52
53 $myloc = $this->barrel->getLocation($mydir);
54 if ($myloc or ($mydir == $homepage))
55 {
56 $log_file = $myloc ? "$myloc/$myfile" : $myfile;
57 $url_loc = $myloc ? "$myloc/" : '';
58 $link = $caller->urlBarrel($this->barrel->alias, $this->barrel->vhost, $url_loc);
59 } else {
60 $link = '';
61 }
62
63 return array($log_file, $mydir, $myfile, $link);
64 }
65
66 /** Retrieve recent events.
67 */
68 function getEvents($caller)
69 {
70 global $globals;
71 $events = array();
72 $res = $globals->db->query("select e.action,e.stamp,e.data,a.text,s.auth,s.uid "
73 ."from {$globals->table_log_events} as e "
74 ."left join {$globals->table_log_actions} as a on e.action=a.id "
75 ."left join {$globals->table_log_sessions} as s on e.session=s.id "
76 ."where e.data like '{$this->barrel->alias}:%' "
77 ."order by stamp desc limit 0,10");
78 while ($myarr = mysql_fetch_array($res)) {
79 $myarr['author'] = call_user_func(array($globals->session,'getUsername'),$myarr['auth'],$myarr['uid']);
80 $myarr['flags'] = EVENT_FLAG_NONE;
81 list($op_alias, $op_file) = split(":",$myarr['data']);
82
83 switch($myarr['text']) {
84 case "barrel_create":
85 $myarr['title'] = __("site created");
86 $myarr['icon'] = $globals->icons->get_action_icon('add');
87 break;
88
89 case "barrel_options":
90 $myarr['title'] = __("barrel options");
91 $myarr['icon'] = $globals->icons->get_action_icon('properties');
92 break;
93
94 case "barrel_plugins":
95 $myarr['title'] = __("barrel plugins");
96 $myarr['icon'] = $globals->icons->get_action_icon('plugins');
97 $myarr['link_admin'] = "plugins";
98 break;
99
100 case "page_create":
101 $myarr['title'] = __("page created");
102 $myarr['icon'] = $globals->icons->get_action_icon('add');
103 list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller);
104 $myarr['link_admin'] = "pages?dir={$myarr['dir']}";
105 $myarr['flags'] |= EVENT_FLAG_PUBLIC;
106 break;
107
108 case "page_delete":
109 $myarr['title'] = __("page removed");
110 $myarr['icon'] = $globals->icons->get_action_icon('remove');
111 break;
112
113 case "page_props":
114 $myarr['title'] = __("page properties");
115 $myarr['icon'] = $globals->icons->get_action_icon('properties');
116 list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);
117 $myarr['link_admin'] = "pages?dir={$myarr['dir']}";
118 break;
119
120 case "page_plugins":
121 $myarr['title'] = __("page plugins");
122 $myarr['icon'] = $globals->icons->get_action_icon('plugins');
123 list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);
124 $myarr['link_admin'] = "plugins?plug_page={$myarr['dir']}";
125 break;
126
127 case "rcs_commit":
128 $myarr['title'] = __("file updated");
129 $myarr['icon'] = $globals->icons->get_action_icon('update');
130 list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller);
131 $myarr['link_admin'] = "files?action=revs&amp;dir={$myarr['dir']}&amp;target={$myarr['file']}";
132 $myarr['flags'] |= EVENT_FLAG_PUBLIC;
133
134 break;
135
136 case "rcs_delete":
137 $myarr['title'] = __("file deleted");
138 $myarr['icon'] = $globals->icons->get_action_icon('delete');
139 list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);
140 break;
141 }
142 $myarr['opfile'] = $op_file;
143
144 if (isset($myarr['title']))
145 array_push($events, $myarr);
146 }
147 mysql_free_result($res);
148 return $events;
149 }
150 }
151
152 ?>