function addressfield_staticmap_clean_address in Address Field Static Map 7
Returns a Google Maps-friendly address from the Address Field format.
Parameters
array $address: An array containing parts of the address to use.
string $field_type: The type of field being processed.
Return value
array A string containing the address, formatted for Google / Mapquest.
2 calls to addressfield_staticmap_clean_address()
File
- ./
addressfield_staticmap.module, line 739 - Main file for the addressfield static map module.
Code
function addressfield_staticmap_clean_address(array $address, $field_type = 'addressfield') {
if ($field_type == 'addressfield') {
$address = _addressfield_staticmap_render_address($address);
// Remove newline from address prevents %0A in URL encode.
$address = str_replace(array(
"\r\n",
"\r",
"\n",
), ' ', $address);
// Add some commas so that the address can still be parsed by Google Map's
// API.
$address = preg_replace('/(<\\/[^>]+?>)(<[^>\\/][^>]*?>)/', '$1, $2', $address);
// Remove all HTML tags added by addressfield module.
$address = strip_tags($address);
}
else {
if ($field_type == 'location') {
$location = $address;
$address = array();
$location_parts = array();
if (isset($location['latitude']) && $location['latitude'] != 0 && isset($location['longitude']) && $location['longitude'] != 0) {
$location_parts = array(
'latitude',
'longitude',
);
}
else {
$location_parts = array(
'street',
'additional',
'city',
'province',
'postal_code',
'country',
);
}
foreach ($location_parts as $location_part) {
if (!empty($location[$location_part])) {
$address[] = $location[$location_part];
}
}
$address = implode(', ', $address);
}
}
return $address;
}