public $east = null;
public $west = null;
public $geocodedText = null;
- public $geocodedPostalText = null;
public $geocodeChosen = null;
// Database's field required for both 'home' and 'job' addresses.
return ($this->flags != null && $this->flags->hasFlag($flag));
}
+ // Returns the address formated for postal use.
+ // The main rules are (cf AFNOR XPZ 10-011):
+ // -everything in upper case;
+ // -if there are more then than 38 characters in a line, split it;
+ // -if there are more then than 32 characters in the description of the "street", use abbreviations.
+ public function formatPostalAddress() {
+ static $abbreviations = array(
+ 'IMPASSE' => 'IMP',
+ 'RUE' => 'R',
+ 'AVENUE' => 'AV',
+ 'BOULEVARD' => 'BVD',
+ 'ROUTE' => 'R',
+ 'STREET' => 'ST',
+ 'ROAD' => 'RD',
+ );
+
+ $text = strtoupper($text);
+ $arrayText = explode("\n", $text);
+ $postalText = '';
+
+ foreach ($arrayText as $i => $line) {
+ $postalText .= (($i == 0) ? '' : "\n");
+ if (($length = strlen($line)) > 32) {
+ $words = explode(' ', $line);
+ $count = 0;
+ foreach ($words as $word) {
+ if (isset($abbreviations[$word])) {
+ $word = $abbreviations[$word];
+ }
+ if ($count + ($wordLength = strlen($word)) <= 38) {
+ $postalText .= (($count == 0) ? '' : ' ') . $word;
+ $count += (($count == 0) ? 0 : 1) + $wordLength;
+ } else {
+ $postalText .= "\n" . $word;
+ $count = strlen($word);
+ }
+ }
+ } else {
+ $postalText .= $line;
+ }
+ }
+ $this->postalText = $postalText;
+ }
+
public function format(array $format = array())
{
if (empty($format)) {
$format['requireGeocoding'] = false;
$format['stripGeocoding'] = false;
+ $format['postalText'] = false;
}
$this->text = trim($this->text);
if ($this->removed == 1) {
$mailer->send();
}
}
+ if ($format['postalText']) {
+ $this->formatPostalAddress();
+ }
if ($this->countryId == '') {
$this->countryId = null;
}
);
if (!is_null($this->geocodedText)) {
$address['geocodedText'] = $this->geocodedText;
- $address['geocodedPostalText'] = $this->geocodedPostalText;
$address['geocodeChosen'] = $this->geocodeChosen;
}
{
static $areas = array('administrativeArea', 'subAdministrativeArea', 'locality');
- $this->format();
+ $this->format(array('postalText'));
if (!$this->isEmpty()) {
foreach ($areas as $area) {
Geocoder::getAreaId($this, $area);
public function stripGeocodingFromAddress(Address &$address) {
$address->geocodedText = null;
- $address->geocodedPostalText = null;
$address->geoloc_choice = null;
$address->countryId = null;
$address->country = null;
// Prepares address to be geocoded
private function prepareAddress(Address &$address) {
$address->text = preg_replace('/\s*\n\s*/m', "\n", trim($address->text));
- $address->postalText = $this->getPostalAddress($address->text);
}
// Builds the Google Maps geocoder url to fetch information about @p address.
if ($extraLines) {
$address->geocodedText = $extraLines . "\n" . $address->geocodedText;
}
- $address->geocodedPostalText = $this->getPostalAddress($address->geocodedText);
$geoloc = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
array('', "\n"), $address->geocodedText));
$text = strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"),
if ($same) {
$address->geocodedText = null;
- $address->geocodedPostalText = null;
} else {
$address->geocodedText = str_replace("\n", "\r\n", $address->geocodedText);
- $address->geocodedPostalText = str_replace("\n", "\r\n", $address->geocodedPostalText);
}
$address->text = str_replace("\n", "\r\n", $address->text);
- $address->postalText = str_replace("\n", "\r\n", $address->postalText);
- }
-
- // Returns the address formated for postal use.
- // The main rules are (cf AFNOR XPZ 10-011):
- // -everything in upper case;
- // -if there are more then than 38 characters in a line, split it;
- // -if there are more then than 32 characters in the description of the "street", use abbreviations.
- private function getPostalAddress($text) {
- static $abbreviations = array(
- 'IMPASSE' => 'IMP',
- 'RUE' => 'R',
- 'AVENUE' => 'AV',
- 'BOULEVARD' => 'BVD',
- 'ROUTE' => 'R',
- 'STREET' => 'ST',
- 'ROAD' => 'RD',
- );
-
- $text = strtoupper($text);
- $arrayText = explode("\n", $text);
- $postalText = '';
-
- foreach ($arrayText as $i => $line) {
- $postalText .= (($i == 0) ? '' : "\n");
- if (($length = strlen($line)) > 32) {
- $words = explode(' ', $line);
- $count = 0;
- foreach ($words as $word) {
- if (isset($abbreviations[$word])) {
- $word = $abbreviations[$word];
- }
- if ($count + ($wordLength = strlen($word)) <= 38) {
- $postalText .= (($count == 0) ? '' : ' ') . $word;
- $count += (($count == 0) ? 0 : 1) + $wordLength;
- } else {
- $postalText .= "\n" . $word;
- $count = strlen($word);
- }
- }
- } else {
- $postalText .= $line;
- }
- }
- return $postalText;
}
// Trims the name of the real country if it contains an ISO 3166-1 non-country
{
if (geoloc == 1) {
$('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geocodedText]').val());
- $('#' + prefid + '_cont').find('[name*=postalText]').val($('#' + prefid + '_cont').find('[name*=geocodedPostalText]').val());
+ $('#' + prefid + '_cont').find('[name*=postalText]').val('');
}
if (geoloc > 0) {
$('#' + prefid + '_cont').find("[name*='[geocodedText]']").remove();
- $('#' + prefid + '_cont').find("[name*='[geocodedPostalText]']").remove();
}
$('#' + prefid + '_cont').find('[name*=text]').removeClass('error');
$('#' + prefid + '_cont').find('[name*=geocodeChosen]').val(geoloc);
{if t($address.geocodedText)}
<input type="hidden" name="{$prefname}[geocodeChosen]" value="1" />
<input type="hidden" name="{$prefname}[geocodedText]" value="{$address.geocodedText}" />
-<input type="hidden" name="{$prefname}[geocodedPostalText]" value="{$address.geocodedPostalText}" />
{/if}
<input type="hidden" name="{$prefname}[accuracy]" value="{$address.accuracy}" />
<input type="hidden" name="{$prefname}[postalText]" value="{$address.postalText}" />