BlueGit

projects-timfalken-com verhalenboek

Files

verhalenboek / web / feed.php

feed.php

feed.php 1.4 KiB Download Raw
1<?php
2declare(strict_types=1);
3// Atom-feed per lezer: feed.php?token=vbf_… . Geen sessie, geen leesmarkering.
4define('VERHALENBOEK_NO_SESSION', true);
5require __DIR__.'/lib/bootstrap.php';
6
7header('X-Robots-Tag: noindex, nofollow');
8header('Cache-Control: private, no-cache');
9header('Referrer-Policy: no-referrer');
10
11function 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
18try {
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}