function yr_verdata_resolve_name in Yr Weatherdata 7
Same name and namespace in other branches
- 6.2 yr_verdata.module \yr_verdata_resolve_name()
Function for resolving the name of a location to use for display on pages and in blocks.
Parameters
$location: The location object as loaded from the database.
Return value
Returns the location name as set in the configuration form. One of 'name', 'name, region' or 'name, country'. This output is not safe, and should be cleaned up before being output to the user.
4 calls to yr_verdata_resolve_name()
- yr_verdata_block_info in ./
yr_verdata.module - Implementation of hook_block_info().
- yr_verdata_block_view in ./
yr_verdata.module - Implementation of hook_block_view().
- yr_verdata_page_all in ./
yr_verdata.module - Function for generating the main forecast page.
- yr_verdata_page_single in ./
yr_verdata.module - Function for generating a forecast page for a single location.
File
- ./
yr_verdata.module, line 439 - yr_verdata.module This file contains the code for getting the forecast from yr.no and displaying it on a Drupal site.
Code
function yr_verdata_resolve_name($location) {
$url = drupal_substr($location->url, 17);
$comps = explode('/', $url);
$nd = variable_get('yr_verdata_name_display', 4);
if ($nd == 4) {
return $location->name;
}
else {
$second_name = str_replace('_', ' ', trim($comps[$nd]));
$fb = variable_get('yr_verdata_name_fallback', 4);
$fallback = $fb == 4 ? $location->name : $location->name . ', ' . str_replace('_', ' ', trim($comps[$fb]));
$name = $second_name != $location->name ? $location->name . ', ' . $second_name : $fallback;
return $name;
}
}