You are here

function getlocations_mapquest_entity_type_map in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_mapquest/getlocations_mapquest.module \getlocations_mapquest_entity_type_map()

Function

Return value

Returns

1 string reference to 'getlocations_mapquest_entity_type_map'
getlocations_mapquest_menu in modules/getlocations_mapquest/getlocations_mapquest.module
Implements hook_menu().

File

modules/getlocations_mapquest/getlocations_mapquest.module, line 1791
getlocations_mapquest.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_mapquest_entity_type_map($type, $entity_id) {
  global $language;
  $entity_type = getlocations_get_entity_type_from_path($type);
  $entity_get_info = entity_get_info($entity_type);

  // get key for entity_type
  $entity_key = $entity_get_info['entity keys']['id'];

  // nid, cid, uid etc
  $locations = getlocations_load_locations($entity_id, $entity_key);
  $getlocations_mapquest_defaults = getlocations_mapquest_defaults();
  $load_hook = $entity_get_info['load hook'];
  $object = $load_hook($entity_id);
  $lang = $object->language ? $object->language : $language->language;
  $locative_field_name = $object->field_mapquest_map[$lang][0]['locative_field_name'];
  $typemarkers = getlocations_get_markertypes($entity_type);
  $bundle = $object->type;
  $marker = '';
  $vector = '';

  // marker
  $marker = $getlocations_mapquest_defaults['node_map_marker'];
  if (isset($getlocations_mapquest_defaults[$entity_type . '_map_marker'])) {
    $marker = $getlocations_mapquest_defaults[$entity_type . '_map_marker'];
  }
  if (isset($typemarkers[$object->type]) && $typemarkers[$object->type]) {
    $marker = $typemarkers[$object->type];
  }
  $entity_title = '';
  if (isset($object->title)) {
    $entity_title = $object->title;
  }
  elseif (isset($object->name)) {
    $entity_title = $object->name;
  }
  elseif (isset($object->subject)) {
    $entity_title = $object->subject;
  }
  $returnlink = FALSE;
  $links = array();

  // return link
  if ($entity_type == 'node' && $getlocations_mapquest_defaults['returnlink_page_enable']) {
    if (is_object($object)) {
      $linktext = $getlocations_mapquest_defaults['returnlink_page_link'];
      if (preg_match("/%t/", $linktext)) {
        $linktext = preg_replace("/%t/", $object->title, $linktext);
      }
      $returnlink = l($linktext, 'node/' . $object->nid);
    }
  }
  elseif ($entity_type == 'user' && $getlocations_mapquest_defaults['returnlink_user_enable']) {
    if (is_object($object)) {
      $linktext = $getlocations_mapquest_defaults['returnlink_user_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->name, $linktext);
      }
      $returnlink = l($linktext, 'user/' . $object->uid);
    }
  }
  elseif (($entity_type == 'term' || $entity_type == 'taxonomy_term') && $getlocations_mapquest_defaults['returnlink_term_enable'] && module_exists('taxonomy')) {
    if (is_object($object)) {
      $linktext = $getlocations_mapquest_defaults['returnlink_term_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->name, $linktext);
      }
      $returnlink = l($linktext, 'taxonomy/term/' . $object->tid);
    }
  }
  elseif ($entity_type == 'comment' && $getlocations_mapquest_defaults['returnlink_comment_enable'] && module_exists('comment')) {
    if (is_object($object)) {
      $linktext = $getlocations_mapquest_defaults['returnlink_comment_link'];
      if (preg_match("/%n/", $linktext)) {
        $linktext = preg_replace("/%n/", $object->subject, $linktext);
      }
      $returnlink = l($linktext, 'comment/' . $object->cid);
    }
  }
  if ($returnlink) {
    $links['returnlink'] = $returnlink;
  }
  $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 ($latlon = getlocations_latlon_check($location['latitude'] . ',' . $location['longitude'])) {
        $ll = explode(',', $latlon);
        $location['latitude'] = $ll[0];
        $location['longitude'] = $ll[1];
        $minmaxes = getlocations_do_minmaxes($ct, $location, $minmaxes);
        $lid = isset($location['glid']) ? $location['glid'] : (isset($location['lid']) ? $location['lid'] : 0);
        if (!isset($location['key'])) {
          $location['key'] = '';
        }
        else {
          $location['lid'] = $entity_id;
        }

        // node only
        if ($entity_type == 'node') {

          // term markers
          $marker = getlocations_get_term_marker($entity_id, $marker);

          // TODO awesome here too?
        }

        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }
        if ($lid && $getlocations_mapquest_defaults['markeraction'] == 'popup') {
          $extra = FALSE;
          if (isset($getlocations_mapquest_defaults['getdirections_link'])) {
            $extra['gdlink'] = $getlocations_mapquest_defaults['getdirections_link'];
          }
          $markeraction = array(
            'type' => 'popup',
            'data' => getlocations_getinfo($lid, $entity_key, $extra),
          );
        }
        elseif ($lid && $getlocations_mapquest_defaults['markeraction'] == 'link') {
          $markeraction = array(
            'type' => 'link',
            'data' => getlocations_getlidinfo($lid, $entity_key),
          );
        }
        else {
          $markeraction = array();
        }
        $name = htmlspecialchars_decode($location['name'] ? strip_tags($location['name']) : strip_tags($entity_title), ENT_QUOTES);
        $latlons[$ct] = array(
          $location['latitude'],
          $location['longitude'],
          $entity_key,
          $entity_id,
          $lid,
          $entity_title,
          $marker,
          $vector,
          $markeraction,
          '',
        );
        $iconlist[$marker] = getlocations_mapquest_get_marker($marker);
        $ct++;
      }
    }

    // end foreach
    if ($ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    $nodezoom = FALSE;
    if ($ct == 1 && $getlocations_mapquest_defaults['nodezoom']) {
      $nodezoom = $getlocations_mapquest_defaults['nodezoom'];
      $map_settings['map_opts']['center'] = array(
        $location['latitude'],
        $location['longitude'],
      );
      $map_settings['map_opts']['zoom'] = $nodezoom;
    }
    elseif ($ct < 1) {
      $ll = explode(',', $getlocations_mapquest_defaults['latlong']);
      $map_settings['map_opts']['center'] = array(
        $ll[0],
        $ll[1],
      );
      $map_settings['map_opts']['zoom'] = $getlocations_mapquest_defaults['zoom'];
    }
    $mapid = getlocations_setup_map('', FALSE, FALSE, TRUE);

    // add in some more
    $map_settings = getlocations_mapquest_map_settings_do($map_settings, $getlocations_mapquest_defaults, $latlons, $mapid);
    $map_settings['map_settings']['nodezoom'] = $nodezoom ? $nodezoom : FALSE;
    $map_settings['map_settings']['minmaxes'] = empty($minmaxes) ? FALSE : implode(',', $minmaxes);
    $map_settings['icons'] = $iconlist;
    $map_settings['datanum'] = $ct;
    $map_settings['latlons'] = $latlons;
    $output = theme('getlocations_mapquest_map', array(
      'width' => $getlocations_mapquest_defaults['width'],
      'height' => $getlocations_mapquest_defaults['height'],
      'map_settings' => $map_settings,
      'mapid' => $mapid,
      'links' => $links,
    ));
    return $output;
  }
}