You are here

function theme_weather_theming in Weather 6.5

Same name and namespace in other branches
  1. 7 weather_theme.inc \theme_weather_theming()

Custom theme function for preprocessing the weather block output

2 theme calls to theme_weather_theming()
weather_block in ./weather.module
Generate HTML for the weather block
weather_search_location in ./weather.module
Searches for the specified location, whether it is a place name or an ICAO code. For example, weather/fuhlsbüttel will display the weather for Hamburg-Fuhlsbüttel.

File

./weather.module, line 379
Display <acronym title="METeorological Aerodrome Report">METAR</acronym> weather data from anywhere in the world

Code

function theme_weather_theming($config, $metar) {

  // Set up variables which might be needed in the templates
  $weather['real_name'] = check_plain($config['real_name']);
  $weather['condition'] = _weather_format_condition($metar);
  $weather['image'] = _weather_get_image($metar);
  if (isset($metar['temperature']) and $config['units']['temperature'] != 'dont-display') {
    $weather = array_merge($weather, _weather_format_temperature($metar['temperature'], $metar['wind'], $config['units'], $config['settings']));
  }
  if (isset($metar['wind']) and $config['units']['windspeed'] != 'dont-display') {
    $weather['wind'] = _weather_format_wind($metar['wind'], $config['units'], $config['settings']);
  }
  if (isset($metar['pressure']) and $config['units']['pressure'] != 'dont-display') {
    $weather['pressure'] = _weather_format_pressure($metar['pressure'], $config['units']);
  }
  if (isset($metar['temperature']) and isset($metar['dewpoint']) and $config['units']['humidity'] != 'dont-display') {
    $weather['rel_humidity'] = _weather_format_relative_humidity($metar['temperature'], $metar['dewpoint']);
  }
  if (isset($metar['visibility']['kilometers']) and $config['units']['visibility'] != 'dont-display') {
    $weather['visibility'] = _weather_format_visibility($metar['visibility'], $config['units']);
  }
  if ($config['settings']['show_sunrise_sunset']) {

    // Check if there is a sunrise or sunset
    if ($metar['daytime']['no_sunrise']) {
      $weather['sunrise'] = t('No sunrise today');
    }
    else {
      if ($metar['daytime']['no_sunset']) {
        $weather['sunset'] = t('No sunset today');
      }
      else {

        // Set up timezone with a sensible default value
        $timezone = $config['settings']['sunrise_sunset_timezone'];

        // If the timezone is numeric, just use that value
        if (!is_numeric($timezone)) {
          if ($timezone == 'drupal') {

            // Use Drupal's default timezone or user's timezone
            $timezone = NULL;
          }
          else {

            // Fall back to using GMT
            $timezone = 0;
          }
        }

        // Try to extract a time format from the system wide date format
        $date_format_short = variable_get('date_format_short', 'm/d/Y - H:i');
        preg_match("/[GgHh].*?i(.*?[Aa])?/", $date_format_short, $matches);
        if (isset($matches[0])) {
          $format = $matches[0];
        }
        else {
          $format = 'G:i';
        }

        // If the selected timezone is "drupal", just show the time.
        // Otherwise, we append either "GMT" or the current GMT offset.
        if (is_null($timezone)) {

          // This is Drupal's default timezone, so do nothing.
        }
        else {
          if ($timezone == 0) {

            // This is GMT
            $format .= ' T';
          }
          else {

            // Append the GMT offset
            $format .= ' O';
          }
        }
        $text = format_date($metar['daytime']['sunrise_on'], 'custom', $format, $timezone);
        $weather['sunrise'] = t('Sunrise: !sunrise', array(
          '!sunrise' => $text,
        ));
        $text = format_date($metar['daytime']['sunset_on'], 'custom', $format, $timezone);
        $weather['sunset'] = t('Sunset: !sunset', array(
          '!sunset' => $text,
        ));
      }
    }
  }
  if (isset($metar['#raw']) and $config['settings']['show_unconverted_metar']) {
    $weather['metar'] = $metar['#raw'];
  }

  // If this is displayed as location block, show information about
  // which METAR station has been used for weather data
  if (isset($config['distance'])) {
    $weather['location'] = _weather_format_closest_station($config['distance'], $config['units'], $config['settings']);
  }
  if (isset($metar['reported_on'])) {
    $weather['reported_on'] = format_date($metar['reported_on']);
  }

  // Use compact block, if desired
  if ($config['settings']['show_compact_block']) {
    return theme('weather_compact', $weather);
  }
  else {
    return theme('weather', $weather);
  }
}