You are here

function spam_scan in Spam 5.3

Same name and namespace in other branches
  1. 6 spam.module \spam_scan()

API call for scanning content for spam. If spam is found, the appropriate action will be taken.

3 calls to spam_scan()
comment_spamapi_form_alter in modules/spam_comment.inc
Form alter gets it's own function so we can reference &$form without causing errors in PHP4 installations. (If we use spamapi, we have to set a default, which PHP4 doesn't support.)
node_spamapi in modules/spam_node.inc
Spam module _spamapi() hook.
user_spamapi in modules/spam_user.inc
User module _spamapi() hook.

File

./spam.module, line 32

Code

function spam_scan($content, $type, $extra = array(), $filter_test = FALSE) {
  if (user_access('bypass filters')) {
    spam_log(SPAM_DEBUG, 'spam_scan', t('bypassing filters'), $type, $id);
    return;
  }

  // bypass filters when admins publish content from spam feedback
  if (isset($_SESSION['bypass_spam_filter'])) {
    if (_spam_sign($content['form_token']) == $_SESSION['bypass_spam_filter']) {
      unset($_SESSION['bypass_spam_filter']);
      spam_log(SPAM_DEBUG, 'spam_scan', t('bypassing filters by request'), $type, $id);
      return;
    }
  }
  $id = spam_invoke_module($type, 'content_id', $content, $extra);
  spam_log(SPAM_DEBUG, 'spam_scan', t('scanning content'), $type, $id);
  spam_update_statistics(t('scan @type', array(
    '@type' => $type,
  )));
  if (spam_content_is_spam($content, $type, $extra, $filter_test)) {
    spam_log(SPAM_DEBUG, 'spam_scan', t('content is spam'), $type, $id);
    spam_update_statistics(t('detected spam @type', array(
      '@type' => $type,
    )));
    switch (variable_get('spam_visitor_action', SPAM_ACTION_PREVENT)) {
      case SPAM_ACTION_PREVENT:
        spam_log(SPAM_LOG, 'spam_scan', t('content is spam, action(prevent)'), $type, $id);
      default:
        $_SESSION['content'] = serialize((array) $content);
        $_SESSION['type'] = $type;
        spam_update_statistics(t('prevented spam @type', array(
          '@type' => $type,
        )));
        drupal_goto('spam/denied');
      case SPAM_ACTION_PREVENT_SILENT:
        spam_log(SPAM_LOG, 'spam_scan', t('content is spam, action(prevent silently)'), $type, $id);
        spam_update_statistics(t('silently prevented spam @type', array(
          '@type' => $type,
        )));
        if ($id) {

          // Content was already published, so we unpublish it.
          spam_unpublish($type, $id, $extra);
        }

        // TODO: We redirect to avoid the content being posted, but we should
        //       be much smarter about where we redirect to.
        drupal_goto('');
        break;
      case SPAM_ACTION_UNPUBLISH:
        spam_log(SPAM_LOG, 'spam_scan', t('content is spam, action(unpublish)'), $type, $id);
        spam_update_statistics(t('prevented spam @type', array(
          '@type' => $type,
        )));
        if ($id) {
          spam_unpublish($type, $id, $extra);
        }
        break;
    }
  }
}