From 17d6151832d1e0a2a0aa718ff29fe8a22e4ee2d4 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 26 Apr 2008 18:59:48 +0000 Subject: [PATCH] some updates to URL and content handlers to make them a bit more flexible --- docs/upgrades/upgrade_7.5.10-7.5.11.pl | 18 +++++++++ lib/WebGUI.pm | 15 +++++-- lib/WebGUI/Content/Referral.pm | 55 ++++++++++++++++++++++++++ lib/WebGUI/URL/Content.pm | 3 +- lib/WebGUI/URL/Credits.pm | 2 +- lib/WebGUI/URL/PassThru.pm | 2 +- lib/WebGUI/URL/Snoop.pm | 2 +- lib/WebGUI/URL/Uploads.pm | 2 +- lib/WebGUI/URL/_url.skeleton | 4 +- 9 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 lib/WebGUI/Content/Referral.pm diff --git a/docs/upgrades/upgrade_7.5.10-7.5.11.pl b/docs/upgrades/upgrade_7.5.10-7.5.11.pl index 8e5868f4f..eedb6dc74 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -24,6 +24,7 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here +addReferralHandler( $session ); addCalendarEventWorkflow( $session ); addPurgeOldInboxActivity( $session ); addingInStoreCredit($session); @@ -45,6 +46,23 @@ mergeProductsWithCommerce($session); finish($session); # this line required +#---------------------------------------------------------------------------- +sub addReferralHandler { + my $session = shift; + print "\tAdding a referral handler." unless $quiet; + my $config = $session->config; + my @handlers = (); + foreach my $element (@{$config->get("contentHandlers")}) { + if ($element eq "WebGUI::Content::Operation") { + push @handlers, "WebGUI::Content::Referral"; + } + push @handlers, $element; + } + $config->set("contentHandlers", \@handlers); + print "DONE!\n" unless $quiet; +} + + #---------------------------------------------------------------------------- # Add the database column to select the workflow to approve Calendar Events sub addCalendarEventWorkflow { diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index e48f79d7e..1fe84c519 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -67,20 +67,27 @@ sub handler { my $matchUri = $request->uri; my $gateway = $config->get("gateway"); $matchUri =~ s{^$gateway(.*)}{/$1}; + my $gotMatch = 0; foreach my $handler (@{$config->get("urlHandlers")}) { my ($regex) = keys %{$handler}; if ($matchUri =~ m{$regex}i) { my $output = eval { WebGUI::Pluggable::run($handler->{$regex}, "handler", [$request, $server, $config]) }; if ($@) { - die $@ if ($@ =~ "^fatal:"); - # bad - return Apache2::Const::DECLINED; + $error = $@; + warn $@ if ($@ =~ "^fatal:"); + last; } else { - return $output; + $gotMatch = 1; + if ($output ne Apache2::Const::DECLINED) { + return $output; + } } } } + return Apache2::Const::DECLINED if ($gotMatch); + + # can't handle the url due to error or misconfiguration $request->push_handlers(PerlResponseHandler => sub { print "This server is unable to handle the url '".$request->uri."' that you requested. ".$error; return Apache2::Const::OK; diff --git a/lib/WebGUI/Content/Referral.pm b/lib/WebGUI/Content/Referral.pm new file mode 100644 index 000000000..79a57897c --- /dev/null +++ b/lib/WebGUI/Content/Referral.pm @@ -0,0 +1,55 @@ +package WebGUI::Content::Referral; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Affiliate; + + +=head1 NAME + +Package WebGUI::Content::Referral + +=head1 DESCRIPTION + +Processes referrals from other sites. + +=head1 SYNOPSIS + + use WebGUI::Content::Referral; + my $output = WebGUI::Content::Referral::handler($session); + +=head1 SUBROUTINES + +These subroutines are available from this package: + +=cut + +#------------------------------------------------------------------- + +=head2 handler ( session ) + +The content handler for this package. + +=cut + +sub handler { + my ($session) = @_; + WebGUI::Affiliate::grabReferral($session); # process affiliate tracking request + return undef; +} + +1; + diff --git a/lib/WebGUI/URL/Content.pm b/lib/WebGUI/URL/Content.pm index fba8a543f..9ae6b9c82 100644 --- a/lib/WebGUI/URL/Content.pm +++ b/lib/WebGUI/URL/Content.pm @@ -80,12 +80,11 @@ sub handler { } } } - WebGUI::Affiliate::grabReferral($session); # process affiliate tracking request $session->close; return Apache2::Const::OK; }); $request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK }); - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } 1; diff --git a/lib/WebGUI/URL/Credits.pm b/lib/WebGUI/URL/Credits.pm index 90a081cd9..b2a37bd1a 100644 --- a/lib/WebGUI/URL/Credits.pm +++ b/lib/WebGUI/URL/Credits.pm @@ -58,7 +58,7 @@ sub handler { return Apache2::Const::OK; } ); $request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK }); - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } diff --git a/lib/WebGUI/URL/PassThru.pm b/lib/WebGUI/URL/PassThru.pm index 55d12a922..58e8643b0 100644 --- a/lib/WebGUI/URL/PassThru.pm +++ b/lib/WebGUI/URL/PassThru.pm @@ -52,7 +52,7 @@ sub handler { $request->handler(Apache2::Const::DIR_MAGIC_TYPE); # Hand off to mod_dir return Apache2::Const::OK; } - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } 1; diff --git a/lib/WebGUI/URL/Snoop.pm b/lib/WebGUI/URL/Snoop.pm index 4397f8ad9..e339b25c3 100644 --- a/lib/WebGUI/URL/Snoop.pm +++ b/lib/WebGUI/URL/Snoop.pm @@ -53,7 +53,7 @@ sub handler { return Apache2::Const::OK; } ); $request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK }); - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } diff --git a/lib/WebGUI/URL/Uploads.pm b/lib/WebGUI/URL/Uploads.pm index 2ebed7dee..cf1067a26 100644 --- a/lib/WebGUI/URL/Uploads.pm +++ b/lib/WebGUI/URL/Uploads.pm @@ -77,7 +77,7 @@ sub handler { return Apache2::Const::NOT_FOUND; } } ); - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } diff --git a/lib/WebGUI/URL/_url.skeleton b/lib/WebGUI/URL/_url.skeleton index ab160016a..790065329 100644 --- a/lib/WebGUI/URL/_url.skeleton +++ b/lib/WebGUI/URL/_url.skeleton @@ -15,7 +15,7 @@ package WebGUI::URL::MyHandler; =cut use strict; -use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND DIR_MAGIC_TYPE); +use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND); =head1 NAME @@ -48,7 +48,7 @@ The Apache request handler for this package. sub handler { my ($request, $server, $config) = @_; # ... - return Apache2::Const::DECLINED; + return Apache2::Const::OK; } 1;