1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of activityReport, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009 JC Denis and contributors |
---|
6 | # jcdenis@gdwd.com |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')){return;} |
---|
14 | |
---|
15 | if (!$core->activityReport instanceof activityReport){return;} |
---|
16 | |
---|
17 | # Dashboarditems |
---|
18 | if ($core->activityReport->getSetting('dashboardItem')) |
---|
19 | { |
---|
20 | $core->addBehavior( |
---|
21 | 'adminDashboardHeaders', |
---|
22 | array('activityReportBehaviors','dashboardHeaders') |
---|
23 | ); |
---|
24 | $core->addBehavior( |
---|
25 | 'adminDashboardItems', |
---|
26 | array('activityReportBehaviors','dashboardItems') |
---|
27 | ); |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | /* Blog |
---|
32 | -------------------------*/ |
---|
33 | $core->activityReport->addGroup('blog',__('Actions on blog')); |
---|
34 | |
---|
35 | # Not use as it is global : BEHAVIOR adminAfterBlogCreate in admin/blog.php |
---|
36 | |
---|
37 | # from BEHAVIOR adminAfterBlogUpdate in admin/blog_pref.php |
---|
38 | $core->activityReport->addAction( |
---|
39 | 'blog', |
---|
40 | 'update', |
---|
41 | __('updating blog'), |
---|
42 | __('Blog was updated by "%s"'), |
---|
43 | 'adminAfterBlogUpdate', |
---|
44 | array('activityReportBehaviors','blogUpdate') |
---|
45 | ); |
---|
46 | |
---|
47 | # from BEHAVIOR publicHeadContent in template |
---|
48 | $core->activityReport->addAction( |
---|
49 | 'blog', |
---|
50 | 'p404', |
---|
51 | __('404 error'), |
---|
52 | __('New 404 error page at "%s"'), |
---|
53 | 'publicHeadContent', |
---|
54 | array('activityReportBehaviors','blogP404') |
---|
55 | ); |
---|
56 | |
---|
57 | |
---|
58 | /* Post |
---|
59 | -------------------------*/ |
---|
60 | $core->activityReport->addGroup('post',__('Actions on posts')); |
---|
61 | |
---|
62 | # from BEHAVIOR coreAfterPostCreate in inc/core/class.dc.blog.php |
---|
63 | # duplicate adminAfterPostCreate in admin/post.php |
---|
64 | # duplicate adminAfterPostCreate in admin/services.php |
---|
65 | $core->activityReport->addAction( |
---|
66 | 'post', |
---|
67 | 'create', |
---|
68 | __('post creation'), |
---|
69 | __('A new post called "%s" was created by "%s" at %s'), |
---|
70 | 'coreAfterPostCreate', |
---|
71 | array('activityReportBehaviors','postCreate') |
---|
72 | ); |
---|
73 | |
---|
74 | # from BEHAVIOR coreAfterPostUpdate in inc/core/class.dc.blog.php |
---|
75 | # duplicate adminAfterPostUpdate in admin/post.php |
---|
76 | $core->activityReport->addAction( |
---|
77 | 'post', |
---|
78 | 'update', |
---|
79 | __('updating post'), |
---|
80 | __('Post called "%s" have been updated by "%s" at %s'), |
---|
81 | 'coreAfterPostUpdate', |
---|
82 | array('activityReportBehaviors','postUpdate') |
---|
83 | ); |
---|
84 | |
---|
85 | # from BEHAVIOR adminBeforePostDelete in admin/posts_actions.php |
---|
86 | # from BEHAVIOR adminBeforePostDelete in admin/post.php |
---|
87 | $core->activityReport->addAction( |
---|
88 | 'post', |
---|
89 | 'delete', |
---|
90 | __('post deletion'), |
---|
91 | __('Post called "%s" have been deleted by "%s"'), |
---|
92 | 'adminBeforePostDelete', |
---|
93 | array('activityReportBehaviors','postDelete') |
---|
94 | ); |
---|
95 | |
---|
96 | |
---|
97 | /* Comment |
---|
98 | -------------------------*/ |
---|
99 | $core->activityReport->addGroup('comment',__('Actions on comments')); |
---|
100 | |
---|
101 | # from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php |
---|
102 | # duplicate adminAfterCommentCreate in admin/comment.php |
---|
103 | # duplicate publicAfterCommentCreate in inc/public/lib.urlhandlers.php |
---|
104 | $core->activityReport->addAction( |
---|
105 | 'comment', |
---|
106 | 'create', |
---|
107 | __('comment creation'), |
---|
108 | __('A new comment was created by "%s" on post "%s" at %s'), |
---|
109 | 'coreAfterCommentCreate', |
---|
110 | array('activityReportBehaviors','commentCreate') |
---|
111 | ); |
---|
112 | |
---|
113 | # from BEHAVIOR coreAfterCommentUpdate in inc/core/class.dc.blog.php |
---|
114 | # duplicate adminAfterCommentUpdate in admin/comment.php |
---|
115 | $core->activityReport->addAction( |
---|
116 | 'comment', |
---|
117 | 'update', |
---|
118 | __('updating comment'), |
---|
119 | __('Comment have been updated by "%s" at %s'), |
---|
120 | 'coreAfterCommentUpdate', |
---|
121 | array('activityReportBehaviors','commentUpdate') |
---|
122 | ); |
---|
123 | |
---|
124 | # Missing coreBeforeCommentDelete in inc/core/class.dc.blog.php |
---|
125 | # Missing adminBeforeCommentDelete in admin/comment.php |
---|
126 | |
---|
127 | # from BEHAVIOR coreAfterCommentCreate in inc/core/class.dc.blog.php |
---|
128 | # duplicate publicAfterTrackbackCreate in inc/core/class.dc.trackback.php |
---|
129 | $core->activityReport->addAction( |
---|
130 | 'comment', |
---|
131 | 'trackback', |
---|
132 | __('trackback creation'), |
---|
133 | __('A new trackback to "%" at "%s" was created on post "%s" at %s'), |
---|
134 | 'coreAfterCommentCreate', |
---|
135 | array('activityReportBehaviors','trackbackCreate') |
---|
136 | ); |
---|
137 | |
---|
138 | |
---|
139 | /* Category |
---|
140 | -------------------------*/ |
---|
141 | $core->activityReport->addGroup('category',__('Actions on categories')); |
---|
142 | |
---|
143 | # from BEHAVIOR adminAfterCategoryCreate in admin/category.php |
---|
144 | $core->activityReport->addAction( |
---|
145 | 'category', |
---|
146 | 'create', |
---|
147 | __('category creation'), |
---|
148 | __('A new category called "%s" was created by "%s" at %s'), |
---|
149 | 'adminAfterCategoryCreate', |
---|
150 | array('activityReportBehaviors','categoryCreate') |
---|
151 | ); |
---|
152 | |
---|
153 | # from BEHAVIOR adminAfterCategoryUpdate in admin/category.php |
---|
154 | $core->activityReport->addAction( |
---|
155 | 'category', |
---|
156 | 'update', |
---|
157 | __('updating category'), |
---|
158 | __('Category called "%s" have been updated by "%s" at %s'), |
---|
159 | 'adminAfterCategoryUpdate', |
---|
160 | array('activityReportBehaviors','categoryUpdate') |
---|
161 | ); |
---|
162 | |
---|
163 | # Missing adminBeforeCategoryDelete in admin/category.php |
---|
164 | |
---|
165 | |
---|
166 | /* User |
---|
167 | -------------------------*/ |
---|
168 | $core->activityReport->addGroup('user',__('Actions on users')); |
---|
169 | |
---|
170 | # from BEHAVIOR adminAfterUserCreate in admin/user.php |
---|
171 | $core->activityReport->addAction( |
---|
172 | 'user', |
---|
173 | 'create', |
---|
174 | __('user creation'), |
---|
175 | __('A new user named "%s" was added by "%s"'), |
---|
176 | 'adminAfterUserCreate', |
---|
177 | array('activityReportBehaviors','userCreate') |
---|
178 | ); |
---|
179 | |
---|
180 | # from BEHAVIOR adminAfterUserUpdated in admin/user.php |
---|
181 | $core->activityReport->addAction( |
---|
182 | 'user', |
---|
183 | 'update', |
---|
184 | __('updating user'), |
---|
185 | __('User named "%s" have been updated by "%s"'), |
---|
186 | 'adminAfterUserUpdate', |
---|
187 | array('activityReportBehaviors','userUpdate') |
---|
188 | ); |
---|
189 | |
---|
190 | # from BEHAVIOR adminBeforeUserDelete in admin/users.php |
---|
191 | $core->activityReport->addAction( |
---|
192 | 'user', |
---|
193 | 'delete', |
---|
194 | __('user deletion'), |
---|
195 | __('User named "%s" have been deleted by "%"'), |
---|
196 | 'adminBeforeUserDelete', |
---|
197 | array('activityReportBehaviors','userDelete') |
---|
198 | ); |
---|
199 | |
---|
200 | |
---|
201 | class activityReportBehaviors |
---|
202 | { |
---|
203 | # Add CSS to dashboardHeaders for items |
---|
204 | public static function dashboardHeaders() |
---|
205 | { |
---|
206 | return |
---|
207 | "\n<!-- CSS for activityReport --> \n". |
---|
208 | "<style type=\"text/css\"> \n". |
---|
209 | "#dashboard-items #report dt { font-weight: bold; margin: 0 0 0.4em 0; } \n". |
---|
210 | "#dashboard-items #report dd { font-size: 0.9em; margin: 0 0 1em 0; } \n". |
---|
211 | "#dashboard-items #report dd p { margin: 0.2em 0 0 0; } \n". |
---|
212 | "</style> \n"; |
---|
213 | } |
---|
214 | |
---|
215 | # Add report to dashboardItems |
---|
216 | public static function dashboardItems($core, $__dashboard_items) |
---|
217 | { |
---|
218 | $r = $core->activityReport->getSetting('requests'); |
---|
219 | $g = $core->activityReport->getGroups(); |
---|
220 | |
---|
221 | $p = array(); |
---|
222 | $p['limit'] = 20; |
---|
223 | $p['order'] = 'activity_dt DESC'; |
---|
224 | $p['sql'] = $core->activityReport->requests2params($r); |
---|
225 | |
---|
226 | $rs = $core->activityReport->getLogs($p); |
---|
227 | if (!$rs->isEmpty()) |
---|
228 | { |
---|
229 | $res = ''; |
---|
230 | while($rs->fetch()) |
---|
231 | { |
---|
232 | $group = $rs->activity_group; |
---|
233 | |
---|
234 | $res .= |
---|
235 | '<dd><p title="'.__($g[$group]['title']).'"><strong>'. |
---|
236 | __($g[$group]['actions'][$rs->activity_action]['title']). |
---|
237 | '</p></strong><em>'. |
---|
238 | vsprintf( |
---|
239 | __($g[$group]['actions'][$rs->activity_action]['msg']), |
---|
240 | $core->activityReport->decode($rs->activity_logs) |
---|
241 | ). |
---|
242 | '</em></dd>'; |
---|
243 | } |
---|
244 | |
---|
245 | if (!empty($res)) |
---|
246 | { |
---|
247 | $__dashboard_items[1][] = |
---|
248 | '<h3>'.__('Activity report').'</h3>'. |
---|
249 | '<dl id="report">'.$res.'</dl>'; |
---|
250 | } |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | public static function blogUpdate($cur,$blog_id) |
---|
255 | { |
---|
256 | global $core; |
---|
257 | |
---|
258 | $logs = array($core->auth->getInfo('user_cn')); |
---|
259 | |
---|
260 | $core->activityReport->addLog('blog','update',$logs); |
---|
261 | } |
---|
262 | |
---|
263 | public static function blogP404() |
---|
264 | { |
---|
265 | global $core; |
---|
266 | if ($core->url->type != '404') return; |
---|
267 | |
---|
268 | $logs = array($core->blog->url.$_SERVER['QUERY_STRING']); |
---|
269 | |
---|
270 | $core->activityReport->addLog('blog','p404',$logs); |
---|
271 | } |
---|
272 | |
---|
273 | public static function postCreate($blog,$cur) |
---|
274 | { |
---|
275 | global $core; |
---|
276 | |
---|
277 | $type = $cur->post_type ? $cur->post_type : 'post'; |
---|
278 | |
---|
279 | $logs = array( |
---|
280 | $cur->post_title, |
---|
281 | $core->auth->getInfo('user_cn'), |
---|
282 | $core->blog->url.$core->url->getBase($type).'/'.$cur->post_url |
---|
283 | ); |
---|
284 | |
---|
285 | $core->activityReport->addLog('post','create',$logs); |
---|
286 | } |
---|
287 | |
---|
288 | public static function postUpdate($blog,$cur) |
---|
289 | { |
---|
290 | global $core; |
---|
291 | |
---|
292 | $type = $cur->post_type ? $cur->post_type : 'post'; |
---|
293 | |
---|
294 | $logs = array( |
---|
295 | $cur->post_title, |
---|
296 | $core->auth->getInfo('user_cn'), |
---|
297 | $core->blog->url.$core->url->getBase($type).'/'.$cur->post_url |
---|
298 | ); |
---|
299 | |
---|
300 | $core->activityReport->addLog('post','update',$logs); |
---|
301 | } |
---|
302 | |
---|
303 | public static function postDelete($post_id) |
---|
304 | { |
---|
305 | global $core; |
---|
306 | $posts = $core->blog->getPosts(array('post_id'=>$post_id,'limit'=>1)); |
---|
307 | |
---|
308 | $logs = array( |
---|
309 | $posts->post_title, |
---|
310 | $core->auth->getInfo('user_cn') |
---|
311 | ); |
---|
312 | |
---|
313 | $core->activityReport->addLog('post','delete',$logs); |
---|
314 | } |
---|
315 | |
---|
316 | public static function commentCreate($blog,$cur) |
---|
317 | { |
---|
318 | global $core; |
---|
319 | if ($cur->comment_trackback) return; |
---|
320 | |
---|
321 | $posts = $core->blog->getPosts(array('post_id'=>$cur->post_id,'limit'=>1)); |
---|
322 | |
---|
323 | $logs = array( |
---|
324 | $cur->comment_author, |
---|
325 | $posts->post_title, |
---|
326 | $core->blog->url.$core->url->getBase($posts->post_type). |
---|
327 | '/'.$posts->post_url.'#c'.$cur->comment_id |
---|
328 | ); |
---|
329 | |
---|
330 | $core->activityReport->addLog('comment','create',$logs); |
---|
331 | } |
---|
332 | |
---|
333 | public static function commentUpdate($blog,$cur,$old) |
---|
334 | { |
---|
335 | global $core; |
---|
336 | $posts = $core->blog->getPosts(array('post_id'=>$old->post_id,'limit'=>1)); |
---|
337 | |
---|
338 | $logs = array( |
---|
339 | $core->auth->getInfo('user_cn'), |
---|
340 | $posts->post_title, |
---|
341 | $core->blog->url.$core->url->getBase($posts->post_type). |
---|
342 | '/'.$posts->post_url.'#c'.$old->comment_id |
---|
343 | ); |
---|
344 | |
---|
345 | $core->activityReport->addLog('comment','update',$logs); |
---|
346 | } |
---|
347 | |
---|
348 | public static function trackbackCreate($cur,$comment_id) |
---|
349 | { |
---|
350 | global $core; |
---|
351 | if (!$cur->comment_trackback) return; |
---|
352 | |
---|
353 | $posts = $core->blog->getPosts(array('post_id'=>$cur->post_id,'limit'=>1)); |
---|
354 | |
---|
355 | $logs = array( |
---|
356 | $cur->comment_author, |
---|
357 | $cur->comment_url, |
---|
358 | $posts->post_title, |
---|
359 | $core->blog->url.$core->url->getBase($posts->post_type). |
---|
360 | '/'.$posts->post_url |
---|
361 | ); |
---|
362 | |
---|
363 | $core->activityReport->addLog('comment','trackback',$logs); |
---|
364 | } |
---|
365 | |
---|
366 | public static function categoryCreate($cur,$cat_id) |
---|
367 | { |
---|
368 | global $core; |
---|
369 | |
---|
370 | $logs = array( |
---|
371 | $cur->cat_title, |
---|
372 | $core->auth->getInfo('user_cn'), |
---|
373 | $core->blog->url.$core->url->getBase('category').'/'.$cur->cat_url |
---|
374 | ); |
---|
375 | |
---|
376 | $core->activityReport->addLog('category','create',$logs); |
---|
377 | } |
---|
378 | |
---|
379 | public static function categoryUpdate($cur,$cat_id) |
---|
380 | { |
---|
381 | global $core; |
---|
382 | |
---|
383 | $logs = array( |
---|
384 | $cur->cat_title, |
---|
385 | $core->auth->getInfo('user_cn'), |
---|
386 | $core->blog->url.$core->url->getBase('category').'/'.$cur->cat_url |
---|
387 | ); |
---|
388 | |
---|
389 | $core->activityReport->addLog('category','update',$logs); |
---|
390 | } |
---|
391 | |
---|
392 | public static function userCreate($cur,$user_id) |
---|
393 | { |
---|
394 | global $core; |
---|
395 | $user_cn = dcUtils::getUserCN($cur->user_id, $cur->user_name, |
---|
396 | $cur->user_firstname, $cur->user_displayname); |
---|
397 | |
---|
398 | $logs = array( |
---|
399 | $user_cn, |
---|
400 | $core->auth->getInfo('user_cn') |
---|
401 | ); |
---|
402 | |
---|
403 | $core->activityReport->addLog('user','create',$logs); |
---|
404 | } |
---|
405 | |
---|
406 | public static function usertUpdate($cur,$user_id) |
---|
407 | { |
---|
408 | global $core; |
---|
409 | $user_cn = dcUtils::getUserCN($cur->user_id, $cur->user_name, |
---|
410 | $cur->user_firstname, $cur->user_displayname); |
---|
411 | |
---|
412 | $logs = array( |
---|
413 | $user_cn, |
---|
414 | $core->auth->getInfo('user_cn') |
---|
415 | ); |
---|
416 | |
---|
417 | $core->activityReport->addLog('user','update',$logs); |
---|
418 | } |
---|
419 | |
---|
420 | public static function userDelete($user_id) |
---|
421 | { |
---|
422 | global $core; |
---|
423 | $users = $core->getUser($id); |
---|
424 | $user_cn = dcUtils::getUserCN($users->user_id, $users->user_name, |
---|
425 | $users->user_firstname, $users->user_displayname); |
---|
426 | |
---|
427 | $logs = array( |
---|
428 | $user_cn, |
---|
429 | $core->auth->getInfo('user_cn') |
---|
430 | ); |
---|
431 | |
---|
432 | $core->activityReport->addLog('user','delete',$logs); |
---|
433 | } |
---|
434 | } |
---|
435 | ?> |
---|