PHP dynamique + cache JSON, nettoyage CSS/HTML, CI Forgejo
- Renommage classes/IDs (BEM cohérent, anglais, noms sémantiques) - Correction HTML : h3→h2 FAQ, button>a→a[role=button] CTA mobile - Conversion index.html → index.php (FR/EN) avec cache JSON depuis API Kirby - Pages merci/thanks converties en PHP dynamique - Ajout includes/cache.php + includes/config.php (cache TTL 5min) - Ajout CI Forgejo (deploy FTP via lftp) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
119c98edab
commit
322d9136b6
29 changed files with 917 additions and 1485 deletions
42
includes/cache.php
Normal file
42
includes/cache.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
function getSoutenirContent(string $lang = 'fr'): array {
|
||||
$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);
|
||||
if (SOUTIEN_API_TOKEN) {
|
||||
$url .= '&token=' . urlencode(SOUTIEN_API_TOKEN);
|
||||
}
|
||||
|
||||
$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 [];
|
||||
}
|
||||
6
includes/config.php
Normal file
6
includes/config.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
define('KIRBY_API_URL', 'https://www.index.ngo/api/soutien-content');
|
||||
define('SOUTIEN_API_TOKEN', ''); // À remplir avec le même token que dans la config Kirby
|
||||
define('CACHE_TTL', 300); // 5 minutes
|
||||
define('CACHE_DIR', __DIR__ . '/../cache');
|
||||
Loading…
Add table
Add a link
Reference in a new issue