You are here

getlocations.module in Get Locations 6

Same filename and directory in other branches
  1. 6.2 getlocations.module
  2. 7.2 getlocations.module
  3. 7 getlocations.module

Displays locations on a map. for Drupal 6 using version 3 googlemaps API

File

getlocations.module
View source
<?php

/**
 * @file
 * Displays locations on a map.
 * for Drupal 6
 * using version 3 googlemaps API
 */
define('GETLOCATIONS_PATH', drupal_get_path('module', 'getlocations'));

/**
 * Implementation of hook_help().
 */
function getlocations_help($path, $arg) {
  switch ($path) {
    case 'admin/help#getlocations':
      $output = '<p>' . t('Displays locations on a map.') . '</p>';
      return $output;
  }
}

/**
 * Implementation of hook_init().
 */
function getlocations_init() {
  module_load_include('inc', 'getlocations', 'getlocations.theme');
  if (module_exists('colorbox')) {
    $getlocations_colorbox = variable_get('getlocations_colorbox', array(
      'enable' => 0,
      'width' => 600,
      'height' => 600,
    ));
    $settings = array(
      'getlocations_colorbox' => $getlocations_colorbox,
    );
    drupal_add_js($settings, 'setting');
    drupal_add_js(GETLOCATIONS_PATH . '/js/getlocations_colorbox.js');
  }
}

/**
 * Implementation of hook_perm().
 */
function getlocations_perm() {
  return array(
    'access getlocations',
    'access user getlocations',
  );
}

/**
 * Implementation of hook_flush_caches().
 */
function getlocations_flush_caches() {
  getlocations_regenerate_markers();
}

/**
 * Implementation of hook_views_api().
 */
function getlocations_views_api() {
  return array(
    'api' => 2,
  );
}

/**
 * Implementation of hook_menu().
 */
function getlocations_menu() {
  $items = array();
  $items['admin/settings/getlocations'] = array(
    'title' => 'Get locations',
    'description' => 'Configure Get locations',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'getlocations_settings_form',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'getlocations.admin.inc',
  );

  // getlocations/node/$nid    # show all location on one node
  $items['getlocations/node/%getlocations_id'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_location',
    'page callback' => 'getlocations_nodemap',
    'page arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/user/$uid    # show all locations for a user
  $items['getlocations/user/%getlocations_id'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_user_location',
    'page callback' => 'getlocations_usermap',
    'page arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/users    # show all locations for all users
  $items['getlocations/users'] = array(
    'title' => 'View all user locations',
    'access callback' => 'getlocations_access_user_location',
    'page callback' => 'getlocations_usersmap',
    'type' => MENU_CALLBACK,
  );

  // getlocations/type/$type     # show all locations of nodes of content-type machine name
  $items['getlocations/type/%getlocations_type'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_location',
    'page callback' => 'getlocations_typemap',
    'page arguments' => array(
      2,
      3,
      4,
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/lids/1,2,3,4    # show lids
  $items['getlocations/lids/%getlocations_cdints'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_location',
    'page callback' => 'getlocations_lids',
    'page arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/nids/1,2,3,4    # show nids locations
  $items['getlocations/nids/%getlocations_cdints'] = array(
    'title' => 'Get locations',
    'access callback' => 'getlocations_access_location',
    'page callback' => 'getlocations_nids',
    'page arguments' => array(
      2,
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/info?lid    # ajax callback to fetch an address
  $items['getlocations/info'] = array(
    'page callback' => 'getlocations_info',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );

  // getlocations/lidinfo?lid    # ajax callback to fetch a link to the 'owner'
  $items['getlocations/lidinfo'] = array(
    'page callback' => 'getlocations_lidinfo',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['getlocations_box'] = array(
    'title' => 'Get locations',
    'access arguments' => array(
      'access getlocations',
    ),
    'page callback' => 'getlocations_box',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * menu placeholder functions
 */
function getlocations_id_load($arg) {
  return is_numeric($arg) && $arg > 0 ? $arg : FALSE;
}

/**
 * Check that the node type exists
 *
 */
function getlocations_type_load($arg) {
  $result = db_query("SELECT name FROM {node_type} WHERE type='%s'", array(
    $arg,
  ));
  $row = db_fetch_array($result);
  return isset($row['name']) && $row['name'] ? $arg : FALSE;
}
function getlocations_cdints_load($arg) {
  $arr = explode(',', $arg);
  foreach ($arr as $a) {
    if (!is_numeric($a) || $a < 1) {
      return FALSE;
    }
  }
  return $arg;
}

/**
 * menu access functions
 */
function getlocations_access_location() {
  if (module_exists('location') && user_access('access getlocations') && (module_exists('location_node') || module_exists('location_cck'))) {
    return TRUE;
  }
  return FALSE;
}
function getlocations_access_user_location() {
  if (module_exists('location') && user_access('access getlocations') && user_access('access user profiles') && user_access('access user getlocations') && module_exists('location_user')) {
    return TRUE;
  }
  return FALSE;
}

/**
 * Menu callback
 *
 * @param int $nid
 *
 * @return
 *   Returns a map of locations of a node
 *
 */
function getlocations_nodemap($nid) {
  $vid = getlocations_get_vid($nid);
  $locations = getlocations_load_locations($vid);
  $node = node_load($nid);
  $getlocations_defaults = getlocations_defaults();
  $marker = $getlocations_defaults['node_map_marker'];
  $typemarkers = getlocations_get_markertypes('node');
  if (isset($typemarkers[$node->type]) && $typemarkers[$node->type]) {
    $marker = $typemarkers[$node->type];
  }
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $ct = 0;
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        if (!isset($location['key'])) {
          $location['key'] = '';
        }
        else {
          if ($location['key'] == 'nid') {
            $location['lid'] = $nid;
          }
          elseif ($location['key'] == 'vid') {
            $location['lid'] = $nid;
          }
        }

        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }
        $ct++;
        $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($node->title), ENT_QUOTES);
        $latlons[] = array(
          $location['latitude'],
          $location['longitude'],
          $location['lid'],
          $name,
          $marker,
          $location['key'],
        );
      }
    }
  }
  if ($ct < 2) {
    unset($minmaxes);
    $minmaxes = '';
  }
  drupal_set_title(t('View @t locations', array(
    '@t' => $node->title,
  )));
  return getlocations_setlocations($latlons, $minmaxes, 'node', $node);
}

/**
 * Menu callback
 *
 * @param int $uid
 *
 * @return
 *   Returns a map of locations of a user
 *
 */
function getlocations_usermap($uid) {
  if (module_exists('location_user')) {
    $getlocations_defaults = getlocations_defaults();
    $marker = $getlocations_defaults['user_map_marker'];
    $locations = getlocations_load_locations($uid, 'uid');
    $account = user_load(array(
      'uid' => $uid,
    ));
    $latlons = array();
    $minmaxes = array(
      'minlat' => 0,
      'minlon' => 0,
      'maxlat' => 0,
      'maxlon' => 0,
    );
    $ct = 0;
    if (count($locations)) {

      // we should loop over them and dump bummers with no lat/lon
      foreach ($locations as $key => $location) {
        if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
          $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
          if (!isset($location['key'])) {
            $location['key'] = '';
          }
          else {
            $location['lid'] = $uid;
          }

          // per location marker
          if (isset($location['marker']) && !empty($location['marker'])) {
            $marker = $location['marker'];
          }
          $ct++;
          $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($account->name), ENT_QUOTES);
          $latlons[] = array(
            $location['latitude'],
            $location['longitude'],
            $location['lid'],
            $name,
            $marker,
            $location['key'],
          );
        }
      }
    }
    if ($ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    drupal_set_title(t('View user @t locations', array(
      '@t' => $account->name,
    )));
    return getlocations_setlocations($latlons, $minmaxes, 'user', $account);
  }
}

/**
 * Menu callback
 *
 *
 * @return
 *   Returns a map of locations of all the users
 *
 */
function getlocations_usersmap() {
  if (module_exists('location_user')) {
    $getlocations_defaults = getlocations_defaults();
    $marker = $getlocations_defaults['user_map_marker'];
    $latlons = array();
    $minmaxes = array(
      'minlat' => 0,
      'minlon' => 0,
      'maxlat' => 0,
      'maxlon' => 0,
    );
    $result = db_query("SELECT uid, name FROM {users} WHERE status=1");
    $ct = 0;
    while ($row = db_fetch_object($result)) {
      $uid = $row->uid;
      $locations = getlocations_load_locations($uid, 'uid');
      if (count($locations)) {

        // we should loop over them and dump bummers with no lat/lon
        foreach ($locations as $key => $location) {
          if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
            $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
            if (!isset($location['key'])) {
              $location['key'] = '';
            }
            else {
              $location['lid'] = $uid;
            }

            // per location marker
            if (isset($location['marker']) && !empty($location['marker'])) {
              $marker = $location['marker'];
            }
            $ct++;
            $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($row->name), ENT_QUOTES);
            $latlons[] = array(
              $location['latitude'],
              $location['longitude'],
              $location['lid'],
              $name,
              $marker,
              $location['key'],
            );
          }
        }
      }
    }
    if ($ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    return getlocations_setlocations($latlons, $minmaxes, 'users');
  }
}

/**
 * Menu callback
 *
 * @param string $type
 * A location enabled content type
 *
 * @return
 *   Returns a map of locations of all nodes of content-type $type
 *
 */
function getlocations_typemap($type, $loc_key = '', $loc_val = '') {
  $getlocations_defaults = getlocations_defaults();
  $marker = $getlocations_defaults['node_map_marker'];
  $typemarkers = getlocations_get_markertypes('node');
  if (isset($typemarkers[$type]) && $typemarkers[$type]) {
    $marker = $typemarkers[$type];
  }
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $result = db_query("SELECT nid, title FROM {node} WHERE type='%s'", array(
    $type,
  ));
  $ct = 0;
  while ($row = db_fetch_object($result)) {
    $nid = $row->nid;
    $vid = getlocations_get_vid($nid);
    $locations = getlocations_load_locations($vid);
    if (count($locations)) {

      // we should loop over them and dump bummers with no lat/lon
      foreach ($locations as $key => $location) {
        if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
          if ($loc_key && isset($location[$loc_key])) {
            if (drupal_strtolower($location[$loc_key]) != drupal_strtolower($loc_val)) {
              continue;
            }
          }
          $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
          if (!isset($location['key'])) {
            $location['key'] = '';
          }
          else {
            if ($location['key'] == 'nid') {
              $location['lid'] = $nid;
            }
            elseif ($location['key'] == 'vid') {
              $location['lid'] = $vid;
            }
          }

          // per location marker
          if (isset($location['marker']) && !empty($location['marker'])) {
            $marker = $location['marker'];
          }
          $ct++;
          $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($row->title), ENT_QUOTES);
          $latlons[] = array(
            $location['latitude'],
            $location['longitude'],
            $location['lid'],
            $name,
            $marker,
            $location['key'],
          );
        }
      }
    }
  }
  if ($ct < 2) {
    unset($minmaxes);
    $minmaxes = '';
  }
  return getlocations_setlocations($latlons, $minmaxes, $type);
}

/**
 * Menu callback
 *
 * @param string $lidlist
 * A comma-delimited list of location ids
 *
 * @return
 *   Returns a map of locations.
 *
 */
function getlocations_lids($lidlist) {
  $lidarr = explode(',', $lidlist);
  $locations = array();
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $marker = '';
  $ct = 0;
  foreach ($lidarr as $lid) {
    $locations[] = getlocations_load_location($lid);
  }
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        $location['key'] = '';
        $ct++;
        $name = htmlspecialchars_decode(strip_tags($location['name']), ENT_QUOTES);
        $latlons[] = array(
          $location['latitude'],
          $location['longitude'],
          $location['lid'],
          $name,
          $location['marker'],
          $location['key'],
        );
      }
    }
  }
  if ($ct < 2) {
    unset($minmaxes);
    $minmaxes = '';
  }
  return getlocations_setlocations($latlons, $minmaxes, 'lids');
}

