function cleantalk_boot in Anti Spam by CleanTalk 7
Same name and namespace in other branches
- 8 cleantalk.module \cleantalk_boot()
- 7.5 cleantalk.module \cleantalk_boot()
- 7.2 cleantalk.module \cleantalk_boot()
- 7.4 cleantalk.module \cleantalk_boot()
Implements hook_boot()
File
- ./
cleantalk.module, line 1965 - Main CleanTalk integration module functions.
Code
function cleantalk_boot() {
if (isset($_POST['cleantalk_authkey'])) {
$url = 'http://moderate.cleantalk.org/api2.0';
$dt = array(
'auth_key' => $_POST['cleantalk_authkey'],
'method_name' => 'check_message',
'message' => 'This message is a test to check the connection to the CleanTalk servers.',
'example' => null,
'agent' => 'drupal-1120',
'sender_ip' => $_SERVER['REMOTE_ADDR'],
'sender_email' => 'good@cleantalk.org',
'sender_nickname' => 'CleanTalk',
'js_on' => 1,
);
sendRawRequest($url, $dt, true);
}
$ct_ccf = variable_get('cleantalk_ccf', 0);
if (sizeof($_POST) > 0 && !isset($_POST['form_build_id']) && !isset($_POST['form_id']) && $ct_ccf == 1) {
//Custom Contact forms
$sender_email = '';
$sender_nickname = '';
$subject = '';
$message = '';
$contact_form = true;
get_fields_any($sender_email, $message, $sender_nickname, $subject, $contact_form, $_POST);
if ($sender_email != '') {
$ct_authkey = variable_get('cleantalk_authkey', '');
if (!isset($_COOKIE['ct_checkjs'])) {
$checkjs = NULL;
}
elseif ($_COOKIE['ct_checkjs'] == _cleantalk_get_checkjs_value()) {
$checkjs = 1;
}
else {
$checkjs = 0;
}
$data = array(
'type' => 'comment',
'auth_key' => $ct_authkey,
'method_name' => 'check_message',
'message' => $message,
'example' => null,
'agent' => 'drupal-1120',
'sender_ip' => $_SERVER['REMOTE_ADDR'],
'sender_email' => $sender_email,
'sender_nickname' => $sender_nickname,
'message_title' => $subject,
'message_body' => '',
'example_title' => '',
'example_body' => '',
'example_comments' => '',
'comment_body' => '',
'js_on' => $checkjs,
);
if (!function_exists('drupal_json_encode')) {
include_once DRUPAL_ROOT . '/includes/common.inc';
}
if (!function_exists('libraries_load')) {
include_once drupal_get_path('module', 'libraries') . '/libraries.module';
}
$result = _cleantalk_check_spam($data);
if ($result['allow'] === 0) {
drupal_set_message($result['ct_result_comment'], 'error');
}
}
}
if (isset($_POST['mergevars'])) {
$sender_email = null;
$message = '';
foreach ($_POST['mergevars'] as $key => $value) {
if ($sender_email === null && preg_match("/^\\S+@\\S+\\.\\S+\$/", $value)) {
$sender_email = $value;
}
else {
$message .= "{$value}\n";
}
}
if ($sender_email != null) {
$url = 'http://moderate.cleantalk.org/api2.0';
$ct_authkey = variable_get('cleantalk_authkey', '');
if (!isset($_COOKIE['ct_checkjs'])) {
$checkjs = NULL;
}
elseif ($_COOKIE['ct_checkjs'] == _cleantalk_get_checkjs_value()) {
$checkjs = 1;
}
else {
$checkjs = 0;
}
$data = array(
'type' => 'comment',
'auth_key' => $ct_authkey,
'method_name' => 'check_message',
'message' => $message,
'example' => null,
'agent' => 'drupal-1120',
'sender_ip' => $_SERVER['REMOTE_ADDR'],
'sender_email' => $sender_email,
'sender_nickname' => '',
'message_title' => '',
'message_body' => '',
'example_title' => '',
'example_body' => '',
'example_comments' => '',
'comment_body' => '',
'js_on' => $checkjs,
);
if (!function_exists('drupal_json_encode')) {
include_once DRUPAL_ROOT . '/includes/common.inc';
}
if (!function_exists('libraries_load')) {
include_once drupal_get_path('module', 'libraries') . '/libraries.module';
}
$result = _cleantalk_check_spam($data);
if ($result['allow'] === 0) {
drupal_set_message($result['ct_result_comment'], 'error');
$_POST['mergevars']['EMAIL'] = '';
}
}
}
}