/[drupal]/contributions/modules/location/location.inc
ViewVC logotype

Contents of /contributions/modules/location/location.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.99 - (show annotations) (download) (as text)
Mon Aug 31 22:09:34 2009 UTC (2 months, 3 weeks ago) by bdragon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.98: +6 -268 lines
File MIME type: text/x-php
WARNING -- PORT IN PROGRESS -- WARNING
This is a very very very preliminary port of some pieces of Location to D7.
There's a lot of work to do before this is remotely usable.
WARNING -- PORT IN PROGRESS -- WARNING


commit 9acd11c864797596209d5c12916e25e209a074cd
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:51:59 2009 -0500

    D7: Fix instance saving. I have now successfully put a location on a node in D7. (Of course there's a LOT to do still, but huzzah!)

commit 868ed6352debce3720e4093b50c42397e66cf991
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:40:22 2009 -0500

    Fix another class bug. Fix location fieldset theming (for a given value of "fix" of course)

commit d10a646b73da9c8b00c002a13483b986f0018340
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:31:43 2009 -0500

    D7: fix call to private api function that got renamed.

commit b79cea16e3c74d0cc7941cd4abcd3b616b793c9f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:28:00 2009 -0500

    D7: Put locative information into the vertical tabs thingie.

commit bf4df441e08a2ba1a0b6164a3688aa2275607f79
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:19:10 2009 -0500

    D7: Fix class arrayness and remove a stray & to make PHP stop crashing.

commit be9d1114797319f0015c266f3f6d4a6d398fea2f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:22:13 2009 -0500

    D7: files[] for location_node.

commit f6c32c64cb43f06fc5baca569826ccaf88b931c3
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:19:30 2009 -0500

    Fix infinite loops with drupal_render_children(). Remove the drupal_render() call at the end as well as it's nonsensical now and ALSO loops.

commit 125639604c4e5c29d03b3da9265b5fc766347794
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:18:10 2009 -0500

    D7 does not have an implicit #theme for elements anymore.

commit 4dcf85adcd30c0a53417fa3c53b2a4882b3cadf4
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:08:51 2009 -0500

    Use core's country list. (Which was pulled from location in the first place, hee hee)

commit ebb58524f2b9ef2eca7513971afbb9029743290f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 14:59:53 2009 -0500

    D7: Remove location_default_country variable and use core's site_default_country variable instead.

commit 4cf3950e1a3fa1369ad5bdecac4c3649b2783f2a
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 17:34:26 2009 -0500

    Add warning.

commit 934fdd3aecb4435b7215705d72998b13439b0920
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 17:14:51 2009 -0500

    D7: hook_node split, some of location_node.module, add file to track API changes.

commit 9e69f25d971fa6b5623fb026d5cfd6dba2cc2d70
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 16:17:18 2009 -0500

    D7: 'file' / 'file_path' stuff got rolled back.

commit 80cbd3b688c4a46dc349d449a1abc265894d619f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:42:45 2009 -0500

    D7: [#161301]

commit 35f82a0845ef020411a351fb307f821f78c5e397
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:38:53 2009 -0500

    bit more dbtngification.

commit 161280467e70664822e397405f3892628de7acdd
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:26:38 2009 -0500

    dbtngify uninstall hook. The rest I'll do later.

commit d6596a08f7a6a424df5109eafae3d7a5b7ce5522
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:20:52 2009 -0500

    DBTNGify location.module.
    Hopefully I didn't introduce bugs.

commit 6986ba94148c19d461808d61441c0033a4abfe31
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 16:02:59 2009 -0500

    Start a todo list.

commit 397adf2c619de9708e4135442204328aac7ae2d8
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:57:30 2009 -0500

    D7: Use '#markup' not '#value' for markup

commit c3fbd82f21e1af2f024871b247c01bc01ca71a7e
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:53:17 2009 -0500

    D7: The hook_menu() and hook_theme() "file" and "file path" keys have
    been removed.

commit cf8acf59887f73b997e50aedec95aa5a9784df84
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:51:55 2009 -0500

    D7: Module .info files must now specify all loadable code files
    explicitly.

commit f4cf33530c11406157745db44cfab0069287da36
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:51:01 2009 -0500

    D7: Permissions are required to have titles and descriptions.

commit 4a29c6fbafdc1ab106c95ed74df27f7dcfe03bca
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:41:46 2009 -0500

    Location HEAD starting point.
    Aug 19 2009 15:42
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 }

  ViewVC Help
Powered by ViewVC 1.1.2