You are here

cleantalk.module in Anti Spam by CleanTalk 8

Main CleanTalk integration module functions.

File

cleantalk.module
View source
<?php

use Drupal\Core\Language\Language;
define("CLEANTALK_USER_AGENT", 'drupal8-11');
$cleantalk_executed = false;

/**
 * @file
 * Main CleanTalk integration module functions.
 */

/**
 * Implements hook_html_head_alter(&$head_elements).
 */

/**
 * Function gets access key automatically
 *
 * @param string website admin email
 * @param string website host
 * @param string website platform
 * @return type
 */
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 gets information about renew notice
 *
 * @param string api_key
 * @return type
 */
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 sends raw request to API server
 *
 * @param string url of API server
 * @param array data to send
 * @param boolean is data have to be JSON encoded or not
 * @param integer connect timeout
 * @return type
 */
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);

    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // resolve 'Expect: 100-continue' issue
    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;
}

/*
*
*
*   END OF CLEANTALK BASE CLASS
*
*/
function cleantalk_preprocess_page(&$variables) {

  //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);
  $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);

  // @FIXME
  // The Assets API has totally changed. CSS, JavaScript, and libraries are now
  // attached directly to render arrays using the #attached property.
  //
  //
  // @see https://www.drupal.org/node/2169605
  // @see https://www.drupal.org/node/2408597
  // drupal_add_js($js_addon_body,
  //     array(
  //       'type' => 'inline',
  //       'scope' => 'footer',
  //       'weight' => 5,
  //       'cache' => FALSE,
  //       'every_page' => TRUE,
  //     )
  //   );
}
function cleantalk_form_contact_message_feedback_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cleantalk_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function cleantalk_form_comment_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_form_BASE_FORM_ID_alter()
 */
function cleantalk_form_comment_node_webform_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_form_BASE_FORM_ID_alter()
 */
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, '/');
  }

  // We cannot place JS in separate file.
  // Because it is not static - we have to use generated values.

  /*  $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, $field_name, $ct_check_value, $ct_check_def);

    drupal_add_js($js_addon_body,
      array(
        'type' => 'inline',
        'scope' => 'footer',
        'weight' => 5,
        'cache' => FALSE,
        'every_page' => FALSE,
      )
    );*/
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cleantalk_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cleantalk_form_contact_personal_form_alter(&$form, &$form_state, $form_id) {
  _cleantalk_form_alter($form, $form_state, $form_id);
}

/**
 * Implements hook_user_presave().
 *
 * @FIXME
 * The $edit and $category parameters are gone in Drupal 8. They have been left
 * here in order to prevent 'undefined variable' errors, but they will never
 * actually be passed to this hook. You'll need to modify this function and
 * remove every reference to them.
 */
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']);
    }
  }
}

/**
 * Cleantalk registration validation function.
 */
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) {

    // Value of ct_result_comment is sanitized already (before storing).

    //form_set_error('mail', $spam_result['ct_result_comment']);
    $form_state
      ->setErrorByName('mail', $spam_result['ct_result_comment']);
  }
}

/**
 * Cleantalk comment validation function.
 */
function cleantalk_validate_comment(&$form, &$form_state) {
  global $user;

  // Don't check reged user with >= 'cleantalk_comments' approved msgs.
  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;
        }*/
  }
  $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) {

    // Value of ct_result_comment is sanitized already (before storing).
    $form_state
      ->setErrorByName('comment_body', $spam_result['ct_result_comment']);
  }
}

/**
 * Cleantalk contact message validation function.
 */
function cleantalk_validate_contact_message(&$form, &$form_state) {
  global $user;

  // Don't check reged user with >= 'cleantalk_comments' approved msgs.
  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) {

    // Value of ct_result_comment is sanitized already (before storing).
    $form_state
      ->setErrorByName('message', $spam_result['ct_result_comment']);
  }
}

