<?php
/**
 * SocialBulk Shop - Dynamic Blog 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();
    $posts = $pdo->query("SELECT slug, updated_at FROM blog_posts WHERE status='published' ORDER BY published_at DESC")->fetchAll();
} catch (Exception $e) { $posts = []; }
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($posts as $p): ?>
  <url>
    <loc><?= htmlspecialchars(SITE_URL . '/blog/' . $p['slug']) ?></loc>
    <lastmod><?= date('Y-m-d', strtotime($p['updated_at'])) ?></lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
<?php endforeach; ?>
</urlset>
