[ABD] TULIP: Tiny User Locator by IP

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16981
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: IP Country Flags - And here's some code to get you started!

Post by DavidIQ » Wed Oct 21, 2009 8:10 pm

On request, this has been moved to the MODs in Development forum.

@dpaanlka: please change your topic title in accordance to MOD Development Forum rules section 3. Might also want to use the template listed right after that section. Thank you.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
katib
Registered User
Posts: 562
Joined: Thu Jun 26, 2008 12:27 pm

Re: [DEV] TULIP: Tiny User Locator by IP

Post by katib » Wed Oct 21, 2009 9:23 pm

Thanks for Mod
Loks quite simple and easy to install
but how about shwowing country flags on index_body.html especially at the bottom page in who is online part ?

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Wed Oct 21, 2009 9:29 pm

katib wrote:Thanks for Mod
Loks quite simple and easy to install
but how about shwowing country flags on index_body.html especially at the bottom page in who is online part ?
I'll take a look at it in a little bit when I'm done with some work, but if you want to check into it, find where the template variables are generated for that portion of the page, and add a new one for the user_id of the users being displayed. You'll have to determine how that part of the page works, but again I'll look into it in a few hours.
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

fasko
Registered User
Posts: 185
Joined: Wed Jan 28, 2009 9:49 am

Re: [DEV] TULIP: Tiny User Locator by IP

Post by fasko » Wed Oct 21, 2009 9:52 pm

When I click on viewtopic_body.html so I only have white pages
Sorry for my english

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Wed Oct 21, 2009 9:58 pm

fasko wrote:When I click on viewtopic_body.html so I only have white pages
Can you provide a link? I recently re-wrote the first post of this topic to reflect changes to the MOD, so I want to be sure I haven't accidentally left something out.

EDIT: I just installed this MOD on a clean phpBB board following my instructions exactly and it works, so I'll have to take a look at what you did to see where the installation went wrong. Try purging your cache from the Administration Control Panel before concluding that it doesn't work.
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Wed Oct 21, 2009 11:59 pm

katib wrote:Thanks for Mod
Loks quite simple and easy to install
but how about shwowing country flags on index_body.html especially at the bottom page in who is online part ?
Hey katib, go ahead and try this. It's a simple one-line edit.

Open /includes/functions.php

Find:

Code: Select all

$user_online_link = get_username_string(($row['user_type'] <> USER_IGNORE) ? 'full' : 'no_profile', $row['user_id'], $row['username'], $row['user_colour']);
Replace with:

Code: Select all

$user_online_link = '<img src="./flags/' . iptocountry($row['user_id']) . '.gif"> ' . get_username_string(($row['user_type'] <> USER_IGNORE) ? 'full' : 'no_profile', $row['user_id'], $row['username'], $row['user_colour']);
Works for me on 3.0.5! As you can see, I simply looked for the code that generates that line, and passed the user_id to TULIP's country code function.
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

User avatar
katib
Registered User
Posts: 562
Joined: Thu Jun 26, 2008 12:27 pm

Re: [DEV] TULIP: Tiny User Locator by IP

Post by katib » Thu Oct 22, 2009 9:48 am

THank so much for takig the time to help me
Worked like a charm :D
I even apply it to activity_stats_mod which sisplay the a list of users who logged in in the last 24 hours and other stuff
But I dont know how to add ALT tag to php code, like you did for .html code:

Code: Select all

<img src="./flags/{postrow.POSTER_COUNTRY}.gif" alt="{postrow.POSTER_COUNTRY_FULL}">
Thre is only one drawback
whenever I try to enter ACP, it says:

Code: Select all