/**
 * Menu callback
 *
 * @param string $nidlist
 * A comma-delimited list of node ids
 *
 * @return
 *   Returns a map of locations.
 *
 */
function getlocations_nids($nidlist) {
  $nidarr = explode(',', $nidlist);
  $locations = array();
  $latlons = array();
  $minmaxes = array(
    'minlat' => 0,
    'minlon' => 0,
    'maxlat' => 0,
    'maxlon' => 0,
  );
  $typemarkers = getlocations_get_markertypes('node');
  $ct = 0;
  foreach ($nidarr as $nid) {
    $vid = getlocations_get_vid($nid);
    $locs = getlocations_load_locations($vid);
    if (count($locs)) {
      foreach ($locs as $key => $loc) {
        $type = getlocations_get_nodetype($nid);
        $loc['marker'] = $typemarkers[$type];
        $locations[] = $loc;
      }
    }
  }
  if (count($locations)) {

    // we should loop over them and dump bummers with no lat/lon
    foreach ($locations as $key => $location) {
      if (getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        if (!isset($location['key'])) {
          $location['key'] = '';
        }
        else {
          if ($location['key'] == 'nid') {
            $location['lid'] = $nid;
          }
          elseif ($location['key'] == 'vid') {
            $location['lid'] = $vid;
          }
        }
        $ct++;
        $name = htmlspecialchars_decode(strip_tags($location['name']), ENT_QUOTES);
        $latlons[] = array(
          $location['latitude'],
          $location['longitude'],
          $location['lid'],
          $name,
          $location['marker'],
          $location['key'],
        );
      }
    }
  }
  if ($ct < 2) {
    unset($minmaxes);
    $minmaxes = '';
  }
  return getlocations_setlocations($latlons, $minmaxes, 'nids');
}

/**
 * Set up javascript settings and map
 */
function getlocations_setlocations($latlons, $minmaxes = '', $type = 'node', $node = '', $width = '', $height = '') {
  if (!getlocations_check()) {
    return t('You need to !c first.', array(
      '!c' => l('configure Getlocations', 'admin/settings/getlocations'),
    ));
  }
  global $language;
  $getlocations_defaults = getlocations_defaults();
  $mapid = getlocations_setup_map($getlocations_defaults);
  getlocations_js_settings_do($getlocations_defaults, $latlons, $minmaxes, $mapid);
  if (empty($width)) {
    $width = $getlocations_defaults['width'];
  }
  if (empty($height)) {
    $height = $getlocations_defaults['height'];
  }
  return theme('getlocations_show', $width, $height, $getlocations_defaults, $mapid, $type, $node);
}

/**
 * Function to setup the map scripts
 *
 * @param $defaults
 *   Required. the current settings.
 * Sets up the call to googlemaps, css and the relevant getlocations js in html head
 */
function getlocations_setup_map($defaults) {
  static $getlocations_mapid;
  if (!isset($getlocations_mapid) || empty($getlocations_mapid)) {
    $getlocations_mapid = 0;
  }
  $getlocations_mapid++;
  getlocations_setup_js($defaults);

  // Generate unique Map ID.
  $mapid = 'key_' . $getlocations_mapid;
  return $mapid;
}

