Exemplo n.º 1
0
    /**
     * 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;
    }
Exemplo n.º 2
0
    public function getDefaultCountry(Gpf_Plugins_ValueContext $valueContext) {
        $ip = Gpf_Http::getRemoteIp();
        if (!strlen($ip) || $ip == '127.0.0.1') {
            return;
        }

        try {
            $location = new GeoIp_Location();
            $location->setIpString($ip);
            $location->load();
            $valueContext->set($location->getCountryCode());
        } catch (Exception $e) {
        }
    }
 /**
  * @return GeoIp_Location
  * @throws Gpf_Exception
  */
 protected function getLocation($ip) {
     $location = new GeoIp_Location();
     $location->setIpString($ip);
     $location->load();
     return $location;
 }