You are here

function antispam_callback_set_spam_status in AntiSpam 7

Same name and namespace in other branches
  1. 6 antispam.module \antispam_callback_set_spam_status()

Menu callback; mark/unmark content as spam.

When content is marked as spam, it is also unpublished (if necessary) and vice-versa.

Parameters

string Content type; it can be 'node' or 'comment' .:

integer Content ID; can be either a nid or a cid.:

string Operation; it can be 'submit-spam' or 'submit-ham' .:

1 string reference to 'antispam_callback_set_spam_status'
antispam_load in ./antispam.module
Implements hook_load().

File

./antispam.module, line 664
Primary hook implementations for the Antispam module.

Code

function antispam_callback_set_spam_status($content_type, $object, $op) {
  if ($content_type == 'node') {
    $is_spam = antispam_content_is_spam($content_type, $object->nid);

    // Load the content (existence has been checked in hook_menu).
    $content = antispam_content_load($content_type, $object->nid);
    $is_published = $content->status ? TRUE : FALSE;
  }
  else {
    $is_spam = antispam_content_is_spam($content_type, $object->cid);

    // Load the content (existence has been checked in hook_menu).
    $content = antispam_content_load($content_type, $object->cid);
    $is_published = $content->status == COMMENT_PUBLISHED ? TRUE : FALSE;
  }

  // Insert or remove the spam marker (publishing/unpublishing if necessary).
  if ($op == 'submit-spam') {
    if (!$is_spam) {
      antispam_content_spam_operation($content_type, $content, 'submit-spam');
      antispam_increase_counter(ANTISPAM_COUNT_FALSE_NEGATIVE);
    }
    if ($is_published) {
      antispam_content_publish_operation($content_type, $content, 'unpublish');
    }
  }
  elseif ($op == 'submit-ham') {
    if ($is_spam) {
      antispam_content_spam_operation($content_type, $content, 'submit-ham');
      antispam_increase_counter(ANTISPAM_COUNT_FALSE_POSITIVE);
    }
    if (!$is_published) {
      antispam_content_publish_operation($content_type, $content, 'publish');
    }
  }
  if ($content_type == 'node') {
    drupal_goto('node/' . $content->nid);
  }
  else {
    drupal_goto('node/' . $content->nid, array(
      'fragment' => 'comment-' . $content->cid,
    ));
  }
}