/**
 * Implements hook_comment_presave().
 */
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) {

      // Automoderation enabled - change comment status.
      // Not empty 'ct_result_comment' means bad comment, set status = 0.
      // Empty 'ct_result_comment' means good comment, set status = 1.
      $comment
        ->setPublished(empty($ct_result['ct_result_comment']) ? COMMENT_PUBLISHED : 0);
    }

    // Don't clear 'ct_request_id', use it in cleantalk_comment_insert().
  }
}

/**
 * Implements hook_comment_insert().
 */
function cleantalk_comment_insert(\Drupal\comment\CommentInterface $comment) {
  $ct_result = _cleantalk_ct_result();
  if (!empty($ct_result['ct_request_id'])) {

    // Values of request_id and comment are stored in globals.
    // Store them in DB now.
    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');
  }
}

/**
 * Implements hook_user_insert().
 *
 * @FIXME
 * The $edit and $category parameters are gone in Drupal 8. They have been left
 * here in order to prevent 'undefined variable' errors, but they will never
 * actually be passed to this hook. You'll need to modify this function and
 * remove every reference to them.
 */
function cleantalk_user_insert(\Drupal\user\UserInterface $account) {

  /*if ($category != 'account') {
      return;
    }*/
  $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');
  }
}

/**
 * Implements hook_comment_publish().
 */
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();

    // If ct_result_comment is not empty then comment is not approved by server.
    // But we publish it then comment is approved by admin.
    // We need to send positive feedback.
    _cleantalk_send_feedback($ct_result->ct_request_id, 1);
    db_delete('cleantalk_cids')
      ->condition('cid', $comment->cid, '=')
      ->execute();
  }
}

/**
 * Implements hook_comment_delete().
 */
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();

    // If ct_result_comment is empty then comment is approved by server.
    // But we delete it then comment is not approved by admin.
    // We need to send negative feedback.
    _cleantalk_send_feedback($ct_result->ct_request_id, 0);
    db_delete('cleantalk_cids')
      ->condition('cid', $comment
      ->id(), '=')
      ->execute();
  }
}

/**
 * Implements hook_user_delete().
 */
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();

    // If ct_result_comment is empty then user is approved by server.
    // But we delete it then user is not approved by admin.
    // We need to send negative feedback.
    _cleantalk_send_feedback($ct_result->ct_request_id, 0);
    db_delete('cleantalk_uids')
      ->condition('uid', $account
      ->id(), '=')
      ->execute();
  }
}

/**
 * Implements hook_comment_view_alter().
 */

//function cleantalk_comment_view_alter(&$build) {

//  if (\Drupal::currentUser()->hasPermission('administer comments')) {
//    $result = db_select('cleantalk_cids', 'c')
//      ->fields('c', array('ct_request_id', 'ct_result_comment'))
//      ->condition('cid', $build['#comment']->cid, '=')
//      ->range(0, 1)
//      ->execute();
//    if ($result->rowCount() > 0) {
//      $ct_result = $result->fetchObject();
//      if (!empty($ct_result->ct_result_comment)) {
//        // Value of ct_result_comment is sanitized already (before storing).
//        $build['comment_body'][0]['#markup'] .= '<hr>' .
//          $ct_result->ct_result_comment;
//      }
//    }
//  }

//}

/**
 * Implements hook_menu().
 */
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;
}

/**
 * Implements hook_mail().
 */
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'];
  }
}

/**
 * Implements hook_libraries_info().
 *
 * For defining external CleanTalk librariy.
 */

/*function cleantalk_libraries_info() {
  // Expected to be extracted into 'sites/all/libraries/cleantalk'.
  $libraries['cleantalk'] = array(
    'name' => 'CleanTalk PHP-antispam classes',
    'vendor url' => 'http://cleantalk.org',
    'download url' => 'https://github.com/CleanTalk/php-antispam',
    'version arguments' => array(
      'file' => 'cleantalk.class.php',
      'pattern' => '/@version\s+([0-9a-zA-Z\.-]+)/',
      'lines' => 10,
    ),
    'files' => array(
      'php' => array('cleantalk.class.php'),
    ),
  );
  return $libraries;
}*/

/**
 * Cleantalk inner function - gets working server.
 */
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'),
  );
}

/**
 * Cleantalk inner function - sets working server.
 */
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();
}

