You are here

function cleantalk_init in Anti Spam by CleanTalk 7.5

Same name and namespace in other branches
  1. 7.2 cleantalk.module \cleantalk_init()
  2. 7.4 cleantalk.module \cleantalk_init()

Implements hook_init()

File

./cleantalk.module, line 320
Main CleanTalk integration module functions.

Code

function cleantalk_init() {
  global $user;
  if (user_access('administer modules') || path_is_admin(current_path())) {
    return;
  }

  // Remote calls
  if (isset($_GET['spbc_remote_call_token'], $_GET['spbc_remote_call_action'], $_GET['plugin_name']) && in_array($_GET['plugin_name'], array(
    'antispam',
    'anti-spam',
    'apbct',
  ))) {
    CleantalkFuncs::_cleantalk_apbct_remote_call__perform();
  }
  CleantalkFuncs::_cleantalk_apbct_cookies_set();
  drupal_add_js(drupal_get_path('module', 'cleantalk') . '/src/js/apbct-public.js', 'file');
  drupal_add_js('ctSetCookie("ct_check_js", "' . CleantalkFuncs::_cleantalk_get_checkjs_value() . '", "0");', array(
    'type' => 'inline',
    'scope' => 'footer',
    'weight' => 5,
    /*'cache' => FALSE,
     * This not need here
     * 'cache' option Used only when 'type' references a JavaScript file
     * https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7.x
     */
    'every_page' => TRUE,
  ));
  $ct_authkey = trim(variable_get('cleantalk_authkey', ''));
  if ($ct_authkey != '') {
    if (sizeof($_POST) > 0 && !isset($_POST['form_build_id']) && !isset($_POST['form_id']) && variable_get('cleantalk_check_ccf', 0) && strpos($_SERVER['REQUEST_URI'], 'cron.php') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'libwww-perl') === false && strpos($_SERVER['REQUEST_URI'], 'checkout/add') === false) {

      //Custom Contact forms
      $spam_check = array();
      $ct_temp_msg_data = CleantalkFuncs::_cleantalk_get_fields_any($_POST);
      $spam_check['type'] = 'custom_contact_form';
      $spam_check['sender_email'] = $ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '';
      $spam_check['sender_nickname'] = $ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '';
      $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'] : '';
      if ($spam_check['sender_email'] != '' && (!empty($spam_check['message_title']) || !empty($spam_check['message_body']))) {
        $spam_result = CleantalkFuncs::_cleantalk_check_spam($spam_check);
        if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
          drupal_set_message($spam_result['ct_result_comment'], 'error');
        }
      }
    }
    if (isset($_GET['q']) && strpos($_GET['q'], 'search') !== false && module_exists('search')) {

      // Search form
      if (variable_get('cleantalk_add_search_noindex', 0)) {

        // Setup index search results
        $skip_index_results = array(
          '#type' => 'html_tag',
          '#tag' => 'meta',
          '#attributes' => array(
            'name' => 'robots',
            'content' => 'noindex',
          ),
        );

        // Add header meta tag for skip index results
        drupal_add_html_head($skip_index_results, 'skip_index_results');
      }
      if (variable_get('cleantalk_check_search_form', 0)) {
        $get_query = explode("/", $_GET['q']);
        if (count($get_query) > 2) {
          $search_word = $get_query[2];
          $spam_check['type'] = 'site_search_drupal7';
          $spam_check['sender_email'] = !empty($user->mail) ? $user->mail : '';
          $spam_check['sender_nickname'] = !empty($user->name) ? $user->name : '';
          $spam_check['message_title'] = '';
          $spam_check['message_body'] = $search_word;
          if ($spam_check['sender_email'] != '' || $spam_check['message_body']) {
            $spam_result = CleantalkFuncs::_cleantalk_check_spam($spam_check);
            if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {
              CleantalkFuncs::_cleantalk_die($spam_result['ct_result_comment']);
            }
          }
        }
      }
    }
  }
}