aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/Alert.pm19
-rw-r--r--perllib/FixMyStreet/Geocode.pm42
-rw-r--r--perllib/FixMyStreet/Map.pm1
-rw-r--r--perllib/FixMyStreet/Map/OSM.pm14
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm7
5 files changed, 54 insertions, 29 deletions
diff --git a/perllib/FixMyStreet/Alert.pm b/perllib/FixMyStreet/Alert.pm
index 90a5b1aaa..6b50e62e6 100644
--- a/perllib/FixMyStreet/Alert.pm
+++ b/perllib/FixMyStreet/Alert.pm
@@ -30,7 +30,6 @@ use mySociety::DBHandle qw(dbh);
use mySociety::Email;
use mySociety::EmailUtil;
use mySociety::Gaze;
-use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::MaPit;
use mySociety::Random qw(random_bytes);
@@ -91,7 +90,7 @@ sub delete ($) {
sub email_alerts ($) {
my ($testing_email) = @_;
my $url;
- my $q = dbh()->prepare("select * from alert_type where ref not like 'local_problems%'");
+ my $q = dbh()->prepare("select * from alert_type where ref not like '%local_problems%'");
$q->execute();
my $testing_email_clause = '';
while (my $alert_type = $q->fetchrow_hashref) {
@@ -136,18 +135,18 @@ sub email_alerts ($) {
# call checks if this is the host that sends mail for this cobrand.
next unless (Cobrand::email_host($row->{alert_cobrand}));
- # create problem status message for the templates
- $data{state_message} =
- $row->{state} eq 'fixed'
- ? _("This report is currently marked as fixed.")
- : _("This report is currently marked as open.");
-
dbh()->do('insert into alert_sent (alert_id, parameter) values (?,?)', {}, $row->{alert_id}, $row->{item_id});
if ($last_alert_id && $last_alert_id != $row->{alert_id}) {
_send_aggregated_alert_email(%data);
%data = ( template => $alert_type->{template}, data => '' );
}
+ # create problem status message for the templates
+ $data{state_message} =
+ $row->{state} eq 'fixed'
+ ? _("This report is currently marked as fixed.")
+ : _("This report is currently marked as open.");
+
$url = Cobrand::base_url_for_emails($row->{alert_cobrand}, $row->{alert_cobrand_data});
if ($row->{item_text}) {
$data{problem_url} = $url . "/report/" . $row->{id};
@@ -307,7 +306,9 @@ sub generate_rss ($$$;$$$$) {
if ($display_photos && $row->{photo}) {
$item{description} .= ent("\n<br><img src=\"". Cobrand::url($cobrand, $url, $http_q) . "/photo?id=$row->{id}\">");
}
- $item{description} .= ent("\n<br><a href='$cobrand_url'>Report on FixMyStreet</a>");
+ my $recipient_name = Cobrand::contact_name($cobrand);
+ $item{description} .= ent("\n<br><a href='$cobrand_url'>" .
+ sprintf(_("Report on %s"), $recipient_name) . "</a>");
if ($row->{latitude} || $row->{longitude}) {
$item{georss} = { point => "$row->{latitude} $row->{longitude}" };
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index 0379169b8..17a4d8539 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -9,6 +9,7 @@
package FixMyStreet::Geocode;
use strict;
+use Encode;
use Error qw(:try);
use File::Slurp;
use File::Path ();
@@ -18,8 +19,9 @@ use URI::Escape;
use Cobrand;
use Page;
+use Utils;
use mySociety::Config;
-use mySociety::GeoUtil;
+use mySociety::Locale;
use mySociety::MaPit;
use mySociety::PostcodeUtil;
use mySociety::Web qw(NewURL);
@@ -38,15 +40,18 @@ BEGIN {
sub lookup {
my ($s, $q) = @_;
my ($latitude, $longitude, $error);
- if ($s =~ /^\d+$/) {
- $error = 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.';
- } elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) {
- my $location = mySociety::MaPit::call('postcode', $s);
- unless ($error = Page::mapit_check_error($location)) {
- $latitude = $location->{wgs84_lat};
- $longitude = $location->{wgs84_lon};
+ if (mySociety::Config::get('COUNTRY') eq 'GB') {
+ if ($s =~ /^\d+$/) {
+ $error = 'FixMyStreet is a UK-based website that currently works in England, Scotland, and Wales. Please enter either a postcode, or a Great British street name and area.';
+ } elsif (mySociety::PostcodeUtil::is_valid_postcode($s)) {
+ my $location = mySociety::MaPit::call('postcode', $s);
+ unless ($error = Page::mapit_check_error($location)) {
+ $latitude = $location->{wgs84_lat};
+ $longitude = $location->{wgs84_lon};
+ }
}
- } else {
+ }
+ unless ($error || defined $latitude) {
($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $q);
}
return ($latitude, $longitude, $error);
@@ -61,6 +66,16 @@ sub geocoded_string_coordinates {
} elsif ( $js =~ /"coordinates" *: *\[ *(.*?), *(.*?),/ ) {
$longitude = $1;
$latitude = $2;
+ if (mySociety::Config::get('COUNTRY') eq 'GB') {
+ try {
+ my ($easting, $northing) = Utils::convert_latlon_to_en( $latitude, $longitude );
+ } catch Error::Simple with {
+ mySociety::Locale::pop(); # We threw exception, so it won't have happened.
+ $error = shift;
+ $error = _('That location does not appear to be in Britain; please try again.')
+ if $error =~ /out of the area covered/;
+ }
+ }
}
return ($latitude, $longitude, $error);
}
@@ -73,8 +88,9 @@ sub geocoded_string_coordinates {
# of the site.
sub string {
my ($s, $q) = @_;
+ $s = decode_utf8($s);
$s = lc($s);
- $s =~ s/[^-&0-9a-z ']/ /g;
+ $s =~ s/[^-&\w ']/ /g;
$s =~ s/\s+/ /g;
$s = URI::Escape::uri_escape_utf8($s);
$s = Cobrand::disambiguate_location(Page::get_cobrand($q), "q=$s", $q);
@@ -86,8 +102,9 @@ sub string {
if (-s $cache_file) {
$js = File::Slurp::read_file($cache_file);
} else {
- $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i;
- $url .= '&sensor=false&gl=uk&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY');
+ $url .= ',+UK' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i
+ || mySociety::Config::get('COUNTRY') ne 'GB';
+ $url .= '&sensor=false&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY');
$js = LWP::Simple::get($url);
File::Path::mkpath($cache_dir);
File::Slurp::write_file($cache_file, $js) if $js && $js !~ /"code":6[12]0/;
@@ -130,6 +147,7 @@ sub list_choices {
my $out = '<p>' . $message . '</p>';
my $choice_list = '<ul>';
foreach my $choice (@$choices) {
+ $choice = decode_utf8($choice);
$choice =~ s/, United Kingdom//;
$choice =~ s/, UK//;
$url = Cobrand::url($cobrand, NewURL($q, -retain => 1, -url => $page, 'pc' => $choice), $q);
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index 0902914dd..a9978103f 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -14,7 +14,6 @@ use Problems;
use Cobrand;
use mySociety::Config;
use mySociety::Gaze;
-use mySociety::GeoUtil qw(national_grid_to_wgs84);
use mySociety::Locale;
use mySociety::Web qw(ent NewURL);
use Utils;
diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm
index ccbb3ca53..820a4ce63 100644
--- a/perllib/FixMyStreet/Map/OSM.pm
+++ b/perllib/FixMyStreet/Map/OSM.pm
@@ -15,13 +15,12 @@ sub header_js {
return '
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript" src="/js/map-OpenStreetMap.js"></script>
-<script type="text/javascript" src="/js/OpenLayers.Projection.OrdnanceSurvey.js"></script>
';
}
# display_map Q PARAMS
# PARAMS include:
-# EASTING, NORTHING for the centre point of the map
+# latitude, longitude for the centre point of the map
# TYPE is 1 if the map is clickable, 2 if clickable and has a form upload,
# 0 if not clickable
# PINS is array of pins to show, location and colour
@@ -31,16 +30,23 @@ sub display_map {
$params{pre} ||= '';
$params{post} ||= '';
+ my @pins;
foreach my $pin (@{$params{pins}}) {
+ $pin->[3] ||= '';
+ push @pins, "[ $pin->[0], $pin->[1], '$pin->[2]', '$pin->[3]' ]";
}
+ my $pins = join(",\n", @pins);
my $out = FixMyStreet::Map::header($q, $params{type});
my $copyright = _('Map &copy; <a href="http://www.openstreetmap.org/">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>');
$out .= <<EOF;
+<input type="hidden" name="latitude" id="fixmystreet.latitude" value="$params{latitude}">
+<input type="hidden" name="longitude" id="fixmystreet.longitude" value="$params{longitude}">
<script type="text/javascript">
var fixmystreet = {
- 'easting': $params{easting},
- 'northing': $params{northing},
+ 'latitude': $params{latitude},
+ 'longitude': $params{longitude},
+ 'pins': [ $pins ],
'map_type': OpenLayers.Layer.OSM.Mapnik
}
</script>
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index 81b123b30..b6d24fd6a 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -12,13 +12,14 @@ use strict;
use LWP::Simple;
use Cobrand;
-use mySociety::Web qw(ent NewURL);
use mySociety::GeoUtil;
+use mySociety::Locale;
+use mySociety::Web qw(ent NewURL);
use Utils;
sub _ll_to_en {
my ($lat, $lon) = @_;
- return mySociety::GeoUtil::wgs84_to_national_grid( $lat, $lon, 'G' );
+ return Utils::convert_latlon_to_en( $lat, $lon );
}
sub header_js {
@@ -268,7 +269,7 @@ sub click_to_os {
# tile they were), convert to WGS84 and return.
sub click_to_wgs84 {
my ( $easting, $northing ) = FixMyStreet::Map::click_to_os(@_);
- my ( $lat, $lon ) = national_grid_to_wgs84( $easting, $northing, 'G' );
+ my ( $lat, $lon ) = mySociety::GeoUtil::national_grid_to_wgs84( $easting, $northing, 'G' );
return ( $lat, $lon );
}