You are here

function cleantalk_boot in Anti Spam by CleanTalk 7.5

Same name and namespace in other branches
  1. 8 cleantalk.module \cleantalk_boot()
  2. 7 cleantalk.module \cleantalk_boot()
  3. 7.2 cleantalk.module \cleantalk_boot()
  4. 7.4 cleantalk.module \cleantalk_boot()

Implements hook_boot()

File

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

Code

function cleantalk_boot() {
  $ct_authkey = trim(variable_get('cleantalk_authkey', ''));
  if (variable_get('cleantalk_sfw', 0)) {
    $sfw = new CleantalkSFW();
    $ct_sfw_last_logs_sent = variable_get('cleantalk_sfw_last_logs_sent', null);
    if ($ct_sfw_last_logs_sent && time() - $ct_sfw_last_logs_sent > 3600) {
      variable_set('cleantalk_sfw_last_logs_sent', time());
      $sfw
        ->send_logs($ct_authkey);
    }
    $ct_sfw_last_updated = variable_get('cleantalk_sfw_last_updated', null);
    if ($ct_sfw_last_updated && time() - $ct_sfw_last_updated > 86400) {
      variable_set('cleantalk_sfw_last_updated', time());
      $sfw
        ->sfw_update($ct_authkey);
    }
    $is_sfw_check = true;
    $sfw->ip_array = (array) CleantalkSFW::ip_get(array(
      'real',
    ), true);
    foreach ($sfw->ip_array as $key => $value) {
      if (isset($_COOKIE['apbct_sfw_pass_key']) && $_COOKIE['apbct_sfw_pass_key'] == md5($value . $ct_authkey)) {
        $is_sfw_check = false;
        if (isset($_COOKIE['apbct_sfw_passed'])) {
          @setcookie('apbct_sfw_passed');

          //Deleting cookie
          $sfw
            ->sfw_update_logs($value, 'passed');
        }
      }
    }
    unset($key, $value);
    if ($is_sfw_check) {
      $sfw
        ->check_ip();
      if ($sfw->result) {
        $sfw
          ->sfw_update_logs($sfw->blocked_ip, 'blocked');
        $sfw
          ->sfw_die($ct_authkey);
      }
    }
  }
}