['timeout' => 6]]); $raw = @file_get_contents(NEWS_INDEX_URL, false, $ctx); if ($raw !== false && json_decode($raw, true) !== null) { @mkdir(dirname(CACHE_FILE), 0775, true); @file_put_contents(CACHE_FILE, $raw, LOCK_EX); return $raw; } return is_file(CACHE_FILE) ? (string)file_get_contents(CACHE_FILE) : null; } $raw = fetch_index(); $data = $raw === null ? null : json_decode($raw, true); if (!is_array($data) || !isset($data['items'])) { readfile(__DIR__ . '/sitemap.xml'); exit; } $today = gmdate('Y-m-d'); $static = [ ['/', '1.0', 'weekly'], ['/cyberbezpieczenstwo', '0.9', 'monthly'], ['/med', '0.9', 'monthly'], ['/cennik', '0.9', 'monthly'], ['/kontakt', '0.8', 'monthly'], ['/news', '0.8', 'daily'], ['/polityka', '0.3', 'yearly'], ]; $x = static fn(string $s): string => htmlspecialchars($s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); echo '', "\n"; echo '', "\n"; foreach ($static as [$path, $prio, $freq]) { echo '', $x(SITE_ORIGIN . $path), '', $today, '', $freq, '', $prio, '', "\n"; } foreach ($data['items'] as $item) { $slug = (string)($item['slug'] ?? ''); if ($slug === '') continue; $date = substr((string)($item['publishedAt'] ?? $today), 0, 10); echo '', $x(SITE_ORIGIN . '/news/' . rawurlencode($slug)), '', $x($date), 'monthly', '0.6', "\n"; } echo '', "\n";