You are here

function _antispam_comment_save in AntiSpam 7

Called from hook_comment_insert() and hook_comment_update().

2 calls to _antispam_comment_save()
antispam_comment_insert in ./antispam.module
Implements hook_comment_insert().
antispam_comment_update in ./antispam.module
Implements hook_comment_update().

File

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

Code

function _antispam_comment_save($comment) {

  // If anti-spam servie connections are not enabled, we have nothing else to
  // do here.
  if (!variable_get('antispam_connection_enabled', 1)) {
    antispam_notify_moderators('node', $node, $node->status ? TRUE : FALSE, FALSE);
    return;
  }

  // Also quit asap, if current user has administration permission or
  // permission to post without spam checking.
  if (antispam_is_spam_moderator('comments') || user_access('post with no antispam checking')) {
    antispam_notify_moderators('comment', $comment, $comment->status == COMMENT_PUBLISHED ? TRUE : FALSE, FALSE);
    return;
  }

  // Ok, let's send a query to anti-spam service.
  $api_result = antispam_api_cmd_comment_check('comment', $comment);
  if ($api_result[0] == ANTISPAM_API_RESULT_IS_HAM) {
    watchdog('antispam', '_antispam_comment_save: it is HAM');
    antispam_notify_moderators('comment', $comment, $comment->status == COMMENT_PUBLISHED ? TRUE : FALSE, FALSE);
    antispam_increase_counter(ANTISPAM_COUNT_HAM_DETECTED);
  }
  else {
    if ($api_result[0] == ANTISPAM_API_RESULT_IS_SPAM) {
      watchdog('antispam', '_antispam_comment_save: it is SPAM');
      $comment->signature = $api_result[1];
      $comment->spaminess = $api_result[2];
      antispam_increase_counter(ANTISPAM_COUNT_SPAM_DETECTED);
      antispam_notify_moderators('comment', $comment, FALSE, TRUE);
    }
    else {
      watchdog('antispam', '_antispam_comment_save: it is ERROR');
      antispam_notify_moderators('comment', $comment, FALSE, FALSE);
    }

    // Unpublish the comment, if necessary.
    if ($comment->status == COMMENT_PUBLISHED) {
      antispam_content_publish_operation('comment', $comment, 'unpublish', FALSE);
    }

    // Record the event to watchdog.
    if ($api_result[0] == ANTISPAM_API_RESULT_ERROR) {
      watchdog('content', 'AntiSpam service seems to be down, comment queued for manual approval: %subject', array(
        '%subject' => $comment->subject,
      ), WATCHDOG_WARNING, l(t('view'), 'node/' . $comment->nid, array(
        'fragment' => 'comment-' . $comment->cid,
      )));
    }
    else {
      watchdog('content', 'Spam detected by AntiSpam in comment: %subject', array(
        '%subject' => $comment->subject,
      ), WATCHDOG_WARNING, l(t('view'), 'node/' . $comment->nid, array(
        'fragment' => 'comment-' . $comment->cid,
      )));

      // If requested to, generate a delay so the spammer has to wait for a
      // while.
      if (($seconds = variable_get('antispam_antispambot_delay', 60)) > 0) {
        sleep($seconds);
      }
    }
  }
}