diff options
| author | Jano Slota <jano@alokal.eu> | 2014-07-04 02:47:24 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-07-06 01:29:12 +0200 |
| commit | db3c7f4ee984002fccb86e0cb3fda45edde74351 (patch) | |
| tree | 3559fe5daab91f50f134e8bb9a12cb1ac9c7595e /inc/functions.php | |
| parent | 4adf893c3906bebb29fc1720793366291da87b58 (diff) | |
Rework the GeoIP code, add country-based poster names
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/inc/functions.php b/inc/functions.php index 6ce76472..4313e531 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -21,6 +21,8 @@ require_once 'inc/api.php'; require_once 'inc/bans.php'; require_once 'inc/lib/gettext/gettext.inc'; +use Lifo\IP\IP; + // the user is not currently logged in as a moderator $mod = false; @@ -242,6 +244,23 @@ function loadConfig() { if (is_array($config['anonymous'])) $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + + if ($config['country_flags'] || $config['country_anonymous']) { + require_once 'inc/lib/geoip/geoip.inc'; + $gi=geoip_open('inc/lib/geoip/GeoIPv6.dat', GEOIP_STANDARD); + $ipaddy = $_SERVER['REMOTE_ADDR']; + if (IP::isIPv4($ipaddy)) + $ipaddy = IP::to_ipv6($ipaddy, true); + global $country_code, $country_name; + $country_code = strtolower(geoip_country_code_by_addr_v6($gi, $ipaddy)); + $country_name = geoip_country_name_by_addr_v6($gi, $ipaddy); + if (isset($config['country_anonymous'][$country_code])) { + if (is_array($config['country_anonymous'][$country_code])) + $config['anonymous'] = $config['country_anonymous'][$country_code][array_rand($config['country_anonymous'][$country_code])]; + else + $config['anonymous'] = $config['country_anonymous'][$country_code]; + } + } event('load-config'); |
