aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleteoryx <alyx@aleteoryx.me>2024-11-14 16:50:04 -0500
committerAleteoryx <alyx@aleteoryx.me>2024-11-14 16:50:04 -0500
commit881b7d973373b432155f664003e7e54fe6db7266 (patch)
tree19ca7253c45e53f4e2681cee173d3285da904e32
parent51781163e0eb64128a69062090183fa1877be693 (diff)
downloadrss_dot_php-master.tar.gz
rss_dot_php-master.tar.bz2
rss_dot_php-master.zip
default content to '', rename render_mode to modeHEADmaster
-rw-r--r--README.md2
-rw-r--r--rss.php22
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 @@
<?php define("VERSION", "0.0.2");
/* --- FEEDS - EDIT AS NEEDED --- */
-$feeds["OTW News"] ["url"] = "https://www.transformativeworks.org/category/announcement/feed/";
-$feeds["OTW News"] ["render_mode"] = "content";
+$feeds["OTW News"] ["url"] = "https://www.transformativeworks.org/category/announcement/feed/";
+$feeds["OTW News"] ["mode"] = "content";
-$feeds["Dreamwidth News"]["url"] = "https://dw-news.dreamwidth.org/data/rss";
-$feeds["Dreamwidth News"]["home"] = "https://dw-news.dreamwidth.org/";
+$feeds["Dreamwidth News"]["url"] = "https://dw-news.dreamwidth.org/data/rss";
+$feeds["Dreamwidth News"]["home"] = "https://dw-news.dreamwidth.org/";
/* --- CONFIG - EDIT AS NEEDED --- */
@@ -87,7 +87,7 @@ function load_rss(string $uri, string $linkrel = "alternate", ?bool $allow_html
// assume rss is html by default
$data["content"] = $node->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
// <https://www.php.net/manual/en/domdocument.loadhtml.php>
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"]);
}