feat: remplacer les étoiles par les réactions dans le hero article
This commit is contained in:
@@ -18,32 +18,6 @@ $_csrfToken = bin2hex(random_bytes(16));
|
||||
$_SESSION['comment_csrf'] = $_csrfToken;
|
||||
?>
|
||||
|
||||
<!-- ── Réactions ──────────────────────────────────────────────────── -->
|
||||
<div class="card mb-4" id="reactions">
|
||||
<div class="card-body">
|
||||
<h6 class="card-title mb-3 text-muted text-uppercase" style="font-size:.75rem;letter-spacing:.06em">Réactions</h6>
|
||||
<div class="d-flex gap-2 flex-wrap" id="reaction-buttons">
|
||||
<?php foreach ($_reactionDefs as $type => [$icon, $label]): ?>
|
||||
<?php $active = in_array($type, $visitorReactions, true); ?>
|
||||
<form method="post" action="/react" class="reaction-form d-inline">
|
||||
<input type="hidden" name="uuid" value="<?= htmlspecialchars($article['uuid']) ?>">
|
||||
<input type="hidden" name="type" value="<?= htmlspecialchars($type) ?>">
|
||||
<input type="hidden" name="_back" value="/post/<?= rawurlencode($article['slug'] ?? '') ?>#reactions">
|
||||
<button type="submit"
|
||||
class="btn btn-sm <?= $active ? 'btn-primary' : 'btn-outline-secondary' ?> reaction-btn"
|
||||
data-type="<?= htmlspecialchars($type) ?>"
|
||||
data-uuid="<?= htmlspecialchars($article['uuid']) ?>">
|
||||
<span class="reaction-icon"><?= $icon ?></span>
|
||||
<span class="reaction-label"><?= htmlspecialchars($label) ?></span>
|
||||
<span class="badge <?= $active ? 'bg-light text-primary' : 'bg-secondary' ?> ms-1 reaction-count"
|
||||
data-type="<?= htmlspecialchars($type) ?>"><?= (int)($reactionStats[$type] ?? 0) ?></span>
|
||||
</button>
|
||||
</form>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($alsoReadArticles ?? [])): ?>
|
||||
<!-- ── À lire aussi ──────────────────────────────────────────────── -->
|
||||
<div class="also-read mb-4" id="also-read">
|
||||
|
||||
+23
-28
@@ -127,30 +127,31 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
<?php if ($hasSources): ?>
|
||||
<a href="/sources/<?= rawurlencode($article['uuid']) ?>" class="hero-btn">ℹ Sources</a>
|
||||
<?php endif; ?>
|
||||
<?php if (function_exists('isLoggedIn') && isLoggedIn()): ?>
|
||||
<form method="post" action="/?action=rate" class="d-flex align-items-center gap-2">
|
||||
<?php
|
||||
$_heroReactionDefs = [
|
||||
'useful' => ['👍', 'Utile'],
|
||||
'important' => ['🔥', 'Important'],
|
||||
'interesting' => ['🤔', 'À creuser'],
|
||||
];
|
||||
?>
|
||||
<div class="hero-reactions" id="reactions">
|
||||
<?php foreach ($_heroReactionDefs as $type => [$icon, $label]): ?>
|
||||
<?php $active = in_array($type, $visitorReactions ?? [], true); ?>
|
||||
<form method="post" action="/react" class="reaction-form d-inline">
|
||||
<input type="hidden" name="uuid" value="<?= htmlspecialchars($article['uuid']) ?>">
|
||||
<?php if ($ratingStats['count'] > 0): ?>
|
||||
<span class="hero-rating-score">
|
||||
<?= number_format((float)($ratingStats['avg'] ?? 0), 1) ?> <span style="opacity:.6">/ 5</span>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<div class="star-rating star-rating--hero">
|
||||
<?php for ($s = 5; $s >= 1; $s--): ?>
|
||||
<input type="radio" id="star<?= $s ?>-<?= $article['uuid'] ?>"
|
||||
name="rating" value="<?= $s ?>"
|
||||
<?= (int)($userRating ?? 0) === $s ? 'checked' : '' ?>
|
||||
onchange="this.form.submit()">
|
||||
<label for="star<?= $s ?>-<?= $article['uuid'] ?>" title="<?= $s ?>★">★</label>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<input type="hidden" name="type" value="<?= htmlspecialchars($type) ?>">
|
||||
<input type="hidden" name="_back" value="/post/<?= rawurlencode($article['slug'] ?? '') ?>#reactions">
|
||||
<button type="submit"
|
||||
class="hero-reaction-btn<?= $active ? ' hero-reaction-btn--active' : '' ?> reaction-btn"
|
||||
data-type="<?= htmlspecialchars($type) ?>"
|
||||
data-uuid="<?= htmlspecialchars($article['uuid']) ?>"
|
||||
title="<?= htmlspecialchars($label) ?>">
|
||||
<span><?= $icon ?></span>
|
||||
<span class="reaction-count" data-type="<?= htmlspecialchars($type) ?>"><?= (int)($reactionStats[$type] ?? 0) ?></span>
|
||||
</button>
|
||||
</form>
|
||||
<?php elseif ($ratingStats['count'] > 0): ?>
|
||||
<span class="hero-rating-score">
|
||||
★ <?= number_format((float)($ratingStats['avg'] ?? 0), 1) ?>
|
||||
<span style="opacity:.6">(<?= $ratingStats['count'] ?>)</span>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -163,12 +164,6 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!isLoggedIn() && $ratingStats['count'] > 0): ?>
|
||||
<p class="text-muted small mt-3">
|
||||
Note : <?= number_format((float)($ratingStats['avg'] ?? 0), 1) ?>/5
|
||||
— <a href="/login">Connectez-vous</a> pour noter.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include __DIR__ . '/comments_section.php'; ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user