<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
abstract class Geocoder {
// Geocodes @p the address, and returns the corresponding updated address.
// Unknown key-value pairs available in the input map are retained as-is.
- abstract public function getGeocodedAddress(Address &$address);
+ abstract public function getGeocodedAddress(Address $address);
// Cleans the address from its geocoded data
- abstract public function stripGeocodingFromAddress(Address &$address);
+ abstract public function stripGeocodingFromAddress(Address $address);
// Updates geoloc_administrativeareas, geoloc_subadministrativeareas and
// geoloc_localities databases with new geocoded data and returns the
// corresponding id.
- static public function getAreaId(Address &$address, $area)
+ static public function getAreaId(Address $address, $area)
{
static $databases = array(
'administrativeArea' => 'geoloc_administrativeareas',
// and the city name, within the limit of $limit number of lines.
static public function getFirstLines($text, $postalCode, $limit)
{
- $textArray = explode("\n", $text);
+ $text = str_replace("\r", '', $text);
+ $textArray = explode("\n", $text);
+ $linesNb = $limit;
+
for ($i = 0; $i < count($textArray); ++$i) {
if ($i > $limit || strpos($textArray[$i], $postalCode) !== false) {
- $limit = $i;
+ $linesNb = $i;
break;
}
}
- return implode("\n", array_slice($textArray, 0, $limit));
+ $firstLines = implode("\n", array_slice($textArray, 0, $linesNb));
+
+ // Adds empty lines to complete the $limit lines required.
+ for (; $i < $limit; ++$i) {
+ $firstLines .= "\n";
+ }
+ return $firstLines;
}
// Returns the number of non geocoded addresses for a user.