function cleantalk_validate_comment in Anti Spam by CleanTalk 8.3
Same name and namespace in other branches
- 8.4 cleantalk.module \cleantalk_validate_comment()
- 8 cleantalk.module \cleantalk_validate_comment()
- 7.5 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 inner function - 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 90
Code
function cleantalk_validate_comment(&$form, &$form_state) {
if (\Drupal::config('cleantalk.settings')
->get('cleantalk_check_comments') && CleantalkFuncs::_cleantalk_check_form_submit_handlers($form_state
->getSubmitHandlers())) {
$current_user = \Drupal::currentUser();
$ct_temp_msg_data = CleantalkHelper::get_fields_any(\Drupal::request()->request
->all(), \Drupal::config('cleantalk.settings')
->get('cleantalk_fields_exclusions'));
$comment_lang = !empty($form_state
->getValue('language')) ? $form_state
->getValue('language') : Language::LANGCODE_NOT_SPECIFIED;
$spam_check = array();
$spam_check['type'] = 'comment';
if ($current_user
->id()) {
$user = \Drupal\user\Entity\User::load($current_user
->id());
$spam_check['sender_nickname'] = !empty($user
->get('name')) ? $user
->get('name')->value : '';
$spam_check['sender_email'] = !empty($user
->get('mail')->value) ? $user
->get('mail')->value : '';
}
else {
if (empty($form_state
->getValue('name'))) {
$spam_check['sender_nickname'] = $ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '';
}
else {
$spam_check['sender_nickname'] = $form_state
->getValue('name');
}
if (empty($form_state
->getValue('mail'))) {
$spam_check['sender_email'] = $ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '';
}
else {
$spam_check['sender_email'] = $form_state
->getValue('mail');
}
}
if (empty($form_state
->getValue('subject')[0]['value'])) {
$spam_check['message_title'] = $ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '';
}
else {
$spam_check['message_title'] = $form_state
->getValue('subject')[0]['value'];
}
if (empty($form_state
->getValue('comment_body')[0]['value'])) {
$spam_check['message_body'] = $ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : '';
}
else {
$spam_check['message_body'] = $form_state
->getValue('comment_body')[0]['value'];
}
$spam_result = CleantalkFuncs::_cleantalk_check_spam($spam_check, $form_state
->getErrors());
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
// Value of ct_result_comment is sanitized already (before storing).
if (!\Drupal::config('cleantalk.settings')
->get('cleantalk_check_comments_automod') || $spam_result['stop_queue'] == 1) {
$form_state
->setErrorByName('comment_body', strip_tags($spam_result['ct_result_comment'], '<p><a>'));
}
}
}
}