#
# GeocodedLocate.pl
#
# http://www.w3.org/2003/01/geo/
# http://www.w3.org/2003/01/geo/wgs84_pos#
#####################################################################################
#
# Tag: <$MTEntryGeoLocate$>
#
# Usage: <$MTEntryGeoLocate type="(rss|rssinline|rsspoint|coordinates|kmllookat|javascriptvar|lat|long)"$>
#
# EntryKeyword: lat="34.71004443754351" lng="137.74840593338013"
#
# Template:
#
#
#
#
# -
# <$MTEntryTitle remove_html="1" encode_xml="1"$>
# <$MTCategoryLabel$>
# <$MTEntryPermalink encode_xml="1"$>
# <$MTEntryGeoLocate type="rsspoint"$>
#
#
#
#
#
#
#####################################################################################
package MT::Plugin::GeocodedLocate;
use strict;
use vars qw( $VERSION );
$VERSION = '0.2';
use MT;
use MT::Template::Context;
if ( MT->version_number >= 3 ){
require MT::Plugin;
my $plugin = new MT::Plugin();
$plugin->description( 'GeocodedLocate Plugin' );
$plugin->doc_link( 'http://xn--y8jmg4a9b7g.jp/GeocodedLocate/' );
if ( MT->version_number >= 3.2 ){
$plugin->name( 'GeocodedLocate' );
$plugin->version( $VERSION );
$plugin->author_name( 'Satoshi KUBOTA' );
$plugin->author_link( 'http://xn--y8jmg4a9b7g.jp/' );
}else{
$plugin->name( 'GeocodedLocate, v' . $VERSION );
}
MT->add_plugin( $plugin );
}
#
MT::Template::Context->add_tag( EntryGeoLocate => \&EntryLocater );
#
sub EntryLocater
{
my ($ctx, $args) = @_;
my $res='';
my $lat='';
my $long='';
my $range='40000.00';
my $tilt='10';
my $heading='3';
my $argType = lc (defined( $args->{type} ) ? $args->{type} : 'rss');
my $entry = $ctx->stash ('entry')
or return $ctx->error("No entry found.");
return "" if (!defined $entry->keywords);
my $keywords = $entry->keywords;
if($keywords=~/lat="([\d\.]+)"/){
$lat=$1;
}
if($keywords=~/lng="([\d\.]+)"/){
$long=$1;
}elsif($keywords=~/long="([\d\.]+)"/){
$long=$1;
}
if($keywords=~/range="([\d\.]+)"/){
$range=$1;
}
if($keywords=~/tilt="([\d\.]+)"/){
$tilt=$1;
}
if($keywords=~/heading="([\d\.]+)"/){
$heading=$1;
}
if($lat && $long){
if($argType eq 'rss'){
$res = "$lat\n$long";
}elsif($argType eq 'javascriptvar'){
$res = "vat lat=\"$lat\";\nvar lng=\"$long\";";
}elsif($argType eq 'lat'){
$res = "$lat";
}elsif($argType eq 'long'){
$res = "$long";
}elsif($argType eq 'rsspoint'){
$res = "\n$lat\n$long\n";
}elsif($argType eq 'rssinline'){
$res = "geo:lat=\"$lat\" geo:long=\"$long\"";
}elsif($argType eq 'inline'){
$res = "lat=\"$lat\" long=\"$long\"";
}elsif($argType eq 'kmllookat'){
$res = "\n$long\n$lat\n$range\n$tilt\n$heading\n";
}elsif($argType eq 'coordinates'){
$res = "$long,$lat";
}
}
return $res;
}
1;