82 lines
4.5 KiB
PHP
82 lines
4.5 KiB
PHP
<?php
|
|
|
|
use Plugi\Extensions\Blog\CategoriesRepository;
|
|
use Plugi\Extensions\Blog\PostsRepository;
|
|
|
|
$posts = (new PostsRepository())->getAllForAdmin();
|
|
$categories = (new CategoriesRepository())->getAllForAdmin();
|
|
$categoryNames = [];
|
|
foreach ($categories as $category) {
|
|
$categoryNames[$category['id']] = $category['name'];
|
|
}
|
|
?>
|
|
<section class="space-y-5">
|
|
<header class="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
|
|
<div class="space-y-1">
|
|
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-primary">Blog extension</p>
|
|
<h2 class="text-xl font-bold tracking-tight text-base-content">Posts</h2>
|
|
<p class="text-sm text-base-content/60"><?= count($posts) ?> post<?= count($posts) !== 1 ? 's' : '' ?></p>
|
|
</div>
|
|
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--blog', 'action' => 'editPost']) ?>" class="btn btn-primary">
|
|
<i class="ph-duotone ph-plus" aria-hidden="true"></i>
|
|
New post
|
|
</a>
|
|
</header>
|
|
|
|
<?php if (empty($posts)): ?>
|
|
<div class="card border border-dashed border-base-300 bg-base-100 shadow-sm" role="status">
|
|
<div class="card-body items-center gap-3 px-5 py-12 text-center sm:py-16">
|
|
<span class="grid size-14 place-items-center rounded-2xl bg-primary/10 text-primary">
|
|
<i class="text-3xl ph-duotone ph-article" aria-hidden="true"></i>
|
|
</span>
|
|
<h3 class="card-title mt-1 text-lg">No posts yet</h3>
|
|
<p class="max-w-md text-sm leading-relaxed text-base-content/60">Create a draft or publish your first article.</p>
|
|
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--blog', 'action' => 'editPost']) ?>" class="btn btn-primary mt-2">
|
|
<i class="ph-duotone ph-plus" aria-hidden="true"></i>
|
|
Create your first post
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="overflow-x-auto rounded-box border border-base-300 bg-base-100">
|
|
<table class="table table-zebra w-full min-w-[48rem]">
|
|
<thead>
|
|
<tr>
|
|
<th>Title</th>
|
|
<th>Category</th>
|
|
<th>Status</th>
|
|
<th>Published</th>
|
|
<th class="w-40 text-right">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($posts as $post): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="font-medium"><?= phpb_e($post['title']) ?></div>
|
|
<div class="text-xs text-base-content/60">/<?= phpb_e($post['slug']) ?></div>
|
|
</td>
|
|
<td><?= phpb_e($categoryNames[$post['category_id']] ?? '—') ?></td>
|
|
<td><span class="badge <?= $post['status'] === 'published' ? 'badge-success' : 'badge-warning' ?>"><?= phpb_e(ucfirst($post['status'])) ?></span></td>
|
|
<td><?= phpb_e($post['published_at'] ?? '—') ?></td>
|
|
<td>
|
|
<div class="flex items-center justify-end gap-1">
|
|
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--blog', 'action' => 'editPost', 'id' => $post['id']]) ?>" class="btn btn-ghost btn-square btn-sm" title="Edit post" aria-label="Edit <?= phpb_e($post['title']) ?>">
|
|
<i class="ph-duotone ph-pencil-line text-lg" aria-hidden="true"></i>
|
|
</a>
|
|
<form action="/ext--blog/delete-post" method="post" onsubmit="return confirm('Delete this post?')">
|
|
<?php phpb_csrf_field(); ?>
|
|
<input type="hidden" name="id" value="<?= phpb_e((string) $post['id']) ?>">
|
|
<button type="submit" class="btn btn-ghost btn-square btn-sm text-error" title="Delete post" aria-label="Delete <?= phpb_e($post['title']) ?>">
|
|
<i class="ph-duotone ph-trash text-lg" aria-hidden="true"></i>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</section>
|