#!/usr/bin/perl -w # # CrossSell.pm: # Adverts from FixMyStreet to another site. # # Unlike the PHP crosssell script, returns strings rather than prints them; # and currently displays the same advert if e.g. there's a connection problem. # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # # $Id: CrossSell.pm,v 1.17 2009-09-10 09:36:42 matthew Exp $ # Config parameters site needs set to call these functions: # OPTION_AUTH_SHARED_SECRET # OPTION_HEARFROMYOURMP_BASE_URL package CrossSell; use strict; use LWP::Simple qw($ua get); $ua->timeout(5); use URI::Escape; use mySociety::AuthToken; use mySociety::Web qw(ent); sub display_random_hfymp_advert { my ($email, $name, $text) = @_; $name ||= ''; my $auth_signature = mySociety::AuthToken::sign_with_shared_secret($email, mySociety::Config::get('AUTH_SHARED_SECRET')); # See if already signed up my $url = mySociety::Config::get('HEARFROMYOURMP_BASE_URL'); my $already_signed = get($url . '/authed?email=' . uri_escape($email) . "&sign=" . uri_escape($auth_signature)); # Different from PHP version; display this advert if e.g. connection problem return '' if $already_signed && $already_signed eq 'already signed'; $email = ent($email); $name = ent($name); $auth_signature = ent($auth_signature); $text =~ s#\[form\]#
EOF return ($out, "cheltenhamhfyc$rand"); } sub display_democracyclub { my (%input) = @_; return <Join Democracy Club and have fun keeping an eye on your election candidates. Sign me up!
EOF
}
sub display_news_form {
my (%input) = @_;
my %input_h = map { $_ => $input{$_} ? ent($input{$_}) : '' } qw(name email signed_email);
my $auth_signature = $input_h{signed_email};
return < Interested in hearing more about FixMyStreet successes? Enter your email
address below and we’ll send you occasional emails about what mySociety
and our users have been up to. mySociety respects your privacy, and we'll never sell or give away your private
details. You can unsubscribe at any time. Do you have an issue that’s too big for FixMyStreet?
#It could be time to petition your council. Try our new site:
#
$out
EOF
}
# Choose appropriate advert and display it.
# $this_site is to stop a site advertising itself.
sub display_advert ($$;$%) {
my ($c, $email, $name, %data) = @_;
return '' unless $c->cobrand->moniker eq 'fixmystreet';
#if (defined $data{council} && $data{council} eq '2326') {
# my ($out, $ad) = display_hfyc_cheltenham_advert($email, $name);
# if ($out) {
# $c->stash->{scratch} = "advert=$ad";
# return $out;
# }
#}
#if ($data{lat}) {
# my $out = display_gny_groups($data{lon}, $data{lat});
# if ($out) {
# $c->stash->{scratch} = 'advert=gnygroups';
# return '
#PetitionYourCouncil
and have a chance to discuss what they say in a public forum [form]Sign up to HearFromYourMP[/form]' ], #[ 'twfy_alerts0', '