diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/Cobrand.pm | 41 | ||||
-rw-r--r-- | perllib/Page.pm | 18 |
2 files changed, 48 insertions, 11 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm index 2441aff73..c780e28e8 100644 --- a/perllib/Cobrand.pm +++ b/perllib/Cobrand.pm @@ -7,7 +7,7 @@ # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: louise@mysociety.org. WWW: http://www.mysociety.org # -# $Id: Cobrand.pm,v 1.16 2009-09-15 17:42:43 louise Exp $ +# $Id: Cobrand.pm,v 1.17 2009-09-16 17:00:35 louise Exp $ package Cobrand; use strict; @@ -18,7 +18,7 @@ use Carp; Return an array reference of allowed cobrand subdomains =cut -sub get_allowed_cobrands{ +sub get_allowed_cobrands { my $allowed_cobrand_string = mySociety::Config::get('ALLOWED_COBRANDS'); my @allowed_cobrands = split(/\|/, $allowed_cobrand_string); return \@allowed_cobrands; @@ -53,7 +53,7 @@ sub cobrand_handle { Return a string containing the HTML to be rendered for a custom Cobranded page =cut -sub cobrand_page{ +sub cobrand_page { my $q = shift; my $cobrand = $q->{site}; my $handle = cobrand_handle($cobrand); @@ -68,7 +68,7 @@ data. Q is the query object. Returns an empty string and site key 0 if the cobra data. =cut -sub set_site_restriction{ +sub set_site_restriction { my $q = shift; my $site_restriction = ''; my $site_id = 0; @@ -83,7 +83,7 @@ sub set_site_restriction{ Return the base url for the cobranded version of the site =cut -sub base_url{ +sub base_url { my $cobrand = shift; return mySociety::Config::get('BASE_URL') unless $cobrand; my $handle = cobrand_handle($cobrand); @@ -91,6 +91,26 @@ sub base_url{ return $handle->base_url(); } +=item base_url_for_emails COBRAND + +Return the base url to use in links in emails for the cobranded +version of the site + +=cut + +sub base_url_for_emails { + my ($cobrand) = @_; + my $handle; + if ($cobrand){ + $handle = cobrand_handle($cobrand); + } + if ( !$cobrand || !$handle || ! $handle->can('base_url_for_emails')){ + return base_url($cobrand); + }{ + return $handle->base_url_for_emails(); + } +} + =item contact_email COBRAND Return the contact email for the cobranded version of the site @@ -104,11 +124,16 @@ sub contact_email { sub get_cobrand_conf { my ($cobrand, $key) = @_; my $value; - $cobrand = uc($cobrand); if ($cobrand){ - $value = mySociety::Config::get($key . "_" . $cobrand, undef); + (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 (!$value){ + if (!defined($value)){ $value = mySociety::Config::get($key); } return $value; diff --git a/perllib/Page.pm b/perllib/Page.pm index 1bb94bc58..b4610c3d4 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.pm,v 1.178 2009-09-15 17:42:43 louise Exp $ +# $Id: Page.pm,v 1.179 2009-09-16 17:00:35 louise Exp $ # package Page; @@ -125,9 +125,21 @@ sub get_cobrand { return $cobrand; } +=item base_url_with_lang Q REVERSE EMAIL + +Return the base URL for the site. Reverse the language component if REVERSE is set to one. If EMAIL is set to +one, return the base URL to use in emails. + +=cut + sub base_url_with_lang { - my ($q, $reverse) = @_; - my $base = Cobrand::base_url(get_cobrand($q)); + my ($q, $reverse, $email) = @_; + my $base; + if ($email) { + $base = Cobrand::base_url_for_emails(get_cobrand($q)); + } else { + $base = Cobrand::base_url(get_cobrand($q)); + } return $base unless $q->{site} eq 'emptyhomes'; my $lang = $mySociety::Locale::lang; if ($reverse && $lang eq 'en-gb') { |