Skip to content

Commit

Permalink
New/cake day (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich authored Jun 14, 2024
1 parent e8ae52d commit 88800b1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/Service/ActivityPubManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ 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]);
Expand Down Expand Up @@ -463,6 +474,17 @@ public function updateMagazine(string $actorUrl): ?Magazine
$magazine->title = $actor['preferredUsername'];
}

if (isset($actor['published'])) {
try {
$createdAt = new \DateTimeImmutable($actor['published']);
$now = new \DateTimeImmutable();
if ($createdAt < $now) {
$magazine->createdAt = $createdAt;
}
} catch (\Exception) {
}
}

$magazine->apInboxUrl = $actor['endpoints']['sharedInbox'] ?? $actor['inbox'];
$magazine->apDomain = parse_url($actor['id'], PHP_URL_HOST);
$magazine->apFollowersUrl = $actor['followers'] ?? null;
Expand Down
9 changes: 9 additions & 0 deletions src/Service/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Repository\SettingsRepository;
use Doctrine\ORM\EntityManagerInterface;
use JetBrains\PhpStorm\Pure;
use Symfony\Component\HttpFoundation\RequestStack;

class SettingsManager
{
Expand All @@ -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,
Expand Down Expand Up @@ -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');
}
}
1 change: 1 addition & 0 deletions src/Twig/Extension/SettingsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
}
}
5 changes: 5 additions & 0 deletions src/Twig/Runtime/SettingsExtensionRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public function mbinSsoShowFirst(): bool
{
return $this->settings->get('MBIN_SSO_SHOW_FIRST');
}

public function mbinLang(): string
{
return $this->settings->getLocale();
}
}
10 changes: 7 additions & 3 deletions templates/user/_info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{% endif %}
<ul class="info">
<li>{{ 'joined'|trans }}: {{ component('date', {date: user.createdAt}) }}</li>
<li>{{ 'cake_day'|trans }}: <span><i class="fa-solid fa-cake" style="margin-right: .5em"></i>{{ user.createdAt|format_date('short', '', null, 'gregorian', mbin_lang()) }}</span></li>
{% if app.user is defined and app.user is not null and app.user.admin() and user.apId is not null %}
<li>
{{ 'last_updated'|trans }}: {{ component('date', {date: user.apFetchedAt}) }}
Expand All @@ -30,9 +31,12 @@
class="stretched-link">{{ 'moderated'|trans }}:</a> {{ count_user_moderated(user) }}
</li>
{% if app.user is not same as user %}
<li><a href="{{ path('messages_create', {username: user.username}) }}"
class="stretched-link">{{ 'send_message'|trans }}</a> <i
class="fa-solid fa-envelope" aria-hidden="true"></i></li>
<li>
<a href="{{ path('messages_create', {username: user.username}) }}" class="stretched-link">
{{ 'send_message'|trans }}
</a>
<i class="fa-solid fa-envelope" aria-hidden="true"></i>
</li>
{% endif %}
</ul>
</section>
4 changes: 4 additions & 0 deletions templates/user/_user_popover.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
</p>
<ul>
<li>{{ 'joined'|trans }}: {{ component('date', {date: user.createdAt}) }}</li>
<li>
<i class="fa-solid fa-cake" style="margin-right: .5em;"></i>
<span>{{ user.createdAt|format_date('short', '', null, 'gregorian', mbin_lang()) }}</span>
</li>
<li>
{%- set TYPE_ENTRY = constant('App\\Repository\\ReputationRepository::TYPE_ENTRY') -%}
<a href="{{ path('user_reputation', {username: user.username, reputationType: TYPE_ENTRY}) }}">
Expand Down
1 change: 1 addition & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,7 @@ related_entry: Related
restrict_magazine_creation: Restrict local magazine creation to admins and global mods
sso_show_first: Show SSO first on login and registration pages
continue_with: Continue with
cake_day: Cake day
someone: Someone
magazine_log_mod_added: has added a moderator
magazine_log_mod_removed: has removed a moderator
Expand Down

0 comments on commit 88800b1

Please sign in to comment.