You are here

function node_age_spam_filter in Spam 5.3

Determine if a comment is being posted against too old of a node.

1 call to node_age_spam_filter()
node_age_spamapi in filters/node_age/node_age.module

File

filters/node_age/node_age.module, line 62

Code

function node_age_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) {
  $action = array();
  $id = spam_invoke_module($type, 'content_id', $content, $extra);
  if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
    $nid = arg(2);
    spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('retrieved nid (@nid) from url', array(
      '@nid' => $nid,
    )), $type, $id);
  }
  else {
    $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', $id));
    spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('retrieved nid (@nid) from database', array(
      '@nid' => $nid,
    )), $type, $id);
  }
  if ($type == 'comment' && $nid) {
    $node = spam_invoke_module('node', 'load', $nid);
    if (is_object($node)) {
      $timestamp_field = variable_get('node_age_filter_on', 'created');
      if ($node->{$timestamp_field} < time() - variable_get('node_age_limit_long', 4838400)) {
        $action['total'] = variable_get('node_age_weight_long', 99);
        spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) older than long limit, spam probability(@weight)', array(
          '@nid' => $nid,
          '@weight' => $action['total'],
        )), $type, $id);
      }
      else {
        if ($node->{$timestamp_field} < time() - variable_get('node_age_limit_short', 2419200)) {
          $action['total'] = variable_get('node_age_weight_short', 85);
          spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) older than short limit, spam probability(@weight)', array(
            '@nid' => $nid,
            '@weight' => $action['total'],
          )), $type, $id);
        }
        else {
          $action['total'] = 0;
          spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) is recent.', array(
            '@nid' => $nid,
          )), $type, $id);
        }
      }
    }
  }
  else {
    spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('content type is not comment, skipping'), $type, $id);
    $action['total'] = 0;
  }
  return $action;
}