aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/Cobrand.pm7
-rw-r--r--perllib/Cobrands/Barnet/Util.pm2
-rw-r--r--perllib/Cobrands/Emptyhomes/Util.pm4
-rw-r--r--perllib/Cobrands/Fiksgatami/Util.pm46
-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
-rw-r--r--perllib/Page.pm126
-rw-r--r--perllib/Problems.pm7
-rw-r--r--perllib/Utils.pm32
12 files changed, 203 insertions, 104 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 328445fcc..fa2dd9e88 100644
--- a/perllib/Cobrand.pm
+++ b/perllib/Cobrand.pm
@@ -41,7 +41,7 @@ my %fns = (
# Return the base url for the cobranded version of the site
'base_url' => { default => "mySociety::Config::get('BASE_URL')" },
# Return the text that prompts the user to enter their postcode/place name. Parameter is QUERY
- 'enter_postcode_text' => { default => '_("Enter a nearby GB postcode, or street name and area:")' },
+ 'enter_postcode_text' => { default => '""' },
# Set the language and domain of the site based on the cobrand and host
'set_lang_and_domain' => { default => '\&default_set_lang_and_domain' },
# Return HTML for a list of alert options for the cobrand, given QUERY and OPTIONS.
@@ -55,7 +55,7 @@ my %fns = (
'front_stats' => { default => '\&Problems::front_stats' },
# Given a STRING ($_[1]) representing a location and a QUERY, return a string that
# includes any disambiguating information available
- 'disambiguate_location' => { default => '$_[1]' },
+ 'disambiguate_location' => { default => '"$_[1]&gl=uk"' },
# Parameter is EPOCHTIME
'prettify_epoch' => { default => '0' },
# Parameters are FORM_NAME, QUERY. Return HTML for any extra needed elements for FORM_NAME
@@ -116,6 +116,9 @@ my %fns = (
'admin_pages' => { default => '0' },
# Show the problem creation graph in the admin interface
'admin_show_creation_graph' => { default => '1' },
+ # The MaPit types this site handles
+ 'area_types' => { default => '[qw(DIS LBO MTD UTA CTY COI)]' },
+ 'area_min_generation' => { default => '10' },
);
foreach (keys %fns) {
diff --git a/perllib/Cobrands/Barnet/Util.pm b/perllib/Cobrands/Barnet/Util.pm
index 8ce296aaf..eb8b91649 100644
--- a/perllib/Cobrands/Barnet/Util.pm
+++ b/perllib/Cobrands/Barnet/Util.pm
@@ -79,7 +79,7 @@ sub council_check {
}
my $url = 'http://www.fixmystreet.com/';
$url .= 'alert' if $context eq 'alert';
- $url .= '?pc=' . URI::Escape::uri_escape_utf8($q->param('pc')) if $q->param('pc');
+ $url .= '?pc=' . URI::Escape::uri_escape($q->param('pc')) if $q->param('pc');
my $error_msg = "That location is not covered by Barnet.
Please visit <a href=\"$url\">the main FixMyStreet site</a>.";
return (0, $error_msg);
diff --git a/perllib/Cobrands/Emptyhomes/Util.pm b/perllib/Cobrands/Emptyhomes/Util.pm
index acb870695..d23857f50 100644
--- a/perllib/Cobrands/Emptyhomes/Util.pm
+++ b/perllib/Cobrands/Emptyhomes/Util.pm
@@ -33,6 +33,10 @@ sub admin_base_url {
return 'https://secure.mysociety.org/admin/emptyhomes/';
}
+sub area_types {
+ return qw(DIS LBO MTD UTA LGD COI); # No CTY
+}
+
=item set_lang_and_domain LANG UNICODE
Set the language and text domain for the site based on the query and host.
diff --git a/perllib/Cobrands/Fiksgatami/Util.pm b/perllib/Cobrands/Fiksgatami/Util.pm
new file mode 100644
index 000000000..9fb448be5
--- /dev/null
+++ b/perllib/Cobrands/Fiksgatami/Util.pm
@@ -0,0 +1,46 @@
+#!/usr/bin/perl -w
+#
+# Util.pm:
+# Fiksgatami cobranding for FixMyStreet.
+#
+# Copyright (c) 2011 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+
+package Cobrands::Fiksgatami::Util;
+use strict;
+use Carp;
+
+sub new {
+ my $class = shift;
+ return bless {}, $class;
+}
+
+sub set_lang_and_domain {
+ my ($self, $lang, $unicode) = @_;
+ mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO', 'nb');
+ mySociety::Locale::gettext_domain('FixMyStreet', $unicode);
+ mySociety::Locale::change();
+}
+
+sub enter_postcode_text {
+ my ($self, $q) = @_;
+ return _('Enter a nearby postcode, or street name and area:');
+}
+
+# Is also adding language parameter
+sub disambiguate_location {
+ my ($self, $s, $q) = @_;
+ $s = "hl=no&gl=no&$s";
+ return $s;
+}
+
+sub area_types {
+ return ( 'NKO', 'NFY' );
+}
+
+sub area_min_generation {
+ return '';
+}
+
+1;
+
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 );
}
diff --git a/perllib/Page.pm b/perllib/Page.pm
index fc7127a78..279c5a79a 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -15,6 +15,7 @@ use strict;
use Carp;
use mySociety::CGIFast qw(-no_xhtml);
use Data::Dumper;
+use Encode;
use Error qw(:try);
use File::Slurp;
use HTTP::Date; # time2str
@@ -49,7 +50,9 @@ use FixMyStreet::Map;
my $lastmodified;
sub do_fastcgi {
- my ($func, $lm) = @_;
+ my ($func, $lm, $binary) = @_;
+
+ binmode(STDOUT, ":utf8") unless $binary;
try {
my $W = new mySociety::WatchUpdate();
@@ -83,7 +86,7 @@ sub report_error {
my $msg_br = join '<br><br>', split m{\n}, $msg;
- print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
+ print "Status: 500\nContent-Type: text/html; charset=utf-8\n\n",
qq(<html><head><title>$somethingwrong</title></head></html>),
q(<body>),
qq(<h1>$somethingwrong</h1>),
@@ -111,7 +114,7 @@ sub microsite {
my $lang;
$lang = 'cy' if $host =~ /cy/;
$lang = 'en-gb' if $host =~ /^en\./;
- Cobrand::set_lang_and_domain(get_cobrand($q), $lang);
+ Cobrand::set_lang_and_domain(get_cobrand($q), $lang, 1);
Problems::set_site_restriction($q);
Memcached::set_namespace(mySociety::Config::get('BCI_DB_NAME') . ":");
@@ -185,9 +188,8 @@ sub template_vars ($%) {
my $lang_url = base_url_with_lang($q, 1);
$lang_url .= $ENV{REQUEST_URI} if $ENV{REQUEST_URI};
- my $site_title = $q->{site} eq 'fixmystreet'
- ? _('FixMyStreet')
- : Cobrand::site_title(get_cobrand($q));
+ my $site_title = Cobrand::site_title(get_cobrand($q));
+ $site_title = _('FixMyStreet') unless $site_title;
%vars = (
'report' => _('Report a problem'),
@@ -202,7 +204,7 @@ sub template_vars ($%) {
'lang_url' => $lang_url,
'title' => $params{title},
'rss' => '',
- map_js => FixMyStreet::Map::header_js(),
+ map_js => $params{js} || '',
);
if ($params{rss}) {
@@ -213,12 +215,10 @@ sub template_vars ($%) {
$vars{robots} = '<meta name="robots" content="' . $params{robots} . '">';
}
- if ($q->{site} eq 'fixmystreet') {
- my $home = !$params{title} && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING};
- $vars{heading_element_start} = $home ? '<h1 id="header">' : '<div id="header"><a href="/">';
- $vars{heading} = _('Fix<span id="my">My</span>Street');
- $vars{heading_element_end} = $home ? '</h1>' : '</a></div>';
- }
+ my $home = !$params{title} && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING};
+ $vars{heading_element_start} = $home ? '<h1 id="header">' : '<div id="header"><a href="/">';
+ $vars{heading} = _('Fix<span id="my">My</span>Street');
+ $vars{heading_element_end} = $home ? '</h1>' : '</a></div>';
return \%vars;
}
@@ -260,22 +260,6 @@ sub template_include {
return $template->fill_in(HASH => \%params);
}
-=item template_header TEMPLATE Q ROOT PARAMS
-
-Return HTML for the templated top of a page, given a
-template name, request, template root, and parameters.
-
-=cut
-
-sub template_header($$$%) {
- my ($template, $q, $template_root, %params) = @_;
- $template = $q->{site} eq 'fixmystreet'
- ? 'header'
- : $template . '-header';
- my $vars = template_vars($q, %params);
- return template_include($template, $q, $template_root, %$vars);
-}
-
=item header Q [PARAM VALUE ...]
Return HTML for the top of the page, given PARAMs (TITLE is required).
@@ -287,7 +271,7 @@ sub header ($%) {
my $default_params = Cobrand::header_params(get_cobrand($q), $q, %params);
my %default_params = %{$default_params};
%params = (%default_params, %params);
- my %permitted_params = map { $_ => 1 } qw(title rss expires lastmodified template cachecontrol context status_code robots);
+ my %permitted_params = map { $_ => 1 } qw(title rss expires lastmodified template cachecontrol context status_code robots js);
foreach (keys %params) {
croak "bad parameter '$_'" if (!exists($permitted_params{$_}));
}
@@ -305,8 +289,8 @@ sub header ($%) {
$params{title} = ent($params{title});
$params{lang} = $mySociety::Locale::lang;
- my $template = template($q, %params);
- my $html = template_header($template, $q, template_root($q), %params);
+ my $vars = template_vars($q, %params);
+ my $html = template_include('header', $q, template_root($q), %$vars);
my $cache_val = $default_params{cachecontrol};
if (mySociety::Config::get('STAGING_SITE')) {
$html .= '<p class="error">' . _("This is a developer site; things might break at any time, and the database will be periodically deleted.") . '</p>';
@@ -320,10 +304,28 @@ sub header ($%) {
sub footer {
my ($q, %params) = @_;
- if ($q->{site} ne 'fixmystreet') {
- my $template = template($q, %params) . '-footer';
- my $template_root = template_root($q);
- my $html = template_include($template, $q, $template_root, %params);
+ my $pc = $q->param('pc') || '';
+ $pc = '?pc=' . URI::Escape::uri_escape($pc) if $pc;
+
+ my $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a>&nbsp;<a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.');
+ if (mySociety::Config::get('COUNTRY') eq 'NO') {
+ $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a> and maintained by <a href="http://www.nuug.no/">NUUG</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a>&nbsp;<a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.');
+ }
+
+ %params = (%params,
+ navigation => _('Navigation'),
+ report => _("Report a problem"),
+ reports => _("All reports"),
+ alerts => _("Local alerts"),
+ help => _("Help"),
+ contact => _("Contact"),
+ pc => $pc,
+ orglogo => _('<a href="http://www.mysociety.org/"><img id="logo" width="133" height="26" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>'),
+ creditline => $creditline,
+ );
+
+ my $html = template_include('footer', $q, template_root($q), %params);
+ if ($html) {
my $lang = $mySociety::Locale::lang;
if ($q->{site} eq 'emptyhomes' && $lang eq 'cy') {
$html =~ s/25 Walter Road<br>Swansea/25 Heol Walter<br>Abertawe/;
@@ -331,9 +333,6 @@ sub footer {
return $html;
}
- my $pc = $q->param('pc') || '';
- $pc = "?pc=" . ent($pc) if $pc;
-
my $piwik = "";
if (mySociety::Config::get('BASE_URL') eq "http://www.fixmystreet.com") {
$piwik = <<EOF;
@@ -352,29 +351,20 @@ piwikTracker.enableLinkTracking();
EOF
}
- my $navigation = _('Navigation');
- my $report = _("Report a problem");
- my $reports = _("All reports");
- my $alerts = _("Local alerts");
- my $help = _("Help");
- my $contact = _("Contact");
- my $orglogo = _('<a href="http://www.mysociety.org/"><img id="logo" width="133" height="26" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>');
- my $creditline = _('Built by <a href="http://www.mysociety.org/">mySociety</a>, using some <a href="http://github.com/mysociety/fixmystreet">clever</a>&nbsp;<a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>.');
-
return <<EOF;
</div></div>
-<h2 class="v">$navigation</h2>
+<h2 class="v">$params{navigation}</h2>
<ul id="navigation">
-<li><a href="/">$report</a></li>
-<li><a href="/reports">$reports</a></li>
-<li><a href="/alert$pc">$alerts</a></li>
-<li><a href="/faq">$help</a></li>
-<li><a href="/contact">$contact</a></li>
+<li><a href="/">$params{report}</a></li>
+<li><a href="/reports">$params{reports}</a></li>
+<li><a href="/alert$params{pc}">$params{alerts}</a></li>
+<li><a href="/faq">$params{help}</a></li>
+<li><a href="/contact">$params{contact}</a></li>
</ul>
-$orglogo
+$params{orglogo}
-<p id="footer">$creditline</p>
+<p id="footer">$params{creditline}</p>
$piwik
@@ -518,17 +508,17 @@ sub prettify_duration {
return _('less than a minute') if $s == 0;
}
my @out = ();
- _part(\$s, 60*60*24*7, _('week'), \@out);
- _part(\$s, 60*60*24, _('day'), \@out);
- _part(\$s, 60*60, _('hour'), \@out);
- _part(\$s, 60, _('minute'), \@out);
+ _part(\$s, 60*60*24*7, _('%d week'), _('%d weeks'), \@out);
+ _part(\$s, 60*60*24, _('%d day'), _('%d days'), \@out);
+ _part(\$s, 60*60, _('%d hour'), _('%d hours'), \@out);
+ _part(\$s, 60, _('%d minute'), _('%d minutes'), \@out);
return join(', ', @out);
}
sub _part {
- my ($s, $m, $w, $o) = @_;
+ my ($s, $m, $w1, $w2, $o) = @_;
if ($$s >= $m) {
my $i = int($$s / $m);
- push @$o, "$i $w" . ($i != 1 ? 's' : '');
+ push @$o, sprintf(mySociety::Locale::nget($w1, $w2, $i), $i);
$$s -= $i * $m;
}
}
@@ -688,10 +678,16 @@ sub mapit_check_error {
}
sub short_name {
- my $name = shift;
+ my ($area, $info) = @_;
# Special case Durham as it's the only place with two councils of the same name
- return 'Durham+County' if ($name eq 'Durham County Council');
- return 'Durham+City' if ($name eq 'Durham City Council');
+ # And some places in Norway
+ return 'Durham+County' if $area->{name} eq 'Durham County Council';
+ return 'Durham+City' if $area->{name} eq 'Durham City Council';
+ if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) {
+ my $parent = $info->{$area->{parent_area}}->{name};
+ return URI::Escape::uri_escape_utf8("$area->{name}, $parent");
+ }
+ my $name = $area->{name};
$name =~ s/ (Borough|City|District|County) Council$//;
$name =~ s/ Council$//;
$name =~ s/ & / and /;
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index 8c6eeccad..127d88a30 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -12,6 +12,7 @@
package Problems;
use strict;
+use Encode;
use Memcached;
use mySociety::DBHandle qw/dbh select_all/;
use mySociety::Locale;
@@ -93,12 +94,14 @@ sub recent_photos {
my $key = "recent_photos:$site_key:$num:$lat:$lon:$dist";
$probs = Memcached::get($key);
unless ($probs) {
- $probs = select_all("select id, title
+ $probs = mySociety::Locale::in_gb_locale {
+ select_all("select id, title
from problem_find_nearby(?, ?, ?) as nearby, problem
where nearby.problem_id = problem.id
and state in ('confirmed', 'fixed') and photo is not null
$site_restriction
order by confirmed desc limit $num", $lat, $lon, $dist);
+ };
Memcached::set($key, $probs, 3600);
}
} else {
@@ -259,7 +262,7 @@ sub problems_matching_criteria {
my $areas_info = mySociety::MaPit::call('areas', \@councils);
foreach my $problem (@$problems){
if ($problem->{council}) {
- my @council_names = map { $areas_info->{$_}->{name}} @{$problem->{council}} ;
+ my @council_names = map { $areas_info->{$_}->{name} } @{$problem->{council}} ;
$problem->{council} = join(' and ', @council_names);
}
}
diff --git a/perllib/Utils.pm b/perllib/Utils.pm
index d54e081c8..21994d20b 100644
--- a/perllib/Utils.pm
+++ b/perllib/Utils.pm
@@ -14,6 +14,7 @@ package Utils;
use strict;
use mySociety::DBHandle qw(dbh);
use mySociety::GeoUtil;
+use mySociety::Locale;
sub workaround_pg_bytea {
my ( $st, $img_idx, @elements ) = @_;
@@ -33,11 +34,30 @@ sub workaround_pg_bytea {
$s->execute();
}
+=head2 convert_latlon_to_en
+
+ ( $easting, $northing ) = Utils::convert_en_to_latlon( $latitude, $longitude );
+
+Takes the WGS84 latitude and longitude and returns OSGB36 easting and northing.
+
+=cut
+
+sub convert_latlon_to_en {
+ my ( $latitude, $longitude ) = @_;
+
+ my ( $easting, $northing ) =
+ mySociety::Locale::in_gb_locale {
+ mySociety::GeoUtil::wgs84_to_national_grid( $latitude, $longitude, 'G' );
+ };
+
+ return ( $easting, $northing );
+}
+
=head2 convert_en_to_latlon
( $latitude, $longitude ) = Utils::convert_en_to_latlon( $easting, $northing );
-Takes the easting and northing and returns latitude and longitude.
+Takes the OSGB36 easting and northing and returns WGS84 latitude and longitude.
=cut
@@ -56,8 +76,8 @@ sub convert_en_to_latlon {
( $lat, $lon ) = Utils::convert_en_to_latlon( $easting, $northing );
-Takes the easting and northing and returns latitude and longitude (truncated
-using C<Utils::truncate_coordinate>).
+Takes the OSGB36 easting and northing and returns WGS84 latitude and longitude
+(truncated using C<Utils::truncate_coordinate>).
=cut
@@ -74,13 +94,15 @@ sub convert_en_to_latlon_truncated {
$short = Utils::truncate_coordinate( $long );
Given a long coordinate returns a shorter one - rounded to 6 decimal places -
-which is < 1m at the equator.
+which is < 1m at the equator, if you're using WGS84 lat/lon.
=cut
sub truncate_coordinate {
my $in = shift;
- my $out = sprintf( '%0.6f', $in );
+ my $out = mySociety::Locale::in_gb_locale {
+ sprintf( '%0.6f', $in );
+ };
$out =~ s{\.?0+\z}{} if $out =~ m{\.};
return $out;
}