aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates
diff options
context:
space:
mode:
authorwinter2025-02-07 18:26:05 +0000
committerwinter2025-02-07 18:26:05 +0000
commitd18ec187847893f94418b29bc6a087d6b2dd9a2d (patch)
tree8ea4451cb1f62f8041eae71ca60ec2b64fafe8b2 /templates
parent43f0b9f41a582925838b2ba686110b2f07576be3 (diff)
localise note timestamps and stuff
Diffstat (limited to 'templates')
-rw-r--r--templates/note.php14
-rw-r--r--templates/preferences_form.php31
-rw-r--r--templates/settings_field.php8
3 files changed, 30 insertions, 23 deletions
diff --git a/templates/note.php b/templates/note.php
index b43e63e..db4fbb9 100644
--- a/templates/note.php
+++ b/templates/note.php
@@ -3,8 +3,10 @@ use Digitigrade\Model\Actor;
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\NotePrivacyScope;
use Digitigrade\Model\UserAccount;
+use Digitigrade\UserSettings;
$user = UserAccount::findByCurrentSession();
+$prefs = $user ? new UserSettings($user) : null;
$interKinds = [];
$actionsDisabled = $user == null;
if ($user != null) {
@@ -25,13 +27,11 @@ if ($user != null) {
href="/@/<?= $note->author->getFullHandle() ?>"><?= htmlspecialchars($note->author->displayName) ?></a>
<span class="authorHandle">@<?= $note->author->getFullHandle() ?></span>
<a class="timestamp" href="/@/<?= $note->author->getFullHandle() ?>/note/<?= $note->id ?>">
- <?= // TODO: localise
- $note->created->format('Y-m-d \a\t H:i')
+ <?= format_datetime($note->created, $prefs?->get('locale.timezone'))
. (isset($note->modified) && $note->modified != $note->created
- ? ' (edited ' . $note->modified->format('Y-m-d \a\t H:i') . ')'
+ ? ' (' . format_datetime($note->modified, $prefs?->get('locale.timezone')) . ')'
: ''
- )
- ?>
+ ) ?>
</a>
<span class="privacyScope inlineIcon material-symbols <?= match ($note->privacy->scope) {
NotePrivacyScope::NONE => 'lock',
@@ -78,11 +78,11 @@ if ($user != null) {
<div class="attachments">
<?php foreach ($note->attachments as $attachment): ?>
<div>
- <?php if (str_starts_with($attachment->type, 'image/')): ?>
+ <?php if ($attachment->isImage()): ?>
<img src="<?= $attachment->href ?>" alt="<?= htmlspecialchars($attachment->description ?? '') ?>"
title="<?= htmlspecialchars($attachment->description ?? '') ?>">
<?php else: ?>
- <a class="file" href="<?= $attachment->href ?>" target="_blank">
+ <a class="file" href="<?= $attachment->href ?>" target="_blank" download>
<span class="material-symbols attach-file"></span>
<span><?= htmlspecialchars($attachment->description ?? basename($attachment->href)) ?></span>
</a>
diff --git a/templates/preferences_form.php b/templates/preferences_form.php
index 8c8f203..33418f6 100644
--- a/templates/preferences_form.php
+++ b/templates/preferences_form.php
@@ -2,27 +2,26 @@
use Digitigrade\UserSettings;
$settings = new UserSettings($user);
+
+function _user_pref(string $id, mixed $value, string $type) {
+ call_template('settings_field', [
+ 'id' => "pref-$id",
+ 'fieldName' => $id,
+ 'name' => __("preferences.$id.name"),
+ 'description' => __("preferences.$id.description"),
+ 'value' => $value,
+ 'type' => $type
+ ]);
+}
+
?>
<form class="settings" method="post" action="/todo" hx-post="/fragment/preferences" hx-disabled-elt="find button"
hx-swap="outerHTML">
<?php
- call_template('settings_field', [
- 'id' => 'pref-requestToFollow',
- 'fieldName' => 'requestToFollow',
- 'name' => __('preferences.requestToFollow.name'),
- 'description' => __('preferences.requestToFollow.description'),
- 'value' => $user->actor->requestToFollow,
- 'type' => 'boolean'
- ]);
- call_template('settings_field', [
- 'id' => 'pref-smallIndicators',
- 'fieldName' => 'smallIndicators',
- 'name' => __('preferences.smallIndicators.name'),
- 'description' => __('preferences.smallIndicators.description'),
- 'value' => $settings->getBool('interface.smallUnreadIndicators'),
- 'type' => 'boolean'
- ]);
+ _user_pref('requestToFollow', $user->actor->requestToFollow, 'boolean');
+ _user_pref('smallIndicators', $settings->getBool('interface.smallUnreadIndicators'), 'boolean');
+ _user_pref('timezone', $settings->get('locale.timezone'), 'timezone');
?>
<div class="row">
diff --git a/templates/settings_field.php b/templates/settings_field.php
index fe68a52..f9de886 100644
--- a/templates/settings_field.php
+++ b/templates/settings_field.php
@@ -38,5 +38,13 @@ $fieldName ??= str_replace('.', '<DOT>', $key);
<input id="<?= $id ?>" name="<?= $fieldName ?>" value="<?= $value ?>" type="<?= $inputType ?>" autocomplete="off">
+ <?php if ($inputType == 'timezone'): ?>
+ <button type="button" class="primary material-symbols update" title="<?= __('preferences.timezone.auto') ?>" _="
+ on click
+ js return Intl.DateTimeFormat().resolvedOptions().timeZone end
+ set the value of #<?= $id ?> to it
+ "></button>
+ <?php endif; ?>
+
<?php endif; ?>
</div> \ No newline at end of file