antal;
}
return $amount;
}
# Return how many unique entries there are in the DB.
function counterize_getuniqueamount(&$ips)
{
static $unique_amount = -1;
if ($unique_amount == -1) $unique_amount = count($ips);
return $unique_amount;
}
# Returns amount of entries in the DB matching the specified IP-address.
function counterize_getfromspecificip(&$ips, $specip)
{
foreach ($ips as $ip) if ($ip->IP === $specip) return $ip->antal;
return 0;
}
# Returns amount of entries in the DB matching the visiting IP-address.
function counterize_getfromcurrentip(&$ips)
{
return counterize_getfromspecificip($ips, $_SERVER['REMOTE_ADDR']);
}
# Returns amount of hits today.
function counterize_gethitstoday()
{
$today = date('Y-m-d');
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp >= '$today'";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
# Returns amount of hits during the last 7 days.
function counterize_getlatest7days()
{
$sevendaysago = date('Y-m-d', strtotime('-1 week'));
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp >= '$sevendaysago'";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
# Returns amount of unique referer-URl's
function counterize_getuniquereferers()
{
$sql = 'SELECT DISTINCT referer FROM %sCounterize';
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return count($wpdb->get_results($sql));
}
# Returns amount of unique browser-strings in DB.
function counterize_getuniquebrowsers()
{
$sql = 'SELECT DISTINCT useragent FROM %sCounterize';
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return count($wpdb->get_results($sql));
}
# Returns amount of unique URl's
function counterize_getuniqueurl()
{
$sql = 'SELECT DISTINCT url FROM %sCounterize WHERE referer != "unknown"';
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return count($wpdb->get_results($sql));
}
function counterize_return_first_hit($dateformat = 'j/n-Y')
{
$sql = "SELECT timestamp from %sCounterize ORDER BY id ASC LIMIT 1";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
$t = $wpdb->get_var($sql);
return date($dateformat, strtotime($t));
}
function counterize_most_visited_pages($number = 10)
{
$sql = "SELECT COUNT(url) AS antal, url FROM %sCounterize GROUP BY url ORDER BY antal DESC LIMIT $number";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
$tmp = $wpdb->get_results($sql);
$count=count($tmp);
$counter=0;
$total_amount=counterize_getamount($ips);
if ($total_amount > 300)
$multiply=15;
else
$multiply=4;
?>
| Page |
Amount |
Graph / % of total pages |
>
|
url . '">' . $tmp[$counter]->url . ''; ?>
|
antal; ?>
|
antal/$total_amount*100); ?>
%
|
get_results($sql);
}
function counterize_most_visited_ips(&$ips, $number = 10)
{
$tmp = array_slice($ips, 0, $number);
$count=count($tmp);
$counter=0;
$total_amount=counterize_getamount($ips);
if ($total_amount > 300)
$multiply=15;
else
$multiply=4;
?>
| Page |
Amount |
Graph / % of total pages |
>
IP . ' '; ?>
|
antal; ?>
|
antal/$total_amount*100); ?>
%
|
get_results($sql);
$count=count($tmp);
$counter=0;
$total_amount=counterize_getamount($ips);
if ($total_amount > 300)
$multiply=12;
else
$multiply=4;
?>
| Page |
Amount |
Graph / % of total pages |
>
|
useragent; ?>
|
antal; ?>
|
antal/$total_amount*100); ?>
%
|
get_var($sqlfire);
if ($type == 'number')
return $container[$i];
else if ($type == 'percent')
return sprintf("%01.0f", $container[$i]/$amount*100);
else if ($type == 'both')
return $container[$i] . ' ' . sprintf("%01.0f", $container[$i]/$amount*100);
else
echo 'Second parameter to the function counterize_getdailystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
else if ($day == 'undef')
{
echo "You've gotta specify a date to the function counterize_getdailystats()";
return 'failure';
}
else if ( ! is_integer($day))
{
echo "You've gotta specify a correct date(read: integer!) to the function counterize_getdailystats()";
return 'failure';
}
else if ($day < 0 || $day > 32)
{
echo 'Come on - days only go from 1 to 31... You know that :)';
return 'failure';
}
if (! isset($container))
{
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
if ($day < 10)
$sqlfire = $sql . " LIKE '%-0$day %'";
else
$sqlfire = $sql . " LIKE '%-$day %'";
# echo "Day " . $day . " -> " . $wpdb->get_var($sqlfire) . "
";
$res = $wpdb->get_var($sqlfire);
if ($type == 'number')
return $res;
else if ($type == 'percent')
return sprintf("%01.0f", $res/$amount*100);
else if ($type == 'both')
return $res . ' ' . sprintf("%01.0f", $res/$amount*100);
else
echo 'Second parameter to the function counterize_getdailystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
# This is function is still not done - needs more work...
function counterize_getmonthlystats($month = 'undef', $type = both)
{
$wpdb =& $GLOBALS['wpdb'];
$amount=counterize_getamount($ips);
if ($month == 'all')
{
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
for ($i=1; $i<13; $i++)
{
if ($i < 10)
$sqlfire = $sql . " LIKE '%-0$i-%'";
else
$sqlfire = $sql . " LIKE '%-$i-%'";
$container[$i] = $wpdb->get_var($sqlfire);
if ($type == 'number')
return $container[$i];
else if ($type == 'percent')
return sprintf("%01.0f", $container[$i]/$amount*100);
else if ($type == 'both')
return $container[$i] . ' ' . sprintf("%01.0f", $container[$i]/$amount*100);
else
echo 'Second parameter to the function counterize_getdailystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
else if ($month == 'undef')
{
echo "You've gotta specify a month to the function counterize_getmonthlystats()";
return 'failure';
}
else if ( ! is_integer($month))
{
echo "You've gotta specify a correct month(read: integer!) to the function counterize_getmonthlystats()";
return 'failure';
}
else if ($month < 0 || $month > 13)
{
echo 'Come on - months only go from 1 to 12... You know that :)';
return 'failure';
}
if (! isset($container))
{
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
if ($month < 10)
$sqlfire = $sql . " LIKE '%-0$month-%'";
else
$sqlfire = $sql . " LIKE '%-$month-%'";
$res = $wpdb->get_var($sqlfire);
if ($type == 'number')
return $res;
else if ($type == 'percent')
return sprintf("%01.0f", $res/$amount*100);
else if ($type == 'both')
return $res . ' ' . sprintf("%01.0f", $res/$amount*100);
else
echo 'Second parameter to the function counterize_getdailystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
# This is function is still not done - needs more work...
function counterize_gethourlystats($hour = 'undef', $type = both)
{
$wpdb =& $GLOBALS['wpdb'];
$amount=counterize_getamount($ips);
if ($hour == 'all')
{
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
for ($i=0; $i<24; $i++)
{
if ($i < 10)
$sqlfire = $sql . " LIKE '% 0$i:%'";
else
$sqlfire = $sql . " LIKE '% $i:%'";
$container[$i] = $wpdb->get_var($sqlfire);
if ($type == 'number')
return $container[$i];
else if ($type == 'percent')
return sprintf("%01.0f", $container[$i]/$amount*100);
else if ($type == 'both')
return $container[$i] . ' ' . sprintf("%01.0f", $container[$i]/$amount*100);
else
echo 'Second parameter to the function counterize_gethourlystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
else if ($hour == 'undef')
{
echo "You've gotta specify an hour to the function counterize_gethourlystats()";
return 'failure';
}
else if ( ! is_integer($hour))
{
echo "You've gotta specify a correct hour(read: integer!) to the function counterize_gethourlystats()";
return 'failure';
}
else if ($hour < 0 || $hour > 24)
{
echo 'Come on - hours only go from 1 to 24... You know that :)';
return 'failure';
}
if (! isset($container))
{
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
if ($hour < 10)
$sqlfire = $sql . " LIKE '% 0$hour:%'";
else
$sqlfire = $sql . " LIKE '% $hour:%'";
$res = $wpdb->get_var($sqlfire);
if ($type == 'number')
return $res;
else if ($type == 'percent')
return sprintf("%01.0f", $res/$amount*100);
else if ($type == 'both')
return $res . ' ' . sprintf("%01.0f", $res/$amount*100);
else
echo 'Second parameter to the function counterize_gethourlystats NOT correct. Has to be "number", "percent" or "both"
';
}
}
# Returns amount of unique hits today
function counterize_getuniquehitstoday()
{
$today = date('Y-m-d');
$sql = "SELECT DISTINCT ip FROM %sCounterize WHERE timestamp >= '$today'";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return count($wpdb->get_results($sql));
}
# Returns amount of hits today, from the visiting IP
function counterize_gethitstodayfromcurrentip()
{
$today = date('Y-m-d');
$sql = "SELECT COUNT(*) FROM %sCounterize WHERE timestamp >= '$today' AND IP = '" . $_SERVER['REMOTE_ADDR'] . "'";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_var($sql);
}
# Fetches entries in DB
function counterize_getentries()
{
$amount = get_option('counterize_amount');
$sql = 'SELECT id FROM %sCounterize ORDER BY timestamp DESC';
if ($amount == '')
$sql .= ' LIMIT 50';
else if ($amount != 0)
$sql .= " LIMIT $amount";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$wpdb =& $GLOBALS['wpdb'];
return $wpdb->get_col($sql);
}
# Fetch information matching ID in DB.
function counterize_getinformation($number = 0)
{
if ($number == 0)
{
echo 'doh! Incorrect use of function counterize_getinformation()...';
return 0;
}
else
{
$wpdb =& $GLOBALS['wpdb'];
$sql = "SELECT * FROM %sCounterize";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$sql .= " WHERE id=$number";
return $wpdb->get_row($sql,ARRAY_A);
}
}
# Append information to DB
function counterize_add()
{
# Set to unknown, if we're unable to extract information below.
$referer = $remoteaddr = $useragent = $requesturl = 'unknown';
if ($_SERVER['REMOTE_ADDR'])
$remoteaddr = $_SERVER['REMOTE_ADDR'];
if ($_SERVER['HTTP_USER_AGENT'])
$useragent = $_SERVER['HTTP_USER_AGENT'];
if ($_SERVER['PHP_SELF']) {
$requesturl = $_SERVER['PHP_SELF'] . $_SERVER['PATH_INFO'];
if ($_SERVER['QUERY_STRING'])
$requesturl .= '?' . $_SERVER['QUERY_STRING'];
}
if ($_SERVER['HTTP_REFERER'])
$referer = $_SERVER['HTTP_REFERER'];
# Check to see if we really want to insert the entry...
$checkval=0;
if (current_user_can('edit_posts'))
$checkval=1;
# Bot-checking....
elseif (stristr($useragent, 'bot'))
$checkval=1;
elseif (stristr($useragent, 'Yahoo'))
$checkval=1;
elseif (stristr($useragent, 'google'))
$checkval=1;
elseif (stristr($useragent, 'slurpy'))
$checkval=1;
elseif (stristr($useragent, 'agent 007'))
$checkval=1;
elseif (stristr($useragent, 'ichiro'))
$checkval=1;
elseif (stristr($useragent, 'ia_archiver'))
$checkval=1;
elseif (stristr($useragent, 'zyborg'))
$checkval=1;
elseif (stristr($useragent, 'linkwalker'))
$checkval=1;
elseif (stristr($useragent, 'crawler'))
$checkval=1;
elseif (stristr($useragent, 'python'))
$checkval=1;
elseif (stristr($useragent, 'w3c_validator'))
$checkval=1;
elseif (stristr($useragent, 'almaden'))
$checkval=1;
elseif (stristr($useragent, 'topicspy'))
$checkval=1;
elseif (stristr($useragent, 'poodle predictor'))
$checkval=1;
elseif (stristr($useragent, 'link checker pro'))
$checkval=1;
elseif (stristr($useragent, 'xenu link sleuth'))
$checkval=1;
elseif (stristr($useragent, 'iconsurf'))
$checkval=1;
elseif (stristr($useragent, 'zoe indexer'))
$checkval=1;
elseif (stristr($useragent, 'grub-client'))
$checkval=1;
elseif (stristr($useragent, 'baidu'))
$checkval=1;
elseif (stristr($useragent, 'sohu'))
$checkval=1;
elseif (stristr($useragent, 'blog'))
$checkval=1;
elseif (stristr($useragent, 'Jakarta'))
$checkval=1;
elseif (stristr($useragent, 'Sphere'))
$checkval=1;
elseif (stristr($useragent, 'psycheclone'))
$checkval=1;
elseif (stristr($useragent, 'larbin'))
$checkval=1;
elseif (stristr($useragent, 'wordpress'))
$checkval=1;
elseif (stristr($useragent, 'spider'))
$checkval=1;
elseif (stristr($useragent, 'explode'))
$checkval=1;
# ... aaaaand, exclude all "unknown" agents
elseif (stristr($useragent, 'unknown'))
$checkval=1;
# TODO: More bot-rules?
# ...afterwards check to see if it's on the excludelist...
if ($checkval == 0)
{
$tmp=get_option('counterize_excluded');
$excludelist = preg_replace('/\s\s+/', ' ', $tmp);
$tmp_array = explode(' ', $excludelist);
$count=count($tmp_array);
if ($excludelist != '' && $excludelist != ' ')
{
for ($i=0; $i<$count; $i++)
{
if (strpos($remoteaddr, $tmp_array[$i]) === FALSE)
{
# Coming up...
}
else
{
# IP found on exclude-list - we don't want it!
$checkval=1;
}
}
}
}
# If checkval is still 0, then yes - we want to insert it...
if ($checkval == 0)
{
# Replace %20's(spaces) in strings with a white-space
# Man, someone should create a better checking-module... *sigh*
$requesturl = str_replace("%20", ' ', $requesturl);
$referer = str_replace("%20", ' ', $referer);
# Readyyyy, aaaiimmmmm
$wpdb =& $GLOBALS['wpdb'];
$sql = "INSERT INTO %sCounterize (IP, timestamp, url, referer, useragent) VALUES (";
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$sql .= "'" . $remoteaddr . "',";
$sql .= "now(), '";
$sql .= $requesturl . "', '";
$sql .= $referer . "', '";
$sql .= $useragent . "')";
# ...FIRE!
$results = $wpdb->query($sql);
}
# Nope, we don't want the text. The IP is in the excluded hosts.
else
{
return 42;
}
}
function display_daily_statistics()
{
if (counterize_getamount($ips) > 0)
{?>
';
echo $temp2;
?>
$temp %";
}
?>
$i";
}
?>
0)
{?>
' . $temp2;
?>
$temp %";
}
?>
| Jan |
Feb |
Mar |
Apr |
May |
Jun |
Jul |
Aug |
Sep |
Oct |
Nov |
Dec |
0)
{?>
';
echo $temp2;
?>
$temp %";
}
?>
' . $i . '-' . ++$i . '';
$i--;
}
?>
' . _('Counterize Status') . " » ";
$content .= _('Total: ') . '' . $count . ' ' . _('hits and ') . '' . $unique . '' . _(' unique.');
$content .= _('Today: ') . '' . $todaycount . ' ' . _('hits and ') . '' . $todayunique . '' . _(' unique.
');
print ' ';
}
}
# Used for first-time initialization - create table if not present...
function Counterize_Install()
{
update_option('counterize_logbots', 'disabled');
$pre = $GLOBALS['table_prefix'];
$wpdb =& $GLOBALS['wpdb'];
$sql = 'SHOW TABLES LIKE \'%sCounterize\'';
$sql = sprintf($sql, $pre);
$results = $wpdb->query($sql);
# Nope, it's not there - let's create it, shall we?
if ($results == 0)
{
$sql = "
create table %sCounterize
(
id integer not null auto_increment,
IP varchar(16) not null default 'unknown',
timestamp datetime not null default 'now()',
url varchar(255) not null default 'unknown',
referer varchar(255) not null default 'unknown',
useragent text,
primary key(id)
)
";
$sql = sprintf($sql, $pre);
$results = $wpdb->query($sql);
}
}
# Do the installation stuff, if the plugin is marked to be activated...
$install = (basename($_SERVER['SCRIPT_NAME']) == 'plugins.php' && isset($_GET['activate']));;
if ($install)
{
Counterize_Install();
}
function counterize_manage_page()
{
?>
Number-settings updated...');
}
else
echo 'What the f*ck?!? ' . $_POST['amount'] . ' is not a valid number...';
?>
Say goodbye - killing entry .
query($sql);
?>
Bot logging disabled!');
}
else
{
update_option('counterize_logbots', 'enabled');
_e('Bot logging enabled!');
}
?>
query($sql);
echo "Database FLUSHED! - it's all gone ($num records deleted!)... ";
}
else
echo 'Hey, you have to click the checkbox to confirm flushing the database... - database not flushed!';
?>
comments WHERE comment_approved = \"spam\"";
$spam_IPs = $wpdb->get_col($sql);
if (!$spam_IPs)
{
$num = 0;
} else
{
$sql = 'DELETE FROM %sCounterize WHERE IP IN ("' . implode('", "', $wpdb->get_col($sql)) . '")';
$sql = sprintf($sql, $GLOBALS['table_prefix']);
$num = $wpdb->query($sql);
}
echo "Spammer IPs REMOVED! - it's all gone ($num records deleted!)... ";
?>
Excludelist-Settings updated...');
}
else
echo 'What the f*ck?!? ' . $_POST['excludelist'] . ' is not a valid string...';
?>
|
Total hits:
|
Hits from unique IPs:
|
Total hits, today:
|
Hits from unique IPs, today:
|
Hits, the last 7 days:
|
0)
{?>
| ID |
IP |
Timestamp |
URl |
Referer |
UserAgent |
Kill |
$i; $i++)
{
#Get the row we're currently at
$temp = counterize_getinformation($entries[$i]);
?>
>
| |
'; ?> |
(' . counterize_getfromspecificip($ips, $temp['IP']) . ')'; ?> |
' . wordwrap($temp['url'], 30, "\n", 1); ?> |
' . wordwrap($temp['referer'], 30, "\n", 1) . '';
else
echo wordwrap($temp['referer'], 30, "\n", 1);
?>
|
|
'
?>
X
|
If you\'re in doubt on how to configure it, look at the Counterize homepage at http://andersdrengen.dk/projects.');
?>