<?php
require __DIR__ . '/includes/bootstrap.php';
header('Content-Type: application/xml; charset=utf-8');
header('Cache-Control: public, max-age=3600');
function sxl($value) { return htmlspecialchars((string) $value, ENT_XML1 | ENT_QUOTES, 'UTF-8'); }
$mtime = max((int) @filemtime(__FILE__), (int) @filemtime(__DIR__.'/config/locations.php'), (int) @filemtime(__DIR__.'/config/location-content.json'), (int) @filemtime(__DIR__.'/location.php'));
$lastmod = gmdate('Y-m-d', $mtime ?: time());
$locations = seo_hub_indexable_location_entries();
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
echo "  <url><loc>" . sxl(absolute_url('/locations')) . "</loc><lastmod>" . $lastmod . "</lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>\n";
foreach ($locations as $location) {
    $priority = $location['level'] === 'country' ? '0.7' : ($location['level'] === 'region' ? '0.65' : '0.6');
    echo "  <url><loc>" . sxl(seo_location_hub_url($location)) . "</loc><lastmod>" . $lastmod . "</lastmod><changefreq>monthly</changefreq><priority>" . $priority . "</priority></url>\n";
}
echo "</urlset>\n";
