<?php
// sitemap.xml — Auto-updating XML sitemap for Main Event Weddings with SEO-friendly URLs
header('Content-Type: application/xml; charset=UTF-8');
$base = 'https://www.maineventweddings.com';
$pages = [
    ['/', 'monthly', '1.0', 'index.php'],
    ['/wedding-dj-services-ri-ma.php', 'monthly', '0.9', 'wedding-dj-services-ri-ma.php'],
    ['/wedding-photography-ri-ma.php', 'monthly', '0.9', 'wedding-photography-ri-ma.php'],
    ['/wedding-videography-ri-ma.php', 'monthly', '0.9', 'wedding-videography-ri-ma.php'],
    ['/photo-booth-rental-ri-ma.php', 'monthly', '0.8', 'photo-booth-rental-ri-ma.php'],
    ['/wedding-uplighting-ri-ma.php', 'monthly', '0.8', 'wedding-uplighting-ri-ma.php'],
    ['/wedding-packages-pricing-ri-ma.php', 'monthly', '0.8', 'wedding-packages-pricing-ri-ma.php'],
    ['/wedding-dj-photography-videography-ri-ma.php', 'monthly', '0.8', 'wedding-dj-photography-videography-ri-ma.php'],
    ['/contact-main-event-weddings.php', 'monthly', '0.6', 'contact-main-event-weddings.php'],
    // Comment out directions if not live to avoid 404
    // ['/directions-to-main-event-weddings.php', 'yearly', '0.4', 'directions-to-main-event-weddings.php'],
    ['/sitemap.php', 'yearly', '0.3', 'sitemap.php'],
    ['/sitemap.xml', 'yearly', '0.3', 'sitemap.xml'],
];

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:geo="http://www.google.com/geo/schemas/sitemap-geo/1.0">
<?php foreach ($pages as [$loc, $freq, $prio, $file]): ?>
<url>
    <loc><?= htmlspecialchars($base . $loc) ?></loc>
    <?php $path = $_SERVER['DOCUMENT_ROOT'] . '/' . $file; ?>
    <?php if (is_file($path)): ?>
        <lastmod><?= date('c', filemtime($path)) ?></lastmod>
    <?php else: ?>
        <!-- Log missing file and use current date as fallback -->
        <?php error_log("Sitemap: File not found at $path"); ?>
        <lastmod><?= date('c') ?></lastmod>
    <?php endif; ?>
    <changefreq><?= htmlspecialchars($freq) ?></changefreq>
    <priority><?= htmlspecialchars($prio) ?></priority>
    <!-- Geo extension (optional, for Google) -->
    <geo:lat>41.9220</geo:lat>
    <geo:long>-71.5495</geo:long>
</url>
<?php endforeach; ?>
</urlset>
