<?php
require __DIR__ . '/app/bootstrap.php';

header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">

<?php
$stmt = $pdo->query("
    SELECT id, slug, title, publish_date 
    FROM articles 
    WHERE status='published' 
    AND publish_date >= NOW() - INTERVAL 2 DAY
    ORDER BY publish_date DESC
");

while ($row = $stmt->fetch()) {
    $url = BASE_URL . "article/" . $row['id'] . "/" . rawurlencode($row['slug']);
    $date = date('c', strtotime($row['publish_date']));
?>
    <url>
        <loc><?= htmlspecialchars($url) ?></loc>
        <news:news>
            <news:publication>
                <news:name>mzamin</news:name>
                <news:language>bn</news:language>
            </news:publication>
            <news:publication_date><?= $date ?></news:publication_date>
            <news:title><?= htmlspecialchars($row['title']) ?></news:title>
        </news:news>
    </url>
<?php } ?>

</urlset>