From 1119cf74af4e3fdc0b81e0667ba7f76f25313cc3 Mon Sep 17 00:00:00 2001 From: marcus Date: Thu, 14 May 2009 13:50:49 +0000 Subject: Fixed geocode stuff + version bump git-svn-id: https://code.elgg.org/elgg/trunk@3289 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/location.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'engine/lib/location.php') diff --git a/engine/lib/location.php b/engine/lib/location.php index 482a241b4..69e2fe2b1 100644 --- a/engine/lib/location.php +++ b/engine/lib/location.php @@ -59,23 +59,30 @@ { global $CONFIG; + // Handle cases where we are passed an array (shouldn't be but can happen if location is a tag field) + if (is_array($location)) + $location = implode(', ', $location); + $location = sanitise_string($location); // Look for cached version $cached_location = get_data_row("SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'"); - // Trigger geocode event + if ($cached_location) + return array('lat' => $cached_location->lat, 'long' => $cached_location->long); + + // Trigger geocode event if not cached $return = false; - $return = trigger_plugin_hook('geocode', 'location', array('location' => $location, $return)); + $return = trigger_plugin_hook('geocode', 'location', array('location' => $location), $return); // If returned, cache and return value if (($return) && (is_array($return))) { - $lat = (int)$return['lat']; - $long = (int)$return['long']; + $lat = (float)$return['lat']; + $long = (float)$return['long']; // Put into cache at the end of the page since we don't really care that much - execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (lat, long) VALUES ({$lat}, {$long}) ON DUPLICATE KEY UPDATE lat={$lat} long={$long}"); + execute_delayed_write_query("INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}') ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'"); } return $return; -- cgit v1.2.3