Author: Steve Bauman (steven_bauman_7@hotmail.com)
Beispiel #1
1
 /**
  * Retrieves the location from the driver MaxMind and returns a location object.
  *
  * @param string $ip
  *
  * @return Location
  */
 public function get($ip)
 {
     $location = new Location();
     $settings = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.MaxMind.configuration');
     try {
         if ($settings['web_service']) {
             $maxmind = new Client($settings['user_id'], $settings['license_key']);
         } else {
             $path = app_path('database/maxmind/GeoLite2-City.mmdb');
             /*
              * Laravel 5 compatibility
              */
             if ($this->instance->getConfigSeparator() === '.') {
                 $path = base_path('database/maxmind/GeoLite2-City.mmdb');
             }
             $maxmind = new Reader($path);
         }
         $record = $maxmind->city($ip);
         $location->ip = $ip;
         $location->isoCode = $record->country->isoCode;
         $location->countryName = $record->country->name;
         $location->cityName = $record->city->name;
         $location->postalCode = $record->postal->code;
         $location->latitude = $record->location->latitude;
         $location->driver = get_class($this);
     } catch (\Exception $e) {
         $location->error = true;
     }
     return $location;
 }
Beispiel #2
0
 /**
  * Retrieves the location from the driver IpInfo and returns a location object
  *
  * @param string $ip
  * @return Location
  */
 public function get($ip)
 {
     $location = new Location();
     try {
         $contents = json_decode(file_get_contents($this->url . $ip));
         $location->ip = $ip;
         if (property_exists($contents, 'country')) {
             $location->countryCode = $contents->country;
         }
         if (property_exists($contents, 'postal')) {
             $location->postalCode = $contents->postal;
         }
         if (property_exists($contents, 'region')) {
             $location->regionName = $contents->region;
         }
         if (property_exists($contents, 'city')) {
             $location->cityName = $contents->city;
         }
         if (property_exists($contents, 'loc')) {
             $coords = explode(',', $contents->loc);
             if (array_key_exists(0, $coords)) {
                 $location->latitude = $coords[0];
             }
             if (array_key_exists(1, $coords)) {
                 $location->longitude = $coords[1];
             }
         }
         $countries = $this->config->get('location' . $this->instance->getConfigSeparator() . 'country_codes');
         /*
          * See if we can convert the country code to the country name
          */
         if (is_array($countries) && array_key_exists($location->countryCode, $countries)) {
             $location->countryName = $countries[$location->countryCode];
         }
         $location->driver = get_class($this);
     } catch (\Exception $e) {
         $location->error = true;
     }
     return $location;
 }
Beispiel #3
0
 /**
  * Constructor.
  *
  * @param LocationInstance $instance
  */
 public function __construct(LocationInstance $instance)
 {
     $this->instance = $instance;
     $this->config = $this->instance->getConfig();
     $this->url = $this->config->get('location.drivers.GeoPlugin.url');
 }
Beispiel #4
0
 /**
  * Constructor.
  *
  * @param LocationInstance $instance
  */
 public function __construct(LocationInstance $instance)
 {
     $this->instance = $instance;
     $this->config = $this->instance->getConfig();
 }
Beispiel #5
0
 /**
  * @param LocationInstance $instance
  */
 public function __construct(LocationInstance $instance)
 {
     $this->instance = $instance;
     $this->config = $this->instance->getConfig();
     $this->url = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.Telize.url');
 }