Page 1 of 2

[BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Sep 22, 2013 1:23 pm
by Goztow
Mod name: Country flags on posts based on ip
Mod description: adds small flags to the post details of each post (see screenshot below). These small flags are based on the IP of the poster.

Image

Phpbb version: 3.0.11/12
Mod version: 1.0.0

Comments: this existed for phpbb2 but after searching for a while, I realized that the attempts for this modification were all abandoned nowadays. Maybe there exists a working mod but I did not find it. Anyway, this is my version.

Before installing: Install this in production on your own risk!

Files changes In case of problems, I keep the manual file changes below Note: files of Ver 0.11.

Downloads:

This Mod has been packed for phpBB 3.0.14
Download: phpBB country IP flags in posts (by zac2613, I did not check this version personally)
3.0.11/12 phpBB Country flags in posts based on ip Ver 1.0.0 (by zac2613, I did not check this version personally)
3.0.11/12 phpBB Country flags in posts based on ip Ver 0.11

FAQ / Known issues

1. SEO-mod compatibility

I presume there will be a problem if you're using a SEO-mod but post here if you do and I can help you solved the problem.

Old instructions (now available in the download package)
1. Upload these files

Click here to download them.
the /flags/ directory --> /images/flags/
the /geolitedb/ directory in /geolitedb/

Note that the geoIP.dat file is the September 2013 database file from http://dev.maxmind.com/geoip/legacy/geolite/ . Maxmind updates it every month around the 6th. You can simply overwrite the file with a newer version.

2. Make the following changes in viewtopic.php

FIND

Code: Select all

include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 
AFTER, ADD

Code: Select all

//needed for Goz geoiplite db mod
include($phpbb_root_path . 'geolitedb/geoip.inc');
 
FIND

Code: Select all

// Posts are stored in the $rowset array while $attach_list, $user_cache
// and the global bbcode_bitfield are built
while ($row = $db->sql_fetchrow($result))
{
 
AFTER, ADD

Code: Select all

    //Goz geoiplite db mod    
$correctlink = "".substr($_SERVER['SCRIPT_FILENAME'], 0, -13)."geolitedb/GeoIP.dat";
            $gi = geoip_open("$correctlink",GEOIP_STANDARD);

            $user_country_code = geoip_country_code_by_addr($gi, $row['poster_ip']);
            $user_country_name = geoip_country_name_by_addr($gi, $row['poster_ip']);

            geoip_close($gi);
            $user_country_flag = "<img src='" . $phpbb_root_path . "images/flags/" . strtolower($user_country_code) .".png' alt='$user_country_name' title='$user_country_name'>";
 
FIND

Code: Select all

'post_edit_locked'    => $row['post_edit_locked'],
 
AFTER, ADD

Code: Select all

//Goz geoiplite db mod
'country_flag'   => $user_country_flag,
 
FIND

Code: Select all

'POSTER_ID'            => $poster_id,
 
AFTER, ADD

IF YOU WANT EVERYONE TO SEE THE FLAGS

Code: Select all

//Goz geoiplite db mod
        'USER_COUNTRY_FLAG'  => $row['country_flag'],
 
IF YOU ONLY WANT MODERATORS OR ADMINS TO SEE THE FLAGS

Code: Select all


//Goz geoiplite db mod
        'USER_COUNTRY_FLAG'  => (($auth->acl_get('a_') || $auth->acl_get('m_')) && $user->data['is_registered']) ? $row['country_flag'] : '',
 
3. Make the following changes in styles/prosilver/template/viewtopic_body.html

Find:

Code: Select all

			<p class="author"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF -->{L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong> &raquo; {postrow.POST_DATE} </p>
Inline find:

Code: Select all

{postrow.POST_DATE}
Add after:

Code: Select all

<!-- IF postrow.USER_COUNTRY_FLAG -->&nbsp;{postrow.USER_COUNTRY_FLAG}<!-- ENDIF -->
[/color]
Additions to update 1.0.0
[Added] Mod enable/disable now controlled via Board configuration/Board features.
[Added] Enable/disable Switch for view by everyone or Admin/Mods only.
[Added] Enable/disable Posted by.
[Added] SubSilver2 style edits.
[Fix] W3C validation on Image code.

Image

Downloads:
3.0.11/12 phpBB Country flags in posts based on ip Ver 1.0.0 (by zac2613, I did not check this version personally)
3.0.11/12 phpBB Country flags in posts based on ip Ver 0.11

Update: 14th July 2014

Re: [alpha]Country flags on posts based on ip (geoip lite)

Posted: Sun Sep 22, 2013 3:26 pm
by 5hocK
All good for me except No.3, couldn't find {L_POSTED_ON_DATE} {postrow.POST_DATE}
Got this instead
Find:

Code: Select all

			<p class="author"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF -->{L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong> &raquo; {postrow.POST_DATE} </p>
Inline find:

Code: Select all

{postrow.POST_DATE}
Add after:

Code: Select all

<!-- IF postrow.USER_COUNTRY_FLAG -->&nbsp;{postrow.USER_COUNTRY_FLAG}<!-- ENDIF -->
Image

Re: [alpha]Country flags on posts based on ip (geoip lite)

Posted: Sun Sep 22, 2013 7:13 pm
by Goztow
Thanks a bunch, updated. How long did the installation time take you?

Re: [alpha]Country flags on posts based on ip (geoip lite)

Posted: Sun Sep 22, 2013 8:25 pm
by 5hocK
About 3 minutes, would have been quicker if that one edit was findable ;)

Edit:
subsilver2/template/viewtopic_body.html

Find:

Code: Select all

<td class="gensmall" width="100%"><div style="float: {S_CONTENT_FLOW_BEGIN};">&nbsp;<b>{L_POST_SUBJECT}:</b> <a href="#p{postrow.POST_ID}">{postrow.POST_SUBJECT}</a></div><div style="float: {S_CONTENT_FLOW_END};"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF --><b>{L_POSTED}:</b> {postrow.POST_DATE}&nbsp;</div></td>
Replace with:

Code: Select all

<td class="gensmall" width="100%"><div style="float: {S_CONTENT_FLOW_BEGIN};">&nbsp;<b>{L_POST_SUBJECT}:</b> <a href="#p{postrow.POST_ID}">{postrow.POST_SUBJECT}</a></div><div style="float: {S_CONTENT_FLOW_END};"><!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF --><b>{L_POSTED}:</b> {postrow.POST_DATE}<!-- IF postrow.USER_COUNTRY_FLAG -->&nbsp;{postrow.USER_COUNTRY_FLAG}<!-- ENDIF --></div></td>
Image

Re: [alpha]Country flags on posts based on ip (geoip lite)

Posted: Mon Sep 23, 2013 1:52 am
by prototech
As per rule 5b of the MODs in Development forum rules, file changes must be provided as a download instead of being posted directly in your topic. You can use the MODX creator to create the necessary MODX installation file. The MOD packaging guidelines will also provide some guidance when packaging your MOD.

Please take a look into this as soon as possible. Thanks. :)

Re: [ALPHA] Country flags on posts based on ip (geoip lite)

Posted: Mon Sep 23, 2013 7:30 am
by Goztow
I made it so.

Re: [ALPHA] Country flags on posts based on ip (geoip lite)

Posted: Mon Sep 23, 2013 3:58 pm
by SwT-CarbonzZ
Nice i will follow this so i can use it on my live board :)

Nice to see a developer from Belgium :-D

Re: [ALPHA] Country flags on posts based on ip (geoip lite)

Posted: Sat Sep 28, 2013 9:04 pm
by Goztow
Could someone else confirm that the newly released zip works, plz?

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Oct 27, 2013 8:35 am
by Goztow
Updated to beta (no code changes though). I have been running this mod for a long enough period to feel confident about it.

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sat Dec 28, 2013 2:47 am
by Lonewolf147
Hello
I just added this code to my board and it sorta works. I get flags on every post, but they are not the correct country. All the USA posts are showing a United Kingdom flag. France and Canada are showing up correctly though.

Any ideas?

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sat Dec 28, 2013 7:11 pm
by ViolaF
may a proxy is in effect?

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Dec 29, 2013 11:49 am
by Lonewolf147
That would make sense since I'm hosting the board on a computer on my home LAN. It's probably reading the local IP address instead of my ISP's IP address. Any ideas how to get it to check my external IP instead of the internal IP?

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Dec 29, 2013 11:53 am
by Goztow
Maybe it's jsut a flag that has a wrong name? Could you right click it and check its name?

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Dec 29, 2013 12:18 pm
by Lonewolf147
I did check, it was the correct flag. In fact, while I was writing, someone in the US made a post from outside my LAN and the US flag shows up correctly for them. It's only the posts that the people logged onto my LAN make that have the wrong image.

Re: [BETA] Country flags on posts based on ip (geoip lite)

Posted: Sun Dec 29, 2013 12:36 pm
by Goztow
Make this change

Code: Select all

$user_country_flag = "<img src='" . $phpbb_root_path . "images/flags/" . strtolower($user_country_code) .".png' alt='$user_country_name' title='$user_country_name'> $correctlink";
 
(adding $correctlink)

it should show you the ip that generated the country. It could help to determine the cause. Post it here or PM it to me if u prefer.