/**
 * Function to setup the map scripts
 *
 * @param $defaults
 *   Required. the current settings.
 * Sets up the call to googlemaps, css and the relevant getlocations js in html head
 */
function getlocations_setup_js($defaults) {
  global $language, $getlocations_setmap;
  $current_js = drupal_get_js();
  $current_css = drupal_get_css();

  // v3 googlemaps API
  $key = variable_get('getlocations_api3_key', '');
  $query = array();
  if (!empty($key)) {
    $query['key'] = $key;
  }
  $query['sensor'] = 'false';
  $query['language'] = $language->language;
  $libraries = array();
  if ($defaults['panoramio_use']) {
    $libraries[] = 'panoramio';
  }
  if ($defaults['places']) {
    $libraries[] = 'places';
  }
  if ($defaults['weather_use']) {
    $libraries[] = 'weather';
  }

  // more libraries here
  // load libraries if any
  if (count($libraries)) {
    $query['libraries'] = implode(',', $libraries);
  }
  $scheme = 'http';
  if ($defaults['use_https']) {
    $scheme = 'https';
  }
  if (empty($getlocations_setmap)) {
    $gmapdomain = "maps.google.com/maps/api/js";
    if (!empty($key)) {
      $gmapdomain = "maps.googleapis.com/maps/api/js";
    }
    $gmaplink = '<script src="' . url($scheme . '://' . $gmapdomain, array(
      'query' => $query,
    )) . '" type="text/javascript"></script>';
    drupal_set_html_head($gmaplink);
  }
  $getlocations_setmap = 1;
  if (!stristr($current_css, GETLOCATIONS_PATH . '/getlocations.css')) {
    drupal_add_css(GETLOCATIONS_PATH . '/getlocations.css');
  }
  if (!stristr($current_js, GETLOCATIONS_PATH . '/js/icons.js')) {
    drupal_add_js(GETLOCATIONS_PATH . '/js/icons.js');
  }
  $markerfile = getlocations_get_markerfile();
  if ($markerfile && !stristr($current_js, $markerfile)) {
    drupal_add_js($markerfile);
  }
  $getlocations_paths = getlocations_paths_get();
  if ($defaults['markermanagertype'] == 1 && !stristr($current_js, $getlocations_paths['markermanager_path'])) {
    drupal_add_js($getlocations_paths['markermanager_path']);
  }
  elseif ($defaults['markermanagertype'] == 2 && !stristr($current_js, $getlocations_paths['markerclusterer_path'])) {
    drupal_add_js($getlocations_paths['markerclusterer_path']);
  }
  if ($defaults['markeraction'] == 2 && !stristr($current_js, $getlocations_paths['infobubble_path'])) {
    drupal_add_js($getlocations_paths['infobubble_path']);
    if (file_exists($getlocations_paths['infobubble_options_path'])) {
      drupal_add_js($getlocations_paths['infobubble_options_path']);
    }
  }
  if (!stristr($current_js, GETLOCATIONS_PATH . '/js/getlocations.js')) {
    drupal_add_js(GETLOCATIONS_PATH . '/js/getlocations.js');
  }
}

/**
 * Some defaults.
 *
 * @return
 *   Returns the current settings
 */
function getlocations_defaults() {
  $defaults = array(
    'api_version' => 3,
    'width' => '300px',
    'height' => '200px',
    'zoom' => 3,
    'controltype' => 'small',
    'pancontrol' => 1,
    'latlong' => '40,0',
    'maptype' => 'Map',
    'mtc' => 'standard',
    'baselayers' => array(
      'Map' => 1,
      'Satellite' => 1,
      'Hybrid' => 1,
      'Physical' => 1,
    ),
    'behavior' => array(
      'scale' => 0,
      'overview' => 0,
      'overview_opened' => 0,
      'scrollwheel' => 0,
    ),
    'streetview_show' => 0,
    'trafficinfo' => 0,
    'trafficinfo_state' => 0,
    'bicycleinfo' => 0,
    'bicycleinfo_state' => 0,
    'transitinfo' => 0,
    'transitinfo_state' => 0,
    'panoramio_use' => 0,
    'panoramio_show' => 0,
    'panoramio_state' => 0,
    'places' => 0,
    'poi_show' => 1,
    'transit_show' => 1,
    'node_map_marker' => 'drupal',
    'user_map_marker' => 'drupal',
    'markeraction' => 0,
    'markeractiontype' => 1,
    'minzoom' => 6,
    'maxzoom' => 16,
    'nodezoom' => 12,
    'markermanagertype' => 1,
    'usemarkermanager' => 1,
    'useclustermanager' => 0,
    'markerclusterer_style' => -1,
    'markerclusterer_zoom' => -1,
    'markerclusterer_size' => -1,
    'markerclusterer_minsize' => -1,
    'pansetting' => 2,
    'draggable' => 1,
    'styles' => '',
    'returnlink_page_enable' => 0,
    'returnlink_page_link' => t('Return to Page'),
    'returnlink_user_enable' => 0,
    'returnlink_user_link' => t('Return to User'),
    'use_https' => isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 1 : 0,
    'custom_content_enable' => 0,
    'custom_content_source' => '',
    'weather_use' => 0,
    'weather_show' => 0,
    'weather_state' => 0,
    'weather_temp' => 1,
    'weather_speed' => 1,
    'weather_label' => 0,
    'weather_cloud' => 1,
    'weather_cloud_state' => 0,
    'weather_clickable' => 1,
    'weather_info' => 1,
    'map_backgroundcolor' => '',
  );
  $getlocations_defaults = variable_get('getlocations_default', array());

  // array_merge deletes things in $defaults that are not in $getlocations_defaults ;-/
  // roll my own
  $newdefaults = array();
  foreach ($defaults as $k => $v) {
    if (is_array($v)) {
      foreach ($defaults[$k] as $k1 => $v1) {
        if (isset($getlocations_defaults[$k][$k1])) {
          $newdefaults[$k][$k1] = $getlocations_defaults[$k][$k1];
        }
        else {
          $newdefaults[$k][$k1] = $v1;
        }
      }
    }
    else {
      if (isset($getlocations_defaults[$k])) {
        $newdefaults[$k] = $getlocations_defaults[$k];
      }
      else {
        $newdefaults[$k] = $v;
      }
    }
  }
  return $newdefaults;
}

/**
 * Function to check if the configuration has been done yet
 *
 * @return
 *   Returns true or false
 */
function getlocations_check() {
  $check = variable_get('getlocations_default', 'xxx');
  if ($check == 'xxx') {
    return FALSE;
  }
  return TRUE;
}

/**
 * Function to check a lat,lon string
 *
 * @param string $latlon
 *
 * @return
 *   Returns true or false
 */
function getlocations_latlon_check($latlon) {
  if (!empty($latlon) && preg_match("/[0-9.\\-],[0-9.\\-]/", $latlon)) {
    $ll = explode(',', $latlon);
    if (!($ll[0] == 0 && $ll[1] == 0) && isset($ll[0]) && is_numeric($ll[0]) && isset($ll[1]) && is_numeric($ll[1])) {
      return $latlon;
    }
  }
  return FALSE;
}

/**
 * Function to get the vid from node table.
 *
 * @param int $nid
 *
 * @return
 *   Returns vid.
 */
