You are here

function uc_address_format in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_store/uc_store.module \uc_address_format()
  2. 7.3 uc_store/uc_store.module \uc_address_format()

Format an address for display based on a country's address format.

5 calls to uc_address_format()
theme_uc_ups_confirm_shipment in shipping/uc_ups/uc_ups.module
Display final shipment information for review.
uc_order_address in uc_order/uc_order.module
Return an address from an order object.
uc_payment_method_check in payment/uc_payment_pack/uc_payment_pack.module
Handle the Check payment method.
uc_quote_overview in shipping/uc_quote/uc_quote.module
Display a summary of the shipping quote settings.
uc_store_address in uc_store/uc_store.module

File

uc_store/uc_store.module, line 1991
Contains global Ubercart functions and store administration functionality.

Code

function uc_address_format($first_name, $last_name, $company, $street1, $street2, $city, $zone, $postal_code, $country) {
  $result = db_query("SELECT * FROM {uc_zones} WHERE zone_id = %d", $zone);
  if (!($zone_data = db_fetch_array($result))) {
    $zone_data = array(
      'zone_code' => t('N/A'),
      'zone_name' => t('Unknown'),
    );
  }
  $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country);
  if (!($country_data = db_fetch_array($result))) {
    $country_data = array(
      'country_name' => t('Unknown'),
      'country_iso_code_2' => t('N/A'),
      'country_iso_code_3' => t('N/A'),
    );
  }
  $variables = array(
    "\r\n" => '<br />',
    '!company' => check_plain($company),
    '!first_name' => check_plain($first_name),
    '!last_name' => check_plain($last_name),
    '!street1' => check_plain($street1),
    '!street2' => check_plain($street2),
    '!city' => check_plain($city),
    '!zone_code' => $zone_data['zone_code'],
    '!zone_name' => $zone_data['zone_name'],
    '!postal_code' => check_plain($postal_code),
    '!country_name' => $country_data['country_name'],
    '!country_code2' => $country_data['country_iso_code_2'],
    '!country_code3' => $country_data['country_iso_code_3'],
  );
  if (uc_store_default_country() != $country) {
    $variables['!country_name_if'] = $country_data['country_name'];
    $variables['!country_code2_if'] = $country_data['country_iso_code_2'];
    $variables['!country_code3_if'] = $country_data['country_iso_code_3'];
  }
  else {
    $variables['!country_name_if'] = '';
    $variables['!country_code2_if'] = '';
    $variables['!country_code3_if'] = '';
  }
  $format = variable_get('uc_address_format_' . $country, '');
  if (empty($format)) {
    $format = "!company\r\n!first_name !last_name\r\n!street1\r\n!street2\r\n!city, !zone_code !postal_code\r\n!country_name_if";
  }
  $address = strtr($format, $variables);
  $address = strtr($address, array(
    "\n" => '<br />',
  ));
  $match = array(
    '`^<br( /)?>`',
    '`<br( /)?>$`',
    '`<br( /)?>(\\s*|[\\s*<br( /)?>\\s*]+)<br( /)?>`',
    '`<br( /)?><br( /)?>`',
    '`<br( /)?>, N/A`',
  );
  $replace = array(
    '',
    '',
    '<br />',
    '<br />',
    '',
    '',
  );
  $address = preg_replace($match, $replace, $address);
  return $address;
}