Ejemplo n.º 1
0
 /**
  *
  * @param type $strConfig
  * @param GeolocationContainer $objGeolocation
  * @return boolean|GeolocationContainer 
  */
 public function getLocation($strConfig, GeolocationContainer $objGeolocation)
 {
     //calculate ipNum
     $arrIP = explode(".", $objGeolocation->getIP());
     $ipNum = 16777216 * $arrIP[0] + 65536 * $arrIP[1] + 256 * $arrIP[2] + 0;
     // Load country from cache or do a db-lookup
     if (!isset(self::$arrIPCache[$ipNum])) {
         // Initialize cache
         self::$arrIPCache[$ipNum] = '';
         $arrResult = $this->Database->prepare("SELECT * FROM tl_geodata WHERE ? >= ipnum_start AND ? <= ipnum_end")->limit(1)->execute($ipNum, $ipNum)->fetchAllAssoc();
         if (count($arrResult) != 0) {
             $country_short = strtolower($arrResult[0]['country_short']);
             $arrCountries = $this->getCountries();
             self::$arrIPCache[$ipNum] = $country_short;
             $objGeolocation->setIP("{$arrIP['0']}.{$arrIP['1']}.{$arrIP['2']}.0");
             $objGeolocation->setCountryShort($country_short);
             $objGeolocation->setCountry($arrCountries[$country_short]);
         } else {
             return false;
         }
     } else {
         $arrCountries = $this->getCountries();
         $objGeolocation->setCountryShort(self::$arrIPCache[$ipNum]);
         $objGeolocation->setCountry($arrCountries[self::$arrIPCache[$ipNum]]);
     }
     return $objGeolocation;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param type $arrReturn
  * @return array 
  */
 protected function ajaxSetError($arrReturn)
 {
     switch ($this->Input->post("errID")) {
         case 1:
             $strError = "Premission denined";
             break;
         case 2:
             $strError = "Position unavailable";
             break;
         case 3:
             $strError = "Timeout";
             break;
         case 10:
             $strError = "Not supported Browser.";
             break;
         default:
             $strError = "Unknown error";
             break;
     }
     $this->objUserGeolocation->setFailed(true);
     // Set information for geolocation
     $this->objUserGeolocation->setError($strError);
     $this->objUserGeolocation->setErrorID($this->Input->post("errID"));
     return $arrReturn;
 }
Ejemplo n.º 3
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;
 }
 /**
  *
  * @param type $strConfig
  * @param GeolocationContainer $objGeolocation
  * @return boolean|\GeolocationContainer 
  */
 public function getLocation($strConfig, GeolocationContainer $objGeolocation)
 {
     $objRequest = new Request();
     $objRequest->send(vsprintf($strConfig, array($objGeolocation->getLat(), $objGeolocation->getLon())));
     if ($objRequest->code != 200) {
         $this->log("Error by location service: " . vsprintf("Request error code %s - %s ", array($objRequest->code, $objRequest->error)), __CLASS__ . " | " . __FUNCTION__, __FUNCTION__);
         return false;
     }
     $arrJson = json_decode($objRequest->response, true);
     if (!is_array($arrJson)) {
         $this->log("Response is not a array.", __CLASS__ . " | " . __FUNCTION__, __FUNCTION__);
         return false;
     }
     $arrCountries = $this->getCountries();
     $strCountryShort = $arrJson['address']['country_code'];
     $strCounty = $arrCountries[$arrJson['address']['country_code']];
     $objGeolocation->setCountryShort($strCountryShort);
     $objGeolocation->setCountry($strCounty);
     return $objGeolocation;
 }