From 30fa49bc3fa4f94184d693932e838c0672f24a16 Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 10 Mar 2025 20:13:40 +0000 Subject: add user rss/atom feeds --- templates/actor_atom.php | 51 ++++++++++++++++++++++++++++++++++++++++ templates/actor_profile.php | 23 ++++++++++++++---- templates/actor_profile_page.php | 23 +++++++++++++++--- templates/actor_rss.php | 46 ++++++++++++++++++++++++++++++++++++ templates/note.php | 4 +++- templates/preferences_form.php | 1 + templates/skeleton.php | 7 +++++- 7 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 templates/actor_atom.php create mode 100644 templates/actor_rss.php (limited to 'templates') diff --git a/templates/actor_atom.php b/templates/actor_atom.php new file mode 100644 index 0000000..8bd40fb --- /dev/null +++ b/templates/actor_atom.php @@ -0,0 +1,51 @@ +id/feed/$lang/feed.atom"); +$actorPage = path_to_uri("/@/$actor->handle"); + +echo ''; +?> + + + + <?= htmlspecialchars($actor->displayName) ?> — <?= GlobalSettings::getInstance()->get('instance.name') ?> + + created->format(DateTime::ATOM) ?> + + displayName) ?> + + + + + Digitigrade + avatar)): ?> + avatar ?> + + displayName) ?> + + + privacy->scope != NotePrivacyScope::PUBLIC || $note->inReplyTo != null) { + continue; + } + ?> + + id") ?> + <![CDATA[<?= htmlspecialchars(substr($note->plainContent, 0, 50), double_encode: false) ?>]]> + modified ?? $note->created)->format(DateTime::ATOM) ?> + handle/note/$note->id") ?>" /> + getBestContentAsHtml() ?>]]> + attachments as $file): ?> + + + + + \ No newline at end of file diff --git a/templates/actor_profile.php b/templates/actor_profile.php index ca19978..dfb0174 100644 --- a/templates/actor_profile.php +++ b/templates/actor_profile.php @@ -1,7 +1,9 @@
@@ -23,11 +25,7 @@ $user = UserAccount::findByCurrentSession();
- + isLocal && isset($actor->homepage)): ?>
  • @@ -36,6 +34,21 @@ $user = UserAccount::findByCurrentSession();
  • + getBool('profile.rssEnabled')): ?> + +
  • + id/feed/$lang/feed.rss" ?>" target="_blank" type="application/rss+xml"> + + + +
  • +
  • + id/feed/$lang/feed.atom" ?>" target="_blank" type="application/atom+xml"> + + + +
  • + actor != $actor): ?>
  • $user, 'actor' => $actor]) ?>
  • diff --git a/templates/actor_profile_page.php b/templates/actor_profile_page.php index dbeb86a..1b2981d 100644 --- a/templates/actor_profile_page.php +++ b/templates/actor_profile_page.php @@ -2,6 +2,10 @@ use Digitigrade\Model\Note; use Digitigrade\Model\UserAccount; +use Digitigrade\UserSettings; + +$lang = get_ui_language(); +$actorUser = UserAccount::findByLinkedActor($actor); call_template('skeleton', [ 'pageTitle' => "$actor->displayName - @" . $actor->getFullHandle(), @@ -10,9 +14,22 @@ call_template('skeleton', [ 'ogDesc' => $actor->bio, 'ogImage' => $actor->avatar ?? path_to_uri('/static/default-avatar.png'), 'ogType' => 'profile', - 'ogHandle' => '@' . $actor->getFullHandle(true) -], function () { - global $actor; + 'ogHandle' => '@' . $actor->getFullHandle(true), + 'headLinks' => ($actorUser != null && (new UserSettings($actorUser))->getBool('profile.rssEnabled')) ? [ + [ + 'rel' => 'alternate', + 'type' => 'application/rss+xml', + 'href' => "/actor/$actor->id/feed/$lang/feed.rss", + 'title' => __('user.profile.feed.rss') + ], + [ + 'rel' => 'alternate', + 'type' => 'application/atom+xml', + 'href' => "/actor/$actor->id/feed/$lang/feed.atom", + 'title' => __('user.profile.feed.atom') + ] + ] : [] +], function () use ($actor) { $user = UserAccount::findByCurrentSession(); call_template('actor_profile', ['actor' => $actor]); diff --git a/templates/actor_rss.php b/templates/actor_rss.php new file mode 100644 index 0000000..03fc4f5 --- /dev/null +++ b/templates/actor_rss.php @@ -0,0 +1,46 @@ +'; +?> + + + + <?= htmlspecialchars($actor->displayName) ?> — <?= GlobalSettings::getInstance()->get('instance.name') ?> + + handle") ?> + displayName)) ?> + + + avatar)): ?> + + avatar ?> + + + + privacy->scope != NotePrivacyScope::PUBLIC || $note->inReplyTo != null) { + continue; + } + ?> + + handle/note/$note->id") ?> + id") ?> + <![CDATA[<?= htmlspecialchars(substr($note->plainContent, 0, 50), double_encode: false) ?>]]> + getBestContentAsHtml() ?>]]> + created->format(DateTime::RSS) ?> + attachments as $file): ?> + + + + + + \ No newline at end of file diff --git a/templates/note.php b/templates/note.php index 6835a0f..94edf2b 100644 --- a/templates/note.php +++ b/templates/note.php @@ -1,4 +1,6 @@ author->getFullHandle() . '/note/' . $note->id;
    summary) ?> -
    +
    getBestContentAsHtml() ?>
    diff --git a/templates/preferences_form.php b/templates/preferences_form.php index 33418f6..d1694eb 100644 --- a/templates/preferences_form.php +++ b/templates/preferences_form.php @@ -22,6 +22,7 @@ function _user_pref(string $id, mixed $value, string $type) { _user_pref('requestToFollow', $user->actor->requestToFollow, 'boolean'); _user_pref('smallIndicators', $settings->getBool('interface.smallUnreadIndicators'), 'boolean'); _user_pref('timezone', $settings->get('locale.timezone'), 'timezone'); + _user_pref('rssEnabled', $settings->getBool('profile.rssEnabled'), 'boolean'); ?>
    diff --git a/templates/skeleton.php b/templates/skeleton.php index 7f40611..5848054 100644 --- a/templates/skeleton.php +++ b/templates/skeleton.php @@ -7,7 +7,7 @@ $user = UserAccount::findByCurrentSession(); $settings = GlobalSettings::getInstance(); ?> - + <?= $pageTitle ?> — <?= $settings->get('instance.name') ?> @@ -29,6 +29,11 @@ $settings = GlobalSettings::getInstance(); + + + + -- cgit v1.3