function weather_show_detailed_forecast in Weather 7.3
Same name and namespace in other branches
- 7.2 weather.common.inc \weather_show_detailed_forecast()
Display a detailed weather forecast for a given place.
Parameters
string $country: Country of place.
string $link: Link of place, as in the database. The link may contain an appended slash with more information about the display configuration.
1 string reference to 'weather_show_detailed_forecast'
- weather_menu in ./
weather.module - Implements hook_menu().
File
- ./
weather.common.inc, line 34 - Common functions in a separate file to reduce size of weather.module.
Code
function weather_show_detailed_forecast($country, $link) {
global $user;
// If the last part of the link contains an appended slash
// and a number, this indicates the display configuration of
// the system-wide display with the given number.
$display_type = 'default';
$display_number = 0;
$link_parts = explode('/', $link);
$last_link_element = array_pop($link_parts);
// Examine the last element of the link.
if (preg_match('/^[0-9]+$/', $last_link_element)) {
// Only digits, remove that part from the link.
$link = implode('/', $link_parts);
// Use the system-wide display with the given number.
$display_type = 'system-wide';
$display_number = $last_link_element;
}
elseif ($last_link_element == 'u') {
// Only the letter 'u', remove that part from the link.
$link = implode('/', $link_parts);
// Use the user's custom display.
$display_type = 'user';
$display_number = $user->uid;
}
// See if there is a matching place in the database.
$sql = db_select('weather_places')
->fields('weather_places', array(
'geoid',
'country',
'name',
'link',
))
->orderBy('name', 'ASC');
$and = db_and()
->where('UPPER(country) LIKE UPPER(:country)', array(
':country' => $country,
))
->where('UPPER(link) LIKE UPPER(:link)', array(
':link' => $link,
));
$sql
->condition($and);
$place = $sql
->execute()
->fetchObject();
if ($place !== FALSE) {
$name = $place->name;
// Check proper permission for access:
// If the place is already configured in a display, the user wants
// to see the detailed forecast of a display and just needs the
// permission 'access content'. This is checked in weather_menu().
// If the place is not configured in a display, this equals a
// search for a place. This need the permission 'access weather search page'.
$configured = db_query('SELECT * FROM {weather_displays_places} WHERE place_geoid = :geoid', array(
':geoid' => $place->geoid,
))
->fetchObject();
if ($configured === FALSE) {
if (!user_access('access weather search page')) {
return MENU_ACCESS_DENIED;
}
}
else {
$name = $configured->displayed_name;
}
$display = weather_get_display_config($display_type, $display_number);
$display->detailed = TRUE;
$forecasts = weather_get_weather($place->geoid, 0, $display->detailed);
$weather[0]['forecasts'] = $forecasts['forecasts'];
$weather[0]['utc_offset'] = $forecasts['utc_offset'];
$weather[0]['name'] = $name;
$weather[0]['geoid'] = $place->geoid;
$weather[0]['yr.no'] = _weather_get_link_for_geoid($place->geoid, 'yr.no');
return theme('weather_forecast_preprocess', array(
'weather' => $weather,
'display' => $display,
));
}
else {
// The specified link does not exist in the weather database.
return MENU_NOT_FOUND;
}
}