From 675361fdc6036858d6a90404d62e1294958ca20e Mon Sep 17 00:00:00 2001 From: b_b Date: Wed, 28 Apr 2021 22:44:03 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9porter=20la=20fonction=20de=20geocoding?= =?UTF-8?q?=20dans=20un=20fichier=20d=C3=A9di=C3=A9=20afin=20de=20l'utilis?= =?UTF-8?q?er=20aussi=20dans=20le=20pipeline=20gis=5Fpost=5Fedition()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #17 --- action/gis_geocoder_rechercher.php | 37 ++------------------- gis_pipelines.php | 22 +++++++++---- inc/gis_geocode.php | 53 ++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 41 deletions(-) create mode 100644 inc/gis_geocode.php diff --git a/action/gis_geocoder_rechercher.php b/action/gis_geocoder_rechercher.php index ad64f56..416fd95 100644 --- a/action/gis_geocoder_rechercher.php +++ b/action/gis_geocoder_rechercher.php @@ -4,8 +4,6 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } -include_spip('inc/distant'); - /** * Proxy vers le service du geocoder * @@ -16,42 +14,11 @@ include_spip('inc/distant'); */ function action_gis_geocoder_rechercher_dist() { include_spip('inc/modifier'); - - $mode = _request('mode'); - if (!$mode || !in_array($mode, array('search', 'reverse'))) { - return; - } - /* On filtre les arguments à renvoyer à Nomatim (liste blanche) */ $arguments = collecter_requests(array('format', 'q', 'limit', 'addressdetails', 'accept-language', 'lat', 'lon'), array()); - - $geocoder = defined('_GIS_GEOCODER') ? _GIS_GEOCODER : 'photon'; - - if ($geocoder == 'photon') { - unset($arguments['format']); - unset($arguments['addressdetails']); - } - - if (!empty($arguments) && in_array($geocoder, array('photon','nominatim'))) { + include_spip('inc/gis_geocode'); + if ($data = gis_geocode_request(_request('mode'), $arguments)) { header('Content-Type: application/json; charset=UTF-8'); - if ($geocoder == 'photon') { - if (isset($arguments['accept-language'])) { - // ne garder que les deux premiers caractères du code de langue, car les variantes spipiennes comme fr_fem posent problème - $arguments['lang'] = substr($arguments['accept-language'], 0, 2); - unset($arguments['accept-language']); - } - if ($mode == 'search') { - $mode = 'api/'; - } else { - $mode = 'reverse'; - } - $url = 'http://photon.komoot.io/'; - } else { - $url = 'http://nominatim.openstreetmap.org/'; - } - - $url = defined('_GIS_GEOCODER_URL') ? _GIS_GEOCODER_URL : $url; - $data = recuperer_page("{$url}{$mode}?" . http_build_query($arguments)); echo $data; } } diff --git a/gis_pipelines.php b/gis_pipelines.php index 56bcc5b..e5d2890 100755 --- a/gis_pipelines.php +++ b/gis_pipelines.php @@ -139,9 +139,14 @@ function gis_post_edition($flux) { $longitude = round(dms_to_dec($exifs['GPSLongitudeRef'], $intLongDeg, $intLongMin, $intLongSec), 5); } if ($config['geocoder'] == 'on') { - include_spip('inc/distant'); - $url_geocoder = 'http://nominatim.openstreetmap.org/reverse/?format=json&addressdetails=1&accept-language='.urlencode($GLOBALS['meta']['langue_site']).'&lat='.urlencode($latitude).'&lon='.urlencode($longitude); - $json = recuperer_page($url_geocoder); + include_spip('inc/gis_geocode'); + $json = gis_geocode_request('reverse', array( + 'format' => 'json', + 'addressdetails' => 1, + 'accept-language' => $GLOBALS['meta']['langue_site'], + 'lat' => $latitude, + 'lon' => $longitude + )); $geocoder = json_decode($json, true); if (is_array($geocoder)) { $pays = $geocoder['address']['country']; @@ -176,9 +181,14 @@ function gis_post_edition($flux) { $string_recherche .= $iptc['country']; } if (strlen($string_recherche)) { - include_spip('inc/distant'); - $url_geocoder = 'http://nominatim.openstreetmap.org/search/?format=json&addressdetails=1&limit=1&accept-language='.urlencode($GLOBALS['meta']['langue_site']).'&q='.urlencode($string_recherche); - $json = recuperer_page($url_geocoder); + include_spip('inc/gis_geocode'); + $json = gis_geocode_request('search', array( + 'format' => 'json', + 'addressdetails' => 1, + 'limit' => 1, + 'accept-language' => $GLOBALS['meta']['langue_site'], + 'q' => $string_recherche + )); $geocoder = json_decode($json, true); if (is_array($geocoder[0])) { $latitude = $geocoder[0]['lat']; diff --git a/inc/gis_geocode.php b/inc/gis_geocode.php new file mode 100644 index 0000000..27dc314 --- /dev/null +++ b/inc/gis_geocode.php @@ -0,0 +1,53 @@ +