diff options
Diffstat (limited to 'templates/note/note.php')
| -rw-r--r-- | templates/note/note.php | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/templates/note/note.php b/templates/note/note.php new file mode 100644 index 0000000..7cef342 --- /dev/null +++ b/templates/note/note.php @@ -0,0 +1,176 @@ +<?php +/** @var \Digitigrade\Model\Note $note */ + +use Digitigrade\Model\Actor; +use Digitigrade\Model\InteractionKind; +use Digitigrade\Model\NotePrivacyScope; +use Digitigrade\Model\UserAccount; +use Digitigrade\UserSettings; + +$MAX_PREVIEW_CARDS = 1; + +$user = UserAccount::findByCurrentSession(); +$prefs = $user ? new UserSettings($user) : null; +$interKinds = []; +$actionsDisabled = $user == null; +if ($user != null) { + $interactions = $note->getInteractionsWithAuthor($user->actor); + $interKinds = array_map(fn($inter) => $inter->kind, $interactions); +} +$pathToSelf = $note->getLocalUiHref(); +?> +<article class="note <?= ($selected ?? false) ? 'selected' : '' ?>"> + + <a href="/@/<?= $note->author->getFullHandle() ?>"> + <?php call_template('actor/avatar', ['actor' => $note->author]); ?> + </a> + + <div> + + <div class="infoLine"> + <a class="authorName" + href="/@/<?= htmlspecialchars($note->author->getFullHandle()) ?>"><?= htmlspecialchars($note->author->displayName) ?></a> + <span class="authorPronouns"> + <?php if (isset($note->author->pronouns) && trim($note->author->pronouns) != '') { + echo htmlspecialchars($note->author->pronouns); + } ?> + </span> + <a class="timestamp" href="<?= htmlspecialchars($pathToSelf) ?>"> + <?= format_datetime($note->created) + . (isset($note->modified) && $note->modified != $note->created + ? ' (' . format_datetime($note->modified) . ')' + : '' + ) ?> + </a> + <span class="privacyScope inlineIcon material-symbols <?= match ($note->privacy->scope) { + NotePrivacyScope::NONE => 'lock', + NotePrivacyScope::MUTUALS => 'group', + NotePrivacyScope::FOLLOWERS => 'groups', + NotePrivacyScope::PUBLIC => 'public' + } ?>" title="<?= match ($note->privacy->scope) { + NotePrivacyScope::NONE => __('note.privacy.scope.none'), + NotePrivacyScope::MUTUALS => __('note.privacy.scope.mutuals'), + NotePrivacyScope::FOLLOWERS => __('note.privacy.scope.followers'), + NotePrivacyScope::PUBLIC => __('note.privacy.scope.public') + } ?>"></span> + </div> + + <?php if (isset($note->inReplyTo)): ?> + <div class="replyInfo"> + <span class="material-symbols reply inlineIcon"></span> + <a + href="/@/<?= htmlspecialchars($note->inReplyTo->author->getFullHandle()) ?>/note/<?= $note->inReplyTo->id ?>"> + <?= sprintf(__('note.info.replyTo'), + '<b>' . htmlspecialchars($note->inReplyTo->author->displayName)) . '</b>' ?> + </a> + </div> + <?php elseif (count($note->mentions) > 0): ?> + <div class="replyInfo"> + <span class="material-symbols alternate-email inlineIcon"></span> + <span> + <?= sprintf(__('note.info.mentions'), implode(', ', array_map( + fn(Actor $m) => '<b><a href="/@/' . htmlspecialchars($m->getFullHandle()) . '">' . htmlspecialchars($m->displayName) . '</a></b>', + $note->mentions + ))) ?> + </span> + </div> + <?php endif; ?> + + <?php if (isset($note->summary)): ?> + <details> + <summary><?= htmlspecialchars($note->summary) ?></summary> + <?php endif; ?> + <div class="content" lang="<?= $note->language ?>"> + <?php if ($note->hasPage()): ?> + <?= __f('note.page.summaryMessage', htmlspecialchars($note->getPage()->title)) ?> + <?php else: ?> + <?= $note->getBestContentAsHtml() ?> + <?php endif; ?> + </div> + + <?php if (count($note->attachments) > 0): ?> + <div class="attachments"> + <?php foreach ($note->attachments as $attachment) { + call_template('note/attachment', ['attachment' => $attachment]); + } ?> + </div> + <?php endif; ?> + + <?php + $i = 0; + foreach ($note->getLinkPreviews() as $preview) { + call_template('note/link_preview', ['preview' => $preview]); + if (++$i > $MAX_PREVIEW_CARDS) + break; + } + ?> + + <?php if (isset($note->summary)): ?> + </details> + <?php endif; ?> + + <?php if ($note->hasPage()): ?> + <a class="button secondary minWidth" href="<?= $note->getLocalUiHref(true) ?>"> + <span class="material-symbols article-outline"></span> + <span><?= __('note.openPage') ?></span> + </a> + <?php endif; ?> + + <div class="buttons"> + <?php foreach (['like', 'dislike', 'reshare'] as $action) { + $kind = InteractionKind::from($action); + call_template('interaction_button', [ + 'action' => $action, + 'note' => $note, + 'active' => in_array($kind, $interKinds), + 'count' => $note->countInteractionsOfKind($kind), + 'disabled' => $actionsDisabled + ]); + } + call_template('note/reply_button', [ + 'note' => $note, + 'count' => $note->countReplies(), + 'disabled' => $actionsDisabled + ]); + ?> + <div class="right"> + <?php call_template('menu_button', [], function () { + global $note; + $user = UserAccount::findByCurrentSession(); + ?> + <li> + <button data-share-url="<?= htmlspecialchars($note->uri) ?>" _=" + on click + set url to my @data-share-url + js(url) + navigator.share({ url: url }) + end" type="button"> + <span class="material-symbols share"></span> + <span><?= __('action.share') ?></span> + </button> + </li> + <?php if ($note->author->isLocal && ($note->author == $user?->actor || $user?->isAdmin)): ?> + <li> + <button hx-delete="/fragment/note/<?= $note->id ?>" + hx-confirm="<?= __('note.action.delete.confirmation') ?>" hx-target="closest .note" + hx-swap="delete"> + <span class="material-symbols delete-outline"></span> + <span><?= __('note.action.delete') ?></span> + </button> + </li> + <?php endif; ?> + <?php if (!$note->author->isLocal): ?> + <li> + <a target="_blank" href="<?= htmlspecialchars($note->uri) ?>" rel="nofollow noreferrer"> + <span class="material-symbols open-in-new"></span> + <span><?= __('note.openRemote') ?></span> + </a> + </li> + <?php endif; ?> + <?php }); ?> + </div> + </div> + + <?php call_template('note/reply_form', ['note' => $note]); ?> + </div> +</article>
\ No newline at end of file |
