diff --git a/api/cache/donorbox_data.json b/api/cache/donorbox_data.json index 7cf3fb2..6a861e6 100644 --- a/api/cache/donorbox_data.json +++ b/api/cache/donorbox_data.json @@ -1,14 +1,8 @@ { - "total_raised": "35825.53", + "total_raised": "35675.25", "goal_amt": "50000.0", "currency": "eur", - "donations_count": 533, - "recurring_donors_count": 56, + "donations_count": 521, "campaign_name": "Soutenez Index avant le 31 d\u00e9cembre 2025 !", - "updated_at": "2026-03-06T07:41:46+00:00", - "DEBUG_plans_breakdown": { - "cancelled|monthly": 36, - "active|monthly": 56, - "failed|monthly": 19 - } + "updated_at": "2026-02-27T12:51:20+01:00" } \ No newline at end of file diff --git a/api/donorbox-proxy.php b/api/donorbox-proxy.php index 27dd6d7..90fdb04 100644 --- a/api/donorbox-proxy.php +++ b/api/donorbox-proxy.php @@ -128,56 +128,14 @@ if ($campaign === null) { } } -// Compter tous les donateurs réguliers actifs (toutes campagnes confondues) -$recurring_count = 0; -$plans_page = 1; -do { - $plans_url = 'https://donorbox.org/api/v1/plans?per_page=100&page=' . $plans_page; - - $ch_plans = curl_init(); - curl_setopt_array($ch_plans, [ - CURLOPT_URL => $plans_url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_USERPWD => DONORBOX_EMAIL . ':' . DONORBOX_API_KEY, - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'User-Agent: Index-NGO-Website'], - CURLOPT_TIMEOUT => 10, - CURLOPT_SSL_VERIFYPEER => true - ]); - - $plans_response = curl_exec($ch_plans); - $plans_http_code = curl_getinfo($ch_plans, CURLINFO_HTTP_CODE); - curl_close($ch_plans); - - if ($plans_response === false || $plans_http_code !== 200) { - break; - } - - $plans = json_decode($plans_response, true); - if (!is_array($plans)) break; - - foreach ($plans as $plan) { - if (isset($plan['status']) && $plan['status'] === 'active') { - $recurring_count++; - } - $status = $plan['status'] ?? 'unknown'; - $type = $plan['type'] ?? 'unknown'; - $plans_detail[$status . '|' . $type] = ($plans_detail[$status . '|' . $type] ?? 0) + 1; - } - - $plans_page++; -} while (count($plans) === 100); - // Extraire uniquement les données nécessaires $filteredData = [ 'total_raised' => $campaign['total_raised'] ?? 0, 'goal_amt' => $campaign['goal_amt'] ?? 50000, 'currency' => $campaign['currency'] ?? 'EUR', 'donations_count' => $campaign['donations_count'] ?? 0, - 'recurring_donors_count' => $recurring_count, 'campaign_name' => $campaign['name'] ?? 'Unknown', - 'updated_at' => date('c'), - 'plans_detail' => $plans_detail ?? [] + 'updated_at' => date('c') ]; $jsonResponse = json_encode($filteredData, JSON_PRETTY_PRINT); diff --git a/assets/js/donorbox-gauge.js b/assets/js/donorbox-gauge.js index 3401c41..a410517 100644 --- a/assets/js/donorbox-gauge.js +++ b/assets/js/donorbox-gauge.js @@ -2,8 +2,17 @@ const DONORBOX_CONFIG = { proxyUrl: '/api/donorbox-proxy.php', }; -const RECURRING_DONORS_OFFSET = 98; -const GOAL_SUPPORTERS = 500; +function formatCurrency(amount) { + const rounded = Math.round(amount * 100) / 100; + const hasDecimals = rounded % 1 !== 0; + + const formatted = rounded.toLocaleString('fr-FR', { + minimumFractionDigits: 0, + maximumFractionDigits: hasDecimals ? 2 : 0, + }); + + return formatted.replace(/[\s\u00A0\u202F]/g, '\u202F') + '\u202F€'; +} async function fetchDonorboxData() { try { @@ -32,9 +41,9 @@ async function fetchDonorboxData() { } function updateGaugeDisplay(campaignData) { - const recurringCount = campaignData.recurring_donors_count || 0; - const totalSupport = recurringCount + RECURRING_DONORS_OFFSET; - const percentage = Math.min((totalSupport / GOAL_SUPPORTERS) * 100, 100); + const collected = campaignData.total_raised || 0; + const goal = campaignData.goal_amt || 50000; + const percentage = Math.min((collected / goal) * 100, 100); const gaugeElement = document.getElementById('gauge'); if (gaugeElement) { @@ -44,16 +53,27 @@ function updateGaugeDisplay(campaignData) { ); } - const countElement = document.querySelector( + const collectedElement = document.querySelector( '#gauge--infos__donateurs .value' ); - if (countElement) { - countElement.textContent = totalSupport; + if (collectedElement) { + collectedElement.textContent = formatCurrency(collected); + } + + const goalElement = document.querySelector('#gauge--infos__objectif .value'); + if (goalElement) { + goalElement.textContent = formatCurrency(goal); + } + + const donorsCount = campaignData.donations_count || 0; + const donorsElement = document.querySelector('#gauge--infos__donors .value'); + if (donorsElement) { + donorsElement.textContent = donorsCount; } console.log('Gauge updated:', { - recurringDonors: recurringCount, - totalSupport, + collected: formatCurrency(collected), + goal: formatCurrency(goal), percentage: `${percentage.toFixed(1)}%`, }); } diff --git a/en/index.html b/en/index.html index fdc4982..6f59cab 100644 --- a/en/index.html +++ b/en/index.html @@ -96,17 +96,21 @@
Regular supporters
+Raised
+0€
+Donors
0
Goal
-500
+
- Goal: 500 Supporters
by 21 June 2026
+ Support us in 2026