#!/usr/local/bin/perl
######################
# Copyright © 2000 Portal Scripts.
# All Rights Reserved.
#
# The original developer of this software module and his/her company, the subsequent
# editors and their companies, have no liability for use of this
# software module or modifications thereof in an implementation.
#
# Permission to use, copy, and modify this software and its documentation on
# the server of the customer is hereby granted, provided that the above copyright
# notice, this paragraph and the following two paragraphs appear in all
# copies.
#
# This software program and documentation are copyrighted by Portal Scripts.
# The software program and documentation are supplied "as is", without any
# accompanying services. Portal Scripts does not
# warrant that the operation of the program will be
# uninterrupted or error-free.
#
# IN NO EVENT SHALL PORTAL SCRIPTS BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
# LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION.
#
######################
#use strict;
use vars qw(%CONFIG %months_hash );
my $real_path;
if($^O =~ m#win32#i){
if($ENV{'PATH_TRANSLATED'} ne ""){
$real_path = $ENV{'PATH_TRANSLATED'};
$real_path =~ s#\\#/#g;
$real_path =~ s#[^/]*$##;
chdir($real_path);
}
}
else{
if($ENV{'SCRIPT_FILENAME'} ne ""){
$real_path = $ENV{'SCRIPT_FILENAME'};
$real_path =~ s#[^/]*$##;
chdir($real_path);
}
}
require "../tools.pm";
my $output = "";
my ($cgi_url, $script_name) = &get_url;
$CONFIG{'CGI_URL'} = $cgi_url;
$CONFIG{'SCRIPT_NAME'} = $script_name;
opendir(MAIN, "..");
my @names = grep{m#\.name$#}readdir(MAIN);
closedir(MAIN);
my $main_script = shift @names;
$main_script =~ s#\.name$##;
undef $/;
open(FILE, "../data/default.txt");
flock(FILE, 2);
my $template = ;
flock(FILE, 8);
close(FILE);
$/ = "\n";
my %formdata = &Parse_Form;
my $type = $formdata{'type'};
chdir("stats");
print "Content-type: text/html\n\n";
if( $type eq "" ){
my $global_count = -s "global.count";
my $main_count = -s "main.count";
$output .= qq!
General Page Views
Total visits of the main page
Most Popular Categories
Recently visited Categories
Most Popular Search Terms
Recent Search Phrases
!;
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
exit;
}
if( $type eq "global_monthly" ){
opendir(DIR, ".");
my @months = map{[$_, -s $_, eval{m#^(\d+)#;$1}]} grep{m#^\d+\.\d+\.global\.count$#} readdir(DIR);
closedir(DIR);
$output .= "General monthly and daily page views
";
for my $month (sort{$a->[2]<=>$b->[2]}@months){
my $nice_name = $month->[0];
$nice_name =~ s#\.global\.count##;
$nice_name =~ s#\.# - #g;
# $output .= qq!
# - $nice_name: $month->[1] hits
# !;
$output .= qq!
- $nice_name: $month->[1] hits
!;
}
$output .= "
";
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
exit;
}
if( $type eq "main_monthly" ){
opendir(DIR, ".");
my @months = map{[$_, -s $_, eval{m#^(\d+)#;$1}]} grep{m#^\d+\.\d+\.main\.count$#} readdir(DIR);
closedir(DIR);
$output .= "Main page's monthly and daily page views
";
for my $month (sort{$a->[2]<=>$b->[2]}@months){
my $nice_name = $month->[0];
$nice_name =~ s#\.main\.count##;
$nice_name =~ s#\.# - #g;
# $output .= qq!
# - $nice_name: $month->[1] hits
# !;
$output .= qq!
- $nice_name: $month->[1] hits
!;
}
$output .= "
";
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
exit;
}
if( $type eq "global_days"){
my $month = $formdata{'days'};
$month =~ m#^(\d+)#;
my $cur_month = $1;
opendir(DIR, ".");
my @days = map{[eval{$_ =~ m#^(\d+)#; $1}, $_, -s $_]} grep{m#\.$month#} readdir(DIR);
closedir(DIR);
$output .= "General daily page views for $months_hash{$cur_month}
";
for my $day (sort{$a->[0]<=>$b->[0]}@days){
my $nice_name = $day->[1];
$nice_name =~ s#\.global\.count##;
$nice_name =~ s#\.# - #g;
$output .= qq!
- $nice_name: $day->[2] hits
!;
}
$output .= "
";
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
exit;
}
if( $type eq "main_days"){
my $month = $formdata{'days'};
$month =~ m#^(\d+)#;
my $cur_month = $1;
opendir(DIR, ".");
my @days = map{[eval{$_ =~ m#^(\d+)#; $1}, $_, -s $_]} grep{m#\.$month#} readdir(DIR);
closedir(DIR);
$output .= "Main page's daily page views for $months_hash{$cur_month}
";
for my $day (sort{$a->[0]<=>$b->[0]}@days){
my $nice_name = $day->[1];
$nice_name =~ s#\.main\.count##;
$nice_name =~ s#\.# - #g;
$output .= qq!
- $nice_name: $day->[2] hits
!;
}
$output .= "
";
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
exit;
}
if( $type eq "popular_cats" ){
if(-f "top_cats.log"){
open(FILE, "top_cats.log");
flock(FILE, 2);
my @lines = ;
flock(FILE, 8);
close(FILE);
chomp(@lines);
@lines = map{ eval {
my ($cat, $hit) = split("\t", $_);
my $cat2 = uri_unescape($cat);
my $cat3 = $cat;
$cat3 =~ s#/#_#g;
$cat2 =~ s#_# #g;
[$cat2, $hit, $cat3, $cat]
} }@lines;
$output .= "Most Popular Categories
";
for my $line (@lines){
my $cached = "";
if(-e "../../cache/$line->[2].txt"){
$cached = qq!(Currently cached)!;
}
else{
$cached = qq!(Not cached)!;
}
$output .= qq!
- $line->[0] $cached : $line->[1] hits
!;
}
$output .= "
";
}
else{
$output .= "No info available yet";
}
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
}
if( $type eq "popular_searches" ){
if(-f "top_searches.log"){
open(FILE, "top_searches.log");
flock(FILE, 2);
my @lines = ;
flock(FILE, 8);
close(FILE);
chomp(@lines);
@lines = map{ eval{my ($search, $hit) = split("\t", $_);my $search2 = uri_unescape($search);[$search2, $hit, $search]} }@lines;
$output .= "Most Popular Search Terms
";
for my $line (@lines){
$output .= qq!
- $line->[0] : $line->[1] hits
!;
}
$output .= "
";
}
else{
$output .= "No info available yet";
}
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
}
if( $type eq "last_cats" ){
if(-f "last_cats.log"){
open(FILE, "last_cats.log");
flock(FILE, 2);
my @lines = ;
flock(FILE, 8);
close(FILE);
chomp(@lines);
$output .= "Recently Visited Categories
";
for my $line (@lines){
my $line2 = uri_unescape($line);
$line2 =~ s#_# #g;
$output .= qq!
- $line2
!;
}
$output .= "
";
}
else{
$output .= "No info available yet";
}
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
}
if( $type eq "last_searches" ){
if(-f "last_searches.log"){
open(FILE, "last_searches.log");
flock(FILE, 2);
my @lines = ;
flock(FILE, 8);
close(FILE);
chomp(@lines);
$output .= "Recent Search Phrases
";
for my $line (@lines){
my $line2 = uri_unescape($line);
$line =~ s# #+#g;
$output .= qq!
- $line2
!;
}
$output .= "
";
}
else{
$output .= "No info available yet";
}
$template =~ s#\[module\]\s*MAIN\s*\[/module\]#$output#gsi;
print $template;
}