[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / gis / action / gis_geocoder_rechercher.php
1 <?php
2 if (!defined('_ECRIRE_INC_VERSION')) {
3 return;
4 }
5 include_spip('inc/distant');
6
7 /**
8 * Proxy vers le service Nomatim d'OpenStreetMap.
9 *
10 * Cette fonction permet de transmettre une requete auprès du service
11 * de recherche d'adresse d'OpenStreetMap (Nomatim).
12 *
13 * Seuls les arguments spécifiques à Nomatim sont transmis.
14 */
15 function action_gis_geocoder_rechercher_dist() {
16 include_spip('inc/modifier');
17
18 $mode = _request('mode');
19 if (!$mode || !in_array($mode, array('search', 'reverse'))) {
20 return;
21 }
22
23 /* On filtre les arguments à renvoyer à Nomatim (liste blanche) */
24 $arguments = collecter_requests(array('json_callback', 'format', 'q', 'limit', 'addressdetails', 'accept-language', 'lat', 'lon'), array());
25
26 $geocoder = defined('_GIS_GEOCODER') ? _GIS_GEOCODER : 'nominatim';
27
28 if (!empty($arguments) && in_array($geocoder, array('photon','nominatim'))) {
29 header('Content-Type: application/json; charset=UTF-8');
30 if ($geocoder == 'photon') {
31 if (isset($arguments['accept-language'])) {
32 $arguments['lang'] = $arguments['accept-language'];
33 unset($arguments['accept-language']);
34 }
35 if ($mode == 'search') {
36 $mode = 'api/';
37 } else {
38 $mode = 'reverse';
39 }
40 $url = 'http://photon.komoot.de/';
41 } else {
42 $url = 'http://nominatim.openstreetmap.org/';
43 }
44
45 $url = defined('_GIS_GEOCODER_URL') ? _GIS_GEOCODER_URL : $url;
46 $data = recuperer_page("{$url}{$mode}?" . http_build_query($arguments));
47 echo $data;
48 }
49 }