function theme_weather_theming in Weather 7
Same name and namespace in other branches
- 6.5 weather.module \theme_weather_theming()
Custom theme function for preprocessing the weather display.
2 theme calls to theme_weather_theming()
- weather_block_view in ./
weather.module - Implement hook_block_view().
- weather_search_location in ./
weather.forms.inc - Search for a given location.
File
- ./
weather_theme.inc, line 27 - Prepare themed weather output.
Code
function theme_weather_theming($variables) {
$display = $variables['display'];
$location = $variables['location'];
$metar = $variables['metar'];
// Set up variables which will be needed in the templates.
$weather = new stdClass();
$weather->real_name = check_plain($location->real_name);
$weather->condition = weather_format_sky_condition($metar);
// Support a custom image directory. If the variable is not set or the specified
// file is not available, fall back to the default images of the module.
$path = variable_get('weather_image_directory', '');
$image = file_default_scheme() . '://' . $path . '/' . $metar->image . '.png';
if (!is_readable($image)) {
$image = drupal_get_path('module', 'weather') . '/images/' . $metar->image . '.png';
}
$size = getimagesize($image);
// Prepare the <img> tag
$weather->image = theme('image', array(
'path' => $image,
'width' => $size[0],
'height' => $size[1],
'alt' => $weather->condition,
'title' => $weather->condition,
'attributes' => array(
'class' => 'weather-image',
),
));
// Set up optional variables which might be displayed.
if (!empty($display->settings['data'])) {
$show = $display->settings['data'];
$units = $display->units;
if (!empty($show['temperature']) and isset($metar->temperature)) {
$weather->temperature = weather_format_temperature($metar->temperature, $units['temperature']);
if (!empty($display->settings['show_apparent_temperature'])) {
$weather->apparent_temperature = weather_format_apparent_temperature($metar, $units['temperature']);
}
}
if (!empty($show['wind']) and isset($metar->wind_direction)) {
// Set gusts speed to 0 if the database returned NULL.
if (empty($metar->wind_gusts)) {
$metar->wind_gusts = 0;
}
$weather->wind = weather_format_wind($metar->wind_speed, $metar->wind_direction, $metar->wind_gusts, $display->settings, $units['windspeed']);
}
if (!empty($show['pressure']) and isset($metar->pressure)) {
$weather->pressure = weather_format_pressure($metar->pressure, $units['pressure']);
}
if (!empty($show['humidity']) and isset($metar->dewpoint) and isset($metar->temperature)) {
$weather->rel_humidity = weather_format_relative_humidity($metar->temperature, $metar->dewpoint);
}
if (!empty($show['visibility']) and isset($metar->visibility)) {
$weather->visibility = weather_format_visibility($metar->visibility, $units['distance']);
}
if (!empty($show['suninfo']) and isset($metar->sunrise_on) and isset($metar->sunset_on)) {
$suninfo = weather_format_suninfo($metar->sunrise_on, $metar->sunset_on);
$weather->sunrise = $suninfo['sunrise'];
$weather->sunset = $suninfo['sunset'];
}
if (!empty($show['metar']) and isset($metar->raw)) {
$weather->metar = $metar->raw;
}
if (isset($metar->reported_on)) {
$weather->reported_on = format_date($metar->reported_on);
}
}
// If the original location is not identical to the weather station, show
// information about which METAR station has been used for weather data.
if (isset($location->distance)) {
$weather->station = weather_format_nearest_station($location, $display->units['distance'], $display->settings);
}
// Use compact block, if desired
if (!empty($display->settings['show_compact_block'])) {
return theme('weather_compact', array(
'weather' => $weather,
));
}
else {
return theme('weather', array(
'weather' => $weather,
));
}
}