Skip to content

Commit 76596ee

Browse files
committed
Fixed Telize driver, as well as driver backups not using inputted IP address. Updated config layout
1 parent c8923c6 commit 76596ee

File tree

4 files changed

+395
-346
lines changed

4 files changed

+395
-346
lines changed

src/Stevebauman/Location/Drivers/Telize.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public function __construct($config)
1212
$this->config = $config;
1313

1414
$this->url = $this->config->get('location::drivers.Telize.url');
15-
1615
}
1716

1817
public function get($ip)
@@ -21,29 +20,49 @@ public function get($ip)
2120

2221
try {
2322
$contents = json_decode(file_get_contents($this->url.$ip));
24-
23+
2524
$location->ip = $ip;
2625

27-
$location->countryName = $contents->country;
26+
if(property_exists($contents, 'country')) {
27+
$location->countryName = $contents->country;
28+
}
2829

29-
$location->countryCode = $contents->country_code;
30+
if(property_exists($contents, 'country_code')) {
31+
$location->countryCode = $contents->country_code;
32+
}
3033

31-
$location->regionName = $contents->region;
34+
if(property_exists($contents, 'region')) {
35+
$location->regionName = $contents->region;
36+
}
3237

33-
$location->regionCode = $contents->region_code;
38+
if(property_exists($contents, 'region_code')) {
39+
$location->regionCode = $contents->region_code;
40+
}
3441

35-
$location->cityName = $contents->city;
42+
if(property_exists($contents, 'city')) {
43+
$location->cityName = $contents->city;
44+
}
3645

37-
$location->postalCode = $contents->postal_code;
46+
if(property_exists($contents, 'postal_code')) {
47+
$location->postalCode = $contents->postal_code;
48+
}
3849

39-
$location->longitude = $contents->longitude;
50+
if(property_exists($contents, 'longitude')) {
51+
$location->longitude = $contents->longitude;
52+
}
4053

41-
$location->latitude = $contents->latitude;
54+
if(property_exists($contents, 'latitude')) {
55+
$location->latitude = $contents->latitude;
56+
}
57+
58+
if(property_exists($contents, 'isp')) {
59+
$location->isp = $contents->isp;
60+
}
4261

4362
$location->driver = get_class($this);
4463

4564
} catch (\Exception $e) {
46-
65+
4766
$location->error = true;
4867

4968
}

src/Stevebauman/Location/Location.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class Location {
2828
*/
2929
private $location;
3030

31+
/*
32+
* Holds the current IP of the user
33+
*/
34+
private $ip;
35+
3136
public function __construct(Config $config, Session $session)
3237
{
3338
$this->config = $config;
@@ -109,7 +114,7 @@ public function lists($value = '', $name = '')
109114
*
110115
* @param string $value
111116
* @param string $name
112-
* @return type
117+
* @return array
113118
*/
114119
public function dropdown($value = '', $name = '')
115120
{
@@ -169,7 +174,7 @@ private function setLocation($ip = NULL)
169174
if($this->config->get('location::localhost_forget_location')) {
170175
$this->session->forget('location');
171176
}
172-
177+
173178
/*
174179
* Check if the location has already been set in the current session
175180
*/
@@ -183,14 +188,14 @@ private function setLocation($ip = NULL)
183188
} else {
184189

185190
/*
186-
* If an IP address is supplied, we'll send it right to the driver,
187-
* if not, we'll get it from the client automatically
191+
* Set the IP
188192
*/
189-
if($ip) {
190-
$this->location = $this->driver->get($this->validateIp($ip));
191-
} else {
192-
$this->location = $this->driver->get($this->getClientIP());
193-
}
193+
$this->setIp($ip);
194+
195+
/*
196+
* Set the location
197+
*/
198+
$this->location = $this->driver->get($this->ip);
194199

195200
/*
196201
* The locations object property 'error' will be true if an exception has
@@ -207,6 +212,25 @@ private function setLocation($ip = NULL)
207212
}
208213
}
209214

215+
/**
216+
* Sets the current IP property. If an IP address is supplied, it is validated
217+
* before it's set, otherwise it is grabbed automatically from the client
218+
*
219+
* @param string $ip
220+
*/
221+
private function setIp($ip)
222+
{
223+
/*
224+
* If an IP address is supplied, we'll validate it and set it,
225+
* otherwise we'll grab it automatically from the client
226+
*/
227+
if($ip) {
228+
$this->ip = $this->validateIp($ip);
229+
} else {
230+
$this->ip = $this->getClientIP();
231+
}
232+
}
233+
210234
/**
211235
* Returns the IP address if it is valid, throws an exception if it's not
212236
*
@@ -242,8 +266,8 @@ private function getLocationFromFallback()
242266
foreach($fallbacks as $fallbackDriver) {
243267

244268
$driver = $this->getDriver($fallbackDriver);
245-
246-
$location = $driver->get($this->getClientIP());
269+
270+
$location = $driver->get($this->ip);
247271

248272
/*
249273
* If no error has occured, return the new location

src/Stevebauman/Location/Objects/Location.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Location {
2828

2929
public $areaCode = '';
3030

31+
public $isp = '';
32+
3133
/*
3234
* Holds the IP address that was used to retrieve location information
3335
*/

0 commit comments

Comments
 (0)