feat(ext-blog): Add timezone support for blog publication dates and search

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.
This commit is contained in:
2026-12-02 12:08:45 +01:00
parent 8ebed89e73
commit 58e05e88ae
8 changed files with 56 additions and 37 deletions
@@ -5,6 +5,7 @@ use Plugi\Extensions\Blog\PostsRepository;
use Plugi\Repositories\UploadRepository;
$postsRepository = new PostsRepository();
$timezone = new \DateTimeZone((string) (phpb_config('general.timezone') ?: 'UTC'));
$post = [
'title' => '',
'slug' => '',
@@ -19,7 +20,7 @@ if (isset($_GET['id']) && ctype_digit((string) $_GET['id'])) {
$post = $postsRepository->findWithId($_GET['id']) ?? $post;
}
$isEditing = isset($post['id']);
$publishedAt = $post['published_at'] ? date('Y-m-d\TH:i', strtotime($post['published_at'])) : '';
$publishedAt = $post['published_at'] ? (new \DateTimeImmutable($post['published_at'], $timezone))->format('Y-m-d\TH:i') : '';
$categories = (new CategoriesRepository())->getAllForAdmin();
$imageUploads = array_values(array_filter((new UploadRepository())->getAll(), static fn($file): bool => is_string($file->mime_type ?? null) && str_starts_with(strtolower($file->mime_type), 'image/')));
?>
@@ -147,7 +148,7 @@ $imageUploads = array_values(array_filter((new UploadRepository())->getAll(), st
<div>
<label for="post-published-at" class="label"><span class="label-text font-medium">Publication date</span></label>
<input id="post-published-at" type="datetime-local" name="published_at" value="<?= phpb_e($publishedAt) ?>" class="input w-full" aria-describedby="post-published-at-help">
<p id="post-published-at-help" class="mt-1 text-sm text-base-content/60">Leave blank to use the current time when publishing. Future dates are not supported.</p>
<p id="post-published-at-help" class="mt-1 text-sm text-base-content/60">Times use the site timezone (<?= phpb_e($timezone->getName()) ?>). Leave blank to use the current time when publishing. Future dates are not supported.</p>
</div>
</div>
</section>
@@ -73,7 +73,7 @@ foreach ($categories as $category) {
<th>Title</th>
<th>Category</th>
<th>Status</th>
<th>Published</th>
<th>Published (site time)</th>
<th class="w-40 text-right">Actions</th>
</tr>
</thead>