/sitemap.xml // ============================================================ require_once __DIR__ . '/includes/config.php'; $type = $_GET['type'] ?? 'index'; $page = max(0, (int)($_GET['page'] ?? 0)); $per = 10000; // Google's max per sitemap header('Content-Type: application/xml; charset=utf-8'); header('X-Robots-Tag: noindex'); if ($type === 'index') { // Sitemap index $total = (int)db()->query("SELECT COUNT(*) FROM solutions")->fetchColumn(); $pages = (int)ceil($total / $per); echo '' . "\n"; echo '' . "\n"; echo "" . SITE_URL . "/sitemap.xml?type=static" . date('Y-m-d') . "\n"; for ($i = 0; $i < $pages; $i++) { echo "" . SITE_URL . "/sitemap.xml?type=solutions&page={$i}" . date('Y-m-d') . "\n"; } echo ''; exit; } if ($type === 'static') { echo '' . "\n"; echo '' . "\n"; $static = [['/', '1.0', 'daily'], ['/categories.php', '0.9', 'daily'], ['/search.php', '0.7', 'weekly']]; foreach ($static as [$path, $pri, $freq]) { echo "" . SITE_URL . $path . "{$freq}{$pri}\n"; } foreach (db()->query("SELECT slug, updated_at FROM categories") as $cat) { echo "" . SITE_URL . "/category.php?slug=" . urlencode($cat['slug']) . "hourly0.8" . substr($cat['updated_at'] ?? date('Y-m-d'), 0, 10) . "\n"; } echo ''; exit; } if ($type === 'solutions') { $offset = $page * $per; $rows = db()->prepare("SELECT slug, updated_at FROM solutions ORDER BY id LIMIT {$per} OFFSET {$offset}"); $rows->execute(); echo '' . "\n"; echo '' . "\n"; foreach ($rows as $row) { echo "" . SITE_URL . "/solution.php?slug=" . urlencode($row['slug']) . "" . substr($row['updated_at'], 0, 10) . "monthly0.6\n"; } echo ''; exit; }