mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Refactor about.php
- Hardcode source code URL and credits in about template, remove from DB/admin interface; only contacts remains editable - Merge apropos editables into one À propos section, remove charte, add editable source code URL
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Save handler for apropos contents (contacts, credits).
|
||||
* Structure: groups[] with label/role, each having entries[] of {text, url, email}.
|
||||
* Save handler for apropos contacts.
|
||||
* Structure: groups[] with role, each having entries[] of {text, url, email}.
|
||||
*/
|
||||
require_once __DIR__ . "/../../../bootstrap.php";
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
@@ -13,7 +13,7 @@ if (!isset($_POST['csrf_token']) || !isset($_SESSION['csrf_token']) ||
|
||||
die("Erreur de sécurité : token invalide.");
|
||||
}
|
||||
|
||||
$allowedKeys = ['contacts', 'credits'];
|
||||
$allowedKeys = ['contacts'];
|
||||
$aproposKey = $_POST['apropos_key'] ?? '';
|
||||
if (!in_array($aproposKey, $allowedKeys)) {
|
||||
die("Clé invalide.");
|
||||
@@ -28,38 +28,22 @@ try {
|
||||
$cleaned = [];
|
||||
|
||||
foreach ($groups as $group) {
|
||||
if ($aproposKey === 'credits') {
|
||||
$label = trim($group['label'] ?? '');
|
||||
if ($label === '') continue;
|
||||
$entries = [];
|
||||
foreach ($group['entries'] ?? [] as $entry) {
|
||||
$text = trim($entry['text'] ?? '');
|
||||
if ($text === '') continue;
|
||||
$e = ['text' => $text];
|
||||
$url = trim($entry['url'] ?? '');
|
||||
if ($url !== '') $e['url'] = $url;
|
||||
$entries[] = $e;
|
||||
}
|
||||
if (empty($entries)) continue;
|
||||
$cleaned[] = ['label' => $label, 'entries' => $entries];
|
||||
} else { // contacts
|
||||
$role = trim($group['role'] ?? '');
|
||||
if ($role === '') continue;
|
||||
$entries = [];
|
||||
foreach ($group['entries'] ?? [] as $entry) {
|
||||
$text = trim($entry['text'] ?? '');
|
||||
if ($text === '') continue;
|
||||
$e = [
|
||||
'text' => $text,
|
||||
'email' => trim($entry['email'] ?? ''),
|
||||
];
|
||||
$url = trim($entry['url'] ?? '');
|
||||
if ($url !== '') $e['url'] = $url;
|
||||
$entries[] = $e;
|
||||
}
|
||||
if (empty($entries)) continue;
|
||||
$cleaned[] = ['role' => $role, 'entries' => $entries];
|
||||
$role = trim($group['role'] ?? '');
|
||||
if ($role === '') continue;
|
||||
$entries = [];
|
||||
foreach ($group['entries'] ?? [] as $entry) {
|
||||
$text = trim($entry['text'] ?? '');
|
||||
if ($text === '') continue;
|
||||
$e = [
|
||||
'text' => $text,
|
||||
'email' => trim($entry['email'] ?? ''),
|
||||
];
|
||||
$url = trim($entry['url'] ?? '');
|
||||
if ($url !== '') $e['url'] = $url;
|
||||
$entries[] = $e;
|
||||
}
|
||||
if (empty($entries)) continue;
|
||||
$cleaned[] = ['role' => $role, 'entries' => $entries];
|
||||
}
|
||||
|
||||
if (empty($cleaned)) {
|
||||
|
||||
@@ -13,7 +13,7 @@ if (!isset($_POST['csrf_token'], $_SESSION['csrf_token'])
|
||||
exit;
|
||||
}
|
||||
|
||||
$allowedSlugs = ['about', 'licenses', 'charte'];
|
||||
$allowedSlugs = ['about', 'licenses'];
|
||||
$slug = $_POST['slug'] ?? '';
|
||||
$content = $_POST['content'] ?? '';
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ if (empty($_SESSION["csrf_token"])) {
|
||||
$_SESSION["csrf_token"] = bin2hex(random_bytes(32));
|
||||
}
|
||||
|
||||
$allowedPageSlugs = ["about", "licenses", "charte"];
|
||||
$allowedApropos = ["contacts", "credits"];
|
||||
$allowedPageSlugs = ["about", "licenses"];
|
||||
$allowedApropos = ["contacts"];
|
||||
|
||||
$pageSlug = $_GET["slug"] ?? "";
|
||||
$aproposKey = $_GET["apropos"] ?? "";
|
||||
@@ -40,7 +40,13 @@ try {
|
||||
die("Page introuvable.");
|
||||
}
|
||||
$editTitle = $page["title"];
|
||||
$editType = "page";
|
||||
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);
|
||||
@@ -50,7 +56,6 @@ try {
|
||||
$value = $db->getAproposContent($aproposKey);
|
||||
$editTitle = match($aproposKey) {
|
||||
'contacts' => 'Contacts',
|
||||
'credits' => 'Crédits',
|
||||
};
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
@@ -58,8 +63,15 @@ try {
|
||||
}
|
||||
|
||||
$pageTitle = "Éditer : " . $editTitle;
|
||||
$extraJs = ["/assets/js/overtype.min.js"];
|
||||
$extraJsInline = <<<'JS'
|
||||
|
||||
$initialContent = '';
|
||||
$extraJs = [];
|
||||
$extraJsInline = '';
|
||||
|
||||
if ($editType === 'page' || $editType === 'about_page') {
|
||||
$initialContent = $page["content"] ?? "";
|
||||
$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'), {
|
||||
@@ -69,12 +81,19 @@ var editor = new OT(document.getElementById('editor'), {
|
||||
onChange: function(value) { hidden.value = value; }
|
||||
});
|
||||
JS;
|
||||
|
||||
$initialContent = '';
|
||||
if ($editType === 'page') {
|
||||
$initialContent = $page["content"] ?? "";
|
||||
} elseif ($editType === 'form_help') {
|
||||
$initialContent = $formHelpContent;
|
||||
$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;
|
||||
}
|
||||
|
||||
$isAdmin = true;
|
||||
|
||||
@@ -10,9 +10,12 @@ if (empty($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
|
||||
$allowedPageSlugs = ['about', 'licenses'];
|
||||
|
||||
try {
|
||||
$db = new Database();
|
||||
$pages = $db->getAllPages();
|
||||
$allPages = $db->getAllPages();
|
||||
$pages = array_values(array_filter($allPages, fn($p) => in_array($p['slug'], $allowedPageSlugs, true)));
|
||||
$aproposKeys = $db->getAllAproposContents();
|
||||
$formHelpBlocks = $db->getAllFormHelpBlocks();
|
||||
} catch (Exception $e) {
|
||||
|
||||
@@ -89,6 +89,21 @@
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.apropos-toc-source {
|
||||
padding-top: var(--space-xs);
|
||||
}
|
||||
|
||||
.apropos-toc-source a {
|
||||
font-size: var(--step--2);
|
||||
color: var(--accent-primary);
|
||||
text-decoration: none;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
|
||||
.apropos-toc-source a:hover {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Right — main content area */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
Reference in New Issue
Block a user