aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
authorwinter2025-03-10 20:13:40 +0000
committerwinter2025-03-10 20:13:40 +0000
commit30fa49bc3fa4f94184d693932e838c0672f24a16 (patch)
treed15bccf49c5c15905bb581e2f394b281ce852ee3 /templates
parent2bd4a086b0f50b1b88faf846da91267290ca4b07 (diff)
add user rss/atom feeds
Diffstat (limited to 'templates')
-rw-r--r--templates/actor_atom.php51
-rw-r--r--templates/actor_profile.php23
-rw-r--r--templates/actor_profile_page.php23
-rw-r--r--templates/actor_rss.php46
-rw-r--r--templates/note.php4
-rw-r--r--templates/preferences_form.php1
-rw-r--r--templates/skeleton.php7
7 files changed, 145 insertions, 10 deletions
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 @@
+<?php
+/** @var \Digitigrade\Model\Actor $actor */
+/** @var string $lang */
+
+use Digitigrade\GlobalSettings;
+use Digitigrade\Model\Note;
+use Digitigrade\Model\NotePrivacyScope;
+
+$selfUri = path_to_uri("/actor/$actor->id/feed/$lang/feed.atom");
+$actorPage = path_to_uri("/@/$actor->handle");
+
+echo '<?xml version="1.0" encoding="utf-8"?>';
+?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <id><?= $selfUri ?></id>
+ <title>
+ <?= htmlspecialchars($actor->displayName) ?> — <?= GlobalSettings::getInstance()->get('instance.name') ?>
+ </title>
+ <updated><?= Note::findAllWithAuthor($actor, 1)[0]->created->format(DateTime::ATOM) ?></updated>
+ <author>
+ <name><?= htmlspecialchars($actor->displayName) ?></name>
+ <uri><?= $actorPage ?></uri>
+ </author>
+ <link rel="self" href="<?= $selfUri ?>" />
+ <link rel="alternate" type="text/html" href="<?= $actorPage ?>" />
+ <generator version="<?= get_version() ?>">Digitigrade</generator>
+ <?php if (isset($actor->avatar)): ?>
+ <icon><?= $actor->avatar ?></icon>
+ <?php endif; ?>
+ <subtitle><?= __f('user.rss.description', $actor->displayName) ?></subtitle>
+
+ <?php foreach (Note::findAllWithAuthor($actor, limit: 50) as $note): ?>
+ <?php
+ /** @var Note $note */
+ if ($note->privacy->scope != NotePrivacyScope::PUBLIC || $note->inReplyTo != null) {
+ continue;
+ }
+ ?>
+ <entry>
+ <id><?= path_to_uri("/note/$note->id") ?></id>
+ <title><![CDATA[<?= htmlspecialchars(substr($note->plainContent, 0, 50), double_encode: false) ?>]]></title>
+ <updated><?= ($note->modified ?? $note->created)->format(DateTime::ATOM) ?></updated>
+ <link rel="alternate" type="text/html" href="<?= path_to_uri("/@/$actor->handle/note/$note->id") ?>" />
+ <content type="html"><![CDATA[<?= $note->getBestContentAsHtml() ?>]]></content>
+ <?php foreach ($note->attachments as $file): ?>
+ <link rel="enclosure" title="<?= htmlspecialchars($file->description) ?>" type="<?= $file->type ?>"
+ href="<?= $file->href ?>" />
+ <?php endforeach; ?>
+ </entry>
+ <?php endforeach; ?>
+</feed> \ 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 @@
<?php
use Digitigrade\Model\UserAccount;
+use Digitigrade\UserSettings;
$user = UserAccount::findByCurrentSession();
+$actorUser = UserAccount::findByLinkedActor($actor);
?>
<div class="fullProfile">
<div class="basicInfo">
@@ -23,11 +25,7 @@ $user = UserAccount::findByCurrentSession();
</div>
<div class="profileMiniActions">
- <?php call_template('menu_button', [], function () {
- global $actor;
- // i don't know why but `global $user` just straight up doesnt work?
- $user = UserAccount::findByCurrentSession();
- ?>
+ <?php call_template('menu_button', [], function () use ($actor, $user, $actorUser) { ?>
<?php if (!$actor->isLocal && isset($actor->homepage)): ?>
<li>
<a href="<?= $actor->homepage ?>" target="_blank">
@@ -36,6 +34,21 @@ $user = UserAccount::findByCurrentSession();
</a>
</li>
<?php endif; ?>
+ <?php if ($actorUser != null && (new UserSettings($actorUser))->getBool('profile.rssEnabled')): ?>
+ <?php $lang = get_ui_language(); ?>
+ <li>
+ <a href="<?= "/actor/$actor->id/feed/$lang/feed.rss" ?>" target="_blank" type="application/rss+xml">
+ <span class="material-symbols rss-feed"></span>
+ <span><?= __('user.profile.feed.rss') ?></span>
+ </a>
+ </li>
+ <li>
+ <a href="<?= "/actor/$actor->id/feed/$lang/feed.atom" ?>" target="_blank" type="application/atom+xml">
+ <span class="material-symbols orbit-outline"></span>
+ <span><?= __('user.profile.feed.atom') ?></span>
+ </a>
+ </li>
+ <?php endif; ?>
<?php if ($user != null && $user->actor != $actor): ?>
<li><?php call_template('actor_profile_block_button', ['user' => $user, 'actor' => $actor]) ?></li>
<?php endif; ?>
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 @@
+<?php
+/** @var \Digitigrade\Model\Actor $actor */
+/** @var string $lang */
+
+use Digitigrade\GlobalSettings;
+use Digitigrade\Model\Note;
+use Digitigrade\Model\NotePrivacyScope;
+
+// putting this here because otherwise my ide yells about "shorthand <?"
+// because it thinks i'm trying to do a php thing instead of xml directive
+echo '<?xml version="1.0" encoding="utf-8"?>';
+?>
+<rss version="2.0">
+ <channel>
+ <title>
+ <?= htmlspecialchars($actor->displayName) ?> — <?= GlobalSettings::getInstance()->get('instance.name') ?>
+ </title>
+ <link><?= path_to_uri("/@/$actor->handle") ?></link>
+ <description><?= __f('user.rss.description', htmlspecialchars($actor->displayName)) ?></description>
+ <language><?= $lang ?></language>
+ <generator><?= __f('version', get_version()) ?></generator>
+ <?php if (isset($actor->avatar)): ?>
+ <image>
+ <url><?= $actor->avatar ?></url>
+ </image>
+ <?php endif; ?>
+ <?php foreach (Note::findAllWithAuthor($actor, limit: 50) as $note): ?>
+ <?php
+ /** @var Note $note */
+ if ($note->privacy->scope != NotePrivacyScope::PUBLIC || $note->inReplyTo != null) {
+ continue;
+ }
+ ?>
+ <item>
+ <link><?= path_to_uri("/@/$actor->handle/note/$note->id") ?></link>
+ <guid><?= path_to_uri("/note/$note->id") ?></guid>
+ <title><![CDATA[<?= htmlspecialchars(substr($note->plainContent, 0, 50), double_encode: false) ?>]]></title>
+ <description><![CDATA[<?= $note->getBestContentAsHtml() ?>]]></description>
+ <pubDate><?= $note->created->format(DateTime::RSS) ?></pubDate>
+ <?php foreach ($note->attachments as $file): ?>
+ <enclosure url="<?= $file->href ?>" type="<?= $file->type ?>" size="-1" /><!-- size unknown sorry :( -->
+ <?php endforeach; ?>
+ </item>
+ <?php endforeach; ?>
+ </channel>
+</rss> \ 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 @@
<?php
+/** @var \Digitigrade\Model\Note $note */
+
use Digitigrade\Model\Actor;
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\NotePrivacyScope;
@@ -79,7 +81,7 @@ $pathToSelf = '/@/' . $note->author->getFullHandle() . '/note/' . $note->id;
<details>
<summary><?= htmlspecialchars($note->summary) ?></summary>
<?php endif; ?>
- <div class="content">
+ <div class="content" lang="<?= $note->language ?>">
<?= $note->getBestContentAsHtml() ?>
</div>
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');
?>
<div class="row">
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();
?>
<!DOCTYPE html>
-<html lang="en">
+<html lang="<?= get_ui_language() ?>">
<head>
<title><?= $pageTitle ?> &mdash; <?= $settings->get('instance.name') ?></title>
@@ -29,6 +29,11 @@ $settings = GlobalSettings::getInstance();
<?php if (isset($ogHandle)): ?>
<meta name="fediverse:creator" content="<?= $ogHandle ?>">
<?php endif; ?>
+ <!-- any custom links e.g. rss/atom feeds -->
+ <?php foreach (($headLinks ?? []) as $link): ?>
+ <link rel="<?= $link['rel'] ?>" type="<?= $link['type'] ?? '' ?>" href="<?= $link['href'] ?>"
+ title="<?= $link['title'] ?? '' ?>">
+ <?php endforeach; ?>
<!-- other page resources -->
<?php call_template('head_tags'); ?>
</head>