Приглашаем посетить
WebAdverts (CGI Display)
############################################
## ##
## WebAdverts (CGI Display) ##
## by Darryl Burgdorf ##
## (e-mail burgdorf@awsd.com) ##
## ##
## last modified: 5/27/97 ##
## copyright (c) 1997 ##
## ##
## latest version is available from ##
## http://awsd.com/scripts/ ##
## ##
############################################
sub insertadvert {
require "/usr/www/users/dburgdor/scripts/ads/ads_configure.pl";
&ConfigureAdverts;
$ADVUseLocking = 1;
$ADVWrapCounter = 0;
&ADVdisplayad;
srand();
}
sub ADVdisplayad {
$ADVWrapCounter++;
open (ADVCOUNT, "+<$advertcount");
$ADVlockerror = &ADVLockFile(ADVCOUNT);
if ($ADVlockerror) {
print "[ File Lock Error ($advertcount)! ]";
return;
}
@ADVlines = <ADVCOUNT>;
if ((@ADVlines < 4) || ($ADVWrapCounter > @ADVlines-3)) {
&ADVUnlockFile(ADVCOUNT);
close (ADVCOUNT);
return;
}
foreach $ADVline (@ADVlines) { chop ($ADVline) if ($ADVline =~ /\n$/); }
$ADVcount = $ADVlines[0];
$ADVexposures = $ADVlines[1];
$ADVdisplayad = $ADVlines[$ADVcount+2];
$ADVexposures++;
$ADVcount++;
if ($ADVcount > @ADVlines-3) { $ADVcount = 1; }
$ADVlines[0] = $ADVcount;
unless ($ADVshown > 0) {
$ADVlines[1] = $ADVexposures;
}
truncate (ADVCOUNT,0);
seek(ADVCOUNT, 0, 0);
foreach $ADVline (@ADVlines) { print ADVCOUNT "$ADVline\n"; }
&ADVUnlockFile(ADVCOUNT);
close (ADVCOUNT);
open (ADVDISPLAY, "+<$adverts_dir/$ADVdisplayad.txt");
$ADVlockerror = &ADVLockFile(ADVDISPLAY);
if ($ADVlockerror) {
print "[ File Lock Error ($ADVdisplayad.txt)! ]";
return;
}
@ADVlines = <ADVDISPLAY>;
foreach $ADVline (@ADVlines) { chop ($ADVline) if ($ADVline =~ /\n$/); }
($ADVmax,$ADVshown,$ADVvisits,$ADVurl,$ADVimage,$ADVheight,$ADVwidth,$ADValt,$ADVpass,$ADVtext,$ADVstart,$ADVweight) = @ADVlines;
unless ($ADVweight) { $ADVweight = 1; }
unless ($ADVtext) { $ADVtext = "Please Visit Our Sponsor!"; }
if ((($AdvertTracking < 2) && ($ADVmax <= $ADVshown)) ||
(($AdvertTracking == 2) && ($ADVmax <= $ADVvisits)) ||
((rand) > $ADVweight)) {
&ADVUnlockFile(ADVDISPLAY);
close (ADVDISPLAY);
&ADVdisplayad;
return;
}
print "<P ALIGN=CENTER><A HREF=\"$gotoadvert?$ADVdisplayad\">";
print "<IMG SRC=\"$ADVimage\" HEIGHT=$ADVheight WIDTH=$ADVwidth ALT=\"$ADValt\">";
print "</A><BR><SMALL><A HREF=\"$gotoadvert?$ADVdisplayad\">";
print "$ADVtext</A></SMALL></P>\n";
$ADVshown += 1;
truncate (ADVDISPLAY,0);
seek(ADVDISPLAY, 0, 0);
print ADVDISPLAY "$ADVmax\n";
print ADVDISPLAY "$ADVshown\n";
print ADVDISPLAY "$ADVvisits\n";
print ADVDISPLAY "$ADVurl\n";
print ADVDISPLAY "$ADVimage\n";
print ADVDISPLAY "$ADVheight\n";
print ADVDISPLAY "$ADVwidth\n";
print ADVDISPLAY "$ADValt\n";
print ADVDISPLAY "$ADVpass\n";
print ADVDISPLAY "$ADVtext\n";
print ADVDISPLAY "$ADVstart\n";
print ADVDISPLAY "$ADVweight\n";
&ADVUnlockFile(ADVDISPLAY);
close (ADVDISPLAY);
return;
}
sub ADVLockFile {
local(*FILE) = @_;
local($ADVTrysLeft) = 10;
if ($ADVUseLocking) {
while ($ADVTrysLeft--) {
$ADVlockresult = eval("flock(FILE,6)");
if ($@) {
$ADVUseLocking = 0;
last;
}
if (!$ADVlockresult) {
select(undef,undef,undef,0.1);
}
else {
last;
}
}
}
if ($ADVTrysLeft >= 0) {
return 0;
}
else {
return -1;
}
}
sub ADVUnlockFile {
local(*FILE) = @_;
if ($ADVUseLocking) {
flock(FILE,8);
}
}
1;