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 1Within phpmyadmin run the following query to alter the comments table to store the commenter's IP: (be sure to use your prefix)
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.$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$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):
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
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;
}