From dce7b451d05bd6ef792afedbbedf13fac2d33123 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Fri, 22 Nov 2024 11:06:24 +0000 Subject: [PATCH] change(indieblog): when building rss feed, include original article content too --- generate_indieblog_rss.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/generate_indieblog_rss.php b/generate_indieblog_rss.php index 3f7f2aa..b7e04f6 100644 --- a/generate_indieblog_rss.php +++ b/generate_indieblog_rss.php @@ -49,8 +49,12 @@ foreach ($recentItems as $item) { $rssItem = $channel->addChild('item'); $rssItem->addChild('title', htmlspecialchars($item['itemtitle'] ?? 'No title')); $rssItem->addChild('link', htmlspecialchars($item['itemurl'] ?? '')); - $rssItem->addChild('description', htmlspecialchars($item['feedtitle'] ?? '')); $rssItem->addChild('pubDate', date(DATE_RSS, $item['published'])); + + // Fetch original RSS feed content for the entry + $originalContent = fetchOriginalContent($item['itemurl']); + $rssItem->addChild('description', htmlspecialchars($originalContent ?? $item['feedtitle'] ?? 'No content')); + $newEntries[] = $item['itemid']; } @@ -61,3 +65,25 @@ if (!empty($newEntries)) { // Save RSS feed $rss->asXML($rssFile); + +/** + * Fetches the original content from a given URL. + * + * @param string $url The URL of the article to fetch. + * @return string|null The extracted content, or null if unavailable. + */ +function fetchOriginalContent(string $url): ?string +{ + $html = @file_get_contents($url); + if (!$html) { + return null; + } + + // Extract content between tags (basic extraction, adapt as needed) + if (preg_match('/(.*?)<\/body>/si', $html, $matches)) { + // Clean HTML content (strip tags, keep minimal formatting) + return strip_tags($matches[1], '


'); + } + + return null; +}