function theme_weather_forecast_preprocess in Weather 7.2
Same name and namespace in other branches
- 7.3 weather_theme.inc \theme_weather_forecast_preprocess()
Custom theme function for preprocessing the weather display.
2 theme calls to theme_weather_forecast_preprocess()
- weather_block_view in ./
weather.module - Implements hook_block_view().
- weather_show_detailed_forecast in ./
weather.common.inc - Display a detailed weather forecast for a given place.
File
- ./
weather_theme.inc, line 27 - Prepare themed weather output.
Code
function theme_weather_forecast_preprocess($variables) {
$weather = $variables['weather'];
$display = $variables['display'];
// Create a result array.
foreach ($weather as $idx => $place) {
// Use a day counter to prepend "today" and "tomorrow" to forecast dates.
$day_counter = 0;
$forecasts = array();
foreach ($place['forecasts'] as $date => $time_ranges) {
$formatted_date = format_date(strtotime($date), 'weather');
if ($day_counter == 0) {
$formatted_date = t('Today, @date', array(
'@date' => $formatted_date,
));
}
elseif ($day_counter == 1) {
$formatted_date = t('Tomorrow, @date', array(
'@date' => $formatted_date,
));
}
$forecasts[$date]['formatted_date'] = $formatted_date;
// Calculate sunrise and sunset information, if desired.
if ($display->config['show_sunrise_sunset']) {
$forecasts[$date]['sun_info'] = _weather_calculate_sun_info($date, $place['utc_offset'], $place['geoid']);
}
foreach ($time_ranges as $time_range => $data) {
$condition = weather_format_condition($data['symbol']);
$forecasts[$date]['time_ranges'][$time_range]['condition'] = $condition;
$forecasts[$date]['time_ranges'][$time_range]['symbol'] = weather_format_image($data['symbol'], $condition);
$forecasts[$date]['time_ranges'][$time_range]['temperature'] = weather_format_temperature($data['temperature'], $display->config['temperature']);
if ($display->config['show_windchill_temperature']) {
$forecasts[$date]['time_ranges'][$time_range]['windchill'] = weather_format_windchill_temperature($data['temperature'], $data['wind_speed'], $display->config['temperature']);
}
$forecasts[$date]['time_ranges'][$time_range]['precipitation'] = t('!precipitation mm', array(
'!precipitation' => $data['precipitation'],
));
$forecasts[$date]['time_ranges'][$time_range]['pressure'] = weather_format_pressure($data['pressure'], $display->config['pressure']);
$forecasts[$date]['time_ranges'][$time_range]['wind'] = weather_format_wind($data['wind_direction'], $data['wind_speed'], $display->config['windspeed'], $display->config['show_abbreviated_directions'], $display->config['show_directions_degree']);
}
$day_counter++;
}
$weather[$idx]['forecasts'] = $forecasts;
if (isset($weather[$idx]['station'])) {
$weather[$idx]['station'] = weather_format_nearest_station($weather[$idx]['station'], $display);
}
}
if ($display->detailed) {
return theme('weather_detailed_forecast', array(
'weather' => $weather,
));
}
else {
return theme('weather', array(
'weather' => $weather,
));
}
}