index (13)


=addon
=cut
my $configfile = "classifieds.cgi";
my $update = 1200;
my $desclength = 250;
my $phraselength = 75;
=head
=cut
use strict;
my %config;
my %category = ();
open(DAT, $configfile)||logerr("index.txt: Cannot open $configfile");
my $file = join '', ;
close(DAT);
eval("\%category = ($1);") if($file=~/\%category\s*\=\s*\((.*?)\)\s*;/s);
eval("\$config{basepath} = $1") if($file=~/\$config\{["']?basepath["']?\}\s*=\s*([^;]*?)\s*;/s);
logerr("index.txt: Cannot extract \%category from $configfile.") unless scalar(@{[keys %category]});
logerr("index.txt: Cannot extract basepath from $configfile.") if $config{basepath} eq '';
update_index();
sub logerr{
open ERR, ">INDEX_ERROR";
print ERR "[".scalar(localtime(time))."] $_[0]\n";
close ERR;
exit
}
sub update_index{
open(RESUME, "$config{basepath}resume.dat");
$_ = ;
chomp;
my($resumetime,$resumedir,$resumefile,$resumedbsize) = split /\t/;
close(RESUME);
$resumedir = '' if $category{$resumedir} eq '';
$resumefile = '' if $resumedir eq '';
$resumefile = '' if !-e "$config{basepath}$resumedir/$resumefile.dat";
exit if $resumedir eq '' && time < $resumetime; # No new update
exit if time < $resumetime+15;
my $dbsize = abs $resumedbsize;
my $starttime = time;
my $thistime;
my $counter = 0;
unlink "./core" if -e "./core";
IDXCAT: foreach my $dir (sort keys %category){
my $resumethis = 0;
if($resumedir ne ''){
next if $dir ne $resumedir;
$resumedir = '';
$resumethis = 1;
open(IDX, ">>$config{basepath}tmp_$dir.dat");
}else{
open(IDX, ">$config{basepath}tmp_$dir.dat");
}

opendir(DIR, "$config{basepath}$dir");
readdir(DIR);readdir(DIR);
my @files = sort {int($a) <=> int($b)} readdir(DIR);
IDXFILE: foreach my $file(@files){
$file = int $file;
if($resumethis){
if($resumefile ne ''){
next if $file ne $resumefile;
$resumefile = '';
next;
}
}

open(DAT, "$config{basepath}$dir/$file.dat") || next IDXFILE;
my ($title, $rgt, $rht, $desc, $image, $url, $firstrft, @rfts) = ;
close DAT;
$dbsize += -s "$config{basepath}$dir/$file.dat";
chomp $title;
chomp $desc;
$title=~s|\s+| |og;
$firstrft =~s|\[.*$||;
if($#rfts>=20){ @rfts = @rfts[($#rfts-19)..$#rfts] }
my $users;
foreach(@rfts){
$_=~s|\[.*$||;
$users .= " $_";
}
$desc=~s|||oig; #