You are here

function duplicate_spam_filter in Spam 5.3

Determine whether or not the content is spam.

1 call to duplicate_spam_filter()
duplicate_spamapi in filters/duplicate/duplicate.module
Spam API Hook

File

filters/duplicate/duplicate.module, line 300

Code

function duplicate_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) {
  $score = 0;
  $action = array();
  $hash = _duplicate_content_hash($content, $fields);
  $id = spam_invoke_module($type, 'content_id', $content, $extra);
  $duplicate_hash = db_result(db_query("SELECT COUNT(d.iid) FROM {spam_duplicate} d LEFT JOIN {spam_tracker} t ON d.sid = t.sid WHERE content_hash = '%s' AND content_id != %d", $hash, $id)) + 1;
  if ($duplicate_hash >= variable_get('duplicate_threshold', DUPLICATE_DEFAULT_THRESHOLD)) {
    $sids = db_query("SELECT sid FROM spam_duplicate WHERE content_hash = '%s'", $hash);
    if (!$filter_test) {
      while ($sid = db_result($sids)) {
        $unpublish = db_fetch_object(db_query('SELECT content_type, content_id, score FROM {spam_tracker} WHERE sid = %d', $sid));
        spam_mark_as_spam($unpublish->content_type, $unpublish->content_id, array(
          'score' => 99,
        ));
      }

      // Update counter tracking that we've blocked a duplicate posting of this
      // content.  (It will actually increment the counter on
      // "duplicate_threshold" rows.)
      db_query("UPDATE {spam_duplicate} SET duplicate_hash = duplicate_hash + 1 WHERE content_hash = '%s'", $hash);
    }
    $action['hash'] = array(
      'score' => 99,
      'description' => t('Content is identical to %count other existing posts.', array(
        '%count' => variable_get('duplicate_threshold', DUPLICATE_DEFAULT_THRESHOLD),
      )),
    );
    $action['total'] = 99;
    $action['redirect'] = 'duplicate/denied/post';
    _duplicate_action($action);
    return $action;
  }
  $duplicate_ip = db_result(db_query("SELECT COUNT(iid) FROM {spam_duplicate} WHERE hostname = '%s' AND spam = %d", $_SERVER['REMOTE_ADDR'], DUPLICATE_SPAM));
  if ($duplicate_ip >= variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) && variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) > -1) {
    $action['ip'] = array(
      'score' => 99,
      'description' => t('Content was posted by the same IP address used to post %count other spam posts.', array(
        '%count' => variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST),
      )),
    );
    $action['total'] = 99;
    $action['redirect'] = 'duplicate/denied/ip';
  }
  return $action;
}