<?php
require __DIR__ . '/lib/core.php';
header('Content-Type: application/xml; charset=UTF-8');
$site = mz_site();
$name = $site['site']['name'] ?? 'MORGENZEITUNG';

$posts = $site['posts'] ?? [];
$cut = time() - 48*3600;
$out = [];
foreach ($posts as $p) {
  $dt = strtotime(($p['published_at'] ?? '') ?: '');
  if ($dt && $dt >= $cut) $out[] = $p;
}

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 foreach ($out as $p): ?>
  <url>
    <loc><?php echo h("https://".$_SERVER['HTTP_HOST']."/post.php?slug=".urlencode($p['slug'])); ?></loc>
    <news:news>
      <news:publication>
        <news:name><?php echo h($name); ?></news:name>
        <news:language>de</news:language>
      </news:publication>
      <news:publication_date><?php echo h(($p['published_at'] ?? '')); ?></news:publication_date>
      <news:title><?php echo h(($p['title'] ?? '')); ?></news:title>
    </news:news>
  </url>
<?php endforeach; ?>
</urlset>
