3bb83b3ffd
Balaye tous les fichiers correspondant au pattern (ex: *-access.log) et leurs rotations .gz/.tar.gz. Valeur par défaut : *-access.log. Label renommé en "Pattern des logs d'accès". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
94 lines
2.2 KiB
PHP
94 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
function siteSettingsPath(): string
|
|
{
|
|
return BASE_PATH . '/data/site_settings.json';
|
|
}
|
|
|
|
function siteSettings(): array
|
|
{
|
|
static $settings = null;
|
|
if ($settings !== null) {
|
|
return $settings;
|
|
}
|
|
$settings = [];
|
|
$path = siteSettingsPath();
|
|
if (is_file($path)) {
|
|
$data = @json_decode((string)file_get_contents($path), true);
|
|
if (is_array($data)) {
|
|
$settings = $data;
|
|
}
|
|
}
|
|
return $settings;
|
|
}
|
|
|
|
function siteTitle(): string
|
|
{
|
|
return siteSettings()['site_title'] ?? 'varlog';
|
|
}
|
|
|
|
function siteClaim(): string
|
|
{
|
|
return siteSettings()['site_claim'] ?? 'journal de Cédrix · informatique, hack & loisirs';
|
|
}
|
|
|
|
function siteLang(): string
|
|
{
|
|
return siteSettings()['site_lang'] ?? 'fr-FR';
|
|
}
|
|
|
|
function siteLangOgLocale(): string
|
|
{
|
|
return str_replace('-', '_', siteLang());
|
|
}
|
|
|
|
function postsPerPage(): int
|
|
{
|
|
return max(1, (int)(siteSettings()['posts_per_page'] ?? 12));
|
|
}
|
|
|
|
function siteLicenseLabel(): string
|
|
{
|
|
return siteSettings()['site_license_label'] ?? 'CC BY 4.0';
|
|
}
|
|
|
|
function siteLicenseUrl(): string
|
|
{
|
|
return siteSettings()['site_license_url'] ?? 'https://creativecommons.org/licenses/by/4.0/';
|
|
}
|
|
|
|
function apacheAccessLog(): string
|
|
{
|
|
$fromSettings = siteSettings()['apache_access_log'] ?? '';
|
|
if ($fromSettings !== '') {
|
|
return $fromSettings;
|
|
}
|
|
return (string)($_ENV['APACHE_ACCESS_LOG'] ?? getenv('APACHE_ACCESS_LOG') ?: '*-access.log');
|
|
}
|
|
|
|
function saveSiteSettings(array $data): bool
|
|
{
|
|
$current = siteSettings();
|
|
$stringKeys = ['site_title', 'site_claim', 'site_lang', 'site_license_label', 'site_license_url', 'apache_access_log'];
|
|
foreach ($stringKeys as $key) {
|
|
if (array_key_exists($key, $data)) {
|
|
$val = trim((string)$data[$key]);
|
|
if ($val !== '') {
|
|
$current[$key] = $val;
|
|
}
|
|
}
|
|
}
|
|
if (array_key_exists('posts_per_page', $data)) {
|
|
$val = (int)$data['posts_per_page'];
|
|
if ($val > 0) {
|
|
$current['posts_per_page'] = $val;
|
|
}
|
|
}
|
|
return file_put_contents(
|
|
siteSettingsPath(),
|
|
json_encode($current, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
|
|
) !== false;
|
|
}
|