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

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Suggested Hosts
Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sun Sep 22, 2013 1:23 pm

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
Last edited by Goztow on Mon Jun 08, 2015 7:44 pm, edited 8 times in total.

User avatar
5hocK
Registered User
Posts: 3012
Joined: Wed Nov 23, 2011 7:00 pm
Location: England

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

Post by 5hocK » Sun Sep 22, 2013 3:26 pm

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
A thread is pretty much a topic. Stop with the pedantics will ya.

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sun Sep 22, 2013 7:13 pm

Thanks a bunch, updated. How long did the installation time take you?

User avatar
5hocK
Registered User
Posts: 3012
Joined: Wed Nov 23, 2011 7:00 pm
Location: England

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

Post by 5hocK » Sun Sep 22, 2013 8:25 pm

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
A thread is pretty much a topic. Stop with the pedantics will ya.

User avatar
prototech
Former Team Member
Posts: 5406
Joined: Mon Mar 19, 2007 2:04 pm
Location: Southern California

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

Post by prototech » Mon Sep 23, 2013 1:52 am

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. :)
Need help with MOD/style installations or other phpBB problems? Contact me for a quote.

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Mon Sep 23, 2013 7:30 am

I made it so.

SwT-CarbonzZ
Registered User
Posts: 575
Joined: Tue Oct 12, 2010 7:17 am

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

Post by SwT-CarbonzZ » Mon Sep 23, 2013 3:58 pm

Nice i will follow this so i can use it on my live board :)

Nice to see a developer from Belgium :-D

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sat Sep 28, 2013 9:04 pm

Could someone else confirm that the newly released zip works, plz?

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sun Oct 27, 2013 8:35 am

Updated to beta (no code changes though). I have been running this mod for a long enough period to feel confident about it.

User avatar
Lonewolf147
Registered User
Posts: 77
Joined: Fri Jul 12, 2013 3:13 pm
Location: Milwaukee, WI
Name: Scott

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

Post by Lonewolf147 » Sat Dec 28, 2013 2:47 am

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?

User avatar
ViolaF
Registered User
Posts: 1368
Joined: Tue Aug 14, 2012 11:52 pm

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

Post by ViolaF » Sat Dec 28, 2013 7:11 pm

may a proxy is in effect?

User avatar
Lonewolf147
Registered User
Posts: 77
Joined: Fri Jul 12, 2013 3:13 pm
Location: Milwaukee, WI
Name: Scott

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

Post by Lonewolf147 » Sun Dec 29, 2013 11:49 am

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?

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sun Dec 29, 2013 11:53 am

Maybe it's jsut a flag that has a wrong name? Could you right click it and check its name?

User avatar
Lonewolf147
Registered User
Posts: 77
Joined: Fri Jul 12, 2013 3:13 pm
Location: Milwaukee, WI
Name: Scott

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

Post by Lonewolf147 » Sun Dec 29, 2013 12:18 pm

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.

Goztow
Registered User
Posts: 364
Joined: Fri Aug 17, 2007 10:31 am
Location: Belgium
Contact:

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

Post by Goztow » Sun Dec 29, 2013 12:36 pm

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.

Locked

Return to “[3.0.x] MODs in Development”

Who is online

Users browsing this forum: Google [Bot] and 17 guests

cron