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

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

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

revision 1.1.2.2 by btmash, Wed May 14 19:13:19 2008 UTC revision 1.1.2.3 by btmash, Fri Jul 18 15:52:51 2008 UTC
# Line 41  function abuse_admin_settings(&$form_sta Line 41  function abuse_admin_settings(&$form_sta
41      '#return_value' => 1,      '#return_value' => 1,
42      '#default_value' => variable_get(ABUSE_CONTENT_USERS, 0),      '#default_value' => variable_get(ABUSE_CONTENT_USERS, 0),
43    );    );
44    
45    // Ticketing system settings    // Ticketing system settings
46    $form['assigned'] = array(    $form['assigned'] = array(
47      '#title' => t('Ticketing settings'),      '#title' => t('Ticketing settings'),
# Line 84  function abuse_admin_settings(&$form_sta Line 84  function abuse_admin_settings(&$form_sta
84      '#title' => t('Abuse threshold'),      '#title' => t('Abuse threshold'),
85      '#type' => 'textfield',      '#type' => 'textfield',
86      '#default_value' => variable_get('abuse_threshold', 3),      '#default_value' => variable_get('abuse_threshold', 3),
87      '#size' => 6,      '#size' => 6,
88      '#maxlength' => 6,      '#maxlength' => 6,
89      '#required' => TRUE,      '#required' => TRUE,
90    );    );
91    
# Line 93  function abuse_admin_settings(&$form_sta Line 93  function abuse_admin_settings(&$form_sta
93      '#title' => t('Warning subject'),      '#title' => t('Warning subject'),
94      '#type' => 'textfield',      '#type' => 'textfield',
95      '#default_value' => variable_get('abuse_warn_subject', t('Abuse warning')),      '#default_value' => variable_get('abuse_warn_subject', t('Abuse warning')),
96      '#size' => 72,      '#size' => 72,
97      '#required' => TRUE,      '#required' => TRUE,
98    );    );
99    
100    $form['general_settings']['abuse_warn_body'] = array(    $form['general_settings']['abuse_warn_body'] = array(
101      '#title' => t('Warning body'),      '#title' => t('Warning body'),
102      '#type' => 'textarea',      '#type' => 'textarea',
# Line 110  function abuse_admin_settings(&$form_sta Line 110  function abuse_admin_settings(&$form_sta
110      '#title' => t('Warning BCC'),      '#title' => t('Warning BCC'),
111      '#type' => 'textfield',      '#type' => 'textfield',
112      '#default_value' => variable_get('abuse_warn_bcc', ''),      '#default_value' => variable_get('abuse_warn_bcc', ''),
113      '#size' => 72,      '#size' => 72,
114    );    );
115    
116    $form['general_settings']['abuse_form_pre'] = array(    $form['general_settings']['abuse_form_pre'] = array(
117      '#title' => t('Abuse form intro text'),      '#title' => t('Abuse form intro text'),
118      '#type' => 'textarea',      '#type' => 'textarea',
119      '#default_value' => variable_get('abuse_form_pre', ''),      '#default_value' => variable_get('abuse_form_pre', ''),
120      '#cols' => 72,      '#cols' => 72,
121      '#rows' => 10,      '#rows' => 10,
122    );    );
123    
124    return system_settings_form($form);    return system_settings_form($form);
125  }  }
126    
# Line 241  function abuse_admin_edit_reason($form_s Line 241  function abuse_admin_edit_reason($form_s
241      '#type' => 'submit',      '#type' => 'submit',
242      '#value' => t('Cancel')      '#value' => t('Cancel')
243    );    );
244    
245    return $form;    return $form;
246  }  }
247    
248  function abuse_admin_reason_settings_validate($form, &$form_state) {  function abuse_admin_reason_settings_validate($form, &$form_state) {
249    $values = $form_state['values'];    $values = $form_state['values'];
250    $op = $form_state['clicked_button']['#value'];    $op = $form_state['clicked_button']['#value'];
251    if ($values['op'] == t('Save')) {    if ($values['op'] == t('Save')) {
252      if (empty ($values['short_form'])) {      if (empty ($values['short_form'])) {
253        form_set_error('short_form', t('You MUST provide a reason.'));        form_set_error('short_form', t('You MUST provide a reason.'));
254      }      }
255      elseif (empty($values['description'])) {      elseif (empty($values['description'])) {
256        form_set_error('description', t('You MUST provide a description of the reason.'));        form_set_error('description', t('You MUST provide a description of the reason.'));
257      }      }
258      elseif (empty($values['email_notice'])) {      elseif (empty($values['email_notice'])) {
259        form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));        form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));
260      }      }
# Line 264  function abuse_admin_reason_settings_sub Line 265  function abuse_admin_reason_settings_sub
265    $values = $form_state['values'];    $values = $form_state['values'];
266    $op = $form_state['clicked_button']['#value'];    $op = $form_state['clicked_button']['#value'];
267    if ($values['op'] == t('Save')) {    if ($values['op'] == t('Save')) {
268      db_query("INSERT INTO {abuse_reasons} (reason, description, argumentation) VALUES ('%s', '%s', '%s', %d)",      db_query("INSERT INTO {abuse_reasons} (reason, description, argumentation) VALUES ('%s', '%s', '%s')",
269        $values['short_form'], $values['description'], $values['email_notice']);        $values['short_form'], $values['description'], $values['email_notice']);
270      drupal_set_message(t("Added new reason to list"));      drupal_set_message(t("Added new reason to list"));
271    }    }
# Line 284  function abuse_admin_edit_reason_validat Line 285  function abuse_admin_edit_reason_validat
285    if ($values['op'] == t('Save')) {    if ($values['op'] == t('Save')) {
286      if (empty ($values['short_form'])) {      if (empty ($values['short_form'])) {
287        form_set_error('short_form', t('You MUST provide a reason.'));        form_set_error('short_form', t('You MUST provide a reason.'));
288      }      }
289      elseif (empty($values['description'])) {      elseif (empty($values['description'])) {
290        form_set_error('description', t('You MUST provide a description of the reason.'));        form_set_error('description', t('You MUST provide a description of the reason.'));
291      }      }
292      elseif (empty($values['email_notice'])) {      elseif (empty($values['email_notice'])) {
293        form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));        form_set_error('email_notice', t('You MUST provide an email notice that may be sent to the user for this reason.'));
294      }      }
# Line 311  function abuse_admin_edit_reason_submit( Line 312  function abuse_admin_edit_reason_submit(
312  function abuse_admin_moderate($status = array(), $assigned_to_uid = FALSE) {  function abuse_admin_moderate($status = array(), $assigned_to_uid = FALSE) {
313    global $user;    global $user;
314    $limit = (empty($_GET['limit'])) ? 25 : $_GET['limit'];    $limit = (empty($_GET['limit'])) ? 25 : $_GET['limit'];
315    
316    $content = '';    $content = '';
317    $query = "SELECT type, oid, status, assigned_to_uid FROM {abuse_status} WHERE (status=". implode(' OR status=', $status) .")";    $query = "SELECT type, oid, status, assigned_to_uid FROM {abuse_status} WHERE (status=". implode(' OR status=', $status) .")";
318    if ($assigned_to_uid) {    if ($assigned_to_uid) {
# Line 338  function abuse_admin_default_callback() Line 339  function abuse_admin_default_callback()
339  }  }
340    
341  function abuse_admin_status($type, $oid) {  function abuse_admin_status($type, $oid) {
342    if ('user' === strtolower($type)) {    if ('user' === drupal_strtolower($type)) {
343      return abuse_admin_user($oid);      return abuse_admin_user($oid);
344    }    }
345    $result = pager_query("SELECT type, oid, status, assigned_to_uid FROM {abuse_status} WHERE type='%s' AND oid=%d", 10, 0, NULL, $type, $oid);    $object = _abuse_load($type, $oid);
346    $reports = array();    if ($object->oid) {
347    while ($object = db_fetch_object($result)) {      $reports[] = $object;
     $obj = _abuse_load($object);  
     $reports[] = $obj;  
   }  
   if (sizeof($reports) > 0) {  
     $content = theme('abuse_page', $reports);  
348    }    }
349    else {    else {
350      $anchor = NULL;      return drupal_not_found();
     if ('comment' == strtolower($type)) {  
       $nid = db_result(db_query("SELECT nid FROM {comments} WHERE cid=%d", $oid));  
       $anchor = "comment-$oid";  
     }  
     else {  
       $nid = $oid;  
     }  
     $content = t('No abuse reports for this particular piece of content - view %content', array('%content' => l(t('content'), "node/$nid", array('fragment' => $anchor))));  
351    }    }
352    return $content;    return theme('abuse_page', $reports);
353  }  }
354    
355  function abuse_admin_user($uid = NULL) {  function abuse_admin_user($uid = NULL) {
# Line 441  function abuse_admin_warn_user($type, $o Line 429  function abuse_admin_warn_user($type, $o
429        $type, $oid, time(), $account->uid, $user->uid);        $type, $oid, time(), $account->uid, $user->uid);
430      if ('allow' == $op) {      if ('allow' == $op) {
431        _abuse_allow($object->type, $object->oid);        _abuse_allow($object->type, $object->oid);
432      }      }
433      elseif ('remove' == $op) {      elseif ('remove' == $op) {
434        _abuse_remove($object->type, $object->oid);        _abuse_remove($object->type, $object->oid);
435      }      }
# Line 455  function abuse_admin_ban_user($uid) { Line 443  function abuse_admin_ban_user($uid) {
443    global $user;    global $user;
444    $account = user_load(array('uid' => $uid));    $account = user_load(array('uid' => $uid));
445    $status = FALSE;    $status = FALSE;
446    $message = 'User !name could not be banned.';    $message = 'User @name could not be banned.';
447    if ($user->uid > 1 && $user->uid !== $account->uid) {    if ($user->uid > 1 && $user->uid !== $account->uid) {
448      abuse_remove_account_content($account);      abuse_remove_account_content($account);
449      sess_destroy_uid($uid);      sess_destroy_uid($uid);
# Line 463  function abuse_admin_ban_user($uid) { Line 451  function abuse_admin_ban_user($uid) {
451      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->mail);      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->mail);
452      db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);      db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);
453      $status = TRUE;      $status = TRUE;
454      $message = "The user !name has been banned.";      $message = "The user @name has been banned.";
455    }    }
456    return array('status' => $status, 'data' => t($message, array('!name' => $account->name)));    return array('status' => $status, 'data' => t($message, array('@name' => $account->name)));
457    }
458    
459    function abuse_admin_unban_user($account) {
460      db_query("DELETE FROM {access} WHERE mask='%s' AND type='mail' AND status=0", $account->mail);
461      db_query("DELETE FROM {access} WHERE mask='%s' AND type='user' AND status=0", $account->name);
462      db_query("UPDATE {users} SET status=1 WHERE uid=%d", $account->uid);
463      drupal_set_message(t('The user @name has been unbanned', array('@name' => $account->name)));
464      drupal_goto("user/$account->uid/edit");
465  }  }
466    
467  function abuse_admin_moderate_content(&$form_state, $type = NULL, $oid = NULL, $inline = FALSE) {  function abuse_admin_moderate_content(&$form_state, $type = NULL, $oid = NULL, $inline = FALSE) {
# Line 489  function abuse_admin_moderate_content(&$ Line 485  function abuse_admin_moderate_content(&$
485      );      );
486      $run_once = TRUE;      $run_once = TRUE;
487    }    }
488    
489    $form['object_type'] = array(    $form['object_type'] = array(
490      '#type' => 'hidden',      '#type' => 'hidden',
491      '#value' => $object->type      '#value' => $object->type
# Line 521  function abuse_admin_moderate_content(&$ Line 517  function abuse_admin_moderate_content(&$
517    );    );
518    $form['allow']['message'] = array(    $form['allow']['message'] = array(
519      '#type' => 'item',      '#type' => 'item',
520      '#value' => t('Are you sure you want to allow !content?', array('!content' => '<em>'. $object->title .'</em>'))      '#value' => t('Are you sure you want to allow !content?', array('!content' => '<em>'. $object->title .'</em>')),
521        '#attributes' => array(
522          'class' => 'confirm'
523        ),
524    );    );
525    $form['allow']['allow'] = array(    $form['allow']['allow'] = array(
526      '#type' => 'submit',      '#type' => 'submit',
# Line 540  function abuse_admin_moderate_content(&$ Line 539  function abuse_admin_moderate_content(&$
539    );    );
540    $form['remove']['message'] = array(    $form['remove']['message'] = array(
541      '#type' => 'item',      '#type' => 'item',
542      '#value' => t('Are you sure you want to remove !content?', array('!content' => '<em>'. $object->title .'</em>'))      '#value' => t('Are you sure you want to remove !content?', array('!content' => '<em>'. $object->title .'</em>')),
543        '#attributes' => array(
544          'class' => 'confirm'
545        ),
546    );    );
547    $form['remove']['remove'] = array(    $form['remove']['remove'] = array(
548      '#type' => 'submit',      '#type' => 'submit',
# Line 593  function abuse_admin_moderate_content(&$ Line 595  function abuse_admin_moderate_content(&$
595    $reasons = _abuse_reasons();    $reasons = _abuse_reasons();
596    foreach ($reasons as $key => $reason) {    foreach ($reasons as $key => $reason) {
597      $tmp_content .= "<!-- $reason->reason -->\n";      $tmp_content .= "<!-- $reason->reason -->\n";
598      $tmp_content .= "<dt class=\"warning-reason-title\"><a href='#'>". check_plain($reason->reason) ."</a></dt>\n";      $tmp_content .= "<dt class=\"warning-reason-title\"><a href='#'>". check_plain($reason->reason) ."</a></dt>\n";
599      $tmp_content .= "<dd class=\"warning-reason-email\">". check_markup($reason->argumentation) ."</dd>\n";      $tmp_content .= "<dd class=\"warning-reason-email\">". check_plain($reason->argumentation) ."</dd>\n";
600    }    }
601    $tmp_content .= '</dl></div>';    $tmp_content .= '</dl></div>';
602    
603    $form['warn']['allow']['allow_preset_messages'] = $form['warn']['remove']['remove_preset_messages'] = array(    $form['warn']['allow']['allow_preset_messages'] = $form['warn']['remove']['remove_preset_messages'] = array(
604      '#type' => 'item',      '#type' => 'item',
605      '#value' => $tmp_content,      '#value' => $tmp_content,
# Line 611  function abuse_admin_moderate_content(&$ Line 613  function abuse_admin_moderate_content(&$
613      '#type' => 'submit',      '#type' => 'submit',
614      '#value' => t('warn and remove'),      '#value' => t('warn and remove'),
615    );    );
616    
617    if ($user->uid !== $object->uid && $object->uid > 1) {    if ($user->uid !== $object->uid && $object->uid > 1) {
618      $form['ban'] = array(      $form['ban'] = array(
619        '#type' => 'fieldset',        '#type' => 'fieldset',
620        '#title' => t('Ban !user?', array('!user' => check_plain($object->name))),        '#title' => t('Ban !user?', array('!user' => check_plain($object->name))),
621        '#collapsible' => TRUE,        '#collapsible' => TRUE,
622        '#collapsed' => TRUE,        '#collapsed' => TRUE,
623          '#attributes' => array(
624            'class' => 'abuse-report-ban'
625          ),
626      );      );
627      $form['ban']['confirmation_message'] = array(      $form['ban']['confirmation_message'] = array(
628        '#type' => 'item',        '#type' => 'item',
629        '#value' => t('Are you sure you want to ban !name?', array('!name' => '<em>'. check_plain($object->name) .'</em>'))        '#value' => t('Are you sure you want to ban !name?', array('!name' => '<em>'. check_plain($object->name) .'</em>')),
630          '#attributes' => array(
631            'class' => 'confirm'
632          ),
633      );      );
634      $form['ban']['ban'] = array(      $form['ban']['ban'] = array(
635        '#type' => 'submit',        '#type' => 'submit',
# Line 690  function abuse_admin_ban(&$form_state, $ Line 698  function abuse_admin_ban(&$form_state, $
698    $form = array();    $form = array();
699    $form['#validate'][] = array('abuse_admin_ban_validate');    $form['#validate'][] = array('abuse_admin_ban_validate');
700    $form['#submit'][] = array('abuse_admin_ban_submit');    $form['#submit'][] = array('abuse_admin_ban_submit');
701    
702    $form['#attributes'] = array('class' => 'abuse-admin-ban');    $form['#attributes'] = array('class' => 'abuse-admin-ban');
703    if ($user->uid === $account->uid || $account->uid === 1) {    if ($user->uid === $account->uid || $account->uid === 1) {
704      $form['notallowed'] = array(      $form['notallowed'] = array(
# Line 760  function abuse_admin_ban_submit($form, & Line 768  function abuse_admin_ban_submit($form, &
768    }    }
769    if ($user->uid > 1 && $user->uid !== $account->uid && t('Yes') == $op) {    if ($user->uid > 1 && $user->uid !== $account->uid && t('Yes') == $op) {
770        abuse_remove_account_content($account);        abuse_remove_account_content($account);
771    
772      // ban this email address      // ban this email address and username
773      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'mail', 0)", $account->mail);      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'mail', 0)", $account->mail);
774        db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->name);
775    
776      // block this user      // block this user
777      db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);      db_query("UPDATE {users} SET status=0 WHERE uid=%d", $account->uid);
     db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'user', 0)", $account->name);  
778      db_query("DELETE FROM {sessions} WHERE uid=%d", $uid);      db_query("DELETE FROM {sessions} WHERE uid=%d", $uid);
779      drupal_set_message(t('The user !name has been banned.', array('!name' => $account->name)));      drupal_set_message(t('The user @name has been banned.', array('@name' => $account->name)));
780    }    }
781  }  }
782    
# Line 799  function abuse_mail($key, &$message, $pa Line 807  function abuse_mail($key, &$message, $pa
807    $account = $params['account'];    $account = $params['account'];
808    $object = $params['object'];    $object = $params['object'];
809    $vars = array(    $vars = array(
810      '!title' => $object->title,      '@title' => $object->title,
811      '!url' => $object->link,      '@url' => $object->link,
812      '!name' => $account->name,      '@name' => $account->name,
813      '!id' => $object->link,      '@id' => $object->link,
814    );    );
815    $subject = strtr($params['subject'], $vars);    $subject = strtr($params['subject'], $vars);
816    $body = strtr($params['body'], $vars);    $body = strtr($params['body'], $vars);
817    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);    $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
818    $message['body'][] = drupal_html_to_text($body);    $message['body'][] = htmlspecialchars($body, ENT_NOQUOTES);
 }  
   
 function _abuse_get_offence_count($uid) {  
   static $offences_count;  
   if (!isset($offences_count["uid-$uid"])) {  
     $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));  
     $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));  
   }  
   return $offences_count["uid-$uid"];  
 }  
   
 function _abuse_get_warning_count($uid) {  
   static $warnings_count;  
   if (!isset($warnings_count["uid-$uid"])) {  
     $warnings_count["uid-$uid"] = db_result(db_query('SELECT count(*) FROM {abuse_warnings} WHERE uid=%d', $uid));  
   }  
   return $warnings_count["uid-$uid"];  
819  }  }
820    
821  function template_preprocess_abuse_page(&$variables) {  function template_preprocess_abuse_page(&$variables) {
# Line 842  function template_preprocess_abuse_repor Line 833  function template_preprocess_abuse_repor
833    $variables['account'] = user_load(array('uid' => $object->uid));    $variables['account'] = user_load(array('uid' => $object->uid));
834    $variables['offences'] = number_format(_abuse_get_offence_count($object->uid));    $variables['offences'] = number_format(_abuse_get_offence_count($object->uid));
835    $variables['warnings'] = number_format(_abuse_get_warning_count($object->uid));    $variables['warnings'] = number_format(_abuse_get_warning_count($object->uid));
836    $variables['nodeType'] = ($object->type == 'comment') ? "Comment" : "Movie";    $variables['nodeType'] = $object->type;
837    
838    $variables['moderate'] = drupal_get_form('abuse_admin_moderate_content'. $counter++, $object->type, $object->oid, TRUE);    $variables['moderate'] = drupal_get_form('abuse_admin_moderate_content'. $counter++, $object->type, $object->oid, TRUE);
839  }  }

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

  ViewVC Help
Powered by ViewVC 1.1.3