-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
36 lines (28 loc) · 1.13 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$URLS = [
'manche' => 'https://www.premar-manche.gouv.fr',
'atlantique' => 'https://www.premar-atlantique.gouv.fr',
'méditerranée' => 'https://www.premar-mediterranee.gouv.fr'
];
$region = $_GET['region'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$URLS[$region]/api/avis-urgents-aux-navigateurs.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output, true);
$res = [];
foreach ($data as $avurnav) {
$current = [];
$current['valid_from'] = substr($avurnav['dateDebut'], 0, 10);
$current['valid_until'] = substr($avurnav['dateFin'], 0, 10);
$current['url'] = $URLS[$region]."/avis-urgents-aux-navigateurs/".$avurnav['slug'];
$current['title'] = $avurnav['title']." - n°".$avurnav['numero'];
$current['number'] = $avurnav['numero'];
$current['latitude'] = floatval($avurnav['latitude']);
$current['longitude'] = floatval($avurnav['longitude']);
$res[] = $current;
}
header('Content-type: application/json; charset=UTF-8');
header('Access-Control-Allow-Origin: *');
echo json_encode($res, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);