aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rwxr-xr-xweb/alert.cgi353
-rwxr-xr-xweb/confirm.cgi27
-rwxr-xr-xweb/contact.cgi26
-rw-r--r--web/css.css43
-rwxr-xr-xweb/faq.cgi12
-rwxr-xr-xweb/flickr.cgi26
-rwxr-xr-xweb/flickr2.cgi27
-rwxr-xr-xweb/index.cgi122
-rwxr-xr-xweb/photo.cgi27
-rwxr-xr-xweb/posters/index.cgi13
-rwxr-xr-xweb/questionnaire.cgi26
-rwxr-xr-xweb/reports.cgi53
-rwxr-xr-xweb/rss.cgi86
13 files changed, 398 insertions, 443 deletions
diff --git a/web/alert.cgi b/web/alert.cgi
index 2af4f93b0..6e5dcce6e 100755
--- a/web/alert.cgi
+++ b/web/alert.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# alert.cgi:
# Alert code for FixMyStreet
@@ -6,111 +6,231 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: alert.cgi,v 1.9 2007-08-02 11:45:06 matthew Exp $
+# $Id: alert.cgi,v 1.10 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use Digest::SHA1 qw(sha1_hex);
-
use CrossSell;
-use Page;
use mySociety::Alert;
use mySociety::AuthToken;
use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
use mySociety::EmailUtil qw(is_valid_email);
+use mySociety::Gaze;
+use mySociety::MaPit;
+use mySociety::VotingArea;
use mySociety::Web qw(ent);
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
my $out = '';
- if (my $signed_email = $q->param('signed_email')) {
- my ($salt, $signed_email) = split /,/, $signed_email;
- my $email = $q->param('email');
- my $id = $q->param('id');
- my $secret = scalar(dbh()->selectrow_array('select secret from secret'));
- if ($signed_email eq sha1_hex("$id-$email-$salt-$secret")) {
- my $alert_id = mySociety::Alert::create($email, 'new_updates', $id);
- mySociety::Alert::confirm($alert_id);
- $out .= $q->p(_('You have successfully subscribed to that alert.'));
- $out .= CrossSell::display_advert($email);
- } else {
- $out = $q->p(_('We could not validate that alert.'));
- }
+ my $title = 'Confirmation';
+ if ($q->param('signed_email')) {
+ $out = alert_signed_input($q);
} elsif (my $token = $q->param('token')) {
my $data = mySociety::AuthToken::retrieve('alert', $token);
- if (my $id = $data->{id}) {
- my $type = $data->{type};
- my $email = $data->{email};
- if ($type eq 'subscribe') {
- mySociety::Alert::confirm($id);
- $out = $q->p(_('You have successfully confirmed your alert.'));
- $out .= CrossSell::display_advert($email);
- } elsif ($type eq 'unsubscribe') {
- mySociety::Alert::delete($id);
- $out = $q->p(_('You have successfully deleted your alert.'));
- $out .= CrossSell::display_advert($email);
- }
+ if ($data->{id}) {
+ $out = alert_token($q, $data);
} else {
$out = $q->p(_(<<EOF));
-Thank you for trying to confirm your update or problem. We seem to have a
-problem ourselves though, so <a href="/contact">please let us know what went on</a>
-and we'll look into it.
+Thank you for trying to confirm your alert. We seem to have a problem ourselves
+though, so <a href="/contact">please let us know what went on</a> and we'll look into it.
EOF
}
- } elsif (my $email = $q->param('email')) {
- my @errors;
- push @errors, _('Please enter a valid email address') unless is_valid_email($email);
- if (@errors) {
- $out = display_form($q, @errors);
- } else {
- my $type = $q->param('type');
- my $alert_id;
- if ($type eq 'updates') {
- my $id = $q->param('id');
- $alert_id = mySociety::Alert::create($email, 'new_updates', $id);
- } elsif ($type eq 'problems') {
- $alert_id = mySociety::Alert::create($email, 'new_problems');
- } else {
- throw mySociety::Alert::Error('Invalid type');
- }
- my %h = ();
- $h{url} = mySociety::Config::get('BASE_URL') . '/A/'
- . mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } );
- dbh()->commit();
- $out = Page::send_email($email, undef, 'alert', %h);
- }
+ } elsif ($q->param('rss')) {
+ $out = alert_rss($q);
+ return unless $out;
+ } elsif ($q->param('email')) {
+ $out = alert_do_subscribe($q, $q->param('email'));
} elsif ($q->param('id')) {
- $out = display_form($q);
+ $out = alert_updates_form($q);
+ } elsif ($q->param('pc')) {
+ $title = 'Local RSS feeds and email alerts';
+ $out = alert_list($q);
} else {
- $out = $q->p(_('Subscribe from a problem page!'));
+ $title = 'Local RSS feeds and email alerts';
+ $out = alert_front_page();
}
- print Page::header($q, title=>_('Confirmation'));
+ print Page::header($q, title => $title);
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
-# Updates only at present
-sub display_form {
+sub alert_list {
+ my ($q, @errors) = @_;
+ my %input = map { $_ => scalar $q->param($_) } qw(pc email);
+ my %input_h = map { $_ => ent($q->param($_)) } qw(pc email);
+ my ($x, $y, $e, $n, $error) = Page::geocode($input{pc});
+ return alert_front_page($q, $error) if $error;
+
+ my $errors = '';
+ $errors = '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>' if @errors;
+
+ my @types = (@$mySociety::VotingArea::council_parent_types, @$mySociety::VotingArea::council_child_types);
+ my %councils = map { $_ => 1 } @$mySociety::VotingArea::council_parent_types;
+
+ my $areas = mySociety::MaPit::get_voting_areas_by_location({easting=>$e, northing=>$n}, 'polygon', \@types);
+ $areas = mySociety::MaPit::get_voting_areas_info([ keys %$areas ]);
+
+ my ($options);
+ if (keys %$areas == 2) {
+
+ # One-tier council
+ my (@options, $council, $ward);
+ foreach (values %$areas) {
+ if ($councils{$_->{type}}) {
+ $council = $_;
+ } else {
+ $ward = $_;
+ }
+ }
+ push @options, [ 'council', $council->{area_id}, Page::short_name($council->{name}),
+ "Problems within $council->{name}" ];
+ push @options, [ 'ward', $council->{area_id}.':'.$ward->{area_id}, Page::short_name($council->{name}) . '/'
+ . Page::short_name($ward->{name}), "Problems within $ward->{name} ward" ];
+
+ $options = '<div>' . $q->ul({id=>'rss_feed'},
+ alert_list_options($q, @options)
+ );
+
+ } elsif (keys %$areas == 4) {
+
+ # Two-tier council
+ my (@options, $county, $district, $c_ward, $d_ward);
+ foreach (values %$areas) {
+ if ($_->{type} eq 'CTY') {
+ $county = $_;
+ } elsif ($_->{type} eq 'DIS') {
+ $district = $_;
+ } elsif ($_->{type} eq 'CED') {
+ $c_ward = $_;
+ } elsif ($_->{type} eq 'DIW') {
+ $d_ward = $_;
+ }
+ }
+ push @options,
+ [ 'area', $district->{area_id}, Page::short_name($district->{name}), $district->{name} ],
+ [ 'area', $district->{area_id}.':'.$d_ward->{area_id}, Page::short_name($district->{name}) . '/'
+ . Page::short_name($d_ward->{name}), "$d_ward->{name} ward, $district->{name}" ],
+ [ 'area', $county->{area_id}, Page::short_name($county->{name}), $county->{name} ],
+ [ 'area', $county->{area_id}.':'.$c_ward->{area_id}, Page::short_name($county->{name}) . '/'
+ . Page::short_name($c_ward->{name}), "$c_ward->{name} ward, $county->{name}" ];
+ $options = '<div id="rss_list">';
+ $options .= $q->p($q->strong('Feed of problems within:')) .
+ $q->ul(alert_list_options($q, @options));
+ @options = ();
+ push @options,
+ [ 'council', $district->{area_id}, Page::short_name($district->{name}), $district->{name} ],
+ [ 'ward', $district->{area_id}.':'.$d_ward->{area_id}, Page::short_name($district->{name}) . '/' . Page::short_name($d_ward->{name}),
+ "$district->{name}, within $d_ward->{name} ward" ],
+ [ 'council', $county->{area_id}, Page::short_name($county->{name}), $county->{name} ],
+ [ 'ward', $county->{area_id}.':'.$c_ward->{area_id}, Page::short_name($county->{name}) . '/'
+ . Page::short_name($c_ward->{name}), "$county->{name}, within $c_ward->{name} ward" ];
+ $options .= $q->p($q->strong('Problems reported to:')) .
+ $q->ul(alert_list_options($q, @options));
+ $options .= '</div>
+<div id="rss_buttons">
+';
+
+ } else {
+ # Hopefully impossible in the UK!
+ throw Error::Simple('An area with three tiers of council? Impossible!');
+ }
+
+ my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G');
+ my $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
+ $dist = int($dist*10+0.5)/10;
+
+ <<EOF;
+<h1>Local RSS feeds and email alerts for &lsquo;$input_h{pc}&rsquo;</h1>
+
+<p>We have a variety of RSS feeds for local problems. The easiest is our simple geographic one:</p>
+
+<p id="rss_local"><a href="/rss/$x,$y"><img
+src="/i/feed.png" width="16" height="16" title="RSS feed of recent local problems" alt="RSS feed" border="0"></a>
+<a href="/rss/$x,$y">Problems within ${dist}km of this location</a> (a default
+distance which covers roughly 200,000 people)
+</p>
+<p id="rss_local_alt">
+(alternatively within <a href="/rss/$x,$y/2">2km</a> / <a href="/rss/$x,$y/5">5km</a>
+/ <a href="/rss/$x,$y/10">10km</a> / <a href="/rss/$x,$y/20">20km</a>)
+</ul>
+
+<p>Or you can subscribe to a feed based upon what ward or council you&rsquo;re in. Simply
+select which feed you&rsquo;d like and click the button. If you&rsquo;d prefer,
+these feeds are also available as email alerts &ndash; just enter your email
+address below.</p>
+
+<form id="alerts" method="post" action="/alert">
+<input type="hidden" name="type" value="local">
+<input type="hidden" name="pc" value="$input_h{pc}">
+
+$options
+
+$errors
+
+<p><input type="submit" name="rss" value="Give me an RSS feed"></p>
+
+<p id="alert_or">or</p>
+
+<p>Your email: <input type="text" id="email" name="email" value="$input_h{email}" size="30"></p>
+<p><input type="submit" name="alert" value="Subscribe me to an email alert"></p>
+
+</div>
+</form>
+EOF
+}
+
+sub alert_list_options {
+ my $q = shift;
+ my $out = '';
+ foreach (@_) {
+ my ($type, $vals, $rss, $text) = @$_;
+ (my $vals2 = $rss) =~ tr{/+}{:_};
+ my $id = $type . ':' . $vals . ':' . $vals2;
+ $out .= '<li><input type="radio" name="feed" id="' . $id . '" ';
+ $out .= 'checked ' if ($q->param('feed') eq $id);
+ $out .= 'value="' . $id . '"> <label for="' . $id . '">' . $text
+ . '</label> <a href="/rss/';
+ $out .= $type eq 'area' ? 'area' : 'reports';
+ $out .= '/' . $rss . '"><img src="/i/feed.png" width="16" height="16"
+title="RSS feed of recent local problems" alt="RSS feed" border="0"></a>';
+ }
+ return $out;
+}
+
+sub alert_front_page {
+ my $out = <<EOF;
+<h1>Local RSS feeds and email alerts</h1>
+<form method="get" action="/alert">
+<p>To find out what local alerts we have, please enter your postcode or street name here:
+<input type="text" name="pc" value="">
+<input type="submit" value="Look up">
+</form>
+EOF
+ return $out;
+}
+
+sub alert_rss {
+ my $q = shift;
+ my $feed = $q->param('feed');
+ return alert_list($q, 'Please select the feed you want') unless $feed;
+ if ($feed =~ /^area:(?:\d+:)+(.*)$/) {
+ (my $id = $1) =~ tr{:_}{/+};
+ print $q->redirect('/rss/area/' . $id);
+ return;
+ } elsif ($feed =~ /^(?:council|ward):(?:\d+:)+(.*)$/) {
+ (my $id = $1) =~ tr{:_}{/+};
+ print $q->redirect('/rss/reports/' . $id);
+ return;
+ } else {
+ return alert_list($q, 'Illegal feed selection');
+ }
+}
+
+sub alert_updates_form {
my ($q, @errors) = @_;
my @vars = qw(id email);
my %input = map { $_ => $q->param($_) || '' } @vars;
@@ -133,3 +253,80 @@ sub display_form {
EOF
return $out;
}
+
+sub alert_signed_input {
+ my $q = shift;
+ my ($salt, $signed_email) = split /,/, $q->param('signed_email');
+ my $email = $q->param('email');
+ my $id = $q->param('id');
+ my $secret = scalar(dbh()->selectrow_array('select secret from secret'));
+ my $out;
+ if ($signed_email eq sha1_hex("$id-$email-$salt-$secret")) {
+ my $alert_id = mySociety::Alert::create($email, 'new_updates', $id);
+ mySociety::Alert::confirm($alert_id);
+ $out = $q->p(_('You have successfully subscribed to that alert.'));
+ $out .= CrossSell::display_advert($email);
+ } else {
+ $out = $q->p(_('We could not validate that alert.'));
+ }
+ return $out;
+}
+
+sub alert_token {
+ my ($q, $data) = @_;
+ my $id = $data->{id};
+ my $type = $data->{type};
+ my $email = $data->{email};
+ my $out;
+ if ($type eq 'subscribe') {
+ mySociety::Alert::confirm($id);
+ $out = $q->p(_('You have successfully confirmed your alert.'));
+ $out .= CrossSell::display_advert($email);
+ } elsif ($type eq 'unsubscribe') {
+ mySociety::Alert::delete($id);
+ $out = $q->p(_('You have successfully deleted your alert.'));
+ $out .= CrossSell::display_advert($email);
+ }
+ return $out;
+}
+
+sub alert_do_subscribe {
+ my ($q, $email) = @_;
+
+ my $type = $q->param('type');
+
+ my @errors;
+ push @errors, _('Please enter a valid email address') unless is_valid_email($email);
+ push @errors, _('Please select the feed you want') if $type eq 'local' && !$q->param('feed');
+ if (@errors) {
+ return alert_updates_form($q, @errors) if $type eq 'updates';
+ return alert_list($q, @errors) if $type eq 'local';
+ return 'argh';
+ }
+
+ my $alert_id;
+ if ($type eq 'updates') {
+ my $id = $q->param('id');
+ $alert_id = mySociety::Alert::create($email, 'new_updates', $id);
+ } elsif ($type eq 'problems') {
+ $alert_id = mySociety::Alert::create($email, 'new_problems');
+ } elsif ($type eq 'local') {
+ my $feed = $q->param('feed');
+ if ($feed =~ /^area:(?:\d+:)?(\d+)/) {
+ $alert_id = mySociety::Alert::create($email, 'area_problems', $1);
+ } elsif ($feed =~ /^council:(\d+)/) {
+ $alert_id = mySociety::Alert::create($email, 'council_problems', $1, $1);
+ } elsif ($feed =~ /^ward:(\d+):(\d+)/) {
+ $alert_id = mySociety::Alert::create($email, 'ward_problems', $1, $2);
+ }
+ } else {
+ throw mySociety::Alert::Error('Invalid type');
+ }
+
+ my %h = ();
+ $h{url} = mySociety::Config::get('BASE_URL') . '/A/'
+ . mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } );
+ dbh()->commit();
+ return Page::send_email($email, undef, 'alert', %h);
+}
+
diff --git a/web/confirm.cgi b/web/confirm.cgi
index 78b0db0d6..86e79a0cf 100755
--- a/web/confirm.cgi
+++ b/web/confirm.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# confirm.cgi:
# Confirmation code for FixMyStreet
@@ -6,35 +6,15 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: confirm.cgi,v 1.28 2007-08-02 11:45:06 matthew Exp $
+# $Id: confirm.cgi,v 1.29 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use Digest::SHA1 qw(sha1_hex);
-
use CrossSell;
-use Page;
use mySociety::AuthToken;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
use mySociety::Random qw(random_bytes);
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
@@ -63,7 +43,6 @@ EOF
print Page::header($q, title=>_('Confirmation'));
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/contact.cgi b/web/contact.cgi
index 8a211a21a..4a0a03bd4 100755
--- a/web/contact.cgi
+++ b/web/contact.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# contact.cgi:
# Contact page for FixMyStreet
@@ -6,34 +6,15 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: contact.cgi,v 1.22 2007-08-02 11:45:06 matthew Exp $
+# $Id: contact.cgi,v 1.23 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use CrossSell;
-use Page;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh);
use mySociety::Email;
use mySociety::EmailUtil;
use mySociety::Web qw(ent);
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
# Main code for index.cgi
sub main {
my $q = shift;
@@ -46,7 +27,6 @@ sub main {
}
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/css.css b/web/css.css
index 7056457a3..0d20f5ad0 100644
--- a/web/css.css
+++ b/web/css.css
@@ -159,6 +159,13 @@ ul#error {
color: #e3d595;
}
+#nav_new a {
+ background-image: url("http://upload.wikimedia.org/wikipedia/en/1/1a/New.png");
+ background-repeat: no-repeat;
+ background-position: 100% 0;
+}
+
+
#footer {
clear: both;
text-align: right;
@@ -253,7 +260,7 @@ fieldset div.checkbox label, label.n {
cursor: hand;
}
-#questionnaire label {
+#questionnaire label, #alerts label {
float: none;
}
@@ -401,6 +408,40 @@ ol#current img {
border:1px solid #999999;
}
+/* Alerts */
+#rss_feed {
+ list-style-type: none;
+ margin-bottom: 2em;
+}
+#rss_feed li {
+ margin-bottom: 1em;
+}
+#alert_or {
+ font-style: italic;
+ font-size: 125%;
+ margin: 0;
+}
+#rss_list {
+ float: left;
+ width: 47%;
+}
+#rss_list ul {
+ list-style-type: none;
+}
+#rss_buttons {
+ float: right;
+ width: 47%;
+ text-align: center;
+ margin-bottom: 2em;
+}
+#rss_local {
+ margin-left: 3em;
+ margin-bottom: 0;
+}
+#rss_local_alt {
+ margin: 0 0 2em 6em;
+}
+
/* Report page */
#col_problems, #col_fixed {
diff --git a/web/faq.cgi b/web/faq.cgi
index 6e3bb716f..8ed99b5a1 100755
--- a/web/faq.cgi
+++ b/web/faq.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# faq.cgi:
# FAQ page for FixMyStreet
@@ -6,16 +6,10 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: faq.cgi,v 1.26 2007-08-01 11:27:37 matthew Exp $
+# $Id: faq.cgi,v 1.27 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
-use Page;
+use Standard -db;
# Main code for index.cgi
sub main {
diff --git a/web/flickr.cgi b/web/flickr.cgi
index 68e8fb396..ac0e83d78 100755
--- a/web/flickr.cgi
+++ b/web/flickr.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# flickr.cgi:
# Register for Flickr usage, and update photos
@@ -6,34 +6,15 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: flickr.cgi,v 1.4 2007-06-17 11:46:42 matthew Exp $
+# $Id: flickr.cgi,v 1.5 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use LWP::Simple;
use mySociety::AuthToken;
-use mySociety::DBHandle qw(dbh);
use mySociety::Email;
use mySociety::EmailUtil;
-use Page;
-
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
print Page::header($q, title=>'Flickr photo upload');
@@ -112,7 +93,6 @@ EOF
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/flickr2.cgi b/web/flickr2.cgi
index 1817ba9b0..631e96f8c 100755
--- a/web/flickr2.cgi
+++ b/web/flickr2.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# flickr2.cgi:
# Check photo details, and confirm for council
@@ -6,35 +6,15 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: flickr2.cgi,v 1.2 2007-08-24 22:35:51 matthew Exp $
+# $Id: flickr2.cgi,v 1.3 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use URI::Escape;
-
use mySociety::AuthToken;
-use mySociety::DBHandle qw(dbh select_all);
use mySociety::Email;
use mySociety::EmailUtil;
-use Page;
-
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
my $out = '';
@@ -66,6 +46,5 @@ EOF
print Page::header($q, title=>'Flickr photo upload');
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/index.cgi b/web/index.cgi
index 760b08f2b..11fc57b4c 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# index.cgi:
# Main code for FixMyStreet
@@ -6,28 +6,22 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.162 2007-08-27 11:47:55 matthew Exp $
+# $Id: index.cgi,v 1.163 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
+use Standard;
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
use Error qw(:try);
use File::Slurp;
use Image::Magick;
use LWP::Simple;
use RABX;
use CGI::Carp;
-use Digest::MD5 qw(md5_hex);
use URI::Escape;
-use Page;
use mySociety::AuthToken;
use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
+use mySociety::DBHandle qw(select_all);
use mySociety::EmailUtil;
use mySociety::Gaze;
use mySociety::GeoUtil;
@@ -38,15 +32,6 @@ use mySociety::VotingArea;
use mySociety::Web qw(ent NewURL);
BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-
if (!dbh()->selectrow_array('select secret from secret for update of secret')) {
local dbh()->{HandleError};
dbh()->do('insert into secret (secret) values (?)', {}, unpack('h*', mySociety::Random::random_bytes(32)));
@@ -80,8 +65,7 @@ sub main {
}
print Page::header($q, %params);
print $out;
- print Page::footer();
- dbh()->rollback();
+ print Page::footer($q);
}
Page::do_fastcgi(\&main);
@@ -386,15 +370,15 @@ sub display_form {
|| ($input{flickr} && $input{pc});
my $out = '';
- my ($px, $py, $easting, $northing, $island);
+ my ($px, $py, $easting, $northing);
if ($input{skipped}) {
# Map is being skipped
if ($input{x} && $input{y}) {
$easting = Page::tile_to_os($input{x});
$northing = Page::tile_to_os($input{y});
} else {
- my ($x, $y, $e, $n, $i, $error) = geocode($input{pc});
- $easting = $e; $northing = $n; $island = $i;
+ my ($x, $y, $e, $n, $error) = Page::geocode($input{pc});
+ $easting = $e; $northing = $n;
}
} elsif ($pin_x && $pin_y) {
# Map was clicked on
@@ -405,8 +389,8 @@ sub display_form {
$easting = Page::tile_to_os($pin_x);
$northing = Page::tile_to_os($pin_y);
} elsif ($input{flickr} && $input{pc} && !$input{easting} && !$input{northing}) {
- my ($x, $y, $e, $n, $i, $error) = geocode($input{pc});
- $easting = $e; $northing = $n; $island = $i;
+ my ($x, $y, $e, $n, $error) = Page::geocode($input{pc});
+ $easting = $e; $northing = $n;
$input{x} = int(Page::os_to_tile($easting));
$input{y} = int(Page::os_to_tile($northing));
$px = Page::os_to_px($easting, $input{x});
@@ -586,14 +570,14 @@ sub display_location {
my %input = map { $_ => $q->param($_) || '' } @vars;
my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars;
- my($error, $easting, $northing, $island);
+ my($error, $easting, $northing);
my $x = $input{x}; my $y = $input{y};
$x ||= 0; $x += 0;
$y ||= 0; $y += 0;
return front_page($q, @errors) unless $x || $y || $input{pc};
if (!$x && !$y) {
try {
- ($x, $y, $easting, $northing, $island, $error) = geocode($input{pc});
+ ($x, $y, $easting, $northing, $error) = Page::geocode($input{pc});
} catch Error::Simple with {
$error = shift;
};
@@ -845,85 +829,3 @@ sub geocode_choice {
return $out;
}
-sub geocode {
- my ($s) = @_;
- my ($x, $y, $easting, $northing, $island, $error);
- if (mySociety::PostcodeUtil::is_valid_postcode($s)) {
- try {
- my $location = mySociety::MaPit::get_location($s);
- $island = $location->{coordsyst};
- throw RABX::Error("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.") if $island eq 'I';
- $easting = $location->{easting};
- $northing = $location->{northing};
- my $xx = Page::os_to_tile($easting);
- my $yy = Page::os_to_tile($northing);
- $x = int($xx);
- $y = int($yy);
- $x -= 1 if ($xx - $x < 0.5);
- $y -= 1 if ($yy - $y < 0.5);
- } catch RABX::Error with {
- my $e = shift;
- if ($e->value() && ($e->value() == mySociety::MaPit::BAD_POSTCODE
- || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND)) {
- $error = 'That postcode was not recognised, sorry.';
- } else {
- $error = $e;
- }
- }
- } else {
- ($x, $y, $easting, $northing, $error) = geocode_string($s);
- }
- return ($x, $y, $easting, $northing, $island, $error);
-}
-
-sub geocode_string {
- my $s = shift;
- $s = lc($s);
- $s =~ s/[^-&0-9a-z ']/ /g;
- $s =~ s/\s+/ /g;
- $s = uri_escape($s);
- $s =~ s/%20/+/g;
- my $url = 'http://maps.google.com/maps/geo?q=' . $s;
- my $cache_dir = mySociety::Config::get('GEO_CACHE');
- my $cache_file = $cache_dir . md5_hex($url);
- my ($js, $error, $x, $y, $easting, $northing);
- if (-s $cache_file) {
- $js = File::Slurp::read_file($cache_file);
- } else {
- $url .= ',+United+Kingdom' unless $url =~ /united\++kingdom$/ || $url =~ /uk$/i;
- $url .= '&key=' . mySociety::Config::get('GOOGLE_MAPS_API_KEY');
- $js = LWP::Simple::get($url);
- File::Slurp::write_file($cache_file, $js) if $js;
- }
-
- if (!$js) {
- $error = 'Sorry, we had a problem parsing that location. Please try again.';
- } elsif ($js =~ /BT\d/) {
- # Northern Ireland, hopefully
- $error = "We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.";
- } elsif ($js !~ /"code":200/) {
- $error = 'Sorry, we could not understand that location.';
- } elsif ($js =~ /},{/) { # Multiple
- while ($js =~ /"address":"(.*?)"/g) {
- push (@$error, $1);
- }
- $error = 'Sorry, we could not understand that location.' unless $error;
- } else {
- my ($accuracy) = $js =~ /"Accuracy": (\d)/;
- if ($accuracy < 5) {
- $error = 'Sorry, that location appears to be too general; please be more specific.';
- } else {
- $js =~ /"coordinates":\[(.*?),(.*?),/;
- my $lon = $1; my $lat = $2;
- ($easting, $northing) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G');
- my $xx = Page::os_to_tile($easting);
- my $yy = Page::os_to_tile($northing);
- $x = int($xx);
- $y = int($yy);
- $x -= 1 if ($xx - $x < 0.5);
- $y -= 1 if ($yy - $y < 0.5);
- }
- }
- return ($x, $y, $easting, $northing, $error);
-}
-
diff --git a/web/photo.cgi b/web/photo.cgi
index 392f1befa..d6d920007 100755
--- a/web/photo.cgi
+++ b/web/photo.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# photo.cgi:
# Display a photo for FixMyStreet
@@ -6,33 +6,13 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: photo.cgi,v 1.6 2007-06-17 09:40:51 matthew Exp $
+# $Id: photo.cgi,v 1.7 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use Error qw(:try);
use CGI::Carp;
-use Page;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
-
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
print $q->header(-type => 'image/jpeg',
@@ -55,7 +35,6 @@ sub main {
}
print $photo;
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/posters/index.cgi b/web/posters/index.cgi
index 252284125..a4f2fca2f 100755
--- a/web/posters/index.cgi
+++ b/web/posters/index.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../../perllib -I../../../perllib
# posters/index.cgi:
# List of publicity stuff on FixMyStreet
@@ -6,16 +6,11 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.4 2007-07-16 15:07:55 matthew Exp $
+# $Id: index.cgi,v 1.5 2007-08-29 23:03:17 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../../perllib";
-use lib "$FindBin::Bin/../../../perllib";
-use Page;
+use Standard -db;
+use mySociety::Config;
# XXX: Ugh, as we're in a subdirectory
BEGIN {
diff --git a/web/questionnaire.cgi b/web/questionnaire.cgi
index 603b1959c..6044d302d 100755
--- a/web/questionnaire.cgi
+++ b/web/questionnaire.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# questionnaire.cgi:
# Questionnaire for problem creators
@@ -6,35 +6,16 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: questionnaire.cgi,v 1.16 2007-08-17 10:33:24 matthew Exp $
+# $Id: questionnaire.cgi,v 1.17 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use Error qw(:try);
-
use CrossSell;
-use Page;
use mySociety::AuthToken;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
use mySociety::MaPit;
use mySociety::Web qw(ent);
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
sub main {
my $q = shift;
@@ -47,7 +28,6 @@ sub main {
print Page::header($q, title=>_('Questionnaire'));
print $out;
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
diff --git a/web/reports.cgi b/web/reports.cgi
index e4f8a7a65..f4823739c 100755
--- a/web/reports.cgi
+++ b/web/reports.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# report.cgi:
# Display summary reports for FixMyStreet
@@ -7,36 +7,17 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: reports.cgi,v 1.10 2007-08-27 20:29:34 matthew Exp $
+# $Id: reports.cgi,v 1.11 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use URI::Escape;
-
-use Page;
use mySociety::Alert;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh select_all);
+use mySociety::DBHandle qw(select_all);
use mySociety::MaPit;
use mySociety::Web qw(ent NewURL);
use mySociety::VotingArea;
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
my $all = $q->param('all') || 0;
@@ -76,15 +57,15 @@ sub main {
}
}
if (!$ward) { # Given a false ward name
- print $q->redirect('/reports/' . short_name($q_council));
+ print $q->redirect('/reports/' . Page::short_name($q_council));
return;
}
}
# RSS - reports for sent reports, area for all problems in area
if ($rss && $one_council) {
- my $url = short_name($q_council);
- $url .= '/' . short_name($q_ward) if $ward;
+ my $url = Page::short_name($q_council);
+ $url .= '/' . Page::short_name($q_ward) if $ward;
if ($rss eq 'area' && $area_type ne 'DIS' && $area_type ne 'CTY') {
# Two possibilites are the same for one-tier councils, so redirect one to the other
print $q->redirect('/rss/reports/' . $url);
@@ -164,7 +145,7 @@ sub main {
foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %councils) {
print '<tr align="center"';
print ' class="a"' if (++$c%2);
- my $url = short_name($areas_info->{$_}->{name});
+ my $url = Page::short_name($areas_info->{$_}->{name});
print '><td align="left"><a href="/reports/' . $url . '">' .
$areas_info->{$_}->{name} . '</a></td>';
summary_cell(\@{$open{$_}{new}});
@@ -183,10 +164,10 @@ sub main {
print $q->a({href => '/reports' }, 'Show all councils');
print ".";
} else {
- my $rss_url = '/rss/reports/' . short_name($name);
+ my $rss_url = '/rss/reports/' . Page::short_name($name);
my $thing = 'council';
if ($ward) {
- $rss_url .= '/' . short_name($q_ward);
+ $rss_url .= '/' . Page::short_name($q_ward);
$thing = 'ward';
$name = ent($q_ward) . ", $name";
}
@@ -217,7 +198,6 @@ sub main {
}
}
print Page::footer();
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
@@ -257,16 +237,3 @@ sub list_problems {
print '</ul>';
}
-sub short_name {
- my $name = shift;
- # Special case Durham as it's the only place with two councils of the same name
- return 'Durham+County' if ($name eq 'Durham County Council');
- return 'Durham+City' if ($name eq 'Durham City Council');
- $name =~ s/ (Borough|City|District|County) Council$//;
- $name =~ s/ Council$//;
- $name =~ s/ & / and /;
- $name = uri_escape($name);
- $name =~ s/%20/+/g;
- return $name;
-}
-
diff --git a/web/rss.cgi b/web/rss.cgi
index c3b33f8a3..bd75f0ce0 100755
--- a/web/rss.cgi
+++ b/web/rss.cgi
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl -w -I../perllib
# rss.cgi:
# RSS for FixMyStreet
@@ -6,69 +6,22 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: rss.cgi,v 1.17 2007-08-25 00:17:30 matthew Exp $
+# $Id: rss.cgi,v 1.18 2007-08-29 23:03:16 matthew Exp $
use strict;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../../perllib";
+use Standard;
use URI::Escape;
-
-use Page;
-use mySociety::Config;
-use mySociety::DBHandle qw(dbh);
use mySociety::Alert;
use mySociety::MaPit;
use mySociety::Web;
use mySociety::GeoUtil;
use mySociety::Gaze;
-BEGIN {
- mySociety::Config::set_file("$FindBin::Bin/../conf/general");
- mySociety::DBHandle::configure(
- Name => mySociety::Config::get('BCI_DB_NAME'),
- User => mySociety::Config::get('BCI_DB_USER'),
- Password => mySociety::Config::get('BCI_DB_PASS'),
- Host => mySociety::Config::get('BCI_DB_HOST', undef),
- Port => mySociety::Config::get('BCI_DB_PORT', undef)
- );
-}
-
sub main {
my $q = shift;
my $type = $q->param('type') || '';
if ($type eq 'local_problems') {
- my $x = $q->param('x');
- my $y = $q->param('y');
- my $lat = $q->param('lat');
- my $lon = $q->param('lon');
- my ($e, $n);
- if ($lat) { # In the UK, it'll never be 0 :)
- ($e, $n) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G');
- $x = Page::os_to_tile($e);
- $y = Page::os_to_tile($n);
- } elsif ($x && $y) {
- $e = Page::tile_to_os($x);
- $n = Page::tile_to_os($y);
- ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G');
- } else {
- die "Missing x/y or lat/lon parameter in RSS feed";
- }
- my $qs = "?x=$x;y=$y";
-
- my $d = $q->param('d');
- if ($d) {
- $qs .= ";d=$d";
- $d = 100 if $d > 100;
- } else {
- $d = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
- $d = int($d*10+0.5)/10;
- }
-
- mySociety::Alert::generate_rss($type, $qs, [$e, $n, $d]);
+ rss_local_problems($q);
} elsif ($type eq 'new_updates') {
my $id = $q->param('id');
my $qs = '?id='.$id;
@@ -89,7 +42,36 @@ sub main {
} else {
throw Error::Simple('Unknown alert type') unless $type;
}
- dbh()->rollback();
}
Page::do_fastcgi(\&main);
+sub rss_local_problems {
+ my $q = shift;
+ my $x = $q->param('x');
+ my $y = $q->param('y');
+ my $lat = $q->param('lat');
+ my $lon = $q->param('lon');
+ my ($e, $n);
+ if ($lat) { # In the UK, it'll never be 0 :)
+ ($e, $n) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G');
+ $x = Page::os_to_tile($e);
+ $y = Page::os_to_tile($n);
+ } elsif ($x && $y) {
+ $e = Page::tile_to_os($x);
+ $n = Page::tile_to_os($y);
+ ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G');
+ } else {
+ die "Missing x/y or lat/lon parameter in RSS feed";
+ }
+ my $qs = "?x=$x;y=$y";
+ my $d = $q->param('d');
+ if ($d) {
+ $qs .= ";d=$d";
+ $d = 100 if $d > 100;
+ } else {
+ $d = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
+ $d = int($d*10+0.5)/10;
+ }
+ mySociety::Alert::generate_rss('local_problems', $qs, [$e, $n, $d]);
+}
+