WWW::AdServer::Displayer::NonSSI - displays adverts using non-SSI method


WWW-AdServer documentation Contained in the WWW-AdServer distribution.

Index


Code Index:

NAME

Top

WWW::AdServer::Displayer::NonSSI - displays adverts using non-SSI method

SYNOPSIS

Top

  use WWW::AdServer::Displayer::NonSSI;

  my $displayer = WWW::AdServer::Displayer::NonSSI->new( r=>$r );

  $displayer->display($advert);

DESCRIPTION

Top

$displayer = WWW::AdServer::Displayer::NonSSI->new( $r );

Constructor for a Non-SSI Displayer. Must be supplied with either an Apache request object, or an Apache::Emulator object (when using CGI).

$displayer->display($advert);

Outputs the advert to the client.

EXPORT

None by default.

AUTHOR

Top

Nigel Wetters (nwetters@cpan.org)

COPYRIGHT

Top


WWW-AdServer documentation Contained in the WWW-AdServer distribution.

package WWW::AdServer::Displayer::NonSSI;
$VERSION = '0.01';
use strict;
use vars qw ( $VERSION @ISA );
use Carp;
use WWW::AdServer::Displayer;
use CGI::Cookie;

@ISA = qw ( WWW::AdServer::Displayer );

use Apache::Constants qw( :http );

sub display
{
    my ($self,$advert) = @_;
    my $r = $$self;
    my $image = $advert->get_image;
    
    $r->status(301);
    $r->header_out('Cache-Control','no-cache');
    $r->header_out('Pragma','no-cache');
    $r->header_out('Location',$image);
    
    my @zones = $advert->get_zones;
    if (@zones){
	my $zones = join ",", @zones;
	my $ad_id = $advert->get_advert;
	my $cookie = CGI::Cookie->new(
				      -name    => "ADZONE$zones",
				      -value   => $ad_id,
				      -expires => '+1h'
				      );
	$r->header_out( 'Set-Cookie', $cookie );
    }
    $r->send_http_header();
}

sub redirect
{
    my ($self,$advert) = @_;
    my $r = $$self;
    
    my $raw_cookie = $r->header_in('Cookie');
    if (defined $raw_cookie){
	my @zones = $advert->get_zones;
	if (@zones){
	    my $zones = join ",", @zones;
	    my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
	    if (defined $cookies{"ADZONE$zones"}){
		my $ad_id = $cookies{"ADZONE$zones"}->value;
#		$r->print("Content-type: text/plain\n\n$zones - FOO! $ad_id\n");
		$advert->set_advert($ad_id);
	    }
	}
    }
    
    my $link = $advert->get_link;
    
    $r->status(301);
    $r->header_out('Cache-Control','no-cache');
    $r->header_out('Pragma','no-cache');
    $r->header_out('Location',$link);
    $r->header_out('Expires','Thu, 15 Nov 2001 11:59:59 GMT');
    $r->send_http_header();
}

1;
__END__