diff options
author | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-02-21 11:19:22 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-02-21 11:19:22 +0000 |
commit | a375628603ffe50e4a96b4eacbe8606927b970ea (patch) | |
tree | 2bfd86381ebc8fb73db3b332d7589ce21ad1a4e8 | |
parent | 6722cb5711e23a0e801e415bb3928adf7eafaec8 (diff) | |
parent | 2ac9ea17dba28894cb3453da417a1648b026a2aa (diff) |
Merge branch 'master' of ssh://matthew@git.mysociety.org/data/git/public/fixmystreet
-rw-r--r-- | conf/httpd.conf | 1 | ||||
-rw-r--r-- | db/alert_types.sql | 22 | ||||
-rw-r--r-- | db/alert_types_eha.pl | 3 | ||||
-rw-r--r-- | db/alert_types_eha.sql | 11 | ||||
-rw-r--r-- | perllib/Cobrands/Barnet/Util.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Alert.pm | 2 | ||||
-rwxr-xr-x | web/alert.cgi | 19 | ||||
-rwxr-xr-x | web/index.cgi | 13 | ||||
-rwxr-xr-x | web/rss.cgi | 42 |
9 files changed, 100 insertions, 15 deletions
diff --git a/conf/httpd.conf b/conf/httpd.conf index 8bc50645a..1074b799d 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -66,6 +66,7 @@ RewriteRule ^/rss/l/([0-9.-]+)[,/]([0-9.-]+)$ /rss.cgi?type=local_pro RewriteRule ^/rss/([0-9]+)[,/]([0-9]+)/([0-9]+)$ /rss.cgi?type=local_problems;x=$1;y=$2;d=$3 [QSA] RewriteRule ^/rss/n/([0-9]+)[,/]([0-9]+)/([0-9]+)$ /rss.cgi?type=local_problems;e=$1;n=$2;d=$3 [QSA] RewriteRule ^/rss/l/([0-9.-]+)[,/]([0-9.-]+)/([0-9]+)$ /rss.cgi?type=local_problems;lat=$1;lon=$2;d=$3 [QSA] +RewriteRule ^/rss/pc/(.*)/([0-9]+)$ /rss.cgi?type=local_problems;pc=$1;d=$2 [QSA] RewriteRule ^/rss/pc/(.*)$ /rss.cgi?type=local_problems;pc=$1 [QSA] RewriteRule ^/rss/problems$ /rss.cgi?type=new_problems [QSA] diff --git a/db/alert_types.sql b/db/alert_types.sql index 82a8c71f8..fb1aac1d0 100644 --- a/db/alert_types.sql +++ b/db/alert_types.sql @@ -53,6 +53,28 @@ values ('local_problems_state', '', '', 'problem_find_nearby(?, ?, ?) as nearby,problem', 'nearby.problem_id = problem.id and problem.state in (?)', 'created desc', '{{title}}, {{confirmed}}', '/report/{{id}}', '{{detail}}', 'alert-problem-nearby'); +-- New problems around a postcode +insert into alert_type +(ref, head_sql_query, head_table, + head_title, head_link, head_description, + item_table, item_where, item_order, + item_title, item_link, item_description, template) +values ('postcode_local_problems', '', '', + 'New problems near {{POSTCODE}} on FixMyStreet', '/', 'The latest local problems reported by users', + 'problem_find_nearby(?, ?, ?) as nearby,problem', 'nearby.problem_id = problem.id and problem.state in (''confirmed'', ''fixed'')', 'created desc', + '{{title}}, {{confirmed}}', '/report/{{id}}', '{{detail}}', 'alert-problem-nearby'); + +-- New problems around a postcode with a particular state +insert into alert_type +(ref, head_sql_query, head_table, + head_title, head_link, head_description, + item_table, item_where, item_order, + item_title, item_link, item_description, template) +values ('postcode_local_problems_state', '', '', + 'New problems NEAR {{POSTCODE}} on FixMyStreet', '/', 'The latest local problems reported by users', + 'problem_find_nearby(?, ?, ?) as nearby,problem', 'nearby.problem_id = problem.id and problem.state in (?)', 'created desc', + '{{title}}, {{confirmed}}', '/report/{{id}}', '{{detail}}', 'alert-problem-nearby'); + -- New problems sent to a particular council insert into alert_type (ref, head_sql_query, head_table, diff --git a/db/alert_types_eha.pl b/db/alert_types_eha.pl index 0e0bdd162..3d707e030 100644 --- a/db/alert_types_eha.pl +++ b/db/alert_types_eha.pl @@ -18,6 +18,9 @@ _('New local reports on reportemptyhomes.com'), _('The latest local reports reported by users'), +# New problems around a postcode + _('New reports on reportemptyhomes.com near {{POSTCODE}}'), + # New problems sent to a particular council _('New reports to {{COUNCIL}} on reportemptyhomes.com'), _('The latest reports for {{COUNCIL}} reported by users'), diff --git a/db/alert_types_eha.sql b/db/alert_types_eha.sql index c949ea2f8..17f44fcd9 100644 --- a/db/alert_types_eha.sql +++ b/db/alert_types_eha.sql @@ -42,6 +42,17 @@ values ('local_problems', '', '', 'problem_find_nearby(?, ?, ?) as nearby,problem', 'nearby.problem_id = problem.id and problem.state in (''confirmed'', ''fixed'')', 'created desc', '{{title}}, {{confirmed}}', '/report/{{id}}', '{{detail}}', 'alert-problem-nearby'); +-- New problems around a postcode +insert into alert_type +(ref, head_sql_query, head_table, + head_title, head_link, head_description, + item_table, item_where, item_order, + item_title, item_link, item_description, template) +values ('postcode_local_problems', '', '', + 'New reports on reportemptyhomes.com near {{POSTCODE}}', '/', 'The latest local reports reported by users', + 'problem_find_nearby(?, ?, ?) as nearby,problem', 'nearby.problem_id = problem.id and problem.state in (''confirmed'', ''fixed'')', 'created desc', + '{{title}}, {{confirmed}}', '/report/{{id}}', '{{detail}}', 'alert-problem-nearby'); + -- New problems sent to a particular council insert into alert_type (ref, head_sql_query, head_table, diff --git a/perllib/Cobrands/Barnet/Util.pm b/perllib/Cobrands/Barnet/Util.pm index e0821e4ba..eb8b91649 100644 --- a/perllib/Cobrands/Barnet/Util.pm +++ b/perllib/Cobrands/Barnet/Util.pm @@ -79,7 +79,7 @@ sub council_check { } my $url = 'http://www.fixmystreet.com/'; $url .= 'alert' if $context eq 'alert'; - $url .= '?pc=' . URI::Escape::uri_escape($q->param('pc') if $q->param('pc'); + $url .= '?pc=' . URI::Escape::uri_escape($q->param('pc')) if $q->param('pc'); my $error_msg = "That location is not covered by Barnet. Please visit <a href=\"$url\">the main FixMyStreet site</a>."; return (0, $error_msg); diff --git a/perllib/FixMyStreet/Alert.pm b/perllib/FixMyStreet/Alert.pm index 4a6e63564..6b50e62e6 100644 --- a/perllib/FixMyStreet/Alert.pm +++ b/perllib/FixMyStreet/Alert.pm @@ -90,7 +90,7 @@ sub delete ($) { sub email_alerts ($) { my ($testing_email) = @_; my $url; - my $q = dbh()->prepare("select * from alert_type where ref not like 'local_problems%'"); + my $q = dbh()->prepare("select * from alert_type where ref not like '%local_problems%'"); $q->execute(); my $testing_email_clause = ''; while (my $alert_type = $q->fetchrow_hashref) { diff --git a/web/alert.cgi b/web/alert.cgi index 8924d97f5..fba7ef5d7 100755 --- a/web/alert.cgi +++ b/web/alert.cgi @@ -97,8 +97,11 @@ sub alert_list { return alert_front_page($q, $error) if $error; my $pretty_pc = $input_h{pc}; + my $pretty_pc_text;# This one isnt't getting the nbsp. if (mySociety::PostcodeUtil::is_valid_postcode($input{pc})) { $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($input{pc}); + $pretty_pc_text = $pretty_pc; + $pretty_pc_text =~ s/ //g; $pretty_pc =~ s/ / /; } @@ -291,17 +294,23 @@ feed, or enter your email address to subscribe to an email alert.')); <input type="radio" name="feed" id="local:$lat:$lon" value="local:$lat:$lon"$checked> <label for="local:$lat:$lon">$rss_label</label> EOF - my $rss_feed = Cobrand::url($cobrand, "/rss/l/$lat,$lon", $q); + my $rss_feed; + if ($pretty_pc_text) { + $rss_feed = Cobrand::url($cobrand, "/rss/pc/$pretty_pc_text/", $q); + } else { + $rss_feed = Cobrand::url($cobrand, "/rss/l/$lat,$lon/", $q); + } + my $default_link = Cobrand::url($cobrand, "/alert?type=local;feed=local:$lat:$lon", $q); my $rss_details = _('(a default distance which covers roughly 200,000 people)'); $out .= $rss_details; $out .= " <a href='$rss_feed'><img src='/i/feed.png' width='16' height='16' title='" . _('RSS feed of nearby problems') . "' alt='" . _('RSS feed') . "' border='0'></a>"; $out .= '</p> <p id="rss_local_alt">' . _('(alternatively the RSS feed can be customised, within'); - my $rss_feed_2k = Cobrand::url($cobrand, "/rss/l/$lat,$lon/2", $q); - my $rss_feed_5k = Cobrand::url($cobrand, "/rss/l/$lat,$lon/5", $q); - my $rss_feed_10k = Cobrand::url($cobrand, "/rss/l/$lat,$lon/10", $q); - my $rss_feed_20k = Cobrand::url($cobrand, "/rss/l/$lat,$lon/20", $q); + my $rss_feed_2k = Cobrand::url($cobrand, $rss_feed.'2', $q); + my $rss_feed_5k = Cobrand::url($cobrand, $rss_feed.'5', $q); + my $rss_feed_10k = Cobrand::url($cobrand, $rss_feed.'10', $q); + my $rss_feed_20k = Cobrand::url($cobrand, $rss_feed.'20', $q); $out .= <<EOF; <a href="$rss_feed_2k">2km</a> / <a href="$rss_feed_5k">5km</a> / <a href="$rss_feed_10k">10km</a> / <a href="$rss_feed_20k">20km</a>) diff --git a/web/index.cgi b/web/index.cgi index 003b51734..35786057b 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -937,6 +937,13 @@ sub display_location { ); my $pc_h = ent($q->param('pc') || ''); + my $rss_url; + if ($pc_h) { + $rss_url = "/rss/pc/" . URI::Escape::uri_escape($pc_h); + } else { + $rss_url = "/rss/l/$short_lat,$short_lon"; + } + my %vars = ( 'map' => FixMyStreet::Map::display_map($q, latitude => $latitude, longitude => $longitude, @@ -946,7 +953,11 @@ sub display_location { ), map_end => FixMyStreet::Map::display_map_end(1), url_home => Cobrand::url($cobrand, '/', $q), - url_rss => Cobrand::url($cobrand, NewURL($q, -retain => 1, -url=> "/rss/l/$short_lat,$short_lon", pc => undef, x => undef, y => undef, lat => undef, lon => undef ), $q), + url_rss => Cobrand::url( + $cobrand, + NewURL($q, -retain => 1, -url=> $rss_url, + pc => undef, x => undef, y => undef, lat=> undef, lon => undef ), + $q), url_email => Cobrand::url($cobrand, NewURL($q, -retain => 1, pc => undef, lat => $short_lat, lon => $short_lon, -url=>'/alert', feed=>"local:$short_lat:$short_lon"), $q), url_skip => $url_skip, email_me => _('Email me new local problems'), diff --git a/web/rss.cgi b/web/rss.cgi index 43c5b82b9..2d6f3a037 100755 --- a/web/rss.cgi +++ b/web/rss.cgi @@ -63,6 +63,7 @@ Page::do_fastcgi(\&main); sub rss_local_problems { my $q = shift; my $pc = $q->param('pc'); + my $x = $q->param('x'); my $y = $q->param('y'); my $lat = $q->param('lat'); @@ -82,6 +83,10 @@ sub rss_local_problems { $state = 'confirmed' if $state eq 'open'; + my $qs; + my %title_params; + my $alert_type; + my $cobrand = Page::get_cobrand($q); my $base = Cobrand::base_url($cobrand); if ($x && $y) { @@ -102,11 +107,22 @@ sub rss_local_problems { } catch Error::Simple with { $error = shift; }; - unless ($error) { + if ($error) { + return ''; + } else { ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); - print $q->redirect(-location => "$base/rss/l/$lat,$lon$d_str$state_qs"); + + my $pretty_pc = $pc; + if (mySociety::PostcodeUtil::is_valid_postcode($pc)) { + $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($pc); + } + my $pretty_pc_escaped = URI::Escape::uri_escape_utf8($pretty_pc); + $pretty_pc_escaped =~ s/%20/+/g; + $qs = "?pc=$pretty_pc_escaped"; + + $title_params{'POSTCODE'} = encode_utf8($pretty_pc); } - return ''; + # pass through rather than redirecting. } elsif ( $lat || $lon ) { # pass through } else { @@ -116,7 +132,9 @@ sub rss_local_problems { # truncate the lat,lon for nicer urls ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); - my $qs = "?lat=$lat;lon=$lon"; + if (!$qs) { + $qs = "?lat=$lat;lon=$lon"; + } if ($d) { $qs .= ";d=$d"; @@ -127,10 +145,20 @@ sub rss_local_problems { } my $xsl = Cobrand::feed_xsl($cobrand); - if ($state eq 'all') { - return FixMyStreet::Alert::generate_rss('local_problems', $xsl, $qs, [$lat, $lon, $d], undef, $cobrand, $q); + + if ($pc) { + $alert_type = 'postcode_local_problems'; } else { - return FixMyStreet::Alert::generate_rss('local_problems_state', $xsl, $qs, [$lat, $lon, $d, $state], undef, $cobrand, $q); + $alert_type = 'local_problems'; } + + my @db_params = ($lat, $lon, $d); + + if ($state ne 'all') { + $alert_type .= '_state'; + push @db_params, $state; + } + + return FixMyStreet::Alert::generate_rss($alert_type, $xsl, $qs, \@db_params, \%title_params, $cobrand, $q); } |