44 return [
'de',
'en',
'es',
'fr',
'ja',
'pt-BR',
'ru',
'zh-CN'];
55 if (!$dataResult->isSuccess())
60 $geoData =
new Data();
61 $geoData->lang = ($lang !=
'' ? $lang :
'en');
65 $type = $this->config[
'TYPE'] ??
'city';
69 $record = static::$reader->city($ip);
73 $record = static::$reader->country($ip);
76 $geoData->ipNetwork = $record->traits->network;
78 $geoData->continentCode = $record->continent->code;
79 $geoData->continentName = Encoding::convertEncodingToCurrent(($record->continent->names[$geoData->lang] ?? $record->continent->name));
81 $geoData->countryCode = $record->country->isoCode;
82 $geoData->countryName = Encoding::convertEncodingToCurrent(($record->country->names[$geoData->lang] ?? $record->country->name));
84 if ($record instanceof \GeoIp2\Model\City)
86 if (isset($record->subdivisions[0]))
89 $subdivision = $record->subdivisions[0];
90 $geoData->regionCode = $subdivision->isoCode;
91 $geoData->regionName = Encoding::convertEncodingToCurrent(($subdivision->names[$geoData->lang] ?? $subdivision->name));
92 $geoData->regionGeonameId = $subdivision->geonameId;
94 if ($subdivision->geonameId)
96 $geoData->geonames[$subdivision->geonameId] = $subdivision->names;
100 if (isset($record->subdivisions[1]))
103 $subdivision = $record->subdivisions[1];
104 $geoData->subRegionCode = $subdivision->isoCode;
105 $geoData->subRegionName = Encoding::convertEncodingToCurrent(($subdivision->names[$geoData->lang] ?? $subdivision->name));
106 $geoData->subRegionGeonameId = $subdivision->geonameId;
108 if ($subdivision->geonameId)
110 $geoData->geonames[$subdivision->geonameId] = $subdivision->names;
114 $geoData->cityName = Encoding::convertEncodingToCurrent(($record->city->names[$geoData->lang] ?? $record->city->name));
115 $geoData->cityGeonameId = $record->city->geonameId;
117 if ($record->city->geonameId)
119 $geoData->geonames[$record->city->geonameId] = $record->city->names;
122 $geoData->latitude = $record->location->latitude;
123 $geoData->longitude = $record->location->longitude;
124 $geoData->timezone = $record->location->timeZone;
126 $geoData->zipCode = $record->postal->code;
128 $geoData->ispName = $record->traits->isp;
129 $geoData->organizationName = $record->traits->organization;
130 $geoData->asn = $record->traits->autonomousSystemNumber;
131 $geoData->asnOrganizationName = $record->traits->autonomousSystemOrganization;
134 $dataResult->setGeoData($geoData);
136 catch(Exception\AddressNotFoundException $e)
140 catch(Reader\InvalidDatabaseException $e)
154 return (isset($this->config[
'FILE']) && $this->config[
'FILE'] !==
'' && file_exists($this->config[
'FILE']));
164 'TYPE' => $postFields[
'TYPE'] ??
'city',
165 'FILE' => $postFields[
'FILE'] ??
'',
179 'VALUE' => ($this->config[
'TYPE'] ??
'city'),
181 'city' =>
'GeoIP2/GeoLite2 City',
182 'country' =>
'GeoIP2/GeoLite2 Country',
190 'VALUE' => htmlspecialcharsbx($this->config[
'FILE'] ??
''),
201 $type = $this->config[
'TYPE'] ??
'city';
215 $dataResult =
new Result();
217 if (static::$reader ===
null)
219 if ($this->config[
'FILE'] ==
'')
225 if (!file_exists($this->config[
'FILE']))
233 static::$reader =
new Database\Reader($this->config[
'FILE']);
235 catch(Reader\InvalidDatabaseException $e)
static getMessage($code, $replace=null, $language=null)
getDataResult($ip, $lang='')
createConfigField(array $postFields)
static createForCountry()