function cleantalk_validate_comment in Anti Spam by CleanTalk 7.5
Same name and namespace in other branches
- 8.4 cleantalk.module \cleantalk_validate_comment()
- 8 cleantalk.module \cleantalk_validate_comment()
- 8.3 cleantalk.module \cleantalk_validate_comment()
- 7 cleantalk.module \cleantalk_validate_comment()
- 7.2 cleantalk.module \cleantalk_validate_comment()
- 7.4 cleantalk.module \cleantalk_validate_comment()
- 9.1.x cleantalk.module \cleantalk_validate_comment()
Cleantalk comment validation function.
1 string reference to 'cleantalk_validate_comment'
- _cleantalk_form_alter in ./
cleantalk.module - Cleantalk inner function - alters needed form.
File
- ./
cleantalk.module, line 70 - Main CleanTalk integration module functions.
Code
function cleantalk_validate_comment(&$form, &$form_state) {
global $user;
if (variable_get('cleantalk_check_comments', 0) && CleantalkFuncs::_cleantalk_check_form_submit_handlers($form_state['triggering_element']['#parents'])) {
$spam_check = array();
// Fill parameters array for usual comment
$spam_check['type'] = 'comment';
$comment_lang = array_key_exists('language', $form_state['values']) ? $form_state['values']['language'] : LANGUAGE_NONE;
if (isset($form_state['values']['comment_body']) && is_array($form_state['values']['comment_body']) && isset($form_state['values']['comment_body'][$comment_lang]) && is_array($form_state['values']['comment_body'][$comment_lang]) && isset($form_state['values']['comment_body'][$comment_lang][0])) {
$comment_body = $form_state['values']['comment_body'][$comment_lang][0];
}
// Values below can be empty, we'll check as comment because of $base_form_id
if (isset($user->mail)) {
$spam_check['sender_email'] = $user->mail;
}
else {
$spam_check['sender_email'] = !empty($form_state['values']['mail']) ? $form_state['values']['mail'] : '';
}
$spam_check['sender_nickname'] = !empty($form_state['values']['name']) ? $form_state['values']['name'] : '';
$spam_check['message_title'] = !empty($form_state['values']['subject']) ? $form_state['values']['subject'] : '';
$spam_check['message_body'] = is_array($comment_body) && isset($comment_body['value']) ? $comment_body['value'] : '';
$spam_result = CleantalkFuncs::_cleantalk_check_spam($spam_check, form_get_errors());
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
if (variable_get('cleantalk_check_comments_automod', 0) == 0 || $spam_result['stop_queue'] == 1) {
form_set_error('comment_body', $spam_result['ct_result_comment']);
}
}
}
}