function getlocations_get_vid($nid) {
  $result = db_query('SELECT vid FROM {node} WHERE nid=%d', array(
    $nid,
  ));
  $row = db_fetch_array($result);
  return isset($row['vid']) && $row['vid'] ? $row['vid'] : FALSE;
}
function getlocations_get_nid_from_lid($lid) {
  if ($lid) {
    $result = db_query('SELECT nid FROM {location_instance} WHERE lid=%d', array(
      $lid,
    ));
    $row = db_fetch_array($result);
    return isset($row['nid']) && $row['nid'] ? $row['nid'] : FALSE;
  }
}
function getlocations_get_uid_from_lid($lid) {
  if ($lid) {
    $result = db_query('SELECT uid FROM {location_instance} WHERE lid=%d', array(
      $lid,
    ));
    $row = db_fetch_array($result);
    return isset($row['uid']) && $row['uid'] ? $row['uid'] : FALSE;
  }
}

// ajax callback to fill infobubble
function getlocations_info() {
  $lid = $_GET['lid'];
  $location = getlocations_load_location($lid);
  $location['nid'] = 0;
  $location['uid'] = 0;
  if ($nid = getlocations_get_nid_from_lid($lid)) {
    $location['nid'] = $nid;
  }
  elseif ($uid = getlocations_get_uid_from_lid($lid)) {
    $location['uid'] = $uid;
  }
  $content = theme('getlocations_info', $location);
  print $content;
  exit;
}

// ajax callback to provide a link
function getlocations_lidinfo() {
  $lid = $_GET['lid'];
  $content = FALSE;
  if ($nid = getlocations_get_nid_from_lid($lid)) {
    $content = '/node/' . $nid;
  }
  elseif ($uid = getlocations_get_uid_from_lid($lid)) {
    $content = '/user/' . $uid;
  }
  print $content;
  exit;
}

/**
 * Get the list of marker titles.
 * adapted from gmap
 */
function getlocations_get_marker_titles($reset = FALSE) {
  static $titles;
  if (!$reset) {
    if (is_array($titles)) {
      return $titles;
    }
    $cached = cache_get('getlocations_marker_titles', 'cache');
    if (!empty($cached)) {
      $titles = $cached->data;
      if (is_array($titles)) {
        return $titles;
      }
    }
  }
  module_load_include('inc', 'getlocations', 'getlocations.markerinfo');
  $titles = _getlocations_get_marker_titles();
  cache_set('getlocations_marker_titles', $titles, 'cache');
  return $titles;
}

/**
 * Get the JSON icon data for all the default markers.
 */
function getlocations_get_icondata($reset = FALSE) {
  static $icons;
  if (is_array($icons) && !$reset) {
    return $icons;
  }
  $icons = cache_get('getlocations_icondata');
  if ($icons) {
    $icons = $icons->data;
  }
  if ($reset || !$icons) {
    module_load_include('inc', 'getlocations', 'getlocations.markerinfo');
    $icons = _getlocations_get_icondata();
  }
  cache_set('getlocations_icondata', $icons, 'cache');
  return $icons;
}

/**
 * Regenerate the markerdata file.
 */
function getlocations_regenerate_markers() {
  $contents = '';
  $contents .= "// Getlocations marker image data.\n";
  $contents .= "Drupal.getlocations.iconpath = " . drupal_to_js(base_path()) . ";\n";
  $contents .= "Drupal.getlocations.icondata = " . drupal_to_js(getlocations_get_icondata(TRUE)) . ";\n";

  // Create the js/ within the files folder.
  $jspath = getlocations_get_markerfile(TRUE, FALSE);
  $jsfile = getlocations_get_markerfile(FALSE, FALSE);
  if ($jspath && $jsfile && file_check_directory($jspath, FILE_CREATE_DIRECTORY) && file_save_data($contents, $jsfile, FILE_EXISTS_REPLACE)) {

    // Also regenerate the cached marker titles array
    getlocations_get_marker_titles(TRUE);
  }
  else {

    // failed
    drupal_set_message(t('Getlocations is unable to save the marker bundle, so the markers will not work. Please check file system permissions of %filepath!', array(
      '%filepath' => $jsfile,
    )), 'error');
    watchdog('getlocations', 'Getlocations write error when saving the marker bundle to %filepath.', array(
      '%filepath' => $jsfile,
    ), WATCHDOG_ERROR);
  }
}
function getlocations_get_markerfile($dir = FALSE, $check = TRUE) {
  if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {

    // private
    $markerpath = '';
    $markerfile = variable_get('getlocations_private_markerfile', '');
    if ($markerfile && preg_match("~^(.*)/getlocations_markers.js~", $markerfile, $matches)) {
      $markerpath = $matches[1];
    }
  }
  else {
    $markerpath = file_create_path('getlocations');
    $markerfile = '';
    if ($markerpath) {
      $markerfile = $markerpath . '/getlocations_markers.js';
    }
  }
  if ($dir && $markerpath) {
    if ($check) {
      if (file_exists($markerpath)) {
        return $markerpath;
      }
    }
    else {
      return $markerpath;
    }
  }
  elseif ($markerfile) {
    if ($check) {
      if (file_exists($markerfile)) {
        return $markerfile;
      }
    }
    else {
      return $markerfile;
    }
  }
  return FALSE;
}

/**
 * hook_getlocations_markerdir
 * from jhm http://drupal.org/user/15946
 */
function getlocations_getlocations_markerdir() {
  $markerdir = libraries_get_path('getlocations') . '/markers';
  return $markerdir;
}

/**
 * @param int $ct $location $minmaxes
 *
 * @return
 *   Returns $minmaxes
 *
 */
function getlocations_do_minmaxes($ct, $location, $minmaxes) {
  if ($ct) {

    // latitudes
    if ($location['latitude'] > $minmaxes['maxlat']) {
      $minmaxes['maxlat'] = $location['latitude'];
    }
    if ($location['latitude'] < $minmaxes['minlat']) {
      $minmaxes['minlat'] = $location['latitude'];
    }

    // longitudes
    if ($location['longitude'] > $minmaxes['maxlon']) {
      $minmaxes['maxlon'] = $location['longitude'];
    }
    if ($location['longitude'] < $minmaxes['minlon']) {
      $minmaxes['minlon'] = $location['longitude'];
    }
  }
  else {
    $minmaxes['minlat'] = $location['latitude'];
    $minmaxes['maxlat'] = $location['latitude'];
    $minmaxes['minlon'] = $location['longitude'];
    $minmaxes['maxlon'] = $location['longitude'];
  }
  return $minmaxes;
}

