<?php
declare(strict_types=1);
header('Content-Type: application/xml; charset=utf-8');
$https = $_SERVER['HTTPS'] ?? '';
$forwarded = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
$scheme = (($https !== '' && strtolower((string)$https) !== 'off') || strtolower((string)$forwarded) === 'https') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? ($_SERVER['SERVER_NAME'] ?? '');
$host = preg_replace('/[^A-Za-z0-9.\-:]/', '', (string)$host);
$base = $host !== '' ? $scheme . '://' . $host : '';
$urls = [
  '/', '/brand-movie/', '/video-community/', '/ai-lab/', '/entertainment-culture/', '/creator-center/', '/contact-brand/',
  '/featured-video/', '/sweet-community/', '/ai-toolbox/', '/emotion-space/'
];
function x(string $value): string { return htmlspecialchars($value, ENT_XML1 | ENT_QUOTES, 'UTF-8'); }
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($urls as $url): ?>
  <url>
    <loc><?php echo x($base !== '' ? rtrim($base, '/') . $url : $url); ?></loc>
    <lastmod><?php echo date('Y-m-d'); ?></lastmod>
    <changefreq><?php echo $url === '/' ? 'daily' : 'weekly'; ?></changefreq>
    <priority><?php echo $url === '/' ? '1.0' : '0.8'; ?></priority>
  </url>
<?php endforeach; ?>
</urlset>