/**
 * Cleantalk inner function - sends feedback to server.
 */
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);
}

/**
 * Cleantalk inner function - missing CleanTalk library message for runtime.
 */

/*function _cleantalk_library_missing_message_4runtime($title, $path) {
  $t = get_t();
  return
    $t(
      '"Antispam by CleanTalk" module is NOT WORKING' .
      ' due to missing or broken CleanTalk library.'
    ) .
    ' <br />' .
    $t(
      'Please download <a target="_blank" href="@url">@title</a>, extract ' .
      'the archive and copy the contents to the following location:' .
      '<br /><code>@path</code>.',
      array(
        '@url' => 'https://github.com/CleanTalk/php-antispam',
        '@path' => $path,
        '@title' => $title,
      )
    ) .
    ' <br />' .
    $t(
      'Make sure 2 files <strong>cleantalk.class.php</strong> and ' .
      '<strong>JSON.php</strong> are located there.'
    ) .
    '<br />';
}*/

/**
 * Cleantalk inner function - alters needed form.
 */
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';
      }
    }
  }

  //drupal_session_start();

  //$_SESSION[$session_time_key] = REQUEST_TIME;
  $field_name = 'ct_checkjs';
  $ct_check_def = '0';
  if (!isset($_COOKIE[$field_name])) {
    setcookie($field_name, $ct_check_def, 0, '/');
  }
}

/**
 * Cleantalk inner function - gets JavaScript checking value.
 */
function _cleantalk_get_checkjs_value() {
  return md5(\Drupal::config('cleantalk.settings')
    ->get("cleantalk_authkey") . '+' . \Drupal::config('system.site')
    ->get("mail"));
}

/**
 * Cleantalk inner function - performs antispam checking.
 */
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;

  //drupal_session_start();
  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'];

      // Additional info.
      $post_info = '';
      $a_post_info['comment_type'] = 'comment';

      // JSON format.
      $post_info = \Drupal\Component\Serialization\Json::encode($a_post_info);

      // Plain text format.
      if ($post_info === FALSE) {
        $post_info = '';
      }
      $ct_request->post_info = $post_info;

      // Example is obsolete now.
      $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);
  }

  // First check errstr flag.
  if (!empty($ct_result->errstr) || !empty($ct_result->inactive) && $ct_result->inactive == 1) {

    // Cleantalk error so we go default way (no action at all).
    $ret_val['errno'] = 1;
    if ($checkjs == 0) {
      $ret_val['allow'] = 0;
    }

    // Just inform admin.
    $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) {

      // 15 minutes.
      $send_flag = TRUE;
    }
    if ($send_flag) {
      db_merge('cleantalk_timelabels')
        ->key(array(
        'ct_key' => $timelabels_key,
      ))
        ->fields(array(
        'ct_value' => REQUEST_TIME,
      ))
        ->execute();

      // @FIXME
      // // @FIXME
      // // This looks like another module's variable. You'll need to rewrite this call
      // // to ensure that it uses the correct configuration object.
      // $to = variable_get('site_mail', ini_get('sendmail_from'));
      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) {

    // Not spammer.
    $ret_val['allow'] = 1;

    // Store request_id in globals to store it in DB later.
    _cleantalk_ct_result('set', $ct_result->id);

    // Don't store 'ct_result_comment', means good comment.
  }
  else {

    // Spammer.
    $ret_val['allow'] = 0;
    $ret_val['ct_result_comment'] = _cleantalk_filter_response($ct_result->comment);

    // Check stop_queue flag.
    if ($spam_check['type'] == 'comment' && $ct_result->stop_queue == 0) {

      // Spammer and stop_queue == 0 - to manual approvement.
      $ret_val['stop_queue'] = 0;

      // Store request_id and comment in static to store them in DB later.
      // Store 'ct_result_comment' - means bad comment.
      _cleantalk_ct_result('set', $ct_result->id, $ret_val['ct_result_comment']);
    }
    else {

      // New user or Spammer and stop_queue == 1 - display form error message.
      $ret_val['stop_queue'] = 1;
    }
  }
  return $ret_val;
}

