/[drupal]/contributions/modules/abuse/abuse.admin.inc
ViewVC logotype

Contents of /contributions/modules/abuse/abuse.admin.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Mon Apr 7 16:37:02 2008 UTC (19 months, 2 weeks ago) by btmash
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Dev version of 6.x code
1 <?php
2
3 // A LIST OF ALL THE ADMIN FUNCTIONS
4
5 function abuse_admin_settings(&$form_state) {
6 $form = array();
7 $form['abuse_reasons_configuration'] = array(
8 '#title' => t('Reasons'),
9 '#type' => 'item',
10 '#value' => t('You can configure the list of reasons at !link', array('!link' => l('Reason configuration settings', 'admin/settings/abuse/reasons')))
11 );
12 // Configure which content types can be flagged
13 $form['contenttypes'] = array(
14 '#title' => t('Enable flagging for these content types'),
15 '#type' => 'fieldset',
16 '#collapsible' => TRUE,
17 '#collapsed' => FALSE,
18 );
19 foreach (node_get_types() as $type => $name) {
20 $form['contenttypes'][ABUSE_CONTENT_NODE_TYPE . $type] = array(
21 '#title' => $name->type,
22 '#type' => 'checkbox',
23 '#return_value' => 1,
24 '#default_value' => variable_get(ABUSE_CONTENT_NODE_TYPE . $type, 0),
25 );
26 }
27 $form['contenttypes'][ABUSE_CONTENT_COMMENTS] = array(
28 '#title' => t('comments'),
29 '#type' => 'checkbox',
30 '#return_value' => 1,
31 '#default_value' => variable_get(ABUSE_CONTENT_COMMENTS, 0),
32 );
33 $form['contenttypes'][ABUSE_CONTENT_USERS] = array(
34 '#title' => t('users'),
35 '#type' => 'checkbox',
36 '#description' => t('Users is still a work in progress - do not bother till fully coded out'),
37 '#return_value' => 1,
38 '#default_value' => variable_get(ABUSE_CONTENT_USERS, 0),
39 );
40
41 // Ticketing system settings
42 $form['assigned'] = array(
43 '#title' => t('Ticketing settings'),
44 '#type' => 'fieldset',
45 '#collapsible' => TRUE,
46 '#collapsed' => FALSE,
47 );
48 $form['assigned']['abuse_assigned_moderators'] = array(
49 '#title' => t('Abuse Assigned Moderators'),
50 '#description' => t('Select this option if you have a pool of moderators and you wish to assign each one a certain number of tickets to work with.'),
51 '#type' => 'checkbox',
52 '#return_value' => TRUE,
53 '#default_value' => variable_get('abuse_assigned_moderators', FALSE)
54 );
55 $form['assigned']['abuse_num_assigned'] = array(
56 '#title' => t('Moderator queue limit'),
57 '#type' => 'textfield',
58 '#description' => t('This field is to set a maximum limit on the number of flagged items that will be added to the queue of a moderator'),
59 '#default_value' => variable_get('abuse_num_assigned', 20),
60 '#size' => 6,
61 '#maxlength' => 6,
62 );
63 $form['assigned']['abuse_cleanup_hour'] = array(
64 '#title' => t('Reset assigned ticket items (Please type hour of day)'),
65 '#type' => 'textfield',
66 '#default_value' => variable_get('abuse_cleanup_hour', 0),
67 '#size' => 2,
68 '#maxlength' => 2,
69 );
70
71 // General settings
72 $form['general_settings'] = array(
73 '#title' => t('Settings for all abuse content'),
74 '#type' => 'fieldset',
75 '#description' => t('These settings apply to all content that is allowed to be flagged into the abuse administration system'),
76 '#collapsible' => FALSE,
77 );
78
79 $form['general_settings']['abuse_threshold'] = array(
80 '#title' => t('Abuse threshold'),
81 '#type' => 'textfield',
82 '#default_value' => variable_get('abuse_threshold', 3),
83 '#size' => 6,
84 '#maxlength' => 6,
85 '#required' => TRUE,
86 );
87
88 $form['general_settings']['abuse_warn_subject'] = array(
89 '#title' => t('Warning subject'),
90 '#type' => 'textfield',
91 '#default_value' => variable_get('abuse_warn_subject', ''),
92 '#size' => 72,
93 '#required' => TRUE,
94 );
95
96 $form['general_settings']['abuse_warn_body'] = array(
97 '#title' => t('Warning body'),
98 '#type' => 'textarea',
99 '#default_value' => variable_get('abuse_warn_body', ''),
100 '#cols' => 72,
101 '#rows' => 10,
102 '#required' => TRUE,
103 );
104
105 $form['general_settings']['abuse_warn_bcc'] = array(
106 '#title' => t('Warning BCC'),
107 '#type' => 'textfield',
108 '#default_value' => variable_get('abuse_warn_bcc', ''),
109 '#size' => 72,
110 );
111
112 $form['general_settings']['abuse_form_pre'] = array(
113 '#title' => t('Abuse form intro text'),
114 '#type' => 'textarea',
115 '#default_value' => variable_get('abuse_form_pre', ''),
116 '#cols' => 72,
117 '#rows' => 10,
118 );
119
120 return system_settings_form($form);
121 }
122
123 function abuse_admin_reason_settings(&$form_state) {
124 $form = array();
125 $form['add_reason'] = array(
126 '#type' => 'fieldset',
127 '#title' => t('Add new reason'),
128 '#weight' => -1,
129 '#collapsible' => TRUE,
130 '#collapsed' => TRUE,
131 );
132 $form['add_reason']['short_form'] = array(
133 '#type' => 'textfield',
134 '#title' => t('Reason'),
135 '#description' => t('Provide a short form of what the reason is'),
136 '#size' => 35,
137 '#maxlength' => 35,
138 );
139 $form['add_reason']['description'] = array(
140 '#type' => 'textarea',
141 '#title' => t('Description'),
142 '#description' => t('A more details description of what the reason is'),
143 '#rows' => 5,
144 '#cols' => 50,
145 );
146 $form['add_reason']['email_notice'] = array(
147 '#type' => 'textarea',
148 '#title' => t('Email Notice addition'),
149 '#description' => t('Text that will automatically be included in the warning email.'),
150 '#rows' => 5,
151 '#cols' => 50,
152 );
153 $form['add_reason']['add'] = array(
154 '#type' => 'submit',
155 '#value' => t('Save'),
156 );
157 $num_reasons = db_result(db_query('SELECT COUNT(arid) FROM {abuse_reasons}'));
158 if ($num_reasons > 0) {
159 $form['reason_list'] = array(
160 '#type' => 'fieldset',
161 '#title' => t('Current list of reasons - check items that you wish to remove'),
162 '#weight' => 5,
163 '#collapsible' => FALSE,
164 );
165 $reasons = _abuse_reasons();
166 $count = 0;
167 foreach ($reasons as $reason) {
168 $count++;
169 $form['reason_list']['field'. $count] = array(
170 '#type' => 'fieldset',
171 '#title' => t($reason->reason),
172 );
173 $form['reason_list']['field'. $count]['arid'. $reason->arid] = array(
174 '#type' => 'checkbox',
175 '#title' => t('Remove from of list of reasons')
176 );
177 $form['reason_list']["field$count"]['edit'] = array(
178 '#type' => 'item',
179 '#value' => l('Edit reason', 'admin/settings/abuse/reasons/edit/'.$reason->arid)
180 );
181 $form['reason_list']['field'. $count]['reason'] = array(
182 '#type' => 'item',
183 '#value' => t('Description') .': '. t($reason->description)
184 );
185 $form['reason_list']['field'. $count]['argumentation'] = array(
186 '#type' => 'item',
187 '#value' => t('Email content') .': '. t($reason->argumentation)
188 );
189 }
190 $form['reason_list']['remove'] = array(
191 '#type' => 'submit',
192 '#value' => t('Remove'),
193 );
194 }
195 return $form;
196 }
197
198 function abuse_admin_edit_reason($form_state, $arid) {
199 $reason = db_fetch_object(db_query("SELECT * FROM {abuse_reasons} WHERE arid=%d", $arid));
200 if (!$reason->arid) {
201 drupal_not_found();
202 }
203 $form = array();
204 $form['arid'] = array(
205 '#type' => 'value',
206 '#value' => $reason->arid,
207 );
208 $form['short_form'] = array(
209 '#type' => 'textfield',
210 '#title' => t('Reason'),
211 '#description' => t('Provide a short form of what the reason is'),
212 '#default_value' => $reason->reason,
213 '#size' => 35,
214 '#maxlength' => 35,
215 );
216 $form['description'] = array(
217 '#type' => 'textarea',
218 '#title' => t('Description'),
219 '#description' => t('A more details description of what the reason is'),
220 '#default_value' => $reason->description,
221 '#rows' => 5,
222 '#cols' => 50,
223 );
224 $form['email_notice'] = array(
225 '#type' => 'textarea',
226 '#title' => t('Email Notice addition'),
227 '#description' => t('Text that should automatically be included in the warning email.'),
228 '#default_value' => $reason->argumentation,
229 '#rows' => 5,
230 '#cols' => 50,
231 );
232 $form['save'] = array(
233 '#type' => 'submit',
234 '#value' => t('Save')
235 );
236 $form['cancel'] = array(
237 '#type' => 'submit',
238 '#value' => t('Cancel')
239 );
240
241 return $form;
242 }
243 function abuse_admin_reason_settings_validate($form, &$form_state) {
244 $values = $form_state['values'];
245 $op = $form_state['clicked_button']['#value'];
246 if ($values['op'] == t('Save')) {
247 if (empty ($values['short_form'])) {
248 form_set_error('short_form', t('You MUST provide a reason.'));
249 }
250 elseif (empty($values['description'])) {
251 form_set_error('description', t('You MUST provide a description of the reason.'));
252 }
253 elseif (empty($values['email_notice'])) {
254 form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));
255 }
256 }
257 }
258
259 function abuse_admin_reason_settings_submit($form, &$form_state) {
260 $values = $form_state['values'];
261 $op = $form_state['clicked_button']['#value'];
262 if ($values['op'] == t('Save')) {
263 db_query("INSERT INTO {abuse_reasons} (reason, description, argumentation) VALUES ('%s', '%s', '%s')",
264 $values['short_form'], $values['description'], $values['email_notice']);
265 drupal_set_message(t("Added new reason to list"));
266 } elseif ($op == t('Remove')) {
267 foreach ($values as $key => $value) {
268 if (strpos($key, 'arid') === 0 && $value === 1) {
269 db_query("DELETE FROM {abuse_reasons} WHERE arid=%d", str_replace('arid', '', $key));
270 drupal_set_message("Successfully removed reason from list");
271 }
272 }
273 }
274 }
275
276 function abuse_admin_edit_reason_validate($form, &$form_state) {
277 $values = $form_state['values'];
278 $op = $form_state['clicked_button']['#value'];
279 if ($values['op'] == t('Save')) {
280 if (empty ($values['short_form'])) {
281 form_set_error('short_form', t('You MUST provide a reason.'));
282 }
283 elseif (empty($values['description'])) {
284 form_set_error('description', t('You MUST provide a description of the reason.'));
285 }
286 elseif (empty($values['email_notice'])) {
287 form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));
288 }
289 }
290 }
291
292 function abuse_admin_edit_reason_submit($form, &$form_state) {
293 $values = $form_state['values'];
294 $op = $form_state['clicked_button']['#value'];
295 if ($op == t('Save')) {
296 db_query("UPDATE {abuse_reasons} SET reason='%s', description='%s', argumentation='%s' WHERE arid=%d",
297 $values['short_form'], $values['description'], $values['email_notice'], $values['arid']);
298 drupal_set_message(t('Reason edit '.$values['arid'].' saved'));
299 }
300 $form_state['redirect'] = 'admin/settings/abuse/reasons';
301 }
302
303 /**
304 * Implement a generic moderation point
305 */
306 function abuse_admin_moderate($status = array(), $assigned_to_uid = FALSE) {
307 global $user;
308 $limit = (empty($_GET['limit'])) ? 25 : $_GET['limit'];
309
310 $content = '';
311 $query = "SELECT type, oid, status, assigned_to_uid FROM {abuse_status} WHERE (status=". implode(' OR status=', $status) .")";
312 if ($assigned_to_uid) {
313 $query .= " AND assigned_to_uid=".$user->uid;
314 }
315 $query .= " ORDER BY oid ASC";
316 $result = pager_query($query, $limit, 0, NULL);
317 $reports = array();
318 while ($object = db_fetch_object($result)) {
319 $obj = _abuse_load($object);
320 $reports[] = $obj;
321 }
322 $content = theme('abuse_page', $reports, $limit);
323 return $content;
324 }
325
326 function abuse_admin_default_callback() {
327 if (variable_get('abuse_assigned_moderators', FALSE)) {
328 return abuse_admin_moderate(array(ABUSE_PENDING, ABUSE_HIDDEN), TRUE);
329 } else {
330 return abuse_admin_moderate(array(ABUSE_PENDING));
331 }
332 }
333
334 function abuse_admin_status($type, $oid) {
335 if ('user' === strtolower($type)) {
336 return abuse_admin_user($oid);
337 }
338 $result = pager_query("SELECT type, oid, status, assigned_to_uid FROM {abuse_status} WHERE type='%s' AND oid=%d", 10, 0, NULL, $type, $oid);
339 $reports = array();
340 while ($object = db_fetch_object($result)) {
341 $obj = _abuse_load($object);
342 $reports[] = $obj;
343 }
344 if (sizeof($reports) > 0) {
345 $content = theme('abuse_page', $reports);
346 } else {
347 $anchor = NULL;
348 if ('comment' == strtolower($type)) {
349 $nid = db_result(db_query("SELECT nid FROM {comments} WHERE cid=%d", $oid));
350 $anchor = "comment-$oid";
351 } else {
352 $nid = $oid;
353 }
354 $content = t('No abuse reports for this particular piece of content - view %content', array('%content' => l(t('content'), "node/$nid", array('fragment' => $anchor))));
355 }
356 return $content;
357 }
358
359 function abuse_admin_user($uid = NULL) {
360 if (empty($uid)) {
361 return drupal_not_found();
362 }
363 $limit = (empty($_GET['limit'])) ? 25 : $_GET['limit'];
364 $node_query = "SELECT a.oid, a.type, a.status, a.assigned_to_uid FROM {abuse_status} a INNER JOIN {node} n ON a.oid=n.nid WHERE a.type='node' AND n.uid = %d AND a.status = %d ORDER BY a.oid DESC";
365 $comment_query = "SELECT a.oid, a.type, a.status, a.assigned_to_uid FROM {abuse_status} a INNER JOIN {comments} c ON a.oid=c.cid WHERE a.type='comment' AND c.uid = %d AND a.status = %d ORDER BY a.oid DESC";
366 $query = "SELECT a.oid, a.type, a.status, a.assigned_to_uid FROM (($node_query) UNION ($comment_query)) AS a ORDER BY a.oid DESC";
367 $count_query = "SELECT COUNT(*) FROM (($node_query) UNION ($comment_query)) AS counter";
368
369 $result = pager_query($query, $limit, 0, $count_query, $uid, ABUSE_REMOVED, $uid, ABUSE_REMOVED);
370 //$result = db_query("SELECT n.nid, count(a.valid) as num FROM {node} n INNER JOIN {abuse} a ON a.oid=n.nid WHERE a.type='node' AND n.uid = %d GROUP BY n.nid HAVING num <= 2 ORDER BY num DESC", $uid);
371 $reports = array();
372 while ($object = db_fetch_object($result)) {
373 $obj = _abuse_load($object);
374 $reports[] = $obj;
375 }
376 $content = theme('abuse_page', $reports, $limit);
377 return $content;
378 }
379
380 function abuse_admin_allow($type = NULL, $oid = NULL) {
381 $object = _abuse_load($type, $oid);
382 $status = FALSE;
383 $message = t('Sorry, this content could not be allowed');
384 if ($object->oid) {
385 if (_abuse_allow($type, $oid)) {
386 $status = TRUE;
387 $message = t('Item allowed');
388 }
389 }
390 return array('status' => $status, 'data' => $message);
391 }
392
393 function abuse_admin_remove($type = NULL, $oid = NULL) {
394 $object = _abuse_load($type, $oid);
395 $status = FALSE;
396 $message = t('Sorry, this content could not be removed');
397 if ($object->oid) {
398 _abuse_remove($type, $oid);
399 $status = TRUE;
400 $message = t('Item removed: %title', array('%title' => $object->title));
401 }
402 return array('status' => $status, 'data' => $message);
403 }
404
405 function abuse_admin_assign_to_superadmin($type = NULL, $oid = NULL) {
406 $object = _abuse_load($type, $oid);
407 $status = FALSE;
408 $message = t('Sorry, this content could not be sent to the super moderator');
409 if ($object->oid) {
410 _abuse_assign_superadmin($type, $oid);
411 $status = TRUE;
412 $message = t('Item sent to super moderator: %title', array('%title' => $object->title));
413 }
414 return array('status' => $status, 'data' => $message);
415 }
416
417 function abuse_admin_warn_user($type, $oid, $subject = NULL, $body = NULL, $op = 'allow') {
418 global $user, $language;
419 $object = _abuse_load($type, $oid);
420 $status = FALSE;
421 $message = t('Sorry, the user could not be warned and the operation could not be carried out');
422 if ($object->oid) {
423 $account = user_load(array('uid' => $object->uid));
424 $to = $account->name ."<".$account->mail.">";
425 $params = array();
426 $params['object'] = $object;
427 $params['account'] = $account;
428 $params['subject'] = (isset($subject)) ? $subject : variable_get('abuse_warn_subject', '');
429 $params['body'] = (isset($body)) ? $body : variable_get('abuse_warn_body', '');
430 $params['bcc'] = variable_get('abuse_warn_bcc', '');
431 drupal_mail('abuse', 'warning_email', $to, $language, $params);
432 db_query("INSERT INTO {abuse_warnings} (type, oid, created, uid, sent_by_uid) VALUES ('%s', %d, %d, %d, %d)",
433 $type, $oid, time(), $account->uid, $user->uid);
434 if ('allow' == $op) {
435 _abuse_allow($object->type, $object->oid);
436 }
437 elseif ('remove' == $op) {
438 _abuse_remove($object->type, $object->oid);
439 }
440 $status = TRUE;
441 $message = t('Your message has been sent.');
442 }
443 return array('status' => $status, 'data' => $message);
444 }
445
446 function abuse_admin_ban_user($uid) {
447 global $user;
448 $account = user_load(array('uid' => $uid));
449 $status = FALSE;
450 $message = 'User !name could not be banned.';
451 if ($user->uid > 1 && $user->uid !== $account->uid) {
452 abuse_remove_account_content($account);
453 sess_destroy_uid($uid);
454 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'mail', 0)", $account->mail);
455 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->mail);
456 db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);
457 $status = TRUE;
458 $message = "The user !name has been banned.";
459 }
460 return array('status' => $status, 'data' => t($message, array('!name' => $account->name)));
461 }
462
463 function abuse_admin_moderate_content(&$form_state, $type = NULL, $oid = NULL, $inline = FALSE) {
464 $object = _abuse_load($type, $oid);
465 if (!isset($object)) {
466 return drupal_not_found();
467 }
468
469 global $user;
470 static $run_once;
471 $form = array();
472 $form['#validate'][] = 'abuse_admin_moderate_content_validate';
473 $form['#submit'][] = 'abuse_admin_moderate_content_submit';
474
475 if (!$inline) {
476 $form['target'] = array(
477 '#type' => 'item',
478 '#value' => "<!-- Empty Section -->",
479 '#prefix' => '<div id="message-wrapper" class="message status">',
480 '#suffix' => '</div>' ,
481 );
482 $run_once = TRUE;
483 }
484
485 $form['object_type'] = array(
486 '#type' => 'hidden',
487 '#value' => $object->type
488 );
489 $form['object_oid'] = array(
490 '#type' => 'hidden',
491 '#value' => $object->oid,
492 );
493 $form['object_uid'] = array(
494 '#type' => 'hidden',
495 '#value' => $object->uid,
496 );
497
498 if ($inline) {
499 $form['redirect'] = array(
500 '#type' => 'hidden',
501 '#value' => $_GET['q'],
502 );
503 }
504
505 $form['allow'] = array(
506 '#type' => 'fieldset',
507 '#title' => t('Allow content on site?'),
508 '#collapsible' => TRUE,
509 '#collapsed' => TRUE,
510 );
511 $form['allow']['message'] = array(
512 '#type' => 'item',
513 '#value' => t('Are you sure you want to allow !content?', array('!content' => '<em>'. $object->title .'</em>'))
514 );
515 $form['allow']['allow'] = array(
516 '#type' => 'submit',
517 '#value' => t('allow'),
518 //'#ahah' => $temp,
519 );
520
521 $form['remove'] = array(
522 '#type' => 'fieldset',
523 '#title' => t('Remove content from site?'),
524 '#collapsible' => TRUE,
525 '#collapsed' => TRUE,
526 );
527 $form['remove']['message'] = array(
528 '#type' => 'item',
529 '#value' => t('Are you sure you want to remove !content?', array('!content' => '<em>'. $object->title .'</em>'))
530 );
531 $form['remove']['remove'] = array(
532 '#type' => 'submit',
533 '#value' => t('remove'),
534 );
535
536 if (variable_get('abuse_assigned_moderators', FALSE) && !user_access(ADMINISTER_ALL_ABUSE_REPORTS)) {
537 $form['assign'] = array(
538 '#type' => 'submit',
539 '#value' => t('assign to superadmin'),
540 );
541 }
542
543 $form['warn']['allow'] = array(
544 '#type' => 'fieldset',
545 '#title' => t('Warn and Allow'),
546 '#collapsible' => TRUE,
547 '#collapsed' => TRUE,
548 );
549
550 $form['warn']['remove'] = array(
551 '#type' => 'fieldset',
552 '#title' => t('Warn and Remove'),
553 '#collapsible' => TRUE,
554 '#collapsed' => TRUE,
555 );
556
557 $form['warn']['allow']['allow_subject'] = $form['warn']['remove']['remove_subject'] = array(
558 '#type' => 'textfield',
559 '#title' => t('Warning subject'),
560 '#default_value' => variable_get('abuse_warn_subject', ''),
561 '#cols' => 72,
562 '#rows' => 10,
563 '#required' => TRUE,
564 );
565 $form['warn']['allow']['allow_body'] = $form['warn']['remove']['remove_body'] = array(
566 '#type' => 'textarea',
567 '#title' => t('Warning subject'),
568 '#default_value' => t(variable_get('abuse_warn_body', '')),
569 '#size' => 72,
570 '#required' => TRUE,
571 '#description' => t('available fields are !title, !url, !name, and !id')
572 );
573 $form['warn']['allow']['allow_warn'] = array(
574 '#type' => 'submit',
575 '#value' => t('warn and allow'),
576 );
577
578 $form['warn']['remove']['remove_warn'] = array(
579 '#type' => 'submit',
580 '#value' => t('warn and remove'),
581 );
582
583 if ($user->uid !== $object->uid && $object->uid > 1) {
584 $form['ban'] = array(
585 '#type' => 'fieldset',
586 '#title' => t('Ban !user?', array('!user' => $object->name)),
587 '#collapsible' => TRUE,
588 '#collapsed' => TRUE,
589 );
590 $form['ban']['confirmation_message'] = array(
591 '#type' => 'item',
592 '#value' => t('Are you sure you want to ban !name?', array('!name' => '<em>'. $object->name .'</em>'))
593 );
594 $form['ban']['ban'] = array(
595 '#type' => 'submit',
596 '#value' => t('ban')
597 );
598 }
599 return $form;
600 }
601
602 function abuse_admin_moderate_content_validate($form, &$form_state) {
603 global $user;
604 $values = $form_state['values'];
605 $op = $form_state['clicked_button']['#value'];
606 if (t('ban') === $op && ($values['object_uid'] || $values['object_uid'] <= 1)) {
607 form_set_error(NULL, t('User cannot be banned'));
608 }
609 }
610
611 function abuse_admin_moderate_content_submit($form, &$form_state) {
612 global $user;
613 $values = $form_state['values'];
614 $op = $form_state['clicked_button']['#value'];
615 if ($values['redirect']) {
616 $form_state['redirect'] = $values['redirect'];
617 }
618 $message = _abuse_admin_moderate_content_shared($values, $op);
619 drupal_set_message($message['data']);
620 }
621
622
623 function abuse_admin_moderate_content_js() {
624 global $user;
625 $values = $_POST;
626 $op = $values['op'];
627 $message = _abuse_admin_moderate_content_shared($values, $op);
628 drupal_json($message);
629 }
630
631 function _abuse_admin_moderate_content_shared($values, $op) {
632 $message = array('status' => FALSE, 'data' => t('Sorry, could not perform requested operation.'));
633 switch($op) {
634 case t('allow'):
635 $message = abuse_admin_allow($values['object_type'], $values['object_oid']);
636 break;
637 case t('remove'):
638 $message = abuse_admin_remove($values['object_type'], $values['object_oid']);
639 break;
640 case t('warn and allow'):
641 $message = abuse_admin_warn_user($values['object_type'], $values['object_oid'], $values['allow_subject'], $values['allow_body'], 'allow');
642 break;
643 case t('warn and remove'):
644 $message = abuse_admin_warn_user($values['object_type'], $values['object_oid'], $values['remove_subject'], $values['remove_body'], 'remove');
645 break;
646 case t('ban'):
647 $message = abuse_admin_ban_user($values['object_uid']);
648 break;
649 case t('assign to superadmin'):
650 $message = abuse_admin_assign_to_superadmin($values['object_type'], $values['object_oid']);
651 break;
652 }
653 return $message;
654 }
655
656 function abuse_admin_ban(&$form_state, $account, $inline = FALSE) {
657 global $user;
658 $form = array();
659 $form['#validate'][] = array('abuse_admin_ban_validate');
660 $form['#submit'][] = array('abuse_admin_ban_submit');
661
662 $form['#attributes'] = array('class' => 'abuse-admin-ban');
663 if ($user->uid === $account->uid || $account->uid === 1) {
664 $form['notallowed'] = array(
665 '#type' => 'item',
666 '#value' => t('Sorry, you are not allowed to ban this user'),
667 );
668 } else {
669 if ($inline) {
670 $form['message'] = array(
671 '#title' => t('Ban !user', array('!user' => $account->name)),
672 '#type' => 'fieldset',
673 '#collapsible' => TRUE,
674 '#collapsed' => TRUE
675 );
676 $form['redirect'] = array(
677 '#type' => 'value',
678 '#value' => $_GET['q'],
679 );
680 $form['ajax'] = array(
681 '#type' => 'hidden',
682 '#default_value' => '0',
683 );
684 }
685 $form['message']['uid'] = array(
686 '#type' => 'value',
687 '#value' => $account->uid
688 );
689 $form['message']['confirmation_message'] = array(
690 '#type' => 'item',
691 '#value' => t('Are you sure you want to ban !name?', array('!name' => '<em>'. $account->name .'</em>'))
692 );
693 $form['message']['confirm'] = array(
694 '#type' => 'submit',
695 '#value' => t('Yes')
696 );
697 if ($inline === FALSE) {
698 $form['message']['cancel'] = array(
699 '#type' => 'item',
700 '#value' => l(t('No'), 'admin/content/abuse')
701 );
702 }
703 }
704 return $form;
705 }
706
707 function abuse_admin_ban_validate($form, &$form_state) {
708 global $user;
709 $values = $form_state['values'];
710 $op = $form_state['clicked_button']['#value'];
711 $account = user_load(array('uid' => $values['uid']));
712 if (($user->uid === 1 || $user->uid === $account->uid) && t('Yes') == $op) {
713 form_set_error(NULL, t('You cannot ban the site administrator or yourself.'));
714 }
715 }
716
717 function abuse_admin_ban_submit($form, &$form_state) {
718 global $user;
719 $values = $form_state['values'];
720 $op = $form_state['clicked_button']['#value'];
721 $account = user_load(array('uid' => $values['uid']));
722 if ($values['redirect']) {
723 $form_state['redirect'] = $values['redirect'];
724 } else {
725 $form_state['redirect'] = 'admin/content/abuse';
726 }
727 if ($user->uid > 1 && $user->uid !== $account->uid && t('Yes') == $op) {
728 abuse_remove_account_content($account);
729
730 // ban this email address
731 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'mail', 0)", $account->mail);
732
733 // block this user
734 db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);
735 db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->name);
736 db_query("DELETE FROM {sessions} WHERE uid=%d", $uid);
737 drupal_set_message(t('The user !name has been banned.', array('!name' => $account->name)));
738 }
739 }
740
741 /**
742 * Remove user content
743 *
744 * @param user $account account of user whose content is being blocked
745 */
746 function abuse_remove_account_content($account) {
747 $result = db_query("SELECT nid FROM {node} WHERE uid=%d", $account->uid);
748 while ($nid = db_fetch_object($result)) {
749 _abuse_remove('node', $nid->nid);
750 }
751
752 // remove their comments:
753 $result = db_query("SELECT cid FROM {comments} WHERE uid=%d", $account->uid);
754 while ($cid = db_fetch_object($result)) {
755 _abuse_remove('comment', $cid->cid);
756 }
757 return TRUE;
758 }
759
760
761 /**
762 * Implement mailing functionality
763 */
764 function abuse_mail($key, &$message, $params) {
765 $account = $params['account'];
766 $object = $params['object'];
767 $vars = array(
768 '!title' => $object->title,
769 '!url' => $object->link,
770 '!name' => $account->name,
771 '!id' => $object->link,
772 );
773 $subject = strtr($params['subject'], $vars);
774 $body = strtr($params['body'], $vars);
775 $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
776 $message['body'][] = drupal_html_to_text($body);
777 }
778
779 function _abuse_get_offence_count($uid) {
780 static $offences_count;
781 if (!isset($offences_count["uid-$uid"])) {
782 $offences_count["uid-$uid"] = db_result(db_query("SELECT count(*) FROM {node} n INNER JOIN {abuse_status} a ON a.oid=n.nid WHERE a.type='node' AND n.uid=%d AND a.status=%d", $uid, ABUSE_REMOVED));
783 $offences_count["uid-$uid"] += db_result(db_query("SELECT count(*) FROM {comments} c INNER JOIN {abuse_status} a ON a.oid=c.cid WHERE a.type='comment' AND c.uid=%d AND a.status=%d", $uid, ABUSE_REMOVED));
784 }
785 return $offences_count["uid-$uid"];
786 }
787
788 function _abuse_get_warning_count($uid) {
789 static $warnings_count;
790 if (!isset($warnings_count["uid-$uid"])) {
791 $warnings_count["uid-$uid"] = db_result(db_query('SELECT count(*) FROM {abuse_warnings} WHERE uid=%d', $uid));
792 }
793 return $warnings_count["uid-$uid"];
794 }
795
796 function template_preprocess_abuse_page(&$variables) {
797 drupal_add_js('/misc/jquery.form.js');
798 drupal_add_js("Drupal.base_url = '". url('') ."';", 'inline');
799 drupal_add_js(drupal_get_path('module', 'abuse') .'/abuse.js');
800 }
801
802 function template_preprocess_abuse_report(&$variables) {
803 static $counter;
804 if (!isset($counter)) {
805 $counter = 1;
806 }
807 $object = $variables['object'];
808 $variables['account'] = user_load(array('uid' => $object->uid));
809 $variables['offences'] = number_format(_abuse_get_offence_count($object->uid));
810 $variables['warnings'] = number_format(_abuse_get_warning_count($object->uid));
811 $variables['nodeType'] = ($object->type == 'comment') ? "Comment" : "Movie";
812
813 $variables['moderate'] = drupal_get_form('abuse_admin_moderate_content'. $counter++, $object->type, $object->oid, TRUE);
814 }
815
816 ?>

  ViewVC Help
Powered by ViewVC 1.1.2