Changeset 179

Show
Ignore:
Timestamp:
03/06/06 20:49:56 (3 years ago)
Author:
ogawa
Message:

Now support "adr" microformat.
And support "language" option, to select proper geo-server. It means, when "language" is set to "ja", the plugin obtain the geo-information from maps.google.co.jp, otherwise from maps.google.com.
And now properly work in non-utf8 charset.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Mapper/trunk/Mapper.pl

    r177 r179  
    4141 
    4242    %$config = (%$config, %$args); 
     43    $config->{unique} = $ctx->stash('entry')->id 
     44        if defined $ctx->stash('entry'); 
    4345    my $mapper_class = __PACKAGE__ . '::' . ($args->{method} || 'Google'); 
    4446    my $mapper = $mapper_class->new($config); 
    4547 
    4648    defined(my $html = $ctx->stash('builder')->build($ctx, $ctx->stash('tokens'), $cond)) or return; 
    47  
    48 #    $html =~ s!(?:<p>|<div>|<div\s+[^>]+>)?\s*\[map:([^]]+)\]\s*(?:</p>|</div>)?!$mapper->generate($1)!ge; 
    49     $html =~ s!(?:<p>)\s*\[map:([^]]+)\]\s*(?:</p>)!$mapper->generate($1)!ge; 
     49    $html =~ s!(?:<div\s+[^<]*class="adr"[^<]*>\s*([^<]+)\s*</div>)|(?:<p>\s*\[map:([^]]+)\]\s*</p>)!$mapper->generate($1||$2)!ge; 
    5050    $html; 
    5151} 
     
    7070use strict; 
    7171use MT::Util qw(encode_url); 
     72use MT::ConfigMgr; 
    7273use LWP::Simple; 
    7374use HTML::Template; 
     
    7778    my($config) = @_; 
    7879    $config->{count} = 0; 
    79     $config->{unique} = int(rand(65536)); 
     80    my $cfg = MT::ConfigMgr->instance; 
     81    $config->{language} ||= $cfg->DefaultLanguage; 
     82    $config->{charset} ||= $cfg->PublishCharset; 
     83    $config->{unique} ||= int(rand(65536)); 
    8084    bless $config, $class; 
    8185} 
     
    8791    my($address) = @_; 
    8892    my ($lat, $lon) = eval { $this->resolve_address($address) }; 
    89     return "<p>Sorry, this address \"$address\" cannot be resolved.</p>\n" if $@; 
     93    return "<div class=\"adr\">$address (Sorry, this address cannot be resolved.)</div>" if $@; 
    9094    my $res = ''; 
    9195    $res .= $this->preamble unless $this->{count}; 
     
    98102    my $this = shift; 
    99103    my($address) = @_; 
    100     my $res = get('http://maps.google.co.jp/maps?q=' . encode_url($address) . '&output=kml'); 
     104    my $geo_url = $this->{language} eq 'ja' ? 
     105        'http://maps.google.co.jp/maps?q=' : 'http://maps.google.com/maps?q='; 
     106    $geo_url .= encode_url($address) . '&output=kml'; 
     107    $geo_url .= '&ie=' . $this->{charset} . '&oe=' . $this->{charset}; 
     108    my $res = get($geo_url); 
    101109    if ($res && $res =~ /coordinates>([0-9.]+),([0-9.]+),/is) { 
    102110        return ($2, $1); 
     
    106114} 
    107115 
    108 sub preamble { 
    109     my $this = shift; 
    110     my $preamble_tmpl = <<'EOT'; 
     116my $preamble_tmpl = <<'EOT'; 
    111117<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=1.28&key=<TMPL_VAR NAME="google_maps_key">"></script> 
    112118<script type="text/javascript"> 
     
    146152</script> 
    147153EOT 
     154 
     155sub preamble { 
     156    my $this = shift; 
    148157    my $tmpl = HTML::Template->new(scalarref => \$preamble_tmpl); 
    149158    $tmpl->param(google_maps_key => $this->{google_maps_key}); 
     
    151160} 
    152161 
    153 sub body { 
    154     my $this = shift; 
    155     my($lat, $lon, $address) = @_; 
    156     $address =~ s/:.*$//; 
    157     my $body_tmpl = <<'EOT'; 
    158 <div id="<TMPL_VAR NAME="mapid">" style="width:<TMPL_VAR NAME="width">;height:<TMPL_VAR NAME="height">;"></div> 
     162my $body_tmpl = <<'EOT'; 
     163<div id="<TMPL_VAR NAME="mapid">" style="width:<TMPL_VAR NAME="width">;height:<TMPL_VAR NAME="height">;" class="adr"><TMPL_VAR NAME="address"></div> 
    159164<script type="text/javascript"> 
    160165//<![CDATA[ 
     
    165170</script> 
    166171EOT 
     172 
     173sub body { 
     174    my $this = shift; 
     175    my($lat, $lon, $address) = @_; 
     176    $address =~ s/:.*$//; 
    167177    my $tmpl = HTML::Template->new(scalarref => \$body_tmpl); 
    168178    $tmpl->param(