From 73f6c16524535d2bab4cbc2334b9d105e927bce1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Wed, 18 Feb 2009 22:23:14 +0100 Subject: [PATCH] Non geocoded addresses could not be saved. --- include/geocoding.inc.php | 12 ++++++++++++ modules/profile/addresses.inc.php | 4 ++-- modules/profile/jobs.inc.php | 4 ++-- modules/profile/page.inc.php | 20 +++++++++++--------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/geocoding.inc.php b/include/geocoding.inc.php index 9538faa..fc812fa 100644 --- a/include/geocoding.inc.php +++ b/include/geocoding.inc.php @@ -27,6 +27,9 @@ abstract class Geocoder { // Unknown key-value pairs available in the input map are retained as-is. abstract public function getGeocodedAddress(array $address); + // Cleans the address from its geocoded data + abstract public function stripGeocodingFromAddress(array $address); + // Updates geoloc_administrativeareas, geoloc_subadministrativeareas and // geoloc_localities databases with new geocoded data and returns the // corresponding id. @@ -107,6 +110,15 @@ class GMapsGeocoder extends Geocoder { return $address; } + public function stripGeocodingFromAddress(array $address) { + unset($address['geoloc'], $address['geoloc_choice'], $address['countryId'], + $address['country'], $address['administrativeAreaName'], + $address['subAdministrativeAreaName'], $address['localityName'], + $address['thoroughfareName'], $address['postalCode']); + $address['accuracy'] = 0; + return $address; + } + // Updates the address with the geocoded information from Google Maps. Also // cleans up the final informations. private function getUpdatedAddress(array $address, array $geocodedData, $extraLines) { diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 6574761..5388595 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -19,7 +19,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -class ProfileAddress extends ProfileGeoloc +class ProfileAddress extends ProfileGeocoding { private $bool; private $pub; @@ -75,7 +75,7 @@ class ProfileAddress extends ProfileGeoloc if (!trim($address['text'])) { unset($value[$key]); } elseif (!$init) { - $this->geolocAddress($address, $s); + $this->geocodeAddress($address, $s); $success = $success && $s; } $this->cleanAddress($page, $key, $address); diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 81dbafe..1e19fc1 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -19,7 +19,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -class ProfileJob extends ProfileGeoloc +class ProfileJob extends ProfileGeocoding { private $pub; private $mail_new; @@ -131,7 +131,7 @@ class ProfileJob extends ProfileGeoloc } foreach ($value as $key=>&$job) { $ls = true; - $this->geolocAddress($job['w_adr'], $s); + $this->geocodeAddress($job['w_adr'], $s); $ls = ($ls && $s); $this->cleanJob($page, $key, $job, $s); $ls = ($ls && $s); diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 27e1958..bb884db 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -254,9 +254,9 @@ class ProfileDate extends ProfileNoSave } } -abstract class ProfileGeoloc implements ProfileSetting +abstract class ProfileGeocoding implements ProfileSetting { - protected function geolocAddress(array &$address, &$success) + protected function geocodeAddress(array &$address, &$success) { require_once 'geocoding.inc.php'; $success = true; @@ -267,13 +267,15 @@ abstract class ProfileGeoloc implements ProfileSetting $success = false; } } - if (isset($address['geoloc_choice']) && $address['geoloc_choice'] == 0) { - $mailer = new PlMailer('geoloc/geoloc.mail.tpl'); - $mailer->assign('text', $address['text']); - $mailer->assign('geoloc', $address['geoloc']); - $mailer->send(); - } elseif (isset($address['geoloc_choice'])) { - unset($address['geoloc'], $address['geoloc_choice']); + if (isset($address['geoloc_choice'])) { + if ($address['geoloc_choice'] == 0) { + $mailer = new PlMailer('geoloc/geoloc.mail.tpl'); + $mailer->assign('text', $address['text']); + $mailer->assign('geoloc', $address['geoloc']); + $mailer->send(); + } + $gmapsGeocoder = new GMapsGeocoder(); + $address = $gmapsGeocoder->stripGeocodingFromAddress($address); } } } -- 2.1.4