function _location_supported_countries in Location 5
Same name and namespace in other branches
- 5.3 location.inc \_location_supported_countries()
- 6.3 location.inc \_location_supported_countries()
- 7.5 location.inc \_location_supported_countries()
- 7.3 location.inc \_location_supported_countries()
- 7.4 location.inc \_location_supported_countries()
Returns an associative array of countries currently supported by the location system where -> the keys represent the two-letter ISO code and -> the values represent the English name of the country. The array is sorted the index (i.e., by the short English name of the country).
Please note the different between "supported" countries and "configured" countries: A country being "supported" means that there is an include file to support the country while "configure" implies that the site admin has configured the site to actually use that country.
2 calls to _location_supported_countries()
- location_admin_settings in ./
location.module - Callback for admin/settings/location
- location_configured_countries in ./
location.inc - Returns an associative array of countries currently recognized by the site admin's configuration where: -> the keys represent the two-letter ISO code and -> the values represent the English name of the country.
File
- ./
location.inc, line 1124
Code
function _location_supported_countries() {
static $supported_countries = array();
// If this function has already been called this request, we can avoid a DB hit.
if (!empty($supported_countries)) {
return $supported_countries;
}
// Try first to load from cache, it's much faster than the scan below.
$cache = cache_get('location:supported-countries');
if (!empty($cache)) {
$supported_countries = unserialize($cache->data);
}
else {
// '<ISO two-letter code>' => '<English name for country>'
$iso_list = _location_get_iso3166_list();
$iso_keys = array_keys($iso_list);
if (is_dir(LOCATION_PATH . '/supported') && ($handle = opendir(LOCATION_PATH . '/supported'))) {
$matches = array();
while ($file = readdir($handle)) {
if (ereg('location.([a-z]{2}).inc', $file, $matches) && is_file(LOCATION_PATH . '/supported/' . $file)) {
if (in_array($matches[1], $iso_keys)) {
$supported_countries[] = $matches[1];
$matches = array();
}
}
}
}
$supported_countries = array_flip($supported_countries);
// In the foreach, here, $index is just an integer that we want to
// replace with the name of the country, where the key pointing to it
// is the two-letter ISO code for the country
foreach ($supported_countries as $code => $index) {
$supported_countries[$code] = $iso_list[$code];
}
array_multisort($supported_countries);
// Data is now in an array where key = <ISO code for country> and values = <English name for country>
// Cache our processed array before returning
cache_set('location:supported-countries', 'cache', serialize($supported_countries));
}
return $supported_countries;
}