<?php
header('Content-Type: application/xml; charset=utf-8');
date_default_timezone_set('Asia/Shanghai');
function sm_host() {
    $host = $_SERVER['HTTP_HOST'] ?? '';
    return preg_replace('/[^A-Za-z0-9\.\-:]/', '', $host);
}
function sm_scheme() {
    if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') { return 'https'; }
    $forwarded = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
    return $forwarded === 'https' ? 'https' : 'http';
}
$base = sm_scheme() . '://' . sm_host();
$urls = [
    ['loc'=>'/', 'priority'=>'1.0', 'changefreq'=>'daily'],
    ['loc'=>'/topics/', 'priority'=>'0.9', 'changefreq'=>'daily'],
    ['loc'=>'/archive/', 'priority'=>'0.9', 'changefreq'=>'daily'],
    ['loc'=>'/authors/', 'priority'=>'0.7', 'changefreq'=>'weekly'],
    ['loc'=>'/about/', 'priority'=>'0.7', 'changefreq'=>'weekly'],
    ['loc'=>'/contact/', 'priority'=>'0.6', 'changefreq'=>'weekly'],
    ['loc'=>'/article/video-guide/', 'priority'=>'0.8', 'changefreq'=>'weekly'],
    ['loc'=>'/article/topic-map/', 'priority'=>'0.8', 'changefreq'=>'weekly'],
    ['loc'=>'/article/safe-reading/', 'priority'=>'0.8', 'changefreq'=>'weekly'],
    ['loc'=>'/article/update-brief/', 'priority'=>'0.8', 'changefreq'=>'daily']
];
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($urls as $item): ?>
    <url>
        <loc><?= htmlspecialchars($base . $item['loc'], ENT_XML1, 'UTF-8'); ?></loc>
        <lastmod><?= date('Y-m-d'); ?></lastmod>
        <changefreq><?= htmlspecialchars($item['changefreq'], ENT_XML1, 'UTF-8'); ?></changefreq>
        <priority><?= htmlspecialchars($item['priority'], ENT_XML1, 'UTF-8'); ?></priority>
    </url>
<?php endforeach; ?>
</urlset>
