aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rwxr-xr-xweb/flickr.cgi116
-rwxr-xr-xweb/flickr2.cgi71
-rwxr-xr-xweb/index.cgi129
-rwxr-xr-xweb/photo.cgi4
4 files changed, 283 insertions, 37 deletions
diff --git a/web/flickr.cgi b/web/flickr.cgi
new file mode 100755
index 000000000..f5651b12e
--- /dev/null
+++ b/web/flickr.cgi
@@ -0,0 +1,116 @@
+#!/usr/bin/perl -w
+
+# flickr.cgi:
+# Register for Flickr usage, and update photos
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: flickr.cgi,v 1.1 2007-06-17 09:40:51 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 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');
+ my $out = '';
+ if (my $token = $q->param('token')) {
+ my $email = mySociety::AuthToken::retrieve('flickr', $token);
+ if ($email) {
+ my $key = mySociety::Config::get('FLICKR_API');
+ my $url = 'http://api.flickr.com/services/rest/?method=flickr.people.findByEmail&api_key='.$key.'&find_email='.$email;
+ my $result = get($url);
+ my ($nsid) = $result =~ /nsid="([^"]*)"/;
+ $url = 'http://api.flickr.com/services/rest/?method=flickr.people.getInfo&api_key='.$key.'&user_id='.$nsid;
+ $result = get($url);
+ my ($name) = $result =~ /<realname>(.*?)<\/realname>/;
+
+ my $id = dbh()->selectrow_array("select nextval('flickr_id_seq');");
+ dbh()->do("insert into flickr (id, nsid, name, email) values (?, ?, ?, ?)", {},
+ $id, $nsid, $name, $email);
+ dbh()->commit();
+ $out .= $q->p('Thanks for confirming your email address. Please now tag
+your photos with FixMyStreet (and geo-tag them if you want/can, automatically if possible!)
+for us to pick them up.');
+ } else {
+ $out = $q->p(_(<<EOF));
+Thank you for trying to register for your Flickr photos. 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 $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/flickr-confirm");
+ my %h = ();
+ my $token = mySociety::AuthToken::store('flickr', $email);
+ $h{url} = mySociety::Config::get('BASE_URL') . '/F/' . $token;
+
+ my $body = mySociety::Email::construct_email({
+ _template_ => $template,
+ _parameters_ => \%h,
+ To => $email,
+ From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ],
+ });
+
+ my $result;
+ $result = mySociety::EmailUtil::send_email($body, mySociety::Config::get('CONTACT_EMAIL'), $email);
+ if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) {
+ $out = 'Thanks, we\'ve sent you a confirmation email!';
+ dbh()->commit();
+ } else {
+ $out = 'Sorry, something went wrong - very alpha!';
+ dbh()->rollback();
+ }
+ } else {
+ $out .= <<EOF;
+<p><strong>Very alpha status</strong></p>
+<p>Using the Flickr API, FixMyStreet can utilise all the methods of uploading photos to Flickr
+to report problems to your council:</p>
+<ol>
+<li>Register that you're going to be using Flickr here, so we know to check your photos.
+<li>Upload your photo to Flickr, for example via camera phone on location
+<li>Tag the photo with FixMyStreet when uploading, or afterwards;
+<li>Locate the problem on Flickr's map (if you have GPS, this should be done automatically :) )
+<li>FixMyStreet will find the photo, and ask you to add/ check the details;
+<li>The report is then sent to the council.
+</ol>
+
+<form method="post">
+<p>To begin, please enter your Flickr email address, both so we know the account to watch and
+so we can email you when you upload FixMyStreet photos with a link to check and confirm
+the details: <input type="text" name="email" value="" size="30">
+<input type="submit" value="Go">
+</p></form>
+EOF
+ }
+
+ print $out;
+ print Page::footer();
+ dbh()->rollback();
+}
+Page::do_fastcgi(\&main);
+
diff --git a/web/flickr2.cgi b/web/flickr2.cgi
new file mode 100755
index 000000000..71cc07f39
--- /dev/null
+++ b/web/flickr2.cgi
@@ -0,0 +1,71 @@
+#!/usr/bin/perl -w
+
+# flickr2.cgi:
+# Check photo details, and confirm for council
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: flickr2.cgi,v 1.1 2007-06-17 09:40:51 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 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 = '';
+ if (my $token = $q->param('token')) {
+ my $id = mySociety::AuthToken::retrieve('flickr', $token);
+ if ($id) {
+ my ($e, $n, $name, $email, $title) = dbh()->selectrow_array(
+ "select easting,northing,name,email,title from problem where id=? and state='flickr'", {}, $id);
+ if ($email) {
+ $name = uri_escape($name);
+ $email = uri_escape($email);
+ $title = uri_escape($title);
+ # XXX: Look up some of this stuff at the destination instead???
+ print $q->redirect("/?flickr=$token;submit_map=1;easting=$e;northing=$n;name=$name;email=$email;title=$title;anonymous=1");
+ exit;
+ }
+ $out = $q->p("That report appears to have been checked already.");
+ } else {
+ $out = $q->p(_(<<EOF));
+Thank you for trying to register for your Flickr photos. 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
+ }
+ } else {
+ $out .= $q->p('You need a token to get to this page!');
+ }
+
+ 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 32ee880a1..0f80b1bde 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.140 2007-06-16 19:42:25 matthew Exp $
+# $Id: index.cgi,v 1.141 2007-06-17 09:40:51 matthew Exp $
use strict;
require 5.8.0;
@@ -95,8 +95,27 @@ EOF
my $fixed = dbh()->selectrow_array("select count(*) from problem where state='fixed' and lastupdate>ms_current_timestamp()-'1 month'::interval");
my $updates = dbh()->selectrow_array("select count(*) from comment where state='confirmed'");
my $new = dbh()->selectrow_array("select count(*) from problem where state in ('confirmed','fixed') and confirmed>ms_current_timestamp()-'1 week'::interval");
+ $out .= '<form action="./" method="get" id="postcodeForm">';
+ if (my $token = $q->param('flickr')) {
+ my $id = mySociety::AuthToken::retrieve('flickr', $token);
+ if ($id) {
+ my $name = ent($q->param('name'));
+ my $email = ent($q->param('email'));
+ my $title = ent($q->param('title'));
+ $out .= <<EOF;
+<p style="margin-top:0;color: #cc0000;">Thanks for uploading your photo via Flickr! We need to locate your problem,
+so please enter a nearby street name or postcode in the box below...</p>
+
+<input type="hidden" name="flickr" value="$token">
+<input type="hidden" name="submit_map" value="1">
+<input type="hidden" name="name" value="$name">
+<input type="hidden" name="email" value="$email">
+<input type="hidden" name="title" value="$title">
+<input type="hidden" name="anonymous" value="1">
+EOF
+ }
+ }
$out .= <<EOF;
-<form action="./" method="get" id="postcodeForm">
<label for="pc">Enter a nearby postcode, or street name and area:</label>
&nbsp;<input type="text" name="pc" value="$pc_h" id="pc" size="10" maxlength="200">
&nbsp;<input type="submit" value="Go" id="submit">
@@ -182,7 +201,7 @@ sub submit_update {
sub submit_problem {
my $q = shift;
- my @vars = qw(council title detail name email phone pc easting northing skipped anonymous category);
+ my @vars = qw(council title detail name email phone pc easting northing skipped anonymous category flickr);
my %input = map { $_ => scalar $q->param($_) } @vars;
my @errors;
@@ -275,43 +294,61 @@ sub submit_problem {
my $used_map = $input{skipped} ? 'f' : 't';
$input{category} = 'Other' unless $input{category};
- my $id = dbh()->selectrow_array("select nextval('problem_id_seq');");
- # This is horrid
- my $s = dbh()->prepare("insert into problem
- (id, postcode, easting, northing, title, detail, name,
- email, phone, photo, state, council, used_map, anonymous, category)
- values
- (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed', ?, ?, ?, ?)");
- $s->bind_param(1, $id);
- $s->bind_param(2, $input{pc});
- $s->bind_param(3, $input{easting});
- $s->bind_param(4, $input{northing});
- $s->bind_param(5, $input{title});
- $s->bind_param(6, $input{detail});
- $s->bind_param(7, $input{name});
- $s->bind_param(8, $input{email});
- $s->bind_param(9, $input{phone});
- $s->bind_param(10, $image, { pg_type => DBD::Pg::PG_BYTEA });
- $s->bind_param(11, $input{council});
- $s->bind_param(12, $used_map);
- $s->bind_param(13, $input{anonymous} ? 'f': 't');
- $s->bind_param(14, $input{category});
- $s->execute();
- my %h = ();
- $h{title} = $input{title};
- $h{detail} = $input{detail};
- $h{name} = $input{name};
- $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id);
- dbh()->commit();
-
- my $out = Page::send_email($input{email}, $input{name}, 'problem', %h);
+ my ($id, $out);
+ if (my $token = $input{flickr}) {
+ my $id = mySociety::AuthToken::retrieve('flickr', $token);
+ if ($id) {
+ dbh()->do("update problem set easting=?, northing=?, title=?, detail=?,
+ name=?, email=?, phone=?, state='confirmed', council=?, used_map='t',
+ anonymous=?, category=?, confirmed=ms_current_timestamp(),
+ lastupdate=ms_current_timestamp() where id=?", {}, $input{easting}, $input{northing},
+ $input{title}, $input{detail}, $input{name}, $input{email},
+ $input{phone}, $input{council}, $input{anonymous} ? 'f' : 't',
+ $input{category}, $id);
+ dbh()->commit();
+ $out = $q->p(sprintf(_('You have successfully confirmed your problem and you can now <a href="%s">view it on the site</a>.'), "/?id=$id"));
+ } else {
+ $out = $q->p('There appears to have been a problem.');
+ }
+ } else {
+ $id = dbh()->selectrow_array("select nextval('problem_id_seq');");
+ # This is horrid
+ my $s = dbh()->prepare("insert into problem
+ (id, postcode, easting, northing, title, detail, name,
+ email, phone, photo, state, council, used_map, anonymous, category)
+ values
+ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'unconfirmed', ?, ?, ?, ?)");
+ $s->bind_param(1, $id);
+ $s->bind_param(2, $input{pc});
+ $s->bind_param(3, $input{easting});
+ $s->bind_param(4, $input{northing});
+ $s->bind_param(5, $input{title});
+ $s->bind_param(6, $input{detail});
+ $s->bind_param(7, $input{name});
+ $s->bind_param(8, $input{email});
+ $s->bind_param(9, $input{phone});
+ $s->bind_param(10, $image, { pg_type => DBD::Pg::PG_BYTEA });
+ $s->bind_param(11, $input{council});
+ $s->bind_param(12, $used_map);
+ $s->bind_param(13, $input{anonymous} ? 'f': 't');
+ $s->bind_param(14, $input{category});
+ $s->execute();
+ my %h = ();
+ $h{title} = $input{title};
+ $h{detail} = $input{detail};
+ $h{name} = $input{name};
+ $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id);
+ dbh()->commit();
+
+ $out = Page::send_email($input{email}, $input{name}, 'problem', %h);
+ }
return $out;
}
sub display_form {
my ($q, @errors) = @_;
my ($pin_x, $pin_y, $pin_tile_x, $pin_tile_y) = (0,0,0,0);
- my @vars = qw(title detail name email phone pc easting northing x y skipped council anonymous);
+ my @vars = qw(title detail name email phone pc easting northing x y skipped council anonymous flickr);
my %input = map { $_ => $q->param($_) || '' } @vars;
my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars;
my @ps = $q->param;
@@ -323,7 +360,8 @@ sub display_form {
unless ($pin_x && $pin_y)
|| ($input{easting} && $input{northing})
|| ($input{skipped} && $input{x} && $input{y})
- || ($input{skipped} && $input{pc});
+ || ($input{skipped} && $input{pc})
+ || ($input{flickr} && $input{pc});
my $out = '';
my ($px, $py, $easting, $northing, $island);
@@ -344,8 +382,17 @@ sub display_form {
$py = Page::tile_to_px($pin_y, $input{y});
$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;
+ $input{x} = int(Page::os_to_tile($easting));
+ $input{y} = int(Page::os_to_tile($northing));
+ $px = Page::os_to_px($easting, $input{x});
+ $py = Page::os_to_px($northing, $input{y});
} else {
# Normal form submission
+ $input{x} = int(Page::os_to_tile($input{easting}));
+ $input{y} = int(Page::os_to_tile($input{northing}));
$px = Page::os_to_px($input{easting}, $input{x});
$py = Page::os_to_px($input{northing}, $input{y});
$easting = $input_h{easting};
@@ -475,8 +522,20 @@ $category
<div><label for="form_phone">Phone:</label>
<input type="text" value="$input_h{phone}" name="phone" id="form_phone" size="20">
<small>(optional, so the council can get in touch)</small></div>
+EOF
+ if (my $token = $input{flickr}) {
+ my $id = mySociety::AuthToken::retrieve('flickr', $token);
+ if ($id) {
+ $out .= '<p>The photo you uploaded was:</p> <input type="hidden" name="flickr" value="' . $token . '">';
+ $out .= '<p align="center"><img src="/photo?id=' . $id . '"></p>';
+ }
+ } else {
+ $out .= <<EOF;
<div><label for="form_photo">Photo:</label>
<input type="file" name="photo" id="form_photo"></div>
+EOF
+ }
+ $out .= <<EOF;
<p>Please note:</p>
<ul>
<li>Please be polite, concise and to the point.
diff --git a/web/photo.cgi b/web/photo.cgi
index 41e9221ef..392f1befa 100755
--- a/web/photo.cgi
+++ b/web/photo.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: photo.cgi,v 1.5 2007-06-15 14:57:52 matthew Exp $
+# $Id: photo.cgi,v 1.6 2007-06-17 09:40:51 matthew Exp $
use strict;
require 5.8.0;
@@ -39,7 +39,7 @@ sub main {
-expires => '+1y' );
my $id = $q->param('id') || return;
my $problem = dbh()->selectrow_arrayref(
- "select photo from problem where id=? and state in ('confirmed', 'fixed')
+ "select photo from problem where id=? and state in ('confirmed', 'fixed', 'flickr')
and photo is not null", {}, $id);
return unless $problem;
my $photo = $problem->[0];