You are here

function spam_default_actions in Spam 5

The default callback, performs all actions on spam/not spam content.

Parameters

$type Type of content (ie 'comment', 'node'...):

$id The content id.:

$header The header field of the content.:

$body The main text of the content.:

$probability 1-99% chance of being spam.:

$old If updated content, information about pre-update.:

$delete Flag that if is set to 1 we should auto-delete content.:

7 calls to spam_default_actions()
spam_content_filter in ./spam.module
Determine whether or not provided text is spam.
spam_duplicate_filter in ./spam.module
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.
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.

... See full list

File

./spam.module, line 2170

Code

function spam_default_actions($type, $id, $header, $body, $probability, $old, $action, $quiet = NULL) {
  static $counter;
  $is_spam = _is_spam($probability);

  // auto-delete
  if ($action[SPAM_CUSTOM_ACTION_DELETE] && $is_spam) {
    $function = "spam_delete_{$type}";
    $function($id);
    return;
  }

  // check if we've already filtered the content
  if ($old->id) {
    if ($is_spam == _is_spam($old->probability)) {

      // nothing has changed, we don't need to do anything
      return;
    }
  }

  // publish/unpublish the content
  if (variable_get('spam_unpublish', 1)) {
    if ($is_spam) {
      $function = "spam_unpublish_{$type}";
      $function($id);

      // notify user content was blocked
      if (variable_get('spam_notify_user', 1) && !$quiet) {
        if (!$counter++) {

          // only display this message once, even if we block multiple messages
          drupal_set_message(t('The @type you posted has been flagged as potential spam.  It will not be visible until the site administrator has a chance to review it.', array(
            '@type' => $type,
          )));
        }
      }
    }
    else {
      if ($old->id) {
        $function = "spam_publish_{$type}";
        $function($id);
      }
    }
  }

  // generate a mail message
  if (!($quiet || $action[SPAM_CUSTOM_ACTION_NOMAIL])) {
    if ($is_spam && variable_get('spam_notify_admin', 1)) {
      $subject = t('[@sitename] Detected spam @type', array(
        '@sitename' => variable_get('site_name', 'drupal'),
        '@type' => $type,
      ));
      if ($old->id) {

        // update
        spam_mail($subject . ' on update', spam_mail_body($type, $header, $body, $id));
      }
      else {

        // add
        spam_mail($subject, spam_mail_body($type, $header, $body, $id));
      }
    }
  }
}