This is a script used to upload and parse a data file
#!/usr/bin/perl -w
# This Script was developed for www.miniplantkingdom.com.
# Their site is run by Perl CGI scripts reading a flat
file database
# to fill out the various web pages on the fly.
# This file uploads a database created from a FileMaker
File and output as comma delimited
# text file to be processed, then it checks the file for
properly filled out records, usually
# dropping the record if it is not correct.
# After error checking, the corrected text file is saved
for CGI use by the site,
# and serious errors are reported back to the user, so
they can decide if they want to try
# uploading again after fixing the data in the FileMaker
File.
# after uploading, a web page is made for each plant record
that is uploaded
# and an index is made with a listing linking to all the
plant web pages.
# the individual files are made for spiders and web crawlers
to identify for search engines
my $theloop;
# the repeating part of the loop
my $trlr;
# closing section of html file
$query = new CGI;
open(HTML, $htmlfile) || die "can't open
$htmlfile for parsing";
open(NEWFL, ">../plants/plantindex.html")
|| die "can't open plantindex.html for input";
#
read the entire html file
my $x = $/;
undef $/;
my $rawhtml = <HTML>
$/ = $x;
#
Divide the html into three sections, header, trailer and loop
$hdr = $rawhtml;
$hdr =~ s/\<\!-- LOOP -->.*$//si;
#
chop off everything starting with <!-- LOOP
$theloophdr = substr($rawhtml, length($hdr));
# chop off header
$theloophdr =~ s/^.*\<\!-- LOOPHEADER
-->(.*)\<\!-- \/LOOPHEADER -->.*$/$1/si;
# read
loopheader
$theloop = substr($rawhtml, length($hdr)
+ length($theloophdr));
# chop off header and loopheader
(includes loop start tag)
$theloop =~ s/^.*\<\!-- \/LOOPHEADER
-->(.*)\<\!-- \/LOOP -->.*$/$1/si;
# read from end
of loopheader to end of loop
$theloop =~ s/oneplant\.cgi\?plant=\$\{plantid\}/\$\{plantid\}\.html/ig;
$theloop =~ s(src=")(src="../)ig;
$theloop =~ s(src=')(src='../)ig;
$trlr = substr($rawhtml, length($hdr) +
length($theloophdr) + length($theloop));
# chop off loop
and hdr
$trlr =~ s/^.*\<\!-- \/LOOP -->(.*$)/$1/si;
# read from end of loop to end of file
#
Done with the "HTML compilation" phase
&setPlantRec(0);
#
Adjust all the hrefs for the position of the files (go up a level to
find everything)
$hdr =~ s(nav_top.macro)(../nav_top.macro)ig;
$hdr =~ s(nav_left.macro)(../nav_left.macro)ig;
$hdr = repl($hdr);
$hdr =~ s(href=")(href="../)ig;
$hdr =~ s(src=")(src="../)ig;
$hdr =~ s(href=')(href='../)ig;
$hdr =~ s(src=')(src='../)ig;
$hdr =~ s('navs/navbar)('../navs/navbar)ig;
$hdr =~ s{\.\./javascript}{javascript}ig;
$hdr =~ s{'index.html'}{'../index.html'}ig;
$hdr =~ s{'plant_groups.cgi'}{'../plant_groups.cgi'}ig;
$hdr =~ s{'search.cgi}{'../search.cgi}ig;
$hdr =~ s{'order.cgi'}{'../order.cgi'}ig;
$hdr =~ s{'about.cgi'}{'../about.cgi'}ig;
$hdr =~ s{'contact.cgi'}{'../contact.cgi'}ig;
print NEWFL $hdr;
my $n=0;
my %hash;
my $category = " ";
my @idparts;
foreach my $hold (@linesplant) {
%hash = %{$hold};
$plantid = $hash{plantid};
@idparts = split("_", $plantid);
if (!($idparts[0] eq $category))
{
$category = $idparts[0];
&setDescRec($category);
print NEWFL repl($theloophdr,
"toc");
}
&setPlantRec($n);
print NEWFL repl($theloop,
"toc");
$n++;
}
print NEWFL repl($trlr);
close(HTML);
close(NEWFL);
# this section writes the individual plant files
$htmlfile = "../oneplant.macro";
$query = new CGI;
open(HTML, $htmlfile) || die "can't open
$htmlfile for parsing";
#
read the entire html file
$x = $/;
undef $/;
$rawhtml = <HTML>
$/ = $x;
#
Done with the "HTML compilation" phase
my $thishtml;
my $outputhtml;
$n=0;
foreach my $hold (@linesplant) {
%hash = %{$hold};
open(NEWF, ">../plants/$hash{plantid}.html")
|| die " cant open $hash{plantid}.html for input.";
&setPlantRec($n);
$thishtml = $rawhtml;
$thishtml =~ s(nav_top.macro)(../nav_top.macro)ig;
$thishtml =~ s(nav_left.macro)(../nav_left.macro)ig;
$outputhtml = repl($thishtml);
#adjust
nav to call up a level
$outputhtml =~ s(href=")(href="../)ig;
$outputhtml =~ s(src=")(src="../)ig;
$outputhtml =~ s(href=')(href='../)ig;
$outputhtml =~ s(src=')(src='../)ig;
$outputhtml =~ s('navs/navbar)('../navs/navbar)ig;
$outputhtml =~ s{../javascript}{javascript}ig;
$outputhtml =~ s{'index.html'}{'../index.html'}ig;
$outputhtml =~ s{'plant_groups.cgi'}{'../plant_groups.cgi'}ig;
$outputhtml =~ s{'search.cgi}{'../search.cgi}ig;
$outputhtml =~ s{'order.cgi'}{'../order.cgi'}ig;
$outputhtml =~ s{'about.cgi'}{'../about.cgi'}ig;
$outputhtml =~ s{'contact.cgi'}{'../contact.cgi'}ig;
print NEWF $outputhtml;
close(NEWF);
$n++;
}
}
}