From 476c1bf413225a80e34f7269cc9e09342cb91411 Mon Sep 17 00:00:00 2001 From: para <157126561+mdegallaix@users.noreply.github.com> Date: Sat, 26 Sep 2026 00:23:02 +0200 Subject: [PATCH] Fix W3C validator errors in the Facebook feed proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FetchRSS's raw feed fails validation: entry is a bare Facebook post ID rather than a full URI, and points at the FetchRSS URL instead of where we actually serve it. Parse the fetched XML with DOMDocument and fix both before caching/serving: reuse each entry's own alternate link (already a full post URL) as its id, and rewrite the self link to our own facebook.php URL. Requires the php-xml extension (ext-dom) — near-universal on shared hosting, but worth checking if this breaks on deploy. Co-Authored-By: Claude Sonnet 5 --- php/facebook.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/php/facebook.php b/php/facebook.php index f594560..42b9b70 100644 --- a/php/facebook.php +++ b/php/facebook.php @@ -10,10 +10,46 @@ require __DIR__ . '/common.php'; * notre propre domaine pour avoir une URL stable a partager. */ const FETCHRSS_URL = 'https://fetchrss.com/feed/1xABzW0ZB9CM1xAByX0rYAhW.atom'; +const SELF_URL = 'https://sillycone-village.be/silly-rss/facebook.php'; +/** + * Le flux FetchRSS brut ne passe pas le validateur W3C : + * - de chaque est l'identifiant numerique brut du post + * Facebook, alors que la spec Atom exige une URI complete. On reutilise + * le de l'entree (deja une URL complete vers le + * post) a la place. + * - Le pointe vers l'URL FetchRSS d'origine au lieu de + * celle ou ce flux est reellement servi. + */ function fetch_facebook_feed(): string { - return http_get(FETCHRSS_URL, ['Accept: application/atom+xml, application/xml']); + $raw = http_get(FETCHRSS_URL, ['Accept: application/atom+xml, application/xml']); + + $doc = new DOMDocument(); + if (!$doc->loadXML($raw)) { + return $raw; // XML illisible : on sert quand meme le brut plutot que de casser le flux + } + + $atomNs = 'http://www.w3.org/2005/Atom'; + $xpath = new DOMXPath($doc); + $xpath->registerNamespace('a', $atomNs); + + foreach ($xpath->query('/a:feed/a:link[@rel="self"]') as $selfLink) { + $selfLink->setAttribute('href', SELF_URL); + } + + foreach ($xpath->query('/a:feed/a:entry') as $entry) { + $idNode = $xpath->query('a:id', $entry)->item(0); + $linkNode = $xpath->query('a:link[@rel="alternate"]', $entry)->item(0); + if ($idNode && $linkNode) { + $href = $linkNode->getAttribute('href'); + if ($href && !preg_match('#^https?://#', $idNode->textContent)) { + $idNode->textContent = $href; + } + } + } + + return $doc->saveXML(); } // text/xml plutot que application/atom+xml : voir la note dans common.php