mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 13:24:01 -07:00
Show client country in seeders / leechers list 🌍 (#1478)
* Show client country in seeders / leechers list * Update functions.php * Update functions.php * Update functions.php * Updated * Update displaying_torrent.php * Update functions.php * Update viewtopic_torrent.tpl * Update viewtopic_torrent.tpl * Update functions.php * Update functions.php * Update functions.php * Update functions.php * Update config.php * Updated * Updated * Updated * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Update update_geolite_db.php * Updated * Update viewtopic_torrent.tpl * Updated * Update composer.lock * Update defines.php * Updated * Update init_bb.php * Update CHANGELOG.md
This commit is contained in:
parent
2fa3520872
commit
459fba6b86
20 changed files with 475 additions and 89 deletions
|
@ -2165,3 +2165,30 @@ function readUpdaterFile(): array|bool
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show country ISO Code by user IP address
|
||||
*
|
||||
* @param string $ipAddress
|
||||
* @param int $port
|
||||
* @return mixed|string|null
|
||||
*/
|
||||
function countryByIP(string $ipAddress, int $port = 1111): 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());
|
||||
}
|
||||
CACHE('bb_ip2countries')->set($ipAddress . '_' . $port, $data, 1200);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue