You are here

public static function CleantalkFuncs::_cleantalk_apbct_remote_call__perform in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/CleantalkFuncs.php \CleantalkFuncs::_cleantalk_apbct_remote_call__perform()

Cleantalk inner function - perform remote call

1 call to CleantalkFuncs::_cleantalk_apbct_remote_call__perform()
cleantalk_init in ./cleantalk.module
Implements hook_init()

File

src/CleantalkFuncs.php, line 827

Class

CleantalkFuncs
Cleantalk class create request

Code

public static function _cleantalk_apbct_remote_call__perform() {
  $remote_calls_config = variable_get('cleantalk_remote_calls', array());
  $remote_action = $_GET['spbc_remote_call_action'];
  $auth_key = trim(variable_get('cleantalk_authkey', ''));
  if (array_key_exists($remote_action, $remote_calls_config)) {
    if (time() - $remote_calls_config[$remote_action]['last_call'] > APBCT_REMOTE_CALL_SLEEP) {
      $remote_calls[$remote_action]['last_call'] = time();
      variable_set('remote_calls', $remote_calls);
      if (strtolower($_GET['spbc_remote_call_token']) == strtolower(md5($auth_key))) {

        // Close renew banner
        if ($_GET['spbc_remote_call_action'] == 'close_renew_banner') {
          variable_set('cleantalk_show_renew_banner', 0);
          die('OK');

          // SFW update
        }
        elseif ($_GET['spbc_remote_call_action'] == 'sfw_update') {
          $sfw = new CleantalkSFW();
          $result = $sfw
            ->sfw_update($auth_key);
          die(empty($result['error']) ? 'OK' : 'FAIL ' . json_encode(array(
            'error' => $result['error_string'],
          )));

          // SFW send logs
        }
        elseif ($_GET['spbc_remote_call_action'] == 'sfw_send_logs') {
          $sfw = new CleantalkSFW();
          $result = $sfw
            ->sfw_send_logs($auth_key);
          die(empty($result['error']) ? 'OK' : 'FAIL ' . json_encode(array(
            'error' => $result['error_string'],
          )));

          // Update plugin
        }
        elseif ($_GET['spbc_remote_call_action'] == 'update_plugin') {

          //add_action('wp', 'apbct_update', 1);
        }
        else {
          die('FAIL ' . json_encode(array(
            'error' => 'UNKNOWN_ACTION_2',
          )));
        }
      }
      else {
        die('FAIL ' . json_encode(array(
          'error' => 'WRONG_TOKEN',
        )));
      }
    }
    else {
      die('FAIL ' . json_encode(array(
        'error' => 'TOO_MANY_ATTEMPTS',
      )));
    }
  }
  else {
    die('FAIL ' . json_encode(array(
      'error' => 'UNKNOWN_ACTION',
    )));
  }
}