You are here

function theme_getlocations_fields_show in Get Locations 7.2

Same name and namespace in other branches
  1. 7 modules/getlocations_fields/getlocations_fields.module \theme_getlocations_fields_show()

Parameters

array $variables:

Return value

Returns $output

1 theme call to theme_getlocations_fields_show()
getlocations_fields_field_formatter_view in modules/getlocations_fields/getlocations_fields.module
Implements hook_field_formatter_view(). Build a renderable array for a field value.

File

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

Code

function theme_getlocations_fields_show($variables) {
  $locations = $variables['locations'];
  $settings = $variables['settings'];
  if ($settings['display_onemap']) {
    $minmaxes = array(
      'minlat' => 0,
      'minlon' => 0,
      'maxlat' => 0,
      'maxlon' => 0,
    );
  }
  else {
    $minmaxes = '';
  }
  $output = '';
  $location_ct = 0;
  foreach ($locations as $location) {
    $output .= '<div class="location vcard">';
    if (!empty($location['name']) && $settings['display_name']) {
      $output .= '<h4>' . $location['name'] . '</h4>';
    }
    $output .= '<div class="adr">';
    if (!empty($location['street']) && $settings['display_street']) {
      $output .= '<div class="street-address">' . $location['street'];
      if (!empty($location['additional']) && $settings['display_additional']) {
        $output .= ' ' . '<span class="extended-address">' . $location['additional'] . '</span>';
      }
      $output .= '</div>';
    }
    if (!empty($location['city']) && $settings['display_city']) {
      $output .= '<span class="locality">' . $location['city'] . '</span>';
      if (!empty($location['province']) && $settings['display_province']) {
        $output .= ",&nbsp;";
      }
      else {
        $output .= "&nbsp;";
      }
    }
    if (!empty($location['province']) && $settings['display_province']) {
      $output .= '<span class="region">' . $location['province'] . '</span>';
      if (!empty($location['postal_code']) && $settings['display_postal_code']) {
        $output .= "&nbsp;";
      }
    }
    if (!empty($location['postal_code']) && $settings['display_postal_code']) {
      $output .= '<span class="postal-code">' . drupal_strtoupper($location['postal_code']) . '</span>';
    }
    if (!empty($location['country']) && $settings['display_country']) {
      if ($settings['country_full'] && drupal_strlen($location['country']) == 2) {

        // this is a 2 letter code, we want the full name
        $countries = getlocations_get_countries_list();
        $country = $countries[$location['country']];
        if (empty($country)) {
          $country = $location['country'];
        }
      }
      else {
        $country = $location['country'];
      }
      $output .= '<div class="country-name">' . $country . '</div>';
    }
    $output .= '</div>';
    if ($location['phone'] && $settings['display_phone'] || $location['mobile'] && $settings['display_mobile'] || $location['fax'] && $settings['display_fax']) {
      $output .= '<div class="phones">';
      if ($location['phone'] && $settings['display_phone']) {
        $output .= '<div class="phone"><span class="phone_label">' . t('Phone') . '</span>' . $location['phone'] . '</div>';
      }
      if ($location['mobile'] && $settings['display_mobile']) {
        $output .= '<div class="mobile"><span class="mobile_label">' . t('Mobile') . '</span>' . $location['mobile'] . '</div>';
      }
      if ($location['fax'] && $settings['display_fax']) {
        $output .= '<div class="fax"><span class="fax_label">' . t('Fax') . '</span>' . $location['fax'] . '</div>';
      }
      $output .= '</div>';
    }
    $output .= '</div>';

    // what3words
    $what3words_lic = variable_get('getlocations_what3words_lic', array(
      'key' => '',
      'url' => 'http://api.what3words.com',
    ));
    if ($what3words_lic['key'] && isset($location['what3words']) && $location['what3words'] && $settings['what3words_display']) {
      $output .= '<div class="w3w"><span class="w3w_label">' . t('What3Words') . '</span>' . $location['what3words'] . '</div>';
    }
    if ($settings['display_latlong']) {
      $lat = $location['latitude'];
      $lng = $location['longitude'];
      if ($settings['display_geo_microformat'] > 0) {
        $lat_dms = theme('getlocations_latitude_dms', array(
          'latitude' => $lat,
        ));
        $lng_dms = theme('getlocations_longitude_dms', array(
          'longitude' => $lng,
        ));
        if ($settings['display_geo_microformat'] == 1) {
          $output .= '<div class="geo">';
          $output .= '<abbr class="latitude" title="' . $lat . '">' . $lat_dms . '</abbr> ';
          $output .= '<abbr class="longitude" title="' . $lng . '">' . $lng_dms . '</abbr>';
          $output .= '</div>';
        }
        else {
          $output .= '<div itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">';
          $output .= t('Latitude') . '&nbsp;' . $lat_dms . '<br />';
          $output .= t('Longitude') . '&nbsp;' . $lng_dms;
          $output .= '<meta itemprop="latitude" content="' . $lat . '" />';
          $output .= '<meta itemprop="longitude" content="' . $lng . '" />';
          $output .= '</div>';
        }
        $output .= '<br />';
      }
      else {
        if ($settings['display_dms']) {
          $lat = theme('getlocations_latitude_dms', array(
            'latitude' => $lat,
          ));
          $lng = theme('getlocations_longitude_dms', array(
            'longitude' => $lng,
          ));
        }
        $nomap = '';
        if (!$settings['display_showmap']) {
          $nomap = '_nomap';
        }
        $output .= '<div class="getlocations_fields_latlon_wrapper_themed' . $nomap . '">';
        $output .= '<div class="getlocations_fields_lat_wrapper_themed' . $nomap . '">';
        $output .= t('Latitude') . ":&nbsp;" . $lat . '</div>';
        $output .= '<div class="getlocations_fields_lon_wrapper_themed' . $nomap . '">';
        $output .= t('Longitude') . ":&nbsp;" . $lng . '</div>';
        $output .= '</div>';
        $output .= '<br />';
      }
    }

    // smuggle these in from location data
    // map_settings_allow
    if (isset($location['map_settings_allow'])) {
      $map_settings_allow = $location['map_settings_allow'];
    }
    else {
      $map_settings_allow = getlocations_fields_map_settings_allow();
    }
    if ($map_settings_allow) {
      if (isset($location['mapzoom']) && is_numeric($location['mapzoom'])) {
        $settings['nodezoom'] = $location['mapzoom'];
      }
      if (isset($location['map_maptype']) && $location['map_maptype']) {
        $settings['maptype'] = $location['map_maptype'];
      }
    }

    // streetview
    if (isset($location['streetview_settings_allow'])) {
      $streetview_settings_allow = $location['streetview_settings_allow'];
    }
    else {
      $streetview_settings_allow = getlocations_fields_streetview_settings_allow();
    }
    if ($streetview_settings_allow) {
      if (isset($location['sv_enable'])) {
        $settings['sv_enable'] = $location['sv_enable'] == 1 ? 1 : 0;
      }
      if (isset($location['sv_showfirst'])) {
        $settings['sv_showfirst'] = $location['sv_showfirst'] == 1 ? 1 : 0;
      }
      if (isset($location['sv_heading']) && is_numeric($location['sv_heading'])) {
        $settings['sv_heading'] = $location['sv_heading'];
      }
      if (isset($location['sv_zoom']) && is_numeric($location['sv_zoom'])) {
        $settings['sv_zoom'] = $location['sv_zoom'];
      }
      if (isset($location['sv_pitch']) && is_numeric($location['sv_pitch'])) {
        $settings['sv_pitch'] = $location['sv_pitch'];
      }
      $settings += getlocations_fields_get_display_settings($location);
    }
    else {
      $settings['sv_enable'] = 0;
      $settings['sv_showfirst'] = 0;
    }
    if ($location['longitude'] && $location['latitude']) {
      if ($settings['display_showmap']) {
        $name = htmlspecialchars_decode(isset($location['name']) && $location['name'] ? strip_tags($location['name']) : (isset($location['title']) && $location['title'] ? strip_tags($location['title']) : ''), ENT_QUOTES);
        $base = $location['entity_key'];
        $marker = $settings['map_marker'];

        // per location marker
        if (isset($location['marker']) && !empty($location['marker'])) {
          $marker = $location['marker'];
        }

        // onemap
        if ($settings['display_onemap']) {
          $latlons[] = array(
            $location['latitude'],
            $location['longitude'],
            $location['glid'],
            $name,
            $marker,
            $base,
            '',
            '',
          );
          $minmaxes = getlocations_do_minmaxes($location_ct, $location, $minmaxes);
        }
        else {
          $latlons = array(
            $location['latitude'],
            $location['longitude'],
            $location['glid'],
            $name,
            $marker,
            $base,
            '',
            '',
          );
          $map = getlocations_fields_getmap_show($settings, $latlons);
          $output .= $map;
        }
      }
      else {

        // TODO
        if ($settings['display_maplink']) {
          if (count($locations) > 1) {
            $output .= '<p>' . l(t('Show on a map'), 'getlocations/lids/' . $location['glid']) . '</p>';
          }
          else {
            if ($location['entity_id'] && $location['entity_type']) {
              if ($location['entity_type'] == 'taxonomy_term') {
                $output .= '<p>' . l(t('Show on a map'), 'getlocations/term/' . $location['entity_id']) . '</p>';
              }
              else {
                $output .= '<p>' . l(t('Show on a map'), 'getlocations/' . $location['entity_type'] . '/' . $location['entity_id']) . '</p>';
              }
            }
          }
        }
      }
      $location_ct++;
    }
  }

  // onemap
  if ($settings['display_showmap'] && $settings['display_onemap'] && isset($latlons)) {
    if ($location_ct < 2) {
      unset($minmaxes);
      $minmaxes = '';
    }
    $map = getlocations_fields_getmap_show($settings, $latlons, $minmaxes);
    $output .= $map;
  }
  return $output;
}