<?php
// BOM'suz dosya, ilk satırda kesinlikle boşluk yok!
// Content-Type header
header('Content-Type: application/xml; charset=UTF-8');

// Output buffer temizle (önceden bir echo çıktıysa siler)
if (ob_get_length()) ob_clean();

// DB bağlantısını ekle
require_once __DIR__ . '/../app/config.php';

// XML başlığı
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc><?= BASE_URL ?>/countuser/</loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    <?php
    // Sunucu listesi
    $stmt = $db->query("SELECT id, slug, updated_at FROM servers WHERE is_verified = 1 ORDER BY updated_at DESC");
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
        <url>
            <loc><?= BASE_URL ?>/server/<?= $row['id'] ?>/<?= htmlspecialchars($row['slug'] ?? '') ?></loc>
            <lastmod><?= date('Y-m-d', strtotime($row['updated_at'])) ?></lastmod>
            <changefreq>weekly</changefreq>
            <priority>0.8</priority>
        </url>
    <?php endwhile; ?>
</urlset>
<?php
exit;