mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 11:39:18 +02:00
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
require_once __DIR__ . "/../../config/bootstrap.php";
|
|
require_once __DIR__ . "/../../src/AdminAuth.php";
|
|
AdminAuth::requireLogin();
|
|
|
|
if (empty($_SESSION["csrf_token"])) {
|
|
$_SESSION["csrf_token"] = bin2hex(random_bytes(32));
|
|
}
|
|
|
|
require_once __DIR__ . "/../../src/Database.php";
|
|
|
|
$allowedSlugs = ["about", "licenses", "charte", "contact"];
|
|
$slug = $_GET["slug"] ?? "";
|
|
|
|
if (!in_array($slug, $allowedSlugs)) {
|
|
header("Location: /admin/pages.php");
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$db = new Database();
|
|
$page = $db->getPage($slug);
|
|
if (!$page) {
|
|
die("Page introuvable.");
|
|
}
|
|
} catch (Exception $e) {
|
|
die("Erreur: " . htmlspecialchars($e->getMessage()));
|
|
}
|
|
|
|
$pageTitle = "Éditer : " . htmlspecialchars($page["title"]);
|
|
$extraJs = ["/assets/js/overtype.min.js"];
|
|
$extraJsInline = <<<'JS'
|
|
var OT = window.OverType.default || window.OverType;
|
|
var hidden = document.getElementById('content');
|
|
var editor = new OT(document.getElementById('editor'), {
|
|
value: hidden.value,
|
|
minHeight: '400px',
|
|
spellcheck: false,
|
|
onChange: function(value) { hidden.value = value; }
|
|
});
|
|
JS;
|
|
?>
|
|
<?php
|
|
$isAdmin = true;
|
|
$bodyClass = "admin-body";
|
|
require_once APP_ROOT . "/templates/head.php";
|
|
?>
|
|
<?php include APP_ROOT . "/templates/header.php"; ?>
|
|
|
|
<main id="main-content">
|
|
<h1>Éditer : <?= htmlspecialchars($page["title"]) ?></h1>
|
|
|
|
<form action="/admin/actions/page.php" method="post" class="admin-form">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars(
|
|
$_SESSION["csrf_token"],
|
|
) ?>">
|
|
<input type="hidden" name="slug" value="<?= htmlspecialchars($slug) ?>">
|
|
|
|
<label for="editor">Contenu (Markdown) :</label>
|
|
<input type="hidden" id="content" name="content"
|
|
value="<?= htmlspecialchars($page["content"] ?? "") ?>">
|
|
<div id="editor"></div>
|
|
|
|
<div class="admin-form-footer">
|
|
<button type="submit" class="admin-btn">Enregistrer</button>
|
|
<a href="/admin/pages.php" class="admin-btn-secondary admin-cancel-link">Annuler</a>
|
|
</div>
|
|
</form>
|
|
</main>
|
|
<?php require_once APP_ROOT . "/templates/admin/footer.php"; ?>
|