From 4b5943c0a4b19eca886180a74d1f14d11a36fd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Fri, 15 May 2026 09:44:52 +0200 Subject: [PATCH] feat : FOLIO_REPO_URL et branche configurables depuis l'admin (dashboard) Co-Authored-By: Claude Sonnet 4.6 --- public/index.php | 16 +++++++++++++++- src/SiteSettings.php | 20 +++++++++++++++++++- src/UpdateChecker.php | 4 ++-- templates/admin.php | 29 ++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/public/index.php b/public/index.php index 4b2b797..168437d 100644 --- a/public/index.php +++ b/public/index.php @@ -45,7 +45,7 @@ $action = $_GET['action'] ?? 'list'; $uuid = $_GET['uuid'] ?? ''; $slug = $_GET['slug'] ?? ''; -$_noindexActions = ['create', 'edit', 'admin', 'categories', 'diff', 'add_files', 'import_image', 'import_image_step2', 'sources', 'profile', 'delete_file', 'delete_external_link', 'rename_category', 'delete_category', 'toggle_private_category', 'admin_save_site', 'not_found', 'add_feed', 'delete_feed', 'add_link', 'delete_link', 'reorder_links', 'react', 'comment', 'verify_comment', 'comment_moderate', 'comment_delete', 'comment_resend', 'create_tag_type', 'delete_tag_type', 'edit_tags', 'book_save', 'book_delete', 'admin_save_as_groups']; +$_noindexActions = ['create', 'edit', 'admin', 'categories', 'diff', 'add_files', 'import_image', 'import_image_step2', 'sources', 'profile', 'delete_file', 'delete_external_link', 'rename_category', 'delete_category', 'toggle_private_category', 'admin_save_site', 'not_found', 'add_feed', 'delete_feed', 'add_link', 'delete_link', 'reorder_links', 'react', 'comment', 'verify_comment', 'comment_moderate', 'comment_delete', 'comment_resend', 'create_tag_type', 'delete_tag_type', 'edit_tags', 'book_save', 'book_delete', 'admin_save_as_groups', 'admin_save_folio_config']; $metaRobots = in_array($action, $_noindexActions, true) ? 'noindex, nofollow' : null; unset($_noindexActions); @@ -2826,6 +2826,20 @@ switch ($action) { header('Location: /admin?tab=dashboard'); exit; + case 'admin_save_folio_config': + requireAuth(); + if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') { + http_response_code(403); + exit; + } + $ok = saveSiteSettings([ + 'folio_repo_url' => $_POST['folio_repo_url'] ?? '', + 'folio_update_branch' => $_POST['folio_update_branch'] ?? '', + ]); + $_updateChecker->clearCache(); + header('Location: /admin?tab=dashboard¬ice=' . ($ok ? 'folio_saved' : 'folio_error')); + exit; + case 'admin_save_site': requireAuth(); if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') { diff --git a/src/SiteSettings.php b/src/SiteSettings.php index 37d187b..ad6d270 100644 --- a/src/SiteSettings.php +++ b/src/SiteSettings.php @@ -68,6 +68,24 @@ function apacheAccessLog(): string return (string)($_ENV['APACHE_ACCESS_LOG'] ?? getenv('APACHE_ACCESS_LOG') ?: '*-access.log'); } +function folioRepoUrl(): string +{ + $fromSettings = siteSettings()['folio_repo_url'] ?? ''; + if ($fromSettings !== '') { + return rtrim($fromSettings, '/'); + } + return rtrim((string)($_ENV['FOLIO_REPO_URL'] ?? getenv('FOLIO_REPO_URL') ?: ''), '/'); +} + +function folioUpdateBranch(): string +{ + $fromSettings = siteSettings()['folio_update_branch'] ?? ''; + if ($fromSettings !== '') { + return $fromSettings; + } + return (string)($_ENV['FOLIO_UPDATE_BRANCH'] ?? getenv('FOLIO_UPDATE_BRANCH') ?: 'main'); +} + /** @return list}> */ function asGroups(): array { @@ -78,7 +96,7 @@ function asGroups(): array function saveSiteSettings(array $data): bool { $current = siteSettings(); - $stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url', 'apache_access_log']; + $stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url', 'apache_access_log', 'folio_repo_url', 'folio_update_branch']; foreach ($stringKeys as $key) { if (array_key_exists($key, $data)) { $val = trim((string)$data[$key]); diff --git a/src/UpdateChecker.php b/src/UpdateChecker.php index 3962b4b..cad72e4 100644 --- a/src/UpdateChecker.php +++ b/src/UpdateChecker.php @@ -67,7 +67,7 @@ class UpdateChecker */ private function checkRemoteVersion(): ?string { - $repoUrl = rtrim((string) ($_ENV['FOLIO_REPO_URL'] ?? getenv('FOLIO_REPO_URL') ?: ''), '/'); + $repoUrl = folioRepoUrl(); if ($repoUrl === '') { return null; } @@ -91,7 +91,7 @@ class UpdateChecker public function getBranch(): string { - return (string) ($_ENV['FOLIO_UPDATE_BRANCH'] ?? getenv('FOLIO_UPDATE_BRANCH') ?: 'main'); + return folioUpdateBranch(); } public function getLastChecked(): ?int diff --git a/templates/admin.php b/templates/admin.php index f67f3be..8237bd4 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -106,7 +106,7 @@ function adminStatusBadge(array $a, int $now): string $_notices = isset($_updateChecker) ? $_updateChecker->adminNotices() : []; $_branch = isset($_updateChecker) ? $_updateChecker->getBranch() : 'main'; $_lastChecked = isset($_updateChecker) ? $_updateChecker->getLastChecked() : null; - $_repoConfigured = (($_ENV['FOLIO_REPO_URL'] ?? getenv('FOLIO_REPO_URL') ?: '') !== ''); + $_repoConfigured = folioRepoUrl() !== ''; $_remoteLabel = '—'; foreach ($_notices as $_n) { if ($_n['type'] === 'info' && preg_match('/v([\d]+\.[\d]+\.[\d]+)/', $_n['message'], $_m)) { @@ -164,6 +164,33 @@ function adminStatusBadge(array $a, int $now): string + +
Configuration Folio enregistrée.
+ +
Impossible d'enregistrer.
+ +
+
Configuration des mises à jour
+
+
+
+ + +
Sans slash final. Laissez vide pour utiliser FOLIO_REPO_URL du .env.
+
+
+ + +
+ +
+
+
+
Activité récente