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

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

// Главная страница
echo '<url>';
echo '<loc>https://premier-show.ru/</loc>';
echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>1.0</priority>';
echo '</url>';

// Категории
$categories = $pdo->query("SELECT * FROM categories");
while ($cat = $categories->fetch()) {
    echo '<url>';
    echo '<loc>https://premier-show.ru/catalog/category.php?slug=' . urlencode($cat['slug']) . '</loc>';
    echo '<lastmod>' . date('Y-m-d') . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.8</priority>';
    echo '</url>';
}

// Товары
$products = $pdo->query("SELECT * FROM products");
while ($product = $products->fetch()) {
    echo '<url>';
    echo '<loc>https://premier-show.ru/catalog/product.php?slug=' . urlencode($product['slug']) . '</loc>';
    echo '<lastmod>' . date('Y-m-d', strtotime($product['created_at'])) . '</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.7</priority>';
    echo '</url>';
}

// Новости
$news = $pdo->query("SELECT * FROM news");
while ($item = $news->fetch()) {
    echo '<url>';
    echo '<loc>https://premier-show.ru/pages/news.php?id=' . $item['id'] . '</loc>';
    echo '<lastmod>' . date('Y-m-d', strtotime($item['publish_date'])) . '</lastmod>';
    echo '<changefreq>monthly</changefreq>';
    echo '<priority>0.6</priority>';
    echo '</url>';
}

echo '</urlset>';