feat: avant-premiere - article visible en liste mais verrouille avant sa date de publication

This commit is contained in:
Cedric Abonnel
2026-05-08 22:55:27 +02:00
parent 201ae53e65
commit f7d80fc72e
3 changed files with 41 additions and 14 deletions
+6 -3
View File
@@ -207,14 +207,14 @@ a:hover {
border-color: var(--vl-border) !important; border-color: var(--vl-border) !important;
} }
/* ─── Ribbon brouillon ───────────────────── */ /* ─── Ribbons (brouillon / avant-première) ── */
.draft-ribbon { .draft-ribbon,
.premiere-ribbon {
position: absolute; position: absolute;
top: 26px; top: 26px;
right: -34px; right: -34px;
width: 130px; width: 130px;
text-align: center; text-align: center;
background: #f59e0b;
color: #fff; color: #fff;
font-size: 0.6rem; font-size: 0.6rem;
font-weight: 700; font-weight: 700;
@@ -227,6 +227,9 @@ a:hover {
box-shadow: 0 1px 3px rgba(0,0,0,.18); box-shadow: 0 1px 3px rgba(0,0,0,.18);
} }
.draft-ribbon { background: #f59e0b; }
.premiere-ribbon { background: #6366f1; }
/* ─── Buttons ─────────────────────────────── */ /* ─── Buttons ─────────────────────────────── */
.btn { .btn {
font-weight: 500; font-weight: 500;
+7
View File
@@ -80,6 +80,13 @@ switch ($action) {
} }
} }
// Avant-première : publié mais date future → contenu verrouillé
if ($article['published'] && strtotime((string)($article['published_at'] ?? '')) > time()) {
http_response_code(404);
echo 'Article introuvable.';
exit;
}
$files = $articles->getFiles($article['uuid']); $files = $articles->getFiles($article['uuid']);
// Résout les chemins de fichiers relatifs dans le contenu // Résout les chemins de fichiers relatifs dans le contenu
+18 -1
View File
@@ -21,29 +21,46 @@ ob_start();
$preview = mb_strimwidth(strip_tags($html), 0, 120, '…'); $preview = mb_strimwidth(strip_tags($html), 0, 120, '…');
$gradient = $coverGradients[$i % count($coverGradients)]; $gradient = $coverGradients[$i % count($coverGradients)];
$postUrl = '/post/' . rawurlencode($post['slug']); $postUrl = '/post/' . rawurlencode($post['slug']);
$isDraft = !$post['published'];
$isAvantPremiere = $post['published'] && strtotime((string)($post['published_at'] ?? '')) > time();
$isLocked = $isAvantPremiere;
?> ?>
<div class="col"> <div class="col">
<article class="card h-100"> <article class="card h-100">
<?php if (!$post['published']): ?> <?php if ($isDraft): ?>
<div class="draft-ribbon">Brouillon</div> <div class="draft-ribbon">Brouillon</div>
<?php elseif ($isAvantPremiere): ?>
<div class="premiere-ribbon">Avant-première</div>
<?php endif; ?> <?php endif; ?>
<div class="card-cover" style="background: <?= $gradient ?>"></div> <div class="card-cover" style="background: <?= $gradient ?>"></div>
<div class="card-body d-flex flex-column"> <div class="card-body d-flex flex-column">
<h2 class="card-title"> <h2 class="card-title">
<?php if ($isLocked): ?>
<?= htmlspecialchars($post['title']) ?>
<?php else: ?>
<a href="<?= htmlspecialchars($postUrl) ?>"> <a href="<?= htmlspecialchars($postUrl) ?>">
<?= htmlspecialchars($post['title']) ?> <?= htmlspecialchars($post['title']) ?>
</a> </a>
<?php endif; ?>
</h2> </h2>
<p class="card-text flex-grow-1"><?= htmlspecialchars($preview) ?></p> <p class="card-text flex-grow-1"><?= htmlspecialchars($preview) ?></p>
<div class="post-entry-meta mt-auto"> <div class="post-entry-meta mt-auto">
<?php if ($isAvantPremiere): ?>
<span class="text-muted">Disponible le <?= htmlspecialchars(date('d/m/Y \à H\hi', strtotime((string)($post['published_at'] ?? '')))) ?></span>
<?php else: ?>
<span><?= htmlspecialchars(date('d/m/Y', strtotime((string)($post['created_at'] ?? '')))) ?></span> <span><?= htmlspecialchars(date('d/m/Y', strtotime((string)($post['created_at'] ?? '')))) ?></span>
<?php endif; ?>
<?php if (function_exists('isAdmin') && isAdmin()): ?> <?php if (function_exists('isAdmin') && isAdmin()): ?>
<a href="/?action=edit&uuid=<?= htmlspecialchars($post['uuid']) ?>" class="post-entry-edit">modifier</a> <a href="/?action=edit&uuid=<?= htmlspecialchars($post['uuid']) ?>" class="post-entry-edit">modifier</a>
<?php endif; ?> <?php endif; ?>
<?php if (!$isLocked): ?>
<a href="<?= htmlspecialchars($postUrl) ?>" class="post-entry-read">→ lire</a> <a href="<?= htmlspecialchars($postUrl) ?>" class="post-entry-read">→ lire</a>
<?php endif; ?>
</div> </div>
</div> </div>
<?php if (!$isLocked): ?>
<a href="<?= htmlspecialchars($postUrl) ?>" class="stretched-link"></a> <a href="<?= htmlspecialchars($postUrl) ?>" class="stretched-link"></a>
<?php endif; ?>
</article> </article>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>