You are here

function theme_yr_verdata_location_block in Yr Weatherdata 6

1 theme call to theme_yr_verdata_location_block()
yr_verdata_block in ./yr_verdata.module
Implementation of hook_block().

File

./yr_verdata.module, line 389
yr_verdata.module This file provides the yr_verdata forecast module.

Code

function theme_yr_verdata_location_block($rows) {
  $modpath = drupal_get_path('module', 'yr_verdata');
  drupal_add_css($modpath . '/yr_verdata.css');
  $output = '';

  // If we are just theming a single-location block, we still need to make it an array.
  if (!is_array($rows)) {
    $rows = array(
      $rows,
    );
  }
  foreach ($rows as $row) {

    // Make sure there are no punctuation in the url, as this could possibly lead to a malicious user
    // navigating elsewhere in the filesystem?
    $row->url = str_replace('.', '_', $row->url);
    _yr_verdata_xml($row->url);

    // Load the xml file.
    $local_dir = file_directory_path() . '/yr_verdata';
    $comps = explode('/', $row->url);
    $local_file = $local_dir . '/' . implode('_', $comps) . '.xml';
    $data = simplexml_load_file($local_file);

    // Some of the values we are putting in, needs to be "calculated".
    // Main symbol:
    $symbol = _yr_verdata_get_symbol($data->forecast->tabular->time[0]);

    // Wind:
    $wind = _yr_verdata_get_wind($data->forecast->tabular->time[0]);

    // Temperature:
    $temp = _yr_verdata_get_temp($data->forecast->tabular->time[0]);

    // Pressure:
    $pressure = $data->forecast->tabular->time[0]->pressure['value'] . $data->forecast->tabular->time[0]->pressure['unit'];

    // Time:
    $periods = _yr_periods();
    $this_time = _yr_format_time($data->forecast->tabular->time[0]['from'], 'custom', 'D d M') . '<br />' . $periods[(int) $data->forecast->tabular->time[0]['period']];
    $location = array(
      'name' => l($data->location->name, 'yr_verdata/' . $row->yid),
      'symbol' => $symbol,
      'wind' => $wind,
      'temp' => $temp,
      'precip' => t('@precip mm precipitation.', array(
        '@precip' => $data->forecast->tabular->time[0]->precipitation['value'],
      )),
      'pressure' => check_plain($pressure),
      'time' => $this_time,
    );
    $output .= theme('yr_verdata_block_location', $location);
  }
  if (count($rows) > 0) {
    $output .= '<div class="yr-credit"><p>' . t('<a href="!yrl" title="Go to yr.no to view forecasts for more than 7 million locations across the globe">Forecast from yr.no</a>', array(
      '!yrl' => 'http://yr.no',
    )) . '</p></div>';
  }
  return $output;
}