summaryrefslogtreecommitdiff
path: root/post.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-07-06 02:13:08 +0200
committerczaks <marcin@6irc.net>2014-07-06 02:13:08 +0200
commit9b943da60a39b6a4cdc6291ed658908f0e144d89 (patch)
treeef4fc42fbc20286e7dce3b9361c03ce20ff1e3b2 /post.php
parenta9b035d822bd39adc721013578af613ac8c74298 (diff)
Revert "Rework the GeoIP code, add country-based poster names"
This reverts commit db3c7f4ee984002fccb86e0cb3fda45edde74351.
Diffstat (limited to 'post.php')
-rw-r--r--post.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/post.php b/post.php
index dbef412e..d6dfdaa1 100644
--- a/post.php
+++ b/post.php
@@ -488,8 +488,26 @@ if (isset($_POST['delete'])) {
}
if ($config['country_flags']) {
- if (!in_array($country_code, array('eu', 'ap', 'o1', 'a1', 'a2')))
- $post['body'] .= "\n<tinyboard flag>".$country_code."</tinyboard>\n<tinyboard flag alt>".$country_name."</tinyboard>";
+ require 'inc/lib/geoip/geoip.inc';
+ $gi=geoip\geoip_open('inc/lib/geoip/GeoIPv6.dat', GEOIP_STANDARD);
+
+ function ipv4to6($ip) {
+ if (strpos($ip, ':') !== false) {
+ if (strpos($ip, '.') > 0)
+ $ip = substr($ip, strrpos($ip, ':')+1);
+ else return $ip; //native ipv6
+ }
+ $iparr = array_pad(explode('.', $ip), 4, 0);
+ $part7 = base_convert(($iparr[0] * 256) + $iparr[1], 10, 16);
+ $part8 = base_convert(($iparr[2] * 256) + $iparr[3], 10, 16);
+ return '::ffff:'.$part7.':'.$part8;
+ }
+
+ if ($country_code = geoip\geoip_country_code_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))) {
+ if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2')))
+ $post['body'] .= "\n<tinyboard flag>".strtolower($country_code)."</tinyboard>".
+ "\n<tinyboard flag alt>".geoip\geoip_country_name_by_addr_v6($gi, ipv4to6($_SERVER['REMOTE_ADDR']))."</tinyboard>";
+ }
}
if ($config['user_flag'] && isset($_POST['user_flag']))