aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleteoryx <alyx@aleteoryx.me>2024-11-14 16:35:27 -0500
committerAleteoryx <alyx@aleteoryx.me>2024-11-14 16:35:27 -0500
commitd841acfb37d52d89f5b27610754881e3e9e85932 (patch)
tree41dca11ecee3aa1ba63f56d7dae3e90b06dcd1b4
parent1551d2bda2ad95231f9cde3b7cf94a4a1e01a75f (diff)
downloadrss_dot_php-d841acfb37d52d89f5b27610754881e3e9e85932.tar.gz
rss_dot_php-d841acfb37d52d89f5b27610754881e3e9e85932.tar.bz2
rss_dot_php-d841acfb37d52d89f5b27610754881e3e9e85932.zip
add config
-rw-r--r--rss.php39
1 files changed, 29 insertions, 10 deletions
diff --git a/rss.php b/rss.php
index 783a119..b75640f 100644
--- a/rss.php
+++ b/rss.php
@@ -1,11 +1,11 @@
-<?php define("VERSION", "0.0.1");
+<?php define("VERSION", "0.0.2");
/* --- FEEDS - EDIT AS NEEDED --- */
-$feeds["OTW News"] ["url"] = "https://www.transformativeworks.org/category/announcement/feed/";
-//$feeds["OTW News"] ["home"] = "https://www.transformativeworks.org/";
+$feeds["OTW News"] ["url"] = "https://www.transformativeworks.org/category/announcement/feed/";
+$feeds["OTW News"] ["render_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 --- */
@@ -53,7 +53,7 @@ $config["link_target"] = "_top";
/* --- CODE - DO NOT TOUCH --- */
-function load_rss(string $uri, string $linkrel = "alternate", bool? $allow_html = NULL): array {
+function load_rss(string $uri, string $linkrel = "alternate", ?bool $allow_html = NULL): array {
global $config;
$xml = file_get_contents($uri);
@@ -114,7 +114,7 @@ function load_rss(string $uri, string $linkrel = "alternate", bool? $allow_html
if ($node->getElementsByTagName("content")
?->item(0)
?->getAttribute("type") === "html" && $allow_html !== FALSE) {
- $data["content"] = strip_html($data["content"])
+ $data["content"] = strip_html($data["content"]);
} else {
$data["content"] = htmlentities(html_entity_decode($data["content"]));
}
@@ -143,13 +143,13 @@ function load_rss(string $uri, string $linkrel = "alternate", bool? $allow_html
return $parsed??[];
}
-function load_cached(int $ttl, string $uri, string $linkrel = "alternate"): array {
+function load_cached(int $ttl, string $uri, string $linkrel = "alternate", ?bool $allow_html = NULL): array {
global $config;
$path = $config["cache_dir"]."/".md5($uri);
// echo $path."\n";
if ((@filemtime($path) ?? 0) + $ttl < time()) {
// echo "cache miss, loading over network\n";
- $data = load_rss($uri, $linkrel);
+ $data = load_rss($uri, $linkrel, $allow_html);
file_put_contents($path, serialize($data));
return $data;
} else {
@@ -213,9 +213,19 @@ foreach ($feeds as $name => $data) {
if (!isset($data["ttl"])) $data["ttl"] = 3600;
if (!isset($data["linkrel"])) $data["linkrel"] = "alternate";
- foreach(load_cached($data["ttl"], $data["url"], $data["linkrel"]) as $entry) {
+ $data["render_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") {
+ unset($entry["content"]);
+ }
+ if ($data["render_mode"] == "no_title") {
+ unset($entry["title"]);
+ }
+
$combined[] = $entry;
}
}
@@ -266,7 +276,12 @@ $base = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
<?php endif;
foreach ($combined as $entry): ?>
<article>
+ <?php if(isset($entry['title'])): ?>
<h1><a target="<?= $config['link_target'] ?>" href="<?= $entry['link'] ?>"><?= $entry['title'] ?></a></h1>
+ <?php endif; ?>
+ <?php if(isset($entry['content'])): ?>
+ <div class="content"><?= $entry['content'] ?></div>
+ <?php endif; ?>
<span class="source" data-source="<?= $entry['source'] ?>">
<?php if ($entry['home']): ?>
<a target="<?= $config['link_target'] ?>" href="<?= $entry['home'] ?>"><?= $entry['source'] ?></a>
@@ -274,6 +289,10 @@ $base = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
<?= $entry['source'] ?>
<?php endif; ?>
</span>
+ <?php if(!isset($entry['title'])): ?>
+ &bullet;
+ <a href="<?= $entry['link'] ?>">Source</a>
+ <?php endif; ?>
&bullet;
<time datetime="<?= $entry['date']->format(DateTime::ISO8601) ?>">
<?= htmlentities($entry['date']->format($config['date_fmt'])) ?>