You are here

function antispam_node_validate in AntiSpam 7

Implements hook_node_validate().

File

./antispam.module, line 832
Primary hook implementations for the Antispam module.

Code

function antispam_node_validate($node, $form, &$form_state) {
  global $user;
  $num_condition = 0;
  $debug_info = array();

  // Ok, let's build a quick query to see if we can catch a spambot.
  $antispambot_rules = antispam_get_anti_spambot_rules();
  $query = db_select('antispam_spam_marks', 's');
  if (!empty($antispambot_rules['body'])) {
    $query
      ->join('field_data_body', 'e', 'e.entity_id = s.content_id');
  }
  $query
    ->fields('s', array(
    'content_id',
  ));
  if (!empty($antispambot_rules['body'])) {
    $query
      ->addField('e', 'body_value', 'body');
  }
  $query
    ->condition('s.content_type', 'node');
  $query
    ->range(0, 1);
  if (!empty($antispambot_rules['ip'])) {
    $query
      ->condition('s.hostname', ip_address());
    $debug_info['IP-address'] = ip_address();
    $num_condition++;
  }
  if (!empty($antispambot_rules['mail']) && !empty($user->mail)) {
    $query
      ->condition('s.mail', $user->mail);
    $debug_info['E-mail'] = $user->mail;
    $num_condition++;
  }
  if (!empty($antispambot_rules['body']) && !empty($node->body)) {
    $query
      ->condition('e.body_value', $node->body[$node->language][0]['value']);
    $debug_info['Content'] = $node->body[$node->language][0]['value'];
    $num_condition++;
  }
  if ($num_condition) {
    $has_rows = $query
      ->execute()
      ->fetchField();
    if ($has_rows) {
      antispam_anti_spambot_action($debug_info);
    }
  }
}