#!/usr/bin/perl ############################### # Hot Links Pro 3 index.cgi # Created by Mike Ramirez # Nothing below here is configurable ############################### use CGI; my $q = CGI->new; print $q->header; # Display error if setup hasn't been run unless (-e './source/config.pl') { print "You must run the setup script before accessing this page."; exit; } require './source/headerfooter.pl'; require './source/config.pl'; require './source/poplist.pl'; require './source/recentadd.pl'; require './source/linkbuild.pl'; require './lang/langset.pl'; ############################### $halftable = ($indexcattable/2); opendir (DIR, "$catinfopath"); @catbuild = grep (!/^\.\.?$/, readdir (DIR)); closedir(DIR); opendir (DIR2, "$newfilespath"); @newfiles = grep (!/^\.\.?$/, readdir (DIR2)); closedir(DIR2); my $filetolock = $datafilepath; my $tempfile = $filetolock . ".lock"; open (LOCK, ">$tempfile"); if ($useflock == 1) {flock (LOCK, 2)} open (FILE, "$datafilepath"); @newlinkstemp = ; close(FILE); close(LOCK); unlink ($tempfile); @newlinks = sort {$b <=> $a} @newlinkstemp; #reverse link order, new links at the top &header; print <<"HTML";
 Web Directory \n
HTML # Get category list my $filetolock = $catfilepath; my $tempfile = $filetolock . ".lock"; open (LOCK, ">$tempfile"); if ($useflock == 1) {flock (LOCK, 2)} open (FILE, "$catfilepath"); @catsx = ; close(FILE); close(LOCK); unlink ($tempfile); $getcatcount = 0; foreach $cat (@catsx) { my @catline = split(/\|/, $cat); if ($catline[3] eq "main") { $catsy{$catline[1]} = "$catline[0]|$catline[2]"; $getcatcount++; } } foreach $key (sort keys %catsy) { #alphabetize categories #print "$key => $catsy{$key}"; used for testing... push(@cats, "$catsy{$key}|$key"); } $tablecut = ($getcatcount/$categorycolumns); if ($tablecut =~ m/\./g) {$tablecut = int $tablecut; $tablecut++} my $dobuild = 0; foreach $line (@cats) { chomp($line); my @catinfo = split(/\|/, $line); $description = $catinfo[1]; $subcount = 0; if ($catinfo[1] =~ m/\[.*\]/g) { $description =~ s/\[//; $description =~ s/\]//; chomp($description); my @subs = split(/, /, $description); foreach $sub (@subs) { $tempsub = $sub; chomp($tempsub); foreach $line (@catsx) { chomp($line); my @cat2info = split(/\|/, $line); if ($tempsub == $cat2info[0]) { $printsub = $line; $subcount++; } } my @subinfo = split(/\|/, $printsub); $convertsub = " $subinfo[1]"; if ($subcount <= 2) { $description =~ s/$sub/$convertsub/; } elsif ($subcount == 3) { $description =~ s/$sub/$convertsub/; } elsif ($subcount == 4) { $description =~ s/$sub/\.\.\./; } elsif ($subcount > 4) { $description =~ s/$sub//; } } } #----------- Do the category building ------------------# $catid = $catinfo[0]; $catname = $catinfo[2]; if ($showlinkcounts) {&countlinks($catinfo[0], "main")} if ($dobuild == $tablecut) {print ""; $dobuild=1} else {$dobuild++;} &buildcat; } print <<"HTML";
HTML # Get index page template open (FILE, "$basepath/indexpage.txt"); my @indextemp = ; close(FILE); # Print template foreach $line (@indextemp) { chomp($line); $line =~ s/\[tableborder\]/$tableborder/ig; $line =~ s/\[bgcolor\]/$bgcolor/ig; $line =~ s/\[cattable\]/$indexcattable/ig; print "$line\n"; } print <<"HTML";
HTML ## create popular link list ## unless ($popcutoff == 0) {&poplist} ###################### print "
"; ## create recent additions link list ## unless ($recentadd == 0) {&showrecent} ############################# print <<"HTML";
HTML &footer; ################################################## sub countlinks { ################################################## if ($_[2]) {$count = $_[2]} else {$count = 0; $foundnew = ''} foreach $x (@newlinks) { chomp($x); @linkinfo = split(/\|/, $x); my $udate = $linkinfo[13]; my $comparedate = time; my $endnew = ($newlength * 86400) + $udate; if (($endnew >= $comparedate) && ($linkinfo[1] == $_[0])) {$foundnew = 1} } foreach $link (@newlinks) { chomp($link); my @linkinfo = split(/\|/, $link); if ($linkinfo[1] == $_[0]) {$count++} } my $filetolock = "$_[0].$_[1]"; my $tempfile = $filetolock . ".lock"; open (LOCK, ">$catinfopath/$tempfile"); if ($useflock == 1) {flock (LOCK, 2)} open (FILE, "$catinfopath/$_[0].$_[1]"); my @category = ; close(FILE); close(LOCK); unlink ("$catinfopath/$tempfile"); foreach $y (@category) { chomp($y); @subs = split(/\|/, $y); &countlinks($subs[0], "sub", $count) } } ################################################## sub buildcat { ################################################## if ($foundnew == 1) {$shownew = "$displaynew"} else {$shownew = ''} if ($showlinkcounts == 1) {$count = "( $count )";} print " $catname  $count $shownew
\n"; if ($showcatdescriptions == 1) {print "$description

\n";} }