<?php

header("Content-Type: application/xml; charset=utf-8");

require_once __DIR__ . '/config.php';

echo '<?xml version="1.0" encoding="UTF-8"?>';

?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<?php

$sql = "
SELECT slug, updated_at
FROM domains
WHERE status = 1
ORDER BY id DESC
";

$result = $conn->query($sql);

while ($row = $result->fetch_assoc()) {

    $slug = trim($row['slug']);

    $lastmod = !empty($row['updated_at'])
        ? date('Y-m-d', strtotime($row['updated_at']))
        : date('Y-m-d');

    $url = "https://www.domaindd.com/domain/" 
         . urlencode($slug) . "/";

?>

<url>

<loc><?= htmlspecialchars($url) ?></loc>

<lastmod><?= $lastmod ?></lastmod>

<changefreq>weekly</changefreq>

<priority>0.90</priority>

</url>

<?php } ?>

</urlset>