diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-07-06 15:07:58 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-07-06 15:41:04 +0100 |
commit | 222727d7e879838e5c47cf0eb07e739c7969fdae (patch) | |
tree | 63acdd3bb3654e0a8393ff504cff729e22a8073e | |
parent | 9a696b0cb64667ed4608021771aed441a09f3ac0 (diff) |
Make RSS feeds act same as email alerts with links to main site.
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 5 |
4 files changed, 13 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index f898d06a0..4bec33057 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -205,14 +205,10 @@ sub query_main : Private { my ( $self, $c ) = @_; my $alert_type = $c->stash->{alert_type}; - my ( $sql_restriction ) = $c->cobrand->sql_restriction( $c->cobrand->extra_data ); - # Only apply a site restriction if the alert uses the problem table - $sql_restriction = '' unless $alert_type->item_table eq 'problem'; - # FIXME Do this in a nicer way at some point in the future... my $query = 'select * from ' . $alert_type->item_table . ' where ' . ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '') - . $alert_type->item_where . $sql_restriction . ' order by ' + . $alert_type->item_where . ' order by ' . $alert_type->item_order; my $rss_limit = mySociety::Config::get('RSS_LIMIT'); $query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/; @@ -250,7 +246,13 @@ sub add_row : Private { (my $title = _($alert_type->item_title)) =~ s/{{(.*?)}}/$row->{$1}/g; (my $link = $alert_type->item_link) =~ s/{{(.*?)}}/$row->{$1}/g; (my $desc = _($alert_type->item_description)) =~ s/{{(.*?)}}/$row->{$1}/g; - my $url = $c->uri_for( $link ); + + my $hashref_restriction = $c->cobrand->site_restriction; + my $base_url = $c->cobrand->base_url; + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} && $row->{council} ne $hashref_restriction->{council} ) { + $base_url = $c->config->{BASE_URL}; + } + my $url = $base_url . $link; if ( $row->{postcode} ) { my $pc = $c->cobrand->format_postcode( $row->{postcode} ); @@ -268,7 +270,7 @@ sub add_row : Private { if ($c->cobrand->allow_photo_display && $row->{photo}) { my $key = $alert_type->item_table eq 'comment' ? 'c/' : ''; - $item{description} .= ent("\n<br><img src=\"". $c->cobrand->base_url . "/photo/$key$row->{id}.jpeg\">"); + $item{description} .= ent("\n<br><img src=\"". $base_url . "/photo/$key$row->{id}.jpeg\">"); } if ( $row->{used_map} ) { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index a987cf65d..3c6d6b273 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -44,13 +44,12 @@ sub problems { =head1 site_restriction -Return a site restriction clause and a site key if the cobrand uses a subset of -the FixMyStreet data. Parameter is any extra data the cobrand needs. Returns an -empty string and site key 0 if the cobrand uses all the data. +Return a site key and a hash of extra query parameters if the cobrand uses a +subset of the FixMyStreet data. Parameter is any extra data the cobrand needs. +Returns a site key of 0 and an empty hash if the cobrand uses all the data. =cut -sub sql_restriction { return ""; } sub site_restriction { return {}; } sub site_key { return 0; } diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 1627616bd..d0b000102 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -11,16 +11,6 @@ sub council_url { return 'lichfielddc'; } # Different to councils parent due to this being a two-tier council. If we get # more, this can be genericised in the parent. -sub site_restriction { - return { council => '2434' }; -} -sub sql_restriction { - return "and council like '%2434%'"; -} -sub site_key { - return 'lichfield'; -} - sub problems_clause { return { council => { like => '%2434%' } }; } diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index bb71bdd35..6d324c68a 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -15,10 +15,6 @@ sub site_restriction { my $self = shift; return { council => sprintf('%d', $self->council_id) }; } -sub sql_restriction { - my $self = shift; - return "and council='" . $self->council_id . "'"; -} sub site_key { my $self = shift; return $self->council_url; @@ -28,6 +24,7 @@ sub restriction { return { cobrand => shift->moniker }; } +# Different function to site_restriction due to two-tier use sub problems_clause { my $self = shift; return { council => sprintf('%d', $self->council_id) }; |