You are here

function spam_duplicate_filter in Spam 5

Search the spam_tracker table to see if this new content is a duplicate of earlier content. If it is a duplicate, see if the content has been duplicated more than the configured number of allowable times.

Parameters

$hash The md5 hash of the content header and body.:

$source Type of content (comment, node, etc).:

$id Content id (cid, nid, etc).:

$header Content header, used when marking content as spam.:

$body Content body, used when marking content as spam.:

Return value

FALSE = not spam TRUE = duplicated too many times, spam

1 call to spam_duplicate_filter()
spam_content_filter in ./spam.module
Determine whether or not provided text is spam.

File

./spam.module, line 1150

Code

function spam_duplicate_filter($hash, $source, $id, $header, $body) {
  $limit = variable_get('spam_duplicate_content', 2);
  if ($limit > -1) {
    $duplicate = db_fetch_object(db_query("SELECT COUNT(sid) AS count FROM {spam_tracker} WHERE hash = '%s' AND (source != '%s' OR id != %d)", $hash, $source, $id));
    if ($duplicate->count >= variable_get('spam_duplicate_content', 2)) {
      $total = 0;
      spam_log(SPAM_DEBUG, t('spam_duplicate_filter: hash "@hash" found @count times.', array(
        '@hash' => $hash,
        '@count' => $duplicate->count,
      )), $source, $id);
      $result = db_query("SELECT * FROM {spam_tracker} WHERE hash = '%s'", $hash);
      while ($duplicate = db_fetch_object($result)) {
        spam_log(SPAM_DEBUG, t('spam_duplicate_filter: marking duplicate @source "%header" as spam.', array(
          '@source' => $source,
          '%header' => $header,
        )), $duplicate->source, $duplicate->id);
        spam_default_actions($duplicate->source, $duplicate->id, $header, $body, 99, $duplicate, FALSE, FALSE);
        $total++;
      }

      // for efficiency, we update all duplicate comments with one query
      db_query("UPDATE {spam_tracker} SET probability = 99, timestamp = %d WHERE hash = '%s'", time(), $hash);
      spam_log(SPAM_LOG, t('spam_duplicate_filter: @duplicates marked as spam', array(
        '@duplicates' => format_plural($total, 'duplicate', 'duplicates'),
      )), $source, $id);
      return TRUE;
    }
  }
  return FALSE;
}