[ljcom] r10225: LJSUP-8111: created redirect for campaig...
Committer: slobin
LJSUP-8111: created redirect for campaigns (by key)M SUP.pm
U trunk/cgi-bin/LJ/Hooks/SUP.pm
Modified: trunk/cgi-bin/LJ/Hooks/SUP.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/SUP.pm 2011-03-11 05:00:40 UTC (rev 10224)
+++ trunk/cgi-bin/LJ/Hooks/SUP.pm 2011-03-11 05:02:16 UTC (rev 10225)
@@ -963,30 +963,42 @@
my ($host, $uri, $get) = @_;
if ($host eq $LJ::DOMAIN_WEB && $uri =~ m!^/redirect/!) {
- my $url = $get->{'url'};
- if ($url
- && $url =~ m! ^ https?:// [-\w.]*? ([-\w]+ \. [-\w]+) / !x
+
+ my ($campaign_key) = $uri =~ m!/redirect/([\w\d\_]+)!;
+ my $url;
+
+ use Apache::WURFL;
+ # first try to match campaign
+ if($LJ::CAMPAIGN_URIS{$campaign_key}) {
+ $url = $LJ::CAMPAIGN_URIS{$campaign_key}{ Apache::WURFL->is_mobile ? 'mobile' : 'pc' };
+ # if no campaigns found and we have url, take it
+ } elsif ($get->{'url'}
+ && $get->{'url'} =~ m! ^ https?:// [-\w.]*? ([-\w]+ \. [-\w]+) / !x
&& $LJ::ALLOWED_REDIRECT_TO_DOMAIN{$1})
{
- ##
- ## Notify BinAccessLogs (XCounter1) explicitely, since PerlCleanupHandler (where the logging is done)
- ## is not called for requests ended by redirect under mod_perl/Apache 1.
- ## Warnings:
- ## 1) AccessLogRecord is not fully initialized here.
- ## 2) Under mod_perl2, AccessLogSink will be notified twice, field _explicit is used for unambiguity.
- ## Status and content type are faked so that log records are counted by XCounter1.
- ##
- use LJ::AccessLogSink::BinAccessLogs;
- use LJ::AccessLogRecord;
- my $log_record = LJ::AccessLogRecord->new;
- $log_record->{'ctype'} = 'text/html';
- $log_record->{'status'} = 200;
- $log_record->{'_explicit'} = 1;
- LJ::AccessLogSink::BinAccessLogs->new->log($log_record);
+ $url = $get->{'url'};
+ ## if not handled here, /redirect/... url will return 404
+ } else {
+ return;
+ }
- return $url;
- }
- ## else - if not handled here, /redirect/... url will return 404
+ ##
+ ## Notify BinAccessLogs (XCounter1) explicitely, since PerlCleanupHandler (where the logging is done)
+ ## is not called for requests ended by redirect under mod_perl/Apache 1.
+ ## Warnings:
+ ## 1) AccessLogRecord is not fully initialized here.
+ ## 2) Under mod_perl2, AccessLogSink will be notified twice, field _explicit is used for unambiguity.
+ ## Status and content type are faked so that log records are counted by XCounter1.
+ ##
+ use LJ::AccessLogSink::BinAccessLogs;
+ use LJ::AccessLogRecord;
+ my $log_record = LJ::AccessLogRecord->new;
+ $log_record->{'ctype'} = 'text/html';
+ $log_record->{'status'} = 200;
+ $log_record->{'_explicit'} = 1;
+ LJ::AccessLogSink::BinAccessLogs->new->log($log_record);
+
+ return $url;
}
});
