17:36 [Error: Irreparable invalid markup ('<a [...] $config->') in entry. Owner must fix manually. Raw contents below.]
a vot tvnet`am k-kaads erors un var redzeet shitaadu:<lj-cut text="k-kaads man nesaprotams texts">#!/usr/bin/perl -w
###################################################################################### # # # AdvertPRO - Internet Advertising Delivery Application # # # ###################################################################################### # # # Copyright (c) 1998-2003 by Renegade Internet. All Rights Reserved. # # # # This software is the confidential and proprietary information of Renegade Internet # # ("Confidential Information"). You shall not disclose such Confidential # # Information and shall use it only in accordance with the terms of the license # # agreement you entered into with Renegade Internet. # # # # RENEGADE INTERNET MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF # # THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED # # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR # # NON-INFRINGEMENT. RENEGADE INTERNET SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED # # BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS # # DERIVATIVES. # # # ###################################################################################### # # # $AUTHOR: Mike Cherichetti # # $VERSION: 3.7.16.0.0 # # # ######################################################################################
use strict; use FCGI;
######################################################################################
BEGIN { # Add library to path. use lib '/var/www/cgi-bin/advertpro/library';
# Global variables. use vars qw/$CONFIG $CACHE $DB $ADVERTISERS $BANNERS $CAMPAIGNS $PUBLISHERS $REGIONS $ERROR %PARAMS/;
# Load the modules. use AdvertPRO::Cache::Advertiser; use AdvertPRO::Cache::Banner; use AdvertPRO::Cache::Campaign::Banner; use AdvertPRO::Cache::Campaign::Region; use AdvertPRO::Cache::Campaign; use AdvertPRO::Cache::Publisher; use AdvertPRO::Cache::Region; use AdvertPRO::Cache::Rotation; use AdvertPRO::Cache; use AdvertPRO::Collection; use AdvertPRO::Config; use AdvertPRO::DB; use AdvertPRO::Date; use AdvertPRO::Error; use AdvertPRO::GEO; use AdvertPRO::HTML; use AdvertPRO::Utility::Browser; use AdvertPRO::Utility::Custom; use AdvertPRO::Utility::Domain; use AdvertPRO::Utility::IP; use AdvertPRO::Utility::Keyword; use AdvertPRO::Utility::OS; use AdvertPRO::Utility::Referrer; use AdvertPRO::Utility::RichMedia;
# Initilize the globals. $CONFIG = new AdvertPRO::Config(); $CACHE = new AdvertPRO::Cache(AdvertPRO::Date::getHour(), AdvertPRO::Date::getMinute(), $CONFIG->{'CACHE_REFRESH'}); $DB = new AdvertPRO::DB($CONFIG->{'DATABASE_URL'}, $CONFIG->{'DATABASE_USERNAME'}, $CONFIG->{'DATABASE_PASSWORD'}); $ADVERTISERS = new AdvertPRO::Collection(); $BANNERS = new AdvertPRO::Collection(); $CAMPAIGNS = new AdvertPRO::Collection(); $PUBLISHERS = new AdvertPRO::Collection(); $REGIONS = new AdvertPRO::Collection(); $ERROR = new AdvertPRO::Error();
# Signal Traps. $SIG{USR1} = \&usr1_handler; $SIG{TERM} = \&term_handler; $SIG{PIPE} = \&pipe_handler; $SIG{__WARN__} = \&warn_handler; $SIG{__DIE__} = \&die_handler; };
######################################################################################
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV);
while ($request->Accept() >= 0) { init(); main(); }
######################################################################################
END { # Destroy database connection. $DB->disconnect() if ($DB->check() == 1 && $CONFIG->{'CACHE'} == 0); }
################ # sub routines # ################
sub init { # Reload globals. $CONFIG = new AdvertPRO::Config();
if (($CONFIG->{'DATABASE_URL'} && $CONFIG->{'DATABASE_URL'} ne $DB->url()) || ($CONFIG->{'DATABASE_USERNAME'} && $CONFIG->{'DATABASE_USERNAME'} ne $DB->user()) || ($CONFIG->{'DATABASE_PASSWORD'} && $CONFIG->{'DATABASE_PASSWORD'} ne $DB->pass())) { $DB->disconnect() if ($DB->check() == 1); $DB->url($CONFIG->{'DATABASE_URL'}); $DB->user($CONFIG->{'DATABASE_USERNAME'}); $DB->pass($CONFIG->{'DATABASE_PASSWORD'}); $DB->connect(); }
$ERROR = new AdvertPRO::Error(); %PARAMS = ();
# Get dates and times. $PARAMS{'date'} = AdvertPRO::Date::getDate(); $PARAMS{'weekday'} = AdvertPRO::Date::getWeekDay() + 1; $PARAMS{'hour'} = AdvertPRO::Date::getHour(); $PARAMS{'minute'} = AdvertPRO::Date::getMinute(); $PARAMS{'second'} = AdvertPRO::Date::getSecond();
# Check database connection. if ($DB->check() == 0 && $DB->connect() == 0) { $ERROR->flag(1); $ERROR->message("Database connection exception: " . $DB->status()); }
else { # Check the cache. if ($CONFIG->{'CACHE'} == 0 || $CACHE->init() == 0 || $CACHE->check($PARAMS{'hour'}, $PARAMS{'minute'}) == 0) { # Empty the cache. $ADVERTISERS->empty(); $BANNERS->empty(); $CAMPAIGNS->empty(); $PUBLISHERS->empty(); $REGIONS->empty();
# Reload the advertiser cache. foreach my $record ($DB->query("SELECT id,name FROM avp_advertisers ORDER BY id")) { $ADVERTISERS->add(new AdvertPRO::Cache::Advertiser(@$record[0], @$record[1])); }
# Reload the banner cache. foreach my $record ($DB->query("SELECT id,name,image,redirect,width,height,border,target,alt,textlink,extend,code FROM avp_banners ORDER BY id")) { $BANNERS->add(new AdvertPRO::Cache::Banner(@$record[0], @$record[1], @$record[2], @$record[3], @$record[4], @$record[5], @$record[6], @$record[7], @$record[8], @$record[9], @$record[10], @$record[11])); }
# Reload the campaign cache. foreach my $record ($DB->query("SELECT id,name,advertiser,views,clicks,maxviews,maxclicks,startdate,stopdate,delivery,keyword,weekday,hour,continent,country,browser,os,blockreferrer,targetreferrer,blockdomain,targetdomain,blockip,targetip,custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10 FROM avp_campaigns ORDER BY id")) { my $banners = new AdvertPRO::Collection();
foreach my $banner ($DB->query("SELECT banner,weight,status FROM avp_campaign_banners WHERE campaign=@$record[0] ORDER BY banner")) { $banners->add(new AdvertPRO::Cache::Campaign::Banner(@$banner[0], @$banner[1], @$banner[2])); }
my $regions = new AdvertPRO::Collection();
foreach my $region ($DB->query("SELECT region,weight,status FROM avp_campaign_regions WHERE campaign=@$record[0] ORDER BY region")) { $regions->add(new AdvertPRO::Cache::Campaign::Region(@$region[0], @$region[1], @$region[2])); }
$CAMPAIGNS->add(new AdvertPRO::Cache::Campaign(@$record[0], @$record[1], @$record[2], @$record[3], @$record[4], @$record[5], @$record[6], @$record[7], @$record[8], @$record[9], @$record[10], @$record[11], @$record[12], @$record[13], @$record[14], @$record[15], @$record[16], @$record[17], @$record[18], @$record[19], @$record[20], @$record[21], @$record[22], @$record[23], @$record[24], @$record[25], @$record[26], @$record[27], @$record[28], @$record[29], @$record[30], @$record[31], @$record[32], $banners, $regions)); }
# Reload the publisher cache. foreach my $record ($DB->query("SELECT id,name FROM avp_publishers ORDER BY id")) { $PUBLISHERS->add(new AdvertPRO::Cache::Publisher(@$record[0], @$record[1])); }
# Reload the region cache. foreach my $record ($DB->query("SELECT id,name,groupid,image,redirect,width,height,border,target,alt,textlink,extend,code FROM avp_regions ORDER BY id")) { $REGIONS->add(new AdvertPRO::Cache::Region(@$record[0], @$record[1], @$record[2], @$record[3], @$record[4], @$record[5], @$record[6], @$record[7], @$record[8], @$record[9], @$record[10], @$record[11], @$record[12])); }
# Reset the cache expiration. $CACHE->reset($PARAMS{'hour'}, $PARAMS{'minute'}); } } }
sub main { # Get the parameters. get_params();
# Cleanup the paramters. cleanup_params();
# Validate the parameters. validate_params();
# Process the request. if ($ERROR->flag() == 0) { if ($PARAMS{'mode'} =~ /HTML|SSI|POPUP|IMAGE/i) { view(); }
else { click(); } }
else { error(); } }
sub get_params { my ($forminfo, @key_value_pairs, $pair, $key, $value);
# Get parameters. $forminfo = (exists $ENV{'QUERY_STRING'} && length($ENV{'QUERY_STRING'}) > 0) ? $ENV{"QUERY_STRING"} : <STDIN>; # Convert to name/value pairs. @key_value_pairs = ($forminfo) ? split(/&/, $forminfo) : @ARGV;
# Decode name/value pairs. foreach $pair (@key_value_pairs) { ($key, $value) = split(/=/, $pair);
$value =~ s/\\+/ /g; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
if ($key =~ /mode|region|campaign|banner|name|publisher|referrer|useragent|remoteaddr|cookie|redirect|keyword|custom1|custom2|custom3|custom4|custom5|custom6|custom7|custom8|custom9|custom10|slot|bust|timestamp|unique|duplicate|refresh|extra/i) { $PARAMS{$key} = $value; }
elsif (exists $PARAMS{'extra'}) { $PARAMS{'extra'} .= "&$key=$value"; }
else { $PARAMS{'extra'} = "$key=$value"; } } }
sub cleanup_params { # Cleanup the parameters. $PARAMS{'mode'} ||= "HTML"; $PARAMS{'region'} ||= 0; $PARAMS{'campaign'} ||= 0; $PARAMS{'name'} ||= 0; $PARAMS{'banner'} ||= $PARAMS{'name'}; $PARAMS{'banner'} ||= 0; $PARAMS{'publisher'} ||= 0;
if (exists $ENV{'HTTP_REFERER'}) { $PARAMS{'referrer'} ||= $ENV{"HTTP_REFERER"}; } elsif (exists $ENV{'HTTP_HOST'} && exists $ENV{'DOCUMENT_URI'}) { $PARAMS{'referrer'} ||= "http://$ENV{'HTTP_HOST'}$ENV{'DOCUMENT_URI'}"; } elsif (exists $ENV{'HTTP_HOST'}) { $PARAMS{'referrer'} ||= "http://$ENV{'HTTP_HOST'}"; } else { $PARAMS{'referrer'} ||= "Unresolved"; }
$PARAMS{'useragent'} ||= (exists $ENV{'HTTP_USER_AGENT'}) ? $ENV{"HTTP_USER_AGENT"} : "Unresolved"; $PARAMS{'remoteaddr'} ||= (exists $ENV{'HTTP_X_FORWARDED_FOR'} && AdvertPRO::Utility::IP::check($ENV{'HTTP_X_FORWARDED_FOR'}) == 1) ? $ENV{"HTTP_X_FORWARDED_FOR"} : (exists $ENV{'REMOTE_ADDR'} && AdvertPRO::Utility::IP::check($ENV{'REMOTE_ADDR'}) == 1) ? $ENV{"REMOTE_ADDR"} : "Unresolved"; $PARAMS{'cookie'} = (exists $ENV{'HTTP_COOKIE'}) ? $ENV{"HTTP_COOKIE"} : undef;
$PARAMS{'redirect'} ||= "Unresolved"; $PARAMS{'keyword'} ||= "NULL"; $PARAMS{'slot'} ||= 0; $PARAMS{'bust'} ||= AdvertPRO::Date::getBust(); $PARAMS{'timestamp'} ||= AdvertPRO::Date::getTimeStamp(); $PARAMS{'unique'} ||= 0; $PARAMS{'duplicate'} ||= 0; $PARAMS{'refresh'} ||= 0; $PARAMS{'extra'} ||= undef; $PARAMS{'custom1'} ||= undef; $PARAMS{'custom2'} ||= undef; $PARAMS{'custom3'} ||= undef; $PARAMS{'custom4'} ||= undef; $PARAMS{'custom5'} ||= undef; $PARAMS{'custom6'} ||= undef; $PARAMS{'custom7'} ||= undef; $PARAMS{'custom8'} ||= undef; $PARAMS{'custom9'} ||= undef; $PARAMS{'custom10'} ||= undef; # Translate region, campaign, name, and publisher parameters to integers. if ($PARAMS{'region'} =~ /[a-z]/i) { for (my $x = 0; $x < $REGIONS->size(); $x++) { if ($REGIONS->get($x)->name() eq $PARAMS{'region'}) { $PARAMS{'region'} = $REGIONS->get($x)->id(); last; } } }
if ($PARAMS{'campaign'} =~ /[a-z]/i) { for (my $x = 0; $x < $CAMPAIGNS->size(); $x++) { if ($CAMPAIGNS->get($x)->name() eq $PARAMS{'campaign'}) { $PARAMS{'campaign'} = $CAMPAIGNS->get($x)->id(); last; } } }
if ($PARAMS{'banner'} =~ /[a-z]/i) { for (my $x = 0; $x < $BANNERS->size(); $x++) { if ($BANNERS->get($x)->name() eq $PARAMS{'banner'}) { $PARAMS{'banner'} = $BANNERS->get($x)->id(); last; } } }
if ($PARAMS{'publisher'} =~ /[a-z]/i) { for (my $x = 0; $x < $PUBLISHERS->size(); $x++) { if ($PUBLISHERS->get($x)->name() eq $PARAMS{'publisher'}) { $PARAMS{'publisher'} = $PUBLISHERS->get($x)->id(); last; } } } }
sub validate_params { # Validate the paramters. if ($PARAMS{'region'} =~ /[a-z]/i || ($PARAMS{'region'} != 0 && $REGIONS->index(new AdvertPRO::Cache::Region($PARAMS{'region'})) == -1)) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid region parameter!"); }
elsif ($PARAMS{'campaign'} =~ /[a-z]/i || ($PARAMS{'campaign'} != 0 && $CAMPAIGNS->index(new AdvertPRO::Cache::Campaign($PARAMS{'campaign'})) == -1)) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid campaign parameter!"); }
elsif ($PARAMS{'banner'} =~ /[a-z]/i || ($PARAMS{'banner'} != 0 && $BANNERS->index(new AdvertPRO::Cache::Banner($PARAMS{'banner'})) == -1)) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid banner parameter!"); }
elsif ($PARAMS{'publisher'} =~ /[a-z]/i || ($PARAMS{'publisher'} != 0 && $PUBLISHERS->index(new AdvertPRO::Cache::Publisher($PARAMS{'publisher'})) == -1)) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid publisher parameter!"); }
elsif ($PARAMS{'mode'} !~ /HTML|SSI|POPUP|IMAGE|CLICK|FORM|RICH|LINK/i) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid mode parameters!"); }
else { if ($PARAMS{'region'} == 0 && $PARAMS{'campaign'} == 0 && $PARAMS{'banner'} == 0) { $ERROR->flag(1); $ERROR->message("Parameter exception: Invalid invoking parameters!"); } } }
sub view { # Determine what we are displaying. if ($PARAMS{'banner'} != 0) { view_banner(); }
elsif ($PARAMS{'campaign'} != 0) { view_campaign();
if ($PARAMS{'banner'} != -1) { view_banner(); }
else { $ERROR->flag(1); $ERROR->message("Runtime exception: Invoking campaign (ID# $PARAMS{'campaign'}) has no valid banners."); error(); } }
else { view_region();
if ($PARAMS{'campaign'} != -1) { view_campaign();
if ($PARAMS{'banner'} != -1) { view_banner(); }
else { $ERROR->flag(1); $ERROR->message("Runtime exception: Selected campaign (ID# $PARAMS{'campaign'}) has no valid banners."); error(); } }
else { panic(); } } }
sub view_region { my $rotation; my @keyword_excludes = (); my $keyword_matches = 0;
# Fetch the lifetime and rotation statistics for the campaigns in this region. foreach my $record ($DB->query("SELECT c.id,c.views,c.clicks,r.weight,r.views,r.clicks FROM avp_campaigns c, avp_campaign_regions r WHERE c.id=r.campaign AND c.status=1 AND r.region=$PARAMS{'region'} AND r.status=1")) { my $idx = $CAMPAIGNS->index(new AdvertPRO::Cache::Campaign(@$record[0])); if ($idx != -1) { $CAMPAIGNS->get($idx)->views(@$record[1]); $CAMPAIGNS->get($idx)->clicks(@$record[2]); my $ridx = $CAMPAIGNS->get($idx)->regions()->index(new AdvertPRO::Cache::Region($PARAMS{'region'})); if ($ridx != -1) { $CAMPAIGNS->get($idx)->regions()->get($ridx)->weight(@$record[3]); $CAMPAIGNS->get($idx)->regions()->get($ridx)->views(@$record[4]); $CAMPAIGNS->get($idx)->regions()->get($ridx)->clicks(@$record[5]); } } }
# Create a rotation. $rotation = new AdvertPRO::Cache::Rotation();
# Find all valid campaigns. for (my $x = 0; $x < $CAMPAIGNS->size(); $x++) { my $ridx = $CAMPAIGNS->get($x)->regions()->index(new AdvertPRO::Cache::Region($PARAMS{'region'}));
if ($ridx != -1 && $CAMPAIGNS->get($x)->regions()->get($ridx)->status() == 1 && $CAMPAIGNS->get($x)->banners()->size() > 0) { # Set initial validation flag. my $valid = 1;
# Campaign banner status check. if ($valid == 1) { for (my $y = 0; $y < $CAMPAIGNS->get($x)->banners()->size(); $y++) { if ($CAMPAIGNS->get($x)->banners()->get($y)->status() == 1) { $valid = 1; last; }
else { $valid = 0; } } }
# Image only mode check. if ($valid == 1 && $PARAMS{'mode'} eq "IMAGE") { for (my $y = 0; $y < $CAMPAIGNS->get($x)->banners()->size(); $y++) { if ($BANNERS->get($BANNERS->index($CAMPAIGNS->get($x)->banners()->get($y)))->image()) { $valid = 1; last; } else { $valid = 0; } } }
# Max Views / Max Clicks. if ($valid == 1 && $CAMPAIGNS->get($x)->maxviews() != 0) { $valid = ($CAMPAIGNS->get($x)->views() < $CAMPAIGNS->get($x)->maxviews()) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->maxclicks() != 0) { $valid = ($CAMPAIGNS->get($x)->clicks() < $CAMPAIGNS->get($x)->maxclicks()) ? 1 : 0; }
# Start Date / Stop Date. if ($valid == 1 && $CAMPAIGNS->get($x)->startdate() && $CAMPAIGNS->get($x)->startdate() ne "0000-00-00") { $valid = (AdvertPRO::Date::greater_equal($PARAMS{'date'}, $CAMPAIGNS->get($x)->startdate()) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->stopdate() && $CAMPAIGNS->get($x)->stopdate() ne "0000-00-00") { $valid = (AdvertPRO::Date::less_equal($PARAMS{'date'}, $CAMPAIGNS->get($x)->stopdate()) == 1) ? 1 : 0; }
# Week Day. if ($valid == 1 && $CAMPAIGNS->get($x)->weekday()) { my $weekday = $PARAMS{'weekday'};
$valid = ($CAMPAIGNS->get($x)->weekday() =~ /$weekday/i) ? 1 : 0; }
# Hour of Day. if ($valid == 1 && $CAMPAIGNS->get($x)->hour()) { my $hour = $PARAMS{'hour'};
$valid = ($CAMPAIGNS->get($x)->hour() =~ /$hour/i) ? 1 : 0; }
# Geographical targeting. if ($valid == 1 && $CONFIG->{'GEO'} == 1 && ($CAMPAIGNS->get($x)->continent() || $CAMPAIGNS->get($x)->country())) { # Resolve the country code and continent name. my $country = AdvertPRO::GEO::lookup($CONFIG, $PARAMS{'remoteaddr'}); my $continent = AdvertPRO::GEO::continent($country);
# Continent. if ($valid == 1 && $CAMPAIGNS->get($x)->continent()) { $valid = ($CAMPAIGNS->get($x)->continent() =~ /$continent/i) ? 1 : 0; }
# Country. if ($valid == 1 && $CAMPAIGNS->get($x)->country()) { $valid = ($CAMPAIGNS->get($x)->country() =~ /$country/i) ? 1 : 0; } }
# Web Browser. if ($valid == 1 && $CAMPAIGNS->get($x)->browser()) { my $browser = AdvertPRO::Utility::Browser::id($PARAMS{'useragent'});
$valid = ($CAMPAIGNS->get($x)->browser() =~ /$browser/i) ? 1 : 0; }
# Operating System. if ($valid == 1 && $CAMPAIGNS->get($x)->os()) { my $os = AdvertPRO::Utility::OS::id($PARAMS{'useragent'});
$valid = ($CAMPAIGNS->get($x)->os() =~ /$os/i) ? 1 : 0; }
# Referrer Blocking / Targeting. if ($valid == 1 && $CAMPAIGNS->get($x)->blockreferrer()) { $valid = (AdvertPRO::Utility::Referrer::block($CAMPAIGNS->get($x)->blockreferrer(), $PARAMS{'referrer'}) == 0) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->targetreferrer()) { $valid = (AdvertPRO::Utility::Referrer::target($CAMPAIGNS->get($x)->targetreferrer(), $PARAMS{'referrer'}) == 1) ? 1 : 0; }
# Domain Blocking / Targeting. if ($valid == 1 && $CAMPAIGNS->get($x)->blockdomain()) { $valid = (AdvertPRO::Utility::Domain::block($CAMPAIGNS->get($x)->blockdomain(), $PARAMS{'remoteaddr'}) == 0) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->targetdomain()) { $valid = (AdvertPRO::Utility::Domain::target($CAMPAIGNS->get($x)->targetdomain(), $PARAMS{'remoteaddr'}) == 1) ? 1 : 0; }
# IP Address Blocking / Targeting. if ($valid == 1 && $CAMPAIGNS->get($x)->blockip()) { $valid = (AdvertPRO::Utility::IP::block($CAMPAIGNS->get($x)->blockip(), $PARAMS{'remoteaddr'}) == 0) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->targetip()) { $valid = (AdvertPRO::Utility::IP::target($CAMPAIGNS->get($x)->targetip(), $PARAMS{'remoteaddr'}) == 1) ? 1 : 0; }
# Custom targeting. if ($valid == 1 && $CAMPAIGNS->get($x)->custom1() && $CONFIG->{'CUSTOM1_OPERATOR'} && $PARAMS{'custom1'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom1(), $CONFIG->{'CUSTOM1_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom1'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom2() && $CONFIG->{'CUSTOM2_OPERATOR'} && $PARAMS{'custom2'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom2(), $CONFIG->{'CUSTOM2_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom2'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom3() && $CONFIG->{'CUSTOM3_OPERATOR'} && $PARAMS{'custom3'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom3(), $CONFIG->{'CUSTOM3_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom3'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom4() && $CONFIG->{'CUSTOM4_OPERATOR'} && $PARAMS{'custom4'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom4(), $CONFIG->{'CUSTOM4_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom4'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom5() && $CONFIG->{'CUSTOM5_OPERATOR'} && $PARAMS{'custom5'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom5(), $CONFIG->{'CUSTOM5_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom5'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom6() && $CONFIG->{'CUSTOM6_OPERATOR'} && $PARAMS{'custom6'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom6(), $CONFIG->{'CUSTOM6_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom6'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom7() && $CONFIG->{'CUSTOM7_OPERATOR'} && $PARAMS{'custom7'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom7(), $CONFIG->{'CUSTOM7_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom7'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom8() && $CONFIG->{'CUSTOM8_OPERATOR'} && $PARAMS{'custom8'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom8(), $CONFIG->{'CUSTOM8_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom8'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom9() && $CONFIG->{'CUSTOM9_OPERATOR'} && $PARAMS{'custom9'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom9(), $CONFIG->{'CUSTOM9_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom9'})) == 1) ? 1 : 0; }
if ($valid == 1 && $CAMPAIGNS->get($x)->custom10() && $CONFIG->{'CUSTOM10_OPERATOR'} && $PARAMS{'custom10'}) { $valid = (AdvertPRO::Utility::Custom::match($CAMPAIGNS->get($x)->custom10(), $CONFIG->{'CUSTOM10_OPERATOR'}, AdvertPRO::HTML::urldecode($PARAMS{'custom10'})) == 1) ? 1 : 0; }
# Even Distribution Delivery. if ($valid == 1 && $CAMPAIGNS->get($x)->delivery() == 1 && $CAMPAIGNS->get($x)->startdate() ne "0000-00-00" && $CAMPAIGNS->get($x)->stopdate() ne "0000-00-00" && $CAMPAIGNS->get($x)->maxviews() > 0) { my $total = (AdvertPRO::Date::range($CAMPAIGNS->get($x)->stopdate(), $CAMPAIGNS->get($x)->startdate()) * 1440); my $run = (((AdvertPRO::Date::range($PARAMS{'date'}, $CAMPAIGNS->get($x)->startdate()) - 1) * 1440) + ($PARAMS{'hour'} * 60) + $PARAMS{'minute'});
$valid = ($total > 0 && ($CAMPAIGNS->get($x)->views() > (($run / $total) * $CAMPAIGNS->get($x)->maxviews()))) ? 0 : 1; }
# Keyword Only Delivery. if ($valid == 1 && $CAMPAIGNS->get($x)->delivery() == 2) { $valid = (AdvertPRO::Utility::Keyword::match($CAMPAIGNS->get($x)->keyword(), AdvertPRO::HTML::urldecode($PARAMS{'keyword'})) == 1) ? 1 : 0; }
# Keyword Targeting (Part 1). if ($valid == 1 && $PARAMS{'keyword'} ne "NULL") { if (AdvertPRO::Utility::Keyword::match($CAMPAIGNS->get($x)->keyword(), AdvertPRO::HTML::urldecode($PARAMS{'keyword'})) == 1) { $keyword_matches++; }
else { push (@keyword_excludes, $CAMPAIGNS->get($x)->id()); } }
# Final validation check. if ($valid == 1) { $rotation->add($CAMPAIGNS->get($x)->id(), $CAMPAIGNS->get($x)->regions()->get($ridx)->weight(), $CAMPAIGNS->get($x)->regions()->get($ridx)->views(), $CAMPAIGNS->get($x)->regions()->get($ridx)->clicks()); } } }
# Keyword Targeting (Part 2). if ($keyword_matches > 0) { for (my $x = 0; $x <= $#keyword_excludes; $x++) { my $ridx = $rotation->index($keyword_excludes[$x]); if ($ridx != -1) { $rotation->remove($ridx); } } }
# Pick a campaign. $PARAMS{'campaign'} = $rotation->choose(); }
sub view_campaign { # Campaign index. my $idx = $CAMPAIGNS->index(new AdvertPRO::Cache::Campaign($PARAMS{'campaign'}));
# Fetch the rotation statistics for the banners in this campaign. foreach my $record ($DB->query("SELECT banner,weight,views,clicks FROM avp_campaign_banners WHERE campaign=$PARAMS{'campaign'}")) { my $bidx = $CAMPAIGNS->get($idx)->banners()->index(new AdvertPRO::Cache::Banner(@$record[0]));
if ($bidx != -1) { $CAMPAIGNS->get($idx)->banners()->get($bidx)->weight(@$record[1]); $CAMPAIGNS->get($idx)->banners()->get($bidx)->views(@$record[2]); $CAMPAIGNS->get($idx)->banners()->get($bidx)->clicks(@$record[3]); } }
# Create a rotation. my $rotation = new AdvertPRO::Cache::Rotation();
# Find all valid banners. for (my $x = 0; $x < $CAMPAIGNS->get($idx)->banners()->size(); $x++) { if ($CAMPAIGNS->get($idx)->banners()->get($x)->status() == 1) { $rotation->add($CAMPAIGNS->get($idx)->banners()->get($x)->id(), $CAMPAIGNS->get($idx)->banners()->get($x)->weight(), $CAMPAIGNS->get($idx)->banners()->get($x)->views(), $CAMPAIGNS->get($idx)->banners()->get($x)->clicks()); } }
# Pick a banner. $PARAMS{'banner'} = $rotation->choose(); }
sub view_banner { # Update the statistics. view_statistics();
# Display the banner. view_display(); }
sub view_statistics { # Update the lifetime banner statistics. if ($PARAMS{'banner'} != 0) { $DB->do("UPDATE avp_banners SET views=views+1 WHERE id=$PARAMS{'banner'}"); }
# Update the lifetime campaign statistics. if ($PARAMS{'campaign'} != 0) { $DB->do("UPDATE avp_campaigns SET views=views+1 WHERE id=$PARAMS{'campaign'}"); }
# Update the campaign/banner statistics. if ($PARAMS{'campaign'} != 0 && $PARAMS{'banner'} != 0) { $DB->do("UPDATE avp_campaign_banners SET views=views+1 WHERE campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}"); }
# Update the campaign/region statistics. if ($PARAMS{'campaign'} != 0 && $PARAMS{'region'} != 0) { $DB->do("UPDATE avp_campaign_regions SET views=views+1 WHERE campaign=$PARAMS{'campaign'} AND region=$PARAMS{'region'}"); }
# Update the daily statistics. my $result = $DB->do("UPDATE avp_daily_stats SET views=views+1,views_" . $PARAMS{'hour'} . "=views_" . $PARAMS{'hour'} . "+1 WHERE date='$PARAMS{'date'}' AND region=$PARAMS{'region'} AND campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}");
if ($result =~ /[a-z]/i || $result == 0) { $DB->do("LOCK TABLES avp_daily_stats WRITE");
$result = $DB->query_single_result("SELECT COUNT(*) FROM avp_daily_stats WHERE date='$PARAMS{'date'}' AND region=$PARAMS{'region'} AND campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}");
if ($result =~ /[a-z]/i || $result == 0) { $DB->do("INSERT INTO avp_daily_stats (date, region, campaign, banner, views, clicks, views_" . $PARAMS{'hour'} . ") VALUES ('$PARAMS{'date'}', '$PARAMS{'region'}', '$PARAMS{'campaign'}', '$PARAMS{'banner'}', '1', '0', '1')"); }
else { $DB->do("UPDATE avp_daily_stats SET views=views+1,views_" . $PARAMS{'hour'} . "=views_" . $PARAMS{'hour'} . "+1 WHERE date='$PARAMS{'date'}' AND region=$PARAMS{'region'} AND campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}"); }
$DB->do("UNLOCK TABLES"); }
# Update the publisher statistics. if ($PARAMS{'publisher'} != 0) { $result = $DB->do("UPDATE avp_publisher_stats SET views=views+1 WHERE date='$PARAMS{'date'}' AND publisher=$PARAMS{'publisher'}");
if ($result =~ /[a-z]/i || $result == 0) { $DB->do("LOCK TABLES avp_publisher_stats WRITE");
$result = $DB->query_single_result("SELECT COUNT(*) FROM avp_publisher_stats WHERE date='$PARAMS{'date'}' AND publisher=$PARAMS{'publisher'}");
if ($result =~ /[a-z]/i || $result == 0) { $DB->do("INSERT INTO avp_publisher_stats (date, publisher, views, clicks) VALUES ('$PARAMS{'date'}', '$PARAMS{'publisher'}', '1', '0')"); }
else { $DB->do("UPDATE avp_publisher_stats SET views=views+1 WHERE date='$PARAMS{'date'}' AND publisher=$PARAMS{'publisher'}"); }
$DB->do("UNLOCK TABLES"); } }
# Update the temporary table. if ($PARAMS{'mode'} eq "IMAGE" && ($PARAMS{'region'} != 0 || $PARAMS{'campaign'} != 0)) { $DB->do("INSERT INTO avp_temporary (date, campaign, banner, region, bust, slot, ip, referrer, age) VALUES ('$PARAMS{'date'}', '$PARAMS{'campaign'}', '$PARAMS{'banner'}', '$PARAMS{'region'}', '$PARAMS{'bust'}', '$PARAMS{'slot'}', '$PARAMS{'remoteaddr'}', '$PARAMS{'referrer'}', '$PARAMS{'timestamp'}')"); } }
sub view_display { # Get the banner data from cache. my $display = $BANNERS->get($BANNERS->index(new AdvertPRO::Cache::Banner($PARAMS{'banner'})));
# Cache busting. $display->bust($PARAMS{'bust'}, $PARAMS{'timestamp'});
# Rich media tracking. $display->track($PARAMS{'region'}, $PARAMS{'campaign'}, $PARAMS{'banner'}, $PARAMS{'publisher'}, $PARAMS{'referrer'});
# Display the banner. if ($PARAMS{'mode'} eq "IMAGE") { AdvertPRO::HTML::redirect($display->image(), undef, 1); }
elsif ($PARAMS{'mode'} eq "SSI") { AdvertPRO::HTML::header(undef, 0);
if ($display->code()) { my $output = AdvertPRO::Utility::RichMedia::parse( $display->code(), $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'}, "region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) );
print "$output\n\n"; }
else { my $output = "<a href=\"" . $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'} . "?region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&mode=CLICK&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}\" target=\"" . $display->target(). "\">"; $output .= "<img src=\"" . $display->image() . "\" border=\"" . $display->border(). "\" width=\"" . $display->width() . "\" height=\"" . $display->height() . "\" alt=\"" . $display->alt() . "\" " . $display->extend() . ">"; $output .= "<br>" . $display->textlink() if ($display->textlink()); $output .= "</a>";
print "$output\n\n"; } }
elsif ($PARAMS{'mode'} eq "POPUP") { AdvertPRO::HTML::header(undef, 1);
if ($display->code()) { my $output = "<html><head><title>" . $display->alt() . "</title></head>"; $output .= "<body bottommargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" rightmargin=\"0\" topmargin=\"0\">"; $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\"><tr valign=\"middle\"><td width=\"100%\" align=\"middle\">";
$output .= AdvertPRO::Utility::RichMedia::parse( $display->code(), $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'}, "region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) );
$output .= "</td></tr></table>"; $output .= "</body></html>";
print "$output\n\n"; }
else { my $output = "<html><head><title>" . $display->alt() . "</title></head>"; $output .= "<body bottommargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" rightmargin=\"0\" topmargin=\"0\">"; $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\"><tr valign=\"middle\"><td width=\"100%\" align=\"middle\">"; $output .= "<a href=\"" . $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'} . "?region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&mode=CLICK&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) . "\" target=\"_blank\" onclick=\"javascript:window.close()\">"; $output .= "<img src=\"" . $display->image() . "\" border=\"" . $display->border(). "\" width=\"" . $display->width() . "\" height=\"" . $display->height() . "\" alt=\"" . $display->alt() . "\" " . $display->extend() . ">"; $output .= "</a>"; $output .= "</td></tr></table>"; $output .= "</body></html>";
print "$output\n\n"; } }
else { AdvertPRO::HTML::header(undef, 1);
if ($display->code()) { if ($PARAMS{'refresh'} == 0) { my $output .= AdvertPRO::Utility::RichMedia::parse( $display->code(), $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'}, "region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) );
print "$output\n\n"; }
else { my $output = "<html><head><title>" . $display->alt() . "</title><meta content=\"$PARAMS{'refresh'}\" http-equiv=\"refresh\"></head>"; $output .= "<body bottommargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" rightmargin=\"0\" topmargin=\"0\">";
$output .= AdvertPRO::Utility::RichMedia::parse( $display->code(), $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'}, "region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) );
$output .= "</body></html>";
print "$output\n\n"; } }
else { if ($PARAMS{'refresh'} == 0) { my $output = "<a href=\"" . $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'} . "?region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&mode=CLICK&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) . "\" target=\"" . $display->target(). "\">"; $output .= "<img src=\"" . $display->image() . "\" border=\"" . $display->border(). "\" width=\"" . $display->width() . "\" height=\"" . $display->height() . "\" alt=\"" . $display->alt() . "\" " . $display->extend() . ">"; $output .= "</a>";
print "$output\n\n"; }
else { my $output = "<html><head><title>" . $display->alt() . "</title><meta content=\"$PARAMS{'refresh'}\" http-equiv=\"refresh\"></head>"; $output .= "<body bottommargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" rightmargin=\"0\" topmargin=\"0\">"; $output .= "<a href=\"" . $CONFIG->{'SCRIPTS_URL'} . "/banners." . $CONFIG->{'SCRIPTS_EXT'} . "?region=$PARAMS{'region'}&campaign=$PARAMS{'campaign'}&banner=$PARAMS{'banner'}&publisher=$PARAMS{'publisher'}&mode=CLICK&bust=$PARAMS{'bust'}×tamp=$PARAMS{'timestamp'}&referrer=" . AdvertPRO::HTML::urlencode($PARAMS{'referrer'}) . "\" target=\"" . $display->target(). "\">"; $output .= "<img src=\"" . $display->image() . "\" border=\"" . $display->border(). "\" width=\"" . $display->width() . "\" height=\"" . $display->height() . "\" alt=\"" . $display->alt() . "\" " . $display->extend() . ">"; $output .= "</a>"; $output .= "</body></html>";
print "$output\n\n"; } } } }
sub click { # Get information from temporary table. if ($PARAMS{'mode'} eq "LINK" && $PARAMS{'banner'} == 0) { # Attempt to retrieve the data. ($PARAMS{'region'}, $PARAMS{'campaign'}, $PARAMS{'banner'}, $PARAMS{'bust'}, $PARAMS{'timestamp'}) = $DB->query_single_row("SELECT region,campaign,banner,bust,age FROM avp_temporary WHERE (banner=$PARAMS{'banner'} OR campaign=$PARAMS{'campaign'} OR region=$PARAMS{'region'}) AND ((ip='$PARAMS{'remoteaddr'}' AND referrer='" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "') OR ip='$PARAMS{'remoteaddr'}' OR referrer='" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "') AND (bust=$PARAMS{'bust'} OR slot=$PARAMS{'slot'}) ORDER BY age DESC LIMIT 0,1"); # Cleanup the data. $PARAMS{'region'} ||= 0; $PARAMS{'campaign'} ||= 0; $PARAMS{'banner'} ||= 0; $PARAMS{'bust'} ||= AdvertPRO::Date::getBust(); $PARAMS{'timestamp'} ||= AdvertPRO::Date::getTimeStamp(); $PARAMS{'timestamp'} =~ s/\-|\s+|\://g; }
# Check for panic banner display and errors. if ($PARAMS{'banner'} == -1) { panic(); }
elsif ($PARAMS{'banner'} == 0) { $ERROR->flag(1); $ERROR->message("Runtime exception: Unable to determine display information."); error(); }
else { # Update the statistics. click_statistics();
# Display the click url. click_display(); } }
sub click_statistics { # Check the click-through timeout. my $result = $DB->query_single_result("SELECT COUNT(*) FROM avp_click_logs WHERE date='$PARAMS{'date'}' AND banner=$PARAMS{'banner'} AND ip='$PARAMS{'remoteaddr'}' AND '$PARAMS{'date'}'-age <= " . $CONFIG->{'TIMEOUT_CLICK'});
if ($CONFIG->{'TIMEOUT_CLICK'} == 0 || $result =~ /[a-z]/i || $result == 0) { # Update the lifetime banner statistics. if ($PARAMS{'banner'} != 0) { $DB->do("UPDATE avp_banners SET clicks=clicks+1 WHERE id=$PARAMS{'banner'}"); }
# Update the lifetime campaign statistics. if ($PARAMS{'campaign'} != 0) { $DB->do("UPDATE avp_campaigns SET clicks=clicks+1 WHERE id=$PARAMS{'campaign'}"); }
# Update the campaign/banner statistics. if ($PARAMS{'campaign'} != 0 && $PARAMS{'banner'} != 0) { $DB->do("UPDATE avp_campaign_banners SET clicks=clicks+1 WHERE campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}"); }
# Update the campaign/region statistics. if ($PARAMS{'campaign'} != 0 && $PARAMS{'region'} != 0) { $DB->do("UPDATE avp_campaign_regions SET clicks=clicks+1 WHERE campaign=$PARAMS{'campaign'} AND region=$PARAMS{'region'}"); }
# Update the daily statistics. $DB->do("UPDATE avp_daily_stats SET clicks=clicks+1,clicks_" . $PARAMS{'hour'} . "=clicks_" . $PARAMS{'hour'} . "+1 WHERE date='$PARAMS{'date'}' AND region=$PARAMS{'region'} AND campaign=$PARAMS{'campaign'} AND banner=$PARAMS{'banner'}");
# Update the publisher stats table. $DB->do("UPDATE avp_publisher_stats SET clicks=clicks+1 WHERE date='$PARAMS{'date'}' AND publisher=$PARAMS{'publisher'}");
# Update the click logs table. if ($CONFIG->{'CLICK_LOGGING'} == 1) { if ($CONFIG->{'GEO'} == 1) { $DB->do("INSERT INTO avp_click_logs (date, campaign, banner, region, country, ip, host, referrer, browser, os, age) VALUES ('$PARAMS{'date'}', '$PARAMS{'campaign'}', '$PARAMS{'banner'}', '$PARAMS{'region'}', '" . AdvertPRO::GEO::lookup($CONFIG, $PARAMS{'remoteaddr'}) . "', '$PARAMS{'remoteaddr'}', '" . AdvertPRO::Utility::IP::resolve($PARAMS{'remoteaddr'}) . "', '" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "', '" . AdvertPRO::Utility::Browser::id($PARAMS{'useragent'}) . "', '" . AdvertPRO::Utility::OS::id($PARAMS{'useragent'}) . "', '$PARAMS{'date'}')"); } else { $DB->do("INSERT INTO avp_click_logs (date, campaign, banner, region, country, ip, host, referrer, browser, os, age) VALUES ('$PARAMS{'date'}', '$PARAMS{'campaign'}', '$PARAMS{'banner'}', '$PARAMS{'region'}', 'XX', '$PARAMS{'remoteaddr'}', '" . AdvertPRO::Utility::IP::resolve($PARAMS{'remoteaddr'}) . "', '" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "', '" . AdvertPRO::Utility::Browser::id($PARAMS{'useragent'}) . "', '" . AdvertPRO::Utility::OS::id($PARAMS{'useragent'}) . "', '$PARAMS{'date'}')"); } }
else { $DB->do("INSERT INTO avp_click_logs (date, campaign, banner, region, country, ip, host, referrer, browser, os, age) VALUES ('$PARAMS{'date'}', '0', '$PARAMS{'banner'}', '0', 'XX', '$PARAMS{'remoteaddr'}', '', '', '0', '0', '$PARAMS{'date'}')"); } } }
sub click_display { # Get the banner to click-through. my $display = $BANNERS->get($BANNERS->index(new AdvertPRO::Cache::Banner($PARAMS{'banner'})));
# Reset the redirect for rich-media. if ($PARAMS{'mode'} eq "FORM" || $PARAMS{'mode'} eq "RICH") { if ($PARAMS{'redirect'} eq "Unresolved") { $PARAMS{'redirect'} = $display->redirect(); } if ($PARAMS{'mode'} eq "FORM") { if ($PARAMS{'extra'}) { my $temp = AdvertPRO::HTML::urldecode($PARAMS{'redirect'}); if ($temp =~ /\?/i) { $display->redirect(AdvertPRO::HTML::urldecode($PARAMS{'redirect'}) . "&$PARAMS{'extra'}"); } else { $display->redirect(AdvertPRO::HTML::urldecode($PARAMS{'redirect'}) . "?$PARAMS{'extra'}"); } }
else { $display->redirect(AdvertPRO::HTML::urldecode($PARAMS{'redirect'})); } } else { $display->redirect($PARAMS{'redirect'}); } }
# Cache busting. $display->bust($PARAMS{'bust'}, $PARAMS{'timestamp'});
# Rich media tracking. $display->track($PARAMS{'region'}, $PARAMS{'campaign'}, $PARAMS{'banner'}, $PARAMS{'publisher'}, $PARAMS{'referrer'});
# Redirect the user. AdvertPRO::HTML::redirect($display->redirect(), undef, 1); }
sub error { # Write an error_log entry if enabled. if ($CONFIG->{'ERROR_LOGGING'} == 1) { if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) { print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [ERROR] " . $ERROR->message() . "\n"; close (ERRORLOG); } }
# Return error results to user. if ($PARAMS{'mode'} eq "IMAGE") { AdvertPRO::HTML::redirect($CONFIG->{'HTML_URL'} . "/images/admin/clear.gif", undef, 1); }
else { AdvertPRO::HTML::header(undef, 1); print "<FONT size=\"-1\">AdvertPRO Error:</FONT><BR>\n"; print "<FONT size=\"-2\">" . $ERROR->message() . "</FONT><BR><BR>\n\n"; } }
sub panic { my (@panic);
# Write an panic_log entry if enabled. if ($CONFIG->{'PANIC_LOGGING'} == 1) { if (open (PANICLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/panic_log")) { print PANICLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}]\n"; close (PANICLOG); } }
# Grab the index of the region. my $ridx = $REGIONS->index(new AdvertPRO::Cache::Region($PARAMS{'region'}));
# Define the information for our panic banner. my $display = new AdvertPRO::Cache::Banner( undef, undef, $REGIONS->get($ridx)->image(), $REGIONS->get($ridx)->redirect(), $REGIONS->get($ridx)->width(), $REGIONS->get($ridx)->height(), $REGIONS->get($ridx)->border(), $REGIONS->get($ridx)->target(), $REGIONS->get($ridx)->alt(), $REGIONS->get($ridx)->textlink(), $REGIONS->get($ridx)->extend(), $REGIONS->get($ridx)->code() );
# Cache busting. $display->bust($PARAMS{'bust'}, $PARAMS{'timestamp'});
# Rich media tracking. $display->track($PARAMS{'region'}, $PARAMS{'campaign'}, $PARAMS{'banner'}, $PARAMS{'publisher'}, $PARAMS{'referrer'});
# Display the panic banner. if ($PARAMS{'mode'} eq "IMAGE") { $DB->do("INSERT INTO avp_temporary (date, campaign, banner, region, bust, slot, country, ip, referrer, age) VALUES ('$PARAMS{'date'}', '-1', '-1', '$PARAMS{'region'}', '$PARAMS{'bust'}', '$PARAMS{'slot'}', 'XX', '$PARAMS{'remoteaddr'}', '$PARAMS{'referrer'}', '$PARAMS{'timestamp'}')");
AdvertPRO::HTML::redirect($display->image(), undef, 1); }
elsif ($PARAMS{'mode'} eq "LINK") { AdvertPRO::HTML::redirect($display->redirect(), undef, 1); }
else { AdvertPRO::HTML::header(undef, 1);
if ($display->code()) { print $display->code() . "\n\n"; }
else { my $output = "<a href=\"" . $display->redirect() . "\" target=\"" . $display->target(). "\">"; $output .= "<img src=\"" . $display->image() . "\" border=\"" . $display->border(). "\" width=\"" . $display->width() . "\" height=\"" . $display->height() . "\" alt=\"" . $display->alt() . "\" " . $display->extend() . ">"; $output .= "<br>" . $display->textlink() if ($display->textlink()); $output .= "</a>";
print "$output\n\n"; } } }
sub usr1_handler { # Write an error_log entry if enabled. if ($CONFIG->{'ERROR_LOGGING'} == 1) { if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) { while ($_ = shift(@_)) { print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [WARN] $_\n"; }
close (ERRORLOG); } } # We should exit now :) exit(0); }
sub term_handler { # Write an error_log entry if enabled. if ($CONFIG->{'ERROR_LOGGING'} == 1) { if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) { while ($_ = shift(@_)) { print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [SIGNAL] TERM signal caught - shutting down\n"; }
close (ERRORLOG); } }
# We should exit now :) exit(0); }
sub pipe_handler { # Write an error_log entry if enabled. if ($CONFIG->{'ERROR_LOGGING'} == 1) { if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) { while ($_ = shift(@_)) { print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [SIGNAL] PIPE signal caught - aborting request\n"; }
close (ERRORLOG); } } # We should finish this request. $request->Finish(); }
sub warn_handler { # Write an error_log entry if enabled. #if ($CONFIG->{'ERROR_LOGGING'} == 1) #{ # if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) # { # while ($_ = shift(@_)) # { # print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [WARN] $_\n"; # } # # close (ERRORLOG); # } #} }
sub die_handler { # Write an error_log entry if enabled. if ($CONFIG->{'ERROR_LOGGING'} == 1) { if (open (ERRORLOG, ">>" . $CONFIG->{'HTML_PATH'} . "/etc/error_log")) { while ($_ = shift(@_)) { print ERRORLOG "[" . AdvertPRO::Date::getDateTime() . "] [BANNERS." . $CONFIG->{'SCRIPTS_EXT'} . "] [$PARAMS{'remoteaddr'}] [" . AdvertPRO::HTML::urldecode($PARAMS{'referrer'}) . "] [$PARAMS{'mode'}] [$PARAMS{'region'},$PARAMS{'campaign'},$PARAMS{'banner'},$PARAMS{'publisher'}] [DIE] $_\n"; }
close (ERRORLOG); } } } </lj-cut>
|