<?php
require_once __DIR__ . '/includes/config.php';

header('Content-Type: application/xml; charset=UTF-8');
$products   = getProducts();
$categories = getAllCategories();
$brands     = getAllBrands();
$now        = date('c');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url><loc><?= SITE_URL ?>/</loc><lastmod><?= $now ?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>
    <url><loc><?= SITE_URL ?>/about.php</loc><lastmod><?= $now ?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url>
    <url><loc><?= SITE_URL ?>/contact.php</loc><lastmod><?= $now ?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url>
    <url><loc><?= SITE_URL ?>/shipping.php</loc><lastmod><?= $now ?></lastmod><changefreq>monthly</changefreq><priority>0.5</priority></url>
    <?php foreach ($categories as $cat): ?>
    <url><loc><?= SITE_URL ?>/catalog.php?category=<?= urlencode($cat['slug']) ?></loc><lastmod><?= $now ?></lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>
    <?php endforeach; ?>
    <?php foreach ($brands as $brand): ?>
    <url><loc><?= SITE_URL ?>/catalog.php?brand=<?= urlencode($brand['slug']) ?></loc><lastmod><?= $now ?></lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>
    <?php endforeach; ?>
    <?php foreach ($products as $product): ?>
    <url><loc><?= SITE_URL ?>/product.php?slug=<?= urlencode($product['slug']) ?></loc><lastmod><?= $now ?></lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url>
    <?php endforeach; ?>
</urlset>
