function cleantalk_validate_forum_topic in Anti Spam by CleanTalk 9.1.x
Same name and namespace in other branches
- 8.4 cleantalk.module \cleantalk_validate_forum_topic()
- 8.3 cleantalk.module \cleantalk_validate_forum_topic()
Cleantalk inner function - forum topic validation function.
1 string reference to 'cleantalk_validate_forum_topic'
- _cleantalk_form_alter in ./
cleantalk.module - Cleantalk inner function - alters needed form.
File
- ./
cleantalk.module, line 229
Code
function cleantalk_validate_forum_topic(&$form, &$form_state) {
if (\Drupal::config('cleantalk.settings')
->get('cleantalk_check_forum_topics') && 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'));
$spam_check = array();
$spam_check['type'] = 'forum_topic';
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 : '';
}
else {
$spam_check['sender_nickname'] = $ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '';
}
$spam_check['sender_email'] = $ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '';
$spam_check['message_title'] = $ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '';
$spam_check['message_body'] = $ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : '';
$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).
$form_state
->setErrorByName('message', strip_tags($spam_result['ct_result_comment'], '<p><a>'));
}
}
}