# htmlrules for AAO Web pages - $html contains the html page.
# The Header
if (-r "/www/webdoc/template/menu.html") {
$Header = `cat ./template/menu.html`;
}
elsif (-r "./template/menu.html") {
$Header = `cat ./template/menu.html`;
}
else {
die("Can't find the template file");
}
# The footer
if (-r "./template/footer.html") {
$Footer = `cat ./template/footer.html`;
}
elsif (-r "./template/footer.html") {
$Footer = `cat ./template/footer.html`;
}
else {
die("Can't find the template file");
}
##############################
#
# MAIN **
#
# Replace background colour with background image
#$html =~ s/bgcolor\s*=\s*"[^"]+"/background="2dfbg.gif"/i;
# Add headers and footers
replace(\$html,
'',
$Header);
replace(\$html,
'',
$Footer);
#ummmm...
dirlevel(\$html, $name);
#############################
#
# subroutines
#
sub replace {
my($text,$old,$new)=@_;
# Translate $old into a regex - first quote all funny HTML
# characters
my $regex = quotemeta($old);
# Make a regex from hell-replace all spaces (denote by "\" after quotemeta)
# with expression matching multiple \s and/or   - "(\s|\ \;)*";
#$regex =~ s/(\\ )+/(\\s|\\ \\;)*/g;
# Do the substition
$$text =~ s/$regex/$new/gi;
}
sub dirlevel {
my($text,$name)=@_;
# $testing-1 is the number of "/" in $name
my $testing = split "/",$name;
# print "after split... $testing";
# start with current directory and add a ".." for each "/" in $name
$dir = ".";
while (--$testing)
{
$dir = "$dir/..";
}
# change the HEREDIR string
# referenced in header and footer to appropriate directory level reference
$$text =~ s/HEREDIR/$dir/g;
}
1; # Return true on file include