diff options
57 files changed, 407 insertions, 371 deletions
diff --git a/.travis.yml b/.travis.yml index 2c80b3534..b162c4c06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,6 @@ env: - secure: "qW+WCgAF68itADxcbcq+nCnKx3vf3GX73HMfjfbkFFUsYmIR+ZaJ9yQMnGJwxIpCHTWLAeqyx4KO8N8T3GmNdKYzIMZemOzp4ED29YC31QOQeq1CwNp2hD5sq/o47d2BzXWwMYNvNXfxz1K6r2c6EMPUtu8X3B8ExZq1RzSFdXs=" before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq jhead libgmp-dev python-boto -# A couple of other modules that normally come from packages, but no system stuff here - - cpanm -q Locale::gettext Math::BigInt::GMP - sudo locale-gen cy_GB.UTF-8 en_GB.UTF-8 nb_NO.UTF-8 de_CH.UTF-8 sv_SE.UTF-8 install: - .travis/install diff --git a/.travis/after_script b/.travis/after_script index 37fd37eb8..006ff7849 100755 --- a/.travis/after_script +++ b/.travis/after_script @@ -2,13 +2,11 @@ import hashlib import os +import site import subprocess import sys import tarfile -import boto -from boto.s3.key import Key - root = os.path.join(os.path.dirname(__file__), '..') with open(os.path.join(root, 'cpanfile.snapshot')) as cpanfile: hash = hashlib.md5(cpanfile.read()).hexdigest() @@ -18,6 +16,12 @@ if os.path.exists(wanted_filename) and os.path.getsize(wanted_filename): print "File was downloaded, no need to upload" sys.exit() +site.addsitedir(site.getusersitepackages()) +os.system('pip install --user boto') + +import boto +from boto.s3.key import Key + print "Creating archive..." tfile = tarfile.open(wanted_filename, 'w:gz') tfile.add('local') diff --git a/.travis/install b/.travis/install index c766d3598..b73eef330 100755 --- a/.travis/install +++ b/.travis/install @@ -19,6 +19,8 @@ try: tfile.extractall() print "Cached copy found and extracted" sys.exit(0) + else: + os.remove(wanted_filename) except IOError: os.remove(wanted_filename) diff --git a/bin/send-comments b/bin/send-comments index 2d6b525b5..fabf2b633 100755 --- a/bin/send-comments +++ b/bin/send-comments @@ -145,7 +145,7 @@ while ( my $body = $bodies->next ) { sub bromley_retry_timeout { my $row = shift; - my $tz = DateTime::TimeZone->new( name => 'local' ); + my $tz = FixMyStreet->local_time_zone; my $now = DateTime->now( time_zone => $tz ); my $diff = $now - $row->send_fail_timestamp; if ( $diff->in_units( 'minutes' ) < 30 ) { diff --git a/commonlib b/commonlib -Subproject 4e67698fa8d8b25b71b1baaf1a1856dcd566e5a +Subproject f87aecb7510fb6e43156328277ba4aa4b9e17d7 @@ -3,6 +3,10 @@ requires 'List::MoreUtils'; requires 'local::lib'; requires 'Class::Unload'; +# Interesting installation issues, see end of this file +requires 'ExtUtils::MakeMaker', '6.72'; # [1] +# requires 'MooseX::NonMoose'; # [2] + # Catalyst itself, and modules/plugins used requires 'Catalyst', '5.80031'; requires 'Catalyst::Action::RenderView'; @@ -55,6 +59,7 @@ requires 'Image::Size'; requires 'IO::String'; requires 'JSON'; requires 'JSON::XS'; +requires 'Locale::gettext'; requires 'LWP::Simple'; requires 'LWP::UserAgent'; requires 'Math::Trig'; @@ -128,3 +133,52 @@ requires 'Test::Warn'; requires 'Test::WWW::Mechanize::Catalyst'; requires 'Web::Scraper'; +################################################################# +# +# [1] Many things in cpanfile.snapshot require ExtUtils::MakeMaker 6.59, and +# one thing (DBIx::Class::IntrospectableM2M) requires 6.72, and so the snapshot +# contains the details for ExtUtils::MakeMaker 6.72. carton itself requires +# ExtUtils::MakeMaker 6.64. +# +# I don't understand the intracacies of carton/cpanm, but from the +# build.logs, I ascertain that DBIx::Class::Schema::Loader requires +# DBIx::Class::IntrospectableM2M and somehow in the process sets it up so that +# DBIx::Class::IntrospectableM2M tries to install the version of +# ExtUtils::MakeMaker used during the DBIx::Class::Schema::Loader installation. +# +# It seems as if the version of ExtUtils::MakeMaker used at any point is the +# one in local if present, then the one in local-carton if present, then the +# system one. Let's look at a few different installation platforms: +# +# On Debian wheezy, ExtUtils::MakeMaker is version 6.57. The installation of +# carton installs ExtUtils::MakeMaker 7.04 in local-carton. Running carton +# install installs ExtUtils::MakeMaker 6.72 in local at some point before +# DBIx::Class::Schema::Loader (due to one of the 6.59 requirements), and so +# DBIx::Class::IntrospectableM2M uses and tries to install 6.72, which is fine. +# +# On Ubuntu trusty, ExtUtils::MakeMaker is version 6.66. The installation of +# carton is satisfied already. Running carton install, nothing else upgrades +# ExtUtils::MakeMaker (as 6.66 > 6.59), and so when we get to +# DBIx::Class::IntrospectableM2M it uses the system 6.66 and upgrades to 6.72, +# which is again fine. +# +# On Mac OS X 10.9.5, ExtUtils::MakeMaker is version 6.63. The installation of +# carton installs ExtUtils::MakeMaker 7.04 in local-carton. Running carton +# install, nothing else upgrades ExtUtils::MakeMaker (as 6.63 > 6.59), and when +# we get to DBIx::Class::IntrospectableM2M it therefore uses 7.04 and can't +# install it (as the snapshot only contains 6.72) and fails. +# +# Therefore, if we make sure the ExtUtils::MakeMaker from the snapshot is +# installed early in the process, it will be available when we get to +# DBIx::Class::IntrospectableM2M, be used and match its own condition. +# I'm sure this isn't the correct solution, but it is a working one. +# +# +# [2] The installation of Catalyst::Model::DBIC::Schema tries to install any +# module that it finds already present in an optional section. On a Mac, the +# system has MooseX::NonMoose version 0.22, which is an optional component for +# Catalyst::Helper support, and it finds that but then thinks it is not +# installed, tries to install it but doesn't find it in the snapshot, and +# fails. The easiest solution here is to include MooseX::NonMoose in +# cpanfile.snapshot so it can be found, though I guess it shouldn't be trying +# to install it if it's already thought that 0.22 was installed... diff --git a/cpanfile.snapshot b/cpanfile.snapshot index e5d8b9afc..9bade8038 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -4176,6 +4176,22 @@ DISTRIBUTIONS Test::More 0.88 namespace::autoclean 0 namespace::clean 0.10 + MooseX-NonMoose-0.26 + pathname: D/DO/DOY/MooseX-NonMoose-0.26.tar.gz + provides: + MooseX::NonMoose 0.26 + MooseX::NonMoose::InsideOut 0.26 + MooseX::NonMoose::Meta::Role::Class 0.26 + MooseX::NonMoose::Meta::Role::Constructor 0.26 + requirements: + ExtUtils::MakeMaker 6.30 + List::MoreUtils 0 + Module::Runtime 0 + Moose::Exporter 0 + Moose::Role 2.0000 + Moose::Util 0 + Try::Tiny 0 + warnings 0 MooseX-Params-Validate-0.18 pathname: D/DR/DROLSKY/MooseX-Params-Validate-0.18.tar.gz provides: @@ -6599,6 +6615,12 @@ DISTRIBUTIONS common::sense 3.6 requirements: ExtUtils::MakeMaker 0 + gettext-1.05 + pathname: P/PV/PVANDRY/gettext-1.05.tar.gz + provides: + Locale::gettext 1.05 + requirements: + ExtUtils::MakeMaker 0 libwww-perl-6.05 pathname: G/GA/GAAS/libwww-perl-6.05.tar.gz provides: diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm index f3b72c4d0..76760b967 100644 --- a/perllib/FixMyStreet.pm +++ b/perllib/FixMyStreet.pm @@ -6,6 +6,7 @@ use warnings; use Path::Class; my $ROOT_DIR = file(__FILE__)->parent->parent->absolute->resolve; +use DateTime::TimeZone; use Readonly; use Sub::Override; @@ -217,4 +218,23 @@ sub get_email_template { return $template; } +my $tz = DateTime::TimeZone->new( name => "local" ); +my $tz_f; +$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) + if FixMyStreet->config('TIME_ZONE'); + +sub local_time_zone { + return $tz; +} + +sub time_zone { + return $tz_f; +} + +sub set_time_zone { + my ($class, $dt) = @_; + $dt->set_time_zone($tz); + $dt->set_time_zone($tz_f) if $tz_f; +} + 1; diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index e821b7467..1aa70b497 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -441,11 +441,6 @@ sub determine_location : Private { $c->go('index'); } - # truncate the lat,lon for nicer urls - ( $c->stash->{latitude}, $c->stash->{longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $c->stash->{latitude}, $c->stash->{longitude} ); - my $dist = mySociety::Gaze::get_radius_containing_population( $c->stash->{latitude}, $c->stash->{longitude}, 200000 ); diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 0e42b8a17..413af814f 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -40,8 +40,10 @@ sub around_index : Path : Args(0) { # Try to create a location for whatever we have my $ret = $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); - return unless $ret; - return $c->res->redirect('/') if $ret == -1 && !$partial_report; + unless ($ret) { + return $c->res->redirect('/') unless $c->req->param('pc') || $partial_report; + return; + } # Check to see if the spot is covered by a area - if not show an error. return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable'); @@ -158,12 +160,6 @@ sub display_location : Private { my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; - # truncate the lat,lon for nicer rss urls, and strings for outputting - my $short_latitude = Utils::truncate_coordinate($latitude); - my $short_longitude = Utils::truncate_coordinate($longitude); - $c->stash->{short_latitude} = $short_latitude; - $c->stash->{short_longitude} = $short_longitude; - # Deal with pin hiding/age my $all_pins = $c->req->param('all_pins') ? 1 : undef; $c->stash->{all_pins} = $all_pins; @@ -171,7 +167,7 @@ sub display_location : Private { # get the map features my ( $on_map_all, $on_map, $around_map, $distance ) = - FixMyStreet::Map::map_features( $c, $short_latitude, $short_longitude, + FixMyStreet::Map::map_features( $c, $latitude, $longitude, $interval ); # copy the found reports to the stash @@ -199,8 +195,8 @@ sub display_location : Private { $c->stash->{page} = 'around'; # So the map knows to make clickable pins, update on pan FixMyStreet::Map::display_map( $c, - latitude => $short_latitude, - longitude => $short_longitude, + latitude => $latitude, + longitude => $longitude, clickable => 1, pins => \@pins, area => $c->cobrand->areas_on_around, @@ -317,7 +313,7 @@ sub _geocode : Private { if ( ref($suggestions) eq 'ARRAY' ) { foreach (@$suggestions) { push @addresses, decode_utf8($_->{address}); - push @locations, { address => decode_utf8($_->{address}), lat => $_->{latitude}, long => $_->{longitude} }; + push @locations, { address => decode_utf8($_->{address}), lat => $_->{latitude}, long => $_->{longitude} }; } $response = { suggestions => \@addresses, locations => \@locations }; } else { diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 8a174c254..a5915aa46 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -49,9 +49,6 @@ sub load_and_check_areas : Private { $area_types = $c->cobrand->area_types; } - my $short_latitude = Utils::truncate_coordinate($latitude); - my $short_longitude = Utils::truncate_coordinate($longitude); - my $all_areas; my %params; @@ -62,7 +59,7 @@ sub load_and_check_areas : Private { my %area_types = map { $_ => 1 } @$area_types; $all_areas = mySociety::MaPit::call( 'point', - "4326/$short_longitude,$short_latitude", %params ); + "4326/$longitude,$latitude", %params ); $c->stash->{all_areas_mapit} = $all_areas; $all_areas = { map { $_ => $all_areas->{$_} } @@ -72,7 +69,7 @@ sub load_and_check_areas : Private { } else { $all_areas = mySociety::MaPit::call( 'point', - "4326/$short_longitude,$short_latitude", %params, + "4326/$longitude,$latitude", %params, type => $area_types ); } if ($all_areas->{error}) { diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 25c6e1923..c2b0a2ee2 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -128,7 +128,7 @@ sub index : Path : Args(0) { my $dtf = $c->model('DB')->storage->datetime_parser; my %counts; - my $now = DateTime->now( time_zone => 'local' ); + my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone ); my $t = $now->clone->truncate( to => 'day' ); $counts{wtd} = $c->forward( 'updates_search', [ $dtf->format_datetime( $t->clone->subtract( days => $t->dow - 1 ) ) ] ); diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index 8a68b2b3d..5e5349a6c 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -6,6 +6,7 @@ BEGIN {extends 'Catalyst::Controller'; } use Encode; use FixMyStreet::Geocode; +use Utils; =head1 NAME @@ -32,8 +33,8 @@ sub determine_location_from_coords : Private { my $longitude = $c->req->param('longitude') || $c->req->param('lon'); if ( defined $latitude && defined $longitude ) { - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($latitude, $longitude); # Also save the pc if there is one if ( my $pc = $c->req->param('pc') ) { @@ -50,7 +51,7 @@ sub determine_location_from_coords : Private { User has searched for a location - try to find it for them. -Return -1 if nothing provided. +Return false if nothing provided. If one match is found returns true and lat/lng is set. @@ -64,18 +65,19 @@ sub determine_location_from_pc : Private { my ( $self, $c, $pc ) = @_; # check for something to search - $pc ||= $c->req->param('pc') || return -1; + $pc ||= $c->req->param('pc') || return; $c->stash->{pc} = $pc; # for template if ( $pc =~ /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/ ) { - $c->stash->{latitude} = $1; - $c->stash->{longitude} = $2; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($1, $2); return $c->forward( 'check_location' ); } if ( $c->cobrand->country eq 'GB' && $pc =~ /^([A-Z])([A-Z])([\d\s]{4,})$/i) { if (my $convert = gridref_to_latlon( $1, $2, $3 )) { - $c->stash->{latitude} = $convert->{latitude}; - $c->stash->{longitude} = $convert->{longitude}; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } + ($convert->{latitude}, $convert->{longitude}); return $c->forward( 'check_location' ); } } diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 09afabecf..d70be50e6 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -8,6 +8,7 @@ use DateTime::Format::HTTP; use Digest::SHA qw(sha1_hex); use File::Path; use File::Slurp; +use Image::Size; use Path::Class; use if !$ENV{TRAVIS}, 'Image::Magick'; @@ -181,7 +182,11 @@ sub process_photo_upload : Private { my $photo_blob = eval { my $filename = $upload->tempname; my $out = `jhead -se -autorot $filename 2>&1`; - die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; + unless (defined $out) { + my ($w, $h, $err) = Image::Size::imgsize($filename); + die _("Please upload a JPEG image only") . "\n" if !defined $w || $err ne 'JPG'; + } + die _("Please upload a JPEG image only") . "\n" if $out && $out =~ /Not JPEG:/; my $photo = $upload->slurp; return $photo; }; diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 46d6350d7..70edcabe3 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -279,10 +279,6 @@ sub display : Private { my $problem = $c->stash->{questionnaire}->problem; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $problem->latitude, $problem->longitude ); - $c->stash->{updates} = [ $c->model('DB::Comment')->search( { problem_id => $problem->id, state => 'confirmed' }, { order_by => 'confirmed' } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 88a49f6c9..e188a085d 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -159,7 +159,7 @@ sub format_problem_for_display : Private { my $problem = $c->stash->{problem}; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = + ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } ( $problem->latitude, $problem->longitude ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ed5be4e99..ebc5cc6a0 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -540,8 +540,8 @@ sub determine_location_from_tile_click : Private { ); # store it on the stash - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($latitude, $longitude); # set a flag so that the form is not considered submitted. This will prevent # errors showing on the fields. @@ -1090,10 +1090,6 @@ sub generate_map : Private { my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $c->stash->{latitude}, $c->stash->{longitude} ); - # Don't do anything if the user skipped the map if ( $c->stash->{report}->used_map ) { $c->stash->{page} = 'new'; diff --git a/perllib/FixMyStreet/Cobrand/Harrogate.pm b/perllib/FixMyStreet/Cobrand/Harrogate.pm index 6bcc2f227..8c0639ee7 100644 --- a/perllib/FixMyStreet/Cobrand/Harrogate.pm +++ b/perllib/FixMyStreet/Cobrand/Harrogate.pm @@ -238,5 +238,9 @@ sub process_additional_metadata_for_email { $h->{additional_information} = $additional; } +sub send_questionnaires { + return 0; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 4ce72f873..c64cb2ff4 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -69,24 +69,16 @@ __PACKAGE__->belongs_to( # You can replace this text with custom code or comments, and it will be preserved on regeneration -use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 3fae6860a..836462ed5 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -95,25 +95,17 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 34d740912..3c620ba84 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -153,7 +153,6 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); __PACKAGE__->rabx_column('geocode'); -use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; @@ -316,18 +315,11 @@ sub council_states { return wantarray ? keys %{$states} : $states; } -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; @@ -745,7 +737,7 @@ sub update_from_open311_service_request { # of course if local timezone is not the one that went into the data # base then we're also in trouble my $lastupdate = $self->lastupdate; - $lastupdate->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); + $lastupdate->set_time_zone( FixMyStreet->local_time_zone ); # update from open311 is older so skip if ( $req_time < $lastupdate ) { diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index 7f9c79d9a..6f2941546 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -43,22 +43,14 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oL1Hk4/bNG14CY74GA75SA -use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index b704fa7dd..ad180cbd5 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -115,24 +115,14 @@ sub email_alerts ($) { } $data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous}; if ( $cobrand->include_time_in_update_alerts ) { - # this is basically recreating the code from the inflate wrapper - # in the database model. - my $tz; - if ( FixMyStreet->config('TIME_ZONE') ) { - $tz = FixMyStreet->config('TIME_ZONE'); - } - my $parser = DateTime::Format::Pg->new(); my $dt = $parser->parse_timestamp( $row->{item_confirmed} ); - my $l_tz = DateTime::TimeZone->new( name => "local" ); # We need to always set this otherwise we end up with the DateTime # object being in the floating timezone in which case applying a # subsequent timezone set will have no effect. - $dt->set_time_zone( $l_tz ); - if ( $tz ) { - my $tz_obj = DateTime::TimeZone->new( name => $tz ); - $dt->set_time_zone( $tz_obj ); - } + # this is basically recreating the code from the inflate wrapper + # in the database model. + FixMyStreet->set_time_zone($dt); $data{data} .= $cobrand->prettify_dt( $dt, 'alert' ) . "\n\n"; } $data{data} .= $row->{item_text} . "\n\n------\n\n"; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index a84a309ee..10d395684 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -302,10 +302,7 @@ sub send_reports { ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude} ); # email templates don't have conditionals so we need to farmat this here - $h{easting_northing} # - = "Easting: $h{easting}\n\n" # - . "Northing: $h{northing}\n\n"; - + $h{easting_northing} = "Easting/Northing: $h{easting}/$h{northing}\n\n"; } if ( $row->used_map ) { diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index b5be152a8..aac52fbaa 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -7,11 +7,17 @@ package FixMyStreet::Geocode; use strict; +use Digest::MD5 qw(md5_hex); +use Encode; +use File::Slurp; +use File::Path (); +use LWP::Simple qw($ua); use URI::Escape; use FixMyStreet::Geocode::Bing; use FixMyStreet::Geocode::Google; use FixMyStreet::Geocode::OSM; use FixMyStreet::Geocode::Zurich; +use Utils; # lookup STRING CONTEXT # Given a user-inputted string, try and convert it into co-ordinates using either @@ -21,6 +27,11 @@ use FixMyStreet::Geocode::Zurich; sub lookup { my ($s, $c) = @_; my $data = $c->cobrand->geocode_postcode($s); + if (defined $data->{latitude}) { + ( $data->{latitude}, $data->{longitude} ) = + map { Utils::truncate_coordinate($_) } + ( $data->{latitude}, $data->{longitude} ); + } $data = string($s, $c) unless $data->{error} || defined $data->{latitude}; $data->{error} = _('Sorry, we could not find that location.') @@ -55,4 +66,25 @@ sub escape { return $s; } +sub cache { + my ($type, $url, $args, $re) = @_; + my $cache_dir = FixMyStreet->config('GEO_CACHE') . $type . '/'; + my $cache_file = $cache_dir . md5_hex($url); + my $js; + if (-s $cache_file && -M $cache_file <= 7) { + $js = File::Slurp::read_file($cache_file); + } else { + $url .= '&' . $args if $args; + $ua->timeout(15); + $js = LWP::Simple::get($url); + $js = encode_utf8($js) if utf8::is_utf8($js); + File::Path::mkpath($cache_dir); + if ($js && (!$re || $js !~ $re)) { + File::Slurp::write_file($cache_file, $js); + } + } + $js = JSON->new->utf8->allow_nonref->decode($js) if $js; + return $js; +} + 1; diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm index 702e19814..d7db10ae6 100644 --- a/perllib/FixMyStreet/Geocode/Bing.pm +++ b/perllib/FixMyStreet/Geocode/Bing.pm @@ -7,13 +7,8 @@ package FixMyStreet::Geocode::Bing; use strict; -use Encode; -use File::Slurp; -use File::Path (); -use LWP::Simple; -use Digest::MD5 qw(md5_hex); -use mySociety::Locale; +use Utils; # string STRING CONTEXT # Looks up on Bing Maps API, and caches, a user-inputted location. @@ -34,24 +29,10 @@ sub string { $url .= '&userLocation=' . $params->{centre} if $params->{centre}; $url .= '&c=' . $params->{bing_culture} if $params->{bing_culture}; - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; - my $cache_file = $cache_dir . md5_hex($url); - my $js; - if (-s $cache_file) { - $js = File::Slurp::read_file($cache_file); - } else { - $url .= '&key=' . FixMyStreet->config('BING_MAPS_API_KEY'); - $js = LWP::Simple::get($url); - $js = encode_utf8($js) if utf8::is_utf8($js); - File::Path::mkpath($cache_dir); - File::Slurp::write_file($cache_file, $js) if $js; - } - + my $js = FixMyStreet::Geocode::cache('bing', $url, 'key=' . FixMyStreet->config('BING_MAPS_API_KEY')); if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; } - - $js = JSON->new->utf8->allow_nonref->decode($js); if ($js->{statusCode} ne '200') { return { error => _('Sorry, we could not find that location.') }; } @@ -71,15 +52,14 @@ sub string { || $valid_locations[-1]{address}{locality} eq $_->{address}{locality} ); - ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} }; - # These co-ordinates are output as query parameters in a URL, make sure they have a "." - mySociety::Locale::in_gb_locale { - push (@$error, { - address => $address, - latitude => sprintf('%0.6f', $latitude), - longitude => sprintf('%0.6f', $longitude) - }); - }; + ( $latitude, $longitude ) = + map { Utils::truncate_coordinate($_) } + @{ $_->{point}->{coordinates} }; + push (@$error, { + address => $address, + latitude => $latitude, + longitude => $longitude + }); push (@valid_locations, $_); } @@ -88,33 +68,15 @@ sub string { } sub reverse { - my ( $latitude, $longitude, $bing_culture, $cache ) = @_; + my ( $latitude, $longitude, $bing_culture ) = @_; # Get nearest road-type thing from Bing my $key = mySociety::Config::get('BING_MAPS_API_KEY', ''); if ($key) { my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?key=$key"; $url .= '&c=' . $bing_culture if $bing_culture; - my $j; - if ( $cache ) { - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/'; - my $cache_file = $cache_dir . md5_hex($url); - - if (-s $cache_file) { - $j = File::Slurp::read_file($cache_file); - } else { - $j = LWP::Simple::get($url); - File::Path::mkpath($cache_dir); - File::Slurp::write_file($cache_file, $j) if $j; - } - } else { - $j = LWP::Simple::get($url); - } - - if ($j) { - $j = JSON->new->utf8->allow_nonref->decode($j); - return $j; - } + my $j = FixMyStreet::Geocode::cache('bing', $url); + return $j if $j; } return undef; diff --git a/perllib/FixMyStreet/Geocode/FixaMinGata.pm b/perllib/FixMyStreet/Geocode/FixaMinGata.pm index 2ea92c422..3ad98b148 100644 --- a/perllib/FixMyStreet/Geocode/FixaMinGata.pm +++ b/perllib/FixMyStreet/Geocode/FixaMinGata.pm @@ -14,16 +14,11 @@ package FixMyStreet::Geocode::FixaMinGata; use warnings; use strict; -use Data::Dumper; -use Digest::MD5 qw(md5_hex); -use Encode; -use File::Slurp; -use File::Path (); -use LWP::Simple qw($ua); +use LWP::Simple; use Memcached; use XML::Simple; -use mySociety::Locale; +use Utils; my $osmapibase = "http://www.openstreetmap.org/api/"; my $nominatimbase = "http://nominatim.openstreetmap.org/"; @@ -45,8 +40,8 @@ sub string { my %query_params = ( q => $s, format => 'json', - addressdetails => 1, - limit => 20, + addressdetails => 1, + limit => 20, #'accept-language' => '', email => 'info' . chr(64) . 'morus.se', ); @@ -56,53 +51,32 @@ sub string { if $params->{country}; $url .= join('&', map { "$_=$query_params{$_}" } keys %query_params); - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'osm/'; - my $cache_file = $cache_dir . md5_hex($url); - my $js; - if (-s $cache_file) { - $js = File::Slurp::read_file($cache_file); - } else { - $ua->timeout(15); - $js = LWP::Simple::get($url); - $js = encode_utf8($js) if utf8::is_utf8($js); - File::Path::mkpath($cache_dir); - File::Slurp::write_file($cache_file, $js) if $js; - } - + my $js = FixMyStreet::Geocode::cache('osm', $url); if (!$js) { return { error => _('Sorry, we could not find that location.') }; } - $js = JSON->new->utf8->allow_nonref->decode($js); - my ( %locations, $error, @valid_locations, $latitude, $longitude ); foreach (@$js) { - # These co-ordinates are output as query parameters in a URL, make sure they have a "." - next if $_->{class} eq "boundary"; - - my @s = split(/,/, $_->{display_name}); - - my $address = join(",", @s[0,1,2]); - + next if $_->{class} eq "boundary"; + my @s = split(/,/, $_->{display_name}); + my $address = join(",", @s[0,1,2]); $locations{$address} = [$_->{lat}, $_->{lon}]; } - my ($key) = keys %locations; - - return { latitude => $locations{$key}[0], longitude => $locations{$key}[1] } if scalar keys %locations == 1; - return { error => _('Sorry, we could not find that location.') } if scalar keys %locations == 0; - - foreach $key (keys %locations) { - ( $latitude, $longitude ) = ($locations{$key}[0], $locations{$key}[1]); - mySociety::Locale::in_gb_locale { - push (@$error, { - address => $key, - latitude => sprintf('%0.6f', $latitude), - longitude => sprintf('%0.6f', $longitude) - }); - }; + foreach my $key (keys %locations) { + ( $latitude, $longitude ) = + map { Utils::truncate_coordinate($_) } + ($locations{$key}[0], $locations{$key}[1]); + push (@$error, { + address => $key, + latitude => $latitude, + longitude => $longitude + }); + push (@valid_locations, $_); } + return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; return { error => $error }; } diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm index 11ff8ef80..35fcec36f 100644 --- a/perllib/FixMyStreet/Geocode/Google.pm +++ b/perllib/FixMyStreet/Geocode/Google.pm @@ -7,12 +7,7 @@ package FixMyStreet::Geocode::Google; use strict; -use Encode; -use File::Slurp; -use File::Path (); -use LWP::Simple; -use Digest::MD5 qw(md5_hex); -use mySociety::Locale; +use Utils; # string STRING CONTEXT # Looks up on Google Maps API, and caches, a user-inputted location. @@ -24,6 +19,13 @@ sub string { my $params = $c->cobrand->disambiguate_location($s); + # For some reason adding gl=uk is no longer sufficient to make google + # think we are in the UK for some locations so we explictly add UK to + # the address. + if ($c->cobrand->country eq 'GB' && $s !~ /, *UK/ && $s !~ /united *kingdom$/) { + $s .= ', UK'; + } + $s = FixMyStreet::Geocode::escape($s); my $url = 'http://maps.google.com/maps/geo?q=' . $s; @@ -36,38 +38,11 @@ sub string { } $url .= '&hl=' . $params->{lang} if $params->{lang}; - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'google/'; - my $cache_file = $cache_dir . md5_hex($url); - my $js; - if (-s $cache_file) { - $js = File::Slurp::read_file($cache_file); - } else { - # For some reason adding gl=uk is no longer sufficient to make google - # think we are in the UK for some locations so we explictly add UK to - # the address. We do it here so as not to invalidate existing cache - # entries - if ( $c->cobrand->country eq 'GB' - && $url !~ /,\+UK/ - && $url !~ /united\++kingdom$/ ) - { - if ( $url =~ /&/ ) { - $url =~ s/&/,+UK&/; - } else { - $url .= ',+UK'; - } - } - $url .= '&sensor=false&key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY'); - $js = LWP::Simple::get($url); - $js = encode_utf8($js) if utf8::is_utf8($js); - File::Path::mkpath($cache_dir); - File::Slurp::write_file($cache_file, $js) if $js && $js !~ /"code":6[12]0/; - } - + my $args = 'sensor=false&key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY'); + my $js = FixMyStreet::Geocode::cache('google', $url, $args, qr/"code":6[12]0/); if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; } - - $js = JSON->new->utf8->allow_nonref->decode($js); if ($js->{Status}->{code} ne '200') { return { error => _('Sorry, we could not find that location.') }; } @@ -78,15 +53,14 @@ sub string { next unless $_->{AddressDetails}->{Accuracy} >= 4; my $address = $_->{address}; next unless $c->cobrand->geocoded_string_check( $address ); - ( $longitude, $latitude ) = @{ $_->{Point}->{coordinates} }; - # These co-ordinates are output as query parameters in a URL, make sure they have a "." - mySociety::Locale::in_gb_locale { - push (@$error, { - address => $address, - latitude => sprintf('%0.6f', $latitude), - longitude => sprintf('%0.6f', $longitude) - }); - }; + ( $longitude, $latitude ) = + map { Utils::truncate_coordinate($_) } + @{ $_->{Point}->{coordinates} }; + push (@$error, { + address => $address, + latitude => $latitude, + longitude => $longitude + }); push (@valid_locations, $_); } return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm index 919940f78..f165963d7 100644 --- a/perllib/FixMyStreet/Geocode/OSM.pm +++ b/perllib/FixMyStreet/Geocode/OSM.pm @@ -9,14 +9,10 @@ package FixMyStreet::Geocode::OSM; use warnings; use strict; -use Digest::MD5 qw(md5_hex); -use Encode; -use File::Slurp; -use File::Path (); -use LWP::Simple qw($ua); +use LWP::Simple; use Memcached; use XML::Simple; -use mySociety::Locale; +use Utils; my $osmapibase = "http://www.openstreetmap.org/api/"; my $nominatimbase = "http://nominatim.openstreetmap.org/"; @@ -47,36 +43,21 @@ sub string { if $params->{country}; $url .= join('&', map { "$_=$query_params{$_}" } keys %query_params); - my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'osm/'; - my $cache_file = $cache_dir . md5_hex($url); - my $js; - if (-s $cache_file) { - $js = File::Slurp::read_file($cache_file); - } else { - $ua->timeout(15); - $js = LWP::Simple::get($url); - $js = encode_utf8($js) if utf8::is_utf8($js); - File::Path::mkpath($cache_dir); - File::Slurp::write_file($cache_file, $js) if $js; - } - + my $js = FixMyStreet::Geocode::cache('osm', $url); if (!$js) { return { error => _('Sorry, we could not find that location.') }; } - $js = JSON->new->utf8->allow_nonref->decode($js); - my ( $error, @valid_locations, $latitude, $longitude ); foreach (@$js) { - # These co-ordinates are output as query parameters in a URL, make sure they have a "." - ( $latitude, $longitude ) = ( $_->{lat}, $_->{lon} ); - mySociety::Locale::in_gb_locale { - push (@$error, { - address => $_->{display_name}, - latitude => sprintf('%0.6f', $latitude), - longitude => sprintf('%0.6f', $longitude) - }); - }; + ( $latitude, $longitude ) = + map { Utils::truncate_coordinate($_) } + ( $_->{lat}, $_->{lon} ); + push (@$error, { + address => $_->{display_name}, + latitude => $latitude, + longitude => $longitude + }); push (@valid_locations, $_); } diff --git a/perllib/FixMyStreet/Geocode/Zurich.pm b/perllib/FixMyStreet/Geocode/Zurich.pm index 1f0b4fc16..aad918b0e 100644 --- a/perllib/FixMyStreet/Geocode/Zurich.pm +++ b/perllib/FixMyStreet/Geocode/Zurich.pm @@ -15,7 +15,7 @@ use Digest::MD5 qw(md5_hex); use File::Path (); use Geo::Coordinates::CH1903; use Storable; -use mySociety::Locale; +use Utils; my ($soap, $method, $security); @@ -66,7 +66,7 @@ sub string { my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'zurich/'; my $cache_file = $cache_dir . md5_hex($s); my $result; - if (-s $cache_file) { + if (-s $cache_file && -M $cache_file <= 7) { $result = retrieve($cache_file); } else { my $search = SOAP::Data->name('search' => $s)->type(''); @@ -92,14 +92,14 @@ sub string { my ( $error, @valid_locations, $latitude, $longitude ); foreach (@$results) { - ($latitude, $longitude) = Geo::Coordinates::CH1903::to_latlon($_->{easting}, $_->{northing}); - mySociety::Locale::in_gb_locale { - push (@$error, { - address => $_->{text}, - latitude => sprintf('%0.6f', $latitude), - longitude => sprintf('%0.6f', $longitude) - }); - }; + ($latitude, $longitude) = + map { Utils::truncate_coordinate($_) } + Geo::Coordinates::CH1903::to_latlon($_->{easting}, $_->{northing}); + push (@$error, { + address => $_->{text}, + latitude => $latitude, + longitude => $longitude + }); push (@valid_locations, $_); last if lc($_->{text}) eq lc($s); } diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index 40e76ef72..9967b0663 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -23,8 +23,7 @@ sub should_skip { return 0 unless $row->send_fail_count; - my $tz = DateTime::TimeZone->new( name => 'local' ); - my $now = DateTime->now( time_zone => $tz ); + my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone ); my $diff = $now - $row->send_fail_timestamp; my $backoff = $row->send_fail_count > 1 ? 30 : 5; diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 7f95d1f5a..87e0bd7c9 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -225,7 +225,7 @@ sub prettify_dt { $type ||= ''; $type = 'short' if $type eq '1'; - my $now = DateTime->now( time_zone => FixMyStreet->config('TIME_ZONE') || 'local' ); + my $now = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ); my $tt = ''; return "[unknown time]" unless ref $dt; diff --git a/t/MapIt.pm b/t/MapIt.pm new file mode 100644 index 000000000..ebef934e1 --- /dev/null +++ b/t/MapIt.pm @@ -0,0 +1,36 @@ +package t::MapIt; + +use JSON; +use Web::Simple; + +use mySociety::Locale; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /postcode/*) { + my ($self, $postcode) = @_; + my $response = $self->postcode($postcode); + # We must make sure we output correctly for testing purposes, we might + # be within a different locale here... + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode($response) }; + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +sub postcode { + my ($self, $postcode) = @_; + return { + wgs84_lat => 51.5, wgs84_lon => 2.1, postcode => $postcode, + }; +} + +__PACKAGE__->run_if_script; diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t index 105847576..714d475e1 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -1,12 +1,16 @@ use strict; use warnings; use Test::More; +use LWP::Protocol::PSGI; BEGIN { use FixMyStreet; FixMyStreet->test_mode(1); } +use t::MapIt; +use mySociety::Locale; + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -96,6 +100,25 @@ like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay'; like $email->body, qr/V=E4nligen,/, 'signature looks correct'; $mech->clear_emails_ok; +subtest "Test ajax decimal points" => sub { + # The following line is so we are definitely not in Swedish before + # requesting the page, so that the code performs a full switch to Swedish + mySociety::Locale::push('en-gb'); + + # A note to the future - the run_if_script line must be within a subtest + # otherwise it fails to work + LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.sweden'); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixamingata' ], + MAPIT_URL => 'http://mapit.sweden/' + }, sub { + $mech->get_ok('/ajax/lookup_location?term=12345'); + # We want an actual decimal point in a JSON response... + $mech->content_contains('51.5'); + }; +}; + END { $mech->delete_problems_for_body(1); ok $mech->host("www.fixmystreet.com"), "change host back"; diff --git a/templates/email/default/submit-example.txt b/templates/email/default/submit-example.txt index b3853e1a5..7fa0a23da 100644 --- a/templates/email/default/submit-example.txt +++ b/templates/email/default/submit-example.txt @@ -27,9 +27,7 @@ you approach the junction along Bournville Lane from the east, which leads to vehicles rolling back as they fall in and out of it whilst waiting at the junction. -Easting: 404517 - -Northing: 280922 +Easting/Northing: 404517/280922 Latitude: 52.4262642791826 diff --git a/templates/email/fixamingata/submit-example.txt b/templates/email/fixamingata/submit-example.txt deleted file mode 100644 index c11d613ad..000000000 --- a/templates/email/fixamingata/submit-example.txt +++ /dev/null @@ -1,61 +0,0 @@ -Subject: Problem Report: Dangerous pothole - -Dear Birmingham City Council, - -A user of FixMyStreet has submitted the following report of a -local problem that they believe might require your attention. - -To view a map of the precise location of this issue, or to provide -an update on the problem, please visit the following link: - - http://www.fixmystreet.com/report/39092 - ----------- - -Name: Matthew Somerville - -Email: [...] - -Phone: [...] - -Category: Potholes - -Subject: Dangerous pothole - -Details: There is a large pothole almost on the give way line as -you approach the junction along Bournville Lane from the east, -which leads to vehicles rolling back as they fall in and out of it -whilst waiting at the junction. - -Easting: 404517 - -Northing: 280922 - -Latitude: 52.4262642791826 - -Longitude: -1.93500217285966 - -Nearest road to the pin placed on the map (automatically -generated by Bing Maps): Bournville Lane, Birmingham B30 1 - -Nearest postcode to the pin placed on the map (automatically -generated): B30 1LA (83m away) - ----------- - -Replies to this email will go to the user who submitted the problem. - -Yours, -The FixMyStreet team - -This message was sent via FixMyStreet, a project of UKCOD, -registered charity number 1076346. If there is a more appropriate -email address for messages about 'Potholes', please let us know by -visiting <http://www.fixmystreet.com/contact>. This will help -improve the service for local people. We also welcome any other -feedback you may have. - -FixMyStreet is now available for full integration into council -websites, making life easier for both you and your residents. -Read more here: https://www.fixmystreet.com/council - diff --git a/templates/web/base/around/display_location.html b/templates/web/base/around/display_location.html index 804be9603..3f4ec8881 100755 --- a/templates/web/base/around/display_location.html +++ b/templates/web/base/around/display_location.html @@ -6,14 +6,14 @@ rss_url = pc ? c.uri_for( "/rss/pc", pc ) - : c.uri_for( "/rss/l/$short_latitude,$short_longitude" ); + : c.uri_for( "/rss/l/$latitude,$longitude" ); email_url = c.uri_for( '/alert/list', { - lat => short_latitude, - lon => short_longitude, - feed => "local:$short_latitude:$short_longitude", + lat => latitude, + lon => longitude, + feed => "local:$latitude:$longitude", } ); @@ -21,8 +21,8 @@ '/report/new', { pc => pc - latitude => short_latitude, - longitude => short_longitude, + latitude => latitude, + longitude => longitude, skipped => 1, } ); @@ -45,8 +45,8 @@ [% END %] <input type="hidden" name="pc" value="[% pc | html %]"> - <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% short_latitude | html %]"> - <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% short_longitude | html %]"> + <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% latitude | html %]"> + <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% longitude | html %]"> [% END %] [% map_html %] diff --git a/templates/web/base/report/display.html b/templates/web/base/report/display.html index a7181942f..0731d9f0e 100644 --- a/templates/web/base/report/display.html +++ b/templates/web/base/report/display.html @@ -31,7 +31,7 @@ [% IF c.cobrand.moniker != 'emptyhomes' %] <p style="padding-bottom: 0.5em; border-bottom: dotted 1px #999999;" align="right"> - <a href="[% c.uri_for( '/around', { lat => short_latitude, lon => short_longitude } ) %]">[% loc( 'More problems nearby' ) %]</a> + <a href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]">[% loc( 'More problems nearby' ) %]</a> </p> <div id="alert_links"> diff --git a/templates/web/base/report/new/fill_in_details.html b/templates/web/base/report/new/fill_in_details.html index 1b8a866fc..9d3f52041 100644 --- a/templates/web/base/report/new/fill_in_details.html +++ b/templates/web/base/report/new/fill_in_details.html @@ -22,8 +22,8 @@ [% END %] - <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% short_latitude | html %]"> - <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% short_longitude | html %]"> + <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% latitude | html %]"> + <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% longitude | html %]"> [% IF report.used_map %] [% map_html %] diff --git a/templates/web/base/tokens/confirm_problem.html b/templates/web/base/tokens/confirm_problem.html index 217fb0a72..8c92c874a 100644 --- a/templates/web/base/tokens/confirm_problem.html +++ b/templates/web/base/tokens/confirm_problem.html @@ -31,6 +31,8 @@ [% END %] +[% TRY %][% INCLUDE 'tokens/_extras_confirm.html' %][% CATCH file %][% END %] + </div> [% display_crosssell_advert( problem.user.email, problem.name ) %] diff --git a/templates/web/bromley/report/display.html b/templates/web/bromley/report/display.html index f30b4b86d..75b7700a5 100644 --- a/templates/web/bromley/report/display.html +++ b/templates/web/bromley/report/display.html @@ -25,7 +25,7 @@ <ul id="key-tools"> <li><a rel="nofollow" id="key-tool-report-abuse" class="abuse" href="[% c.uri_for( '/contact', { id => problem.id } ) %]">[% loc('Report abuse') %]</a></li> <li><a rel="nofollow" id="key-tool-report-updates" class="feed" href="[% c.uri_for( '/alert/subscribe', { id => problem.id } ) %]">[% loc('Get updates' ) %]</a></li> - <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => short_latitude, lon => short_longitude } ) %]">[% loc( 'Problems nearby' ) %]</a></li> + <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]">[% loc( 'Problems nearby' ) %]</a></li> </ul> <div id="report-updates-data" class="hidden-js"> diff --git a/templates/web/fixmystreet.com/footer_extra.html b/templates/web/fixmystreet.com/footer_extra.html new file mode 100644 index 000000000..ba32a5534 --- /dev/null +++ b/templates/web/fixmystreet.com/footer_extra.html @@ -0,0 +1,3 @@ +<script type="text/javascript"> + (function(){var e=0.6;var t=null;var n=document.cookie.split(";");for(var r=0;r<n.length;r++){var i=n[r];while(i.charAt(0)==" "){i=i.substring(1,i.length)}if(i.indexOf("ms_srv_t=")==0){var t=i.substring("ms_srv_t=".length,i.length)}if(i.indexOf("ms_srv_r=")==0){var s=i.substring("ms_srv_r=".length,i.length)}}if(t==null){if(Math.random()<e){var o=Math.round((new Date).getTime()/1e3);document.cookie="ms_srv_t="+o+"; path=/";document.cookie="ms_srv_r="+document.referrer+"; path=/";t=o;s=document.referrer}else{document.cookie="ms_srv_t=X; path=/";t="X"}}if(t!="X"&&!!document.getElementById("ms_srv_wrapper")){var u=Math.round((new Date).getTime()/1e3)-t;var a=!!document.getElementById("user-meta");var f=document.getElementById("ms_srv_link");data={ms_time:u,ms_referrer:s||null,ms_registered:a,ms_transaction:f.getAttribute("data-transaction")};var l=[];for(var c in data){l.push(encodeURIComponent(c)+"="+encodeURIComponent(data[c]))}f.href=f.href+"?"+l.join("&");document.getElementById("ms_srv_wrapper").style.display=""}})() +</script> diff --git a/templates/web/fixmystreet.com/report/_extras_top.html b/templates/web/fixmystreet.com/report/_extras_top.html new file mode 100755 index 000000000..4938e8749 --- /dev/null +++ b/templates/web/fixmystreet.com/report/_extras_top.html @@ -0,0 +1,3 @@ +[% IF created_report %] + [% INCLUDE 'research/survey_link.html' %] +[% END %] diff --git a/templates/web/fixmystreet.com/research/survey_link.html b/templates/web/fixmystreet.com/research/survey_link.html new file mode 100644 index 000000000..7357249d8 --- /dev/null +++ b/templates/web/fixmystreet.com/research/survey_link.html @@ -0,0 +1,3 @@ +<div id="ms_srv_wrapper" style="display:none"> + <p><a href="https://www.surveygizmo.co.uk/s3/1907419/FMS-2014" id="ms_srv_link" data-transaction="report">We’re running a short survey to help us understand how well FixMyStreet works. If you’d like to take it, click here.</a></p> +</div> diff --git a/templates/web/fixmystreet.com/tokens/_extras_confirm.html b/templates/web/fixmystreet.com/tokens/_extras_confirm.html new file mode 100644 index 000000000..c27383f42 --- /dev/null +++ b/templates/web/fixmystreet.com/tokens/_extras_confirm.html @@ -0,0 +1 @@ +[% INCLUDE 'research/survey_link.html' %] diff --git a/templates/web/fixmystreet/footer.html b/templates/web/fixmystreet/footer.html index 71e87ddfb..63b04de83 100644 --- a/templates/web/fixmystreet/footer.html +++ b/templates/web/fixmystreet/footer.html @@ -37,5 +37,8 @@ <!-- [% INCLUDE 'debug_footer.html' %] --> </div> <!-- .wrapper --> + + [% TRY %][% PROCESS 'footer_extra.html' %][% CATCH file %][% END %] + </body> </html> diff --git a/templates/web/fixmystreet/report/display.html b/templates/web/fixmystreet/report/display.html index 4f4e7a2a6..314b09b28 100644 --- a/templates/web/fixmystreet/report/display.html +++ b/templates/web/fixmystreet/report/display.html @@ -17,6 +17,8 @@ <p class='form-success'>[% loc('You have successfully signed in; please check and confirm your details are accurate:') %]</p> [% END %] +[% TRY %][% INCLUDE 'report/_extras_top.html' %][% CATCH file %][% END %] + [% INCLUDE 'report/banner.html' %] [% INCLUDE 'report/_main.html' %] @@ -38,9 +40,9 @@ <li><a rel="nofollow" id="key-tool-report-share" class="share" href="#report-share">[% loc('Share') %]</a></li> [% END %] [% IF c.cobrand.moniker == 'zurich' %] - <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => short_latitude, lon => short_longitude } ) %]">[% loc( 'Problems on the map' ) %]</a></li> + <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]">[% loc( 'Problems on the map' ) %]</a></li> [% ELSE %] - <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => short_latitude, lon => short_longitude } ) %]">[% loc( 'Problems nearby' ) %]</a></li> + <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]">[% loc( 'Problems nearby' ) %]</a></li> [% END %] </ul> diff --git a/templates/web/seesomething/around/display_location.html b/templates/web/seesomething/around/display_location.html index ea0a499f7..b54311264 100644 --- a/templates/web/seesomething/around/display_location.html +++ b/templates/web/seesomething/around/display_location.html @@ -4,8 +4,8 @@ '/report/new', { pc => pc - latitude => short_latitude, - longitude => short_longitude, + latitude => latitude, + longitude => longitude, skipped => 1, } ); @@ -25,8 +25,8 @@ [% END %] <input type="hidden" name="pc" value="[% pc | html %]"> - <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% short_latitude | html %]"> - <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% short_longitude | html %]"> + <input type="hidden" name="latitude" id="fixmystreet.latitude" value="[% latitude | html %]"> + <input type="hidden" name="longitude" id="fixmystreet.longitude" value="[% longitude | html %]"> [% map_html %] diff --git a/templates/web/stevenage/header.html b/templates/web/stevenage/header.html index dbcc37866..0b3171808 100644 --- a/templates/web/stevenage/header.html +++ b/templates/web/stevenage/header.html @@ -23,6 +23,7 @@ [% INCLUDE 'common_header_tags.html', js_override = '/cobrands/fixmystreet/fixmystreet.js' %] [% extra_js %] + [% INCLUDE 'tracking_code.html' %] </head> <body class="[% bodyclass | html IF bodyclass %]"> diff --git a/templates/web/stevenage/tracking_code.html b/templates/web/stevenage/tracking_code.html new file mode 100644 index 000000000..e7c2bafd6 --- /dev/null +++ b/templates/web/stevenage/tracking_code.html @@ -0,0 +1,16 @@ +[% IF c.config.BASE_URL == "https://www.fixmystreet.com" %] + +<script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', 'UA-21613820-7', 'auto'); + ga('send', 'pageview'); + +</script> + +[% ELSE %] +<!-- Tracking code not inserted as "[% c.config.BASE_URL %]" not "https://www.fixmystreet.com" --> +[% END %] diff --git a/templates/web/trinidadtobago/header_logo.html b/templates/web/trinidadtobago/header_logo.html new file mode 100644 index 000000000..d5da7e6b2 --- /dev/null +++ b/templates/web/trinidadtobago/header_logo.html @@ -0,0 +1 @@ + <a href="[% c.config.BASE_URL %]/" id="site-logo">[% PROCESS 'site-name.html' -%]</a> diff --git a/templates/web/trinidadtobago/site-name.html b/templates/web/trinidadtobago/site-name.html new file mode 100644 index 000000000..d9c3f19c7 --- /dev/null +++ b/templates/web/trinidadtobago/site-name.html @@ -0,0 +1 @@ +FixMyStreeTT diff --git a/templates/web/zerotb/report/display.html b/templates/web/zerotb/report/display.html index 9161fb586..697b5428c 100644 --- a/templates/web/zerotb/report/display.html +++ b/templates/web/zerotb/report/display.html @@ -25,7 +25,7 @@ <div class="shadow-wrap"> <ul id="key-tools"> - <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => short_latitude, lon => short_longitude } ) %]">[% loc( 'Clinics nearby' ) %]</a></li> + <li><a class="chevron" id="key-tool-problems-nearby" href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]">[% loc( 'Clinics nearby' ) %]</a></li> </ul> </div> diff --git a/web/cobrands/trinidadtobago/base.scss b/web/cobrands/trinidadtobago/base.scss index 9fccf92db..77f91f57d 100644 --- a/web/cobrands/trinidadtobago/base.scss +++ b/web/cobrands/trinidadtobago/base.scss @@ -5,3 +5,29 @@ @import "../sass/base"; +#site-header { + background: #fff; +} + + +#site-logo { + display: block; + width: 175px; + height: 40px; + top: 0.4em; + background: url("/cobrands/trinidadtobago/images/sprite.png") -3px -3px no-repeat; + text-indent: -999999px; + position: absolute; + z-index: 2 +} + +#nav-link { + width: 50px; + height: 48px; + background: url("/cobrands/trinidadtobago/images/sprite.png") -5px -916px no-repeat; + display: block; + text-indent: -999999px; + position: absolute; + right: 2em; + top: -2px +}
\ No newline at end of file diff --git a/web/cobrands/trinidadtobago/fixmystreett.png b/web/cobrands/trinidadtobago/fixmystreett.png Binary files differnew file mode 100644 index 000000000..4d0388f19 --- /dev/null +++ b/web/cobrands/trinidadtobago/fixmystreett.png diff --git a/web/cobrands/trinidadtobago/images/sprite.png b/web/cobrands/trinidadtobago/images/sprite.png Binary files differnew file mode 100644 index 000000000..6094712f1 --- /dev/null +++ b/web/cobrands/trinidadtobago/images/sprite.png diff --git a/web/cobrands/trinidadtobago/layout.scss b/web/cobrands/trinidadtobago/layout.scss index 67cc7307f..43783b58b 100644 --- a/web/cobrands/trinidadtobago/layout.scss +++ b/web/cobrands/trinidadtobago/layout.scss @@ -4,3 +4,15 @@ .big-green-banner { background-color: $trinidad_primary; } + +#site-logo, +body.frontpage #site-logo { + margin-top: -10px; + margin-left: 10px; + height: 100px; + background: url(fixmystreett.png) 0px 0px no-repeat; + background-size: contain; +} +body.frontpage #site-logo { + margin-top: -20px; +}
\ No newline at end of file |