You are here

function theme_getlocations_adinfo in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \theme_getlocations_adinfo()

Returns HTML of a location's vcard, requested by ajax.

Parameters

array $variables: An associative array containing:

  • location: The information pertaining to the address to be formatted.

Return value

string $output

1 theme call to theme_getlocations_adinfo()
getlocations_getinfo in ./getlocations.module

File

./getlocations.module, line 7215
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function theme_getlocations_adinfo($variables) {
  $location = $variables['location'];
  $output = '';
  $output .= '<div class="location vcard">';

  // this logic gives the location name field precedence over the node title
  // similarly for users, terms and comments
  $link = FALSE;
  $l = FALSE;
  if (isset($location['nid']) && $location['nid'] > 0) {
    if (!empty($location['name'])) {
      $link = $location['name'];
    }
    else {
      $node = node_load($location['nid']);
      $link = $node->title;
    }
    $l = l($link, 'node/' . $location['nid'], array(
      'attributes' => array(
        'class' => array(
          'getlocations_infolink',
        ),
        'target' => '_parent',
      ),
    ));
  }
  elseif (isset($location['uid']) && $location['uid'] > 0) {
    if (!empty($location['name'])) {
      $link = $location['name'];
    }
    else {
      $account = user_load($location['uid']);
      $link = $account->name;
    }
    $l = l($link, 'user/' . $location['uid'], array(
      'attributes' => array(
        'class' => array(
          'getlocations_infolink',
        ),
        'target' => '_parent',
      ),
    ));
  }
  elseif (isset($location['tid']) && $location['tid'] > 0 && module_exists('taxonomy')) {
    if (!empty($location['name'])) {
      $link = $location['name'];
    }
    else {
      $term = taxonomy_term_load($location['tid']);
      $link = $term->name;
    }
    $l = l($link, 'taxonomy/term/' . $location['tid'], array(
      'attributes' => array(
        'class' => array(
          'getlocations_infolink',
        ),
        'target' => '_parent',
      ),
    ));
  }
  elseif (isset($location['cid']) && $location['cid'] > 0 && module_exists('comment')) {
    if (!empty($location['name'])) {
      $link = $location['name'];
    }
    else {
      $comment = comment_load($location['cid']);
      $link = $comment->subject;
    }
    $l = l($link, 'comment/' . $location['cid'], array(
      'attributes' => array(
        'class' => array(
          'getlocations_infolink',
        ),
        'target' => '_parent',
      ),
    ));
  }
  if ($l) {
    $output .= '<h4>' . $l . '</h4>';
  }
  $output .= '<div class="adr">';
  if (!empty($location['street'])) {
    $output .= '<div class="street-address">' . $location['street'];
    if (!empty($location['additional'])) {
      $output .= "&nbsp;" . '<span class="extended-address">' . $location['additional'] . '</span>';
    }
    $output .= '</div>';
  }
  if (!empty($location['city'])) {
    $output .= '<span class="locality">' . $location['city'] . '</span>';
    if (!empty($location['province_name'])) {
      $output .= ",&nbsp;";
    }
    elseif (!empty($location['province'])) {
      $output .= ",&nbsp;";
    }
    else {
      $output .= "&nbsp;";
    }
  }
  if (isset($location['province_name']) && !empty($location['province_name'])) {
    $output .= '<span class="region">' . $location['province_name'] . '</span>';
    if (!empty($location['postal_code'])) {
      $output .= "&nbsp;";
    }
  }
  elseif (isset($location['province']) && !empty($location['province'])) {
    $output .= '<span class="region">' . $location['province'] . '</span>';
    if (!empty($location['postal_code'])) {
      $output .= "&nbsp;";
    }
  }
  if (!empty($location['postal_code'])) {
    $output .= '<span class="postal-code">' . drupal_strtoupper($location['postal_code']) . '</span>';
  }
  if (isset($location['country_name']) && !empty($location['country_name'])) {
    $output .= '<div class="country-name">' . $location['country_name'] . '</div>';
  }
  elseif (isset($location['country']) && !empty($location['country'])) {
    $output .= '<div class="country-name">' . $location['country'] . '</div>';
  }
  $output .= '</div>';
  if (isset($location['sdist'])) {
    if ($location['sdist'] != 1) {
      $unit_disp = getlocations_get_unit_names($location['sunit']);
    }
    else {
      $unit_disp = getlocations_get_unit_names($location['sunit'], 'single');
    }
    $output .= '<div class="search-distance">' . number_format(floatval($location['sdist']), 2) . "&nbsp;" . $unit_disp . '</div>';
  }
  if (module_exists('getdirections') && isset($location['getdirections_link']) && $location['getdirections_link']) {
    $gdlink = '';
    if (isset($location['nid']) && $location['nid']) {
      $gdlink = l(t('Directions'), 'getdirections/location/to/' . $location['nid'], array(
        'attributes' => array(
          'class' => array(
            'getlocations_infolink',
          ),
          'target' => '_parent',
        ),
      ));
    }
    elseif (isset($location['uid']) && $location['uid']) {
      $gdlink = l(t('Directions'), 'getdirections/location_user/to/' . $location['uid'], array(
        'attributes' => array(
          'class' => array(
            'getlocations_infolink',
          ),
          'target' => '_parent',
        ),
      ));
    }
    elseif (isset($location['cid']) && $location['cid'] && getdirections_check_entity_type('comment')) {
      $gdlink = l(t('Directions'), 'getdirections/location_comment/to/' . $location['cid'], array(
        'attributes' => array(
          'class' => array(
            'getlocations_infolink',
          ),
          'target' => '_parent',
        ),
      ));
    }
    elseif (isset($location['tid']) && $location['tid'] && getdirections_get_vocabularies()) {
      $gdlink = l(t('Directions'), 'getdirections/location_term/to/' . $location['tid'], array(
        'attributes' => array(
          'class' => array(
            'getlocations_infolink',
          ),
          'target' => '_parent',
        ),
      ));
    }
    if ($gdlink) {
      $output .= '<div class="getdirections-link">' . $gdlink . '</div>';
    }
  }
  $output .= '</div>';
  return $output;
}