You are here

public static function Helper::http__request__rc_to_host in Anti Spam by CleanTalk 9.1.x

Same name and namespace in other branches
  1. 8.4 src/lib/Cleantalk/Common/Helper.php \Cleantalk\Common\Helper::http__request__rc_to_host()

Do the remote call to the host.

@todo Have to replace this method to the new class like HttpHelper

Parameters

string $rc_action:

array $request_params:

array $patterns:

Return value

array|bool

1 call to Helper::http__request__rc_to_host()
FirewallUpdater::update in src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php

File

src/lib/Cleantalk/Common/Helper.php, line 1310

Class

Helper
CleanTalk Helper class. Compatible with any CMS.

Namespace

Cleantalk\Common

Code

public static function http__request__rc_to_host($rc_action, $request_params, $patterns = array()) {
  $request_params__default = array(
    'spbc_remote_call_action' => $rc_action,
    'plugin_name' => 'apbct',
  );
  $result__rc_check_website = static::http__request(static::getSiteUrl(), array_merge($request_params__default, $request_params, array(
    'test' => 'test',
  )), array(
    'get',
  ));
  if (empty($result__rc_check_website['error'])) {
    if (is_string($result__rc_check_website) && preg_match('@^.*?OK$@', $result__rc_check_website)) {
      static::http__request(static::getSiteUrl(), array_merge($request_params__default, $request_params), array_merge(array(
        'get',
      ), $patterns));
    }
    else {
      return array(
        'error' => 'WRONG_SITE_RESPONSE ACTION: ' . $rc_action . ' RESPONSE: ' . htmlspecialchars(substr(!is_string($result__rc_check_website) ? print_r($result__rc_check_website, true) : $result__rc_check_website, 0, 400)),
      );
    }
  }
  else {
    return array(
      'error' => 'WRONG_SITE_RESPONSE TEST ACTION: ' . $rc_action . ' ERROR: ' . $result__rc_check_website['error'],
    );
  }
  return true;
}