You are here

function _weather_get_link_for_geoid in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather.common.inc \_weather_get_link_for_geoid()

Construct the link for the given GeoID.

Parameters

string $geoid: The GeoID to construct the link for.

string $destination: Destination to create the link for. Currently supported are 'system-wide', 'default', 'user', 'yr', and 'autocomplete'.

int $number: Optional number of display. Applies only to 'system-wide'.

Return value

string The link for the GeoID.

6 calls to _weather_get_link_for_geoid()
WeatherFunctionsTestCase::testFunction_weather_get_link_for_geoid in tests/functions.test
Test _weather_get_link_for_geoid().
weather_block_view in ./weather.module
Implements hook_block_view().
weather_search_autocomplete in ./weather.forms.inc
Search for a place, country, or link parts matching a partial string.
weather_search_location in ./weather.forms.inc
Search for a given location.
weather_show_detailed_forecast in ./weather.common.inc
Display a detailed weather forecast for a given place.

... See full list

File

./weather.common.inc, line 214
Common functions in a separate file to reduce size of weather.module.

Code

function _weather_get_link_for_geoid($geoid, $destination, $number = 1) {
  $info = weather_get_information_about_geoid($geoid);

  // Conversion rules for all link parts:
  // - Replace all spaces with an underscore.
  // - If the link part ends with a dot, use an underscore.
  $country = str_replace(' ', '_', $info->country);
  if (substr($country, -1) == '.') {
    $country[strlen($country) - 1] = '_';
  }
  $link = $country . '/' . $info->link;
  switch ($destination) {
    case 'system-wide':
      $link = 'weather/' . $link . '/' . $number;
      break;
    case 'default':
      $link = 'weather/' . $link;
      break;
    case 'user':
      $link = 'weather/' . $link . '/u';
      break;
    case 'yr':

      // Encode special characters except the '/' in the URL.
      // Otherwise, the request will fail on yr.no.
      $link = rawurlencode($link);
      $link = str_replace('%2F', '/', $link);
      $link = 'https://www.yr.no/place/' . $link . '/forecast.xml';
      break;
    case 'yr.no':
      $link = 'https://www.yr.no/place/' . $link . '/';
      break;
    case 'autocomplete':

      // Nothing to do here.
      break;
  }
  return $link;
}