private function Cleantalk::httpRequest in Anti Spam by CleanTalk 8.3
httpRequest
Parameters
$msg:
Return value
boolean|\CleantalkResponse
3 calls to Cleantalk::httpRequest()
- Cleantalk::isAllowMessage in src/
lib/ Cleantalk/ Antispam/ Cleantalk.php - Function checks whether it is possible to publish the message
- Cleantalk::isAllowUser in src/
lib/ Cleantalk/ Antispam/ Cleantalk.php - Function checks whether it is possible to publish the message
- Cleantalk::sendFeedback in src/
lib/ Cleantalk/ Antispam/ Cleantalk.php - Function sends the results of manual moderation
File
- src/
lib/ Cleantalk/ Antispam/ Cleantalk.php, line 386
Class
- Cleantalk
- Cleantalk class create request
Namespace
Drupal\cleantalk\lib\Cleantalk\AntispamCode
private function httpRequest($msg) {
$result = false;
if ($msg->method_name != 'send_feedback') {
$ct_tmp = apache_request_headers();
if (isset($ct_tmp['Cookie'])) {
$cookie_name = 'Cookie';
}
elseif (isset($ct_tmp['cookie'])) {
$cookie_name = 'cookie';
}
else {
$cookie_name = 'COOKIE';
}
if (isset($tmp[$cookie_name])) {
$ct_tmp[$cookie_name] = preg_replace(array(
'/\\s{0,1}ct_checkjs=[a-z0-9]*[;|$]{0,1}/',
'/\\s{0,1}ct_timezone=.{0,1}\\d{1,2}[;|$]/',
'/\\s{0,1}ct_pointer_data=.*5D[;|$]{0,1}/',
'/;{0,1}\\s{0,3}$/',
), '', $ct_tmp[$cookie_name]);
}
$msg->all_headers = json_encode($ct_tmp);
}
//$msg->remote_addr=$_SERVER['REMOTE_ADDR'];
//$msg->sender_info['remote_addr']=$_SERVER['REMOTE_ADDR'];
$si = (array) json_decode($msg->sender_info, true);
$si['remote_addr'] = $_SERVER['REMOTE_ADDR'];
$msg->x_forwarded_for = @$_SERVER['X_FORWARDED_FOR'];
$msg->x_real_ip = @$_SERVER['X_REAL_IP'];
$msg->sender_info = json_encode($si);
if (isset($this->work_url) && $this->work_url !== '' && $this->server_changed + $this->server_ttl > time() || $this->stay_on_server == true) {
$url = !empty($this->work_url) ? $this->work_url : $this->server_url;
$result = $this
->sendRequest($msg, $url, $this->server_timeout);
}
if (($result === false || $result->errno != 0) && $this->stay_on_server == false) {
// Split server url to parts
preg_match("@^(https?://)([^/:]+)(.*)@i", $this->server_url, $matches);
$url_prefix = '';
if (isset($matches[1])) {
$url_prefix = $matches[1];
}
$pool = null;
if (isset($matches[2])) {
$pool = $matches[2];
}
$url_suffix = '';
if (isset($matches[3])) {
$url_suffix = $matches[3];
}
if ($url_prefix === '') {
$url_prefix = 'http://';
}
if (empty($pool)) {
return false;
}
else {
// Loop until find work server
foreach ($this
->get_servers_ip($pool) as $server) {
if ($server['host'] === 'localhost' || $server['ip'] === null) {
$work_url = $server['host'];
}
else {
$server_host = $server['ip'];
$work_url = $server_host;
}
$host = filter_var($work_url, FILTER_VALIDATE_IP) ? gethostbyaddr($work_url) : $work_url;
$work_url = $url_prefix . $host;
if (isset($url_suffix)) {
$work_url = $work_url . $url_suffix;
}
$this->work_url = $work_url;
$this->server_ttl = $server['ttl'];
$result = $this
->sendRequest($msg, $this->work_url, $this->server_timeout);
if ($result !== false && $result->errno === 0) {
$this->server_change = true;
break;
}
}
}
}
$response = new CleantalkResponse(null, $result);
if (!empty($this->data_codepage) && $this->data_codepage !== 'UTF-8') {
if (!empty($response->comment)) {
$response->comment = $this
->stringFromUTF8($response->comment, $this->data_codepage);
}
if (!empty($response->errstr)) {
$response->errstr = $this
->stringFromUTF8($response->errstr, $this->data_codepage);
}
if (!empty($response->sms_error_text)) {
$response->sms_error_text = $this
->stringFromUTF8($response->sms_error_text, $this->data_codepage);
}
}
return $response;
}