Minor improvements (#1481)

* Minor improvements

* Updated

* Update functions.php

* Updated

* Update .gitignore

* Updated

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-05-22 14:21:07 +07:00 committed by GitHub
commit f584cf5d29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 10 additions and 108 deletions

View file

@ -2166,26 +2166,17 @@ function readUpdaterFile(): array|bool
}
/**
* Show country ISO Code by user IP address
* IP Geolocation API
*
* @param string $ipAddress
* @param int $port
* @return mixed|string|null
*/
function getCountryByIP(string $ipAddress, int $port = 1111): mixed
function infoByIP(string $ipAddress, int $port = 0): mixed
{
global $lang;
if (!$data = CACHE('bb_ip2countries')->get($ipAddress . '_' . $port)) {
$cityDbReader = new \GeoIp2\Database\Reader(INT_DATA_DIR . '/GeoLite2-City.mmdb');
try {
$record = $cityDbReader->city($ipAddress);
$data = $record->country->isoCode;
} catch (\GeoIp2\Exception\AddressNotFoundException $e) {
$data = $lang['UNKNOWN'];
} catch (\MaxMind\Db\Reader\InvalidDatabaseException $e) {
bb_die($e->getMessage());
}
$response = file_get_contents(API_IP_URL . $ipAddress);
$data = json_decode($response, true);
CACHE('bb_ip2countries')->set($ipAddress . '_' . $port, $data, 1200);
}