mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
- Remove easymde.min.js (320KB) and easymde.min.css (13KB) - Vendor overtype.min.js (118KB, v2.3.5) - Replace <textarea name=content> + 60-line toolbar/SVG init with: - <input type=hidden name=content> for form submission - <div id=editor> as OverType mount target - 6-line init: value from hidden input, onChange syncs it back - Net saving: ~215KB assets, ~54 lines of inline JS
67 lines
2.1 KiB
PHP
67 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) ?>">
|
|
|
|
<div>
|
|
<label for="editor">Contenu (Markdown) :</label>
|
|
<input type="hidden" id="content" name="content"
|
|
value="<?= htmlspecialchars($page['content'] ?? '') ?>">
|
|
<div id="editor"></div>
|
|
</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'; ?>
|