<?php
header("Content-Type: application/xml; charset=utf-8");
require_once('includes/config.php');

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

// لینک صفحه اصلی
echo '<url><loc>https://novinyadaknajafi.ir/</loc><changefreq>daily</changefreq><priority>1.0</priority></url>';

// دریافت محصولات از دیتابیس
$sql = "SELECT slug FROM products WHERE status = 'active'";
$stmt = $pdo->prepare($sql);
$stmt->execute();

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $url = 'https://novinyadaknajafi.ir/product/' . urlencode($row['slug']);
    echo '<url><loc>' . htmlspecialchars($url) . '</loc><changefreq>weekly</changefreq><priority>0.8</priority></url>';
}

echo '</urlset>';
?>
