Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r9325: LJRU-2138: Special URLs to count how man...

Committer: gariev
LJRU-2138: Special URLs to count how many people hit the link (and redirect them to their actual link)
U   trunk/cgi-bin/LJ/Hooks/SUP.pm
Modified: trunk/cgi-bin/LJ/Hooks/SUP.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/SUP.pm	2010-08-10 08:03:40 UTC (rev 9324)
+++ trunk/cgi-bin/LJ/Hooks/SUP.pm	2010-08-10 08:52:26 UTC (rev 9325)
@@ -884,4 +884,37 @@
 
 LJ::register_hook('has_image_dangerous_content', sub { require LJ::ImageContent; LJ::ImageContent::has_image_dangerous_content (@_); });
 
+LJ::register_hook("should_redirect", sub {
+    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 
+            && $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);
+
+            return $url;
+        }
+        ## else - if not handled here, /redirect/... url will return 404
+    }
+});
+
+
+
 1;

Tags: gariev, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments