You are here

function wunderground_weather_get_forecast_data in Wunderground weather 7

Get weather forecast from Wunderground.

File

./wunderground_weather.module, line 407
Wunderground weather module to display weather forecasts and current weather conditions in blocks.

Code

function wunderground_weather_get_forecast_data($block_number = '') {
  $location = variable_get('wunderground_weather_location_forecast_' . $block_number, FALSE);
  if ($location) {
    preg_match('#\\[(.*?)\\]#', variable_get('wunderground_weather_location_forecast_' . $block_number, ''), $match);
    $path = $match[1];
    $options = array(
      'key' => variable_get('wunderground_weather_api_key', ''),
      'data_feature' => 'forecast',
      'language' => 'lang:' . strtoupper(variable_get('wunderground_weather_language', 'EN')),
      'path' => $path,
    );
    $response = wunderground_weather_http_request($options, $path);
    $serialized_fields = variable_get('wunderground_weather_forecast_' . $block_number . '_fields');
    $data['fields'] = unserialize($serialized_fields);
    if ($response) {
      $data['days'] = $response['forecast']['simpleforecast']['forecastday'];

      // Set url for icons sets.
      foreach ($data['days'] as $nr => $day) {
        $icon = $data['days'][$nr]['icon'];
        $icon_set = variable_get('wunderground_weather_forecast_icons_' . $block_number);
        $data['days'][$nr]['icon_url'] = _wunderground_weather_get_icon_url($icon, $icon_set);
      }
    }
    else {
      $data['days'] = FALSE;
    }
  }
  else {
    $data['days'] = FALSE;
  }
  return $data;
}