#!/usr/bin/perl
#
# Page.pm:
# Various HTML stuff for the FixMyStreet site.
#
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: Page.pm,v 1.230 2010-01-15 17:08:55 matthew Exp $
#
package Page;
use strict;
use Carp;
use mySociety::CGIFast qw(-no_xhtml);
use Data::Dumper;
use Encode;
use Error qw(:try);
use File::Slurp;
use HTTP::Date; # time2str
use Image::Magick;
use Image::Size;
use POSIX qw(strftime);
use URI::Escape;
use Text::Template;
use Memcached;
use Problems;
use Cobrand;
use mySociety::Config;
use mySociety::DBHandle qw/dbh select_all/;
use mySociety::Email;
use mySociety::EvEl;
use mySociety::Locale;
use mySociety::MaPit;
use mySociety::TempFiles;
use mySociety::WatchUpdate;
use mySociety::Web qw(ent);
BEGIN {
(my $dir = __FILE__) =~ s{/[^/]*?$}{};
mySociety::Config::set_file("$dir/../conf/general");
}
# Under the BEGIN so that the config has been set.
use FixMyStreet::Map;
my $lastmodified;
sub do_fastcgi {
my ($func, $lm, $binary) = @_;
binmode(STDOUT, ":utf8") unless $binary;
try {
my $W = new mySociety::WatchUpdate();
while (my $q = new mySociety::Web(unicode => 1)) {
next if $lm && $q->Maybe304($lm);
$lastmodified = $lm;
microsite($q);
&$func($q);
dbh()->rollback() if $mySociety::DBHandle::conf_ok;
$W->exit_if_changed();
}
} catch Error::Simple with {
report_error(@_);
} catch Error with {
report_error(@_);
};
dbh()->rollback() if $mySociety::DBHandle::conf_ok;
exit(0);
}
sub report_error {
my $E = shift;
my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), CGI::escapeHTML($E->text()));
warn "caught fatal exception: $msg";
warn "aborting";
ent($msg);
my $contact_email = mySociety::Config::get('CONTACT_EMAIL');
my $trylater = sprintf(_('Please try again later, or email us to let us know.'), $contact_email);
my $somethingwrong = _("Sorry! Something's gone wrong.");
my $errortext = _("The text of the error was:");
my $msg_br = join '
', split m{\n}, $msg;
print "Status: 500\nContent-Type: text/html; charset=utf-8\n\n",
qq(
$trylater
), q($errortext
), qq($msg_br), q(