mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 08:09:18 +02:00
- Remove overtype-webcomponent.min.js (zero references) - Extract copyLogContent + fallbackCopy + HTMX tab-updater → app/admin-logs.js (removes duplicate from both system.php and parametres.php) - Extract copyUrl → app/clipboard.js (shared by acces.php) - Extract tag/language pill-search logic → app/pill-search.js Generalized with data-pill-search attributes, auto-inits via DOMContentLoaded + htmx:afterSwap - Extract access-request form handler → app/access-request.js (was inline in templates/public/tfe.php) Files created: admin-logs.js, clipboard.js, pill-search.js, access-request.js Files modified: 9 templates/controllers to drop inline scripts and reference external JS files
105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
|
require_once __DIR__ . "/../../bootstrap.php";
|
|
require_once __DIR__ . '/../../src/AdminAuth.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
require_once __DIR__ . '/../../src/Database.php';
|
|
|
|
if (empty($_SESSION["csrf_token"])) {
|
|
$_SESSION["csrf_token"] = bin2hex(random_bytes(32));
|
|
}
|
|
|
|
$allowedPageSlugs = ["about", "licenses"];
|
|
$allowedApropos = ["contacts"];
|
|
|
|
$pageSlug = $_GET["slug"] ?? "";
|
|
$aproposKey = $_GET["apropos"] ?? "";
|
|
$formHelpKey = $_GET["form_block"] ?? "";
|
|
|
|
if ($pageSlug && !in_array($pageSlug, $allowedPageSlugs)) {
|
|
$pageSlug = "";
|
|
}
|
|
if ($aproposKey && !in_array($aproposKey, $allowedApropos)) {
|
|
$aproposKey = "";
|
|
}
|
|
if ($formHelpKey && !in_array($formHelpKey, Database::FORM_HELP_KEYS, true)) {
|
|
$formHelpKey = "";
|
|
}
|
|
|
|
if (!$pageSlug && !$aproposKey && !$formHelpKey) {
|
|
header("Location: /admin/contenus.php");
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$db = new Database();
|
|
|
|
if ($pageSlug) {
|
|
$page = $db->getPage($pageSlug);
|
|
if (!$page) {
|
|
die("Page introuvable.");
|
|
}
|
|
$editTitle = $page["title"];
|
|
if ($pageSlug === 'about') {
|
|
$editType = 'about_page';
|
|
$aboutContacts = $db->getAproposContent('contacts');
|
|
$aboutContacts = is_array($aboutContacts) ? $aboutContacts : [];
|
|
} else {
|
|
$editType = "page";
|
|
}
|
|
} elseif ($formHelpKey) {
|
|
$editType = "form_help";
|
|
$formHelpContent = $db->getFormHelpBlock($formHelpKey);
|
|
$editTitle = $formHelpKey;
|
|
} else {
|
|
$editType = "apropos";
|
|
$value = $db->getAproposContent($aproposKey);
|
|
$editTitle = match($aproposKey) {
|
|
'contacts' => 'Contacts',
|
|
};
|
|
}
|
|
} catch (Exception $e) {
|
|
die("Erreur: " . htmlspecialchars($e->getMessage()));
|
|
}
|
|
|
|
$pageTitle = "Éditer : " . $editTitle;
|
|
|
|
$initialContent = '';
|
|
$extraJs = [];
|
|
$extraJsInline = '';
|
|
|
|
if ($editType === 'page' || $editType === 'about_page') {
|
|
$initialContent = $page["content"] ?? "";
|
|
$extraJs = ["/assets/js/vendor/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;
|
|
} elseif ($editType === 'form_help') {
|
|
$initialContent = $formHelpContent;
|
|
$extraJs = ["/assets/js/vendor/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;
|
|
}
|
|
|
|
$isAdmin = true;
|
|
$bodyClass = "admin-body";
|
|
require_once APP_ROOT . "/templates/head.php";
|
|
include APP_ROOT . "/templates/header.php";
|
|
include APP_ROOT . '/templates/admin/contenus-edit.php';
|
|
require_once APP_ROOT . "/templates/admin/footer.php";
|