<?php
require_once __DIR__ . '/includes/db.php';
header('Content-Type: application/xml; charset=utf-8');
$siteUrl = getSiteSetting('site_url', '');
$servers = $pdo->query("SELECT id, updated_at FROM servers WHERE status='approved' ORDER BY updated_at DESC")->fetchAll();
$users   = $pdo->query("SELECT username, updated_at FROM users WHERE is_banned=0 ORDER BY created_at DESC LIMIT 500")->fetchAll();
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc><?= $siteUrl ?>/</loc><changefreq>hourly</changefreq><priority>1.0</priority></url>
  <url><loc><?= $siteUrl ?>/top.php</loc><changefreq>hourly</changefreq><priority>0.9</priority></url>
  <url><loc><?= $siteUrl ?>/categories.php</loc><changefreq>daily</changefreq><priority>0.8</priority></url>
  <url><loc><?= $siteUrl ?>/countries.php</loc><changefreq>daily</changefreq><priority>0.8</priority></url>
  <url><loc><?= $siteUrl ?>/premium.php</loc><changefreq>daily</changefreq><priority>0.7</priority></url>
  <url><loc><?= $siteUrl ?>/add-server.php</loc><changefreq>monthly</changefreq><priority>0.6</priority></url>
  <url><loc><?= $siteUrl ?>/votifier-test.php</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>
  <url><loc><?= $siteUrl ?>/tos.php</loc><changefreq>yearly</changefreq><priority>0.3</priority></url>
  <url><loc><?= $siteUrl ?>/privacy.php</loc><changefreq>yearly</changefreq><priority>0.3</priority></url>
  <url><loc><?= $siteUrl ?>/contact.php</loc><changefreq>monthly</changefreq><priority>0.4</priority></url>
<?php foreach ($servers as $s): ?>
  <url>
    <loc><?= $siteUrl ?>/server.php?id=<?= (int)$s['id'] ?></loc>
    <lastmod><?= date('Y-m-d', strtotime($s['updated_at'])) ?></lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>
<?php endforeach; ?>
<?php foreach ($users as $u): ?>
  <url>
    <loc><?= $siteUrl ?>/profile.php?u=<?= urlencode($u['username']) ?></loc>
    <lastmod><?= date('Y-m-d', strtotime($u['updated_at'] ?? date('Y-m-d'))) ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.5</priority>
  </url>
<?php endforeach; ?>
</urlset>