/**
 * Cleantalk inner function - performs CleanTalk comment|errstr filtering.
 */
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',
  ));
}

/**
 * Cleantalk inner function - stores spam checking result.
 */
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,
    );
  }
}

/**
 * Cleantalk inner function - show error message and exit.
 */
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()">&laquo; Back</a></p></body></html>';
  drupal_exit();
}

/**
 * Inner function - Finds and returns pattern in string
 * @return null|bool
 */
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;
  }
}

/**
* gets data for checking recursively
*/
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);
      }
    }
  }
}

/**
 * Implements hook_boot()
 */
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) {

    //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 = \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,
      );

      /*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 = \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'] = '';
      }
    }
  }
}

/**
 * Implements hook_webform_submission_presave()
 */
function cleantalk_webform_submission_presave($node, &$submission) {
  global $user;

  // Don't check reged user with >= 'cleantalk_comments' approved msgs.
  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');
  }
}

/*
* implemments hook_uc_order - UberCart hook for order processing
*/
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);
}

/**
 * Inner function - Finds and returns pattern in string
 * @return null|bool
 */
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;
  }
}

/*
* Get data from submit recursively
*/
function get_fields_any(&$email, &$message, &$nickname, &$subject, &$contact, $arr) {
  $skip_params = array(
    'ipn_track_id',
    // PayPal IPN #
    'txn_type',
    // PayPal transaction 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);
    }
  }
}

Functions

Namesort descending Description
cleantalk_boot Implements hook_boot()
cleantalk_comment_delete Implements hook_comment_delete().
cleantalk_comment_insert Implements hook_comment_insert().
cleantalk_comment_presave Implements hook_comment_presave().
cleantalk_comment_publish Implements hook_comment_publish().
cleantalk_form_comment_form_alter Implements hook_form_BASE_FORM_ID_alter().
cleantalk_form_comment_node_webform_form_alter Implements hook_form_BASE_FORM_ID_alter()
cleantalk_form_contact_message_feedback_form_alter
cleantalk_form_contact_personal_form_alter Implements hook_form_FORM_ID_alter().
cleantalk_form_contact_site_form_alter Implements hook_form_FORM_ID_alter().
cleantalk_form_mailchimp_signup_subscribe_form_alter Implements hook_form_BASE_FORM_ID_alter()
cleantalk_form_user_register_form_alter Implements hook_form_FORM_ID_alter().
cleantalk_get_data_from_submit Inner function - Finds and returns pattern in string
cleantalk_get_fields_any gets data for checking recursively
cleantalk_get_real_ip
cleantalk_install
cleantalk_mail Implements hook_mail().
cleantalk_menu Implements hook_menu().
cleantalk_page_build
cleantalk_preprocess_page
cleantalk_uc_order
cleantalk_user_delete Implements hook_user_delete().
cleantalk_user_insert Implements hook_user_insert().
cleantalk_user_presave Implements hook_user_presave().
cleantalk_validate_comment Cleantalk comment validation function.
cleantalk_validate_contact_message Cleantalk contact message validation function.
cleantalk_validate_register Cleantalk registration validation function.
cleantalk_webform_submission_presave Implements hook_webform_submission_presave()
getAutoKey Function gets access key automatically
get_data_from_submit Inner function - Finds and returns pattern in string
get_fields_any
noticePaidTill Function gets information about renew notice
sendRawRequest Function sends raw request to API server
_cleantalk_check_spam Cleantalk inner function - performs antispam checking.
_cleantalk_ct_result Cleantalk inner function - stores spam checking result.
_cleantalk_die Cleantalk inner function - show error message and exit.
_cleantalk_filter_response Cleantalk inner function - performs CleanTalk comment|errstr filtering.
_cleantalk_form_alter Cleantalk inner function - alters needed form.
_cleantalk_get_checkjs_value Cleantalk inner function - gets JavaScript checking value.
_cleantalk_get_ws Cleantalk inner function - gets working server.
_cleantalk_send_feedback Cleantalk inner function - sends feedback to server.
_cleantalk_set_ws Cleantalk inner function - sets working server.

Constants