Skip to content

Commit

Permalink
use news link in RSS post when it is internal link (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krylan authored Sep 30, 2024
1 parent e2a5763 commit 774a266
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions public/rss-news.xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
$newsDate = date("D, d M Y H:i:s O", strtotime($news['Timestamp']));
$newsImage = $news['Image'];
$newsLink = config('app.url');
$newsTitle = "<![CDATA[" . htmlspecialchars(strip_tags($news['Title'])) . "]]>";
if (str_starts_with($news['Link'], config('app.url'))) {
$newsLink = "<![CDATA[" . $news['Link'] . "]]>";
}
$newsTitle = "<![CDATA[" . strip_tags($news['Title']) . "]]>";

// Image first?
$payload = "<a href='$newsLink'><img style='padding: 5px;' src='$newsImage' /></a>";
$payload .= "<br>\r\n";
$payload .= $news['Payload'];

$newsPayload = "<![CDATA[" . htmlspecialchars(strip_tags($payload)) . "]]>";
$newsPayload = "<![CDATA[" . strip_tags($payload) . "]]>";

// $newsPayload contains relative URLs, which need converting to absolute URLs
$newsPayload = str_replace("href='/", "href='" . config('app.url') . "/", $newsPayload);
Expand All @@ -53,7 +56,7 @@
// ?!

$article->appendChild($dom->createElement('title', htmlentities($newsTitle)));
$article->appendChild($dom->createElement('link', $newsLink));
$article->appendChild($dom->createElement('link', htmlentities($newsLink)));
$article->appendChild($dom->createElement('description', htmlentities($newsPayload)));
$article->appendChild($dom->createElement('pubDate', $newsDate));

Expand Down

0 comments on commit 774a266

Please sign in to comment.