aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwinter2024-12-24 15:32:56 +0000
committerwinter2024-12-24 15:32:56 +0000
commitd5a57276eb27e215dd0b1bd5eb67ac26acc9575b (patch)
tree0cb3a14fa9a82d2438a7c12838f04ea12e02a9fa
parent01b7c47c68b8b3c5a9fd9137b067b34b566b951d (diff)
more stuff and things
-rw-r--r--Digitigrade/Model/Note.php8
-rw-r--r--Digitigrade/Timeline/GlobalTimeline.php2
-rw-r--r--Digitigrade/Timeline/LocalTimeline.php2
-rw-r--r--routes/note.php16
-rw-r--r--static/style.css13
-rw-r--r--templates/actor_profile.php6
-rw-r--r--templates/actor_profile_page.php3
-rw-r--r--templates/note.php4
-rw-r--r--templates/placeholder_text.php1
-rw-r--r--templates/thread_page.php8
10 files changed, 56 insertions, 7 deletions
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php
index 3c0c690..bc8b39b 100644
--- a/Digitigrade/Model/Note.php
+++ b/Digitigrade/Model/Note.php
@@ -102,8 +102,12 @@ class Note extends PushableModel {
return $actors;
}
- public static function findAllWithAuthor(Actor $author, ?int $limit = null, int $offset = 0): array {
- return self::findAllWhere('author = ?', [$author->id], $limit, $offset, 'created DESC');
+ public static function findAllWithAuthor(Actor $author, ?int $limit = null, int $offset = 0, bool $includeDeleted = false): array {
+ $where = 'author = ?';
+ if (!$includeDeleted) {
+ $where .= ' AND deleted = false';
+ }
+ return self::findAllWhere($where, [$author->id], $limit, $offset, 'created DESC');
}
public function getInteractions(): array {
diff --git a/Digitigrade/Timeline/GlobalTimeline.php b/Digitigrade/Timeline/GlobalTimeline.php
index b495174..2236ee4 100644
--- a/Digitigrade/Timeline/GlobalTimeline.php
+++ b/Digitigrade/Timeline/GlobalTimeline.php
@@ -9,7 +9,7 @@ class GlobalTimeline extends Timeline {
$db = Db::getInstance()->getPdo();
$stmt = $db->prepare(<<<END
SELECT note.id FROM note LEFT JOIN note_privacy ON note_privacy.note_id = note.id
- WHERE note_privacy.scope = 'public' AND note_privacy.indexable = true
+ WHERE note_privacy.scope = 'public' AND note_privacy.indexable = true AND note.deleted = false
ORDER BY note.created DESC LIMIT ? OFFSET ?
END);
$stmt->execute([$limit, $offset]);
diff --git a/Digitigrade/Timeline/LocalTimeline.php b/Digitigrade/Timeline/LocalTimeline.php
index e4594af..69b8634 100644
--- a/Digitigrade/Timeline/LocalTimeline.php
+++ b/Digitigrade/Timeline/LocalTimeline.php
@@ -11,7 +11,7 @@ class LocalTimeline extends Timeline {
SELECT note.id FROM note
LEFT JOIN note_privacy ON note_privacy.note_id = note.id
LEFT JOIN actor ON note.author = actor.id
- WHERE note_privacy.scope = 'public' AND note_privacy.indexable = true AND actor.is_local = true
+ WHERE note_privacy.scope = 'public' AND note_privacy.indexable = true AND actor.is_local = true AND note.deleted = false
ORDER BY note.created DESC LIMIT ? OFFSET ?
END);
$stmt->execute([$limit, $offset]);
diff --git a/routes/note.php b/routes/note.php
index 071c86c..8a6c9da 100644
--- a/routes/note.php
+++ b/routes/note.php
@@ -1,6 +1,7 @@
<?php
use Digitigrade\HttpResponseStatus\NotFound;
+use Digitigrade\HttpResponseStatus\TemporaryRedirect;
use Digitigrade\Model\Note;
use Digitigrade\Router;
@@ -12,5 +13,20 @@ Router::getInstance()->mount('/note/:id', function (array $args) {
if (!$note->author->isLocal) {
throw new NotFound("i don't want to tell you about non local notes sorry");
}
+ if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) {
+ throw new TemporaryRedirect('/@/' . $note->author->handle . "/note/$note->id");
+ }
json_response($note);
});
+
+Router::getInstance()->mount('/@/:handle/note/:id', function (array $args) {
+ $note = Note::find($args['id']);
+ if ($note == null || $note->deleted) {
+ throw new NotFound("i don't know that note");
+ }
+ // change the handle in the url if it's wrong
+ if ($args['handle'] != $note->author->getFullHandle()) {
+ throw new TemporaryRedirect('/@/' . $note->author->getFullHandle() . "/note/$note->id");
+ }
+ render_template('thread_page', ['note' => $note]);
+});
diff --git a/static/style.css b/static/style.css
index 83ea861..fcf6e81 100644
--- a/static/style.css
+++ b/static/style.css
@@ -68,6 +68,12 @@ hr {
margin: 0px 16px;
}
+.placeholder {
+ font-style: italic;
+ color: #555;
+ text-align: center;
+}
+
article.note {
background: #fee4;
border: 1px solid #3b005e44;
@@ -100,6 +106,13 @@ article.note {
text-overflow: ellipsis;
overflow: hidden;
}
+ a.timestamp {
+ color: inherit;
+ text-decoration: none;
+ &:hover {
+ text-decoration: underline;
+ }
+ }
}
.buttons {
diff --git a/templates/actor_profile.php b/templates/actor_profile.php
index 0d99d05..f721fc8 100644
--- a/templates/actor_profile.php
+++ b/templates/actor_profile.php
@@ -13,5 +13,9 @@
<?php endif; ?>
</div>
</div>
- <p class="bio"><?= $actor->bio ?></p>
+ <?php if (isset($actor->bio) && $actor->bio != '') { ?>
+ <p class="bio"><?= $actor->bio ?></p>
+ <?php } else {
+ call_template('placeholder_text', ['message' => "This user hasn't written a bio yet."]);
+ } ?>
</div> \ No newline at end of file
diff --git a/templates/actor_profile_page.php b/templates/actor_profile_page.php
index e745433..ffa94e3 100644
--- a/templates/actor_profile_page.php
+++ b/templates/actor_profile_page.php
@@ -10,6 +10,9 @@ call_template('skeleton', [
call_template('actor_profile', ['actor' => $actor]);
echo '<hr>';
$notes = Note::findAllWithAuthor($actor, 50);
+ if (count($notes) == 0) {
+ call_template('placeholder_text', ['message' => "This user hasn't posted anything yet."]);
+ }
foreach ($notes as $n) {
call_template('note', ['note' => $n]);
}
diff --git a/templates/note.php b/templates/note.php
index 6e718f5..8887afb 100644
--- a/templates/note.php
+++ b/templates/note.php
@@ -6,7 +6,7 @@
<div class="infoLine">
<span class="authorName"><?= $note->author->displayName ?></span>
<span class="authorHandle">@<?= $note->author->getFullHandle() ?></span>
- <span class="timestamp">
+ <a class="timestamp" href="/@/<?= $note->author->getFullHandle() ?>/note/<?= $note->id ?>">
<?=
$note->created->format('Y-m-d \a\t H:i')
. (isset($note->modified) && $note->modified != $note->created
@@ -14,7 +14,7 @@
: ''
)
?>
- </span>
+ </a>
</div>
<div class="content">
<?= $note->getFormattedContent('text/html') ?? htmlspecialchars($note->plainContent) ?>
diff --git a/templates/placeholder_text.php b/templates/placeholder_text.php
new file mode 100644
index 0000000..b27e490
--- /dev/null
+++ b/templates/placeholder_text.php
@@ -0,0 +1 @@
+<p class="placeholder"><?= $message ?? "There's nothing here." ?></p> \ No newline at end of file
diff --git a/templates/thread_page.php b/templates/thread_page.php
new file mode 100644
index 0000000..73d8f0b
--- /dev/null
+++ b/templates/thread_page.php
@@ -0,0 +1,8 @@
+<?php
+call_template('skeleton', [
+ 'pageTitle' => '"' . $note->plainContent . '" - @' . $note->author->getFullHandle(),
+ 'renderTitleHeading' => false
+], function () {
+ global $note;
+ call_template('note', ['note' => $note]);
+}); \ No newline at end of file