/** * Load into Location object all available data * * @param GeoIp_Location $location */ public function loadLocation(GeoIp_Location $location) { require_once "Net/GeoIP.php"; $flag = Net_GeoIP::STANDARD; //TODO: on some hostings it failed to work (e.g. mosso.com), so we will disable option of shared memory until it will be solved // if (Gpf_Php::isFunctionEnabled('shmop_open')) { // $flag = Net_GeoIP::SHARED_MEMORY; // } $geoip = Net_GeoIP::getInstance($this->file->getFileName(), $flag); if ($geoipLocation = @$geoip->lookupLocation($location->getIpString())) { $location->setCountryCode($geoipLocation->countryCode); $location->setCity($geoipLocation->city); $location->setAreaCode($geoipLocation->areaCode); $location->setCountryName($geoipLocation->countryName); $location->setDmaCode($geoipLocation->dmaCode); $location->setLatitude($geoipLocation->latitude); $location->setLongitude($geoipLocation->longitude); $location->setPostalCode($geoipLocation->postalCode); $location->setRegion($geoipLocation->region); } else { throw new Gpf_Exception($this->_('Ip address %s is not in geoip database.', $location->getIpString())); } }
/** * Load Location information for Ip address specified in Id * * @anonym * @service geoip read * @param $fields */ public function load(Gpf_Rpc_Params $params) { $data = new Gpf_Rpc_Data($params); $location = new GeoIp_Location(); $location->setIpString($data->getId()); $location->load(); $data->setValue('ip', $location->getIpString()); $data->setValue('countryCode', $location->getCountryCode()); $data->setValue('countryName', $location->getCountryName()); $data->setValue('city', $location->getCity()); $data->setValue('areaCode', $location->getAreaCode()); $data->setValue('dmaCode', $location->getDmaCode()); $data->setValue('latitude', $location->getLatitude()); $data->setValue('longitude', $location->getLongitude()); $data->setValue('postalCode', $location->getPostalCode()); $data->setValue('region', $location->getRegion()); return $data; }