diff options
| -rw-r--r-- | conf/httpd.conf | 1 | ||||
| -rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 20 | ||||
| -rwxr-xr-x | web/photo.cgi | 54 | 
3 files changed, 14 insertions, 61 deletions
| diff --git a/conf/httpd.conf b/conf/httpd.conf index 00532a3ab..2645af791 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -109,7 +109,6 @@ RewriteRule /(.+) /$1 [L]  RewriteRule ^/flickr(.*)          /flickr.cgi$1             [L]  # RewriteRule ^/fun(.*)             /fun.cgi$1                [L]  # RewriteRule ^/json(.*)            /json.cgi$1               [L] -# RewriteRule ^/photo(.*)           /photo.cgi$1              [L]  # RewriteRule ^/questionnaire(.*)   /questionnaire.cgi$1      [L]  # RewriteRule ^/reports(.*)         /reports.cgi$1            [L]  # RewriteRule ^/rss(.*)             /rss.cgi$1                [L] diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 774e5c4f7..7b2a04e4b 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -32,17 +32,25 @@ sub index :Path :Args(0) {      my $comment = $c->req->param('c');      return unless ( $id || $comment ); -    my $photo; - +    my @photo;      if ( $comment ) { -        $photo = $c->model('DB::Comment')->find( {id => $comment, state => 'confirmed' } ); +        @photo = $c->model('DB::Comment')->search( { +            id => $comment, +            state => 'confirmed', +            photo => { '!=', undef }, +        } );      } else { -        $photo = $c->model('DB::Problem')->find( {id => $id, state => 'confirmed' } ); +        @photo = $c->model('DB::Problem')->search( { +            id => $id, +            state => [ 'confirmed', 'fixed', 'partial' ], +            photo => { '!=', undef }, +        } );      } -    return unless $photo; +    $c->detach( '/page_error_404_not_found', [ 'No photo' ] ) +        unless @photo; -    $photo = $photo->photo; +    my $photo = $photo[0]->photo;      if ( $c->req->param('tn' ) ) {          $photo = _resize( $photo, 'x100' );      } elsif ( $c->cobrand->default_photo_resize ) { diff --git a/web/photo.cgi b/web/photo.cgi deleted file mode 100755 index bd38e3bf1..000000000 --- a/web/photo.cgi +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl -w -I../perllib - -# photo.cgi: -# Display a photo for FixMyStreet -# -# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: photo.cgi,v 1.11 2008-10-09 14:20:54 matthew Exp $ - -use strict; -use Standard; -use Error qw(:try); -use CGI::Carp; - -sub main { -    my $q = shift; -    print $q->header(-type => 'image/jpeg', -        -expires => '+1y' ); -    my $id = $q->param('id'); -    my $c = $q->param('c'); -    return unless ($id || $c); -    my $photo; -    if ($c) { -        $photo = dbh()->selectrow_arrayref("select photo from comment where -            id=? and state = 'confirmed' and photo is not null", {}, $c); -    } else { -        $photo = dbh()->selectrow_arrayref( "select photo from problem where -            id=? and state in ('confirmed', 'fixed', 'partial') and photo is not -            null", {}, $id); -    } -    return unless $photo; -    $photo = $photo->[0]; -    if ($q->param('tn')) { -        $photo = resize($photo, 'x100'); -    } elsif ($q->{site} eq 'emptyhomes') { -        $photo = resize($photo, '195x'); -    } - -    print $photo; -} -Page::do_fastcgi(\&main, 0, 1); - -sub resize { -    my ($photo, $size) = @_; -    use Image::Magick; -    my $image = Image::Magick->new; -    $image->BlobToImage($photo); -    my $err = $image->Scale(geometry => "$size>"); -    throw Error::Simple("resize failed: $err") if "$err"; -    my @blobs = $image->ImageToBlob(); -    undef $image; -    return $blobs[0]; -} | 
