Hello

September 02, 2010, 05:01:53 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?
Login with username, password and session length
What sNews Is: - sNews is a simple, basic, customizable CMS tool suitable for developers with beginner-to-advanced PHP skills. It is also useful to have a good working knowledge of how to work with, set up and manage MySQL databases. sNews is not - geared towards the end-user who knows little or nothing about building and developing PHP-MySQL based websites.
News: Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: [MOD IN PROGRESS] Adding country flag next to name in comments  (Read 5811 times)
bakercad
Administrator
ULTIMATE member
******

Karma: 105
Posts: 1654



WWW
« on: May 24, 2007, 03:12:37 PM »

I put this as IN PROGRESS instead of in the MODS section because I'd like it to be tested for accuracy before moving as  a "ready to go" mod.

This was requested of me by a little bird that flies around our forum.  She gave me a link to someone who did this for WordPress.

If you look at my test comment at http://4inchorange.com/exit20/home/flag-test/ you'll see the USA flag next to my name.  This mod saves the commenter's IP address into the comments database.  Finds the country based on the IP address and displays the flag next to the user's name.  Sure it's not a functional mod, but it's nice to see where your comments are coming from.

You'll need to get the ip database tables from here: http://www.ip2nation.com/.  Download the sql file and use phpmyadmin to add the tables to your database.  Be sure to use FIND/REPLACE to add your database prefix that you used in your snews.php file. This is a large query, over 27,000 records, so it may take a while

Also download the flag images from here: http://frenchfragfactory.net/download/utils/flags.zip. If you don't have an images directory already, create one, then create a flags directory inside the images directory.  So your path would be http://www.yourdomain.com/snewsdirectoryifneeded/imags/flags/.  Unzip the flag images into the "flags" directory.

STEP 1
Within phpmyadmin run the following query to alter the comments table to store the commenter's IP: (be sure to use your prefix)
Quote
ALTER TABLE prefix_comments ADD ip varchar(20);
STEP 2 - snews.php -  tags() function
ADD the blue - EDIT: I put the flag BEFORE the name as suggested by piXelatedEmpire.  Flags line up nicely this way.
Quote
$tags['comments'] = '<div class='comment'>,<p class='date'>,flag,name, '.l('on').' ,date,edit,</p>,<p>,comment,</p>,</div>';
STEP 3 - snews.php - comments() function
ADD the blue
Quote
$query = "INSERT INTO ".db('prefix')."comments(articleid, name, url, comment, time, approved, ip) VALUES('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$ip')";
STEP 4 - snews.php - comments() function
ADD the blue (new case for tags):
Quote
foreach ($tag as $tag) {
  switch (true) {
   case ($tag == 'date'):
      echo '<a id="'.l('comment').$commentNum.'" name="'.l('comment').$commentNum.'" title="'.l('comment').' '.$commentNum.'"></a>'.$date;
   break;
   case ($tag == 'name'): $name = $r['name']; echo !empty($r['url']) ? '<a href="'.$r['url'].'" title="'.$r['url'].'" rel="nofollow">'.$name.'</a> ' : $name; break;
   //FLAGS
   case ($tag == 'flag'):
      $country = get_flag('country',$r['ip']);
      $flag = get_flag('flag',$r['ip']);
      echo ' <img src="images/flags/flag_'.$flag.'.gif" alt="'.$flag.'" title="'.$country.'" /> ';
   break;
   // FLAGS

   case ($tag == 'comment'): echo $r['comment']; break;
   case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()):
      echo $edit_link.'editcomment&commentid='.$r['id'].'" title="'.l('edit').' '.l('comment').'">'.l('edit').'</a> ';
      echo $edit_link.'process&task=deletecomment&articleid='.$r['articleid'].'&commentid='.$r['id'].'" title="'.l('delete').' '.l('comment').'" onclick="return pop()">'.l('delete').'</a>';
   break; case ($tag == 'edit'): ; break; default: echo $tag;
   }
}
STEP 5 - snews.php - NEW function
Quote
function get_flag($var,$ip) {
   if($var == 'flag') { $item = "i";}
   elseif($var == 'country') { $item = "c";}
   $sql = "SELECT ".$item.".country FROM ".db('prefix')."ip2nationCountries c,".db('prefix')."ip2nation i WHERE i.ip < INET_ATON('".$ip."') AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1";
   list($output) = mysql_fetch_row(mysql_query($sql));
   return $output;
}
« Last Edit: January 22, 2008, 06:15:54 PM by bakercad » Logged

David
sNews Dude
Hero Member
*****

Karma: 7
Posts: 580



« Reply #1 on: May 24, 2007, 03:52:47 PM »

great idea Bob! Thanks!
Logged

bakercad
Administrator
ULTIMATE member
******

Karma: 105
Posts: 1654



WWW
« Reply #2 on: May 24, 2007, 04:35:50 PM »

Thanks David....although it's really Zucye's idea.

