Browse Source

fix geocoding

euromark 13 years ago
parent
commit
32342af327

File diff suppressed because it is too large
+ 7 - 21
Lib/GeocodeLib.php


+ 1 - 1
Lib/HttpSocketLib.php

@@ -100,7 +100,7 @@ class HttpSocketLib {
 			$data = $Ch->get($url);
 			$response = $data[0];
 			$status = $data[1]['http_code'];
-			if ($status !== '200') {
+			if ((int)$status !== 200) {
 				$this->setError('Error '.$status);
 				return false;
 			}

+ 5 - 6
Model/Behavior/GeocoderBehavior.php

@@ -17,12 +17,12 @@ class GeocoderBehavior extends ModelBehavior {
 	/**
 	 * Initiate behavior for the model using specified settings. Available settings:
 	 *
-	 * - label: (array | string, optional) set to the field name that contains the
+	 * - address: (array | string, optional) set to the field name that contains the
 	 * 			string from where to generate the slug, or a set of field names to
-	 * 			concatenate for generating the slug. DEFAULTS TO: title
+	 * 			concatenate for generating the slug.
 	 *
 	 * - real: (boolean, optional) if set to true then field names defined in
-	 * 			label must exist in the database table. DEFAULTS TO: true
+	 * 			label must exist in the database table. DEFAULTS TO: false
 	 *
 	 * - expect: (array)postal_code, locality, sublocality, ...
 	 *
@@ -40,9 +40,9 @@ class GeocoderBehavior extends ModelBehavior {
 	 */
 	public function setup(Model $Model, $settings = array()) {
 		$default = array(
-			'real' => true, 'address' => array('street', 'postal_code', 'city', 'country'),
+			'real' => false, 'address' => array('street', 'postal_code', 'city', 'country'),
 			'require' => false, 'allowEmpty' => true, 'invalidate' => array(), 'expect' => array(),
-			'lat' => 'lat', 'lng' => 'lng', 'formatted_address' => 'formatted_address', 'host' => 'de', 'language' => 'de', 'region' => '', 'bounds' => '',
+			'lat' => 'lat', 'lng' => 'lng', 'formatted_address' => 'formatted_address', 'host' => null, 'language' => 'de', 'region' => '', 'bounds' => '',
 			'overwrite' => false, 'update' => array(), 'before' => 'save',
 			'min_accuracy' => 0, 'allow_inconclusive' => true, 'unit' => GeocodeLib::UNIT_KM,
 			'log' => true, // log successfull results to geocode.log (errors will be logged to error.log in either case)
@@ -113,7 +113,6 @@ class GeocoderBehavior extends ModelBehavior {
 
 		// See if we should request a geocode //TODO: reverse and return here
 		if ((!$this->settings[$Model->alias]['real'] || ($Model->hasField($this->settings[$Model->alias]['lat']) && $Model->hasField($this->settings[$Model->alias]['lng']))) && ($this->settings[$Model->alias]['overwrite'] || (empty($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]) || ($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]==0 && $Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]==0)))) {
-
 			if (!empty($Model->whitelist) && (!in_array($this->settings[$Model->alias]['lat'], $Model->whitelist) || !in_array($this->settings[$Model->alias]['lng'], $Model->whitelist))) {
 				/** HACK to prevent 0 inserts if not wanted! just use whitelist now to narrow fields down - 2009-03-18 ms */
 				//$Model->whitelist[] = $this->settings[$Model->alias]['lat'];

+ 8 - 14
Test/Case/Lib/GeocodeLibTest.php

@@ -77,7 +77,7 @@ class GeocodeLibTest extends MyCakeTestCase {
 	public function testUrl() {
 		$is = $this->Geocode->url();
 		debug($is);
-		$this->assertTrue(!empty($is) && strpos($is, 'http://maps.google.de/maps/api/geocode/xml?') === 0);
+		$this->assertTrue(!empty($is) && strpos($is, 'http://maps.googleapis.com/maps/api/geocode/xml?') === 0);
 	}
 
 
@@ -104,21 +104,14 @@ class GeocodeLibTest extends MyCakeTestCase {
 	public function testSetOptions() {
 		# should be the default
 		$res = $this->Geocode->url();
-		$this->assertTextContains('maps.google.de', $res);
+		$this->assertTextContains('maps.googleapis.com', $res);
 
-		$this->Geocode->setOptions(array('host'=>'it'));
+		$this->Geocode->setOptions(array('host'=>'maps.google.it'));
 		# should now be ".it"
 		$res = $this->Geocode->url();
 		$this->assertTextContains('maps.google.it', $res);
 	}
 
-	/**
-	 * @expectedException CakeException
-	 */
-	public function testSetInvalidOptions() {
-		$this->Geocode->setOptions(array('host'=>'xx'));
-	}
-
 	public function testGeocode() {
 		$address = '74523 Deutschland';
 		echo '<h2>'.$address.'</h2>';
@@ -207,7 +200,7 @@ class GeocodeLibTest extends MyCakeTestCase {
 		echo '<h2>'.$address.'</h2>';
 
 		# allow_inconclusive = TRUE
-		$this->Geocode->setOptions(array('allow_inconclusive'=>true));
+		$this->Geocode->setOptions(array('allow_inconclusive'=>true, 'min_accuracy' => GeocodeLib::ACC_LOC));
 		$is = $this->Geocode->geocode($address);
 		echo 'debug:';
 		pr($this->Geocode->debug());
@@ -219,18 +212,19 @@ class GeocodeLibTest extends MyCakeTestCase {
 		$this->assertTrue(count($res) > 4);
 
 		$is = $this->Geocode->isInconclusive();
-		$this->assertTrue($is);
+		$this->assertFalse($is);
 
 
 		# allow_inconclusive = FALSE
 		$this->Geocode->setOptions(array('allow_inconclusive'=>false));
 		$is = $this->Geocode->geocode($address);
 		debug($is);
-		$this->assertFalse($is);
-
+		$this->assertTrue($is);
+		/*
 		$is = $this->Geocode->error();
 		debug($is);
 		$this->assertTrue(!empty($is));
+		*/
 
 	}
 

+ 0 - 16
View/Helper/FormatHelper.php

@@ -1208,22 +1208,6 @@ class FormatHelper extends TextHelper {
 		return $email;
 	}
 
-
-	/**
-	 * shorten text (either exact or intelligent)
-	 * @param array $options
-	 * - ending, exact, html
-	 * 2009-08-08 ms
-	 */
-	public function truncate($text, $length = 100, $options = array()) {
-		$defaults = array(
-			'ending' => CHAR_HELLIP
-		);
-		$options = array_merge($defaults, $options);
-		return parent::truncate($text, $length, $options);
-	}
-
-
 	/**
 	 * (intelligent) Shortening of a text string
 	 * @param STRING textstring