By fighter75 on
Hello,
I just installed the module ip2nation, ( http://drupal.org/project/ip2nation ) but I can not find the snippet to display the flag of the commentators except in the $links.
I want to display the flag in the top of comments or leftside under the user picture can you help please ?
I try the snippet
print theme('('ip2nation_flag', $comment'))),
but it does not work.
This is the module code
<?php
// $Id: ip2nation.module,v 1.1.4.1 2008/10/23 09:01:21 suryanto Exp $
/*
* This module uses the ip2nation database
* For manual and latest release visit http://rachmat.net/en/2008/03/07/ip2nation-module-drupal
*/
define('IP2NATION_DEFAULT_INFO_FORMAT', 'from !flag @country');
/**
* Gets country data from an IP.
* @param $ip the IPv4 address, which is in the format equivalent to that of $_SERVER['REMOTE_ADDR']
*/
function ip2nation_get($ip = NULL) {
static $cache = array();
if ($ip === NULL) {
$ip = ip_address();
}
if ($ip == "127.0.0.1") {
return new stdClass();
}
if (!isset($cache["$ip"])) {
$sql = "SELECT c.code, c.country ";
$sql .= "FROM {ip2nationCountries} c ";
$sql .= "INNER JOIN {ip2nation} i ON c.code = i.country ";
$sql .= "WHERE i.ip < INET_ATON('%s') ";
$sql .= "ORDER BY i.ip DESC ";
$sql .= "LIMIT 0,1";
$cache["$ip"] = db_fetch_object(db_query($sql, $ip));
}
return $cache["$ip"];
}
/**
* Implementation of hook_perm
*/
function ip2nation_perm() {
return array('administer ip2nation', 'view country');
}
/**
* Implementation of hook_menu().
*/
function ip2nation_menu() {
$items['admin/settings/ip2nation'] = array(
'title' => 'IP2Nation',
'page callback' => 'drupal_get_form',
'page arguments' => array('ip2nation_admin_settings', 2),
'access arguments' => array('administer ip2nation'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_settings().
*/
function ip2nation_admin_settings() {
$addr = ip_address();
$c = ip2nation_get($addr);
$form['info'] = array(
'#value' => '<p>' . t('You are from <strong>@country</strong>. Your country code is %code and your IP is %ip.', array('@country' => $c->country, '%code' => $c->code, '%ip' => $addr)) . '</p>'
. '<p>' . t('If the information above is wrong or generates error, there is something wrong either in ip2nation data or your installation.') . '</p>',
);
$form['ip2nation_comment'] = array(
'#type' => 'radios',
'#title' => t("Commenter's information in comments"),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#default_value' => variable_get('ip2nation_comment', 0),
'#description' => t("Turn this on if you wish to show commenter's country in comments. It adds 2 SQL queries for each comment shown."),
);
if (variable_get('ip2nation_comment', 0)) {
$form['ip2nation_info_format'] = array(
'#type' => 'textfield',
'#title' => t("Commenter's information format"),
'#default_value' => variable_get('ip2nation_info_format', IP2NATION_DEFAULT_INFO_FORMAT),
'#description' => t("Customize the format of commenter's information. Available variables are @country (the country name), @code (the 2-letter country code), !flag (show flag image), and @ip (IP address). You can use HTML tags."),
);
}
return system_settings_form($form);
}
/**
* Implementation of hook_link().
*/
function ip2nation_link($type, $node = 0, $main = 0) {
if ($type == 'comment' && variable_get('ip2nation_comment', 0) && user_access("view country")) {
//the variable name $node is confusing - let's alias it
$comment = &$node;
$addr = db_result(db_query("SELECT hostname FROM {comments} WHERE cid = %d", $comment->cid));
$data = ip2nation_get($addr);
if($data->country) {
$links[] = array(
'title' => t(variable_get('ip2nation_info_format', IP2NATION_DEFAULT_INFO_FORMAT), array('@country' => $data->country, '@code' => $data->code, '@ip' => $addr, '!flag' => theme('ip2nation_flag', $data))),
'html' => TRUE,
);
}
}
return $links;
}
function theme_ip2nation_flag($co) {
if (isset($co)) {
$cc = strtolower($co->code);
if (empty($cc)) {
$cc = "unknown";
}
$title = "$cc $co->country";
}
else {
$cc = 'unknown';
$title = 'unknown';
}
$src = url(drupal_get_path('module','ip2nation') . "/flags/flag_$cc.gif");
$attribs = array('width' => 18, height => 12, 'alt' => "$cc", 'title' => "$title");
return "<img src=\"$src\" ".drupal_attributes($attribs)." />";
}
function ip2nation_theme() {
return array(
'ip2nation_flag' => array(
'arguments' => array('co' => NULL),
),
);
}
Comments
Up ! Any Help Plz ?
Up !
Any Help Plz ?