#!/usr/bin/perl -w

#<TITLE>Footer short</TITLE>
#<META name="description" content="This perl script prints a footer for a html page, with some stats.">
#<META name="icon" content="/~jipp/melk/perlt.jpg,66,38">
#made by: jipp@xs4all.nl

$WWWdir = "/www/";
foreach $i (keys %ENV){print "$i= ",$ENV{$i},"\n<br>";}
$uri=$ENV{'DOCUMENT_NAME'};


$name=$uri; 
print $name;
$fullname = "$WWWdir$name";
($page_begun,$css) = lookup_page_begun($fullname);

print $css;
$nameu=&toencode("http://kwark.ddns.org/$name");
$cssu=&toencode("http://kwark.ddns.org$css");
$htmlhelp="http://www.htmlhelp.com/cgi-bin/validate.cgi?url=$nameu&amp;input=yes";
$babelfish = "http://babelfish.altavista.digital.com/cgi-bin/translate?";
$babelfish .= "urltext=$nameu";
$babelfish .= "&quot;language=en";

$validate = "http://validator.w3.org/check?uri=$nameu";


$csscheck ="http://www.htmlhelp.com/cgi-bin/csscheck.cgi?url=$cssu&amp;links=WDG&amp;input=yes";

#$lta1 = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=link%3A$nameu";
#$lta1 = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=link%3A%2F%7Ejipp%2F";
#$lta2 = "&r=&d0=&d1=";
$alta="http://www.altavista.digital.com/cgi-bin/query?pg=q&quot;what=web&quot;fmt=.&quot;q=link%3A$nameu&quot;r=&quot;d0=&quot;d1=";
$sname=$name;
$sname =~ s/\.//g;
$sname =~ s/\-//g;

$date = `ls -lc $fullname`;
($moddate) = $date =~  /(\W\w+\s+\d+\s\d+\:\d+)/;
#stat ($fullname);
#$moddate = -M _;
#($date) = $date =~ /.+([A-Z].+)\/www.+/;

$nowdate= `date`;
chop ($nowdate);


print <<GROK;
GROK

&printstat;

exit(1);

sub printstat{
$backsearch = $alta;
my $beguns =<<GROK;
 <a href="$babelfish"
  onMouseOver="window.status='Try babelfish on this page.' ; return true"
 >Page</a> started: $page_begun
 <br>
GROK
print <<GROK;
<!--  begin footer for: $name 
      see http://www.xs4all.nl/~jipp/perl.html for more info
-->
<br clear="all">
<p align="right"><a href="http://www.opencontent.org/home.shtml"
 ><font size="-3">All rights reserved.</font></a>
<br><a href="http://www.opencontent.org/opl.shtml"
 ><font size="-3">All</font></a><font size="-3"><a 
 href="mailto:pip\@dds.nl?subject=copywrong $name"> wrongs </a></font><a 
 href="http://www.opencontent.org/opl.shtml"><font 
 size="-3">reversed.</font></a></p>



	Validate:<ul><li>
   <a   href="$csscheck">$css</a></li><li>
   </li>
   <li>$beguns</li>
   <li><a href="$htmlhelp">$name</a></ul>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  <td align="left" width="40%">
   <font size="-2">
   <a 
	href="$backsearch"
	onMouseOver="window.status='Search for pages linking to $name' ; return true" 
   >Page </A><a href="$validate"
	onMouseOver="window.status='Validate this page.' ; return true"
   >by </a><a 
	href="mailto:jipp\@xs4all.nl?subject=This ~/jipp/$name thingie is wowzers!"
	onMouseOver="window.status='Mail me about $name' ; return true"    
>Jip</A>

 <img src="http://kwark.ddns.org/htbin/ip.gif" height="1" width="1" alt="">  
 <br>

 <a href="/~jipp/latest.html#$name"
  onMouseOver="window.status='View pages sorted by newestness.' ; return true"	
 >Last modified</A>: $moddate
 <br>
 </font>
</td>
<td align="center" valign="bottom" width="20%">
 <font size="-2">
 <a href="/~jipp/kwark-ip.html"
     onMouseOver="window.status='Index of /~jipp/' ; return true"
	 target="_top"
 >Index</a>
 </font>
</td>
<td align="right" width="40%">
<a 
	href="http://www.nedstat.nl/cgi-bin/viewstat?name=jip$sname"
	onMouseOver="window.status='Nedstat statistics for $name.html';return true"
><img src="http://www.nedstat.nl/cgi-bin/nedstat.gif?name=jip$sname" border=0
align="right" width="32" height="32" alt="NedStat"></a>



      <script language="JavaScript" type="text/javascript">
      <!--
      document.write("<img src=\\"http://www.nedstat.nl/cgi-bin/referstat.gif?name=jip$sname&refer="+escape(top.document.referrer)+"\\" width=1 height=1 alt=\\"R\\">");
      // -->
      </script>


</td></tr></table>
<!-- end footer for: $name -->
GROK
}


sub lookup_page_begun{
        local($file) = @_;
        local($head,$begun);
        if (open(IN, "<$file")) {
                line: while (<IN>) {
                        $head .= $_;
                        if ( m!</head!i ){
                                        last line;
                        }
                }
        }
        ($begun) = $head =~ m!<meta name=\"begun\" content=\"(.+)\">!i;
	($css)= $head =~ m!<link rel=\"stylesheet\" href=\"(.+)\" type!i;
        return $begun,$css;
}  


sub webify {
    my ($i)=@_;
    $i =~ s!/!%2f!g;
    $i =~ s!:!%3a!g;
    $i =~ s!\.!%2e!g;
    $i =~ s!~!%7e!g;
    $i;
}
sub toencode{
    my($toencode) = @_;
    $toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
    $toencode=~s/\%20/+/g;
    return $toencode;
}

