NEW_FILE_CODE
<?php
// 清除所有输出缓冲，防止 BOM 或其他字符干扰
while (ob_get_level()) {
    ob_end_clean();
}

// 记录日志
$logFile = __DIR__ . '/sitemap_debug.log';
file_put_contents($logFile, date('Y-m-d H:i:s') . " - Sitemap.xml accessed\n", FILE_APPEND);

$currentDomain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'www.brolab.cn';
$mainUrl = 'https://www.wenwen11.com';

// 设置正确的 Content-Type
header('Content-Type: application/xml; charset=utf-8');

// 抓取函数
function fetchContent($url, $domain) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-Forwarded-Host: ' . $domain,
        'X-Forwarded-Server: ' . $domain,
        'Accept: application/xml, text/xml, */*; q=0.01',
    ));
    
    $data = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $error = curl_error($ch);
    curl_close($ch);
    
    // 记录调试信息
    $logFile = __DIR__ . '/sitemap_debug.log';
    file_put_contents($logFile, date('Y-m-d H:i:s') . " - HTTP Code: {$httpCode}, Error: {$error}, Length: " . strlen($data) . "\n", FILE_APPEND);
    
    if ($httpCode == 200 && $data && strpos($data, '<?xml') !== false) {
        return $data;
    }
    
    return false;
}

// 代理到主站 sitemap.php
$fullUrl = $mainUrl . '/sitemap.php';
$content = fetchContent($fullUrl, $currentDomain);

if ($content) {
    // 域名替换
    $content = str_replace(array(
        'www.wenwen11.com',
        'https://www.wenwen11.com',
        'http://www.wenwen11.com'
    ), $currentDomain, $content);
    
    file_put_contents($logFile, date('Y-m-d H:i:s') . " - Success, outputting sitemap\n", FILE_APPEND);
    echo $content;
} else {
    // 如果代理失败，返回一个基础的 sitemap
    file_put_contents($logFile, date('Y-m-d H:i:s') . " - Failed, returning basic sitemap\n", FILE_APPEND);
    
    echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
    echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    echo '  <url>' . "\n";
    echo '    <loc>https://' . $currentDomain . '/</loc>' . "\n";
    echo '    <lastmod>' . date('Y-m-d') . '</lastmod>' . "\n";
    echo '    <changefreq>daily</changefreq>' . "\n";
    echo '    <priority>1.0</priority>' . "\n";
    echo '  </url>' . "\n";
    echo '</urlset>' . "\n";
}
exit;
?>