View source
<?php
use Drupal\Core\Language\Language;
define("CLEANTALK_USER_AGENT", 'drupal8-11');
$cleantalk_executed = false;
function getAutoKey($email, $host, $platform) {
$request = array();
$request['method_name'] = 'get_api_key';
$request['email'] = $email;
$request['website'] = $host;
$request['platform'] = $platform;
$url = 'https://api.cleantalk.org';
$result = sendRawRequest($url, $request);
return $result;
}
function noticePaidTill($api_key) {
$request = array();
$request['method_name'] = 'notice_paid_till';
$request['auth_key'] = $api_key;
$url = 'https://api.cleantalk.org';
$result = sendRawRequest($url, $request);
return $result;
}
function sendRawRequest($url, $data, $isJSON = false, $timeout = 3) {
$result = null;
if (!$isJSON) {
$data = http_build_query($data);
}
else {
$data = \Drupal\Component\Serialization\Json::encode($data);
}
$curl_exec = false;
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Expect:',
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = @curl_exec($ch);
if ($result !== false) {
$curl_exec = true;
}
@curl_close($ch);
}
if (!$curl_exec) {
$opts = array(
'http' => array(
'method' => "POST",
'content' => $data,
),
);
$context = stream_context_create($opts);
$result = @file_get_contents($url, 0, $context);
}
return $result;
}
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
$arh = array();
$rx_http = '/\\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rx_http, $key)) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
$rx_matches = explode('_', $arh_key);
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
foreach ($rx_matches as $ak_key => $ak_val) {
$rx_matches[$ak_key] = ucfirst($ak_val);
}
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return $arh;
}
}
function cleantalk_get_real_ip() {
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
}
else {
$headers = $_SERVER;
}
if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$the_ip = $headers['X-Forwarded-For'];
}
elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$the_ip = $headers['HTTP_X_FORWARDED_FOR'];
}
else {
$the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
return $the_ip;
}
function cleantalk_preprocess_page(&$variables) {
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$_SESSION['ct_submit_comment_time'] = REQUEST_TIME;
$_SESSION['ct_submit_register_time'] = REQUEST_TIME;
}
$ct_check_def = '0';
$ct_check_value = _cleantalk_get_checkjs_value();
$js_template = 'function ctSetCookie(c_name, value, def_value) {
document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
}
setTimeout("ctSetCookie(\\"%s\\", \\"%s\\", \\"%s\\");",1000);';
$js_addon_body = sprintf($js_template, 'ct_checkjs', $ct_check_value, $ct_check_def);
$variables['page']['content']['#attached']['html_head'][] = array(
array(
'#tag' => 'script',
'#value' => $js_addon_body,
),
'ga_scripts',
);
}
function cleantalk_page_build(&$page) {
drupal_session_initialize();
drupal_save_session(true);
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$_SESSION['ct_submit_comment_time'] = REQUEST_TIME;
$_SESSION['ct_submit_register_time'] = REQUEST_TIME;
}
$ct_check_def = '0';
$ct_check_value = _cleantalk_get_checkjs_value();
$js_template = 'function ctSetCookie(c_name, value, def_value) {
document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
}
setTimeout("ctSetCookie(\\"%s\\", \\"%s\\", \\"%s\\");",1000);';
$js_addon_body = sprintf($js_template, 'ct_checkjs', $ct_check_value, $ct_check_def);
}
function cleantalk_form_contact_message_feedback_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_form_user_register_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_form_comment_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_form_comment_node_webform_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_form_mailchimp_signup_subscribe_form_alter(&$form, &$form_state, $form_id) {
drupal_session_start();
$_SESSION['ct_submit_comment_time'] = REQUEST_TIME;
$field_name = 'ct_checkjs';
$ct_check_def = '0';
if (!isset($_COOKIE[$field_name])) {
setcookie($field_name, $ct_check_def, 0, '/');
}
}
function cleantalk_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_form_contact_personal_form_alter(&$form, &$form_state, $form_id) {
_cleantalk_form_alter($form, $form_state, $form_id);
}
function cleantalk_user_presave(\Drupal\user\UserInterface $account) {
$ct_result = _cleantalk_ct_result();
if ($account
->isNew() && @empty($ct_result['ct_request_id'])) {
$spam_check = array();
$spam_check['type'] = 'register';
$spam_check['sender_email'] = !empty($_POST['mail']) ? $_POST['mail'] : '';
$spam_check['sender_nickname'] = !empty($_POST['name']) ? $_POST['name'] : '';
$spam_result = _cleantalk_check_spam($spam_check);
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
_cleantalk_die($spam_result['ct_result_comment']);
}
}
}
function cleantalk_validate_register(&$form, &$form_state) {
$spam_check = array();
$spam_check['type'] = 'register';
$spam_check['sender_email'] = !empty($form_state
->getValue('mail')) ? $form_state
->getValue('mail') : '';
$spam_check['sender_nickname'] = !empty($form_state
->getValue('name')) ? $form_state
->getValue('name') : '';
$spam_check['timezone'] = !empty($form_state
->getValue('timezone')) ? $form_state
->getValue('timezone') : '';
$spam_result = _cleantalk_check_spam($spam_check);
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
$form_state
->setErrorByName('mail', $spam_result['ct_result_comment']);
}
}
function cleantalk_validate_comment(&$form, &$form_state) {
global $user;
if (is_object($user) && isset($user->uid) && $user->uid > 0) {
}
$comment_lang = !empty($form_state
->getValue('language')) ? $form_state
->getValue('language') : Language::LANGCODE_NOT_SPECIFIED;
$comment_body = $form_state
->getValue('comment_body')[0]['value'];
$spam_check = array();
$spam_check['type'] = 'comment';
$spam_check['sender_email'] = !empty($form_state
->getValue('mail')) ? $form_state
->getValue('mail') : '';
$spam_check['sender_nickname'] = !empty($form_state
->getValue('name')) ? $form_state
->getValue('name') : '';
$spam_check['message_title'] = !empty($form_state
->getValue('subject')[0]['value']) ? $form_state
->getValue('subject')[0]['value'] : '';
$spam_check['message_body'] = !empty($comment_body) ? $comment_body : '';
$spam_result = _cleantalk_check_spam($spam_check);
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
$form_state
->setErrorByName('comment_body', $spam_result['ct_result_comment']);
}
}
function cleantalk_validate_contact_message(&$form, &$form_state) {
global $user;
if (is_object($user) && isset($user->uid) && $user->uid > 0) {
$result = db_query('SELECT count(*) AS count FROM {comment} WHERE uid=:uid AND status=1', array(
':uid' => $user->uid,
));
$count = intval($result
->fetchObject()->count);
$ct_comments = \Drupal::config('cleantalk.settings')
->get('cleantalk_comments');
if ($count >= $ct_comments) {
return;
}
}
$spam_check = array();
$spam_check['type'] = 'contact';
$spam_check['sender_email'] = !empty($form_state
->getValue('mail')) ? $form_state
->getValue('mail') : '';
$spam_check['sender_nickname'] = !empty($form_state
->getValue('name')) ? $form_state
->getValue('name') : '';
$spam_check['message_title'] = !empty($form_state
->getValue('subject')[0]['value']) ? $form_state
->getValue('subject')[0]['value'] : '';
$spam_check['message_body'] = !empty($form_state
->getValue('message')[0]['value']) ? $form_state
->getValue('message')[0]['value'] : '';
$spam_result = _cleantalk_check_spam($spam_check);
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
$form_state
->setErrorByName('message', $spam_result['ct_result_comment']);
}
}
function cleantalk_comment_presave(\Drupal\comment\CommentInterface $comment) {
$ct_result = _cleantalk_ct_result();
if (!empty($ct_result['ct_request_id'])) {
$ct_automod = \Drupal::config('cleantalk.settings')
->get('cleantalk_automod');
if ($ct_automod == 1) {
$comment
->setPublished(empty($ct_result['ct_result_comment']) ? COMMENT_PUBLISHED : 0);
}
}
}
function cleantalk_comment_insert(\Drupal\comment\CommentInterface $comment) {
$ct_result = _cleantalk_ct_result();
if (!empty($ct_result['ct_request_id'])) {
db_insert('cleantalk_cids')
->fields(array(
'cid' => $comment
->id(),
'ct_request_id' => $ct_result['ct_request_id'],
'ct_result_comment' => empty($ct_result['ct_result_comment']) ? '' : $ct_result['ct_result_comment'],
))
->execute();
_cleantalk_ct_result('set');
}
}
function cleantalk_user_insert(\Drupal\user\UserInterface $account) {
$ct_result = _cleantalk_ct_result();
if (!empty($ct_result['ct_request_id'])) {
db_insert('cleantalk_uids')
->fields(array(
'uid' => $account
->id(),
'ct_request_id' => $ct_result['ct_request_id'],
'ct_result_comment' => empty($ct_result['ct_result_comment']) ? '' : $GLOBALS['ct_result_comment'],
))
->execute();
_cleantalk_ct_result('set');
}
}
function cleantalk_comment_publish($comment) {
$result = db_select('cleantalk_cids', 'c')
->fields('c', array(
'ct_request_id',
'ct_result_comment',
))
->condition('cid', $comment->cid, '=')
->range(0, 1)
->execute();
if ($result
->rowCount() > 0) {
$ct_result = $result
->fetchObject();
_cleantalk_send_feedback($ct_result->ct_request_id, 1);
db_delete('cleantalk_cids')
->condition('cid', $comment->cid, '=')
->execute();
}
}
function cleantalk_comment_delete(\Drupal\comment\CommentInterface $comment) {
$result = db_select('cleantalk_cids', 'c')
->fields('c', array(
'ct_request_id',
'ct_result_comment',
))
->condition('cid', $comment
->id(), '=')
->range(0, 1)
->execute();
if ($result
->rowCount() > 0) {
$ct_result = $result
->fetchObject();
_cleantalk_send_feedback($ct_result->ct_request_id, 0);
db_delete('cleantalk_cids')
->condition('cid', $comment
->id(), '=')
->execute();
}
}
function cleantalk_user_delete(\Drupal\user\UserInterface $account) {
$result = db_select('cleantalk_uids', 'c')
->fields('c', array(
'ct_request_id',
'ct_result_comment',
))
->condition('uid', $account
->id(), '=')
->range(0, 1)
->execute();
if ($result
->rowCount() > 0) {
$ct_result = $result
->fetchObject();
_cleantalk_send_feedback($ct_result->ct_request_id, 0);
db_delete('cleantalk_uids')
->condition('uid', $account
->id(), '=')
->execute();
}
}
function cleantalk_menu() {
$items['admin/config/cleantalk'] = array(
'title' => 'Antispam by CleanTalk',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'cleantalk_settings_form',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'cleantalk.admin.inc',
);
return $items;
}
function cleantalk_mail($key, &$message, $params) {
if (isset($params['subject'])) {
$message['subject'] = $params['subject'];
}
if (isset($params['body'])) {
$message['body'][] = $params['body'];
}
if (isset($params['headers']) && is_array($params['headers'])) {
$message['headers'] += $params['headers'];
}
}
function _cleantalk_get_ws() {
return array(
'work_url' => \Drupal::config('cleantalk.settings')
->get('cleantalk_work_url'),
'server_url' => \Drupal::config('cleantalk.settings')
->get('cleantalk_server_url'),
'server_ttl' => \Drupal::config('cleantalk.settings')
->get('cleantalk_server_ttl'),
'server_changed' => \Drupal::config('cleantalk.settings')
->get('cleantalk_server_changed'),
);
}
function _cleantalk_set_ws($work_url = 'http://moderate.cleantalk.ru', $server_url = 'http://moderate.cleantalk.ru', $server_ttl = 0, $server_changed = 0) {
\Drupal::configFactory()
->getEditable('cleantalk.settings')
->set('cleantalk_work_url', $work_url)
->save();
\Drupal::configFactory()
->getEditable('cleantalk.settings')
->set('cleantalk_server_url', $server_url)
->save();
\Drupal::configFactory()
->getEditable('cleantalk.settings')
->set('cleantalk_server_ttl', $server_ttl)
->save();
\Drupal::configFactory()
->getEditable('cleantalk.settings')
->set('cleantalk_server_changed', $server_changed)
->save();
}
function _cleantalk_send_feedback($request_id, $feedback) {
$ct_authkey = \Drupal::config('cleantalk.settings')
->get('cleantalk_authkey');
$ct_ws = _cleantalk_get_ws();
$ct = new Drupal\cleantalk\Cleantalk();
$ct->work_url = $ct_ws['work_url'];
$ct->server_url = $ct_ws['server_url'];
$ct->server_ttl = $ct_ws['server_ttl'];
$ct->server_changed = $ct_ws['server_changed'];
$ct_request = new Drupal\cleantalk\CleantalkRequest();
$ct_request->auth_key = $ct_authkey;
$ct_request->agent = CLEANTALK_USER_AGENT;
$ct_request->sender_ip = Drupal::request()
->getClientIp();
$ct_request->feedback = $request_id . ':' . $feedback;
$ct
->sendFeedback($ct_request);
}
function _cleantalk_form_alter(&$form, &$form_state, $form_id) {
static $js_cookie_added = FALSE;
$ct_link = \Drupal::config('cleantalk.settings')
->get('cleantalk_link');
if ($ct_link != 0) {
$form['cleantalk_link'] = array(
'#type' => 'item',
'#markup' => t("<a href='https://cleantalk.org/drupal-anti-spam-module-wo-captcha'>Drupal spam</a> blocked by CleanTalk."),
'#required' => FALSE,
'#weight' => 999,
);
}
$js_cookie_added = TRUE;
if ($form_id == 'user_register_form') {
$session_time_key = 'ct_submit_register_time';
$form['#validate'][] = 'cleantalk_validate_register';
}
else {
$session_time_key = 'ct_submit_comment_time';
if ($form_id == 'comment_comment_form' || $form_id == 'comment_form') {
$form['#validate'][] = 'cleantalk_validate_comment';
}
if ($form_id == 'contact_site_form' || $form_id == 'contact_personal_form' || $form_id == 'contact_message_feedback_form') {
$form['#validate'][] = 'cleantalk_validate_contact_message';
}
else {
if (\Drupal::config('cleantalk.settings')
->get('cleantalk_ccf') == 1) {
$form['#validate'][] = 'cleantalk_validate_contact_message';
}
}
}
$field_name = 'ct_checkjs';
$ct_check_def = '0';
if (!isset($_COOKIE[$field_name])) {
setcookie($field_name, $ct_check_def, 0, '/');
}
}
function _cleantalk_get_checkjs_value() {
return md5(\Drupal::config('cleantalk.settings')
->get("cleantalk_authkey") . '+' . \Drupal::config('system.site')
->get("mail"));
}
function _cleantalk_check_spam($spam_check) {
global $cleantalk_executed;
if ($cleantalk_executed) {
return;
}
$ct_authkey = \Drupal::config('cleantalk.settings')
->get('cleantalk_authkey');
$ct_ws = _cleantalk_get_ws();
$checkjs = 0;
if (!isset($_COOKIE['ct_checkjs'])) {
$checkjs = NULL;
}
elseif ($_COOKIE['ct_checkjs'] == _cleantalk_get_checkjs_value()) {
$checkjs = 1;
}
else {
$checkjs = 0;
}
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$refferrer = $_SERVER['HTTP_REFERER'];
$ct = new Drupal\cleantalk\Cleantalk();
$ct->work_url = $ct_ws['work_url'];
$ct->server_url = $ct_ws['server_url'];
$ct->server_ttl = $ct_ws['server_ttl'];
$ct->server_changed = $ct_ws['server_changed'];
$ct_options = array(
'access_key' => $ct_authkey,
'cleantalk_automod' => \Drupal::config('cleantalk.settings')
->get('cleantalk_automod'),
);
$sender_info = \Drupal\Component\Serialization\Json::encode(array(
'cms_lang' => 'en',
'REFFERRER' => $refferrer,
'post_url' => $refferrer,
'USER_AGENT' => $user_agent,
'ct_options' => \Drupal\Component\Serialization\Json::encode($ct_options),
));
$ct_request = new Drupal\cleantalk\CleantalkRequest();
$ct_request->auth_key = $ct_authkey;
$ct_request->agent = CLEANTALK_USER_AGENT;
$ct_request->response_lang = 'en';
$ct_request->js_on = $checkjs;
$ct_request->sender_info = $sender_info;
$ct_request->sender_email = $spam_check['sender_email'];
$ct_request->sender_nickname = $spam_check['sender_nickname'];
$ct_request->sender_ip = Drupal::request()
->getClientIp();
$ct_submit_time = NULL;
switch ($spam_check['type']) {
case 'comment':
case 'contact':
if (isset($_SESSION['ct_submit_comment_time'])) {
$ct_submit_time = REQUEST_TIME - $_SESSION['ct_submit_comment_time'];
}
$timelabels_key = 'mail_error_comment';
$ct_request->submit_time = $ct_submit_time;
$ct_request->message = $spam_check['message_title'] . " \n\n" . $spam_check['message_body'];
$post_info = '';
$a_post_info['comment_type'] = 'comment';
$post_info = \Drupal\Component\Serialization\Json::encode($a_post_info);
if ($post_info === FALSE) {
$post_info = '';
}
$ct_request->post_info = $post_info;
$ct_request->example = '';
$ct_result = $ct
->isAllowMessage($ct_request);
break;
case 'register':
if (isset($_SESSION['ct_submit_register_time'])) {
$ct_submit_time = REQUEST_TIME - $_SESSION['ct_submit_register_time'];
}
$timelabels_key = 'mail_error_reg';
$ct_request->submit_time = $ct_submit_time;
$ct_request->tz = $spam_check['timezone'];
$ct_result = $ct
->isAllowUser($ct_request);
break;
}
$cleantalk_executed = true;
$ret_val = array();
$ret_val['ct_request_id'] = $ct_result->id;
if ($ct->server_change) {
_cleantalk_set_ws($ct->work_url, $ct->server_url, $ct->server_ttl, REQUEST_TIME);
}
if (!empty($ct_result->errstr) || !empty($ct_result->inactive) && $ct_result->inactive == 1) {
$ret_val['errno'] = 1;
if ($checkjs == 0) {
$ret_val['allow'] = 0;
}
$err_title = $_SERVER['SERVER_NAME'] . ' - CleanTalk hook error';
if (!empty($ct_result->errstr)) {
$ret_val['errstr'] = _cleantalk_filter_response($ct_result->errstr);
}
else {
$ret_val['errstr'] = _cleantalk_filter_response($ct_result->comment);
}
$send_flag = FALSE;
$result = db_select('cleantalk_timelabels', 'c')
->fields('c', array(
'ct_value',
))
->condition('ct_key', $timelabels_key, '=')
->execute();
$results = $result
->fetchCol(0);
if (count($results) == 0) {
$send_flag = TRUE;
}
elseif (REQUEST_TIME - 900 > $result
->fetchObject()->ct_value) {
$send_flag = TRUE;
}
if ($send_flag) {
db_merge('cleantalk_timelabels')
->key(array(
'ct_key' => $timelabels_key,
))
->fields(array(
'ct_value' => REQUEST_TIME,
))
->execute();
if (!empty($to)) {
drupal_mail("cleantalk", $timelabels_key, $to, language_default(), array(
'subject' => $err_title,
'body' => $ret_val['errstr'],
'headers' => array(),
), $to, TRUE);
}
}
return $ret_val;
}
$ret_val['errno'] = 0;
if ($ct_result->allow == 1) {
$ret_val['allow'] = 1;
_cleantalk_ct_result('set', $ct_result->id);
}
else {
$ret_val['allow'] = 0;
$ret_val['ct_result_comment'] = _cleantalk_filter_response($ct_result->comment);
if ($spam_check['type'] == 'comment' && $ct_result->stop_queue == 0) {
$ret_val['stop_queue'] = 0;
_cleantalk_ct_result('set', $ct_result->id, $ret_val['ct_result_comment']);
}
else {
$ret_val['stop_queue'] = 1;
}
}
return $ret_val;
}
function _cleantalk_filter_response($ct_response) {
if (preg_match('//u', $ct_response)) {
$err_str = preg_replace('/\\*\\*\\*/iu', '', $ct_response);
}
else {
$err_str = preg_replace('/\\*\\*\\*/i', '', $ct_response);
}
return \Drupal\Component\Utility\Xss::filter($err_str, array(
'a',
));
}
function _cleantalk_ct_result($cmd = 'get', $id = '', $comment = '') {
static $request_id = '';
static $result_comment = '';
if ($cmd == 'set') {
$request_id = $id;
$result_comment = $comment;
}
else {
return array(
'ct_request_id' => $request_id,
'ct_result_comment' => $result_comment,
);
}
}
function _cleantalk_die($message) {
print '<!DOCTYPE html><!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono--><html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Blacklisted</title> <style type="text/css"> html { background: #f1f1f1; } body { background: #fff; color: #444; font-family: "Open Sans", sans-serif; margin: 2em auto; padding: 1em 2em; max-width: 700px; -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.13); box-shadow: 0 1px 3px rgba(0,0,0,0.13); } h1 { border-bottom: 1px solid #dadada; clear: both; color: #666; font: 24px "Open Sans", sans-serif; margin: 30px 0 0 0; padding: 0; padding-bottom: 7px; } #error-page { margin-top: 50px; } #error-page p { font-size: 14px; line-height: 1.5; margin: 25px 0 20px; } a { color: #21759B; text-decoration: none; } a:hover { color: #D54E21; } </style></head><body id="error-page"> <p><center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> Spam protection</center><br><br>' . $message . '<script>setTimeout("history.back()", 5000);</script></p><p><a href="javascript:history.back()">« Back</a></p></body></html>';
drupal_exit();
}
function cleantalk_get_data_from_submit($value = null, $field_name = null) {
if (!$value || !$field_name || !is_string($value)) {
return false;
}
if (preg_match("/[a-z0-9_\\-]*" . $field_name . "[a-z0-9_\\-]*\$/", $value)) {
return true;
}
}
function cleantalk_get_fields_any(&$email, &$message, &$nickname, &$subject, $arr) {
foreach ($arr as $key => $value) {
if (!is_array($value) && !is_object($value)) {
if ($email === '' && @preg_match("/^\\S+@\\S+\\.\\S+\$/", $value)) {
$email = $value;
}
else {
if ($nickname === '' && cleantalk_get_data_from_submit($value, 'name')) {
$nickname = $value;
}
else {
if ($subject === '' && cleantalk_get_data_from_submit($value, 'subject')) {
$subject = $value;
}
else {
@($message .= "{$value}\n");
}
}
}
}
else {
if (!is_object($value)) {
cleantalk_get_fields_any($email, $message, $nickname, $subject, $value);
}
}
}
}
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' => CLEANTALK_USER_AGENT,
'sender_ip' => $_SERVER['REMOTE_ADDR'],
'sender_email' => 'good@cleantalk.org',
'sender_nickname' => 'CleanTalk',
'js_on' => 1,
);
sendRawRequest($url, $dt, true);
}
$ct_ccf = \Drupal::config('cleantalk.settings')
->get('cleantalk_ccf');
if (sizeof($_POST) > 0 && !isset($_POST['form_build_id']) && !isset($_POST['form_id']) && $ct_ccf == 1) {
$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 = \Drupal::config('cleantalk.settings')
->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' => CLEANTALK_USER_AGENT,
'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,
);
$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 = \Drupal::config('cleantalk.settings')
->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' => CLEANTALK_USER_AGENT,
'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,
);
$result = _cleantalk_check_spam($data);
if ($result['allow'] === 0) {
drupal_set_message($result['ct_result_comment'], 'error');
$_POST['mergevars']['EMAIL'] = '';
}
}
}
}
function cleantalk_webform_submission_presave($node, &$submission) {
global $user;
if ($user->uid > 0) {
$result = db_query('SELECT count(*) AS count FROM {comment} WHERE uid=:uid AND status=1', array(
':uid' => $user->uid,
));
$count = intval($result
->fetchObject()->count);
$ct_comments = \Drupal::config('cleantalk.settings')
->get('cleantalk_comments');
if ($count >= $ct_comments) {
return;
}
}
$sender_email = null;
$message = '';
foreach ($_POST['submitted'] as $key => $value) {
if ($sender_email === null && !is_array($value) && preg_match("/^\\S+@\\S+\\.\\S+\$/", $value)) {
$sender_email = $value;
}
else {
$message .= "{$value}\n";
}
}
$spam_check = array();
$spam_check['type'] = 'comment';
$spam_check['sender_email'] = !empty($sender_email) ? $sender_email : '';
$spam_check['sender_nickname'] = '';
$spam_check['message_title'] = '';
$spam_check['message_body'] = $message;
$spam_check['example_title'] = '';
$spam_check['example_body'] = '';
$spam_check['example_comments'] = '';
$spam_result = _cleantalk_check_spam($spam_check);
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1 && $spam_result['stop_queue'] == 1) {
$ct_automod = \Drupal::config('cleantalk.settings')
->get('cleantalk_automod');
if ($ct_automod == 1) {
$submission->is_draft = empty($spam_result['ct_result_comment']) ? 0 : 1;
}
drupal_set_message($spam_result['ct_result_comment'], 'error');
}
}
function cleantalk_uc_order($op, $order, $arg2) {
global $cleantalk_executed;
$email = '';
$message = '';
$nickname = '';
$subject = '';
cleantalk_get_fields_any($email, $message, $nickname, $subject, $_POST);
if ($email != '' && !$cleantalk_executed && $op != 'total' && $op != 'presave' && $op != 'save') {
$spam_check = array();
$spam_check['type'] = 'comment';
$spam_check['sender_email'] = $email;
$spam_check['sender_nickname'] = $nickname;
$spam_check['message_title'] = $subject;
$spam_check['message_body'] = $message;
$spam_check['example_title'] = '';
$spam_check['example_body'] = '';
$spam_check['example_comments'] = '';
$spam_result = _cleantalk_check_spam($spam_check);
$cleantalk_executed = true;
if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1 && $spam_result['stop_queue'] == 1) {
if (strpos($_SERVER['REQUEST_URI'], 'ajax') !== false) {
print $spam_result['ct_result_comment'];
drupal_exit();
}
else {
_cleantalk_die($spam_result['ct_result_comment']);
}
}
}
}
function cleantalk_install() {
$spam_check = array();
$spam_check['type'] = 'comment';
$spam_check['sender_email'] = 'good@cleantalk.org';
$spam_check['sender_nickname'] = 'CleanTalk';
$spam_check['message_title'] = '';
$spam_check['message_body'] = 'This message is a test to check the connection to the CleanTalk servers.';
$spam_check['example_title'] = '';
$spam_check['example_body'] = '';
$spam_check['example_comments'] = '';
$spam_result = _cleantalk_check_spam($spam_check);
}
function get_data_from_submit($value = null, $field_name = null) {
if (!$value || !$field_name || !is_string($value)) {
return false;
}
if (preg_match("/[a-z0-9_\\-]*" . $field_name . "[a-z0-9_\\-]*\$/", $value)) {
return true;
}
}
function get_fields_any(&$email, &$message, &$nickname, &$subject, &$contact, $arr) {
$skip_params = array(
'ipn_track_id',
'txn_type',
'payment_status',
);
foreach ($arr as $key => $value) {
if (!is_array($value) && !is_object($value)) {
if (in_array($key, $skip_params) && $key != 0 && $key != '' || preg_match("/^ct_checkjs/", $key)) {
$contact = false;
}
if ($email === '' && preg_match("/^\\S+@\\S+\\.\\S+\$/", $value)) {
$email = $value;
}
else {
if ($nickname === '' && get_data_from_submit($value, 'name')) {
$nickname = $value;
}
else {
if ($subject === '' && get_data_from_submit($value, 'subject')) {
$subject = $value;
}
else {
$message .= "{$value}\n";
}
}
}
}
else {
get_fields_any($email, $message, $nickname, $subject, $contact, $value);
}
}
}