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

Diff of /contributions/modules/abuse/abuse.module

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

revision 1.34.4.2 by btmash, Wed May 14 19:13:19 2008 UTC revision 1.34.4.3 by btmash, Fri Jul 18 15:52:51 2008 UTC
# Line 30  define('ADMINISTER_ALL_ABUSE_REPORTS', ' Line 30  define('ADMINISTER_ALL_ABUSE_REPORTS', '
30   */   */
31    
32  /**  /**
33   * Implementation of hook_perm   * Implementation of hook_perm().
34   */   */
35  function abuse_perm() {  function abuse_perm() {
36    return array(REPORT_ABUSE, DIRECT_FLAG, ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS, CONFIGURE_ABUSE_SETTINGS);    return array(REPORT_ABUSE, DIRECT_FLAG, ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS, CONFIGURE_ABUSE_SETTINGS);
# Line 43  function abuse_access() { Line 43  function abuse_access() {
43    $args = func_num_args();    $args = func_num_args();
44    if ($args < 1) {    if ($args < 1) {
45      return user_access(ADMINISTER_ALL_ABUSE_REPORTS);      return user_access(ADMINISTER_ALL_ABUSE_REPORTS);
46    }    }
47    else {    else {
48      $perms = func_get_args();      $perms = func_get_args();
49      for ($i = 0; $i < $args; $i++) {      for ($i = 0; $i < $args; $i++) {
# Line 81  function abuse_moderation_system_access( Line 81  function abuse_moderation_system_access(
81  }  }
82    
83  /**  /**
84   * Implementation of hook_help   * Implementation of hook_help().
85   */   */
86  function abuse_help($section) {  function abuse_help($section) {
87    switch ($section) {    switch ($section) {
# Line 93  function abuse_help($section) { Line 93  function abuse_help($section) {
93  }  }
94    
95  /**  /**
96   * Implementation of hook_menu   * Implementation of hook_menu().
97   */   */
98  function abuse_menu() {  function abuse_menu() {
99    //Initial setup work    //Initial setup work
# Line 111  function abuse_menu() { Line 111  function abuse_menu() {
111      'access arguments' => $flagger,      'access arguments' => $flagger,
112      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
113    );    );
114    
115    // Abuse system settings    // Abuse system settings
116    $items['admin/settings/abuse'] = array(    $items['admin/settings/abuse'] = array(
117      'title' => 'Abuse Moderation settings',      'title' => 'Abuse Moderation settings',
# Line 141  function abuse_menu() { Line 141  function abuse_menu() {
141      'file' => 'abuse.admin.inc',      'file' => 'abuse.admin.inc',
142      'type' => MENU_CALLBACK      'type' => MENU_CALLBACK
143    );    );
144    
145    // Callback admin functions    // Callback admin functions
146    $items['admin/abuse/content/moderate/%/%'] = array(    $items['admin/abuse/content/moderate/%/%'] = array(
147      'title' => 'Moderate content',      'title' => 'Moderate content',
# Line 152  function abuse_menu() { Line 152  function abuse_menu() {
152      'file' => 'abuse.admin.inc',      'file' => 'abuse.admin.inc',
153      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
154    );    );
155    
156    $items['admin/abuse/moderate/content/js'] = array(    $items['admin/abuse/moderate/content/js'] = array(
157      'page callback' => 'abuse_admin_moderate_content_js',      'page callback' => 'abuse_admin_moderate_content_js',
158      'access callback' => 'abuse_access',      'access callback' => 'abuse_access',
# Line 160  function abuse_menu() { Line 160  function abuse_menu() {
160      'file' => 'abuse.admin.inc',      'file' => 'abuse.admin.inc',
161      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
162    );    );
163    
   
164    $items['admin/abuse/ban/%user'] = array(    $items['admin/abuse/ban/%user'] = array(
165      'title' => 'Warn user',      'title' => 'Ban user',
166      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
167      'page arguments' => array('abuse_admin_ban', 3),      'page arguments' => array('abuse_admin_ban', 3),
168      'access callback' => 'abuse_access',      'access callback' => 'abuse_access',
# Line 171  function abuse_menu() { Line 170  function abuse_menu() {
170      'file' => 'abuse.admin.inc',      'file' => 'abuse.admin.inc',
171      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
172    );    );
173    
174      $items['admin/abuse/unban/%user'] = array(
175        'title' => 'Unban user',
176        'page callback' => 'abuse_admin_unban_user',
177        'page arguments' => array(3),
178        'access callback' => 'user_access',
179        'access arguments' => array('administer users'),
180        'file' => 'abuse.admin.inc',
181        'type' => MENU_CALLBACK,
182      );
183    
184    //Moderation functions    //Moderation functions
185    $items['admin/content/abuse/pending'] = array(    $items['admin/content/abuse/pending'] = array(
186      'title' => 'Pending Items (!num)',      'title' => 'Pending Items (!num)',
# Line 185  function abuse_menu() { Line 194  function abuse_menu() {
194      'weight' => 0,      'weight' => 0,
195      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_DEFAULT_LOCAL_TASK,
196    );    );
197    
198    $items['admin/content/abuse/hidden'] = array(    $items['admin/content/abuse/hidden'] = array(
199      'title callback' => 'abuse_title_callback',      'title callback' => 'abuse_title_callback',
200      'title arguments' => array('Hidden Items (!num)', array(ABUSE_HIDDEN)),      'title arguments' => array('Hidden Items (!num)', array(ABUSE_HIDDEN)),
# Line 196  function abuse_menu() { Line 206  function abuse_menu() {
206      'weight' => 1,      'weight' => 1,
207      'type' => MENU_LOCAL_TASK      'type' => MENU_LOCAL_TASK
208    );    );
209    
210    $items['admin/content/abuse/removed'] = array(    $items['admin/content/abuse/removed'] = array(
211      'title callback' => 'abuse_title_callback',      'title callback' => 'abuse_title_callback',
212      'title arguments' => array('Removed Items (!num)', array(ABUSE_REMOVED)),      'title arguments' => array('Removed Items (!num)', array(ABUSE_REMOVED)),
# Line 207  function abuse_menu() { Line 218  function abuse_menu() {
218      'weight' => 2,      'weight' => 2,
219      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
220    );    );
221    
222    $items['admin/content/abuse/assigned'] = array(    $items['admin/content/abuse/assigned'] = array(
223      'title' => 'Removed Items (!num of !num2)',      'title' => 'Removed Items (!num of !num2)',
224      'title callback' => 'abuse_title_assigned_callback',      'title callback' => 'abuse_title_assigned_callback',
# Line 220  function abuse_menu() { Line 231  function abuse_menu() {
231      'weight' => 0,      'weight' => 0,
232      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_DEFAULT_LOCAL_TASK,
233    );    );
234    
235    $items['admin/content/abuse/remaining'] = array(    $items['admin/content/abuse/remaining'] = array(
236      'title callback' => 'abuse_title_callback',      'title callback' => 'abuse_title_callback',
237      'title arguments' => array('Remaining Items (!num)', array(ABUSE_PENDING, ABUSE_HIDDEN)),      'title arguments' => array('Remaining Items (!num)', array(ABUSE_PENDING, ABUSE_HIDDEN)),
# Line 231  function abuse_menu() { Line 243  function abuse_menu() {
243      'weight' => 1,      'weight' => 1,
244      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
245    );    );
246    
247    $items['admin/content/abuse'] = array(    $items['admin/content/abuse'] = array(
248      'title' => 'Moderate',      'title' => 'Moderate',
249      'description' => 'Manage items that were either flagged by the system or by other users',      'description' => 'Manage items that were either flagged by the system or by other users',
# Line 240  function abuse_menu() { Line 252  function abuse_menu() {
252      'access arguments' => $admin,      'access arguments' => $admin,
253      'file' => 'abuse.admin.inc',      'file' => 'abuse.admin.inc',
254    );    );
255    
256    $items['admin/abuse/status/%/%'] = array(    $items['admin/abuse/status/%/%'] = array(
257      'title' => 'History',      'title' => 'History',
258      'description' => 'Check the status of a particular item',      'description' => 'Check the status of a particular item',
# Line 254  function abuse_menu() { Line 266  function abuse_menu() {
266  }  }
267    
268  /**  /**
269   * Implementation of hook_theme   * Implementation of hook_theme().
270   */   */
271  function abuse_theme() {  function abuse_theme() {
272    $theme = array();    $theme = array();
# Line 276  function abuse_theme() { Line 288  function abuse_theme() {
288  }  }
289    
290  /**  /**
291   * Implementation of hook_cron   * Implementation of hook_cron().
292   */   */
293  function abuse_cron() {  function abuse_cron() {
294    $hour = variable_get('abuse_cleanup_hour', 0);    $hour = variable_get('abuse_cleanup_hour', 0);
# Line 285  function abuse_cron() { Line 297  function abuse_cron() {
297    $time = time() - ($hour * 3600);    $time = time() - ($hour * 3600);
298    $timestamp = getdate($time);    $timestamp = getdate($time);
299    $timestamp = mktime(0, 0, 0, $timestamp['mon'], $timestamp['mday'], $timestamp['year']);    $timestamp = mktime(0, 0, 0, $timestamp['mon'], $timestamp['mday'], $timestamp['year']);
300    
301    $last_time = variable_get('abuse_cleanup_timestamp', 0);    $last_time = variable_get('abuse_cleanup_timestamp', 0);
302    if ($timestamp > $last_time) {    if ($timestamp > $last_time) {
303        db_query('UPDATE {abuse_status} SET assigned_to_uid=0 WHERE status=%d OR status=%d OR status=%d', ABUSE_PENDING, ABUSE_HIDDEN, ABUSE_SUPERADMIN);        db_query('UPDATE {abuse_status} SET assigned_to_uid=0 WHERE status=%d OR status=%d OR status=%d', ABUSE_PENDING, ABUSE_HIDDEN, ABUSE_SUPERADMIN);
# Line 294  function abuse_cron() { Line 306  function abuse_cron() {
306  }  }
307    
308  /**  /**
309   * Implementation of hook_link   * Implementation of hook_link().
310   */   */
311  function abuse_link($type, $object, $teaser) {  function abuse_link($type, $object, $teaser) {
312    global $user;    global $user;
# Line 304  function abuse_link($type, $object, $tea Line 316  function abuse_link($type, $object, $tea
316      return $$links;      return $$links;
317    }    }
318    if ($type == 'node' && !$teaser) {    if ($type == 'node' && !$teaser) {
319      if (user_access(ADMINISTER_ABUSE_REPORTS)) {      if (user_access(ADMINISTER_ABUSE_REPORTS) && variable_get(ABUSE_CONTENT_NODE_TYPE . $object->type, 0)) {
320        $links['abuse_node_history'] = array(        $links['abuse_node_history'] = array(
321          'title' => t('View abuse history'),          'title' => t('View abuse history'),
322          'href' => 'admin/abuse/content/moderate/node/'. $object->nid,          'href' => 'admin/abuse/status/node/'. $object->nid,
323          'attributes' => array('class' => 'node-history'),          'attributes' => array('class' => 'node-history'),
324        );        );
325      }      }
# Line 315  function abuse_link($type, $object, $tea Line 327  function abuse_link($type, $object, $tea
327        if ($user->uid && ($user->uid != $object->uid)) {        if ($user->uid && ($user->uid != $object->uid)) {
328          $already_reported_check = db_result(db_query("SELECT COUNT(*) FROM {abuse} WHERE type='%s' AND oid=%d AND uid=%d", $type, $object->nid, $user->uid));          $already_reported_check = db_result(db_query("SELECT COUNT(*) FROM {abuse} WHERE type='%s' AND oid=%d AND uid=%d", $type, $object->nid, $user->uid));
329          if ($already_reported_check > 0) {          if ($already_reported_check > 0) {
330  //          $links['abuse_already_flagged'] = array(  
331  //            'title' => t('This content is currently under review'),          }
 //          );  
         }  
332          else {          else {
333            $links['abuse_flag_node'] = array(            $links['abuse_flag_node'] = array(
334              'title' => t('Flag as offensive'),              'title' => t('Flag as offensive'),
335              'href' => 'abuse/report/node/'. $object->nid,              'href' => 'abuse/report/node/'. $object->nid,
336              'attributes' => array('class' => 'flag-content',              'attributes' => array('class' => 'flag-content',
337                                    'title' => t('Notify administrators of problematic content')                                    'title' => t('Notify administrators of problematic content')
338                                   )                                    )
339            );            );
340          }          }
341        }        }
# Line 334  function abuse_link($type, $object, $tea Line 344  function abuse_link($type, $object, $tea
344            'title' => t('Flag as offensive'),            'title' => t('Flag as offensive'),
345            'href' => 'abuse/report/node/'. $object->nid,            'href' => 'abuse/report/node/'. $object->nid,
346            'attributes' => array('class' => 'flag-content',            'attributes' => array('class' => 'flag-content',
347                                  'title' => t('Notify administrators of problematic content')                                  'title' => t('Notify administrators of problematic content')
348                                 )                                  )
349          );          );
350        }        }
351      }      }
352    }    }
353    elseif ($type == 'comment' &&    elseif ($type == 'comment' &&
354      variable_get(ABUSE_CONTENT_COMMENTS, 0) &&      variable_get(ABUSE_CONTENT_COMMENTS, 0) &&
355      (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {      (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
356      if (user_access(ADMINISTER_ABUSE_REPORTS)) {  // Commented out as a temporary solution to ticket 178:
357        $links['abuse_comment_history'] = array(  // https://office.zincroe.com/zimmertwins/ticket/178
358          'title' => t('View abuse history'),  //
359          'href' => 'admin/abuse/content/moderate/comment/'. $object->cid,  //    if (user_access(ADMINISTER_ABUSE_REPORTS)) {
360          'attributes' => array('class' => 'node-history'),  //      $links['abuse_comment_history'] = array(
361        );  //        'title' => t('View abuse history'),
362      }  //        'href' => 'admin/abuse/status/comment/'. $object->cid,
363    //        'attributes' => array('class' => 'node-history'),
364    //      );
365    //    }
366      if ($user->uid && ($user->uid != $object->uid)) {      if ($user->uid && ($user->uid != $object->uid)) {
367        $already_reported_check = db_result(db_query("SELECT COUNT(*) FROM {abuse} WHERE type='%s' AND oid=%d AND uid=%d", $type, $object->cid, $user->uid));        $already_reported_check = db_result(db_query("SELECT COUNT(*) FROM {abuse} WHERE type='%s' AND oid=%d AND uid=%d", $type, $object->cid, $user->uid));
368        if ($already_reported_check > 0) {        if ($already_reported_check > 0) {
369  //        $links['abuse_already_flagged'] = array(  //        $links['abuse_already_flagged'] = array(
370  //          'title' => t('This comment is currently under review'),  //          'title' => t('This comment is currently under review'),
371  //        );  //        );
372        }        }
373        else {        else {
374          $links['abuse_flag_comment'] = array(          $links['abuse_flag_comment'] = array(
375            'title' => t('Flag as offensive'),            'title' => t('Flag as offensive'),
376            'href' => 'abuse/report/comment/'. $object->cid,            'href' => 'abuse/report/comment/'. $object->cid,
377            'attributes' => array('class' => 'flag-content',            'attributes' => array('class' => 'flag-content',
378                                  'title' => t('Notify administrators of problematic comment')                                  'title' => t('Notify administrators of problematic comment')
379                                 )                                  )
380          );          );
381        }        }
382      }      }
383      else {      else {
384          $links['abuse_flag_comment'] = array(          $links['abuse_flag_comment'] = array(
385            'title' => t('Flag as offensive'),            'title' => t('Flag as offensive'),
386            'href' => 'abuse/report/comment/'. $object->cid,            'href' => 'abuse/report/comment/'. $object->cid,
387            'attributes' => array('class' => 'flag-content',            'attributes' => array('class' => 'flag-content',
388                                  'title' => t('Notify administrators of problematic comment')                                  'title' => t('Notify administrators of problematic comment')
389                                 )                                  )
390          );          );
391      }      }
392    }    }
# Line 381  function abuse_link($type, $object, $tea Line 394  function abuse_link($type, $object, $tea
394  }  }
395    
396  /**  /**
397   * Implementation of hook_nodeapi   * Implementation of hook_nodeapi().
398   */   */
399  function abuse_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {  function abuse_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
400    switch ($op) {    switch ($op) {
401      case 'load':      case 'load':
402        if (user_access(ADMINISTER_ABUSE_REPORTS) || user_access(ADMINISTER_ALL_ABUSE_REPORTS)) {        if (user_access(ADMINISTER_ABUSE_REPORTS) || user_access(ADMINISTER_ALL_ABUSE_REPORTS)) {
403          $node->abuse_status = intval(_abuse_get_object_status('node', $node->nid));          return array('abuse_status' => intval(_abuse_get_object_status('node', $node->nid)));
404        }        }
405        return $node;        break;
406        case 'delete':
407          // Delete abuse flags
408          _abuse_cleanup_content('node', $node->nid);
409        break;        break;
410    }    }
411  }  }
412    
413    /**
414     * Implementation of hook_comment().
415     */
416  function abuse_comment($comment, $op) {  function abuse_comment($comment, $op) {
417    switch ($op) {    switch ($op) {
418      case 'view':      case 'view':
# Line 401  function abuse_comment($comment, $op) { Line 420  function abuse_comment($comment, $op) {
420          $comment->abuse_status = intval(_abuse_get_object_status('comment', $comment->cid));          $comment->abuse_status = intval(_abuse_get_object_status('comment', $comment->cid));
421        }        }
422        return $comment;        return $comment;
423        case 'delete':
424          // Delete abuse_flags
425          _abuse_cleanup_content('comment', $comment->cid);
426      }
427    }
428    
429    /**
430     * Implementation of hook_user().
431     */
432    function abuse_user($op, &$edit, &$account, $category = NULL) {
433      switch ($op) {
434        case 'form':
435          if (user_is_blocked($account->name) && user_access('administer users')) {
436            $replacement = array(
437              '!link' => l(t('here'), "admin/abuse/unban/$account->uid"),
438              '@username' => $account->name,
439            );
440            $form['unban'] = array(
441              '#type' => 'item',
442              '#value' => t('Click !link to unban @username.', $replacement),
443              '#weight' => -20,
444            );
445            return $form;
446          }
447        break;        break;
448    }    }
449  }  }
450    
451    
452    /**
453     * Clean out content from the abuse tables - useful when a node/comment/user gets deleted
454     *
455     * @param $type
456     * @param $oid
457     */
458    function _abuse_cleanup_content($type, $oid) {
459      db_query("DELETE FROM {abuse} WHERE oid=%d AND type='%s'", $oid, $type);
460      db_query("DELETE FROM {abuse_status} WHERE oid=%d AND type='%s'", $oid, $type);
461      db_query("DELETE FROM {abuse_warnings} WHERE oid=%d AND type='%s'", $oid, $type);
462    }
463    
464  /**  /**
465   * Implementation of hook_forms   * Implementation of hook_forms().
466   */   */
467  function abuse_forms() {  function abuse_forms() {
468    $args = func_get_args();    $args = func_get_args();
469    $form_id = $args[0];    $form_id = $args[0];
470    
471    $forms = array();    $forms = array();
472    if (strpos($form_id, "abuse_admin_warn") === 0) {    if (strpos($form_id, "abuse_admin_warn") === 0) {
473      $forms[$form_id] = array('callback' => 'abuse_admin_warn');      $forms[$form_id] = array('callback' => 'abuse_admin_warn');
# Line 487  function abuse_report_form($form_state, Line 543  function abuse_report_form($form_state,
543        '#type' => 'value',        '#type' => 'value',
544        '#value' => $user->mail        '#value' => $user->mail
545      );      );
546    }    }
547    else {    else {
548      $form['name'] = array(      $form['name'] = array(
549        '#type' => 'textfield',        '#type' => 'textfield',
# Line 534  function abuse_report_form($form_state, Line 590  function abuse_report_form($form_state,
590      '#type' => 'submit',      '#type' => 'submit',
591      '#value' => t('cancel')      '#value' => t('cancel')
592    );    );
593    return $form;    return $form;
594  }  }
595    
596  function abuse_report_form_validate($form, &$form_state) {  function abuse_report_form_validate($form, &$form_state) {
# Line 549  function abuse_report_form_validate($for Line 605  function abuse_report_form_validate($for
605      if (empty($form_values['reason'])) {      if (empty($form_values['reason'])) {
606        form_set_error('reason', t('Please give a reason.'));        form_set_error('reason', t('Please give a reason.'));
607      }      }
608      $body = trim(strtolower($form_values['body']));      $body = trim(drupal_strtolower($form_values['body']));
609      if (empty($body)) {      if (empty($body)) {
610        form_set_error('body', t('Please provide a more detailed description - no links please.'));        form_set_error('body', t('Please provide a more detailed description - no links please.'));
611      }      }
612      elseif (      elseif (
613        strpos($body, 'href=') !== FALSE ||        strpos($body, 'href=') !== FALSE ||
614        strpos($body, 'url=') !== FALSE ||        strpos($body, 'url=') !== FALSE ||
615        strpos($body, 'http://') !== FALSE        strpos($body, 'http://') !== FALSE
616      ) {      ) {
617        form_set_error('body', t('Please do not use links in your description of the problem.'));        form_set_error('body', t('Please do not use links in your description of the problem.'));
# Line 582  function abuse_report_form_submit($form, Line 638  function abuse_report_form_submit($form,
638        drupal_set_message(t('We have already received your report.  Thank you very much!'));        drupal_set_message(t('We have already received your report.  Thank you very much!'));
639        $errors = TRUE;        $errors = TRUE;
640      }      }
641    
642      // ENSURE USER IS NOT TRYING TO FLAG OWN CONTENT      // ENSURE USER IS NOT TRYING TO FLAG OWN CONTENT
643      if ($user->uid == $object->uid) {      if ($user->uid == $object->uid) {
644        drupal_set_message(t('You cannot flag your own content'));        drupal_set_message(t('You cannot flag your own content'));
645        $errors = TRUE;        $errors = TRUE;
646      }      }
647    }    }
648    
649    if (!$errors) {    if (!$errors) {
650      db_query("INSERT INTO {abuse} (type, oid, created, body, reason, uid, name, mail) VALUES ('%s', %d, %d, '%s', '%s', %d, '%s', '%s')",      db_query("INSERT INTO {abuse} (type, oid, created, body, reason, uid, name, mail) VALUES ('%s', %d, %d, '%s', '%s', %d, '%s', '%s')",
651        $type, $oid,  time(), $form_values['body'], $form_values['reason'], $user->uid, $form_values['name'], $form_values['mail']);        $type, $oid,  time(), $form_values['body'], $form_values['reason'], $user->uid, $form_values['name'], $form_values['mail']);
# Line 599  function abuse_report_form_submit($form, Line 655  function abuse_report_form_submit($form,
655      if ($result) {      if ($result) {
656        drupal_set_message(t('Thank you for your report.  We will look into this shortly.'));        drupal_set_message(t('Thank you for your report.  We will look into this shortly.'));
657        $form_state['redirect'] = '';        $form_state['redirect'] = '';
658      }      }
659      else {      else {
660        drupal_set_message(t('Thank you for your report.'));        drupal_set_message(t('Thank you for your report.'));
661      }      }
# Line 637  function _abuse_load($obj, $second_value Line 693  function _abuse_load($obj, $second_value
693        }        }
694        $object->title = $node->title;        $object->title = $node->title;
695        $object->uid = $node->uid;        $object->uid = $node->uid;
696        $object->name = check_plain($node->name, $node->format, FALSE);        $object->name = check_plain($node->name);
697        $object->description = $node->body;        $object->description = $node->body;
698        $object->content_type = $node->type;        $object->content_type = $node->type;
699        if (function_exists($node->type .'_replacement_content')) {        if (function_exists($node->type .'_replacement_content')) {
700          $function = $node->type .'_replacement_content';          $function = $node->type .'_replacement_content';
701          $object->content = check_markup($function($node), $node->format, FALSE);          $object->content = filter_xss_admin($function($node));
702        }        }
703        else {        else {
704          $object->content = check_markup($node->body, $node->format, FALSE);          $object->content = check_markup($node->body, $node->format, FALSE);
# Line 659  function _abuse_load($obj, $second_value Line 715  function _abuse_load($obj, $second_value
715        if (!$comment->cid) {        if (!$comment->cid) {
716          return false;          return false;
717        }        }
718        $object->title = check_markup($comment->subject, $comment->format, FALSE);        $object->title = check_plain($comment->subject);
719        $object->name = check_markup($comment->name, $comment->format, FALSE);        $object->name = check_markup($comment->name, $comment->format, FALSE);
720        $object->uid = $comment->uid;        $object->uid = $comment->uid;
721        $object->content_type = 'comment';        $object->content_type = 'comment';
# Line 707  function _abuse_load_warnings($type, $oi Line 763  function _abuse_load_warnings($type, $oi
763    return $warnings;    return $warnings;
764  }  }
765    
766    function _abuse_get_offence_count($uid) {
767      static $offences_count;
768      if (!isset($offences_count["uid-$uid"])) {
769        $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));
770        $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));
771      }
772      return $offences_count["uid-$uid"];
773    }
774    
775    function _abuse_get_warning_count($uid) {
776      static $warnings_count;
777      if (!isset($warnings_count["uid-$uid"])) {
778        $warnings_count["uid-$uid"] = db_result(db_query('SELECT count(*) FROM {abuse_warnings} WHERE uid=%d', $uid));
779      }
780      return $warnings_count["uid-$uid"];
781    }
782    
783  function _abuse_reasons($arid = NULL) {  function _abuse_reasons($arid = NULL) {
784    static $reasons;    static $reasons;
785    if (!$reasons) {    if (!$reasons) {
# Line 738  function _abuse_get_assigned_count($stat Line 811  function _abuse_get_assigned_count($stat
811        $result = db_query("UPDATE {abuse_status} SET assigned_to_uid=%d WHERE (assigned_to_uid=0 OR assigned_to_uid=%d) AND (status=%d OR status=%d) ORDER BY assigned_to_uid DESC, oid DESC LIMIT %d",        $result = db_query("UPDATE {abuse_status} SET assigned_to_uid=%d WHERE (assigned_to_uid=0 OR assigned_to_uid=%d) AND (status=%d OR status=%d) ORDER BY assigned_to_uid DESC, oid DESC LIMIT %d",
812          $user->uid, $user->uid, ABUSE_PENDING, ABUSE_HIDDEN, variable_get('abuse_num_assigned', 20));          $user->uid, $user->uid, ABUSE_PENDING, ABUSE_HIDDEN, variable_get('abuse_num_assigned', 20));
813      }      }
814      $result = db_result(db_query("SELECT count(*) FROM {abuse_status} WHERE assigned_to_uid=%d AND (status=%d OR status=%d OR status=%d)",      $result = db_result(db_query("SELECT count(*) FROM {abuse_status} WHERE assigned_to_uid=%d AND (status=%d OR status=%d OR status=%d)",
815          $user->uid, ABUSE_PENDING, ABUSE_HIDDEN, ABUSE_SUPERADMIN));          $user->uid, ABUSE_PENDING, ABUSE_HIDDEN, ABUSE_SUPERADMIN));
816    }    }
817    return $result;    return $result;
# Line 786  function _abuse_get_status($type, $oid) Line 859  function _abuse_get_status($type, $oid)
859  function _abuse_retrieve_status($current_status) {  function _abuse_retrieve_status($current_status) {
860    static $status;    static $status;
861    if (!$status) {    if (!$status) {
862      $status = array(ABUSE_LIVE => t('OK'),      $status = array(
863                      ABUSE_PENDING => t('Pending'),        ABUSE_LIVE => t('OK'),
864                      ABUSE_HIDDEN => t('Hidden'),        ABUSE_PENDING => t('Pending'),
865                      ABUSE_REMOVED => t('Removed'),        ABUSE_HIDDEN => t('Hidden'),
866                      ABUSE_SUPERADMIN => t('Superadmin Assigned'),        ABUSE_REMOVED => t('Removed'),
867                     );        ABUSE_SUPERADMIN => t('Superadmin Assigned'),
868        );
869    }    }
870    return $status[$current_status];    return $status[$current_status];
871  }  }
# Line 807  function _abuse_set_status($type, $oid, Line 881  function _abuse_set_status($type, $oid,
881    }    }
882    db_query("DELETE FROM {abuse_status} WHERE type='%s' AND oid=%d", $type, $oid);    db_query("DELETE FROM {abuse_status} WHERE type='%s' AND oid=%d", $type, $oid);
883    db_query("INSERT INTO {abuse_status} (type, oid, changed, status, assigned_to_uid) VALUES ('%s', %d, %d, %d, %d)",    db_query("INSERT INTO {abuse_status} (type, oid, changed, status, assigned_to_uid) VALUES ('%s', %d, %d, %d, %d)",
884             $type, $oid, time(), $status, $assigned_to_uid);      $type, $oid, time(), $status, $assigned_to_uid);
885    if ('comment' == $type) {    if ('comment' == $type) {
886      $nid = db_result(db_query("SELECT nid FROM {comments} where cid=%d", $oid));      $nid = db_result(db_query("SELECT nid FROM {comments} where cid=%d", $oid));
887    } if ($nid) {    } if ($nid) {
# Line 819  function _abuse_allow($type, $oid) { Line 893  function _abuse_allow($type, $oid) {
893    $object = _abuse_load($type, $oid);    $object = _abuse_load($type, $oid);
894    $account = user_load(array('uid' => $object->uid, 'status' => 1));    $account = user_load(array('uid' => $object->uid, 'status' => 1));
895    if ($account->uid) {    if ($account->uid) {
896      db_query("UPDATE {abuse} SET valid=-1 WHERE type='%s' AND oid=%d", $type, $oid);      // Re-Save the node so it can get indexed if not already done so and any other important functionality is carried out by being published
     // Re-Save the node so it can get indexed if not already done so and any other important functionality is carried out by being published  
897      switch ($type) {      switch ($type) {
898        case 'node':        case 'node':
899          $node = node_load($object->oid);          // Resave the node so it can get reindexed correctly.
900            $node = node_load($oid);
901          $node->status = 1;          $node->status = 1;
902          node_save($node);          node_save($node);
903          //db_query("UPDATE {node} SET status=1 WHERE nid=%d", $oid);          // Update the status just in case
904            db_query("UPDATE {node} SET status=1 WHERE nid=%d", $oid);
905          break;          break;
906        case 'comment':        case 'comment':
907          db_query("UPDATE {comments} SET status=0 WHERE cid=%d", $object->oid);          db_query("UPDATE {comments} SET status=0 WHERE cid=%d", $object->oid);
908          break;          break;
909      }      }
910        db_query("UPDATE {abuse} SET valid=-1 WHERE type='%s' AND oid=%d", $type, $oid);
911      _abuse_set_status($type, $oid, ABUSE_LIVE);      _abuse_set_status($type, $oid, ABUSE_LIVE);
912      _abuse_clear_oid_cache($oid);      _abuse_clear_oid_cache($oid);
913      return true;      return true;
# Line 884  function _abuse_clear_oid_cache($oid) { Line 960  function _abuse_clear_oid_cache($oid) {
960    foreach ($cache_tables as $table) {    foreach ($cache_tables as $table) {
961      cache_clear_all($oid, $table, TRUE);      cache_clear_all($oid, $table, TRUE);
962    }    }
963  }  }
   
 /**  
  * Add an item into the abuse list  
  *  
  * @param string $type type of object being provided  
  * @param int $oid Object ID  
  * @param string[] $matches array of word matches found  
  * @param boolean $pre_moderated if the content is to be un-published  
  * @param boolean $hidden if the content is to be un-published and flagged as hidden from other users  
  *  */  
 function _abuse_report_generated($object = NULL, $type = NULL, $oid = NULL, $matches = array(), $unpublished = FALSE, $hidden=FALSE) {  
   if (!empty($object) && !empty($type) && !empty($oid)) {  
     $admin = array(  
       'uid' => 0,  
       'name' => 'AUTO_ADMIN',  
       'mail' => variable_get('site_mail', 'AUTO_ADMIN@abuse_generator.com'),  
       'reason' => 0,  
       'body' => 'WATCHLIST: '. implode(', ', $matches),  
     );  
     if (empty($matches)) {  
       $admin['body'] = t("AUTO MESSAGE: No questionable words were found in this @type", array('@type' => $type));  
     }  
   
     // If unpublishing the content  
     if ($unpublished === TRUE) {  
       switch ($type) {  
         case 'node':  
           db_query("UPDATE {node} SET STATUS=0 WHERE nid=%d", $object->nid);  
           if (module_exists('search')) {  
             search_touch_node($object->nid);  
           }  
           break;  
         case 'comment':  
           db_query("UPDATE {comments} SET status=1 WHERE cid=%d", $object->cid);  
           if (module_exists('search')) {  
             search_touch_node($object->nid);  
           }  
           break;  
         case 'user':  
           db_query("UPDATE {users} SET status=0 WHERE nid=%d", $object->uid);  
           break;  
       }  
     }  
   
     // Check if movie needs to be in hidden pile  
     if ($hidden === TRUE) {  
       _abuse_set_status($type, $oid, ABUSE_HIDDEN);  
     }  
     else {  
       _abuse_set_status($type, $oid, ABUSE_PENDING);  
     }  
   
     // Add or update the auto field  
     $aid = db_result(db_query("SELECT aid FROM {abuse} WHERE type='%s' AND oid=%d AND uid=%d AND name='%s'", $type, $oid, $admin['uid'], $admin['name']));  
     if ($aid === FALSE) {  
       db_query("INSERT INTO {abuse} (type, oid, created, body, reason, uid, name, mail) VALUES ('%s', %d, %d, '%s', '%s', %d, '%s', '%s')",  
         $type, $oid, time(), $admin['body'], $admin['reason'], $admin['uid'], $admin['name'], $admin['mail']);  
     }  
     else {  
       db_query("UPDATE {abuse} SET body='%s', created=%d WHERE aid=%d", $admin['body'], time());  
     }  
   }  
 }  

Legend:
Removed from v.1.34.4.2  
changed lines
  Added in v.1.34.4.3

  ViewVC Help
Powered by ViewVC 1.1.3