function _antispam_node_form_validate in AntiSpam 6
Node form validate callback; check for spambots.
1 string reference to '_antispam_node_form_validate'
- antispam_form_alter in ./
antispam.module - Implementation of hook_form_alter().
File
- ./
antispam.module, line 891
Code
function _antispam_node_form_validate($form, &$form_state) {
// Quit if there have already been errors in the form.
if (form_get_errors()) {
return;
}
// Ok, let's build a quick query to see if we can catch a spambot.
global $user;
$antispambot_rules = antispam_get_anti_spambot_rules();
$sql_where = array();
$sql_args = array();
if ($antispambot_rules['ip']) {
$sql_where[] = 's.hostname = \'%s\'';
$sql_args[] = ip_address();
}
if ($antispambot_rules['body'] && !empty($form_state['values']['body'])) {
$sql_where[] = 'r.body = \'%s\'';
$sql_args[] = $form_state['values']['body'];
}
if ($antispambot_rules['mail'] && !empty($user->mail)) {
$sql_where[] = 's.mail = \'%s\'';
$sql_args[] = $user->mail;
}
if (count($sql_where) > 0) {
if ($antispambot_rules['body'] || $antispambot_rules['mail']) {
$sql_stmt = 'SELECT 1 FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid INNER JOIN {antispam_spam_marks} s ON s.content_type = \'node\' AND s.content_id = n.nid WHERE (%cond)';
}
else {
$sql_stmt = 'SELECT 1 FROM {antispam_spam_marks} s WHERE s.content_type = \'node\' AND (%cond)';
}
$sql_stmt = str_replace('%cond', implode(' OR ', $sql_where), $sql_stmt);
if (db_result(db_query($sql_stmt, $sql_args, 0, 1))) {
antispam_anti_spambot_action(array(
t('SQL') => _antispam_translate_query($sql_stmt, $sql_args),
t('E-mail') => isset($user->mail) ? $user->mail : '',
t('Body') => $form_state['values']['body'],
));
}
}
}