<?php
header('Content-Type: application/xml; charset=utf-8');
date_default_timezone_set('Asia/Bangkok');
$currentHost = $_SERVER['HTTP_HOST'] ?? '';
$currentHost = preg_replace('/[^A-Za-z0-9.\-:]/', '', $currentHost);
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$baseUrl = $currentHost ? $scheme . '://' . $currentHost : '';
$today = date('Y-m-d');
$paths = ['/', '/topics/', '/boards/', '/discover/', '/ranking/', '/profile/', '/about/', '/help/', '/rules/', '/activity/'];
echo '<?xml version="1.0" encoding="UTF-8"?>' . "
";
?>
<urlset xmlns="<?php echo 'http://' . 'www.sitemaps' . '.org/schemas/sitemap/0.9'; ?>">
<?php foreach ($paths as $path): ?>
  <url>
    <loc><?php echo htmlspecialchars($baseUrl . $path, ENT_XML1, 'UTF-8'); ?></loc>
    <lastmod><?php echo $today; ?></lastmod>
    <changefreq><?php echo $path === '/' ? 'daily' : 'weekly'; ?></changefreq>
    <priority><?php echo $path === '/' ? '1.0' : '0.8'; ?></priority>
  </url>
<?php endforeach; ?>
</urlset>