// for colorbox and suchlike
function getlocations_box() {
  $a1 = FALSE;
  $a2 = FALSE;
  $a3 = FALSE;
  $a4 = FALSE;
  if (arg(1)) {
    $a1 = arg(1);
  }
  if (arg(2)) {
    $a2 = arg(2);
  }
  if (arg(3)) {
    $a3 = arg(3);
  }
  if (arg(4)) {
    $a4 = arg(4);
  }
  $content = '';

  // $a1 can be node, user, users, type, lids, nids
  if ($a1 == 'node' && $a2) {
    $content .= getlocations_nodemap($a2);
  }
  elseif ($a1 == 'user' && $a2) {
    $content .= getlocations_usermap($a2);
  }
  elseif ($a1 == 'users') {
    $content .= getlocations_usersmap();
  }
  elseif ($a1 == 'type' && $a2) {
    $content .= getlocations_typemap($a2, $a3, $a4);
  }
  elseif ($a1 == 'lids' && $a2) {
    $content .= getlocations_lids($a2);
  }
  elseif ($a1 == 'nids' && $a2) {
    $content .= getlocations_nids($a2);
  }
  $output = theme('getlocations_box', $content);
  print $output;
  exit;
}
function getlocations_get_types() {
  $options = array();
  foreach (node_get_types() as $type => $object) {
    if (getlocations_check_node($type)) {
      $options[$type] = $object->name;
    }
  }
  return $options;
}
function getlocations_check_node($type) {
  $module = FALSE;
  if (module_exists('location_node')) {
    return TRUE;
  }
  if (module_exists('location_cck')) {
    $module = 'location_cck';
  }
  if ($module) {
    $sql = "SELECT i.type_name FROM {content_node_field} f, {content_node_field_instance} i ";
    $sql .= "WHERE f.field_name = i.field_name ";
    $sql .= "AND f.module = i.widget_module ";
    $sql .= "AND f.module = '" . $module . "' ";
    $sql .= "AND i.type_name = '" . $type . "' ";
    $sql .= "AND f.active=1 ";
    $sql .= "AND i.widget_active=1 ";
    $data = '';
    $result = db_query($sql);
    if (count($result) > 0) {
      $data = db_fetch_array($result);
      if ($data != FALSE) {
        return TRUE;
      }
    }
  }
  return FALSE;
}
function getlocations_get_markertypes($type) {
  $getlocations_defaults = getlocations_defaults();
  $default_marker = $getlocations_defaults['node_map_marker'];
  $markertypes = array();
  if ($type == 'node') {
    $content_types = getlocations_get_types();
    $getlocations_node_marker = variable_get('getlocations_node_marker', array(
      'enable' => 0,
    ));
    foreach ($content_types as $content_type => $name) {
      if ($getlocations_node_marker['enable'] && isset($getlocations_node_marker['content_type'][$content_type]['map_marker'])) {
        $markertypes[$content_type] = $getlocations_node_marker['content_type'][$content_type]['map_marker'];
      }
      else {
        $markertypes[$content_type] = $default_marker;
      }
    }
    return $markertypes;
  }
  else {
    return FALSE;
  }
}
function getlocations_get_nodetype($nid) {
  $result = db_query('SELECT type FROM {node} WHERE nid=%d', array(
    $nid,
  ));
  $row = db_fetch_array($result);
  return isset($row['type']) && $row['type'] ? $row['type'] : FALSE;
}
function getlocations_js_settings_do($defaults, $latlons, $minmaxes, $mapid) {
  global $language;
  $lla = explode(',', $defaults['latlong']);
  $settings = array(
    $mapid => array(
      'lat' => $lla[0],
      'lng' => $lla[1],
      'mylocale' => $language->language,
      'zoom' => $defaults['zoom'],
      'maptype' => $defaults['maptype'],
      'controltype' => $defaults['controltype'],
      'mtc' => $defaults['mtc'],
      'baselayers' => $defaults['baselayers'],
      'scale' => $defaults['behavior']['scale'],
      'overview' => $defaults['behavior']['overview'],
      'overview_opened' => $defaults['behavior']['overview_opened'],
      'scrollwheel' => $defaults['behavior']['scrollwheel'],
      'trafficinfo' => $defaults['trafficinfo'],
      'trafficinfo_state' => $defaults['trafficinfo_state'],
      'bicycleinfo' => $defaults['bicycleinfo'],
      'bicycleinfo_state' => $defaults['bicycleinfo_state'],
      'transitinfo' => $defaults['transitinfo'],
      'transitinfo_state' => $defaults['transitinfo_state'],
      'streetview_show' => $defaults['streetview_show'],
      'pancontrol' => $defaults['pancontrol'],
      'panoramio_use' => $defaults['panoramio_use'],
      'panoramio_show' => $defaults['panoramio_show'],
      'panoramio_state' => $defaults['panoramio_state'],
      'poi_show' => $defaults['poi_show'],
      'transit_show' => $defaults['transit_show'],
      'map_marker' => $defaults['node_map_marker'],
      'markeraction' => $defaults['markeraction'],
      'markeractiontype' => $defaults['markeractiontype'],
      'minzoom' => $defaults['minzoom'],
      'maxzoom' => $defaults['maxzoom'],
      'nodezoom' => $defaults['nodezoom'],
      'markermanagertype' => $defaults['markermanagertype'],
      'usemarkermanager' => $defaults['usemarkermanager'],
      'useclustermanager' => $defaults['useclustermanager'],
      'markerclusterer_style' => $defaults['markerclusterer_style'],
      'markerclusterer_zoom' => $defaults['markerclusterer_zoom'],
      'markerclusterer_size' => $defaults['markerclusterer_size'],
      'markerclusterer_minsize' => $defaults['markerclusterer_minsize'],
      'pansetting' => $defaults['pansetting'],
      'draggable' => $defaults['draggable'],
      'styles' => $defaults['styles'],
      'datanum' => count($latlons),
      'latlons' => $latlons,
      'minmaxes' => empty($minmaxes) ? '' : implode(',', $minmaxes),
      'custom_content_enable' => $defaults['custom_content_enable'],
      'weather_use' => $defaults['weather_use'],
      'map_backgroundcolor' => $defaults['map_backgroundcolor'],
    ),
  );
  if ($defaults['weather_use']) {
    $settings[$mapid]['weather_show'] = $defaults['weather_show'];
    $settings[$mapid]['weather_state'] = $defaults['weather_state'];
    $settings[$mapid]['weather_temp'] = $defaults['weather_temp'];
    $settings[$mapid]['weather_speed'] = $defaults['weather_speed'];
    $settings[$mapid]['weather_label'] = $defaults['weather_label'];
    $settings[$mapid]['weather_cloud'] = $defaults['weather_cloud'];
    $settings[$mapid]['weather_cloud_state'] = $defaults['weather_cloud_state'];
    $settings[$mapid]['weather_clickable'] = $defaults['weather_clickable'];
    $settings[$mapid]['weather_info'] = $defaults['weather_info'];
  }
  drupal_add_js(array(
    'getlocations' => $settings,
  ), 'setting');
  if ($defaults['markermanagertype'] == 2) {
    if (file_exists(GETLOCATIONS_PATH . '/getlocations.markercluster_override.inc')) {
      module_load_include('inc', 'getlocations', 'getlocations.markercluster_override');
    }
    else {
      module_load_include('inc', 'getlocations', 'getlocations.markercluster');
    }
    $markerclusterer_styles = getlocations_get_markerclusterer_styles();
    drupal_add_js(array(
      'getlocations_markerclusterer' => $markerclusterer_styles,
    ), 'setting');
  }
}
function getlocations_load_locations($id, $key = 'vid') {
  $locations = location_load_locations($id, $key);
  return $locations;
}
function getlocations_load_location($lid) {
  $location = location_load_location($lid);
  if ($location) {
    if ($nid = getlocations_get_nid_from_lid($lid)) {
      $typemarkers = getlocations_get_markertypes('node');
      $type = getlocations_get_nodetype($nid);
      $location['marker'] = $typemarkers[$type];
    }
    elseif ($uid = getlocations_get_uid_from_lid($lid)) {
      $getlocations_defaults = getlocations_defaults();
      $location['marker'] = $getlocations_defaults['user_map_marker'];
    }
  }
  return $location;
}

/**
 * Some form helper functions
 * for admin and views plugin style
 */
