add form help blocks: DB table, admin editor, live rendering in partage form

This commit is contained in:
Pontoporeia
2026-04-29 21:08:09 +02:00
parent 0437ec8d15
commit 670a38f30d
7 changed files with 136 additions and 29 deletions

View File

@@ -0,0 +1,39 @@
<?php
/**
* Save handler for static page content (Markdown).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
if (!isset($_POST['csrf_token'], $_SESSION['csrf_token'])
|| !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
App::flash('error', 'Erreur de sécurité : token invalide.');
header('Location: /admin/contenus.php');
exit;
}
$allowedSlugs = ['about', 'licenses', 'charte'];
$slug = $_POST['slug'] ?? '';
$content = $_POST['content'] ?? '';
if (!in_array($slug, $allowedSlugs, true)) {
App::flash('error', 'Slug de page invalide.');
header('Location: /admin/contenus.php');
exit;
}
require_once APP_ROOT . '/src/Database.php';
$db = new Database();
try {
$db->savePage($slug, $content);
App::flash('success', 'Page « ' . htmlspecialchars($slug) . ' » mise à jour.');
} catch (Exception $e) {
error_log('page save error: ' . $e->getMessage());
App::flash('error', 'Erreur lors de la sauvegarde : ' . htmlspecialchars($e->getMessage()));
}
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
header('Location: /admin/contenus.php');
exit;