From 9091a00a32a3762fb2898d77f6bb7de98b3a0cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Fri, 15 May 2026 00:02:54 +0200 Subject: [PATCH] =?UTF-8?q?fix=20:=20saveSiteSettings=20et=20saveSmtpSetti?= =?UTF-8?q?ngs=20retournent=20bool,=20erreur=20affich=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit file_put_contents() échouait silencieusement (permissions), provoquant un saved=1 trompeur. Les deux fonctions retournent maintenant bool ; les callers redirigent vers ?error=write et le template affiche un message d'erreur explicite. Co-Authored-By: Claude Sonnet 4.6 --- public/index.php | 9 +++++---- src/SiteSettings.php | 6 +++--- src/SmtpSettings.php | 6 +++--- templates/admin.php | 8 ++++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/public/index.php b/public/index.php index 1a0bdcf..b9f361f 100644 --- a/public/index.php +++ b/public/index.php @@ -2293,6 +2293,7 @@ switch ($action) { $tab = $_GET['tab'] ?? (isAdmin() ? 'dashboard' : 'articles'); $adminData = []; $siteSettingsSaved = isset($_GET['saved']); + $siteSettingsError = ($_GET['error'] ?? '') === 'write'; if ($tab === 'dashboard') { if (!isAdmin()) { @@ -2549,7 +2550,7 @@ switch ($action) { } require_once BASE_PATH . '/src/SmtpSettings.php'; - saveSmtpSettings([ + $ok = saveSmtpSettings([ 'host' => $_POST['smtp_host'] ?? '', 'port' => $_POST['smtp_port'] ?? '', 'secure' => $_POST['smtp_secure'] ?? '', @@ -2558,7 +2559,7 @@ switch ($action) { 'from' => $_POST['smtp_from'] ?? '', 'from_name' => $_POST['smtp_from_name'] ?? '', ]); - header('Location: /admin/smtp?saved=1'); + header('Location: /admin/smtp?' . ($ok ? 'saved=1' : 'error=write')); exit; case 'admin_smtp_test': @@ -2774,7 +2775,7 @@ switch ($action) { http_response_code(403); exit; } - saveSiteSettings([ + $ok = saveSiteSettings([ 'site_title' => $_POST['site_title'] ?? '', 'site_claim' => $_POST['site_claim'] ?? '', 'site_lang' => $_POST['site_lang'] ?? '', @@ -2782,7 +2783,7 @@ switch ($action) { 'site_license_label' => $_POST['site_license_label'] ?? '', 'site_license_url' => $_POST['site_license_url'] ?? '', ]); - header('Location: /admin/site?saved=1'); + header('Location: /admin/site?' . ($ok ? 'saved=1' : 'error=write')); exit; case 'admin_create_role': diff --git a/src/SiteSettings.php b/src/SiteSettings.php index 6c4bbc1..c0570cd 100644 --- a/src/SiteSettings.php +++ b/src/SiteSettings.php @@ -59,7 +59,7 @@ function siteLicenseUrl(): string return siteSettings()['site_license_url'] ?? 'https://creativecommons.org/licenses/by/4.0/'; } -function saveSiteSettings(array $data): void +function saveSiteSettings(array $data): bool { $current = siteSettings(); $stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url']; @@ -77,8 +77,8 @@ function saveSiteSettings(array $data): void $current['posts_per_page'] = $val; } } - file_put_contents( + return file_put_contents( siteSettingsPath(), json_encode($current, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) - ); + ) !== false; } diff --git a/src/SmtpSettings.php b/src/SmtpSettings.php index a054959..a4b0765 100644 --- a/src/SmtpSettings.php +++ b/src/SmtpSettings.php @@ -35,7 +35,7 @@ function smtpCfg(string $key, string $envKey, string $default = ''): string return ($v !== false && $v !== '') ? (string)$v : $default; } -function saveSmtpSettings(array $data): void +function saveSmtpSettings(array $data): bool { $current = smtpSettings(); foreach (['host', 'port', 'secure', 'user', 'from', 'from_name'] as $key) { @@ -46,8 +46,8 @@ function saveSmtpSettings(array $data): void if (!empty($data['pass']) && trim((string)$data['pass']) !== '') { $current['pass'] = trim((string)$data['pass']); } - file_put_contents( + return file_put_contents( smtpSettingsPath(), json_encode($current, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) - ); + ) !== false; } diff --git a/templates/admin.php b/templates/admin.php index 67716ae..a2b850f 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -94,11 +94,11 @@ function adminStatusBadge(array $a, int $now): string adminNotices() : []; $_remoteLabel = '—'; foreach ($_notices as $_n) { - if ($_n['type'] === 'info' && preg_match('/publiée le ([^)]+)/', $_n['message'], $_m)) { + if ($_n['type'] === 'info' && preg_match('/v([\d]+\.[\d]+\.[\d]+)/', $_n['message'], $_m)) { $_remoteLabel = $_m[1]; } } @@ -464,6 +464,8 @@ function adminStatusBadge(array $a, int $now): string
Paramètres enregistrés.
+ +
Impossible d'enregistrer : le fichier n'est pas accessible en écriture.
@@ -676,6 +678,8 @@ foreach (COLOR_PALETTE_16 as $_i => $_rgb):
Paramètres SMTP enregistrés.
+ +
Impossible d'enregistrer : le fichier n'est pas accessible en écriture.