<?php
/**
 * Dynamic Sitemap Generator
 * This file generates a sitemap.xml dynamically based on the current content
 */

require_once '../config.php';
require_once '../src/seo_manager.php';

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

// Initialize SEO manager
$seoManager = new SEOManager($pdo);

// Get sitemap URLs
$urls = $seoManager->generateSitemap();

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

foreach ($urls as $url) {
    echo '  <url>' . "\n";
    echo '    <loc>' . htmlspecialchars($url['url']) . '</loc>' . "\n";
    echo '    <priority>' . $url['priority'] . '</priority>' . "\n";
    echo '    <changefreq>' . $url['changefreq'] . '</changefreq>' . "\n";
    if (isset($url['lastmod'])) {
        echo '    <lastmod>' . $url['lastmod'] . '</lastmod>' . "\n";
    }
    echo '  </url>' . "\n";
}

echo '</urlset>' . "\n";
?>
