<?php
/**
 * SocialBulk Shop - Dynamic Accounts Sitemap
 */
require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/db.php';

header('Content-Type: application/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';

try {
    $pdo   = db();
    $accs  = $pdo->query("SELECT slug, updated_at FROM accounts WHERE status='active' ORDER BY updated_at DESC")->fetchAll();
} catch (Exception $e) { $accs = []; }
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($accs as $a): ?>
  <url>
    <loc><?= htmlspecialchars(SITE_URL . '/account/' . $a['slug']) ?></loc>
    <lastmod><?= date('Y-m-d', strtotime($a['updated_at'])) ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
<?php endforeach; ?>
</urlset>
