نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* get_heatmap.php
|
|
* ───────────────
|
|
* تقرأ بيانات الخريطة الحرارية المجمعة من Redis
|
|
* البيانات مقسمة حسب الدولة (عبر Bounding Boxes في الـ Cron)
|
|
*/
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
require_once __DIR__ . '/../../connect.php'; // Includes functions.php which has filterRequest()
|
|
|
|
$days = (int)(filterRequest('days') ?? 7);
|
|
$source = filterRequest('source') ?? 'all';
|
|
$countryCode = strtoupper(filterRequest('country_code') ?? 'all');
|
|
|
|
try {
|
|
$redis = getRedisConnection();
|
|
$cacheJson = $redis->get('siro:cache:heatmap:data');
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Redis connection failed']);
|
|
exit;
|
|
}
|
|
|
|
if (!$cacheJson) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Cache not generated yet']);
|
|
exit;
|
|
}
|
|
|
|
$cacheData = json_decode($cacheJson, true);
|
|
|
|
if (!$cacheData || !isset($cacheData['data'])) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid cache data']);
|
|
exit;
|
|
}
|
|
|
|
$limitDate = date('Y-m-d', strtotime("-$days days"));
|
|
|
|
$filteredLocations = [];
|
|
$stats = ['geofence' => 0, 'app_usage' => 0, 'silent_push' => 0];
|
|
|
|
$dataByCountry = $cacheData['data'];
|
|
|
|
// تحديد الدول التي سنسحب منها
|
|
$countriesToSearch = ($countryCode === 'ALL') ? array_keys($dataByCountry) : [$countryCode];
|
|
|
|
foreach ($countriesToSearch as $cc) {
|
|
if (!isset($dataByCountry[$cc])) continue;
|
|
|
|
foreach ($dataByCountry[$cc] as $loc) {
|
|
// فلتر الأيام
|
|
if ($loc['date'] < $limitDate) continue;
|
|
|
|
// فلتر المصدر
|
|
if ($source !== 'all' && $loc['source'] !== $source) continue;
|
|
|
|
$filteredLocations[] = [
|
|
'latitude' => $loc['lat'],
|
|
'longitude' => $loc['lng'],
|
|
'source' => $loc['source']
|
|
];
|
|
|
|
if (isset($stats[$loc['source']])) {
|
|
$stats[$loc['source']]++;
|
|
}
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => $filteredLocations,
|
|
'total' => count($filteredLocations),
|
|
'stats' => $stats,
|
|
'source' => 'redis_cache'
|
|
], JSON_UNESCAPED_UNICODE);
|
|
|
|
// تم إزالة دالة filterRequest من هنا لتجنب خطأ Redeclaration لأنها معرفة في functions.php
|
|
?>
|