8cab6362a3
- AccessLogParser : parse COMBINED, agrège hits /post/ et /book/, cache 10 min - AsnLookup : batch lookup ip-api.com, cache 30j, agrégation et groupes AS - Onglet Statistiques dans l'admin : top pages, top livres, répartition réseau - Filtrage par groupe AS (badges) + formulaire de configuration des groupes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
105 lines
2.5 KiB
PHP
105 lines
2.5 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');
|
|
}
|
|
|
|
/** @return list<array{label:string,patterns:list<string>}> */
|
|
function asGroups(): array
|
|
{
|
|
$raw = siteSettings()['as_groups'] ?? [];
|
|
return is_array($raw) ? $raw : [];
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
if (array_key_exists('as_groups', $data) && is_array($data['as_groups'])) {
|
|
$current['as_groups'] = $data['as_groups'];
|
|
}
|
|
|
|
return file_put_contents(
|
|
siteSettingsPath(),
|
|
json_encode($current, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
|
|
) !== false;
|
|
}
|