###################### # 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 %VARS %stop_list); sub access_logs { $VARS{'RAW_CURRENT_CAT'} =~ s#/appr_okay$##; unless(-d "logs/stats"){ mkdir("logs/stats", 0755); } chdir("logs/stats"); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon++; $year += 1900; increment_count("global.count"); increment_count("$mon.$year.global.count"); increment_count("$mday.$mon.$year.global.count"); if($VARS{'PAGE_TYPE'} eq "main"){ increment_count("main.count"); increment_count("$mon.$year.main.count"); increment_count("$mday.$mon.$year.main.count"); } elsif($VARS{'PAGE_TYPE'} eq "cat"){ add_to_up("last_cats.log", $CONFIG{'MAX_LOGS'}, $VARS{'RAW_CURRENT_CAT'}); cat_max_hit_upd("top_cats.log", $CONFIG{'MAX_LOGS'}, $VARS{'RAW_CURRENT_CAT'}); } elsif($VARS{'PAGE_TYPE'} eq "search"){ my $search = $VARS{'RAW_SEARCH_STRING'}; $search =~ s#\+# #g; add_to_up("last_searches.log", $CONFIG{'MAX_LOGS'}, $search); search_max_hit_upd("top_searches.log", $CONFIG{'MAX_LOGS'}, $search); } chdir("../.."); } sub increment_count { my ($file) = @_; open(FILE, ">>$file"); flock(FILE, 2); print FILE "\n"; flock(FILE, 8); close(FILE); } sub add_to_up { my ($file, $limit, $string) = @_; open(FILE, "$file"); flock(FILE, 2); my @lines = ; flock(FILE, 8); close(FILE); if(scalar(@lines) > $limit){ @lines = @lines[0..($limit-1)]; } unshift(@lines, "$string\n"); my $out = join('', @lines); open(FILE, ">$file"); flock(FILE, 2); print FILE $out; flock(FILE, 8); close(FILE); } sub cat_max_hit_upd { my ($file, $limit, $cat) = @_; my %hits; if(-f $file){ open(FILE, "$file"); flock(FILE, 2); my @lines = ; flock(FILE, 8); close(FILE); chomp(@lines); if(scalar(@lines) > $limit){ @lines = @lines[0..($limit-1)]; } for my $line (@lines){ my ($cur_cat, $hit) = split("\t", $line); $hits{$cur_cat} = $hit; } } $hits{$cat}++; my @new_lines = map { join("\t", $_, $hits{$_}) } sort{ $hits{$b} <=> $hits{$a} } keys %hits; open(FILE, ">$file"); flock(FILE, 2); for (@new_lines){ print FILE "$_\n"; } flock(FILE, 8); close(FILE); } sub search_max_hit_upd { my ($file, $limit, $search) = @_; my @searches = $search =~ m#([^\s]+)#g; my %hits; if(-f $file){ open(FILE, "$file"); flock(FILE, 2); my @lines = ; flock(FILE, 8); close(FILE); chomp(@lines); if(scalar(@lines) > $limit){ @lines = @lines[0..($limit-1)]; } for my $line (@lines){ my ($cur_search, $hit) = split("\t", $line); $hits{$cur_search} = $hit; } } for my $term (@searches){ $hits{$term}++; } my @new_lines = map { join("\t", $_, $hits{$_}) } sort{ $hits{$b} <=> $hits{$a} } grep{ !(exists $stop_list{$_}) }keys %hits; open(FILE, ">$file"); flock(FILE, 2); for (@new_lines){ print FILE "$_\n"; } flock(FILE, 8); close(FILE); } 1;