From 2b63fe830bd20005904afd01d2fab7d353b129eb Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Fri, 14 Jun 2024 10:03:11 +0200 Subject: [PATCH 1/3] Add cake day and use a user's `published` field - add the cake day to a users profile page, as well as the user popover - set the `createdAt` field to a user's `published` field when updating them. We already expose that field --- src/Service/ActivityPubManager.php | 10 ++++++++++ src/Service/SettingsManager.php | 9 +++++++++ src/Twig/Extension/SettingsExtension.php | 1 + src/Twig/Runtime/SettingsExtensionRuntime.php | 5 +++++ templates/user/_info.html.twig | 10 +++++++--- templates/user/_user_popover.html.twig | 4 ++++ translations/messages.en.yaml | 1 + 7 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php index fda2ec4cc..32073e078 100644 --- a/src/Service/ActivityPubManager.php +++ b/src/Service/ActivityPubManager.php @@ -330,6 +330,16 @@ public function updateUser(string $actorUrl): ?User $user->apTimeoutAt = null; $user->apFetchedAt = new \DateTime(); + if (isset($actor['published'])) { + try { + $createdAt = new \DateTimeImmutable($actor['published']); + $now = new \DateTimeImmutable(); + if ($createdAt < $now) { + $user->createdAt = $createdAt; + } + } catch (\Exception) {} + } + // Only update about when summary is set if (isset($actor['summary'])) { $converter = new HtmlConverter(['strip_tags' => true]); diff --git a/src/Service/SettingsManager.php b/src/Service/SettingsManager.php index 11ac26645..bcd672951 100644 --- a/src/Service/SettingsManager.php +++ b/src/Service/SettingsManager.php @@ -9,6 +9,7 @@ use App\Repository\SettingsRepository; use Doctrine\ORM\EntityManagerInterface; use JetBrains\PhpStorm\Pure; +use Symfony\Component\HttpFoundation\RequestStack; class SettingsManager { @@ -17,6 +18,7 @@ class SettingsManager public function __construct( private readonly EntityManagerInterface $entityManager, private readonly SettingsRepository $repository, + private readonly RequestStack $requestStack, private readonly string $kbinDomain, private readonly string $kbinTitle, private readonly string $kbinMetaTitle, @@ -153,4 +155,11 @@ public static function getValue(string $name): string { return self::$dto->{$name}; } + + public function getLocale(): string + { + $request = $this->requestStack->getCurrentRequest(); + + return $request->cookies->get('kbin_lang') ?? $request->getLocale() ?? $this->get('KBIN_DEFAULT_LANG'); + } } diff --git a/src/Twig/Extension/SettingsExtension.php b/src/Twig/Extension/SettingsExtension.php index c3981962e..1b966c0c3 100644 --- a/src/Twig/Extension/SettingsExtension.php +++ b/src/Twig/Extension/SettingsExtension.php @@ -31,6 +31,7 @@ public function getFunctions(): array new TwigFunction('mbin_restrict_magazine_creation', [SettingsExtensionRuntime::class, 'mbinRestrictMagazineCreation']), new TwigFunction('mbin_private_instance', [SettingsExtensionRuntime::class, 'mbinPrivateInstance']), new TwigFunction('mbin_sso_show_first', [SettingsExtensionRuntime::class, 'mbinSsoShowFirst']), + new TwigFunction('mbin_lang', [SettingsExtensionRuntime::class, 'mbinLang']), ]; } } diff --git a/src/Twig/Runtime/SettingsExtensionRuntime.php b/src/Twig/Runtime/SettingsExtensionRuntime.php index 6f5ce0ea5..2213d98fc 100644 --- a/src/Twig/Runtime/SettingsExtensionRuntime.php +++ b/src/Twig/Runtime/SettingsExtensionRuntime.php @@ -118,4 +118,9 @@ public function mbinSsoShowFirst(): bool { return $this->settings->get('MBIN_SSO_SHOW_FIRST'); } + + public function mbinLang(): string + { + return $this->settings->getLocale(); + } } diff --git a/templates/user/_info.html.twig b/templates/user/_info.html.twig index c6ec88255..c6bbf2899 100644 --- a/templates/user/_info.html.twig +++ b/templates/user/_info.html.twig @@ -19,15 +19,19 @@ {% endif %} diff --git a/templates/user/_user_popover.html.twig b/templates/user/_user_popover.html.twig index a4569f9ee..59578f8a3 100644 --- a/templates/user/_user_popover.html.twig +++ b/templates/user/_user_popover.html.twig @@ -21,6 +21,10 @@