File manager - Edit - /home/opticamezl/www/newok/plugins/system/cookiespolicynotificationbar/lib/geoip2/geoip2.php
Back
<?php /* ====================================================== # Cookies Policy Notification Bar for Joomla! - v4.4.4 (pro version) # ------------------------------------------------------- # For Joomla! CMS (v4.x) # Author: Web357 (Yiannis Christodoulou) # Copyright: (©) 2014-2024 Web357. All rights reserved. # License: GNU/GPLv3, https://www.gnu.org/licenses/gpl-3.0.html # Website: https://www.web357.com # Demo: https://demo-joomla.web357.com/cookies-policy-notification-bar # Support: support@web357.com # Last modified: Monday 27 October 2025, 03:29:25 PM ========================================================= */ defined('_JEXEC') or die(); use GeoIp2\Database\Reader; class Web357GeoIp2 { /** * The MaxMind GeoLite database reader * * @var Reader * * @since 2.0 */ private $reader = null; /** * Records for IP addresses already looked up * * @var array * * @since 2.0 */ private $lookups = array(); /** * Public constructor. Loads up the GeoLite2 database. */ public function __construct() { // Default to a country-level database $filePath = __DIR__ . '/db/GeoLite2-Country.mmdb'; try { $this->reader = new Reader($filePath); } // If anything goes wrong, MaxMind will raise an exception, resulting in a WSOD. Let's be sure to catch everything catch(\Exception $e) { $this->reader = null; } } /** * Gets a raw country record from an IP address * * @param string $ip The IP address to look up * * @return mixed A \GeoIp2\Model\Country record if found, false if the IP address is not found, null if the db can't be loaded */ public function getCountryRecord($ip) { if (!array_key_exists($ip, $this->lookups)) { try { $this->lookups[$ip] = null; if (!is_null($this->reader)) { $this->lookups[$ip] = $this->reader->country($ip); } } catch (\GeoIp2\Exception\AddressNotFoundException $e) { $this->lookups[$ip] = false; } catch (\Exception $e) { // GeoIp2 could throw several different types of exceptions. Let's be sure that we're going to catch them all $this->lookups[$ip] = null; } } return $this->lookups[$ip]; } /** * Gets the ISO country code from an IP address * * @param string $ip The IP address to look up * * @return mixed A string with the country ISO code if found, false if the IP address is not found, null if the db can't be loaded */ public function getCountryCode($ip) { $record = $this->getCountryRecord($ip); if ($record === false) { return false; } if (is_null($record)) { return false; } return $record->country->isoCode; } /** * Gets the country name from an IP address * * @param string $ip The IP address to look up * @param string $locale The locale of the country name, e.g 'de' to return the country names in German. If not specified the English (US) names are returned. * * @return mixed A string with the country name if found, false if the IP address is not found, null if the db can't be loaded */ public function getCountryName($ip, $locale = null) { $record = $this->getCountryRecord($ip); if ($record === false) { return false; } if (is_null($record)) { return false; } if (empty($locale)) { return $record->country->name; } return $record->country->names[$locale]; } /** * Gets the continent ISO code from an IP address * * @param string $ip The IP address to look up * * @return mixed A string with the country name if found, false if the IP address is not found, null if the db can't be loaded */ public function getContinent($ip, $locale = null) { $record = $this->getCountryRecord($ip); if ($record === false) { return false; } if (is_null($record)) { return false; } return $record->continent->code; } /** * Gets the continent name from an IP address * * @param string $ip The IP address to look up * @param string $locale The locale of the continent name, e.g 'de' to return the country names in German. If not specified the English (US) names are returned. * * @return mixed A string with the country name if found, false if the IP address is not found, null if the db can't be loaded */ public function getContinentName($ip, $locale = null) { $record = $this->getCountryRecord($ip); if ($record === false) { return false; } if (is_null($record)) { return false; } if (empty($locale)) { return $record->continent; } return $record->continent->names[$locale]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings