예제 #1
0
 /**
  *
  * @param type $arrReturn
  * @return array
  * @throws Exception 
  */
 protected function ajaxSetLocation($arrReturn)
 {
     // Check if lat/lon is set
     if ((strlen($this->Input->post("lat")) == 0 || strlen($this->Input->post("lon")) == 0) && (strlen($this->Input->post("country")) == 0 || strlen($this->Input->post("countryShort")) == 0)) {
         throw new Exception("Missing longitude/latitude or country/countryShort.");
     }
     $this->objUserGeolocation->setLat($this->Input->post("lat"));
     $this->objUserGeolocation->setLon($this->Input->post("lon"));
     // Do geolocation look up
     $objResultLocation = $this->doGeoLookUP($this->objUserGeolocation);
     // Check if there was a result
     if ($objResultLocation == FALSE) {
         $this->objUserGeolocation->setFailed(true);
         $this->objUserGeolocation->setError("No W3C result.");
         $this->objUserGeolocation->setErrorID(GeolocationContainer::ERROR_NO_W3C_RESULT);
     } else {
         $this->objUserGeolocation = $objResultLocation;
     }
     // Return debug information
     return $arrReturn;
 }
예제 #2
0
 /**
  * 
  * @param String $strConfig
  * @param GeolocationContainer $objGeolocation
  * @return boolean|GeolocationContainer 
  */
 public function getLocation($strConfig, GeolocationContainer $objGeolocation)
 {
     $objRequest = new Request();
     $objRequest->send(vsprintf($strConfig, array($objGeolocation->getIP())));
     if ($objRequest->code != 200) {
         $this->log("Error by location service: " . vsprintf("Request error code %s - %s ", array($objRequest->code, $objRequest->error)), __CLASS__ . " | " . __FUNCTION__, TL_ERROR);
         return false;
     }
     $arrResponse = deserialize($objRequest->response);
     if (!is_array($arrResponse)) {
         return false;
     }
     $arrCountryShort = strtolower($arrResponse['geoplugin_countryCode']);
     $arrCountries = $this->getCountries();
     if (!key_exists($arrCountryShort, $arrCountries)) {
         return false;
     }
     $objGeolocation->setCountryShort($arrCountryShort);
     $objGeolocation->setCountry($arrCountries[$arrCountryShort]);
     $objGeolocation->setLat($arrResponse['geoplugin_latitude']);
     $objGeolocation->setLon($arrResponse['geoplugin_longitude']);
     return $objGeolocation;
 }