From 881b7d973373b432155f664003e7e54fe6db7266 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Thu, 14 Nov 2024 16:50:04 -0500 Subject: default content to '', rename render_mode to mode --- README.md | 2 +- rss.php | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0b4eaba..e0328d3 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The following options are supported per-feed: - `$feeds[feed]["url"]`: **REQUIRED**: The URL of the RSS/Atom feed. - `$feeds[feed]["home"]`: An optional homepage for the feed. Will be linked under every entry from it. -- `$feeds[feed]["render_mode"]`: How to display the feed, one of: +- `$feeds[feed]["mode"]`: How to display the feed, one of: - `"title"`: The default. Shows the title as a link to the article. - `"content"`: Shows the title and content. - `"no_title"`: Hides the title, displays the content. A link to the source is put at the bottom. diff --git a/rss.php b/rss.php index b75640f..4468a7d 100644 --- a/rss.php +++ b/rss.php @@ -1,11 +1,11 @@ getElementsByTagName("description") - ?->item(0)?->textContent; + ?->item(0)?->textContent??""; if ($allow_html === TRUE || $allow_html === NULL) { $data["content"] = strip_html($data["content"]); } else { @@ -109,7 +109,7 @@ function load_rss(string $uri, string $linkrel = "alternate", ?bool $allow_html $data["title"] = htmlentities(html_entity_decode($data["title"])); $data["content"] = $node->getElementsByTagName("content") - ?->item(0)?->textContent; + ?->item(0)?->textContent??""; if ($node->getElementsByTagName("content") ?->item(0) @@ -162,6 +162,8 @@ function load_cached(int $ttl, string $uri, string $linkrel = "alternate", ?bool // TODO: sniff for 8.4 Dom\HTMLDocument when 8.4 releases // function strip_html(string $html): string { + if ($html === "") return $html; + $doc = new DomDocument(); @$doc->loadHTML($html); @@ -177,6 +179,8 @@ function strip_html(string $html): string { $el->setAttribute("javascript:alert('Link stripped for security.')"); if (str_starts_with($el->getAttribute("src"), "javascript:")) $el->setAttribute("javascript:alert('Link stripped for security.')"); + + @$el->removeAttribute("autoplay"); } return implode( @@ -213,16 +217,16 @@ foreach ($feeds as $name => $data) { if (!isset($data["ttl"])) $data["ttl"] = 3600; if (!isset($data["linkrel"])) $data["linkrel"] = "alternate"; - $data["render_mode"] ??= "title"; + $data["mode"] ??= "title"; foreach(load_cached($data["ttl"], $data["url"], $data["linkrel"], @$data["allow_html"]) as $entry) { $entry["source"] = htmlentities($name); $entry["home"] = htmlentities(@$data["home"]); - if ($data["render_mode"] == "title") { + if ($data["mode"] == "title") { unset($entry["content"]); } - if ($data["render_mode"] == "no_title") { + if ($data["mode"] == "no_title") { unset($entry["title"]); } -- cgit v1.2.3-54-g00ecf