Availability
IpToCountry Plugin v0.3 is available at Blojsom3 Plugins download page
.
Description
IpToCountry Plugin adds country information to each comment based on its IPv4 address.

Installation and Setup
Place iptocountryplugin-x.y.jar in /WEB-INF/lib/ directory.
Add the following to /WEB-INF/classes/blojsom-plugins.xml file.
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="dataSource"/>
</constructor-arg>
</bean>
<bean id="ipToCountryDao" class="com.mbledug.blojsom.plugin.iptocountry.IpToCountryDao">
<constructor-arg>
<ref bean="jdbcTemplate"/>
</constructor-arg>
</bean>
<bean id="iptocountry" class="com.mbledug.blojsom.plugin.iptocountry.IpToCountryPlugin" init-method="init" destroy-method="destroy">
<property name="eventBroadcaster">
<ref bean="eventBroadcaster"/>
</property>
<property name="ipToCountryDao">
<ref bean="ipToCountryDao"/>
</property>
<property name="ignoredIpAddresses">
<value>127.0.0.1,10.0.0.1</value>
</property>
</bean>
Modify HTML plugin chain from Blojsom administration menu plugins->mappings
Add "iptocountry" to one of the flavor-based plugin chains. You can place it anywhere within the chain, for example:
| html |
..., iptocountry, ... |
Create iptocountry table:
create table iptocountry (
ip_from int(10) unsigned not null unique key,
ip_to int(10) unsigned not null unique key,
country_code2 char(2) not null,
country_code3 char(3) not null,
country_name varchar(50) not null
);
Download iptocountry-csv-08062005.zip
(the latest version of this csv can be downloaded from webhosting.info
), and load the content to iptocountry table:
load data local infile "E:
into table iptocountry fields terminated by ',' enclosed by '"'
lines terminated by '\r\n';
Download iptocountry-flag.zip
, unzip the flag images to "/images/flag" directory. You can use a different location and change the img src value specified in your template file.
Usage
Display country flag image by using "country-code-2" and "country-name" comment meta data.
E.g. for asual theme, search for the foreach and if-comment code in asual-entry.vm template, then add the code in between.
#foreach ($response in $approvedResponses)
...
#if ($response.getType().equals("comment"))
...
######## START IPTOCOUNTRY PLUGIN
#if ($response.getMetaData().get("country-name") && $response.getMetaData().get("country-code-2"))
#set ($countryName = $response.getMetaData().get("country-name"))
#set ($countryCode = $response.getMetaData().get("country-code-2"))
from <img src="$BLOJSOM_BLOG.getBlogBaseURL()/images/flag/${countryCode.toLowerCase()}.gif" alt="$countryName"/>
($countryName)
#end
######## END IPTOCOUNTRY PLUGIN
...
#end
...
#end