Warning: fopen(./includes/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in K:\xampplite\htdocs\bb\includes\geoip.inc on line 314
Can not open ./includes/GeoIP.dat 
of course, the GeoIP.dat file is there, and it is used y board to show flags on index_body.html :roll:
once again an easy and usefull Mod :D

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Thu Oct 22, 2009 5:10 pm

katib wrote:But I dont know how to add ALT tag to php code, like you did for .html code:

Code: Select all

<img src="./flags/{postrow.POSTER_COUNTRY}.gif" alt="{postrow.POSTER_COUNTRY_FULL}">
Try this:

Code: Select all

$user_online_link = '<img src="./flags/' . iptocountry($row['user_id']) . '.gif" alt="' . iptocountryname($row['user_id']) . '"> ' . get_username_string(($row['user_type'] <> USER_IGNORE) ? 'full' : 'no_profile', $row['user_id'], $row['username'], $row['user_colour']);
katib wrote:whenever I try to enter ACP, it says:

Code: Select all

Warning: fopen(./includes/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in K:\xampplite\htdocs\bb\includes\geoip.inc on line 314
Can not open ./includes/GeoIP.dat 
of course, the GeoIP.dat file is there, and it is used y board to show flags on index_body.html :roll:
once again an easy and usefull Mod :D
Hmm... this might be related to you being on a Windows server rather than a *NIX server. Try replacing ./includes/GeoIP.dat with the full DOS-style path: K:\xampplite\htdocs\bb\includes\GeoIP.dat

I don't have any experience with Windows servers? Maybe someone else can help us? I notice the slashes are different directions! I haven't yet turned this MOD into official phpBB coding style, so maybe when I do that it will fix the problem across all server OSes.
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

User avatar
katib
Registered User
Posts: 562
Joined: Thu Jun 26, 2008 12:27 pm

Re: [DEV] TULIP: Tiny User Locator by IP

Post by katib » Thu Oct 22, 2009 5:40 pm

Thanks for the ALT tag

About the missing file, it seems that the code you added to functions.php

Code: Select all

   include_once("geoip.inc");
   $gi = geoip_open("./includes/GeoIP.dat",GEOIP_STANDARD);
   $two_letter_country_code = geoip_country_code_by_addr($gi, $ip);
   geoip_close($gi);
   return $two_letter_country_code;
}

function iptocountryname($the_id)
{
   global $db;

   $sql = 'SELECT user_ip
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . $the_id;
   $result = $db->sql_query($sql);

   $ip = $db->sql_fetchfield('user_ip');

   include_once("geoip.inc");
   $gi = geoip_open("./includes/GeoIP.dat",GEOIP_STANDARD);
   $country_name = geoip_country_name_by_addr($gi, $ip);
   geoip_close($gi);
   return $country_name;
}
search the GeoIP.dat file at adm/includes/GeoIP.dat !!! once you are at ACP
because I put a copy of the so called missing file into adm/includes, now it stops complaining

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Thu Oct 22, 2009 5:55 pm

katib wrote:because I put a copy of the so called missing file into adm/includes, now it stops complaining
OK, that explains what's going on. But we don't want to create multiple copies of GeoIP.dat and geoip.inc because its a waste of space and adds more work to be done when updating! :(

The solution is to modify the following lines in functions.php:

Code: Select all

include_once("geoip.inc");
$gi = geoip_open("./includes/GeoIP.dat",GEOIP_STANDARD);
Change them to this:

Code: Select all

include_once("{$phpbb_root_path}geoip.inc");
$gi = geoip_open("{$phpbb_root_path}includes/GeoIP.dat",GEOIP_STANDARD);
Note that there are two of these in the TULIP mod - one for each function. Now it should always access the one correct GeoIP.dat file. :D

I've updated the MOD post to reflect these changes. Try making these changes to functions.php and then deleting the second copy of GeoIP data you created in acp and let me know if that works correctly now?
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

Vallkas
Registered User
Posts: 9
Joined: Thu Sep 18, 2008 5:20 am

Re: [DEV] TULIP: Tiny User Locator by IP

Post by Vallkas » Thu Oct 22, 2009 6:03 pm

You can use this mod to display the flag on the profile of users?

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Thu Oct 22, 2009 6:26 pm

Vallkas wrote:You can use this mod to display the flag on the profile of users?
Yes. After installing the MOD per the instructions in the first post, open up memberlist.php and find:

Code: Select all

'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
Below, add:

Code: Select all

########## BEGIN TULIP ##########
'COUNTRY'   => iptocountry($user_id),
'COUNTRY_FULL'   => iptocountryname($user_id),
########## END TULIP ##########
Then, open memberlist_view.html template file for the template you're using. Add the following line wherever you want the flag to appear:

Code: Select all

<img src="./flags/{COUNTRY}.gif" alt="{COUNTRY_FULL}">
The beauty of this MOD is that it can so very easily be adapted for use pretty much anywhere on your phpBB board.
Last edited by dpaanlka on Thu Oct 22, 2009 6:28 pm, edited 1 time in total.
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

User avatar
katib
Registered User
Posts: 562
Joined: Thu Jun 26, 2008 12:27 pm

Re: [DEV] TULIP: Tiny User Locator by IP

Post by katib » Thu Oct 22, 2009 6:27 pm

It is still complaining:

Code: Select all

Warning: fopen(includes/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in K:\xampplite\htdocs\bb\includes\geoip.inc on line 314
Can not open includes/GeoIP.dat

User avatar
dpaanlka
Registered User
Posts: 286
Joined: Wed May 10, 2006 6:48 pm
Location: Chicago, USA
Contact:

Re: [DEV] TULIP: Tiny User Locator by IP

Post by dpaanlka » Thu Oct 22, 2009 6:31 pm

katib wrote:It is still complaining:

Code: Select all

Warning: fopen(includes/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in K:\xampplite\htdocs\bb\includes\geoip.inc on line 314
Can not open includes/GeoIP.dat
Hmm... I was certain that would fix it. There is assuredly some way to fix this, because we definitely don't want multiple copies of the GeoIP data all over the place. Are you sure you placed the php root directory modification inside both TULIP functions? The entire block should look like this now:

Code: Select all

########## BEGIN TULIP ##########

/**
* This mod includes GeoLite data created by MaxMind,
* available from http://www.maxmind.com/.
*/

function iptocountry($the_id)
{
   global $db;

   $sql = 'SELECT user_ip
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . $the_id;
   $result = $db->sql_query($sql);

   $ip = $db->sql_fetchfield('user_ip');

   include_once("{$phpbb_root_path}geoip.inc");
   $gi = geoip_open("{$phpbb_root_path}includes/GeoIP.dat",GEOIP_STANDARD);
   $two_letter_country_code = geoip_country_code_by_addr($gi, $ip);
   geoip_close($gi);
   return $two_letter_country_code;
}

function iptocountryname($the_id)
{
   global $db;

   $sql = 'SELECT user_ip
    FROM ' . USERS_TABLE . '
    WHERE user_id = ' . $the_id;
   $result = $db->sql_query($sql);

   $ip = $db->sql_fetchfield('user_ip');

   include_once("{$phpbb_root_path}geoip.inc");
   $gi = geoip_open("{$phpbb_root_path}includes/GeoIP.dat",GEOIP_STANDARD);
   $country_name = geoip_country_name_by_addr($gi, $ip);
   geoip_close($gi);
   return $country_name;
}

########## END TULIP ##########
phpBB user and evangelist since 2005.
My boards: Info-Mac | System 7 Today

FeuerSturm
Registered User
Posts: 8
Joined: Sat Oct 25, 2008 10:32 am

Re: [DEV] TULIP: Tiny User Locator by IP

Post by FeuerSturm » Thu Oct 22, 2009 6:36 pm

Hello!

I'm running my webserver of a dedicated linux box, made all edits correctly
and I get the
Warning: fopen(includes/GeoIP.dat) [function.fopen]: failed to open stream: No such file or directory in /var/www/vhosts/realismrecon.net/httpdocs/includes/geoip.inc on line 314
Can not open includes/GeoIP.dat
as well after adding the flags to the online users.

And yes, I tried your latest fix with using

Code: Select all

	include_once("{$phpbb_root_path}geoip.inc");
	$gi = geoip_open("{$phpbb_root_path}includes/GeoIP.dat",GEOIP_STANDARD);
as well.

Any help would be appreciated!

Thanks for this easy mod!

Locked

Return to “[3.0.x] Abandoned MODs”