diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 37 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 39 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 41 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 83 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/FakeQ.pm | 60 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 1 |
12 files changed, 155 insertions, 152 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index ec7ec3ff0..09a8609fe 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -11,7 +11,6 @@ use mySociety::Email; use mySociety::EmailUtil; use mySociety::Random qw(random_bytes); use FixMyStreet::Map; -use FixMyStreet::FakeQ; use URI; use URI::QueryParam; @@ -133,11 +132,6 @@ sub _get_cobrand { my $cobrand = $cobrand_class->new( { request => $c->req } ); - # create the cobrand explicitly passing in the site. Avoids the chicken and - # egg situation where one needs to be created first. Should disappear when - # all instances of the old '$q' are gone. - $cobrand->fake_q( $c->fake_q( { site => $cobrand->moniker } ) ); - return $cobrand; } @@ -390,37 +384,6 @@ sub uri_for_email { return URI->new($email_uri); } -=head2 fake_q - - $q = $c->fake_q(); # normal usage - $q = $c->fake_q( { site => 'cobrand_moniker' } ); # when creating - -Returns a faked up object that behaves as the old code expects the old '$q' to -behave. Object is cached for the request. See L<FixMyStreet::FakeQ> for more -details. - -The first time fake_q is called you need to pass in 'site' explicitly. This -should normally be done automatically when the cobrand is first loaded. - -=cut - -sub fake_q { - my $c = shift; - my $args = shift; - - return $c->stash->{fakeq} # - ||= $c->_get_fake_q($args); -} - -sub _get_fake_q { - my $c = shift; - my $args = shift || {}; - - $args->{params} ||= $c->req->parameters; - - return FixMyStreet::FakeQ->new($args); -} - =head1 SEE ALSO L<FixMyStreet::App::Controller::Root>, L<Catalyst> diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 3e71cb0bd..c14b7e9b1 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Geocode; use Encode; +use Image::Magick; use Sort::Key qw(keysort); use List::MoreUtils qw(uniq); use HTML::Entities; @@ -13,6 +14,7 @@ use mySociety::MaPit; use Path::Class; use Utils; use mySociety::EmailUtil; +use mySociety::TempFiles; =head1 NAME @@ -737,7 +739,7 @@ sub process_photo_upload : Private { # convert the photo into a blob (also resize etc) my $photo_blob = - eval { Page::process_photo( $upload->fh, $args->{rotate_photo} ) }; + eval { _process_photo( $upload->fh, $args->{rotate_photo} ) }; if ( my $error = $@ ) { my $format = _( "That image doesn't appear to have uploaded correctly (%s), please try again." @@ -987,6 +989,41 @@ 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/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index b5f6e341d..5b20e286b 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -8,6 +8,7 @@ use mySociety::Locale; use mySociety::Web qw(ent); use FixMyStreet; use CrossSell; +use Utils; __PACKAGE__->config( TEMPLATE_EXTENSION => '.html', @@ -91,7 +92,7 @@ sub display_crosssell_advert { return CrossSell::display_advert( $q, $email, $name, %data ); } -=head2 Page::prettify_epoch +=head2 Utils::prettify_epoch [% pretty = prettify_epoch( $epoch, $short_bool ) %] @@ -104,7 +105,7 @@ Return a pretty version of the epoch. sub prettify_epoch { my ( $self, $c, $epoch, $short_bool ) = @_; - return Page::prettify_epoch( $epoch, $short_bool ); + return Utils::prettify_epoch( $epoch, $short_bool ); } =head2 add_links diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 26c7c0453..f68d61256 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -28,12 +28,11 @@ sub site_title { sub enter_postcode_text { my ($self) = @_; - return 'Enter a Barnet postcode, or street name and area:'; + return 'Enter a Barnet postcode, or street name and area'; } sub council_check { my ( $self, $params, $context ) = @_; - my $q = $self->request; my $councils; if ( $params->{all_councils} ) { @@ -53,8 +52,8 @@ sub council_check { } my $url = 'http://www.fixmystreet.com/'; $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape( $q->param('pc') ) - if $q->param('pc'); + $url .= '?pc=' . URI::Escape::uri_escape( $self->{request}->param('pc') ) + if $self->{request}->param('pc'); my $error_msg = "That location is not covered by Barnet. Please visit <a href=\"$url\">the main FixMyStreet site</a>."; return ( 0, $error_msg ); diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index a2d1bc0bb..e02b208dc 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -11,7 +11,7 @@ use mySociety::MaPit; =head2 new my $cobrand = $class->new; - my $cobrand = $class->new( { request => $c->req, fake_q => $c->fake_q } ); + my $cobrand = $class->new( { request => $c->req } ); Create a new cobrand object, optionally setting the web request. @@ -55,27 +55,6 @@ sub is_default { return $self->moniker eq 'default'; } -=head2 fake_q - - $fake_q = $cobrand->fake_q; - $new_fake_q = $cobrand->fake_q($new_fake_q); - -Often the cobrand needs access to the request so we add it at the start by -passing it to ->new. If the request has not been set and you call this (or a -method that needs it) then it croaks. This is probably because you are trying to -use a request-related method out of a request-context. - -=cut - -sub fake_q { - my $self = shift; - $self->{fake_q} = shift if @_; - - return $self->{fake_q} - || croak "No fake_q has been set" - . " - should you be calling this method outside of a web request?"; -} - =head2 path_to_web_templates $path = $cobrand->path_to_web_templates( ); diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index a5b71e46b..4dd2ef49a 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -62,37 +62,36 @@ sub geocoded_string_check { } sub remove_redundant_councils { - my $self = shift; - my $all_councils = shift; + my $self = shift; + my $all_councils = shift; - # Oslo is both a kommune and a fylke, we only want to show it once - delete $all_councils->{301} # - if $all_councils->{3}; + # Oslo is both a kommune and a fylke, we only want to show it once + delete $all_councils->{301} # + if $all_councils->{3}; } sub filter_all_council_ids_list { - my $self = shift; - my @all_councils_ids = @_; + my $self = shift; + my @all_councils_ids = @_; - # as above we only want to show Oslo once - return grep { $_ != 301 } @all_councils_ids; + # as above we only want to show Oslo once + return grep { $_ != 301 } @all_councils_ids; } sub short_name { - my $self = shift; - my ($area, $info) = @_; - - if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) { - my $parent = $info->{$area->{parent_area}}->{name}; - return URI::Escape::uri_escape_utf8("$area->{name}, $parent"); - } + my $self = shift; + my ($area, $info) = @_; - my $name = $area->{name}; - $name =~ s/ & / and /; - $name = URI::Escape::uri_escape_utf8($name); - $name =~ s/%20/+/g; - return $name; + if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) { + my $parent = $info->{$area->{parent_area}}->{name}; + return URI::Escape::uri_escape_utf8("$area->{name}, $parent"); + } + my $name = $area->{name}; + $name =~ s/ & / and /; + $name = URI::Escape::uri_escape_utf8($name); + $name =~ s/%20/+/g; + return $name; } sub council_rss_alert_options { diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm new file mode 100644 index 000000000..aa9945c00 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -0,0 +1,83 @@ +package FixMyStreet::Cobrand::Southampton; +use base 'FixMyStreet::Cobrand::Default'; + +use strict; +use warnings; + +use Carp; +use URI::Escape; +use mySociety::VotingArea; + +sub site_restriction { + return ( "and council='2567'", 'southampton', { council => '2567' } ); +} + +sub base_url { + my $base_url = mySociety::Config::get('BASE_URL'); + if ($base_url !~ /southampton/) { + $base_url =~ s{http://(?!www\.)}{http://southampton.}g; + $base_url =~ s{http://www\.}{http://southampton.}g; + } + return $base_url; +} + +sub site_title { + my ( $self ) = @_; + return 'Southampton City Council FixMyStreet'; +} + +sub enter_postcode_text { + my ( $self ) = @_; + return 'Enter a Southampton postcode, or street name and area'; +} + +sub council_check { + my ( $self, $params, $context ) = @_; + + my $councils; + if ($params->{all_councils}) { + $councils = $params->{all_councils}; + } elsif (defined $params->{lat}) { + my $parent_types = $mySociety::VotingArea::council_parent_types; + $councils = mySociety::MaPit::call( + 'point', + "4326/$params->{lon},$params->{lat}", + type => $parent_types + ); + } + my $council_match = defined $councils->{2567}; + if ($council_match) { + return 1; + } + my $url = 'http://www.fixmystreet.com/'; + $url .= 'alert' if $context eq 'alert'; + $url .= '?pc=' . URI::Escape::uri_escape_utf8($self->{request}->param('pc')) + if $self->{request}->param('pc'); + my $error_msg = "That location is not covered by Southampton. +Please visit <a href=\"$url\">the main FixMyStreet site</a>."; + return ( 0, $error_msg ); +} + +# All reports page only has the one council. +sub all_councils_report { + return 0; +} + +sub disambiguate_location { + my ( $self, $s ) = @_; + $s = "ll=50.913822,-1.400493&spn=0.084628,0.15701&$s"; + return $s; +} + +sub recent_photos { + my ($self, $num, $lat, $lon, $dist) = @_; + $num = 2 if $num == 3; + return Problems::recent_photos( $num, $lat, $lon, $dist ); +} + +sub tilma_mid_point { + return 189; +} + +1; + diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 40801306b..68175dead 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -72,6 +72,7 @@ __PACKAGE__->belongs_to( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:71bSUgPf3uW607g2EGl/Vw use DateTime::TimeZone; +use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index c3b387710..f496fb062 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -104,8 +104,10 @@ __PACKAGE__->has_many( # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U3aYCRwE4etekKaHdhEkIw use DateTime::TimeZone; +use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; +use Utils; with 'FixMyStreet::Roles::Abuser'; @@ -278,7 +280,7 @@ sub meta_line { my ( $problem, $c ) = @_; my $date_time = - Page::prettify_epoch( $problem->confirmed_local->epoch ); + Utils::prettify_epoch( $problem->confirmed_local->epoch ); my $meta = ''; # FIXME Should be in cobrand @@ -359,7 +361,7 @@ sub duration_string { $body = join(' and ', map { $areas_info->{$_}->{name} } @councils); } return sprintf(_('Sent to %s %s later'), $body, - Page::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') + Utils::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') ); } diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index ab3acc388..ee15f8308 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -4,7 +4,7 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; use File::Slurp; -use Page; +use Utils; use mySociety::EmailUtil; sub send_questionnaires { @@ -63,7 +63,7 @@ sub send_questionnaires_period { } my %h = map { $_ => $row->$_ } qw/name title detail category/; - $h{created} = Page::prettify_duration( time() - $row->confirmed->epoch, 'week' ); + $h{created} = Utils::prettify_duration( time() - $row->confirmed->epoch, 'week' ); my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->create( { problem_id => $row->id, diff --git a/perllib/FixMyStreet/FakeQ.pm b/perllib/FixMyStreet/FakeQ.pm deleted file mode 100644 index 19f5ab32b..000000000 --- a/perllib/FixMyStreet/FakeQ.pm +++ /dev/null @@ -1,60 +0,0 @@ -package FixMyStreet::FakeQ; - -use strict; -use warnings; -use Carp; - -=head1 NAME - -FixMyStreet::FakeQ - adaptor object to ease code transition - -=head1 DESCRIPTION - -The old code uses '$q' everywhere - partly to passaround which cobrand is in -use, partly to give access to the request query parameters and partly as a -scratch pad. - -This object lets us fake this behaviour in a structured way so that the new -Catalyst based code can call the old CGI code with no need for changes. - -Eventually it will be phased out. - -=head1 METHODS - -=head2 new - - $fake_q = FixMyStreet::FakeQ->new( $args ); - -Create a new FakeQ object. Checks that 'site' argument is present and corrects -it if needed. - -=cut - -sub new { - my $class = shift; - my $args = shift || {}; - - croak "required argument 'site' missing" unless $args->{site}; - $args->{site} = 'fixmystreet' if $args->{site} eq 'default'; - - $args->{params} ||= {}; - - return bless $args, $class; -} - -=head2 param - - $val = $fake_q->param( 'key' ); - -Behaves much like CGI's ->param. Returns value if found, or undef if not. - -=cut - -sub param { - my $self = shift; - my $key = shift; - - return $self->{params}->{$key}; -} - -1; diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 9419a91f7..50a7ba339 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -18,7 +18,6 @@ use Digest::MD5 qw(md5_hex); use URI::Escape; use Cobrand; -use Page; use Utils; use mySociety::Config; use mySociety::Locale; |