mémorisation catégorie par cookie, URLs propres /categorie/

This commit is contained in:
Cedric Abonnel
2026-05-12 20:11:29 +02:00
parent 6e438835f8
commit 8f0fe0dbff
3 changed files with 49 additions and 16 deletions
+23 -1
View File
@@ -1770,7 +1770,29 @@ switch ($action) {
default:
$privateCats = $articles->getPrivateCategories();
$allCats = $articles->getCategories();
$filterCat = trim($_GET['cat'] ?? '');
if (array_key_exists('cat', $_GET)) {
$filterCat = trim($_GET['cat']);
if ($filterCat === '') {
// Réinitialisation explicite → effacer le cookie et rediriger
setcookie('varlog_cat', '', time() - 3600, '/', '', $isHttps, true);
header('Location: /', true, 302);
exit;
}
// Sauvegarder la catégorie choisie (1 an)
setcookie('varlog_cat', $filterCat, time() + 365 * 24 * 3600, '/', '', $isHttps, true);
} else {
// Pas de paramètre → appliquer le cookie si la catégorie existe toujours
$savedCat = trim($_COOKIE['varlog_cat'] ?? '');
if ($savedCat !== '' && isset($allCats[$savedCat])) {
header('Location: /categorie/' . rawurlencode($savedCat), true, 302);
exit;
}
if ($savedCat !== '' && !isset($allCats[$savedCat])) {
setcookie('varlog_cat', '', time() - 3600, '/', '', $isHttps, true);
}
$filterCat = '';
}
$allPosts = array_values(array_filter($articles->getAll(), static function (array $a) use ($privateCats, $filterCat): bool {
if (!$a['published']) {
return canDoOnArticle('view_drafts', $a);