You are here

function getdirections_direction in Get Directions 6.2

Same name and namespace in other branches
  1. 6 getdirections.module \getdirections_direction()
  2. 7.3 getdirections.module \getdirections_direction()
  3. 7.2 getdirections.module \getdirections_direction()

Function to setup the map and form

Parameters

string $direction: Optional. The direction the supplied input applies to

string $location: Optional. The string to search with

string $country: Optional. The country

string $latlon: Optional. Comma delimited string containing latitude and longitude

Return value

Returns the themed map and form

11 calls to getdirections_direction()
getdirections_direction_box in ./getdirections.module
getdirections_latlon in ./getdirections.module
Function to setup the map and form
getdirections_n2u_setlocation in ./getdirections.module
Function to setup the map
getdirections_setlocation in ./getdirections.module
Function to setup the map and form
getdirections_setlocations in ./getdirections.module
Function to setup the map

... See full list

1 string reference to 'getdirections_direction'
getdirections_menu in ./getdirections.module
Implementation of hook_menu().

File

./getdirections.module, line 226
Fetches google map directions.

Code

function getdirections_direction($direction = '', $location = '', $country = '', $latlon = '', $id = 0, $type = 'node', $width = '', $height = '') {
  if (!getdirections_check()) {
    return t('You need to !c first.', array(
      '!c' => l('configure Getdirections', 'admin/settings/getdirections'),
    ));
  }
  $getdirections_defaults = getdirections_defaults();
  $getdirections_misc = getdirections_misc_defaults();
  getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  $getdirections_settings['switchfromto'] = $getdirections_misc['switchfromto'];
  drupal_add_js(array(
    'getdirections' => $getdirections_settings,
  ), 'setting');
  if ($getdirections_misc['keep_title'] && $id && $direction) {
    if ($direction == 'to') {
      $direction_translated = t('to');
    }
    elseif ($direction == 'from') {
      $direction_translated = t('from');
    }
    if ($type == 'node') {
      $node = node_load(array(
        'nid' => $id,
      ));
      drupal_set_title(t('Get directions @d !t', array(
        '@d' => $direction_translated,
        '!t' => $node->title,
      )));
    }
    elseif ($type == 'user') {
      $account = user_load(array(
        'uid' => $id,
      ));
      drupal_set_title(t('Get directions @d @t', array(
        '@d' => $direction_translated,
        '@t' => $account->name,
      )));
    }
    elseif ($type == 'location') {
      $t = getdirections_get_lid_title($id);
      if ($t) {
        drupal_set_title(t('Get directions @d @t', array(
          '@d' => $direction_translated,
          '@t' => $t,
        )));
      }
    }
  }
  if (empty($width)) {
    $width = $getdirections_defaults['width'];
  }
  if (empty($height)) {
    $height = $getdirections_defaults['height'];
  }

  // remove brackets if any
  $latlon = preg_replace("/^\\(|\\)\$/", '', $latlon);
  $form = drupal_get_form('getdirections_direction_form', $direction, $location, $country, $latlon);
  return theme('getdirections_show', $form, $width, $height, $id, $type);
}