function getlocations_element_map_marker($title, $options, $default) {
  $element = array(
    '#type' => 'select',
    '#title' => $title,
    '#options' => $options,
    '#default_value' => $default,
  );
  return $element;
}
function getlocations_element_map_tf($title, $default, $size, $maxlength, $description = '', $required = TRUE) {
  $element = array(
    '#type' => 'textfield',
    '#title' => $title,
    '#default_value' => $default,
    '#size' => $size,
    '#maxlength' => $maxlength,
    '#required' => $required,
  );
  if ($description) {
    $element['#description'] = $description;
  }
  return $element;
}
function getlocations_element_map_zoom($title, $default, $description = '') {
  $element = array(
    '#type' => 'select',
    '#title' => $title,
    '#default_value' => $default,
    '#options' => drupal_map_assoc(range(0, 20)),
  );
  if (!empty($description)) {
    $element['#description'] = $description;
  }
  return $element;
}
function getlocations_element_map_zoom_controltype($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Zoom Control type'),
    '#options' => array(
      'none' => t('None'),
      'default' => t('Default'),
      'small' => t('Small'),
      'large' => t('Large'),
    ),
    '#default_value' => $default,
  );
  return $element;
}
function getlocations_element_map_checkbox($title, $default, $description = '') {
  $element = array(
    '#type' => 'checkbox',
    '#title' => $title,
    '#default_value' => $default,
    '#return_value' => 1,
  );
  if (!empty($description)) {
    $element['#description'] = $description;
  }
  return $element;
}
function getlocations_element_map_mtc($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Map Control Type'),
    '#options' => array(
      'none' => t('None'),
      'standard' => t('Horizontal bar'),
      'menu' => t('Dropdown'),
    ),
    '#default_value' => $default,
  );
  return $element;
}
function getlocations_element_map_maptype($default, $baselayers) {
  $options = array();
  $layers = array(
    'Map' => t('Standard street map'),
    'Satellite' => t('Standard satellite map'),
    'Hybrid' => t('Hybrid satellite map'),
    'Physical' => t('Terrain map'),
  );
  foreach ($layers as $key => $layer) {
    if ($baselayers[$key]) {
      $options[$key] = $layer;
    }
  }
  $element = array(
    '#type' => 'select',
    '#title' => t('Default map type'),
    '#options' => $options,
    '#default_value' => $default,
  );
  return $element;
}
function getlocations_element_map_baselayers($view, $default) {

  // Map Satellite Hybrid Physical
  if ($view == 'Map') {
    $title = t('Standard street map');
    $description = t('The standard default street map.');
  }
  elseif ($view == 'Satellite') {
    $title = t('Standard satellite map');
    $description = t('Satellite view without street overlay.');
  }
  elseif ($view == 'Hybrid') {
    $title = t('Hybrid satellite map');
    $description = t('Satellite view with street overlay.');
  }
  elseif ($view == 'Physical') {
    $title = t('Terrain map');
    $description = t('Map with physical data (terrain, vegetation.)');
  }
  if ($title) {
    $element = getlocations_element_map_checkbox($title, $default, $description);
    return $element;
  }
  return FALSE;
}
function getlocations_element_map_pansetting($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Automatic Panning'),
    '#default_value' => $default,
    '#options' => array(
      0 => t('None'),
      1 => t('Pan'),
      2 => t('Pan and zoom'),
      3 => t('Set Center'),
    ),
    '#description' => t('"None" is No panning,<br />"Pan" keeps the markers in the Viewport,<br />"Pan and zoom" fits the markers to the Viewport,<br /> "Set Center" places the markers in the middle of the map.'),
  );
  return $element;
}
function getlocations_element_map_markeraction($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Marker action'),
    '#default_value' => $default,
    '#options' => array(
      0 => t('None'),
      1 => t('InfoWindow'),
      2 => t('InfoBubble'),
      3 => t('Link'),
    ),
    '#description' => t('"None" is No action,<br />"InfoWindow" show information in a Google InfoWindow,<br />"InfoBubble" use InfoBubble instead,<br /> "Link" go to a page.'),
  );
  return $element;
}
function getlocations_element_map_markeractiontype($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Marker action type'),
    '#default_value' => $default,
    '#options' => array(
      1 => t('Click'),
      2 => t('Mouse over'),
    ),
    '#description' => t('"Click" is clicking on the marker,<br />"Mouse over" is holding the mouse over a marker.'),
  );
  return $element;
}
function getlocations_element_markermanagertype($default) {
  $element = array(
    '#type' => 'select',
    '#title' => t('Marker Manager type'),
    '#default_value' => $default,
    '#options' => array(
      0 => t('None'),
      1 => t('Marker Manager'),
      2 => t('Marker Clusterer'),
    ),
    '#description' => t('The type of marker management software to load, if any.'),
  );
  return $element;
}
function getlocations_element_path($title, $default, $size, $maxlength, $description) {
  $element = array(
    '#type' => 'textfield',
    '#title' => $title,
    '#default_value' => $default,
    '#size' => $size,
    '#maxlength' => $maxlength,
    '#description' => $description,
    '#required' => TRUE,
  );
  return $element;
}
function getlocations_element_map_behavior($type, $default) {

  // scale  overview overview_opened scrollwheel
  if ($type == 'scale') {
    $title = t('Scale');
    $description = t('Show scale');
  }
  elseif ($type == 'overview') {
    $title = t('Overview map');
    $description = t('Show overview map');
  }
  elseif ($type == 'overview_opened') {
    $title = t('Overview map state');
    $description = t('Show overview map as open by default.');
  }
  elseif ($type == 'scrollwheel') {
    $title = t('Scrollwheel');
    $description = t('Enable scrollwheel zooming');
  }
  if ($title) {
    $element = getlocations_element_map_checkbox($title, $default, $description);
    return $element;
  }
  return FALSE;
}

/**
 * @param string $default
 * @param string $title
 * @param array $options
 * @param string $description
 * @param bool $multiple
 * @param int $weight
 *
 * @return
 *   Returns form element
 *
 */
