<?php
/**
 * Dynamic sitemap fallback - use if static sitemap.xml fails on host.
 * Serves valid XML with correct content-type.
 */
header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex'); // this endpoint itself; URLs inside are indexable

$base = 'https://www.yumaribprints.com';
$today = date('Y-m-d');

$priorityPages = [
    '/' => '1.0',
    '/products.html' => '0.9',
    '/about-yumaribprints.html' => '0.8',
    '/contact-us.html' => '0.8',
];

$skip = [
    '404.html', 'home.html', 'home.php', 'index.html', 'index.php',
    'paper-bag-printing-printing.html',
    'roll-up-banner-printing-printing.html',
    'tote-bag-printing-printing.html',
    'brochure-printing-printing.html',
    'custom-branded-wireless-mouse-print-printing.html',
    'custom-business-cards.html',
    'custom-mousepad-printing.html',
    'sticker-label-printing.html',
    'sticker-printing-printing.html',
    'table-calendar-printing.html',
    'vehicle-car-branding-printing.html',
    'soft-cover-jotter-printing.html',
];

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

foreach ($priorityPages as $path => $pri) {
    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($base . $path, ENT_XML1) . "</loc>\n";
    echo "    <lastmod>{$today}</lastmod>\n";
    echo "    <changefreq>weekly</changefreq>\n";
    echo "    <priority>{$pri}</priority>\n";
    echo "  </url>\n";
}

foreach (glob(__DIR__ . '/*.html') as $file) {
    $name = basename($file);
    if (in_array($name, $skip, true)) continue;
    if (isset($priorityPages['/' . $name])) continue;

    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($base . '/' . $name, ENT_XML1) . "</loc>\n";
    echo "    <lastmod>" . date('Y-m-d', filemtime($file)) . "</lastmod>\n";
    echo "    <changefreq>monthly</changefreq>\n";
    echo "    <priority>0.7</priority>\n";
    echo "  </url>\n";
}

echo '</urlset>';
