/[drupal]/contributions/modules/moderation_log/moderation_log.module
ViewVC logotype

Contents of /contributions/modules/moderation_log/moderation_log.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Jul 15 13:37:13 2009 UTC (4 months, 1 week ago) by mikhailian
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +307 -0 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /**
3 * $Id: moderation_log.module,v 1.1.4.3.2.1 2009/03/08 11:41:55 mikhailian Exp $ */
4
5 /**
6 * Display help and module information
7 * @param section which section of the site we're displaying help
8 * @return help text for section
9 */
10 function moderation_log_help($path, $arg) {
11
12 $output = '';
13
14 switch ($section) {
15 case "admin/modules#description":
16 $output = t("Logs the comment and node updates done by site moderators and displays them in a block.");
17 break;
18 }
19
20 return $output;
21
22 } // function moderation_log_help
23
24 /**
25 * Valid permissions for this module
26 * @return An array of valid permissions for the moderation_log module
27 */
28 function moderation_log_perm() {
29
30 return array('access content');
31
32 } // function moderation_log_perm()
33
34 /**
35 * Implementation of hook_nodeapi
36 */
37 function moderation_log_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
38 global $user;
39
40 switch ($op) {
41
42 case 'update':
43 case 'delete':
44 if ($node->uid != $user->uid && $_POST['moderation_reason'] != NULL) {
45 foreach($_POST['moderation_reason'] as $value) {
46 db_query('INSERT INTO {moderation_reason_node} VALUES (%d, %d, %d)', $node->nid, $value, $user->uid);
47 }
48 db_query('INSERT INTO {moderation_log_node} VALUES (%d, %d, %d, \'%s\', \'%s\', \'%s\')', $user->uid, $node->nid, time(), $op, $node->type, $node->title);
49 }
50 break;
51 }
52 }
53
54 /**
55 * Implementation of hook_comment().
56 */
57 function moderation_log_comment(&$comment, $op) {
58 global $user;
59 switch ($op) {
60 case 'update':
61 case 'delete':
62 if($comment->uid != $user->uid && $_POST['moderation_reason'] != NULL) {
63 foreach($_POST['moderation_reason'] as $value) {
64 db_query('INSERT INTO {moderation_reason_comment} VALUES (%d, %d, %d)', $comment->cid, $value, $user->uid);
65 }
66 db_query('INSERT INTO {moderation_log_comment} VALUES (%d, %d, %d, \'%s\', \'%s\')', $user->uid, $comment->cid, time(), $op, $comment->subject);
67 }
68 break;
69 }
70 }
71
72 /**
73 * Moderation Log block
74 */
75 function moderation_log_block($op='list', $delta=0) {
76 if ($op == "list") {
77 $block[0]["info"] = t("Moderation Log");
78 return $block;
79 } else if ($op == 'view') {
80
81 $moderation_log_listsize=variable_get('moderation_log_listsize', 25);
82 // Node moderation statistics
83 $query = "SELECT mln.uid uid, u.name name, count(mln.uid) count
84 FROM {moderation_log_node} mln
85 LEFT JOIN {users} u ON u.uid=mln.uid
86 GROUP BY mln.uid ORDER BY count DESC
87 LIMIT %d";
88 // get the links
89 $queryResult = db_query($query,$moderation_log_listsize);
90 $block_content .= '<table>';
91 $block_content .= '<tr><th colspan="2">' . l(t("Node moderation statistics"), 'moderation_log_node') .'</th></tr>';
92 while ($links = db_fetch_object($queryResult)) {
93 $block_content .= '<tr>';
94 $block_content .= '<td>' . theme('username', $links) . '</td>';
95 $block_content .= '<td>' . $links->count . '</td>';
96 $block_content .= '</tr>';
97 }
98 $block_content .= '</table>';
99
100 // Comment moderation statistics
101 $query = "SELECT mlc.uid uid, u.name name, count(mlc.uid) count
102 FROM {moderation_log_comment} mlc
103 LEFT JOIN {users} u ON u.uid=mlc.uid
104 GROUP BY mlc.uid ORDER BY count DESC
105 LIMIT %d";
106 // get the links
107 $queryResult = db_query($query,$moderation_log_listsize);
108 $block_content .= '<table>';
109 $block_content .= '<tr><th colspan="2">' .l(t("Comment moderation statistics"), 'moderation_log_comment') .'</th></tr>';
110 while ($links = db_fetch_object($queryResult)) {
111 $block_content .= '<tr>';
112 $block_content .= '<td>' . theme('username', $links) . '</td>';
113 $block_content .= '<td>' . $links->count . '</td>';
114 $block_content .= '</tr>';
115 }
116 $block_content .= '</table>';
117 }
118
119 // check to see if there was any content before setting up the block
120 if ($block_content == '') {
121 // no content from a week ago, return nothing.
122 return;
123 }
124
125 // set up the block
126 $block['subject'] = t("Moderation Log");
127 $block['content'] = $block_content;
128 return $block;
129 } // end moderation_log_block
130
131
132 /**
133 * Cronjob to execute on expired moderation logs
134 */
135 function moderation_log_cron() {
136 $timespan = time() - variable_get('moderation_log_expire', 365)*86400;
137 db_query("DELETE FROM {moderation_log_node} WHERE date < %d", $timespan);
138 db_query("DELETE FROM {moderation_log_comment} WHERE date < %d", $timespan);
139 }
140
141 /**
142 * hook_menu() implementation
143 */
144 function moderation_log_menu() {
145 $items = array();
146 $items['moderation_log_node'] = array(
147 'title' => 'Moderation Log for nodes',
148 'page callback' => 'moderation_log_nodepage',
149 'access arguments' => array('access content'),
150 'type' => MENU_CALLBACK
151 );
152 $items['moderation_log_comment'] = array(
153 'title' => 'Moderation Log for comments',
154 'page callback' => 'moderation_log_commentpage',
155 'access arguments' => array('access content'),
156 'type' => MENU_CALLBACK
157 );
158 return $items;
159 }
160
161 /**
162 * Detailed moderation log for nodes
163 */
164 function moderation_log_nodepage() {
165 $page_content = "";
166 $header = array(
167 array('data' => t('Date'), 'field' => 'date', 'sort' => 'desc'),
168 array('data' => t('Title'), 'field' => 'title'),
169 array('data' => t('Moderator'), 'field' => 'name',),
170 array('data' => t('Action'), 'field' => 'action'),
171 array('data' => t('Reason'), 'field' => 'reason')
172 );
173 $rows = array();
174
175 $sql = "SELECT mln.nid nid, mln.uid uid, u.name name, mln.date date,
176 mln.action action, mln.type type, mln.title title,
177 GROUP_CONCAT(td.name separator ', ') AS reason
178 FROM {moderation_log_node} mln
179 LEFT JOIN ({users} u, {moderation_reason_node} mrn, {term_data} td)
180 ON (u.uid=mln.uid AND mln.nid=mrn.nid AND td.tid=mrn.tid)
181 GROUP BY mln.nid";
182 $sql .= tablesort_sql($header);
183 $result = pager_query($sql, variable_get('moderation_log_listsize', 25));
184
185 while ($node = db_fetch_object($result)) {
186 $row = array(
187 format_date($node->date,'medium'),
188 l($node->title, 'node/'.$node->nid),
189 l($node->name, 'user/'.$node->uid),
190 $node->action,
191 $node->reason
192 );
193 $rows[] = $row;
194 }
195
196 if (!$rows) {
197 $rows[] = array(
198 array('data' => t('No data.'), 'colspan' => count($header))
199 );
200 }
201
202 $pager = theme('pager', NULL, variable_get('moderation_log_listsize', 25), 0);
203 if (!empty($pager)) {
204 $rows[] = array(array('data' => $pager, 'colspan' => count($header)));
205 }
206
207 $attributes = array('class' => "moderation_log");
208
209 print theme('page', theme('table', $header, $rows, $attributes));
210
211 }
212
213 /**
214 * Detailed moderation statistics for comments
215 */
216 function moderation_log_commentpage() {
217 $page_content = "";
218 $header = array(
219 array('data' => t('Date'), 'field' => 'date', 'sort' => 'desc'),
220 array('data' => t('Subject'), 'field' => 'subject'),
221 array('data' => t('Moderator'), 'field' => 'name',),
222 array('data' => t('Action'), 'field' => 'action'),
223 array('data' => t('Reason'), 'field' => 'reason')
224 );
225 $rows = array();
226
227 $sql = "SELECT mlc.cid, mlc.uid uid, u.name name,
228 mlc.date date, mlc.action action, mlc.subject subject,
229 GROUP_CONCAT(td.name separator ', ') reason
230 FROM {moderation_log_comment} mlc
231 LEFT JOIN ({users} u, {moderation_reason_comment} mrc, {term_data} td)
232 ON u.uid=mlc.uid AND mrc.tid=td.tid AND mlc.cid=mrc.cid
233 GROUP BY mlc.cid";
234 $sql .= tablesort_sql($header);
235 $result = pager_query($sql, variable_get('moderation_log_listsize', 25));
236
237 while ($node = db_fetch_object($result)) {
238 $row = array(
239 format_date($node->date,'medium'),
240 l($node->subject, 'node/'.$node->nid),
241 l($node->name, 'user/'.$node->uid),
242 $node->action,
243 $node->reason
244 );
245 $rows[] = $row;
246 }
247
248 if (!$rows) {
249 $rows[] = array(
250 array('data' => t('No data.'), 'colspan' => count($header))
251 );
252 }
253
254 $pager = theme('pager', NULL, variable_get('moderation_log_listsize', 25), 0);
255 if (!empty($pager)) {
256 $rows[] = array(array('data' => $pager, 'colspan' => count($header)));
257 }
258
259 $attributes = array('class' => "moderation_log");
260
261 print theme('page', theme('table', $header, $rows, $attributes));
262
263 }
264 /**
265 * Configuration page
266 */
267 function moderation_log_settings() {
268
269 // only administrators can access this function
270 if (!user_access('access administration pages')) {
271 return message_access();
272 }
273
274 // 4.7 forms API
275 $form['moderation_log_listsize'] = array('#type' => 'textfield',
276 '#title' => t('Maximum list size'),
277 '#default_value' => variable_get('moderation_log_listsize', 25),
278 '#description' => t("The maximum number of moderators to display in the block as well as the page size for the detailed statistics"),
279 '#maxlength' => '2', '#size' => '2');
280
281 $form['moderation_log_expire'] = array('#type' => 'textfield',
282 '#title' => t('Number of days after which the Moderation Log statistics will be expired.'),
283 '#default_value' => variable_get('moderation_log_expire', 365),
284 '#description' => t("How many days to keep the moderation logs"),
285 '#maxlength' => '5', '#size' => '5');
286 return $form;
287 }
288
289 function moderation_log_form_alter(&$form, &$form_state, $form_id) {
290 if ((($form_id == "node_delete_confirm" || $form_id == "forum_node_form") && user_access('administer nodes')) ||
291 (($form_id == "comment_confirm_delete" || $form_id == "comment_form") && user_access('administer comments'))) {
292 $result = db_query("SELECT td.tid,td.name FROM {term_data} td JOIN ({vocabulary} v) ON (v.vid=td.vid) WHERE v.name='Rulez'");
293 $_moderation_reason = array();
294 while ($line = db_fetch_array($result)) {
295 $_moderation_reason[$line['tid']] = $line['name'];
296 }
297 if ($_moderation_reason) {
298 $form['moderation_reason'] = array(
299 '#type' => 'checkboxes',
300 '#title' => t('Moderation Reason'),
301 '#options' => $_moderation_reason
302 );
303 }
304 }
305 return $form;
306 }
307

  ViewVC Help
Powered by ViewVC 1.1.2