- Fixed date comparison error that caused the same downloads to be counted
multiple times.
- Added support for requests and country names containing apostrophes (').
- Added default title for requests for unknown or deleted items.
1 parent c7f1869 commit e460fe0648076d1964649326b8a51d4a55983629
nstanger authored on 25 Apr 2006
Showing 1 changed file
View
58
Repositories/statistics/scripts/eprints-usage_src.php
$date = preg_replace("/\//", " ", $date);
$when = getdate(strtotime($date));
$request_date = $when["year"]."-".$when["mon"]."-".$when["mday"];
$datetestB = strtotime($request_date);
if ($datetestB < $datetestA)
/* NJS 2006-04-25
Changed date comparison to <= from < to avoid the problem
of counting multiple times downloads whose $request_date
== $lastproc. This only occurred if you ran this script
several times per day. For example, if you ran this
script five times per day, all the downloads that
occurred during that day would be counted EVERY TIME this
script ran, thus overinflating your stats by a factor of
up to five :(
 
If finer granularity for stats updates is desired, the
solution would be to use the full timestamp rather than
just the date.
*/
if ($datetestB <= $datetestA)
continue;
// NJS 2005-11-25 Added regexp for EPrints short URLs.
if(preg_match("/GET \/archive\/0{1,8}\d{1,4}\/\d\d\//i",$buffer) || preg_match("/GET \/\d{1,4}\/\d\d\//i",$buffer)) {
if($eprint_name=='') {
// Do nothing.
} else {
$eprint_name = mysql_escape_string($eprint_name);
/* NJS 2006-04-25
Requests containing apostrophes (') are dumped by
MySQL unless we escape them. Looking in the GeoIP
files I also see country names with apostrophes, so
escape that as well. Everything else should be fine.
*/
$uniquebits = mysql_escape_string($uniquebits);
$country_name = mysql_escape_string($country_name);
// end NJS 2006-04-25
$query = "
INSERT into view (uniquebits,archive_name,ip,request_date,archiveid,country_code,country_name,view_type,eprint_name)
values('".$uniquebits."','".$archive_name."','".$ip."','".$request_date."',".$archive.",'".$country_code."','".$country_name."','".$view_type."','".$eprint_name."')";
$result = mysql_query($query,$connect);
$sqldatabase = $db;
$db = mysql_select_db($sqldatabase,$connect2);
$query3 = "select title from archive where eprintid = $eprintid";
$result3 = mysql_query($query3,$connect2);
$row = mysql_fetch_assoc($result3);
$row["title"] = trim($row["title"]);
$row["title"] = preg_replace("/\s+/"," ",$row["title"]);
return $row["title"];
// NJS 2006-04-25 Added check for empty result, probably a deleted item.
if (mysql_num_rows($result3) == 0) {
return "Unknown item ($eprintid)";
} else {
$row = mysql_fetch_assoc($result3);
$row["title"] = trim($row["title"]);
$row["title"] = preg_replace("/\s+/"," ",$row["title"]);
return $row["title"];
}
}
 
?>