<?php
header('Content-Type: application/xml; charset=utf-8');
require_once __DIR__.'/config/db.php';
$base = 'https://digitvault.shop';
$date = date('Y-m-d');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc><?= $base ?>/</loc><lastmod><?= $date ?></lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>
  <url><loc><?= $base ?>/categories</loc><lastmod><?= $date ?></lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url>
  <url><loc><?= $base ?>/about</loc><lastmod><?= $date ?></lastmod><changefreq>monthly</changefreq><priority>0.7</priority></url>
  <url><loc><?= $base ?>/contact</loc><lastmod><?= $date ?></lastmod><changefreq>monthly</changefreq><priority>0.6</priority></url>
  <url><loc><?= $base ?>/terms</loc><lastmod><?= $date ?></lastmod><changefreq>yearly</changefreq><priority>0.3</priority></url>
  <url><loc><?= $base ?>/privacy</loc><lastmod><?= $date ?></lastmod><changefreq>yearly</changefreq><priority>0.3</priority></url>
<?php
try {
  foreach(rows("SELECT slug,updated_at FROM categories WHERE is_active=1") as $c):
    echo "  <url><loc>{$base}/category/{$c['slug']}</loc><lastmod>".date('Y-m-d',strtotime($c['updated_at']??'now'))."</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url>\n";
  endforeach;
  foreach(rows("SELECT slug,updated_at FROM websites WHERE is_active=1") as $w):
    echo "  <url><loc>{$base}/website/{$w['slug']}</loc><lastmod>".date('Y-m-d',strtotime($w['updated_at']??'now'))."</lastmod><changefreq>weekly</changefreq><priority>0.9</priority></url>\n";
  endforeach;
} catch(Exception $e) {}
?>
</urlset>
