pub / rememori

Simple file-based bookmarking and notes application
git clone https://src.jayvii.de/pub/rememori.git
Home | Log | Files | Exports | Refs | README | RSS

commit 780ea87f2f8f186c9f8d159eb16b04527eba7325
parent b7870c5ac81f9f1ddd2b7f387624269f48bfbece
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sat, 26 Oct 2024 18:26:17 +0200

feat: add option to gather RSS feed from categories

Diffstat:
Aapi/rss.php | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+), 0 deletions(-)

diff --git a/api/rss.php b/api/rss.php @@ -0,0 +1,102 @@ +<?php + + /* Load library functions */ + foreach (glob($_SERVER["DOCUMENT_ROOT"] . "/lib/*.php") as $lib) { + include($lib); + } + + /* Load configurations */ + foreach (glob($_SERVER["DOCUMENT_ROOT"] . "/config/*.php") as $conf) { + include($conf); + } + + /* Gather POST input and validate if necessary */ + $category = validate_input_string(gather_post("category")); + $user = validate_input_string(gather_post("user")); + $token = validate_input_string(gather_post("token")); + + /* Fallback to GET request, if no POST was found */ + if (empty($category)) { + $category = validate_input_string(gather_get("category")); + } + if (empty($user)) { + $user = validate_input_string(gather_get("user")); + } + if (empty($token)) { + $token = validate_input_string(gather_get("token")); + } + + /* run authentification method. exit immediately if it fails */ + $auth = auth_user($user, $token, -1); + if ($auth !== true) { + exit( + "{" . + "\"status\": \"error\"," . + "\"message\": \"You could not be authenticated!\"" . + "}" + ); + } + + /* fetch notes in the given category */ + $notes = gather_notes($user, $category); + + /* Sort filenames by edit timestamp */ + usort($notes, "sort_by_time"); + + /* construct RSS URL */ + $my_url = htmlspecialcharacters( + "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] + ); + + /* write RSS XML */ + header('Content-Type: text/xml'); + +?> + +<!-- XML header --> +<rss + version="2.0" + xmlns:atom="http://www.w3.org/2005/Atom" + xmlns:content="http://purl.org/rss/1.0/modules/content/" +> +<channel> +<title><?php echo $user . "/" . $category; ?></title> +<link><?php echo $_SERVER["SERVER_NAME"]; ?></link> +<description> + Rememori notes in <?php echo $user . "/" . $category; ?> +</description> +<generator>rememori</generator> +<lastBuildDate><?php echo date("Y-m-d H:i:s", time()); ?></lastBuildDate> +<atom:link href="<?php echo $my_url; ?>" rel="self" type="application/rss+xml"/> + +<?php + + /* cycle through items in gather notes and list them */ + foreach ($notes as $note) { + + /* If the entry does not contain a link, skip it! */ + if (empty($note["link"])) { + continue; + } + +?> + +<!-- item: <?php echo $note["name"]; ?> --> +<item> +<title><?php echo $note["name"]; ?></title> +<link><?php echo $note["link"]; ?></link> +<pubDate><?php echo date("Y-m-d H:i:s", $note["time"]); ?></pubDate> +<guid><?php echo $note["link"]; ?></guid> +<description> +<?php echo read_note($user, $note["category"], $note["name"] . ".txt"); ?> +</description> +</item> + +<?php + + } // foreach + +?> + +</channel> +</rss>