Changeset 179
- Timestamp:
- 03/06/06 20:49:56 (3 years ago)
- Files:
-
- Mapper/trunk/Mapper.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Mapper/trunk/Mapper.pl
r177 r179 41 41 42 42 %$config = (%$config, %$args); 43 $config->{unique} = $ctx->stash('entry')->id 44 if defined $ctx->stash('entry'); 43 45 my $mapper_class = __PACKAGE__ . '::' . ($args->{method} || 'Google'); 44 46 my $mapper = $mapper_class->new($config); 45 47 46 48 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; 50 50 $html; 51 51 } … … 70 70 use strict; 71 71 use MT::Util qw(encode_url); 72 use MT::ConfigMgr; 72 73 use LWP::Simple; 73 74 use HTML::Template; … … 77 78 my($config) = @_; 78 79 $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)); 80 84 bless $config, $class; 81 85 } … … 87 91 my($address) = @_; 88 92 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 $@; 90 94 my $res = ''; 91 95 $res .= $this->preamble unless $this->{count}; … … 98 102 my $this = shift; 99 103 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); 101 109 if ($res && $res =~ /coordinates>([0-9.]+),([0-9.]+),/is) { 102 110 return ($2, $1); … … 106 114 } 107 115 108 sub preamble { 109 my $this = shift; 110 my $preamble_tmpl = <<'EOT'; 116 my $preamble_tmpl = <<'EOT'; 111 117 <script type="text/javascript" src="http://maps.google.com/maps?file=api&v=1.28&key=<TMPL_VAR NAME="google_maps_key">"></script> 112 118 <script type="text/javascript"> … … 146 152 </script> 147 153 EOT 154 155 sub preamble { 156 my $this = shift; 148 157 my $tmpl = HTML::Template->new(scalarref => \$preamble_tmpl); 149 158 $tmpl->param(google_maps_key => $this->{google_maps_key}); … … 151 160 } 152 161 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> 162 my $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> 159 164 <script type="text/javascript"> 160 165 //<