feat: titre et claim configurables depuis l'admin
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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 saveSiteSettings(array $data): void
|
||||
{
|
||||
$current = siteSettings();
|
||||
$allowed = ['site_title', 'site_claim'];
|
||||
foreach ($allowed as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$val = trim((string)$data[$key]);
|
||||
if ($val !== '') {
|
||||
$current[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
file_put_contents(
|
||||
siteSettingsPath(),
|
||||
json_encode($current, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user