function getlocations_element_dd($title, $default, $options, $description = '', $multiple = FALSE, $weight = '') {
  $element = array(
    '#type' => 'select',
    '#title' => $title,
    '#default_value' => $default,
    '#options' => $options,
  );
  if ($description) {
    $element['#description'] = $description;
  }
  if ($multiple) {
    $element['#multiple'] = TRUE;
    $element['#size'] = min(12, count($options));
  }
  if (is_numeric($weight)) {
    $element['#weight'] = $weight;
  }
  return $element;
}
function getlocations_map_display_options_form($defaults, $config = TRUE, $extras = TRUE) {
  $form = array();
  $form['controltype'] = getlocations_element_map_zoom_controltype($defaults['controltype']);
  $form['pancontrol'] = getlocations_element_map_checkbox(t('Show Pan control'), $defaults['pancontrol']);
  $form['mtc'] = getlocations_element_map_mtc($defaults['mtc']);
  $form['maptype'] = getlocations_element_map_maptype($defaults['maptype'], $defaults['baselayers']);
  foreach ($defaults['baselayers'] as $key => $value) {
    $layer = getlocations_element_map_baselayers($key, $value);
    if ($layer) {
      $form['baselayers'][$key] = $layer;
    }
  }
  foreach ($defaults['behavior'] as $key => $value) {
    $layer = getlocations_element_map_behavior($key, $value);
    if ($layer) {
      $form['behavior'][$key] = $layer;
    }
  }
  $form['draggable'] = getlocations_element_map_checkbox(t('Draggable'), $defaults['draggable'], t('Enable dragging the map.'));
  $form['map_backgroundcolor'] = getlocations_element_map_tf(t('Map background color'), $defaults['map_backgroundcolor'], 10, 128, t('Can be a color name or HTML hex, eg #FF0000. Leave empty for the default color.'), FALSE);
  if ($extras) {
    $form['streetview_show'] = getlocations_element_map_checkbox(t('Show streetview button'), $defaults['streetview_show']);
    $form['trafficinfo'] = getlocations_element_map_checkbox(t('Enable Traffic information'), $defaults['trafficinfo'], t('Google trafficinfo layer, limited availability.'));
    $form['trafficinfo']['#suffix'] = '<div id="wrap-getlocations-trafficinfo">';
    $form['trafficinfo_state'] = getlocations_element_map_checkbox(t('Activate Traffic information'), $defaults['trafficinfo_state'], t('Activate Traffic layer when map is first displayed.'));
    $form['trafficinfo_state']['#suffix'] = '</div>';
    $form['bicycleinfo'] = getlocations_element_map_checkbox(t('Enable Bicycling information'), $defaults['bicycleinfo'], t('Google bicycling layer, limited availability.'));
    $form['bicycleinfo']['#suffix'] = '<div id="wrap-getlocations-bicycleinfo">';
    $form['bicycleinfo_state'] = getlocations_element_map_checkbox(t('Activate Bicycle information'), $defaults['bicycleinfo_state'], t('Activate Bicycling layer when map is first displayed.'));
    $form['bicycleinfo_state']['#suffix'] = '</div>';
    $form['transitinfo'] = getlocations_element_map_checkbox(t('Enable Public transport information'), $defaults['transitinfo'], t('Google Transit layer, limited availability.'));
    $form['transitinfo']['#suffix'] = '<div id="wrap-getlocations-transitinfo">';
    $form['transitinfo_state'] = getlocations_element_map_checkbox(t('Activate Public transport information'), $defaults['transitinfo_state'], t('Activate Transit layer when map is first displayed.'));
    $form['transitinfo_state']['#suffix'] = '</div>';
    if ($config) {
      $form['panoramio_use'] = getlocations_element_map_checkbox(t('Load Panoramio Library'), $defaults['panoramio_use'], t('Provide Google panoramio library to all maps.'));
      $form['panoramio_use']['#suffix'] = '<div id="wrap-getlocations-panoramio-use">';
      $form['panoramio_show'] = getlocations_element_map_checkbox(t('Enable Panoramio'), $defaults['panoramio_show'], t('Google panoramio picture links.'));
      $form['panoramio_show']['#suffix'] = '<div id="wrap-getlocations-panoramio">';
      $form['panoramio_state'] = getlocations_element_map_checkbox(t('Activate Panoramio'), $defaults['panoramio_state'], t('Activate Panoramio when map is first displayed.'));
      $form['panoramio_state']['#suffix'] = '</div></div>';
    }
    elseif ($defaults['panoramio_use']) {
      $form['panoramio_show'] = getlocations_element_map_checkbox(t('Enable Panoramio'), $defaults['panoramio_show'], t('Google panoramio picture links.'));
      $form['panoramio_show']['#suffix'] = '<div id="wrap-getlocations-panoramio">';
      $form['panoramio_state'] = getlocations_element_map_checkbox(t('Activate Panoramio'), $defaults['panoramio_state'], t('Activate Panoramio when map is first displayed.'));
      $form['panoramio_state']['#suffix'] = '</div>';
    }

    // weather
    if ($config) {
      $form['weather_use'] = getlocations_element_map_checkbox(t('Load Weather Library'), $defaults['weather_use'], t('Provide Google Weather library to all maps.'));
      $form['weather_use']['#suffix'] = '<div id="wrap-getlocations-weather-use">';
      $form['weather_show'] = getlocations_element_map_checkbox(t('Enable Weather information'), $defaults['weather_show'], t('Google Weather information.'));
      $form['weather_show']['#suffix'] = '<div id="wrap-getlocations-weather">';
      $form['weather_state'] = getlocations_element_map_checkbox(t('Activate Weather information'), $defaults['weather_state'], t('Activate Weather information when map is first displayed.'));
      $form['weather_state']['#suffix'] = '</div>';
      $form['weather_temp'] = getlocations_element_dd(t('Temperature units'), $defaults['weather_temp'], array(
        1 => t('Celsius'),
        2 => t('Fahrenheit'),
      ));
      $form['weather_speed'] = getlocations_element_dd(t('Windspeed units'), $defaults['weather_speed'], array(
        1 => t('Kilometers per hour'),
        2 => t('Meters per second'),
        3 => t('Miles per hour'),
      ));
      $form['weather_label'] = getlocations_element_dd(t('Label colour'), $defaults['weather_label'], array(
        0 => 'Auto',
        1 => t('Black'),
        2 => t('White'),
      ));
      $form['weather_cloud'] = getlocations_element_map_checkbox(t('Enable Cloud Layer'), $defaults['weather_cloud'], t('Google Cloud information.'));
      $form['weather_cloud']['#suffix'] = '<div id="wrap-getlocations-weather-cloud">';
      $form['weather_cloud_state'] = getlocations_element_map_checkbox(t('Activate Cloud Layer'), $defaults['weather_cloud_state'], t('Activate Cloud layer when map is first displayed.'));
      $form['weather_cloud_state']['#suffix'] = '</div>';
      $form['weather_clickable'] = getlocations_element_map_checkbox(t('Enable clicking on maps'), $defaults['weather_clickable']);
      $form['weather_info'] = getlocations_element_map_checkbox(t('Enable weather InfoWindows'), $defaults['weather_info']);
      $form['weather_info']['#suffix'] = '</div>';
    }
    elseif ($defaults['weather_use']) {
      $form['weather_show'] = getlocations_element_map_checkbox(t('Enable Weather information'), $defaults['weather_show'], t('Google Weather information.'));
      $form['weather_show']['#suffix'] = '<div id="wrap-getlocations-weather">';
      $form['weather_state'] = getlocations_element_map_checkbox(t('Activate Weather information'), $defaults['weather_state'], t('Activate Weather information when map is first displayed.'));
      $form['weather_cloud'] = getlocations_element_map_checkbox(t('Enable Cloud Layer'), $defaults['weather_cloud'], t('Google cloud information.'));
      $form['weather_cloud']['#suffix'] = '<div id="wrap-getlocations-weather-cloud">';
      $form['weather_cloud_state'] = getlocations_element_map_checkbox(t('Activate Cloud Layer'), $defaults['weather_cloud_state'], t('Activate Cloud layer when map is first displayed.'));
      $form['weather_cloud_state']['#suffix'] = '</div></div>';
    }
    $form['poi_show'] = getlocations_element_map_checkbox(t('Show Points of Interest'), $defaults['poi_show'], t('Show Google points of interest icons.'));
    $form['transit_show'] = getlocations_element_map_checkbox(t('Show Transit Points'), $defaults['transit_show'], t('Show Google transit points icons.'));
  }
  return $form;
}
function getlocations_paths_get() {
  $getlocations_paths = variable_get('getlocations_paths', array(
    'infobubble_path' => GETLOCATIONS_PATH . '/js/infobubble.js',
    'infobubble_options_path' => GETLOCATIONS_PATH . '/js/infobubble_options.js',
    'markermanager_path' => GETLOCATIONS_PATH . '/js/markermanager.js',
    'markerclusterer_path' => GETLOCATIONS_PATH . '/js/markerclusterer.js',
  ));
  if (!isset($getlocations_paths['markerclusterer_path'])) {
    $getlocations_paths['markerclusterer_path'] = GETLOCATIONS_PATH . '/js/markerclusterer.js';
  }
  return $getlocations_paths;
}

/**
 * Geocode an address
 * Input can be a string or an array
 * Output is an array if successful, string if failed
 *
 */
