You are here

function spam_tokens_save in Spam 5

5 calls to spam_tokens_save()
spam_notspam_comment in ./spam.module
Mark the comment as not spam. This may cause the comment to become published depending on settings
spam_notspam_node in ./spam.module
Force a node to be marked as not spam. May not publish depending on settings
spam_page in ./spam.module
Drupal _page hook. Provides various spam actions based on the URL that is currently being accessed.
spam_spam_comment in ./spam.module
Mark the comment as spam. This may cause the comment to become unpublished depending on settings
spam_spam_node in ./spam.module
Force a node to be marked as spam. May unpublish depending on settings

File

./spam.module, line 1407

Code

function spam_tokens_save($tokens, $is_spam) {
  foreach ($tokens as $token) {
    $old = db_fetch_object(db_query("SELECT spam,notspam FROM {spam_tokens} WHERE token = '%s'", $token));
    if ($old) {

      // updating an existing token
      $total = $old->spam + $old->notspam + 1;
      $probability = ($old->spam + ($is_spam ? 1 : 0)) / $total * 100;
      $probability = spam_get_probability($probability);
      if ($is_spam) {
        db_query("UPDATE {spam_tokens} SET spam = spam + 1, probability = %d, last = %d WHERE token = '%s'", $probability, time(), $token);
      }
      else {
        db_query("UPDATE {spam_tokens} SET notspam = notspam + 1, probability = %d, last = %d WHERE token = '%s'", $probability, time(), $token);
      }
    }
    else {

      // adding a new token
      $probablity = $is_spam ? 99 : 1;
      @db_query("INSERT INTO {spam_tokens} (token, spam, notspam, probability, last) VALUES('%s', %d, %d, %d, %d)", $token, $is_spam ? 1 : 0, $is_spam ? 0 : 1, $is_spam ? 99 : 1, time());
    }
  }
}