function _antispam_comment_form_validate in AntiSpam 6
Comment form validate callback; check for spambots.
1 string reference to '_antispam_comment_form_validate'
- antispam_form_alter in ./
antispam.module - Implementation of hook_form_alter().
File
- ./
antispam.module, line 936
Code
function _antispam_comment_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.
$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']['comment'])) {
$sql_where[] = 'c.comment = \'%s\'';
$sql_args[] = $form_state['values']['comment'];
}
if ($antispambot_rules['mail'] && !empty($form_state['values']['mail'])) {
$sql_where[] = 's.mail = \'%s\'';
$sql_args[] = ${$form_state}['values']['mail'];
}
if (count($sql_where) > 0) {
if ($antispambot_rules['body'] || $antispambot_rules['mail']) {
$sql_stmt = 'SELECT 1 FROM {comments} c INNER JOIN {antispam_spam_marks} s ON s.content_type = \'comment\' AND s.content_id = c.cid WHERE (%cond)';
}
else {
$sql_stmt = 'SELECT 1 FROM {antispam_spam_marks} s WHERE s.content_type = \'comment\' 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') => $form_state['values']['mail'],
t('Comment') => $form_state['values']['comment'],
));
}
}
}