function getlocations_geocode($address) {
  if (empty($address)) {
    return;
  }
  if (is_array($address)) {
    if (count($address)) {
      $address = implode('+', $address);
    }
    else {
      return;
    }
  }
  $query = array(
    'address' => $address,
    'sensor' => 'false',
  );
  $msg = '';
  $url = url("http://maps.googleapis.com/maps/api/geocode/json", array(
    'query' => $query,
  ));
  $result = drupal_http_request($url);
  $data = json_decode($result->data);
  $status = $data->status;
  if ($status == 'OK') {
    return array(
      'latitude' => $data->results[0]->geometry->location->lat,
      'longitude' => $data->results[0]->geometry->location->lng,
      'location_type' => $data->results[0]->geometry->location_type,
    );
  }
  elseif ($status == 'ZERO_RESULTS') {
    $msg = t("No result");
  }
  elseif ($status == 'OVER_QUERY_LIMIT') {
    $msg = t("Over query limit");
  }
  elseif ($status == 'REQUEST_DENIED') {
    $msg = t("Request denied");
  }
  elseif ($status == 'INVALID_REQUEST') {
    $msg = t("Request invalid");
  }
  return $msg;

  /**
   * "OK" indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned.
   * "ZERO_RESULTS" indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
   * "OVER_QUERY_LIMIT" indicates that you are over your quota.
   * "REQUEST_DENIED" indicates that your request was denied, generally because of lack of a sensor parameter.
   * "INVALID_REQUEST" generally indicates that the query (address or latlng) is missing.
   */
}

/**
 * Reverse Geocode an address
 * Input can be a string or an array
 * Output is an array if successful, string if failed
 *
 */
function getlocations_reverse_geocode($latlng) {
  if (empty($latlng)) {
    return;
  }
  if (is_array($latlng)) {
    if (count($latlng)) {
      $latlng = implode(',', $latlng);
    }
    else {
      return;
    }
  }
  $query = array(
    'latlng' => $latlng,
    'sensor' => 'false',
  );
  $msg = '';
  $url = url("http://maps.googleapis.com/maps/api/geocode/json", array(
    'query' => $query,
  ));
  $result = drupal_http_request($url);
  $data = json_decode($result->data);
  $status = $data->status;
  if ($status == 'OK') {
    $address_components = $data->results[0]->address_components;
    $out = array();
    foreach ($address_components as $component) {
      $type = $component->types[0];
      if ($type == 'street_address') {
        $out['street_address'] = $component->long_name;
      }
      if ($type == 'street_number') {
        $out['street_number'] = $component->long_name;
      }
      elseif ($type == 'route') {
        $out['route'] = $component->short_name;
        $out['address1'] = $component->long_name;
      }
      elseif ($type == 'locality') {
        $out['locality'] = $component->long_name;
      }
      elseif ($type == 'administrative_area_level_3') {
        $out['administrative_area_level_3'] = $component->long_name;
      }
      elseif ($type == 'administrative_area_level_2') {
        $out['administrative_area_level_2'] = $component->long_name;
      }
      elseif ($type == 'administrative_area_level_1') {
        $out['administrative_area_level_1'] = $component->long_name;
      }
      elseif ($type == 'country') {
        $out['country'] = $component->long_name;
        $out['country_short'] = $component->short_name;
      }
      elseif ($type == 'postal_code_prefix') {
        $out['postal_code'] = $component->long_name;
      }
      elseif ($type == 'intersection') {
        $out['intersection'] = $component->long_name;
      }
      elseif ($type == 'colloquial_area') {
        $out['colloquial_area'] = $component->long_name;
      }
      elseif ($type == 'sublocality') {
        $out['sublocality'] = $component->long_name;
      }
      elseif ($type == 'neighborhood') {
        $out['neighborhood'] = $component->long_name;
      }
      elseif ($type == 'premise') {
        $out['premise'] = $component->long_name;
      }
      elseif ($type == 'subpremise') {
        $out['subpremise'] = $component->long_name;
      }
      elseif ($type == 'natural_feature') {
        $out['natural_feature'] = $component->long_name;
      }
      elseif ($type == 'airport') {
        $out['airport'] = $component->long_name;
      }
      elseif ($type == 'park') {
        $out['park'] = $component->long_name;
      }
      elseif ($type == 'point_of_interest') {
        $out['point_of_interest'] = $component->long_name;
      }
      elseif ($type == 'post_box') {
        $out['post_box'] = $component->long_name;
      }
      elseif ($type == 'floor') {
        $out['floor'] = $component->long_name;
      }
      elseif ($type == 'room') {
        $out['room'] = $component->long_name;
      }
    }
    $out['formatted_address'] = $data->results[0]->formatted_address;
    $out['location_type'] = $data->results[0]->geometry->location_type;
    return $out;
  }
  elseif ($status == 'ZERO_RESULTS') {
    $msg = t("No result");
  }
  elseif ($status == 'OVER_QUERY_LIMIT') {
    $msg = t("Over query limit");
  }
  elseif ($status == 'REQUEST_DENIED') {
    $msg = t("Request denied");
  }
  elseif ($status == 'INVALID_REQUEST') {
    $msg = t("Request invalid");
  }
  return $msg;

  /**
   * "OK" indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned.
   * "ZERO_RESULTS" indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
   * "OVER_QUERY_LIMIT" indicates that you are over your quota.
   * "REQUEST_DENIED" indicates that your request was denied, generally because of lack of a sensor parameter.
   * "INVALID_REQUEST" generally indicates that the query (address or latlng) is missing.
   */
}

Functions

Namesort descending Description
getlocations_access_location menu access functions
getlocations_access_user_location
getlocations_box
getlocations_cdints_load
getlocations_check Function to check if the configuration has been done yet
getlocations_check_node
getlocations_defaults Some defaults.
getlocations_do_minmaxes
getlocations_element_dd
getlocations_element_map_baselayers
getlocations_element_map_behavior
getlocations_element_map_checkbox
getlocations_element_map_maptype
getlocations_element_map_marker Some form helper functions for admin and views plugin style
getlocations_element_map_markeraction
getlocations_element_map_markeractiontype
getlocations_element_map_mtc
getlocations_element_map_pansetting
getlocations_element_map_tf
getlocations_element_map_zoom
getlocations_element_map_zoom_controltype
getlocations_element_markermanagertype
getlocations_element_path
getlocations_flush_caches Implementation of hook_flush_caches().
getlocations_geocode Geocode an address Input can be a string or an array Output is an array if successful, string if failed
getlocations_getlocations_markerdir hook_getlocations_markerdir from jhm http://drupal.org/user/15946
getlocations_get_icondata Get the JSON icon data for all the default markers.
getlocations_get_markerfile
getlocations_get_markertypes
getlocations_get_marker_titles Get the list of marker titles. adapted from gmap
getlocations_get_nid_from_lid
getlocations_get_nodetype
getlocations_get_types
getlocations_get_uid_from_lid
getlocations_get_vid Function to get the vid from node table.
getlocations_help Implementation of hook_help().
getlocations_id_load menu placeholder functions
getlocations_info
getlocations_init Implementation of hook_init().
getlocations_js_settings_do
getlocations_latlon_check Function to check a lat,lon string
getlocations_lidinfo
getlocations_lids Menu callback
getlocations_load_location
getlocations_load_locations
getlocations_map_display_options_form
getlocations_menu Implementation of hook_menu().
getlocations_nids Menu callback
getlocations_nodemap Menu callback
getlocations_paths_get
getlocations_perm Implementation of hook_perm().
getlocations_regenerate_markers Regenerate the markerdata file.
getlocations_reverse_geocode Reverse Geocode an address Input can be a string or an array Output is an array if successful, string if failed
getlocations_setlocations Set up javascript settings and map
getlocations_setup_js Function to setup the map scripts
getlocations_setup_map Function to setup the map scripts
getlocations_typemap Menu callback
getlocations_type_load Check that the node type exists
getlocations_usermap Menu callback
getlocations_usersmap Menu callback
getlocations_views_api Implementation of hook_views_api().

Constants

Namesort descending Description
GETLOCATIONS_PATH @file Displays locations on a map. for Drupal 6 using version 3 googlemaps API