<?php
/**
 * Dynamische sitemap. Verving de handgeschreven sitemap.xml (2026-07-14), waarvan
 * de lastmod-datums al ruim een maand stilstonden op een hardgecodeerde waarde en
 * die bij de URL-rename sowieso stuk zou zijn gegaan.
 *
 * Nu: URL's uit de centrale route-tabel (includes/routes.php), lastmod uit de
 * filemtime van de pagina zelf. Zelfde patroon als p2000amsterdam/sitemap.php.
 */
declare(strict_types=1);

require_once __DIR__ . '/includes/routes.php';

header('Content-Type: application/xml; charset=utf-8');

// changefreq/priority per pagina. De live-pagina's veranderen continu, de
// trust-pagina's zelden.
$META = [
    ''                => ['hourly',  '1.0'],
    'kaart'           => ['hourly',  '0.9'],
    'helikopters'     => ['hourly',  '0.8'],
    'statistieken'    => ['daily',   '0.8'],
    'over'            => ['monthly', '0.5'],
    'privacy'         => ['monthly', '0.4'],
    'privacy-cookies' => ['yearly',  '0.3'],
    'contact'         => ['yearly',  '0.3'],
];

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
foreach (portal_routes() as $url => $r) {
    $bestand = $r['dir'] === ''
        ? __DIR__ . '/index.php'
        : __DIR__ . '/' . $r['dir'] . '/index.php';
    $mtime = @filemtime($bestand) ?: time();
    [$freq, $prio] = $META[$r['dir']] ?? ['monthly', '0.5'];
    printf(
        "  <url>\n    <loc>https://www.p2000online.nl%s</loc>\n    <lastmod>%s</lastmod>\n    <changefreq>%s</changefreq>\n    <priority>%s</priority>\n  </url>\n",
        htmlspecialchars($url, ENT_XML1),
        date('Y-m-d', $mtime),
        $freq,
        $prio
    );
}
echo '</urlset>' . "\n";
