";
#TOTAL
$qry_total = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
");
print "
" . $qry_total->visitors . "
\n";
#LAST MONTH
$qry_lmonth = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $lastmonth . "%'
");
print "
" . $qry_lmonth->visitors . "
\n";
#THIS MONTH
$qry_tmonth = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $thismonth . "%'
");
if($qry_lmonth->visitors <> 0) {
$pc = round( 100 * ($qry_tmonth->visitors / $qry_lmonth->visitors ) - 100,1);
if($pc >= 0) $pc = "+" . $pc;
$qry_tmonth->change = " (" . $pc . "%)";
}
print "
\n";
#YESTERDAY
$qry_y = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$yesterday'
");
print "
" . $qry_y->visitors . "
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$today'
");
print "
";
#TOTAL
$qry_total = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
");
print "
" . $qry_total->pageview . "
\n";
#LAST MONTH
$prec=0;
$qry_lmonth = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $lastmonth . "%'
");
print "
".$qry_lmonth->pageview."
\n";
#THIS MONTH
$qry_tmonth = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $thismonth . "%'
");
if($qry_lmonth->pageview <> 0) {
$pc = round( 100 * ($qry_tmonth->pageview / $qry_lmonth->pageview ) - 100,1);
if($pc >= 0) $pc = "+" . $pc;
$qry_tmonth->change = " (" . $pc . "%)";
}
print "
\n";
#YESTERDAY
$qry_y = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$yesterday'
");
print "
" . $qry_y->pageview . "
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$today'
");
print "
";
#TOTAL
$qry_total = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider<>''
");
print "
" . $qry_total->spiders . "
\n";
#LAST MONTH
$prec=0;
$qry_lmonth = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider<>''
AND date LIKE '" . $lastmonth . "%'
");
print "
" . $qry_lmonth->spiders. "
\n";
#THIS MONTH
$prec=$qry_lmonth->spiders;
$qry_tmonth = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider<>''
AND date LIKE '" . $thismonth . "%'
");
if($qry_lmonth->spiders <> 0) {
$pc = round( 100 * ($qry_tmonth->spiders / $qry_lmonth->spiders ) - 100,1);
if($pc >= 0) $pc = "+" . $pc;
$qry_tmonth->change = " (" . $pc . "%)";
}
print "
\n";
#YESTERDAY
$qry_y = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider<>''
AND date = '$yesterday'
");
print "
" . $qry_y->spiders . "
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider<>''
AND date = '$today'
");
print "
";
#TOTAL
$qry_total = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed<>''
AND spider=''
");
print "
".$qry_total->feeds."
\n";
#LAST MONTH
$qry_lmonth = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed<>''
AND spider=''
AND date LIKE '" . $lastmonth . "%'
");
print "
".$qry_lmonth->feeds."
\n";
#THIS MONTH
$qry_tmonth = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed<>''
AND spider=''
AND date LIKE '" . $thismonth . "%'
");
if($qry_lmonth->feeds <> 0) {
$pc = round( 100 * ($qry_tmonth->feeds / $qry_lmonth->feeds ) - 100,1);
if($pc >= 0) $pc = "+" . $pc;
$qry_tmonth->change = " (" . $pc . "%)";
}
print "
\n";
$qry_y = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed<>''
AND spider=''
AND date = '".$yesterday."'
");
print "
".$qry_y->feeds."
\n";
$qry_t = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed<>''
AND spider=''
AND date = '$today'
");
print "
".$qry_t->feeds."
\n";
print "
\n\n";
################################################################################################
################################################################################################
# THE GRAPHS
# last "N" days graph NEW
$gdays=get_option('statpress_daysinoverviewgraph'); if($gdays == 0) { $gdays=20; }
// $start_of_week = get_settings('start_of_week');
$start_of_week = get_option('start_of_week');
print '
';
$qry = $wpdb->get_row("
SELECT count(date) as pageview, date
FROM $table_name
GROUP BY date HAVING date >= '".gmdate('Ymd', current_time('timestamp')-86400*$gdays)."'
ORDER BY pageview DESC
LIMIT 1
");
$maxxday=$qry->pageview;
if($maxxday == 0) { $maxxday = 1; }
# Y
$gd=(90/$gdays).'%';
for($gg=$gdays-1;$gg>=0;$gg--)
{
#TOTAL VISITORS
$qry_visitors = $wpdb->get_row("
SELECT count(DISTINCT ip) AS total
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
");
$px_visitors = round($qry_visitors->total*100/$maxxday);
#TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
$qry_pageviews = $wpdb->get_row("
SELECT count(date) as total
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
");
$px_pageviews = round($qry_pageviews->total*100/$maxxday);
#TOTAL SPIDERS
$qry_spiders = $wpdb->get_row("
SELECT count(ip) AS total
FROM $table_name
WHERE feed=''
AND spider<>''
AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
");
$px_spiders = round($qry_spiders->total*100/$maxxday);
#TOTAL FEEDS
$qry_feeds = $wpdb->get_row("
SELECT count(ip) AS total
FROM $table_name
WHERE feed<>''
AND spider=''
AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
");
$px_feeds = round($qry_feeds->total*100/$maxxday);
$px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
print '
';
# END OF OVERVIEW
####################################################################################################
$querylimit="LIMIT 10";
# Tabella Last hits
print "
". __('Last hits','statpress'). "
". __('Date','statpress'). "
". __('Time','statpress'). "
IP
". __('Domain','statpress'). "
". __('Page','statpress'). "
OS
Browser
Feed
";
print "";
$fivesdrafts = $wpdb->get_results("SELECT * FROM $table_name WHERE (os<>'' OR feed<>'') order by id DESC $querylimit");
foreach ($fivesdrafts as $fivesdraft) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM $table_name WHERE search<>'' ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested FROM $table_name WHERE ((referrer NOT LIKE '".get_option('home')."%') AND (referrer <>'') AND (searchengine='')) ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM $table_name WHERE (agent <>'') ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
".irihdate($rk->date)."
".$rk->time."
".$rk->agent."
".$rk->os. " ".$rk->browser." ".$rk->spider."
\n";
}
print "
";
# Last pages
print "
".__('Last pages','statpress')."
".__('Date','statpress')."
".__('Time','statpress')."
".__('Page','statpress')."
".__('What','statpress')."
";
print "";
$qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM $table_name WHERE (spider='' AND feed='') ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM $table_name WHERE (spider<>'') ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
".irihdate($rk->date)."
".$rk->time."
".$rk->spider."
".$rk->agent."
\n";
}
print "
";
print " ";
print " StatPress table size: ".iritablesize($wpdb->prefix . "statpress")." ";
print " StatPress current time: ".current_time('mysql')." ";
print " RSS2 url: ".get_bloginfo('rss2_url').' ('.iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')).") ";
}
function iri_StatPress_extractfeedreq($url) {
list($null,$q)=explode("?",$url);
list($res,$null)=explode("&",$q);
return $res;
}
function iriStatPressDetails() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$querylimit="LIMIT 10";
# Top days
iriValueTable("date","Top days",5);
# O.S.
iriValueTable("os","O.S.",0,"","","AND feed='' AND spider='' AND os<>''");
# Browser
iriValueTable("browser","Browser",0,"","","AND feed='' AND spider='' AND browser<>''");
# Feeds
iriValueTable("feed","Feeds",5,"","","AND feed<>''");
# SE
iriValueTable("searchengine","Search engines",10,"","","AND searchengine<>''");
# Search terms
iriValueTable("search","Top search terms",20,"","","AND search<>''");
# Top referrer
iriValueTable("referrer","Top referrer",10,"","","AND referrer<>'' AND referrer NOT LIKE '%".get_bloginfo('url')."%'");
# Countries
iriValueTable("nation","Countries (domains)",10,"","","AND nation<>'' AND spider=''");
# Spider
iriValueTable("spider","Spiders",10,"","","AND spider<>''");
# Top Pages
iriValueTable("urlrequested","Top pages",5,"","urlrequested","AND feed='' and spider=''");
# Top Days - Unique visitors
iriValueTable("date","Top Days - Unique visitors",5,"distinct","ip","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
# Top Days - Pageviews
iriValueTable("date","Top Days - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
# Top IPs - Pageviews
iriValueTable("ip","Top IPs - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
}
function iriStatPressSpy() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
# Spy
$today = gmdate('Ymd', current_time('timestamp'));
$yesterday = gmdate('Ymd', current_time('timestamp')-86400);
print "
".__('Spy','statpress')."
";
$sql="SELECT ip,nation,os,browser,agent FROM $table_name WHERE (spider='' AND feed='') AND (date BETWEEN '$yesterday' AND '$today') GROUP BY ip ORDER BY id DESC LIMIT 20";
$qry = $wpdb->get_results($sql);
?>
";
$qry2=$wpdb->get_results("SELECT * FROM $table_name WHERE ip='".$rk->ip."' AND (date BETWEEN '$yesterday' AND '$today') order by id LIMIT 10");
foreach ($qry2 as $details) {
print "
";
}
function StatPress_Widget($w='') {
}
function StatPress_Print($body='') {
print iri_StatPress_Vars($body);
}
function iri_StatPress_Vars($body) {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
if(strpos(strtolower($body),"%visits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE date = '".gmdate("Ymd",current_time('timestamp'))."' and spider='' and feed='';");
$body = str_replace("%visits%", $qry[0]->pageview, $body);
}
if(strpos(strtolower($body),"%totalvisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='';");
$body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
}
if(strpos(strtolower($body),"%thistotalvisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='".iri_StatPress_URL()."';");
$body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
}
if(strpos(strtolower($body),"%since%") !== FALSE) {
$qry = $wpdb->get_results("SELECT date FROM $table_name ORDER BY date LIMIT 1;");
$body = str_replace("%since%", irihdate($qry[0]->date), $body);
}
if(strpos(strtolower($body),"%os%") !== FALSE) {
$userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
$os=iriGetOS($userAgent);
$body = str_replace("%os%", $os, $body);
}
if(strpos(strtolower($body),"%browser%") !== FALSE) {
$browser=iriGetBrowser($userAgent);
$body = str_replace("%browser%", $browser, $body);
}
if(strpos(strtolower($body),"%ip%") !== FALSE) {
$ipAddress = $_SERVER['REMOTE_ADDR'];
$body = str_replace("%ip%", $ipAddress, $body);
}
if(strpos(strtolower($body),"%visitorsonline%") !== FALSE) {
$to_time = current_time('timestamp');
$from_time = strtotime('-4 minutes', $to_time);
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as visitors FROM $table_name WHERE spider='' and feed='' AND timestamp BETWEEN $from_time AND $to_time;");
$body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
}
if(strpos(strtolower($body),"%usersonline%") !== FALSE) {
$to_time = current_time('timestamp');
$from_time = strtotime('-4 minutes', $to_time);
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as users FROM $table_name WHERE spider='' and feed='' AND user<>'' AND timestamp BETWEEN $from_time AND $to_time;");
$body = str_replace("%usersonline%", $qry[0]->users, $body);
}
if(strpos(strtolower($body),"%toppost%") !== FALSE) {
$qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body);
}
if(strpos(strtolower($body),"%topbrowser%") !== FALSE) {
$qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' GROUP BY browser ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body);
}
if(strpos(strtolower($body),"%topos%") !== FALSE) {
$qry = $wpdb->get_results("SELECT os,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' GROUP BY os ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body);
}
return $body;
}
function iri_StatPress_TopPosts($limit=5, $showcounts='checked') {
global $wpdb;
$res="\n
\n";
$table_name = $wpdb->prefix . "statpress";
$qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT $limit;");
foreach ($qry as $rk) {
$res.="