diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-06 12:32:43 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-06 12:32:43 +0100 |
commit | 75fe00034fc5be24e2222cf116656fc350b98e67 (patch) | |
tree | df8d29092083025a818688d496e26913ed2a3a7f /perllib/Page.pm | |
parent | c297e65b2fb0cf61c5d6a3b2caa477c473fccd96 (diff) | |
parent | 1aa62d33e4e038e9edf994084603086eff26b6ac (diff) |
Merge branch 'migrate_to_catalyst' of ssh://git.mysociety.org/data/git/public/fixmystreet into migrate_to_catalyst
Diffstat (limited to 'perllib/Page.pm')
-rw-r--r-- | perllib/Page.pm | 291 |
1 files changed, 45 insertions, 246 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index 27424d02e..4db72bbdb 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -14,7 +14,6 @@ package Page; use strict; use Carp; use mySociety::CGIFast qw(-no_xhtml); -use Data::Dumper; use Encode; use Error qw(:try); use File::Slurp; @@ -32,7 +31,7 @@ use Problems; use Cobrand; use mySociety::Config; -use mySociety::DBHandle qw/dbh select_all/; +use mySociety::DBHandle qw/dbh/; use mySociety::Email; use mySociety::EvEl; use mySociety::Locale; @@ -472,55 +471,52 @@ sub send_email { # send_confirmation_email TO (NAME) TEMPLATE-NAME PARAMETERS # TEMPLATE-NAME is currently one of problem, update, alert, tms -sub send_confirmation_email { - my ($q, $recipient_email_address, $name, $thing, %h) = @_; - - my $file_thing = $thing; - $file_thing = 'empty property' if $q->{site} eq 'emptyhomes' && $thing eq 'problem'; # Needs to be in English - my $template = "$file_thing-confirm"; - - send_email($q, $recipient_email_address, $name, $template, %h); - - my ($action, $worry); - if ($thing eq 'problem') { - $action = _('your problem will not be posted'); - $worry = _("we'll hang on to your problem report while you're checking your email."); - } elsif ($thing eq 'update') { - $action = _('your update will not be posted'); - $worry = _("we'll hang on to your update while you're checking your email."); - } elsif ($thing eq 'alert') { - $action = _('your alert will not be activated'); - $worry = _("we'll hang on to your alert while you're checking your email."); - } elsif ($thing eq 'tms') { - $action = 'your expression of interest will not be registered'; - $worry = "we'll hang on to your expression of interest while you're checking your email."; - } - - my $out = sprintf(_(<<EOF), $action, $worry); -<h1>Nearly Done! Now check your email...</h1> -<p>The confirmation email <strong>may</strong> take a few minutes to arrive — <em>please</em> be patient.</p> -<p>If you use web-based email or have 'junk mail' filters, you may wish to check your bulk/spam mail folders: sometimes, our messages are marked that way.</p> -<p>You must now click the link in the email we've just sent you — -if you do not, %s.</p> -<p>(Don't worry — %s)</p> -EOF - - my $cobrand = get_cobrand($q); - my %vars = ( - action => $action, - worry => $worry, - url_home => Cobrand::url($cobrand, '/', $q), - ); - my $cobrand_email = Page::template_include('check-email', $q, Page::template_root($q), %vars); - return $cobrand_email if $cobrand_email; - return $out; -} +#sub send_confirmation_email { +# my ($q, $recipient_email_address, $name, $thing, %h) = @_; +# +# my $file_thing = $thing; +# $file_thing = 'empty property' if $q->{site} eq 'emptyhomes' && $thing eq 'problem'; # Needs to be in English +# my $template = "$file_thing-confirm"; +# +# send_email($q, $recipient_email_address, $name, $template, %h); +# +# my ($action, $worry); +# if ($thing eq 'problem') { +# $action = _('your problem will not be posted'); +# $worry = _("we'll hang on to your problem report while you're checking your email."); +# } elsif ($thing eq 'update') { +# $action = _('your update will not be posted'); +# $worry = _("we'll hang on to your update while you're checking your email."); +# } elsif ($thing eq 'alert') { +# $action = _('your alert will not be activated'); +# $worry = _("we'll hang on to your alert while you're checking your email."); +# } elsif ($thing eq 'tms') { +# $action = 'your expression of interest will not be registered'; +# $worry = "we'll hang on to your expression of interest while you're checking your email."; +# } +# +# my $out = sprintf(_(<<EOF), $action, $worry); +#<h1>Nearly Done! Now check your email...</h1> +#<p>The confirmation email <strong>may</strong> take a few minutes to arrive — <em>please</em> be patient.</p> +#<p>If you use web-based email or have 'junk mail' filters, you may wish to check your bulk/spam mail folders: sometimes, our messages are marked that way.</p> +#<p>You must now click the link in the email we've just sent you — +#if you do not, %s.</p> +#<p>(Don't worry — %s)</p> +#EOF +# +# my $cobrand = get_cobrand($q); +# my %vars = ( +# action => $action, +# worry => $worry, +# url_home => Cobrand::url($cobrand, '/', $q), +# ); +# my $cobrand_email = Page::template_include('check-email', $q, Page::template_root($q), %vars); +# return $cobrand_email if $cobrand_email; +# return $out; +#} sub prettify_epoch { - my ($q, $s, $short) = @_; - my $cobrand = get_cobrand($q); - my $cobrand_datetime = Cobrand::prettify_epoch($cobrand, $s); - return $cobrand_datetime if ($cobrand_datetime); + my ($s, $short) = @_; my @s = localtime($s); my $tt = strftime('%H:%M', @s); my @t = localtime(); @@ -567,197 +563,6 @@ sub _part { } } -# sub display_problem_meta_line($$) { -# my ($q, $problem) = @_; -# my $out = ''; -# my $date_time = prettify_epoch($q, $problem->{time}); -# if ($q->{site} eq 'emptyhomes') { -# my $category = _($problem->{category}); -# utf8::decode($category); # So that Welsh to Welsh doesn't encode already-encoded UTF-8 -# if ($problem->{anonymous}) { -# $out .= sprintf(_('%s, reported anonymously at %s'), ent($category), $date_time); -# } else { -# $out .= sprintf(_('%s, reported by %s at %s'), ent($category), ent($problem->{name}), $date_time); -# } -# } else { -# if ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) { -# $out .= sprintf(_('Reported by %s in the %s category anonymously at %s'), ent($problem->{service}), ent($problem->{category}), $date_time); -# } elsif ($problem->{service} && $problem->{category} && $problem->{category} ne _('Other')) { -# $out .= sprintf(_('Reported by %s in the %s category by %s at %s'), ent($problem->{service}), ent($problem->{category}), ent($problem->{name}), $date_time); -# } elsif ($problem->{service} && $problem->{anonymous}) { -# $out .= sprintf(_('Reported by %s anonymously at %s'), ent($problem->{service}), $date_time); -# } elsif ($problem->{service}) { -# $out .= sprintf(_('Reported by %s by %s at %s'), ent($problem->{service}), ent($problem->{name}), $date_time); -# } elsif ($problem->{category} && $problem->{category} ne _('Other') && $problem->{anonymous}) { -# $out .= sprintf(_('Reported in the %s category anonymously at %s'), ent($problem->{category}), $date_time); -# } elsif ($problem->{category} && $problem->{category} ne _('Other')) { -# $out .= sprintf(_('Reported in the %s category by %s at %s'), ent($problem->{category}), ent($problem->{name}), $date_time); -# } elsif ($problem->{anonymous}) { -# $out .= sprintf(_('Reported anonymously at %s'), $date_time); -# } else { -# $out .= sprintf(_('Reported by %s at %s'), ent($problem->{name}), $date_time); -# } -# } -# my $cobrand = get_cobrand($q); -# $out .= Cobrand::extra_problem_meta_text($cobrand, $problem); -# $out .= '; ' . _('the map was not used so pin location may be inaccurate') unless ($problem->{used_map}); -# if ($problem->{council}) { -# if ($problem->{whensent}) { -# my $body; -# if ($problem->{external_body}) { -# $body = $problem->{external_body}; -# } else { -# $problem->{council} =~ s/\|.*//g; -# my @councils = split /,/, $problem->{council}; -# my $areas_info = mySociety::MaPit::call('areas', \@councils); -# $body = join(' and ', map { $areas_info->{$_}->{name} } @councils); -# } -# $out .= '<small class="council_sent_info">'; -# $out .= $q->br() . sprintf(_('Sent to %s %s later'), $body, prettify_duration($problem->{whensent}, 'minute')); -# $out .= '</small>'; -# } -# } else { -# $out .= $q->br() . $q->small(_('Not reported to council')); -# } -# return $out; -# } - -sub display_problem_detail($) { - my $problem = shift; - (my $detail = $problem->{detail}) =~ s/\r//g; - my $out = ''; - foreach (split /\n{2,}/, $detail) { - $out .= '<p>' . ent($_) . '</p>'; - } - return $out; -} - -sub display_problem_photo($$) { - my ($q, $problem) = @_; - my $cobrand = get_cobrand($q); - my $display_photos = Cobrand::allow_photo_display($cobrand); - if ($display_photos && $problem->{photo}) { - my $dims = Image::Size::html_imgsize(\$problem->{photo}); - return "<p align='center'><img alt='' $dims src='/photo?id=$problem->{id}'></p>"; - } - return ''; -} - -# Display information about problem -sub display_problem_text($$) { - my ($q, $problem) = @_; - - my $out = $q->h1(ent($problem->{title})); - $out .= '<p><em>'; - $out .= display_problem_meta_line($q, $problem); - $out .= '</em></p>'; - $out .= display_problem_detail($problem); - $out .= display_problem_photo($q, $problem); - return $out; -} - -# Display updates -sub display_problem_updates($$) { - my ($id, $q) = @_; - my $cobrand = get_cobrand($q); - my $updates = select_all( - "select id, name, extract(epoch from confirmed) as confirmed, text, - mark_fixed, mark_open, photo, cobrand - from comment where problem_id = ? and state='confirmed' - order by confirmed", $id); - my $out = ''; - if (@$updates) { - $out .= '<div id="updates">'; - $out .= '<h2 class="problem-update-list-header">' . _('Updates') . '</h2>'; - foreach my $row (@$updates) { - $out .= "<div><div class=\"problem-update\"><p><a name=\"update_$row->{id}\"></a><em>"; - if ($row->{name}) { - $out .= sprintf(_('Posted by %s at %s'), ent($row->{name}), prettify_epoch($q, $row->{confirmed})); - } else { - $out .= sprintf(_('Posted anonymously at %s'), prettify_epoch($q, $row->{confirmed})); - } - $out .= Cobrand::extra_update_meta_text($cobrand, $row); - $out .= ', ' . _('marked as fixed') if ($row->{mark_fixed}); - $out .= ', ' . _('reopened') if ($row->{mark_open}); - $out .= '</em></p>'; - - my $allow_update_reporting = Cobrand::allow_update_reporting($cobrand); - if ($allow_update_reporting) { - my $contact = '/contact?id=' . $id . ';update_id='. $row->{id}; - my $contact_url = Cobrand::url($cobrand, $contact, $q); - $out .= '<p>'; - $out .= $q->a({rel => 'nofollow', class => 'unsuitable-problem', href => $contact_url}, _('Offensive? Unsuitable? Tell us')); - $out .= '</p>'; - } - $out .= '</div>'; - $out .= '<div class="update-text">'; - my $text = $row->{text}; - $text =~ s/\r//g; - foreach (split /\n{2,}/, $text) { - $out .= '<p>' . ent($_) . '</p>'; - } - my $cobrand = get_cobrand($q); - my $display_photos = Cobrand::allow_photo_display($cobrand); - if ($display_photos && $row->{photo}) { - my $dims = Image::Size::html_imgsize(\$row->{photo}); - $out .= "<p><img alt='' $dims src='/photo?c=$row->{id}'></p>"; - } - $out .= '</div>'; - $out .= '</div>'; - } - $out .= '</div>'; - } - return $out; -} - -sub mapit_check_error { - my $location = shift; - if ($location->{error}) { - return _('That postcode was not recognised, sorry.') if $location->{code} =~ /^4/; - return $location->{error}; - } - if (mySociety::Config::get('COUNTRY') eq 'GB') { - my $island = $location->{coordsyst}; - if (!$island) { - return _("Sorry, that appears to be a Crown dependency postcode, which we don't cover."); - } - if ($island eq 'I') { - return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region."); - } - } - return 0; -} - -sub short_name { - my ($area, $info) = @_; - # Special case Durham as it's the only place with two councils of the same name - # And some places in Norway - return 'Durham+County' if $area->{name} eq 'Durham County Council'; - return 'Durham+City' if $area->{name} eq 'Durham City Council'; - if ($area->{name} =~ /^(Os|Nes|V\xe5ler|Sande|B\xf8|Her\xf8y)$/) { - my $parent = $info->{$area->{parent_area}}->{name}; - return URI::Escape::uri_escape_utf8("$area->{name}, $parent"); - } - my $name = $area->{name}; - $name =~ s/ (Borough|City|District|County) Council$//; - $name =~ s/ Council$//; - $name =~ s/ & / and /; - $name = URI::Escape::uri_escape_utf8($name); - $name =~ s/%20/+/g; - return $name; -} - -sub check_photo { - my ($q, $fh) = @_; - my $ct = $q->uploadInfo($fh)->{'Content-Type'}; - my $cd = $q->uploadInfo($fh)->{'Content-Disposition'}; - # Must delete photo param, otherwise display functions get confused - $q->delete('photo'); - return _('Please upload a JPEG image only') unless - ($ct eq 'image/jpeg' || $ct eq 'image/pjpeg'); - return ''; -} - sub process_photo { my $fh = shift; my $import = shift; @@ -793,10 +598,4 @@ sub process_photo { return $photo; } -sub scambs_categories { - return ('Abandoned vehicles', 'Discarded hypodermic needles', - 'Dog fouling', 'Flytipping', 'Graffiti', 'Lighting (e.g. security lights)', - 'Litter', 'Neighbourhood noise'); -} - 1; |