aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
authorwinter2025-03-10 20:13:40 +0000
committerwinter2025-03-10 20:13:40 +0000
commit30fa49bc3fa4f94184d693932e838c0672f24a16 (patch)
treed15bccf49c5c15905bb581e2f394b281ce852ee3 /routes
parent2bd4a086b0f50b1b88faf846da91267290ca4b07 (diff)
add user rss/atom feeds
Diffstat (limited to 'routes')
-rw-r--r--routes/actor_rss.php44
-rw-r--r--routes/preferences.php1
2 files changed, 45 insertions, 0 deletions
diff --git a/routes/actor_rss.php b/routes/actor_rss.php
new file mode 100644
index 0000000..67d52ad
--- /dev/null
+++ b/routes/actor_rss.php
@@ -0,0 +1,44 @@
+<?php
+
+use Digitigrade\HttpResponseStatus\Forbidden;
+use Digitigrade\HttpResponseStatus\NotFound;
+use Digitigrade\Model\Actor;
+use Digitigrade\Model\UserAccount;
+use Digitigrade\Router;
+use Digitigrade\Text;
+use Digitigrade\UserSettings;
+
+$checkActorFeedEnabled = function (?Actor $actor) {
+ if ($actor == null || $actor->deleted) {
+ throw new NotFound('there is no actor with that id');
+ }
+ if (!$actor->isLocal) {
+ throw new NotFound('refusing to give you an rss feed for a non-local actor go talk to their home instance');
+ }
+ $user = UserAccount::findByLinkedActor($actor);
+ if ($user == null) {
+ throw new NotFound('im truly discombobulated');
+ }
+ $rssEnabled = (new UserSettings($user))->getBool('profile.rssEnabled');
+ if (!$rssEnabled) {
+ throw new Forbidden('this user has not enabled RSS/Atom feeds for their profile');
+ }
+};
+
+Router::getInstance()->mount('/actor/:id/feed/:lang/feed.rss', function (array $args) use ($checkActorFeedEnabled) {
+ $actor = Actor::find($args['id']);
+ $checkActorFeedEnabled($actor);
+ header('Content-Type: application/rss+xml');
+ Text::setDefaultLanguage($args['lang']);
+ render_template('actor_rss', ['actor' => $actor, 'lang' => $args['lang']]);
+});
+
+Router::getInstance()->mount('/actor/:id/feed/:lang/feed.atom', function (array $args) use ($checkActorFeedEnabled) {
+ $actor = Actor::find($args['id']);
+ $checkActorFeedEnabled($actor);
+ header('Content-Type: application/atom+xml');
+ Text::setDefaultLanguage($args['lang']);
+ render_template('actor_atom', ['actor' => $actor, 'lang' => $args['lang']]);
+});
+
+unset($checkActorFeedEnabled);
diff --git a/routes/preferences.php b/routes/preferences.php
index 243f90d..99b8458 100644
--- a/routes/preferences.php
+++ b/routes/preferences.php
@@ -19,6 +19,7 @@ Router::getInstance()->mount('/fragment/preferences', function (array $args) {
$user->actor->save();
$settings->set('interface.smallUnreadIndicators', $_POST['smallIndicators']);
$settings->set('locale.timezone', $_POST['timezone']);
+ $settings->set('profile.rssEnabled', $_POST['rssEnabled']);
$saved = true;
}