2026-04-12 08:00:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
|
|
2026-04-12 08:20:18 +02:00
|
|
|
function getContent(string $lang = 'fr'): array {
|
2026-04-12 08:00:58 +02:00
|
|
|
$cacheFile = CACHE_DIR . "/content.{$lang}.json";
|
|
|
|
|
|
|
|
|
|
// Serve cache if fresh
|
|
|
|
|
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < CACHE_TTL) {
|
|
|
|
|
return json_decode(file_get_contents($cacheFile), true) ?: [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch from Kirby API
|
|
|
|
|
$url = KIRBY_API_URL . '?lang=' . urlencode($lang);
|
2026-04-12 08:20:18 +02:00
|
|
|
if (SUPPORT_API_TOKEN) {
|
|
|
|
|
$url .= '&token=' . urlencode(SUPPORT_API_TOKEN);
|
2026-04-12 08:00:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context = stream_context_create([
|
|
|
|
|
'http' => [
|
|
|
|
|
'timeout' => 5,
|
|
|
|
|
'header' => "Referer: https://soutenir.index.ngo\r\n",
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = @file_get_contents($url, false, $context);
|
|
|
|
|
|
|
|
|
|
if ($response !== false) {
|
|
|
|
|
$data = json_decode($response, true);
|
|
|
|
|
if ($data && !isset($data['error'])) {
|
|
|
|
|
@file_put_contents($cacheFile, $response, LOCK_EX);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback: serve stale cache rather than nothing
|
|
|
|
|
if (file_exists($cacheFile)) {
|
|
|
|
|
return json_decode(file_get_contents($cacheFile), true) ?: [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
}
|