<?php
require __DIR__.'/includes/bootstrap.php';
header('Content-Type: application/xml; charset=utf-8');
$base=(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=='off'?'https':'http').'://'.($_SERVER['HTTP_HOST']??'localhost');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach(['index.php','lich-phung-vu.php','tin-tuc.php','bai-doc.php','thu-vien.php'] as $p) echo '<url><loc>'.e($base.'/'.$p).'</loc></url>';
foreach($pdo->query("SELECT slug,updated_at FROM posts WHERE published=1 ORDER BY updated_at DESC")->fetchAll() as $p)
 echo '<url><loc>'.e($base.'/tin-tuc.php?slug='.rawurlencode($p['slug'])).'</loc><lastmod>'.date('c',strtotime($p['updated_at'])).'</lastmod></url>';
echo '</urlset>';
