<?php
// Hotlink Log and Image Watermarking Script
// Copyright (C) 2005 SillyJokes.co.uk
// Break a logfile line into an array
function MungLogLine($buf)
{
$retval = array();
// can't use explode to break down the string, because the referrer may contain commas
$cpos = strpos($buf,',');
if ($cpos === FALSE)
{
return FALSE;
}
$retval['filename'] = substr($buf,0,$cpos);
$cpos++; // skip comma
$cposa = strpos($buf,',',$cpos); // find next comma
if ($cposa === FALSE)
{
return FALSE;
}
$retval['time'] = substr($buf,$cpos,$cposa-$cpos);
$cpos = $cposa+1;
//echo "remain: ".substr($buf,$cpos)."<br/>";
$cposa = strpos($buf,',',$cpos);
if ($cposa === FALSE)
{
return FALSE;
}
$retval['action'] = substr($buf,$cpos,$cposa-$cpos);
//echo "action: $retval[action]<br/>";
$cposa++; // skip comma
$retval['referrer'] = substr($buf,$cposa);//,strlen($buf)-$cposa);
return $retval;
}
// function copied from hotlinklog.php
function EntryTooOld($time)
{
$now = time();
if(($now-$time)>ONEDAY)
{
return TRUE;
}
return FALSE;
}
function ExtractDomain($guff)
{
$url = str_replace("http://","",$guff);
$urlComponents = explode("/",$url);
return $urlComponents[0];
}
// returns string formatted as KB, MB etc.
define('KILOBYTE',1024);
define('MEGABYTE',1048576);
function ByteFormat($bytes)
{
if ($bytes<1024)
{
return number_format($bytes);
}
if ($bytes<MEGABYTE)
{
return number_format($bytes/KILOBYTE).'KB';
}
return number_format($bytes/MEGABYTE).'MB';
}
?>