34 return Loc::getMessage(
"geoip_geoip2_desc");
43 return [
'de',
'en',
'es',
'fr',
'ja',
'pt-BR',
'ru',
'zh-CN'];
54 if (!$dataResult->isSuccess())
59 $geoData =
new Data();
64 $type = $this->config[
'TYPE'] ??
'city';
68 $record = static::$reader->city($ip);
72 $record = static::$reader->country($ip);
75 $geoData->ipNetwork = $record->traits->network;
77 $geoData->continentCode = $record->continent->code;
78 $geoData->continentName = ($record->continent->names[$geoData->lang] ?? $record->continent->name);
80 $geoData->countryCode = $record->country->isoCode;
81 $geoData->countryName = ($record->country->names[$geoData->lang] ?? $record->country->name);
83 if ($record instanceof \GeoIp2\Model\City)
85 if (isset($record->subdivisions[0]))
88 $subdivision = $record->subdivisions[0];
89 $geoData->regionCode = $subdivision->isoCode;
90 $geoData->regionName = ($subdivision->names[$geoData->lang] ?? $subdivision->name);
91 $geoData->regionGeonameId = $subdivision->geonameId;
93 if ($subdivision->geonameId)
95 $geoData->geonames[$subdivision->geonameId] = $subdivision->names;
99 if (isset($record->subdivisions[1]))
102 $subdivision = $record->subdivisions[1];
103 $geoData->subRegionCode = $subdivision->isoCode;
104 $geoData->subRegionName = ($subdivision->names[$geoData->lang] ?? $subdivision->name);
105 $geoData->subRegionGeonameId = $subdivision->geonameId;
107 if ($subdivision->geonameId)
109 $geoData->geonames[$subdivision->geonameId] = $subdivision->names;
113 $geoData->cityName = ($record->city->names[$geoData->lang] ?? $record->city->name);
114 $geoData->cityGeonameId = $record->city->geonameId;
116 if ($record->city->geonameId)
118 $geoData->geonames[$record->city->geonameId] = $record->city->names;
121 $geoData->latitude = $record->location->latitude;
122 $geoData->longitude = $record->location->longitude;
123 $geoData->timezone = $record->location->timeZone;
125 $geoData->zipCode = $record->postal->code;
127 $geoData->ispName = $record->traits->isp;
128 $geoData->organizationName = $record->traits->organization;
129 $geoData->asn = $record->traits->autonomousSystemNumber;
130 $geoData->asnOrganizationName = $record->traits->autonomousSystemOrganization;
133 $dataResult->setGeoData($geoData);
135 catch(Exception\AddressNotFoundException)
139 catch(Reader\InvalidDatabaseException)
141 $dataResult->addError(
new Error(Loc::getMessage(
"geoip_geoip2_err_reading")));
153 return (isset($this->config[
'FILE']) && $this->config[
'FILE'] !==
'' && file_exists($this->config[
'FILE']));
163 'TYPE' => $postFields[
'TYPE'] ??
'city',
164 'FILE' => $postFields[
'FILE'] ??
'',
176 'TITLE' => Loc::getMessage(
"geoip_geoip2_type"),
178 'VALUE' => ($this->config[
'TYPE'] ??
'city'),
180 'city' =>
'GeoIP2/GeoLite2 City',
181 'country' =>
'GeoIP2/GeoLite2 Country',
187 'TITLE' => Loc::getMessage(
"geoip_geoip2_file"),
200 $type = $this->config[
'TYPE'] ??
'city';
214 $dataResult =
new Result();
216 if (static::$reader ===
null)
218 if ($this->config[
'FILE'] ==
'')
220 $dataResult->addError(
new Error(Loc::getMessage(
"geoip_geoip2_no_file")));
224 if (!file_exists($this->config[
'FILE']))
226 $dataResult->addError(
new Error(Loc::getMessage(
"geoip_geoip2_file_not_found")));
232 static::$reader =
new Database\Reader($this->config[
'FILE']);
234 catch(Reader\InvalidDatabaseException)
236 $dataResult->addError(
new Error(Loc::getMessage(
"geoip_geoip2_err_reading")));
getDataResult($ip, $lang='')
createConfigField(array $postFields)
static createForCountry()
if(!defined('SITE_ID')) $lang