Configure `general.timezone` in root config to control blog publication input and display. Update PostsRepository to validate dates against the site timezone and enforce a minimum search length for public queries. Modify admin views to display publication dates in the site's local timezone and update search labels. Add tests for the new timezone handling and search validation logic.
43 lines
2.4 KiB
PHP
43 lines
2.4 KiB
PHP
<?php
|
|
|
|
$slug = phpb_route_parameter('slug');
|
|
$timezone = new \DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
|
|
$post = is_string($slug) && $slug !== ''
|
|
? (new \Plugi\Extensions\Blog\PostsRepository())->findPublishedBySlug($slug)
|
|
: null;
|
|
?>
|
|
<?php if ($post === null): ?>
|
|
<section class="card border border-base-300 bg-base-100 shadow-sm" aria-labelledby="blog-post-not-found">
|
|
<div class="card-body">
|
|
<h1 id="blog-post-not-found" class="card-title">Article not found</h1>
|
|
<p class="text-base-content/70">This article is unavailable or may no longer be published.</p>
|
|
</div>
|
|
</section>
|
|
<?php else: ?>
|
|
<article class="mx-auto w-full max-w-3xl space-y-8">
|
|
<header class="space-y-4">
|
|
<div class="flex flex-wrap items-center gap-3 text-sm text-base-content/60">
|
|
<?php if (!empty($post['category_name'])): ?>
|
|
<span class="badge badge-outline"><?= phpb_e($post['category_name']) ?></span>
|
|
<?php endif; ?>
|
|
<?php if (!empty($post['published_at'])): ?>
|
|
<?php $publishedDate = date_create($post['published_at'], $timezone); ?>
|
|
<?php if ($publishedDate !== false): ?>
|
|
<time datetime="<?= phpb_e($publishedDate->format('c')) ?>"><?= phpb_e($publishedDate->format('F j, Y')) ?></time>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<h1 class="text-3xl font-bold tracking-tight text-base-content sm:text-4xl"><?= phpb_e($post['title']) ?></h1>
|
|
<?php if ($post['excerpt'] !== ''): ?>
|
|
<p class="text-lg leading-relaxed text-base-content/70"><?= phpb_e($post['excerpt']) ?></p>
|
|
<?php endif; ?>
|
|
</header>
|
|
<?php if (!empty($post['featured_image_url'])): ?>
|
|
<?php $featuredImageAlt = trim((string) ($post['featured_image_alt_text'] ?? '')) ?: $post['title']; ?>
|
|
<figure class="overflow-hidden rounded-box">
|
|
<img src="<?= phpb_e($post['featured_image_url']) ?>" alt="<?= phpb_e($featuredImageAlt) ?>" class="max-h-[32rem] w-full object-cover">
|
|
</figure>
|
|
<?php endif; ?>
|
|
<div class="space-y-4 text-base leading-7 text-base-content"><?= (new \Plugi\Extensions\Blog\PostContentRenderer())->render($post['body']) ?></div>
|
|
</article>
|
|
<?php endif; ?>
|