aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/Cobrand.pm246
-rw-r--r--perllib/CrossSell.pm16
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm7
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm7
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/FiksGataMi.pm2
-rw-r--r--perllib/FixMyStreet/Geocode.pm1
-rw-r--r--perllib/FixMyStreet/Map.pm1
-rw-r--r--perllib/FixMyStreet/Map/Tilma/Original.pm1
-rw-r--r--perllib/Problems.pm4
-rw-r--r--perllib/Standard.pm40
12 files changed, 14 insertions, 315 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
deleted file mode 100644
index 7d4382583..000000000
--- a/perllib/Cobrand.pm
+++ /dev/null
@@ -1,246 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Cobrand.pm:
-# Cobranding for FixMyStreet.
-#
-#
-# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
-# Email: louise@mysociety.org. WWW: http://www.mysociety.org
-#
-# $Id: Cobrand.pm,v 1.58 2010-01-06 12:33:25 louise Exp $
-
-package Cobrand;
-use strict;
-use Carp;
-
-=item get_allowed_cobrands
-
-Return an array reference of allowed cobrand subdomains
-
-=cut
-sub get_allowed_cobrands {
- my $allowed_cobrand_string = mySociety::Config::get('ALLOWED_COBRANDS');
- my @allowed_cobrands = split(/\|/, $allowed_cobrand_string);
- return \@allowed_cobrands;
-}
-
-# Cobrand calling functions
-my %fns = (
- # 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.
- 'site_restriction' => { default => '["", 0]' },
- # Return a contact restriction clause if the cobrand uses a subset of the FixMyStreet contact data.
- 'contact_restriction' => { default => "''" },
- # Return the base url to use in links in emails for the cobranded version of the site, parameter is extra data.
- 'base_url_for_emails' => { default => 'base_url($cobrand)' },
- # Base URL for the admin interface.
- 'admin_base_url' => { default => '0' },
- # URL for writetothem; parameter is COBRAND_DATA.
- 'writetothem_url' => { default => '0' },
- # Return the base url for the cobranded version of the site
- 'base_url' => { default => "mySociety::Config::get('BASE_URL')" },
- # Return the text that prompts the user to enter their postcode/place name. Parameter is QUERY
- 'enter_postcode_text' => { default => '""' },
- # Set the language and domain of the site based on the cobrand and host
- 'set_lang_and_domain' => { default => '\&default_set_lang_and_domain' },
- # Return HTML for a list of alert options for the cobrand, given QUERY and OPTIONS.
- 'alert_list_options' => { default => '0' },
- # Return N recent photos. If EASTING, NORTHING and DISTANCE are supplied, the photos must be attached to problems
- # within DISTANCE of the point defined by EASTING and NORTHING.
- 'recent_photos' => { default => '\&Problems::recent_photos' },
- # Return recent problems on the site.
- 'recent' => { default => '\&Problems::recent' },
- # Given a QUERY, return a block of html for showing front stats for the site
- 'front_stats' => { default => '\&Problems::front_stats' },
- # Given a STRING ($_[1]) representing a location and a QUERY, return a string that
- # includes any disambiguating information available
- 'disambiguate_location' => { default => '"$_[1]&gl=uk"' },
- # Parameter is EPOCHTIME
- 'prettify_epoch' => { default => '0' },
- # Parameters are FORM_NAME, QUERY. Return HTML for any extra needed elements for FORM_NAME
- 'form_elements' => { default => "''" },
- # Parameter is UPDATE_DATA, a reference to a hash of non-cobranded update data. Return cobrand extra data for the update
- 'cobrand_data_for_generic_update' => { default => "''" },
- # Parameter is PROBLEM_DATA, a reference to a hash of non-cobranded problem data. Return cobrand extra data for the problem
- 'cobrand_data_for_generic_problem' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with a problem
- 'extra_problem_data' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with an update
- 'extra_update_data' => { default => "''" },
- # Parameter is QUERY. Return a string of extra data to be stored with an alert
- 'extra_alert_data' => { default => "''" },
- # Given a QUERY, extract any extra data required by the cobrand
- 'extra_data' => { default => "''" },
- # Returns any extra text to be displayed with a PROBLEM.
- 'extra_problem_meta_text' => { default => "''" },
- # Returns any extra text to be displayed with an UPDATE.
- 'extra_update_meta_text' => { default => "''" },
- # Given a URL ($_[1]), QUERY, EXTRA_DATA, return a URL with any extra params needed appended to it.
- 'url' => { default => '$_[1]' },
- # Return any params to be added to responses
- 'header_params' => { default => '{}' },
- # Parameter is QUERY. Return some js to set the root path from which AJAX
- # queries should be made.
- 'root_path_js' => { default => "'var root_path = \"\";'" },
- # Return the title to be used in page heads.
- 'site_title' => { default => "''" },
- # Return the maximum number of items to be given in the list of reports on the map
- 'on_map_list_limit' => { default => 'undef' },
- # Return a boolean indicating whether the cobrand allows photo uploads
- 'allow_photo_upload' => { default => '1' },
- # Return a boolean indicating whether the cobrand allows the display of crosssell adverts
- 'allow_crosssell_adverts' => { default => '1' },
- # Return a boolean indicating whether the cobrand allows photo display
- 'allow_photo_display' => { default => '1' },
- # Return a boolean indication whether users should see links next to updates allowing them
- # to report them as offensive.
- 'allow_update_reporting' => { default => '0' },
- # Parameters are LOCATION, QUERY. Return a boolean indicating whether the
- # string LOCATION passes the cobrands checks.
- 'geocoded_string_check' => { default => '1' },
- # Paramters are COUNCILS, QUERY, CONTEXT. Return a boolean indicating whether
- # COUNCILS pass any extra checks. CONTEXT is where we are on the site.
- 'council_check' => { default => "[1, '']" },
- # Return an XSL to be used in rendering feeds
- 'feed_xsl' => { default => "'/xsl.xsl'" },
- # Return a boolean indicating whether the cobrand displays a report of all councils
- 'all_councils_report' => { default => '1' },
- # Return a boolean indicating whether people should be asked whether this
- # is the first time they've reported a problem.
- 'ask_ever_reported' => { default => '1' },
- # List of names of pages to display on the admin interface
- 'admin_pages' => { default => '0' },
- # Show the problem creation graph in the admin interface
- 'admin_show_creation_graph' => { default => '1' },
- # The MaPit types this site handles
- 'area_types' => { default => '[qw(DIS LBO MTD UTA CTY COI)]' },
- 'area_min_generation' => { default => '10' },
- # Some cobrands that use a Tilma map have a smaller mid-point to make pin centred
- 'tilma_mid_point' => { default => '""' },
-);
-
-foreach (keys %fns) {
- die "Default must be specified for $_" unless $fns{$_}{default} ne '';
- eval <<EOF;
-sub $_ {
- my (\$cobrand, \@args) = \@_;
- return call(\$cobrand, '$_', $fns{$_}{default}, \@args);
-}
-EOF
-}
-
-# This is the main Cobrand calling function that sees if the Cobrand handles
-# the function and responds appropriately.
-sub call {
- my ($cobrand, $fn, $default, @args) = @_;
- return call_default($default, @args) unless $cobrand;
- my $handle = cobrand_handle($cobrand);
- return call_default($default, @args) unless $handle && $handle->can($fn);
- return $handle->$fn(@args);
-}
-
-# If we're not in a Cobrand, or the Cobrand module doesn't offer a function,
-# this function works out how to return the default response
-sub call_default {
- my ($default, @args) = @_;
- return $default unless ref $default;
- return @$default if ref $default eq 'ARRAY'; # Arrays passed back as values
- return $default if ref $default eq 'HASH'; # Hashes passed back as reference
- return $default->(@args) if ref $default eq 'CODE'; # Functions are called.
- die "Default of $default treatment unknown";
-}
-
-=item cobrand_handle Q
-
-Given a query that has the name of a site set, return a handle to the Util module for that
-site, if one exists, or zero if not.
-
-=cut
-sub cobrand_handle {
- my $cobrand = shift;
-
- our %handles;
-
- # Once we have a handle defined, return it.
- return $handles{$cobrand} if defined $handles{$cobrand};
-
- my $cobrand_class = ucfirst($cobrand);
- my $class = "Cobrands::" . $cobrand_class . "::Util";
- eval "use $class";
-
- eval{ $handles{$cobrand} = $class->new };
- $handles{$cobrand} = 0 if $@;
- return $handles{$cobrand};
-}
-
-# Cobrand functions to fetch config variables
-%fns = (
- # Return the contact name for the cobranded version of the site
- # (to be used in emails).
- 'contact_name' => 'CONTACT_NAME',
- # Return the contact email for the cobranded version of the site
- 'contact_email' => 'CONTACT_EMAIL',
-);
-
-foreach (keys %fns) {
- eval <<EOF;
-sub $_ {
- my \$cobrand = shift;
- return get_cobrand_conf(\$cobrand, '$fns{$_}');
-}
-EOF
-}
-
-=item get_cobrand_conf COBRAND KEY
-
-Get the value for KEY from the config file for COBRAND
-
-=cut
-sub get_cobrand_conf {
- my ($cobrand, $key) = @_;
- my $value;
- if ($cobrand){
- (my $dir = __FILE__) =~ s{/[^/]*?$}{};
- if (-e "$dir/../conf/cobrands/$cobrand/general"){
- mySociety::Config::set_file("$dir/../conf/cobrands/$cobrand/general");
- $cobrand = uc($cobrand);
- $value = mySociety::Config::get($key . "_" . $cobrand, undef);
- mySociety::Config::set_file("$dir/../conf/general");
- }
- }
- if (!defined($value)){
- $value = mySociety::Config::get($key);
- }
- return $value;
-}
-
-=item email_host COBRAND
-
-Return the virtual host that sends email for this cobrand
-
-=cut
-
-sub email_host {
- my ($cobrand) = @_;
- my $email_vhost = mySociety::Config::get('EMAIL_VHOST');
- if ($cobrand) {
- $email_vhost = mySociety::Config::get('EMAIL_VHOST_'. uc($cobrand), $email_vhost);
- }
- if ($email_vhost && 'http://' . $email_vhost eq mySociety::Config::get('BASE_URL')) {
- return 1;
- } else {
- return 0;
- }
-}
-
-# Default things to do for the set_lang_and_domain call
-sub default_set_lang_and_domain {
- my ($lang, $unicode) = @_;
- mySociety::Locale::negotiate_language('en-gb,English,en_GB|nb,Norwegian,nb_NO', $lang); # XXX Testing
- mySociety::Locale::gettext_domain('FixMyStreet', $unicode);
- mySociety::Locale::change();
-}
-
-1;
-
diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm
index e40f2166f..44f971462 100644
--- a/perllib/CrossSell.pm
+++ b/perllib/CrossSell.pm
@@ -197,14 +197,14 @@ EOF
# Choose appropriate advert and display it.
# $this_site is to stop a site advertising itself.
sub display_advert ($$;$%) {
- my ($q, $email, $name, %data) = @_;
+ my ($c, $email, $name, %data) = @_;
- return '' unless $q->{site} eq 'fixmystreet';
+ return '' unless $c->cobrand->is_default;
if (defined $data{council} && $data{council} eq '2326') {
my ($out, $ad) = display_hfyc_cheltenham_advert($email, $name);
if ($out) {
- $q->{scratch} = "advert=$ad";
+ $c->stash->{scratch} = "advert=$ad";
return $out;
}
}
@@ -212,17 +212,17 @@ sub display_advert ($$;$%) {
#if ($data{lat}) {
# my $out = display_gny_groups($data{lon}, $data{lat});
# if ($out) {
- # $q->{scratch} = 'advert=gnygroups';
+ # $c->stash->{scratch} = 'advert=gnygroups';
# return '<div style="margin: 0 5em; border-top: dotted 1px #666666;">'
# . $out . '</div>';
# }
#}
- #$q->{scratch} = 'advert=demclub0';
+ #$c->stash->{scratch} = 'advert=demclub0';
#return display_democracyclub();
#unless (defined $data{done_tms} && $data{done_tms}==1) {
- $q->{scratch} = 'advert=news';
+ $c->stash->{scratch} = 'advert=news';
my $auth_signature = '';
unless (defined $data{emailunvalidated} && $data{emailunvalidated}==1) {
$auth_signature = mySociety::AuthToken::sign_with_shared_secret($email, mySociety::Config::get('AUTH_SHARED_SECRET'));
@@ -250,7 +250,7 @@ sub display_advert ($$;$%) {
my $out = &$func($email, $name, $advert_text);
use strict 'refs';
if ($out) {
- $q->{scratch} = "advert=$advert_id";
+ $c->stash->{scratch} = "advert=$advert_id";
return $out;
}
@@ -260,7 +260,7 @@ sub display_advert ($$;$%) {
}
}
- $q->{scratch} = 'advert=pb';
+ $c->stash->{scratch} = 'advert=pb';
return <<EOF;
<div id="advert_thin" style="text-align:center">
<h2 style="font-size: 150%">
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 579ee9b41..b76447233 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -73,7 +73,7 @@ sub index : Path : Args(0) {
$c->stash->{alerts} = \%alert_counts;
- my $contacts = $c->model('DB::Contact')->summary_count;
+ my $contacts = $c->model('DB::Contact')->summary_count( $c->cobrand->contact_restriction );
my %contact_counts =
map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index c14b7e9b1..5c52d0257 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -118,13 +118,6 @@ sub report_import : Path('/import') {
# anything else we return is plain text
$c->res->content_type('text/plain; charset=utf-8');
- # use strict;
- # use Standard;
- # use mySociety::AuthToken;
- # use mySociety::Config;
- # use mySociety::EvEl;
- # use mySociety::Locale;
-
my %input =
map { $_ => $c->req->param($_) || '' } (
'service', 'subject', 'detail', 'name', 'email', 'phone',
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index 5b20e286b..358e280c3 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -84,12 +84,7 @@ sub display_crosssell_advert {
my ( $self, $c, $email, $name, %data ) = @_;
return unless $c->cobrand->allow_crosssell_adverts();
-
- # fake up the old style $q
- my $q = { site => $c->cobrand->moniker, };
- $q->{site} = 'fixmystreet' if $q->{site} eq 'default';
-
- return CrossSell::display_advert( $q, $email, $name, %data );
+ return CrossSell::display_advert( $c, $email, $name, %data );
}
=head2 Utils::prettify_epoch
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index e02b208dc..b002dd7f2 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -87,7 +87,7 @@ FixMyStreet contact data.
=cut
sub contact_restriction {
- '';
+ {};
}
=head2 base_url_for_emails
diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
index 4dd2ef49a..eb7ea89a5 100644
--- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
+++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm
@@ -16,7 +16,7 @@ sub set_lang_and_domain {
}
sub enter_postcode_text {
- my ( $self, $q ) = @_;
+ my ( $self ) = @_;
return _('Enter a nearby postcode, or street name and area');
}
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index 50a7ba339..a520a2daa 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -17,7 +17,6 @@ use LWP::Simple;
use Digest::MD5 qw(md5_hex);
use URI::Escape;
-use Cobrand;
use Utils;
use mySociety::Config;
use mySociety::Locale;
diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm
index fc3f318c2..6b41c8d0d 100644
--- a/perllib/FixMyStreet/Map.pm
+++ b/perllib/FixMyStreet/Map.pm
@@ -20,7 +20,6 @@ use Module::Pluggable
my @ALL_MAP_CLASSES = allowed_maps();
use Problems;
-use Cobrand;
use mySociety::Config;
use mySociety::Gaze;
use mySociety::Locale;
diff --git a/perllib/FixMyStreet/Map/Tilma/Original.pm b/perllib/FixMyStreet/Map/Tilma/Original.pm
index 75177f3af..486a7c739 100644
--- a/perllib/FixMyStreet/Map/Tilma/Original.pm
+++ b/perllib/FixMyStreet/Map/Tilma/Original.pm
@@ -11,7 +11,6 @@ package FixMyStreet::Map::Tilma::Original;
use strict;
use LWP::Simple;
-use Cobrand;
use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::Web qw(ent NewURL);
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index c1430b540..c31fdd507 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -447,8 +447,8 @@ the cobrand if a cobrand is specified.
=cut
sub contact_counts {
- my ($cobrand) = @_;
- my $contact_restriction = Cobrand::contact_restriction($cobrand);
+ my ( $c ) = @_;
+ my $contact_restriction = $c->cobrand->contact_restriction;
my $contacts = dbh()->selectcol_arrayref("select confirmed, count(*) as c from contacts $contact_restriction group by confirmed", { Columns => [1,2] });
return $contacts;
}
diff --git a/perllib/Standard.pm b/perllib/Standard.pm
deleted file mode 100644
index 0a6f27490..000000000
--- a/perllib/Standard.pm
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/perl
-#
-# Standard.pm:
-# Common headers for Perl files. Mostly in the main namespace on purpose
-# (Filter::Macro sadly didn't work, CPAN bug #20494)
-#
-# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
-# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
-#
-# $Id: Standard.pm,v 1.3 2009-09-15 13:57:01 louise Exp $
-
-use strict;
-use warnings;
-require 5.8.0;
-
-# Horrible boilerplate to set up appropriate library paths.
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
-
-package Standard;
-
-sub import {
- my $package = shift;
- my $db = shift;
- unless ($db && $db eq '-db') {
- use mySociety::Config;
- use mySociety::DBHandle qw(dbh);
- (my $file = __FILE__) =~ s{/[^/]*?$}{};
- mySociety::Config::set_file("$file/../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::dbh = \&dbh;
- }
-}