diff options
Diffstat (limited to 'perllib/FixMyStreet/Cobrand.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand.pm | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm index ad21820d7..647261e32 100644 --- a/perllib/FixMyStreet/Cobrand.pm +++ b/perllib/FixMyStreet/Cobrand.pm @@ -18,31 +18,50 @@ my @ALL_COBRAND_CLASSES = __PACKAGE__->_cobrands; =head2 get_allowed_cobrands -Return an array reference of allowed cobrand subdomains +Return an array reference of allowed cobrand monikers and hostname substrings. =cut sub get_allowed_cobrands { - my $allowed_cobrand_string = FixMyStreet->config('ALLOWED_COBRANDS'); - my @allowed_cobrands = split( /\|/, $allowed_cobrand_string ); + my $class = shift; + my @allowed_cobrands = map { + ref $_ ? { moniker => keys %$_, host => values %$_ } + : { moniker => $_, host => $_ } + } @{ $class->_get_allowed_cobrands }; return \@allowed_cobrands; } +=head2 _get_allowed_cobrands + +Simply returns the config variable (so this function can be overridden in test suite). + +=cut + +sub _get_allowed_cobrands { + return FixMyStreet->config('ALLOWED_COBRANDS'); +} + =head2 available_cobrand_classes @available_cobrand_classes = FixMyStreet::Cobrand->available_cobrand_classes(); -Return an array of all the classes that were found and that have monikers that -match the values from get_allowed_cobrands. +Return an array of all the classes that were found and that have monikers +that match the values from get_allowed_cobrands, in the order of +get_allowed_cobrands. =cut sub available_cobrand_classes { my $class = shift; - my %allowed = map { $_ => 1 } @{ $class->get_allowed_cobrands }; - my @avail = grep { $allowed{ $_->moniker } } @ALL_COBRAND_CLASSES; + my %all = map { $_->moniker => $_ } @ALL_COBRAND_CLASSES; + my @avail; + foreach (@{ $class->get_allowed_cobrands }) { + next unless $all{$_->{moniker}}; + $_->{class} = $all{$_->{moniker}}; + push @avail, $_; + } return @avail; } @@ -60,8 +79,7 @@ sub get_class_for_host { my $host = shift; foreach my $avail ( $class->available_cobrand_classes ) { - my $moniker = $avail->moniker; - return $avail if $host =~ m{$moniker}; + return $avail->{class} if $host =~ /$avail->{host}/; } # if none match then use the default @@ -81,7 +99,7 @@ sub get_class_for_moniker { my $moniker = shift; foreach my $avail ( $class->available_cobrand_classes ) { - return $avail if $moniker eq $avail->moniker; + return $avail->{class} if $moniker eq $avail->{moniker}; } # Special case for old blank cobrand entries in fixmystreet.com. |