Could you shoot over to http://4inchorange.com/exit20/home/flag-test/ and give it a test run for me? Tell me if your country flag comes out correctly?
Logged

mosh
Sr. Member
****

Karma: 63
Posts: 413



WWW
« Reply #3 on: May 24, 2007, 05:30:11 PM »

Cheesy  Cheesy  works great bakercad,  :cool:
any news about the MU  Tongue  Tongue  Tongue

awesome day 2 all
mo
Logged

bramsyuur
sNews Dude
Hero Member
*****

Karma: 23
Posts: 899



WWW
« Reply #4 on: May 24, 2007, 06:55:50 PM »

Thanks Bob for this mod and thanks to Zucye for the idea.
Logged

La comunidad sNews en tu idioma!
Comunidad sNews en Español
Keyrocks
Doug
Administrator
ULTIMATE member
******

Karma: 419
Posts: 5556


Semantically Challenged


WWW
« Reply #5 on: May 24, 2007, 07:41:32 PM »

Lookin' good Bob! Smiley
Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
bakercad
Administrator
ULTIMATE member
******

Karma: 105
Posts: 1654



WWW
« Reply #6 on: May 24, 2007, 07:42:26 PM »

I take it that the "real Canadian flag" was displayed?  Smiley
Logged

bramsyuur
sNews Dude
Hero Member
*****

Karma: 23
Posts: 899



WWW
« Reply #7 on: May 24, 2007, 07:48:16 PM »

Ip2nation sql file it's _only_ a 1.6Mb? It's so little for me!  :cool:  :lol:
Logged

La comunidad sNews en tu idioma!
Comunidad sNews en Español
bakercad
Administrator
ULTIMATE member
******

Karma: 105
Posts: 1654



WWW
« Reply #8 on: May 24, 2007, 07:51:45 PM »

should be a LOT smaller!  They didn't have to add "INSERT INTO ip2nation (ip, country) VALUES" for EACH record.  They SHOULD have done it like this:
Quote
INSERT INTO ip2nation (ip, country) VALUES
(0, 'us'),
(698351616, 'za'),
(700710912, 'eg'),
(700776448, 'rw'),
(700973056, 'dz'),
(701235200, 'sz'),
(701243392, 'gh'),
(701251584, 'cm'),
(701259776, 'mg'),
(701267968, 'tz'),
(701276160, 'ke'),
(701284352, 'za'),
(701292544, 'ng'),
(701300736, 'cm'),
(701308928, 'ao'),
(701317120, 'cm'),
...etc.
Logged

bramsyuur
sNews Dude
Hero Member
*****

Karma: 23
Posts: 899



WWW
« Reply #9 on: May 24, 2007, 08:15:19 PM »

yes!
If you have troubles with the original ip2nation sql file, please, download my modified version here:
http://rapidshare.com/files/33167344/ip2nation2.sql.html
This file it's only ~500kb and more flexible to use with your phpmyadmin without problems.
Logged

La comunidad sNews en tu idioma!
Comunidad sNews en Español
David
sNews Dude
Hero Member
*****

Karma: 7
Posts: 580



« Reply #10 on: May 24, 2007, 11:39:44 PM »

Belgium flag exists there Cheesy

Thanks Bob and Zucye!
Logged

iatbm
Sr. Member
****

Karma: 0
Posts: 256


WWW
« Reply #11 on: May 25, 2007, 12:11:23 AM »

fam fam fam has some good flags Wink .... I don't know which one you use with this mod but just to check it out .... here : http://www.famfamfam.com/lab/icons/flags/
Logged

Keyrocks
Doug
Administrator
ULTIMATE member
******

Karma: 419
Posts: 5556


Semantically Challenged


WWW
« Reply #12 on: May 25, 2007, 01:58:14 AM »

Quote from: iatbm
fam fam fam has some good flags Wink .... I don't know which one you use with this mod but just to check it out .... here : http://www.famfamfam.com/lab/icons/flags/
The FAM flags appear to look cleaner and smoother. Smiley
Logged

Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
piXelatedEmpire
MIA
Thread Moderator
ULTIMATE member
*****

Karma: 37
Posts: 1456


currently MIA


« Reply #13 on: May 25, 2007, 02:25:37 AM »

Terrific idea Bob and Zucye!!

May I suggest the flag actually appear BEFORE the username, that way the flags will line up nicely in a row down the page Wink

Also, I'm in Aus, but I got a USA flag.  Never fear tho, as my work connection I believe originates from the USA (I work for a multinational company).

And just to go against the trend, I prefer the flags in the MOD as they are now, as opposed to the FAM flags.

Cheers
Logged

my apologies to the sNews crew, but I will be MIA for the forseeable future
Joost
Guest
« Reply #14 on: May 25, 2007, 02:40:37 AM »

The Dutch are recognized! Smiley
Logged
Pages: [1] 2
  Print  
 
Jump to:  

English Steel 1.6 © Saxon North Technologies
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!