feat : FOLIO_REPO_URL et APP_TIMEZONE configurables depuis admin #67

Merged
cedricAbonnel merged 4 commits from feat/folio-repo-url-admin-config into main 2026-05-15 07:52:18 +00:00
4 changed files with 64 additions and 5 deletions
Showing only changes of commit 4b5943c0a4 - Show all commits
+15 -1
View File
@@ -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&notice=' . ($ok ? 'folio_saved' : 'folio_error'));
exit;
case 'admin_save_site':
requireAuth();
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
+19 -1
View File
@@ -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<array{label:string,patterns:list<string>}> */
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]);
+2 -2
View File
@@ -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
+28 -1
View File
@@ -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
</div>
</div>
<?php if (($_GET['notice'] ?? '') === 'folio_saved'): ?>
<div class="alert alert-success py-2 mb-3 small">Configuration Folio enregistrée.</div>
<?php elseif (($_GET['notice'] ?? '') === 'folio_error'): ?>
<div class="alert alert-danger py-2 mb-3 small">Impossible d'enregistrer.</div>
<?php endif; ?>
<div class="card mb-4" style="max-width:540px">
<div class="card-header bg-transparent py-2 small fw-semibold">Configuration des mises à jour</div>
<div class="card-body">
<form method="POST" action="/?action=admin_save_folio_config">
<div class="mb-3">
<label class="form-label small fw-semibold mb-1">URL du dépôt Folio</label>
<input type="url" name="folio_repo_url" class="form-control form-control-sm font-monospace"
placeholder="https://git.abonnel.fr/cedricAbonnel/folio"
value="<?= htmlspecialchars(folioRepoUrl()) ?>">
<div class="form-text">Sans slash final. Laissez vide pour utiliser <code>FOLIO_REPO_URL</code> du .env.</div>
</div>
<div class="mb-3">
<label class="form-label small fw-semibold mb-1">Branche suivie</label>
<input type="text" name="folio_update_branch" class="form-control form-control-sm font-monospace"
placeholder="main"
value="<?= htmlspecialchars(folioUpdateBranch()) ?>">
</div>
<button type="submit" class="btn btn-primary btn-sm">Enregistrer</button>
</form>
</div>
</div>
<h5>Activité récente</h5>
<table class="table table-sm table-hover">
<thead>