#!/usr/bin/perl # *********************** # Name: hierarchy.pl # Author: Joe Ryan # Date Finished: August 10th, 2001 # Where Used: http://amherst.k12.oh.us/cgi-bin/weblog/hierarchy.pl # Description: An extension to mainlog.pl that lets the # user browse through the amherst website, showing the hits # per directory and per file. Note that the script # doesn't directly run off the weblog, but rather a text # file that is created after processing the weblog. open(DATA, 'pagehits.txt'); @mlines = ; close(DATA); $cutat = 2; # recursive function that prints the hierarchy sub print_hierarchy { my ($newlevelref, $newhitsref, $x, $stophere, $plvars, $temp, $temp1, $resume) = @_; my (@newlevel) = @$newlevelref; my (@newhits) = @$newhitsref; if ($x<=$cutlevelat) { print "\n"; } else { return 1; } } use CGI; $query = CGI::new(); # $cutlevelat is how many levels out a directory is from the base $cutlevelat = $query->param("cutlevelat"); $cutlevelat=0 if (!$cutlevelat); for ($i=0; $i<$cutlevelat; $i++) { eval ("\$pathlevel".$i." = \$query->param(\"pathlevel".$i."\")"); } print "Content-type: text/html\n\nHierarchy View\n"; @mypath = (""); @myhits = (0); $y=0; $v=0; for ($i=0; $i<$cutlevelat; $i++) { eval("\$n".$i."=0"); } for($i=0; $i<@mlines; $i++) { @entry = split (' ', $mlines[$i]); @path = split (/\//, $entry[0]); $temp=""; $x=1; for (; $x<=$cutat;$x++) { $path1[$x-1]=$path[$x-1]; $temp.=$path[$x-1]; $temp.= "/"; } $breakcheck=1; for ($c=0; $c<$cutlevelat; $c++) { $breakcheck=1; eval("\$pathlevel=\$pathlevel".$c); if ($path[$#path1+$c] eq $pathlevel) { eval("\$meep=\@newlevel".$c); for($z=0; $z<$meep; $z++) { eval ("\$narf=\$newlevel".$c."[\$z]"); if ($path[$#path1+1+$c] eq $narf) { eval ("\$newhits".$c."[\$z]+=\$entry[1]"); $breakcheck=0; } } if ($breakcheck) { eval("\$newlevel".$c."[\$n".$c."] = \$path[\$\#path1+1+".$c."]"); eval("\$newhits".$c."[\$n".$c."] = \$entry[1]"); eval("\$n".$c."++"); } } } $entry[0]=$temp; $breakcheck=1; for($x=0; $x<@mypath; $x++) { if ($entry[0] eq $mypath[$x]) { $myhits[$x]+=$entry[1]; $breakcheck=0; } } if ($breakcheck) { $mypath[$t]=$entry[0]; $myhits[$t]=$entry[1]; $t++; } } @indices = (0 .. $#myhits); @sorted_indices = sort {$myhits[$b] <=> $myhits[$a]} @indices; @myhits = @myhits[@sorted_indices]; @mypath = @mypath[@sorted_indices]; for ($i=0; $i<$cutlevelat; $i++) { eval("\@indices = (0 .. \$\#newhits".$i.")"); eval("\@sorted_indices = sort {\$newhits".$i."[\$b] <=> \$newhits".$i."[\$a]} \@indices"); eval("\@newhits".$i." = \@newhits".$i."[\@sorted_indices]"); eval("\@newlevel".$i." = \@newlevel".$i."[\@sorted_indices]"); } # find where the next level of the hierarchy is supposed to go for ($i=0; $i<$cutlevelat-1; $i++) { eval ("\$stophere".($i+1)."=0"); eval ("\$meep=\@newlevel".$i); eval ("\$pathlevel=\$pathlevel".($i+1)); for ($x=0; $x<$meep; $x++) { eval ("\$narf=\$newlevel".($i)."[\$x]"); if ($narf eq $pathlevel) { eval ("\$stophere".($i+1)."=\$x"); } } } print "

Individual Page Hits

\n\n"; for($i=0; $i<@mypath; $i++) { print "\n"; } print "
\n"; my (@path) = split (/\//, $mypath[$i]); print $myhits[$i]." "; print "Amherst Steele"; $temp = "http://www.amherst.k12.oh.us/"; $temp1 = "/"; if ($path[1] eq ""){$stop = 1;} $x=1; for ($x=1; $x < @path && $x < $cutat && $x != $stop; $x++) { print " > "; $temp .= $path[$x]; $temp1 .= $path[$x]; $p_count = ($path[$x] =~ tr/\.//); if ($p_count < 1) {$temp.="/"; $temp1.="/";} print "".$path[$x].""; } $plvars = "&pathlevel0=$path[$#path]"; $endpath = $path[$#path]; if ($path[$#path] eq $pathlevel0) { print_hierarchy(\@newlevel0, \@newhits0, 1, $stophere1, $plvars, $temp, $temp1, $resume); } $p_count = ($endpath =~ /\.//); if ($p_count < 1) { print " > "; } $stop=0; print " +"; print "\n
";