1 | <?php |
---|
2 | |
---|
3 | if (!defined('_ECRIRE_INC_VERSION')) { |
---|
4 | return; |
---|
5 | } |
---|
6 | |
---|
7 | include_spip('inc/distant'); |
---|
8 | |
---|
9 | /** |
---|
10 | * Proxy vers le service du geocoder |
---|
11 | * |
---|
12 | * Cette fonction permet de transmettre une requete auprès du service |
---|
13 | * de recherche d'adresse d'OpenStreetMap (Nomatim ou Photon). |
---|
14 | * |
---|
15 | * Seuls les arguments spécifiques au service sont transmis. |
---|
16 | */ |
---|
17 | function action_gis_geocoder_rechercher_dist() { |
---|
18 | include_spip('inc/modifier'); |
---|
19 | |
---|
20 | $mode = _request('mode'); |
---|
21 | if (!$mode || !in_array($mode, array('search', 'reverse'))) { |
---|
22 | return; |
---|
23 | } |
---|
24 | |
---|
25 | /* On filtre les arguments à renvoyer à Nomatim (liste blanche) */ |
---|
26 | $arguments = collecter_requests(array('format', 'q', 'limit', 'addressdetails', 'accept-language', 'lat', 'lon'), array()); |
---|
27 | |
---|
28 | $geocoder = defined('_GIS_GEOCODER') ? _GIS_GEOCODER : 'photon'; |
---|
29 | |
---|
30 | if ($geocoder == 'photon') { |
---|
31 | unset($arguments['format']); |
---|
32 | unset($arguments['addressdetails']); |
---|
33 | } |
---|
34 | |
---|
35 | if (!empty($arguments) && in_array($geocoder, array('photon','nominatim'))) { |
---|
36 | header('Content-Type: application/json; charset=UTF-8'); |
---|
37 | if ($geocoder == 'photon') { |
---|
38 | if (isset($arguments['accept-language'])) { |
---|
39 | // ne garder que les deux premiers caractères du code de langue, car les variantes spipiennes comme fr_fem posent problème |
---|
40 | $arguments['lang'] = substr($arguments['accept-language'], 0, 2); |
---|
41 | unset($arguments['accept-language']); |
---|
42 | } |
---|
43 | if ($mode == 'search') { |
---|
44 | $mode = 'api/'; |
---|
45 | } else { |
---|
46 | $mode = 'reverse'; |
---|
47 | } |
---|
48 | $url = 'http://photon.komoot.de/'; |
---|
49 | } else { |
---|
50 | $url = 'http://nominatim.openstreetmap.org/'; |
---|
51 | } |
---|
52 | |
---|
53 | $url = defined('_GIS_GEOCODER_URL') ? _GIS_GEOCODER_URL : $url; |
---|
54 | $data = recuperer_page("{$url}{$mode}?" . http_build_query($arguments)); |
---|
55 | echo $data; |
---|
56 | } |
---|
57 | } |
---|