| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | // Atom-feed per lezer: feed.php?token=vbf_… . Geen sessie, geen leesmarkering. |
| 4 | define('VERHALENBOEK_NO_SESSION', true); |
| 5 | require __DIR__.'/lib/bootstrap.php'; |
| 6 | |
| 7 | header('X-Robots-Tag: noindex, nofollow'); |
| 8 | header('Cache-Control: private, no-cache'); |
| 9 | header('Referrer-Policy: no-referrer'); |
| 10 | |
| 11 | function feedNotFound(): never { |
| 12 | http_response_code(404); |
| 13 | header('Content-Type: text/plain; charset=utf-8'); |
| 14 | echo "Deze feed bestaat niet of staat uit.\n"; |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | try { |
| 19 | $method = $_SERVER['REQUEST_METHOD'] ?? 'GET'; |
| 20 | if ($method !== 'GET' && $method !== 'HEAD') { |
| 21 | http_response_code(405); |
| 22 | header('Allow: GET, HEAD'); |
| 23 | exit; |
| 24 | } |
| 25 | if (!feedEnabled()) feedNotFound(); |
| 26 | $token = $_GET['token'] ?? null; |
| 27 | $userId = feedUserForToken($token); |
| 28 | if ($userId === null) feedNotFound(); |
| 29 | $xml = feedXml(feedUrl((string)$token), feedDays()); |
| 30 | $etag = '"'.substr(hash('sha256', $xml), 0, 32).'"'; |
| 31 | header('ETag: '.$etag); |
| 32 | if (($_SERVER['HTTP_IF_NONE_MATCH'] ?? '') === $etag) { |
| 33 | http_response_code(304); |
| 34 | exit; |
| 35 | } |
| 36 | header('Content-Type: application/atom+xml; charset=utf-8'); |
| 37 | if ($method === 'HEAD') exit; |
| 38 | echo $xml; |
| 39 | } catch (Throwable $e) { |
| 40 | error_log('feed: '.$e->getMessage()); |
| 41 | http_response_code(500); |
| 42 | header('Content-Type: text/plain; charset=utf-8'); |
| 43 | echo "De feed kon niet worden gemaakt.\n"; |
| 44 | } |
projects-timfalken-com verhalenboek