aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App.pm43
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm13
-rwxr-xr-xperllib/FixMyStreet/App/Controller/JS.pm30
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm11
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm71
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm24
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm117
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm55
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm4
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Static.pm7
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/Barnet.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Base.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm35
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm10
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm26
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Reading.pm8
-rw-r--r--perllib/FixMyStreet/Cobrand/Southampton.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm13
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm53
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm25
-rw-r--r--perllib/FixMyStreet/Map.pm4
-rw-r--r--perllib/FixMyStreet/Map/OSM.pm5
-rw-r--r--perllib/FixMyStreet/Map/OSM/MapQuest.pm33
-rw-r--r--perllib/FixMyStreet/TestMech.pm2
34 files changed, 415 insertions, 219 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 21552a066..262379b79 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -11,6 +11,7 @@ use mySociety::EmailUtil;
use mySociety::Random qw(random_bytes);
use FixMyStreet::Map;
+use Path::Class;
use URI;
use URI::QueryParam;
@@ -151,8 +152,7 @@ sub setup_request {
my $cobrand = $c->cobrand;
# append the cobrand templates to the include path
- $c->stash->{additional_template_paths} =
- [ $cobrand->path_to_web_templates->stringify ]
+ $c->stash->{additional_template_paths} = $cobrand->path_to_web_templates
unless $cobrand->is_default;
# work out which language to use
@@ -402,6 +402,45 @@ sub finalize {
delete $c->stash->{cobrand};
}
+=head2 render_fragment
+
+If a page needs to render a template fragment internally (e.g. for an Ajax
+call), use this method.
+
+=cut
+
+sub render_fragment {
+ my ($c, $template, $vars) = @_;
+ $vars->{additional_template_paths} = $c->cobrand->path_to_web_templates
+ if $vars && !$c->cobrand->is_default;
+ $c->view('Web')->render($c, $template, $vars);
+}
+
+=head2 get_photo_params
+
+Returns a hashref of details of any attached photo for use in templates.
+Hashref contains height, width and url keys.
+
+=cut
+
+sub get_photo_params {
+ my ($self, $key) = @_;
+ $key = ($key eq 'id') ? '' : "/$key";
+
+ return {} unless $self->photo;
+
+ my $photo = {};
+ if (length($self->photo) == 40) {
+ $photo->{url_full} = '/photo' . $key . '/' . $self->id . '.full.jpeg';
+ } else {
+ ( $photo->{width}, $photo->{height} ) =
+ Image::Size::imgsize( \$self->photo );
+ }
+ $photo->{url} = '/photo' . $key . '/' . $self->id . '.jpeg';
+
+ return $photo;
+}
+
=head1 SEE ALSO
L<FixMyStreet::App::Controller::Root>, L<Catalyst>
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 0e34ea64b..83f77f401 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -627,10 +627,6 @@ sub report_edit : Path('report_edit') : Args(1) {
$problem->photo(undef);
}
- if ( $new_state ne $old_state ) {
- $problem->lastupdate( \'ms_current_timestamp()' );
- }
-
if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) {
$problem->confirmed( \'ms_current_timestamp()' );
}
@@ -639,6 +635,7 @@ sub report_edit : Path('report_edit') : Args(1) {
$problem->discard_changes;
}
else {
+ $problem->lastupdate( \'ms_current_timestamp()' ) if $edited || $new_state ne $old_state;
$problem->update;
if ( $new_state ne $old_state ) {
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 40dde455e..2698c6ac0 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -505,6 +505,8 @@ sub setup_request : Private {
$c->stash->{rznvy} ||= $c->user->email;
}
+ $c->stash->{template} = 'alert/list-ajax.html' if $c->req->param('ajax');
+
return 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 148a22368..e110cf8d7 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -189,7 +189,7 @@ sub display_location : Private {
{
latitude => $p->latitude,
longitude => $p->longitude,
- colour => $p->is_fixed ? 'green' : 'red',
+ colour => 'yellow', # $p->is_fixed ? 'green' : 'red',
id => $p->id,
title => $p->title,
}
@@ -258,12 +258,11 @@ sub ajax : Path('/ajax') {
FixMyStreet::Map::map_pins( $c, $interval );
# render templates to get the html
- my $on_map_list_html =
- $c->view('Web')
- ->render( $c, 'around/on_map_list_items.html', { on_map => $on_map } );
-
- my $around_map_list_html = $c->view('Web')->render(
- $c,
+ my $on_map_list_html = $c->render_fragment(
+ 'around/on_map_list_items.html',
+ { on_map => $on_map }
+ );
+ my $around_map_list_html = $c->render_fragment(
'around/around_map_list_items.html',
{ around_map => $around_map, dist => $dist }
);
diff --git a/perllib/FixMyStreet/App/Controller/JS.pm b/perllib/FixMyStreet/App/Controller/JS.pm
new file mode 100755
index 000000000..ae2f06605
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/JS.pm
@@ -0,0 +1,30 @@
+package FixMyStreet::App::Controller::JS;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::JS - Catalyst Controller
+
+=head1 DESCRIPTION
+
+JS Catalyst Controller. To return a language-dependent list
+of validation strings.
+
+=head1 METHODS
+
+=cut
+
+sub validation_strings : LocalRegex('^validation_strings\.(.*?)\.js$') : Args(0) {
+ my ( $self, $c ) = @_;
+ my $lang = $c->req->captures->[0];
+ $c->cobrand->set_lang_and_domain( $lang, 1 );
+ $c->res->content_type( 'application/javascript' );
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 60e9dd09f..3de83b265 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -30,9 +30,16 @@ sub my : Path : Args(0) {
my $pins = [];
my $problems = {};
- my $rs = $c->user->problems->search( {
+
+ my $params = {
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
- }, {
+ };
+ $params = {
+ %{ $c->cobrand->problems_clause },
+ %$params
+ } if $c->cobrand->problems_clause;
+
+ my $rs = $c->user->problems->search( $params, {
order_by => { -desc => 'confirmed' },
rows => 50
} )->page( $p_page );
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index fe1494b95..34e2b7cd3 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -283,7 +283,7 @@ sub output_requests : Private {
my $display_photos = $c->cobrand->allow_photo_display;
if ($display_photos && $problem->photo) {
my $url = $c->cobrand->base_url();
- my $imgurl = $url . "/photo?id=$id";
+ my $imgurl = $url . "/photo/$id.full.jpeg";
$request->{'media_url'} = [ $imgurl ];
}
push(@problemlist, $request);
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index b4fa3a457..c54bad238 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
use DateTime::Format::HTTP;
+use Path::Class;
=head1 NAME
@@ -25,17 +26,30 @@ Display a photo
=cut
-sub index :Path :Args(0) {
+sub during :LocalRegex('^([0-9a-f]{40})\.temp\.jpeg$') {
my ( $self, $c ) = @_;
+ my ( $hash ) = @{ $c->req->captures };
- my $id = $c->req->param('id');
- my $comment = $c->req->param('c');
- $c->detach( 'no_photo' ) unless $id || $comment;
+ my $file = file( $c->config->{UPLOAD_DIR}, "$hash.jpeg" );
+ my $photo = $file->slurp;
+
+ if ( $c->cobrand->default_photo_resize ) {
+ $photo = _shrink( $photo, $c->cobrand->default_photo_resize );
+ } else {
+ $photo = _shrink( $photo, '250x250' );
+ }
+
+ $c->forward( 'output', [ $photo ] );
+}
+
+sub index :LocalRegex('^(c/)?(\d+)(?:\.(full|tn|fp))?\.jpeg$') {
+ my ( $self, $c ) = @_;
+ my ( $is_update, $id, $size ) = @{ $c->req->captures };
my @photo;
- if ( $comment ) {
+ if ( $is_update ) {
@photo = $c->model('DB::Comment')->search( {
- id => $comment,
+ id => $id,
state => 'confirmed',
photo => { '!=', undef },
} );
@@ -56,14 +70,31 @@ sub index :Path :Args(0) {
$c->detach( 'no_photo' ) unless @photo;
my $photo = $photo[0]->photo;
- if ( $c->req->param('tn' ) ) {
- $photo = _resize( $photo, 'x100' );
+
+ # If photo field contains a hash
+ if (length($photo) == 40) {
+ my $file = file( $c->config->{UPLOAD_DIR}, "$photo.jpeg" );
+ $photo = $file->slurp;
+ }
+
+ if ( $size eq 'tn' ) {
+ $photo = _shrink( $photo, 'x100' );
+ } elsif ( $size eq 'fp' ) {
+ $photo = _crop( $photo );
+ } elsif ( $size eq 'full' ) {
} elsif ( $c->cobrand->default_photo_resize ) {
- $photo = _resize( $photo, $c->cobrand->default_photo_resize );
+ $photo = _shrink( $photo, $c->cobrand->default_photo_resize );
+ } else {
+ $photo = _shrink( $photo, '250x250' );
}
- my $dt = DateTime->now();
- $dt->set_year( $dt->year + 1 );
+ $c->forward( 'output', [ $photo ] );
+}
+
+sub output : Private {
+ my ( $self, $c, $photo ) = @_;
+
+ my $dt = DateTime->now()->add( years => 1 );
$c->res->content_type( 'image/jpeg' );
$c->res->header( 'expires', DateTime::Format::HTTP->format_datetime( $dt ) );
@@ -75,7 +106,8 @@ sub no_photo : Private {
$c->detach( '/page_error_404_not_found', [ 'No photo' ] );
}
-sub _resize {
+# Shrinks a picture to the specified size, but keeping in proportion.
+sub _shrink {
my ($photo, $size) = @_;
use Image::Magick;
my $image = Image::Magick->new;
@@ -87,6 +119,21 @@ sub _resize {
return $blobs[0];
}
+# Shrinks a picture to 90x60, cropping so that it is exactly that.
+sub _crop {
+ my ($photo) = @_;
+ use Image::Magick;
+ my $image = Image::Magick->new;
+ $image->BlobToImage($photo);
+ my $err = $image->Resize( geometry => "90x60^" );
+ throw Error::Simple("resize failed: $err") if "$err";
+ $err = $image->Extent( geometry => '90x60', gravity => 'Center' );
+ throw Error::Simple("resize failed: $err") if "$err";
+ my @blobs = $image->ImageToBlob();
+ undef $image;
+ return $blobs[0];
+}
+
=head1 AUTHOR
Struan Donald
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index f0cb02115..6ed7ddd9d 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -205,10 +205,7 @@ sub submit_standard : Private {
}
);
if ( my $fileid = $c->stash->{upload_fileid} ) {
- my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" );
- my $blob = $file->slurp;
- $file->remove;
- $update->photo($blob);
+ $update->photo( $fileid );
}
$update->insert;
}
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 166f9d58e..afe180c29 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -51,7 +51,7 @@ sub display : Path('') : Args(1) {
return $c->res->redirect( $c->uri_for($1), 301 );
}
- $c->forward('load_problem_or_display_error', [ $id ] );
+ $c->forward( 'load_problem_or_display_error', [ $id ] );
$c->forward( 'load_updates' );
$c->forward( 'format_problem_for_display' );
}
@@ -88,7 +88,24 @@ sub load_updates : Private {
{ order_by => 'confirmed' }
);
- $c->stash->{updates} = $updates;
+ my $questionnaires = $c->model('DB::Questionnaire')->search(
+ {
+ problem_id => $c->stash->{problem}->id,
+ whenanswered => { '!=', undef },
+ old_state => 'confirmed', new_state => 'confirmed',
+ },
+ { order_by => 'whenanswered' }
+ );
+
+ my @combined;
+ while (my $update = $updates->next) {
+ push @combined, [ $update->confirmed, $update ];
+ }
+ while (my $update = $questionnaires->next) {
+ push @combined, [ $update->whenanswered, $update ];
+ }
+ @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined;
+ $c->stash->{updates} = \@combined;
return 1;
}
@@ -127,7 +144,8 @@ sub generate_map_tags : Private {
? [ {
latitude => $problem->latitude,
longitude => $problem->longitude,
- colour => 'blue',
+ colour => 'yellow',
+ type => 'big',
} ]
: [],
);
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 1e5825460..af4cdd5aa 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Geocode;
+use Digest::SHA1 qw(sha1_hex);
use Encode;
use Image::Magick;
use List::MoreUtils qw(uniq);
@@ -23,7 +24,7 @@ FixMyStreet::App::Controller::Report::New
=head1 DESCRIPTION
-Create a new report, or complete a partial one .
+Create a new report, or complete a partial one.
=head1 PARAMETERS
@@ -47,7 +48,10 @@ back into lat/lng by the map code.
=head2 image related
-Parameters are 'photo' or 'upload_fileid'. The 'photo' is used when a user has selected a file. Once it has been uploaded it is cached on disk so that if there are errors on the form it need not be uploaded again. The cache location is stored in 'upload_fileid'.
+Parameters are 'photo' or 'upload_fileid'. The 'photo' is used when a user has
+selected a file. Once it has been uploaded it is cached on disk so that if
+there are errors on the form it need not be uploaded again. The hash of the
+photo is stored in 'upload_fileid'.
=head2 optional
@@ -105,15 +109,20 @@ sub report_form_ajax : Path('ajax') : Args(0) {
$c->forward('initialize_report');
# work out the location for this report and do some checks
- # XXX We don't want to do this here if this actually happens!
- return $c->forward('redirect_to_around')
- unless $c->forward('determine_location');
+ if ( ! $c->forward('determine_location') ) {
+ my $body = JSON->new->utf8(1)->encode( {
+ error => $c->stash->{location_error},
+ } );
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body($body);
+ return;
+ }
$c->forward('setup_categories_and_councils');
# render templates to get the html
- my $category = $c->view('Web')->render( $c, 'report/new/category.html');
- my $councils_text = $c->view('Web')->render( $c, 'report/new/councils_text.html');
+ my $category = $c->render_fragment( 'report/new/category.html');
+ my $councils_text = $c->render_fragment( 'report/new/councils_text.html');
my $has_open311 = keys %{ $c->stash->{category_extras} };
my $body = JSON->new->utf8(1)->encode(
@@ -150,7 +159,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
$c->stash->{report} = { category => $c->req->param('category') };
$c->stash->{category_extras} = { $c->req->param('category' ) => $c->stash->{category_extras}->{ $c->req->param('category') } };
- $category_extra= $c->view('Web')->render( $c, 'report/new/category_extras.html');
+ $category_extra= $c->render_fragment( 'report/new/category_extras.html');
}
my $body = JSON->new->utf8(1)->encode(
@@ -200,8 +209,8 @@ sub report_import : Path('/import') {
}
# handle the photo upload
- $c->forward( 'process_photo_upload', [ { rotate_photo => 1 } ] );
- my $photo = $c->stash->{upload_fileid};
+ $c->forward( 'process_photo_upload' );
+ my $fileid = $c->stash->{upload_fileid};
if ( my $error = $c->stash->{photo_error} ) {
push @errors, $error;
}
@@ -224,7 +233,7 @@ sub report_import : Path('/import') {
if $@;
}
- unless ( $photo || ( $latitude || $longitude ) ) {
+ unless ( $fileid || ( $latitude || $longitude ) ) {
push @errors, 'Either a location or a photo must be provided.';
}
@@ -292,11 +301,8 @@ sub report_import : Path('/import') {
);
# If there was a photo add that too
- if ( $photo ) {
- my $file = file( $c->config->{UPLOAD_CACHE}, "$photo.jpg" );
- my $blob = $file->slurp;
- $file->remove;
- $report->photo($blob);
+ if ( $fileid ) {
+ $report->photo($fileid);
}
# save the report;
@@ -647,7 +653,7 @@ sub process_user : Private {
# The user is trying to sign in. We only care about email from the params.
if ( $c->req->param('submit_sign_in') || $c->req->param('password_sign_in') ) {
unless ( $c->forward( '/auth/sign_in' ) ) {
- $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. Passwords and user accounts are a brand <strong>new</strong> service, so you probably do not have one yet &ndash; please fill in the right hand side of this form to get one.');
+ $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the &lsquo;sign in by email&rsquo; section of the form.');
return 1;
}
my $user = $c->user->obj;
@@ -825,11 +831,7 @@ sub process_photo : Private {
}
sub process_photo_upload : Private {
- my ( $self, $c, $args ) = @_;
-
- # setup args and set defaults
- $args ||= {};
- $args->{rotate_photo} ||= 0;
+ my ( $self, $c ) = @_;
# check for upload or return
my $upload = $c->req->upload('photo')
@@ -842,9 +844,13 @@ sub process_photo_upload : Private {
return;
}
- # convert the photo into a blob (also resize etc)
- my $photo_blob =
- eval { _process_photo( $upload->fh, $args->{rotate_photo} ) };
+ # get the photo into a variable
+ my $photo_blob = eval {
+ my $filename = $upload->tempname;
+ my $out = `jhead -se -autorot $filename`;
+ my $photo = $upload->slurp;
+ return $photo;
+ };
if ( my $error = $@ ) {
my $format = _(
"That image doesn't appear to have uploaded correctly (%s), please try again."
@@ -853,21 +859,18 @@ sub process_photo_upload : Private {
return;
}
- # we have an image we can use - save it to the cache in case there is an
- # error
- my $cache_dir = dir( $c->config->{UPLOAD_CACHE} );
+ # we have an image we can use - save it to the upload dir for storage
+ my $cache_dir = dir( $c->config->{UPLOAD_DIR} );
$cache_dir->mkpath;
unless ( -d $cache_dir && -w $cache_dir ) {
warn "Can't find/write to photo cache directory '$cache_dir'";
return;
}
- # create a random name and store the file there
- my $fileid = int rand 1_000_000_000;
- my $file = $cache_dir->file("$fileid.jpg");
- $file->openw->print($photo_blob);
+ my $fileid = sha1_hex($photo_blob);
+ $upload->copy_to( file($cache_dir, $fileid . '.jpeg') );
- # stick the random number on the stash
+ # stick the hash on the stash, so don't have to reupload in case of error
$c->stash->{upload_fileid} = $fileid;
return 1;
@@ -883,12 +886,12 @@ does return true and put fileid on stash, otherwise false.
sub process_photo_cache : Private {
my ( $self, $c ) = @_;
- # get the fileid and make sure it is just a number
+ # get the fileid and make sure it is just a hex number
my $fileid = $c->req->param('upload_fileid') || '';
- $fileid =~ s{\D+}{}g;
+ $fileid =~ s{[^0-9a-f]}{}gi;
return unless $fileid;
- my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" );
+ my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" );
return unless -e $file;
$c->stash->{upload_fileid} = $fileid;
@@ -980,10 +983,7 @@ sub save_user_and_report : Private {
# If there was a photo add that too
if ( my $fileid = $c->stash->{upload_fileid} ) {
- my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" );
- my $blob = $file->slurp;
- $file->remove;
- $report->photo($blob);
+ $report->photo($fileid);
}
# Set a default if possible
@@ -1031,7 +1031,7 @@ sub generate_map : Private {
pins => [ {
latitude => $latitude,
longitude => $longitude,
- colour => 'purple',
+ colour => 'green', # 'yellow',
} ],
);
}
@@ -1123,41 +1123,6 @@ sub redirect_to_around : Private {
return $c->res->redirect($around_uri);
}
-sub _process_photo {
- my $fh = shift;
- my $import = shift;
-
- my $blob = join('', <$fh>);
- close $fh;
- my ($handle, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
- print $handle $blob;
- close $handle;
-
- my $photo = Image::Magick->new;
- my $err = $photo->Read($filename);
- unlink $filename;
- throw Error::Simple("read failed: $err") if "$err";
- $err = $photo->Scale(geometry => "250x250>");
- throw Error::Simple("resize failed: $err") if "$err";
- my @blobs = $photo->ImageToBlob();
- undef $photo;
- $photo = $blobs[0];
- return $photo unless $import; # Only check orientation for iPhone imports at present
-
- # Now check if it needs orientating
- ($fh, $filename) = mySociety::TempFiles::named_tempfile('.jpeg');
- print $fh $photo;
- close $fh;
- my $out = `jhead -se -autorot $filename`;
- if ($out) {
- open(FP, $filename) or throw Error::Simple($!);
- $photo = join('', <FP>);
- close FP;
- }
- unlink $filename;
- return $photo;
-}
-
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 29933e2f6..15444f556 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -122,7 +122,7 @@ sub process_user : Private {
# The user is trying to sign in. We only care about email from the params.
if ( $c->req->param('submit_sign_in') || $c->req->param('password_sign_in') ) {
unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) {
- $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. Passwords and user accounts are a brand <strong>new</strong> service, so you probably do not have one yet &ndash; please fill in the right hand side of this form to get one.');
+ $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the &lsquo;sign in by email&rsquo; section of the form.');
return 1;
}
my $user = $c->user->obj;
@@ -282,10 +282,7 @@ sub save_update : Private {
# If there was a photo add that too
if ( my $fileid = $c->stash->{upload_fileid} ) {
- my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" );
- my $blob = $file->slurp;
- $file->remove;
- $update->photo($blob);
+ $update->photo($fileid);
}
if ( $update->in_storage ) {
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 68dbd6359..9fb72121e 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -102,7 +102,6 @@ sub ward : Path : Args(2) {
$c->forward( 'load_parent' );
$c->forward( 'check_canonical_url', [ $council ] );
$c->forward( 'load_and_group_problems' );
- $c->forward( 'sort_problems' );
my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} );
$c->stash->{rss_url} = '/rss/reports/' . $council_short;
@@ -342,8 +341,12 @@ sub load_and_group_problems : Private {
{
columns => [
'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand',
- { duration => { extract => "epoch from current_timestamp-lastupdate" } },
- { age => { extract => "epoch from current_timestamp-confirmed" } },
+ #{ duration => { extract => "epoch from current_timestamp-lastupdate" } },
+ #{ age => { extract => "epoch from current_timestamp-confirmed" } },
+ { confirmed => { extract => 'epoch from confirmed' } },
+ { whensent => { extract => 'epoch from whensent' } },
+ { lastupdate => { extract => 'epoch from lastupdate' } },
+ { photo => 'photo is not null' },
],
order_by => { -desc => 'lastupdate' },
rows => 100,
@@ -352,17 +355,18 @@ sub load_and_group_problems : Private {
$c->stash->{pager} = $problems->pager;
$problems = $problems->cursor; # Raw DB cursor for speed
- my ( %fixed, %open, @pins );
+ my ( %problems, @pins );
my $re_councils = join('|', keys %{$c->stash->{areas_info}});
- my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age' );
+ my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' );
while ( my @problem = $problems->next ) {
my %problem = zip @cols, @problem;
+ $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}};
$c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker );
if ( !$problem{council} ) {
# Problem was not sent to any council, add to possible councils
$problem{councils} = 0;
while ($problem{areas} =~ /,($re_councils)(?=,)/g) {
- add_row( \%problem, $1, \%fixed, \%open, \@pins );
+ add_row( \%problem, $1, \%problems, \@pins );
}
} else {
# Add to councils it was sent to
@@ -371,37 +375,19 @@ sub load_and_group_problems : Private {
$problem{councils} = scalar @council;
foreach ( @council ) {
next if $c->stash->{council} && $_ != $c->stash->{council}->{id};
- add_row( \%problem, $_, \%fixed, \%open, \@pins );
+ add_row( \%problem, $_, \%problems, \@pins );
}
}
}
$c->stash(
- fixed => \%fixed,
- open => \%open,
+ problems => \%problems,
pins => \@pins,
);
return 1;
}
-sub sort_problems : Private {
- my ( $self, $c ) = @_;
-
- my $id = $c->stash->{council}->{id};
- my $fixed = $c->stash->{fixed};
- my $open = $c->stash->{open};
-
- foreach (qw/new old/) {
- $c->stash->{fixed}{$id}{$_} = [ sort { $a->{duration} <=> $b->{duration} } @{$fixed->{$id}{$_}} ]
- if $fixed->{$id}{$_};
- }
- foreach (qw/new older unknown/) {
- $c->stash->{open}{$id}{$_} = [ sort { $a->{age} <=> $b->{age} } @{$open->{$id}{$_}} ]
- if $open->{$id}{$_};
- }
-}
-
sub redirect_index : Private {
my ( $self, $c ) = @_;
my $url = '/reports';
@@ -419,24 +405,13 @@ sub redirect_area : Private {
$c->res->redirect( $c->uri_for($url) );
}
-my $fourweeks = 4*7*24*60*60;
sub add_row {
- my ( $problem, $council, $fixed, $open, $pins ) = @_;
- my $duration_str = ( $problem->{duration} > 2 * $fourweeks ) ? 'old' : 'new';
- my $type = ( $problem->{duration} > 2 * $fourweeks )
- ? 'unknown'
- : ($problem->{age} > $fourweeks ? 'older' : 'new');
- # Fixed problems are either old or new
- push @{$fixed->{$council}{$duration_str}}, $problem if
- exists FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}};
- # Open problems are either unknown, older, or new
- push @{$open->{$council}{$type}}, $problem if
- exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}};
-
+ my ( $problem, $council, $problems, $pins ) = @_;
+ push @{$problems->{$council}}, $problem;
push @$pins, {
latitude => $problem->{latitude},
longitude => $problem->{longitude},
- colour => FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red',
+ colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red',
id => $problem->{id},
title => $problem->{title},
};
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index 822780b81..4d0b6cb93 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -267,8 +267,8 @@ sub add_row : Private {
$item{category} = $row->{category} if $row->{category};
if ($c->cobrand->allow_photo_display && $row->{photo}) {
- my $key = $alert_type->item_table eq 'comment' ? 'c' : 'id';
- $item{description} .= ent("\n<br><img src=\"". $c->cobrand->base_url . "/photo?$key=$row->{id}\">");
+ my $key = $alert_type->item_table eq 'comment' ? 'c/' : '';
+ $item{description} .= ent("\n<br><img src=\"". $c->cobrand->base_url . "/photo/$key$row->{id}.jpeg\">");
}
if ( $row->{used_map} ) {
diff --git a/perllib/FixMyStreet/App/Controller/Static.pm b/perllib/FixMyStreet/App/Controller/Static.pm
index 2e6bda28c..52b230c27 100755
--- a/perllib/FixMyStreet/App/Controller/Static.pm
+++ b/perllib/FixMyStreet/App/Controller/Static.pm
@@ -22,6 +22,13 @@ sub about : Global : Args(0) {
# don't need to do anything here - should just pass through.
}
+sub for_councils : Path('/for-councils') : Args(0) {
+ my ( $self, $c ) = @_;
+}
+sub for_councils_faq : Path('/for-councils/faq') : Args(0) {
+ my ( $self, $c ) = @_;
+}
+
sub faq : Global : Args(0) {
my ( $self, $c ) = @_;
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 755f1e405..092e362f9 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -75,6 +75,7 @@ sprintf (different name to avoid clash)
sub tprintf {
my ( $self, $c, $format, @args ) = @_;
+ @args = @{$args[0]} if ref $args[0] eq 'ARRAY';
return sprintf $format, @args;
}
diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm
index 9791b071a..6f115ec63 100644
--- a/perllib/FixMyStreet/Cobrand/Barnet.pm
+++ b/perllib/FixMyStreet/Cobrand/Barnet.pm
@@ -10,7 +10,9 @@ sub council_name { return 'Barnet Council'; }
sub council_url { return 'barnet'; }
sub disambiguate_location {
+ my $self = shift;
return {
+ %{ $self->SUPER::disambiguate_location() },
centre => '51.612832,-0.218169',
span => '0.0563,0.09',
bounds => [ '51.584682,-0.263169', '51.640982,-0.173169' ],
diff --git a/perllib/FixMyStreet/Cobrand/Base.pm b/perllib/FixMyStreet/Cobrand/Base.pm
index 42a891cb4..fada33b78 100644
--- a/perllib/FixMyStreet/Cobrand/Base.pm
+++ b/perllib/FixMyStreet/Cobrand/Base.pm
@@ -62,7 +62,7 @@ Returns the path to the templates for this cobrand - by default
sub path_to_web_templates {
my $self = shift;
- return FixMyStreet->path_to( 'templates/web', $self->moniker );
+ return [ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify ];
}
1;
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
new file mode 100644
index 000000000..75174b638
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -0,0 +1,35 @@
+package FixMyStreet::Cobrand::Bromley;
+use base 'FixMyStreet::Cobrand::UKCouncils';
+
+use strict;
+use warnings;
+
+sub council_id { return 2482; }
+sub council_area { return 'Bromley'; }
+sub council_name { return 'Bromley Council'; }
+sub council_url { return 'bromley'; }
+
+sub path_to_web_templates {
+ my $self = shift;
+ return [
+ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify,
+ FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify
+ ];
+}
+
+sub disambiguate_location {
+ my $self = shift;
+ return {
+ %{ $self->SUPER::disambiguate_location() },
+ centre => '51.366836,0.040623',
+ span => '0.154963,0.24347',
+ bounds => [ '51.289355,-0.081112', '51.444318,0.162358' ],
+ };
+}
+
+sub example_places {
+ return ( 'BR1 3UH', 'Glebe Rd, Bromley' );
+}
+
+1;
+
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 6af538657..47038f25c 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -239,6 +239,8 @@ Returns disambiguating information available
sub disambiguate_location {
return {
country => 'uk',
+ bing_culture => 'en-GB',
+ bing_country => 'United Kingdom'
};
}
@@ -457,7 +459,7 @@ sub find_closest {
my ( $self, $latitude, $longitude, $problem ) = @_;
my $str = '';
- if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude ) ) {
+ if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture} ) ) {
# cache the bing results for use in alerts
if ( $problem ) {
$problem->geocode( $j );
@@ -504,7 +506,7 @@ sub find_closest_address_for_rss {
# if we've not cached it then we don't want to look it up in order to avoid
# hammering the bing api
# if ( !$j ) {
- # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 );
+ # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, disambiguate_location()->{bing_culture}, 1 );
# $problem->geocode( $j );
# $problem->update;
@@ -916,5 +918,9 @@ sub get_report_stats { return 0; }
sub get_council_sender { return 'Email' };
+sub example_places {
+ return [ 'B2 4QA', 'Tib St, Manchester' ];
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 9958e6215..80d57400d 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -19,5 +19,31 @@ sub get_council_sender {
return 'Email';
}
+sub generate_problem_banner {
+ my ( $self, $problem ) = @_;
+
+ my $banner = {};
+ if ( $problem->is_open && time() - $problem->lastupdate_local->epoch > 8 * 7 * 24 * 60 * 60 )
+ {
+ $banner->{id} = 'unknown';
+ $banner->{text} = _('Unknown');
+ }
+ if ($problem->is_fixed) {
+ $banner->{id} = 'fixed';
+ $banner->{text} = _('Fixed');
+ }
+ if ($problem->is_closed) {
+ $banner->{id} = 'closed';
+ $banner->{text} = _('Closed');
+ }
+
+ if ( grep { $problem->state eq $_ } ( 'investigating', 'in progress', 'planned' ) ) {
+ $banner->{id} = 'progress';
+ $banner->{text} = _('In progress');
+ }
+
+ return $banner;
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index 91c5e10ec..4d93aaf76 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -21,7 +21,9 @@ sub problems_clause {
# FIXME - need to double check this is all correct
sub disambiguate_location {
+ my $self = shift;
return {
+ %{ $self->SUPER::disambiguate_location() },
centre => '52.688198,-1.804966',
span => '0.1196,0.218675',
bounds => [ '52.807793,-1.586291', '52.584891,-1.963232' ],
diff --git a/perllib/FixMyStreet/Cobrand/Reading.pm b/perllib/FixMyStreet/Cobrand/Reading.pm
index afc2b6ac6..c8591924e 100644
--- a/perllib/FixMyStreet/Cobrand/Reading.pm
+++ b/perllib/FixMyStreet/Cobrand/Reading.pm
@@ -12,11 +12,13 @@ sub council_name { return 'Reading City Council'; }
sub council_url { return 'reading'; }
sub disambiguate_location {
+ my $self = shift;
return {
+ %{ $self->SUPER::disambiguate_location() },
town => 'Reading',
- centre => '51.452983169803964,-0.98382678731985973',
- span => '0.0833543573028663,0.124500468843446',
- bounds => [ '51.409779668156361,-1.0529948144525243', '51.493134025459227,-0.92849434560907829' ],
+ centre => '51.452983,-0.983827',
+ span => '0.083355,0.1245',
+ bounds => [ '51.409779,-1.052994', '51.493134,-0.928494' ],
};
}
diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm
index 5bb7df3b6..b57091bef 100644
--- a/perllib/FixMyStreet/Cobrand/Southampton.pm
+++ b/perllib/FixMyStreet/Cobrand/Southampton.pm
@@ -10,7 +10,9 @@ sub council_name { return 'Southampton City Council'; }
sub council_url { return 'southampton'; }
sub disambiguate_location {
+ my $self = shift;
return {
+ %{ $self->SUPER::disambiguate_location() },
town => 'Southampton',
centre => '50.913822,-1.400493',
span => '0.084628,0.15701',
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index 589abd178..b40f13d9d 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -1,5 +1,5 @@
package FixMyStreet::Cobrand::UKCouncils;
-use base 'FixMyStreet::Cobrand::FixMyStreet';
+use base 'FixMyStreet::Cobrand::Default';
use strict;
use warnings;
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 958194eb8..195fe4019 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -132,21 +132,12 @@ sub confirm {
=head2 get_photo_params
Returns a hashref of details of any attached photo for use in templates.
-Hashref contains height, width and url keys.
=cut
sub get_photo_params {
my $self = shift;
-
- return {} unless $self->photo;
-
- my $photo = {};
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$self->photo );
- $photo->{url} = '/photo?c=' . $self->id;
-
- return $photo;
+ return FixMyStreet::App::get_photo_params($self, 'c');
}
=head2 meta_problem_state
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 7ceabf1da..ce7488703 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -329,7 +329,7 @@ sub check_for_errors {
|| $self->name =~ m/\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i )
{
$errors{name} = _(
-'Please enter your full name, councils need this information - if you do not wish your name to be shown on the site, untick the box'
+'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below'
);
}
@@ -400,21 +400,12 @@ sub url {
=head2 get_photo_params
Returns a hashref of details of any attached photo for use in templates.
-Hashref contains height, width and url keys.
=cut
sub get_photo_params {
my $self = shift;
-
- return {} unless $self->photo;
-
- my $photo = {};
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$self->photo );
- $photo->{url} = '/photo?id=' . $self->id;
-
- return $photo;
+ return FixMyStreet::App::get_photo_params($self, 'id');
}
=head2 is_open
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 04089096e..83fc85a88 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -24,7 +24,7 @@ sub nearby {
columns => [
'problem.id', 'problem.title', 'problem.latitude',
'problem.longitude', 'distance', 'problem.state',
- 'problem.confirmed'
+ 'problem.confirmed', { 'problem.photo' => 'problem.photo is not null' },
],
bind => [ $mid_lat, $mid_lon, $dist ],
order_by => [ 'distance', { -desc => 'created' } ],
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 17282a656..0b49a4557 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -72,39 +72,36 @@ sub recent_new {
sub recent {
my ( $rs ) = @_;
- my $key = "recent:$site_key";
- my $result = Memcached::get($key);
- if ( $result ) {
- # Need to reattach schema so that confirmed column gets reinflated.
- $result->[0]->result_source->schema( $rs->result_source->schema ) if $result->[0];
- } else {
- $result = [ $rs->search( {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
- }, {
- columns => [ 'id', 'title', 'confirmed' ],
- order_by => { -desc => 'confirmed' },
- rows => 5,
- } )->all ];
- Memcached::set($key, $result, 3600);
- }
- return $result;
+ return _recent( $rs, 5 );
}
sub recent_photos {
my ( $rs, $num, $lat, $lon, $dist ) = @_;
- my $probs;
+ return _recent( $rs, $num, $lat, $lon, $dist, 1);
+}
+
+sub _recent {
+ my ( $rs, $num, $lat, $lon, $dist, $photos ) = @_;
+
+ my $key = $photos ? 'recent_photos' : 'recent';
+ $key .= ":$site_key:$num";
+
my $query = {
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
- photo => { '!=', undef },
};
+ $query->{photo} = { '!=', undef } if $photos;
+
my $attrs = {
- columns => [ 'id', 'title' ],
+ columns => [ 'id', 'title', 'confirmed' ],
order_by => { -desc => 'confirmed' },
rows => $num,
};
+
+ my $probs;
+ my $new = 0;
if (defined $lat) {
my $dist2 = $dist; # Create a copy of the variable to stop it being stringified into a locale in the next line!
- my $key = "recent_photos:$site_key:$num:$lat:$lon:$dist2";
+ $key .= ":$lat:$lon:$dist2";
$probs = Memcached::get($key);
unless ($probs) {
$attrs->{bind} = [ $lat, $lon, $dist ];
@@ -112,16 +109,23 @@ sub recent_photos {
$probs = [ mySociety::Locale::in_gb_locale {
$rs->search( $query, $attrs )->all;
} ];
- Memcached::set($key, $probs, 3600);
+ $new = 1;
}
} else {
- my $key = "recent_photos:$site_key:$num";
$probs = Memcached::get($key);
unless ($probs) {
$probs = [ $rs->search( $query, $attrs )->all ];
- Memcached::set($key, $probs, 3600);
+ $new = 1;
}
}
+
+ if ( $new ) {
+ Memcached::set($key, $probs, 3600);
+ } else {
+ # Need to reattach schema so that confirmed column gets reinflated.
+ $probs->[0]->result_source->schema( $rs->result_source->schema ) if $probs->[0];
+ }
+
return $probs;
}
@@ -132,7 +136,8 @@ sub around_map {
my $attr = {
order_by => { -desc => 'created' },
columns => [
- 'id', 'title' ,'latitude', 'longitude', 'state', 'confirmed'
+ 'id', 'title', 'latitude', 'longitude', 'state', 'confirmed',
+ { photo => 'photo is not null' },
],
};
$attr->{rows} = $limit if $limit;
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index 856d7061e..4ba00dbfe 100644
--- a/perllib/FixMyStreet/Geocode/Bing.pm
+++ b/perllib/FixMyStreet/Geocode/Bing.pm
@@ -23,10 +23,11 @@ use Digest::MD5 qw(md5_hex);
sub string {
my ( $s, $c, $params ) = @_;
$s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i;
- my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s&c=en-GB"; # FIXME nb-NO for Norway
- $url .= '&mapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1]
+ my $url = "http://dev.virtualearth.net/REST/v1/Locations?q=$s";
+ $url .= '&userMapView=' . $params->{bounds}[0] . ',' . $params->{bounds}[1]
if $params->{bounds};
$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);
@@ -43,7 +44,7 @@ sub string {
if (!$js) {
return { error => _('Sorry, we could not parse that location. Please try again.') };
- } elsif ($js =~ /BT\d/) {
+ } elsif ($js =~ /BT\d/ && $params->{bing_country} eq 'United Kingdom') {
return { error => _("We do not currently cover Northern Ireland, I'm afraid.") };
}
@@ -54,24 +55,36 @@ sub string {
my $results = $js->{resourceSets}->[0]->{resources};
my ( $error, @valid_locations, $latitude, $longitude );
+
foreach (@$results) {
my $address = $_->{name};
- next unless $_->{address}->{countryRegion} eq 'United Kingdom'; # FIXME This is UK only
+ next unless $_->{address}->{countryRegion} eq $params->{bing_country};
+
+ # Getting duplicate, yet different, results from Bing sometimes
+ next if @valid_locations
+ && $_->{address}{postalCode} && $valid_locations[-1]{address}{postalCode} eq $_->{address}{postalCode}
+ && ( $valid_locations[-1]{address}{locality} eq $_->{address}{adminDistrict2}
+ || $valid_locations[-1]{address}{adminDistrict2} eq $_->{address}{locality}
+ || $valid_locations[-1]{address}{locality} eq $_->{address}{locality}
+ );
+
( $latitude, $longitude ) = @{ $_->{point}->{coordinates} };
push (@$error, { address => $address, latitude => $latitude, longitude => $longitude });
push (@valid_locations, $_);
}
+
return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1;
return { error => $error };
}
sub reverse {
- my ( $latitude, $longitude, $cache ) = @_;
+ my ( $latitude, $longitude, $bing_culture, $cache ) = @_;
# 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?c=en-GB&key=$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/';
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index 2bccf1584..08bba3285 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -95,8 +95,10 @@ sub _map_features {
my $around_limit = $c->cobrand->on_map_list_limit || undef;
my @around_args = ( $min_lat, $max_lat, $min_lon, $max_lon, $interval );
- my $around_map_list = $c->cobrand->problems->around_map( @around_args, $around_limit );
my $around_map = $c->cobrand->problems->around_map( @around_args, undef );
+ my $around_map_list = $around_limit
+ ? $c->cobrand->problems->around_map( @around_args, $around_limit )
+ : $around_map;
my $dist;
mySociety::Locale::in_gb_locale {
diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm
index be185c35c..8ca5949d8 100644
--- a/perllib/FixMyStreet/Map/OSM.pm
+++ b/perllib/FixMyStreet/Map/OSM.pm
@@ -116,7 +116,10 @@ sub map_pins {
# id => $p->id,
# title => $p->title,
#}
- [ $p->latitude, $p->longitude, $p->is_fixed ? 'green' : 'red', $p->id, $p->title ]
+ [ $p->latitude, $p->longitude,
+ 'yellow', # $p->is_fixed ? 'green' : 'red',
+ $p->id, $p->title
+ ]
} @$around_map, @$nearby;
return (\@pins, $around_map_list, $nearby, $dist);
diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm
new file mode 100644
index 000000000..9cf6de01f
--- /dev/null
+++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map::OSM::CycleMap
+# OSM CycleMap maps on FixMyStreet.
+#
+# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map::OSM::MapQuest;
+use base 'FixMyStreet::Map::OSM';
+
+use strict;
+
+sub map_type {
+ return 'OpenLayers.Layer.OSM.MapQuestOpen';
+}
+
+sub map_tiles {
+ my ($self, $x, $y, $z) = @_;
+ my $tile_url = $self->base_tile_url();
+ return [
+ "http://otile1.$tile_url/$z/" . ($x - 1) . "/" . ($y - 1) . ".png",
+ "http://otile2.$tile_url/$z/$x/" . ($y - 1) . ".png",
+ "http://otile3.$tile_url/$z/" . ($x - 1) . "/$y.png",
+ "http://otile4.$tile_url/$z/$x/$y.png",
+ ];
+}
+
+sub base_tile_url {
+ return 'mqcdn.com/tiles/1.0.0/osm/';
+}
+
+1;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 185b59daa..a8cbc98f2 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -224,6 +224,7 @@ sub form_errors {
my $mech = shift;
my $result = scraper {
process 'div.form-error', 'errors[]', 'TEXT';
+ process 'p.form-error', 'errors[]', 'TEXT';
}
->scrape( $mech->response );
return $result->{errors} || [];
@@ -365,6 +366,7 @@ sub extract_problem_banner {
my $result = scraper {
process 'div#side > p.banner', id => '@id', text => 'TEXT';
+ process 'div.banner > p', id => '@id', text => 'TEXT';
}
->scrape( $mech->response );