You are here

function spam_tokens_unsave in Spam 5

5 calls to spam_tokens_unsave()
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 1430

Code

function spam_tokens_unsave($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) {
      if ($is_spam) {
        $new->spam = $old->spam;

        // be sure $new->notspam doesn't go negative
        $new->notspam = $old->notspam > 0 ? $old->notspam - 1 : 0;
        if ($old->notspam <= 0) {

          // TODO: find out why this happens with trackbacks.
          spam_log(SPAM_DEBUG, t('spam_tokens_unsave: invalid attempt to set "notspam" value for token "@token" to @value.', array(
            '@token' => $token,
            '@value' => $old->notspam - 1,
          )));
        }
      }
      else {

        // be sure $new->spam doesn't go negative
        $new->spam = $old->spam > 0 ? $old->spam - 1 : 0;
        if ($old->spam <= 0) {

          // TODO: find out why this happens with trackbacks.
          spam_log(SPAM_DEBUG, t('spam_tokens_unsave: invalid attempt to set "spam" value for token "@token" to @value.', array(
            '@token' => $token,
            '@value' => $old->spam - 1,
          )));
        }
        $new->notspam = $old->notspam;
      }

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