| 1 |
<?php
|
| 2 |
// $Id: location.inc,v 1.98 2009/07/08 20:52:09 bdragon Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @defgroup Location Location: An API for working with locations.
|
| 6 |
*
|
| 7 |
* Public API for the Location module.
|
| 8 |
*/
|
| 9 |
|
| 10 |
|
| 11 |
/**
|
| 12 |
* @file
|
| 13 |
* An implementation of a universal API for location manipulation. Provides functions for
|
| 14 |
* postal_code proximity searching, deep-linking into online mapping services. Currently,
|
| 15 |
* some options are configured through an interface provided by location.module.
|
| 16 |
*/
|
| 17 |
|
| 18 |
include_once drupal_get_path('module', 'location') .'/earth.inc';
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Get a deep-link to a mapping service such as Yahoo! Maps or MapPoint given an location. The
|
| 22 |
* call is delegated based on the 'country' value in the $location parameter.
|
| 23 |
*
|
| 24 |
* @param $location
|
| 25 |
* An associative array where
|
| 26 |
* 'street' => A string representing the street location
|
| 27 |
* 'additional' => A string for any additional portion of the street location
|
| 28 |
* 'city' => A string for the city name
|
| 29 |
* 'province' => The standard postal abbreviation for the province
|
| 30 |
* 'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
| 31 |
* 'postal_code' => The international postal code for the location
|
| 32 |
*
|
| 33 |
* @return
|
| 34 |
* A link to a map provided by a third-party. The idea is to encode the appropriate
|
| 35 |
* parameters as HTTP GET variables to the URL.
|
| 36 |
*
|
| 37 |
* @ingroup Location
|
| 38 |
*/
|
| 39 |
function location_map_link($location = array(), $link_text = 'See map: ') {
|
| 40 |
if (!isset($location['country']) || $location['country'] == 'xx') {
|
| 41 |
return '';
|
| 42 |
}
|
| 43 |
|
| 44 |
location_load_country($location['country']);
|
| 45 |
|
| 46 |
$default_func = 'location_map_link_'. $location['country'] .'_default_providers';
|
| 47 |
$providers_func = 'location_map_link_'. $location['country'] .'_providers';
|
| 48 |
$providers = function_exists($providers_func) ? $providers_func() : array();
|
| 49 |
$selected_providers = variable_get('location_map_link_'. $location['country'], function_exists($default_func) ? $default_func() : array());
|
| 50 |
|
| 51 |
$links = array();
|
| 52 |
foreach ($selected_providers as $mapper) {
|
| 53 |
$link_func = 'location_map_link_'. $location['country'] .'_'. $mapper;
|
| 54 |
if (function_exists($link_func)) {
|
| 55 |
if ($link = $link_func($location)) {
|
| 56 |
$links[] = '<a href="'. $link .'">'. $providers[$mapper]['name'] .'</a>';
|
| 57 |
}
|
| 58 |
}
|
| 59 |
}
|
| 60 |
if (count($links)) {
|
| 61 |
return t($link_text) . implode($links, ", ");
|
| 62 |
}
|
| 63 |
else {
|
| 64 |
return NULL;
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Try to extract the the Latitude and Longitude data from the
|
| 70 |
* postal code.
|
| 71 |
*
|
| 72 |
* @param $location
|
| 73 |
* Array. the location data
|
| 74 |
* -> the values are:
|
| 75 |
* 'street' => the string representing the street location (REQUIRED)
|
| 76 |
* 'additional' => the string representing the additional street location portion in the location form
|
| 77 |
* 'city' => the city name (REQUIRED)
|
| 78 |
* 'province' => the province code defined in the country-specific include file
|
| 79 |
* 'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
| 80 |
* 'postal_code' => the postal-code (REQUIRED)
|
| 81 |
*
|
| 82 |
* @return
|
| 83 |
* Array or NULL. NULL if the delegated-to function that does the
|
| 84 |
* actual look-up does not exist. If the appropriate function exists,
|
| 85 |
* then this function returns an associative array where
|
| 86 |
* 'lon' => A floating point number for the longitude coordinate of the parameter location
|
| 87 |
* 'lat' => A floating point number for the latitude coordinate of the parameter location
|
| 88 |
*
|
| 89 |
* @ingroup Location
|
| 90 |
*/
|
| 91 |
function location_get_postalcode_data($location = array()) {
|
| 92 |
$location['country'] = isset($location['country']) ? trim($location['country']) : NULL;
|
| 93 |
$location['postal_code'] = isset($location['postal_code']) ? trim($location['postal_code']) : NULL;
|
| 94 |
if (is_null($location['postal_code']) || is_null($location['country']) || empty($location['country']) || empty($location['postal_code']) || $location['postal_code'] == 'xx') {
|
| 95 |
return NULL;
|
| 96 |
}
|
| 97 |
location_load_country($location['country']);
|
| 98 |
$country_specific_function = 'location_get_postalcode_data_'. $location['country'];
|
| 99 |
if (function_exists($country_specific_function)) {
|
| 100 |
return $country_specific_function($location);
|
| 101 |
}
|
| 102 |
else {
|
| 103 |
return NULL;
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Given two points in lat/lon form, returns the distance between them.
|
| 109 |
*
|
| 110 |
* @param $latlon_a
|
| 111 |
* An associative array where
|
| 112 |
* 'lon' => is a floating point of the longitude coordinate for the point given by latlonA
|
| 113 |
* 'lat' => is a floating point of the latitude coordinate for the point given by latlonB
|
| 114 |
*
|
| 115 |
* @param $latlon_b
|
| 116 |
* Another point formatted like $latlon_b
|
| 117 |
*
|
| 118 |
* @param $distance_unit
|
| 119 |
* A string that is either 'km' or 'mile'.
|
| 120 |
* If neither 'km' or 'mile' is passed, the parameter is forced to 'km'
|
| 121 |
*
|
| 122 |
* @return
|
| 123 |
* NULL if sense can't be made of the parameters.
|
| 124 |
* An associative array where
|
| 125 |
* 'scalar' => Is the distance between the two lat/lon parameter points
|
| 126 |
* 'distance_unit' => Is the unit of distance being represented by 'scalar'.
|
| 127 |
* This will be 'km' unless 'mile' is passed for the $distance_unit param
|
| 128 |
*
|
| 129 |
* @ingroup Location
|
| 130 |
*/
|
| 131 |
function location_distance_between($latlon_a = array(), $latlon_b = array(), $distance_unit = 'km') {
|
| 132 |
if (!isset($latlon_a['lon']) || !isset($latlon_a['lat']) || !isset($latlon_b['lon']) || !isset($latlon_b['lat'])) {
|
| 133 |
return NULL;
|
| 134 |
}
|
| 135 |
|
| 136 |
if ($distance_unit != 'km' && $distance_unit != 'mile') {
|
| 137 |
return NULL;
|
| 138 |
}
|
| 139 |
|
| 140 |
// $conversion_factor = number to divide by to convert meters to $distance_unit
|
| 141 |
// At this point, $distance_unit == 'km' or 'mile' and nothing else
|
| 142 |
//$conversion_factor = ($distance_unit == 'km') ? 1000.0 : 1609.347;
|
| 143 |
|
| 144 |
$meters = earth_distance($latlon_a['lon'], $latlon_a['lat'], $latlon_b['lon'], $latlon_b['lat']);
|
| 145 |
return array('scalar' => round($meters/(($distance_unit == 'km') ? 1000.0 : 1609.347), 1), 'distance_unit' => $distance_unit);
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Takes two locations and tries to return a deep-link to driving directions.
|
| 150 |
*
|
| 151 |
* Parameters:
|
| 152 |
* @param $location_a
|
| 153 |
* An associative array that represents an location where
|
| 154 |
* 'street' => the street portions of the location
|
| 155 |
* 'additional' => additional street portion of the location
|
| 156 |
* 'city' => the city name
|
| 157 |
* 'province' => the province, state, or territory
|
| 158 |
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
| 159 |
* 'postal_code' => the postal code
|
| 160 |
*
|
| 161 |
* @param $location_b
|
| 162 |
* An associative array that represents an location in the same way that
|
| 163 |
* parameter $location_a does.
|
| 164 |
*
|
| 165 |
* @param $link_text
|
| 166 |
* The text of the HTML link that is to be generated.
|
| 167 |
*
|
| 168 |
* @return
|
| 169 |
* A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters.
|
| 170 |
* A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters.
|
| 171 |
* The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate
|
| 172 |
* the call.
|
| 173 |
*
|
| 174 |
* We dispatch the call to a country-specific function. The country-specific function, in this case,
|
| 175 |
* will be the one reflected by the country parameter of the first function. We require that
|
| 176 |
* both locationes supplied have a country field at the minimum.
|
| 177 |
*
|
| 178 |
* The country-specific functions will ultimately decide, with the parameters given, whether to
|
| 179 |
* to link to a form for driving directions is provided, where this form will be
|
| 180 |
* pre-populated with whatever values were available or whether to link directly to the driving
|
| 181 |
* directions themselves if enough fields are filled for each location.
|
| 182 |
*
|
| 183 |
* @ingroup Location
|
| 184 |
*/
|
| 185 |
function location_driving_directions_link($location_a = array(), $location_b = array(), $link_text = 'Get directions') {
|
| 186 |
if (!isset($location_a['country']) or !isset($location_b['country'])) {
|
| 187 |
return '';
|
| 188 |
}
|
| 189 |
|
| 190 |
// For now, return empty string if starting-point and destinations are in different countries
|
| 191 |
//if ($location_a['country'] != $location_b['country']) {
|
| 192 |
// return '';
|
| 193 |
//}
|
| 194 |
// Lines above commented out because I want to let the country-specific function of the departure point decide
|
| 195 |
// what it will do with driving destination locationes from other countries. As an example, Yahoo! Maps supports driving
|
| 196 |
// direction queries for locations between the U.S. and Canada.
|
| 197 |
|
| 198 |
$driving_direction_function = 'location_driving_directions_link_'. $location_a['country'];
|
| 199 |
if (function_exists($driving_direction_function)) {
|
| 200 |
$http_link = $driving_direction_function($location_a, $location_b);
|
| 201 |
if (strlen($http_link)) {
|
| 202 |
return '<a href="'. $http_link .'">'. $link_text .'</a>';
|
| 203 |
}
|
| 204 |
else {
|
| 205 |
return '';
|
| 206 |
}
|
| 207 |
}
|
| 208 |
|
| 209 |
return '';
|
| 210 |
}
|
| 211 |
|
| 212 |
/**
|
| 213 |
* @param $distance
|
| 214 |
* A number in either miles or km.
|
| 215 |
*
|
| 216 |
* @param $distance_unit
|
| 217 |
* String (optional). Either 'mile' or 'km' (default)
|
| 218 |
*
|
| 219 |
* @return
|
| 220 |
* A floating point number where the number in meters after the initially passed scalar has been ceil()'d
|
| 221 |
* This is done after the $distance_unit parmeter is forced to be 'km' or 'mile'
|
| 222 |
*/
|
| 223 |
function _location_convert_distance_to_meters($distance, $distance_unit = 'km') {
|
| 224 |
if (!is_numeric($distance)) {
|
| 225 |
return NULL;
|
| 226 |
}
|
| 227 |
|
| 228 |
// Force an integer version of distance, just in case anyone wants to add a caching mechanism
|
| 229 |
// for postal code proximity searches.
|
| 230 |
|
| 231 |
if (is_float($distance)) {
|
| 232 |
$distance = intval(ceil($distance));
|
| 233 |
}
|
| 234 |
|
| 235 |
if ($distance < 1) {
|
| 236 |
return NULL;
|
| 237 |
}
|
| 238 |
|
| 239 |
if ($distance_unit != 'km' && $distance_unit != 'mile') {
|
| 240 |
$distance_unit = 'km';
|
| 241 |
}
|
| 242 |
|
| 243 |
// Convert distance to meters
|
| 244 |
//$distance_float = floatval($distance) * (($distance_unit == 'km') ? 1000.0 : 1609.347);
|
| 245 |
//return round($distance_float, 2);
|
| 246 |
$retval = round(floatval($distance) * (($distance_unit == 'km') ? 1000.0 : 1609.347), 2);
|
| 247 |
return $retval;
|
| 248 |
}
|
| 249 |
|
| 250 |
/**
|
| 251 |
* Takes an location and returns a "rough" latitude/longitude pair based on the postal code
|
| 252 |
* data available for the given country.
|
| 253 |
*
|
| 254 |
* @param $location
|
| 255 |
* An associative array $location where
|
| 256 |
* 'street' => the street portion of the location
|
| 257 |
* 'additional' => additional street portion of the location
|
| 258 |
* 'province' => the province, state, or territory
|
| 259 |
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
| 260 |
* 'postal_code' => international postal code (REQUIRED)
|
| 261 |
*
|
| 262 |
* @return
|
| 263 |
* NULL if data cannont be found.
|
| 264 |
* Otherwise, an associative array where
|
| 265 |
* 'lat' => is a floating point of the latitude coordinate of this location
|
| 266 |
* 'lon' => is a floating point of the longitude coordinate of this location
|
| 267 |
*
|
| 268 |
* @ingroup Location
|
| 269 |
*/
|
| 270 |
function location_latlon_rough($location = array()) {
|
| 271 |
if (!isset($location['country']) || !isset($location['postal_code'])) {
|
| 272 |
return NULL;
|
| 273 |
}
|
| 274 |
|
| 275 |
location_load_country($location['country']);
|
| 276 |
|
| 277 |
$latlon_function = 'location_latlon_rough_'. $location['country'];
|
| 278 |
if (function_exists($latlon_function)) {
|
| 279 |
return $latlon_function($location);
|
| 280 |
}
|
| 281 |
else {
|
| 282 |
return NULL;
|
| 283 |
}
|
| 284 |
}
|
| 285 |
|
| 286 |
/**
|
| 287 |
* Currently, this is not a priority until there is an implementable use for exact longitude,
|
| 288 |
* latitude coordinates for an location. The idea is that this call will eventually retrieve
|
| 289 |
* information through a web-service. Whereas location_latlon_rough() returns an approximate
|
| 290 |
* lat/lon pair based strictly on the postal code where this lat/lon pair is pulled from a
|
| 291 |
* database table, this function is intended to send the entire location to a web-service and
|
| 292 |
* to retrieve exact lat/lon coordinates.
|
| 293 |
*
|
| 294 |
* @param $location
|
| 295 |
* An array where
|
| 296 |
* -> the key values are 'street', 'additional', 'province', 'country', 'postal_code'
|
| 297 |
* -> the values are:
|
| 298 |
* 'street' => the string representing the street location (REQUIRED)
|
| 299 |
* 'additional' => the string representing the additional street location portion in the location form
|
| 300 |
* 'city' => the city name (REQUIRED)
|
| 301 |
* 'province' => the province code defined in the country-specific include file
|
| 302 |
* 'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
| 303 |
* 'postal_code' => the postal-code (REQUIRED)
|
| 304 |
*
|
| 305 |
* @return
|
| 306 |
* NULL if the delegated-to function that does the actual look-up does not exist.
|
| 307 |
* If the appropriate function exists, then this function returns an associative array where
|
| 308 |
* 'lon' => A floating point number for the longitude coordinate of the parameter location
|
| 309 |
* 'lat' => A floating point number for the latitude coordinate of the parameter location
|
| 310 |
*
|
| 311 |
* @ingroup Location
|
| 312 |
*/
|
| 313 |
function location_latlon_exact($location = array()) {
|
| 314 |
$country = $location['country'];
|
| 315 |
location_standardize_country_code($country);
|
| 316 |
$service = variable_get('location_geocode_'. $country, 'none');
|
| 317 |
if (!empty($country) && $service != 'none') {
|
| 318 |
// figure out what the exact function should be
|
| 319 |
if (strpos($service, '|')) {
|
| 320 |
location_load_country($country);
|
| 321 |
// The code change below fixes the problem of the country specific
|
| 322 |
// function for geocoding not being correctly called (it removes any
|
| 323 |
// text from the pipe (|) onwards)
|
| 324 |
$exact_latlon_function = 'location_geocode_'. $country .'_'. substr($service, 0, strpos($service, '|'));
|
| 325 |
}
|
| 326 |
else {
|
| 327 |
location_load_geocoder($service);
|
| 328 |
$exact_latlon_function = $service .'_geocode_location';
|
| 329 |
}
|
| 330 |
if (function_exists($exact_latlon_function)) {
|
| 331 |
return $exact_latlon_function($location);
|
| 332 |
}
|
| 333 |
else {
|
| 334 |
return NULL;
|
| 335 |
}
|
| 336 |
}
|
| 337 |
return NULL;
|
| 338 |
}
|
| 339 |
|
| 340 |
/**
|
| 341 |
* Returns an associative array of countries currently supported
|
| 342 |
* by the location system where
|
| 343 |
* -> the keys represent the two-letter ISO code and
|
| 344 |
* -> the values represent the English name of the country.
|
| 345 |
* The array is sorted the index (i.e., by the short English name of the country).
|
| 346 |
*
|
| 347 |
* Please note the different between "supported" countries and "configured"
|
| 348 |
* countries: A country being "supported" means that there is an include file
|
| 349 |
* to support the country while "configure" implies that the site admin has
|
| 350 |
* configured the site to actually use that country.
|
| 351 |
*
|
| 352 |
* @ingroup Location
|
| 353 |
*/
|
| 354 |
function _location_supported_countries() {
|
| 355 |
static $supported_countries = array();
|
| 356 |
|
| 357 |
// If this function has already been called this request, we can avoid a DB hit.
|
| 358 |
if (!empty($supported_countries)) {
|
| 359 |
return $supported_countries;
|
| 360 |
}
|
| 361 |
|
| 362 |
// Try first to load from cache, it's much faster than the scan below.
|
| 363 |
if ($cache = cache_get('location:supported-countries', 'cache_location')) {
|
| 364 |
$supported_countries = $cache->data;
|
| 365 |
}
|
| 366 |
else {
|
| 367 |
// '<ISO two-letter code>' => '<English name for country>'
|
| 368 |
$iso_list = location_get_iso3166_list();
|
| 369 |
$path = drupal_get_path('module', 'location') .'/supported/location.';
|
| 370 |
foreach ($iso_list as $cc => $name) {
|
| 371 |
if (file_exists($path . $cc .'.inc')) {
|
| 372 |
$supported_countries[$cc] = $name;
|
| 373 |
}
|
| 374 |
}
|
| 375 |
cache_set('location:supported-countries', $supported_countries, 'cache_location');
|
| 376 |
}
|
| 377 |
return $supported_countries;
|
| 378 |
}
|
| 379 |
|
| 380 |
// @@@ New in 3.x, document.
|
| 381 |
/**
|
| 382 |
* Fetch the provinces for a country.
|
| 383 |
*/
|
| 384 |
function location_get_provinces($country = 'us') {
|
| 385 |
static $provinces = array();
|
| 386 |
location_standardize_country_code($country);
|
| 387 |
if (isset($provinces[$country])) {
|
| 388 |
return $provinces[$country];
|
| 389 |
}
|
| 390 |
if ($cache = cache_get("provinces:$country", 'cache_location')) {
|
| 391 |
$provinces[$country] = $cache->data;
|
| 392 |
return $provinces[$country];
|
| 393 |
}
|
| 394 |
location_load_country($country);
|
| 395 |
$func = 'location_province_list_'. $country;
|
| 396 |
if (function_exists($func)) {
|
| 397 |
$provinces[$country] = $func();
|
| 398 |
cache_set("provinces:$country", $provinces[$country], 'cache_location');
|
| 399 |
return $provinces[$country];
|
| 400 |
}
|
| 401 |
return array();
|
| 402 |
}
|
| 403 |
|
| 404 |
// @@@ New in 3.x, document.
|
| 405 |
/**
|
| 406 |
* Get the translated name of a country code.
|
| 407 |
*/
|
| 408 |
function location_country_name($country = 'us') {
|
| 409 |
location_standardize_country_code($country);
|
| 410 |
$countries = location_get_iso3166_list();
|
| 411 |
if (isset($countries[$country])) {
|
| 412 |
return $countries[$country];
|
| 413 |
}
|
| 414 |
else {
|
| 415 |
return '';
|
| 416 |
}
|
| 417 |
}
|
| 418 |
|
| 419 |
// @@@ New in 3.x, document.
|
| 420 |
/**
|
| 421 |
* Get the full name of a province code.
|
| 422 |
*/
|
| 423 |
function location_province_name($country = 'us', $province = 'xx') {
|
| 424 |
$provinces = location_get_provinces($country);
|
| 425 |
$province = strtoupper($province);
|
| 426 |
if (isset($provinces[$province])) {
|
| 427 |
return $provinces[$province];
|
| 428 |
}
|
| 429 |
else {
|
| 430 |
return '';
|
| 431 |
}
|
| 432 |
}
|
| 433 |
|
| 434 |
// @@@ New in 3.x, document.
|
| 435 |
/**
|
| 436 |
* Get a province code from a code or full name and a country.
|
| 437 |
*/
|
| 438 |
function location_province_code($country = 'us', $province = 'xx') {
|
| 439 |
// An array of countries is useful if someone specified multiple countries
|
| 440 |
// in an autoselect for example.
|
| 441 |
// It *is* possibly ambiguous, especially if the province was already a code.
|
| 442 |
// We make an array here for single (the usual case) for code simplicity reasons.
|
| 443 |
if (!is_array($country)) {
|
| 444 |
$country = array($country);
|
| 445 |
}
|
| 446 |
|
| 447 |
$p = strtoupper($province);
|
| 448 |
foreach ($country as $c) {
|
| 449 |
$provinces = location_get_provinces($c);
|
| 450 |
foreach ($provinces as $k => $v) {
|
| 451 |
if ($p == strtoupper($k) || $p == strtoupper($v)) {
|
| 452 |
return $k;
|
| 453 |
}
|
| 454 |
}
|
| 455 |
}
|
| 456 |
return '';
|
| 457 |
}
|
| 458 |
|
| 459 |
// @@@ New in 3.x, document.
|
| 460 |
/**
|
| 461 |
* Canonicalize a country code.
|
| 462 |
*/
|
| 463 |
function location_standardize_country_code(&$country) {
|
| 464 |
$country = trim($country);
|
| 465 |
// @@@ Double check the validity of this validity check. ;)
|
| 466 |
if (!ctype_alpha($country) || strlen($country) != 2) {
|
| 467 |
$country = 'xx';
|
| 468 |
return FALSE;
|
| 469 |
}
|
| 470 |
else {
|
| 471 |
$country = strtolower($country);
|
| 472 |
return TRUE;
|
| 473 |
}
|
| 474 |
}
|
| 475 |
|
| 476 |
// @@@ New in 3.x, document.
|
| 477 |
/**
|
| 478 |
* Load the support file for a country.
|
| 479 |
*/
|
| 480 |
function location_load_country($country) {
|
| 481 |
location_standardize_country_code($country);
|
| 482 |
if ($country != 'xx') {
|
| 483 |
include_once(drupal_get_path('module', 'location') .'/supported/location.'. $country .'.inc');
|
| 484 |
}
|
| 485 |
}
|
| 486 |
|
| 487 |
// @@@ New in 3.x, document.
|
| 488 |
/**
|
| 489 |
* Load a general geocoding service.
|
| 490 |
*/
|
| 491 |
function location_load_geocoder($geocoder) {
|
| 492 |
include_once drupal_get_path('module', 'location') .'/geocoding/'. $geocoder .'.inc';
|
| 493 |
}
|
| 494 |
|
| 495 |
/**
|
| 496 |
* Create a single line address.
|
| 497 |
*
|
| 498 |
* @param $location
|
| 499 |
* Array. The address parts
|
| 500 |
* @return
|
| 501 |
* String. The single line address
|
| 502 |
*/
|
| 503 |
function location_address2singleline($location = array()) {
|
| 504 |
// Check if its a valid address
|
| 505 |
if (empty($location)) {
|
| 506 |
return '';
|
| 507 |
}
|
| 508 |
|
| 509 |
$address = '';
|
| 510 |
if (!empty($location['street'])) {
|
| 511 |
$address .= $location['street'];
|
| 512 |
}
|
| 513 |
|
| 514 |
if (!empty($location['city'])) {
|
| 515 |
if (!empty($location['street'])) {
|
| 516 |
$address .= ', ';
|
| 517 |
}
|
| 518 |
|
| 519 |
$address .= $location['city'];
|
| 520 |
}
|
| 521 |
|
| 522 |
if (!empty($location['province'])) {
|
| 523 |
if (!empty($location['street']) || !empty($location['city'])) {
|
| 524 |
$address .= ', ';
|
| 525 |
}
|
| 526 |
|
| 527 |
// @@@ Fix this!
|
| 528 |
if (substr($location['province'], 0, 3) == $location['country'] .'-') {
|
| 529 |
$address .= substr($location['province'], 3);
|
| 530 |
watchdog('Location', 'BUG: Country found in province attribute.');
|
| 531 |
}
|
| 532 |
else {
|
| 533 |
$address .= $location['province'];
|
| 534 |
}
|
| 535 |
}
|
| 536 |
|
| 537 |
if (!empty($location['postal_code'])) {
|
| 538 |
if (!empty($address)) {
|
| 539 |
$address .= ' ';
|
| 540 |
}
|
| 541 |
$address .= $location['postal_code'];
|
| 542 |
}
|
| 543 |
|
| 544 |
if (!empty($location['country'])) {
|
| 545 |
$address .= ', '. $location['country'];
|
| 546 |
}
|
| 547 |
|
| 548 |
return $address;
|
| 549 |
}
|
| 550 |
|
| 551 |
function location_get_general_geocoder_list() {
|
| 552 |
static $list;
|
| 553 |
|
| 554 |
if (!count($list)) {
|
| 555 |
$files = file_scan_directory(drupal_get_path('module', 'location') .'/geocoding', '\.inc$', array('.', '..', 'CVS', '.svn'));
|
| 556 |
foreach ($files as $full_path_name => $fileinfo) {
|
| 557 |
$list[] = $fileinfo->name;
|
| 558 |
}
|
| 559 |
}
|
| 560 |
|
| 561 |
return $list;
|
| 562 |
}
|
| 563 |
|
| 564 |
/**
|
| 565 |
* The following is an array of all
|
| 566 |
* countrycode => country-name pairs as layed out in
|
| 567 |
* ISO 3166-1 alpha-2
|
| 568 |
*/
|
| 569 |
function location_get_iso3166_list($upper = FALSE) {
|
| 570 |
include_once DRUPAL_ROOT .'/includes/locale.inc';
|
| 571 |
|
| 572 |
$countries = country_get_list();
|
| 573 |
|
| 574 |
if (empty($upper)) {
|
| 575 |
return array_change_key_case($countries, CASE_LOWER);
|
| 576 |
}
|
| 577 |
return $countries;
|
| 578 |
}
|