\n";
//YESTERDAY
$qry_y = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors FROM $table_name WHERE feed='' AND spider='' AND date = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($today) . "' ");
print "
\n";
//YESTERDAY
$qry_y = $wpdb->get_row("SELECT count(date) as pageview FROM $table_name WHERE feed='' AND spider='' AND date = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($today) . "' ");
print "
\n";
//YESTERDAY
$qry_y = $wpdb->get_row("SELECT count(date) as spiders FROM $table_name WHERE feed='' AND spider<>'' AND date = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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";
//THIS MONTH
$qry_tmonth = $wpdb->get_row("SELECT count(date) as feeds FROM $table_name WHERE feed<>'' AND spider='' AND date LIKE '" . mysql_real_escape_string($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 "
" . $qry_tmonth->feeds . $qry_tmonth->change . "
\n";
$qry_y = $wpdb->get_row("SELECT count(date) as feeds FROM $table_name WHERE feed<>'' AND spider='' AND date = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($today) . "'");
print "
" . $qry_t->feeds . "
\n";
print "
\n\n";
echo "
";
print "
";
// GRAPH
// last "N" days graph NEW
$gdays = 7;
// $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 '
";
//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 '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($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 = '" . mysql_real_escape_string($today) . "'
");
print "
" . $qry_t->feeds . "
\n";
print "
\n\n";
//###############################################################################################
//###############################################################################################
// THE GRAPHS
echo "
Day by day
";
// last "N" days graph NEW
$gdays = get_option('StatSurfer_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 '
";
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,urlrequested,os,browser,spider FROM $table_name WHERE (spider='' AND feed='') ORDER BY id DESC $querylimit");
foreach ($qry as $rk)
{
print "
";
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,agent,os,browser,spider FROM $table_name WHERE (agent <>'') ORDER BY id DESC $querylimit");
foreach ($qry as $rk)
{
print "
";
$qry = $wpdb->get_results("SELECT date,time,agent,spider,urlrequested,agent FROM $table_name WHERE (spider<>'') ORDER BY id DESC $querylimit");
foreach ($qry as $rk)
{
print "
";
echo " ";
// Top referrer
iriValueTable("referrer", __('Top referrer', 'StatSurfer'), 10, "", "", "AND referrer<>'' AND referrer NOT LIKE '%" . get_bloginfo('url') . "%'");
echo " ";
// Top Pages
iriValueTable("urlrequested", __('Top pages', 'StatSurfer'), 10, "", "urlrequested", "AND feed='' and spider=''");
echo " ";
echo "
";
echo "
''");
echo "
";
// Countries
iriValueTable_pers_1("nation", __('Countries (domains)', 'StatSurfer'), 25, "", "", "AND nation<>'' AND spider=''");
echo "
";
echo "
";
echo "
";
/* Maddler 04112007: required patching iriValueTable */
}
function StatSurferSpy()
{
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . $_STATSURFER['table_name'];
$LIMIT = 20;
if(isset($_GET['pn']))
{
// Get Current page from URL
$page = $_GET['pn'];
if($page <= 0)
{
// Page is less than 0 then set it to 1
$page = 1;
}
}
else
{
// URL does not show the page set it to 1
$page = 1;
}
// Create MySQL Query String
$strqry = "SELECT id FROM $table_name WHERE (spider='' AND feed='') GROUP BY ip";
$query = $wpdb->get_results($strqry);
$TOTALROWS = $wpdb->num_rows;
$NumOfPages = $TOTALROWS / $LIMIT;
$LimitValue = ($page * $LIMIT) - $LIMIT;
// Spy
$today = gmdate('Ymd', current_time('timestamp'));
$yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
print "
" . __('Spy', 'StatSurfer') . "
";
$sql = "SELECT ip,nation,os,browser,agent FROM $table_name WHERE (spider='' AND feed='') GROUP BY ip ORDER BY id DESC LIMIT $LimitValue, $LIMIT";
$qry = $wpdb->get_results($sql);
?>
Pages:
0) {
// if $i greater than 0 display it as a hyperlink
echo '' . $i . ' ';
}
}
}
if($page == ceil($NumOfPages) ) {
$startPage = $page;
} else {
$startPage = 1;
}
for ($i = $startPage; $i <= $page+19; $i++) {
// Display first 7 pages
if ($i <= ceil($NumOfPages)) {
// $page is not the last page
if($i == $page) {
// $page is current page
echo " [{$i}] ";
} else {
// Not the current page Hyperlink them
echo '' . $i . ' ';
}
}
}
?>
";
$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 StatSurferCheckGoals(){
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . "StatSurfer_goals";
$table_StatSurfer = $wpdb->prefix . $_STATSURFER['table_name'];
//type 1 control
$qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE result_g='Y' AND start_date_g!='0000-00-00' ");
foreach ($qry as $rk){
if($rk->end_date_gconn_type_g;
list($year, $month, $day) = split("-", $rk->start_date_g);
$startDate = date('Ymd', mktime(0, 0, 0, $month, $day, $year));
list($year, $month, $day) = split("-", $rk->end_date_g);
$endDate = date('Ymd', mktime(0, 0, 0, $month, $day, $year));
if($conn_type[0]=="I"){
$qry_visitors = $wpdb->get_row("
SELECT count(DISTINCT ip) AS total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider=''
AND date > '" . $startDate . "'
AND date < '" . $endDate . "'
");
$total_result = $total_result + $qry_visitors->total;
}
if($conn_type[1]=="I"){
$qry_pageviews = $wpdb->get_row("
SELECT count(date) as total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider=''
AND date > '" . $startDate . "'
AND date < '" . $endDate . "'
");
$total_result = $total_result + $qry_pageviews->total;
}
if($conn_type[2]=="I"){
$qry_spiders = $wpdb->get_row("
SELECT count(ip) AS total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider<>''
AND date > '" . $startDate . "'
AND date < '" . $endDate . "'
");
$total_result = $total_result + $qry_spiders->total;
}
if($conn_type[3]=="I"){
$qry_feeds = $wpdb->get_row("
SELECT count(ip) AS total
FROM ".$table_StatSurfer."
WHERE feed<>''
AND spider=''
AND date > '" . $startDate . "'
AND date < '" . $endDate . "'
");
$total_result = $total_result + $qry_feeds->total;
}
if($control==1){
if($rk->goal_g<=$total_result)
$result = "G";
else
$result = "R";
}
else
$result = "Y";
$qry = "UPDATE ".$table_name." SET result_g = '".$result."', partial_g='".$total_result."' WHERE id_g='".$rk->id_g."'";
$wpdb->query($qry);
}
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . "StatSurfer_goals";
$table_StatSurfer = $wpdb->prefix . $_STATSURFER['table_name'];
//type 2 control
$query = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE result_g='Y' AND start_date_g='0000-00-00' ");
foreach ($query as $rk){
//assegnazione prima data
/*if($rk->end_date_g=="0000-00-00"){
$conn = $wpdb->get_results("SELECT* FROM ".$table_StatSurfer." ORDER BY id ASC ");
$st_Timestamp = $conn->timestamp;
$st_Date = gmdate('Y-m-d', $st_Timestamp);
$st_up = "UPDATE ".$table_name." SET end_date_g = '".$st_Date."' WHERE id_g='".$rk->id_g."'";
$wpdb->query($st_up);
}*/
$exDate = $rk->end_date_g;
list($year, $month, $day) = split("-", $exDate);
$startDate = mktime(0,0,0,$month,$day,$year);
for($i=$startDate;$i<=(current_time('timestamp'));$i=$i+86400){
$startDate = gmdate('Ymd', $i);
$total_result = 0;
$conn_type = $rk->conn_type_g;
if($conn_type[0]=="I"){
$qry_visitors = $wpdb->get_row("
SELECT count(DISTINCT ip) AS total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider=''
AND date = '" . $startDate . "'
");
$total_result = $total_result + $qry_visitors->total;
}
if($conn_type[1]=="I"){
$qry_pageviews = $wpdb->get_row("
SELECT count(date) as total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider=''
AND date = '" . $startDate . "'
");
$total_result = $total_result + $qry_pageviews->total;
}
if($conn_type[2]=="I"){
$qry_spiders = $wpdb->get_row("
SELECT count(ip) AS total
FROM ".$table_StatSurfer."
WHERE feed=''
AND spider<>''
AND date = '" . $startDate . "'
");
$total_result = $total_result + $qry_spiders->total;
}
if($conn_type[3]=="I"){
$qry_feeds = $wpdb->get_row("
SELECT count(ip) AS total
FROM ".$table_StatSurfer."
WHERE feed<>''
AND spider=''
AND date = '" . $startDate . "'
");
$total_result = $total_result + $qry_feeds->total;
}
if($rk->goal_g<=$total_result){
$qry = "UPDATE ".$table_name." SET result_g = 'G' WHERE id_g='".$rk->id_g."'";
$wpdb->query($qry);
}
$qry = "UPDATE ".$table_name." SET end_date_g = '".$startDate."', partial_g='".$total_result."' WHERE id_g='".$rk->id_g."'";
$wpdb->query($qry);
}
}
}
function StatSurferAddGoals(){
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . "StatSurfer_goals";
$control = 1;
$conn_type = "OOOO";
if($_GET['check_visitor']=="I")
$conn_type[0] = "I";
if($_GET['check_page']=="I")
$conn_type[1] = "I";
if($_GET['check_spider']=="I")
$conn_type[2] = "I";
if($_GET['check_feed']=="I")
$conn_type[3] = "I";
$start_date = "00000000";
$end_date = "00000000";
if($_GET['goal_type']=="type_1"){
$start_date = $_GET['st_date_Y'] . $_GET['st_date_m'] . $_GET['st_date_d'];
$end_date = $_GET['ed_date_Y'] . $_GET['ed_date_m'] . $_GET['ed_date_d'];
}
else
$end_date = gmdate('Ymd', current_time('timestamp'));
if($conn_type=='OOOO'){
$control = 0;
$control_msg = "You have to set at least one connection type";
}
if($start_date>$end_date){
$control = 0;
$control_msg = "Attention, the initial date have to be previous by the final one";
}
if($_GET['goal_type']=="type_1"&&$_GET['st_date_Y']=='yyyy'&&$_GET['ed_date_Y']=='yyyy'&&$_GET['st_date_m']=='mm'&&$_GET['ed_date_m']=='mm'&&$_GET['st_date_d']=='dd'&&$_GET['ed_date_d']=='dd'){
$control = 0;
$control_msg = "If you have chosen the goals type 1, you have to set the start and the end dates";
}
if($_GET['name']==''){
$control = 0;
$control_msg = "You have to set a name of the goal";
}
if($_GET['goal']==''){
$control = 0;
$control_msg = "You have to set a value in the GOAL field";
}
if($control==1){
$insert = "INSERT INTO " . $table_name . " (name_g, conn_type_g, goal_g, start_date_g, end_date_g, result_g) ";
$insert .= "VALUES ('".$_GET['name']."','".$conn_type."','".$_GET['goal']."','" . $start_date . "','" . $end_date . "','Y')";
$results = $wpdb->query($insert);
}
print "
';
}
function StatSurfer_extractfeedreq($url)
{
if(!strpos($url, '?') === FALSE)
{
list($null, $q) = explode("?", $url);
list($res, $null) = explode("&", $q);
}
else
{
$prsurl = parse_url($url);
$res = $prsurl['path'] . $$prsurl['query'];
}
return $res;
}
function iriStatAppend()
{
$start_script = getmicrotime( );
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . $_STATSURFER['table_name'];
global $userdata;
global $_STATSURFER;
get_currentuserinfo();
$feed = '';
// Time
$timestamp = current_time('timestamp');
$vdate = gmdate("Ymd", $timestamp);
$vtime = gmdate("H:i:s", $timestamp);
// IP
$ipAddress = $_SERVER['REMOTE_ADDR'];
if (iriCheckBanIP($ipAddress) === true)
{
return '';
}
// Determine Threats if http:bl installed
$threat_score = 0;
$threat_type = 0;
$httpbl_key = get_option("httpbl_key");
if ($httpbl_key !== false)
{
$result = explode( ".", gethostbyname( $httpbl_key . "." .
implode ( ".", array_reverse( explode( ".",
$ipAddress ) ) ) .
".dnsbl.httpbl.org" ) );
// If the response is positive
if ($result[0] == 127)
{
$threat_score = $result[2];
$threat_type = $result[3];
}
}
// URL (requested)
$urlRequested = StatSurfer_URL();
if (eregi(".ico$", $urlRequested))
{
return '';
}
if (eregi("favicon.ico", $urlRequested))
{
return '';
}
if (eregi(".css$", $urlRequested))
{
return '';
}
if (eregi(".js$", $urlRequested))
{
return '';
}
if (stristr($urlRequested, "/wp-content/plugins") != false)
{
return '';
}
if (stristr($urlRequested, "/wp-content/themes") != false)
{
return '';
}
$referrer = (isset($_SERVER['HTTP_REFERER']) ? htmlentities($_SERVER['HTTP_REFERER']) : '');
$userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? htmlentities($_SERVER['HTTP_USER_AGENT']) : '');
$spider = iriGetSpider($userAgent);
if (($spider != '') and (get_option('StatSurfer_donotcollectspider') == 'checked'))
{
return '';
}
if ($spider != '')
{
$os = '';
$browser = '';
}
else
{
// Trap feeds
$prsurl = parse_url(get_bloginfo('url'));
$feed = StatSurfer_is_feed($prsurl['scheme'] . '://' . $prsurl['host'] . $_SERVER['REQUEST_URI']);
// Get OS and browser
$os = iriGetOS($userAgent);
$browser = iriGetBrowser($userAgent);
list($searchengine, $search_phrase) = explode("|", iriGetSE($referrer));
}
// Auto-delete visits if...
if (get_option('StatSurfer_autodelete_spider') != '')
{
$t = gmdate("Ymd", strtotime('-' . get_option('StatSurfer_autodelete_spider')));
$results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "' AND spider <> ''");
}
if (get_option('StatSurfer_autodelete') != '')
{
$t = gmdate("Ymd", strtotime('-' . get_option('StatSurfer_autodelete')));
$results = $wpdb->query("DELETE FROM " . $table_name . " WHERE date < '" . $t . "'");
}
if ((!is_user_logged_in()) or (get_option('StatSurfer_collectloggeduser') == 'checked'))
{
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
{
StatSurfer_CreateTable();
}
$insert = "INSERT INTO " . $table_name . " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,threat_score,threat_type,timestamp) " . "VALUES ('$vdate','$vtime','$ipAddress','" . mysql_real_escape_string($urlRequested) . "','" . mysql_real_escape_string(strip_tags($userAgent)) . "','" . mysql_real_escape_string($referrer) . "','" . mysql_real_escape_string(strip_tags($search_phrase)) . "','" . iriDomain($ipAddress) . "','" . mysql_real_escape_string($os) . "','" . mysql_real_escape_string($browser) . "','$searchengine','$spider','$feed','$userdata->user_login',$threat_score,$threat_type,'$timestamp')";
$results = $wpdb->query($insert);
}
///WHITE CONNECTION
/*$table_name_country = $wpdb->prefix . "StatSurfer_countries";
$url = "http://api.hostip.info/country.php?ip=" . $ipAddress;
$ciso = file_get_contents($url);
$cry = $wpdb->get_results("SELECT w_conn_c FROM ".$table_name_country." WHERE iso3166_c='".$ciso."'");
foreach ($cry as $ck){
$w_conn_c = $ck->w_conn_c;
$w_conn_c++;
$upy = "UPDATE ".$table_name_country." SET w_conn_c = '".$w_conn_c."' WHERE iso3166_c='".$ciso."'";
$wpdb->query($upy);
}*/
//mail('icattaniweb@gmail.com', 'StatSurfer tests 1', '1. Aggiungo connessione' . $ipAddress . "SELECT ip FROM ".$table_name." WHERE ip='".$ipAddress."'");
$control_empty = 0;
$empty = $wpdb->get_results("SELECT ip FROM ".$table_name." WHERE ip='".$ipAddress."'");
foreach ($empty as $empty){
$control_empty++;
}
if($control_empty< 2){
//mail('icattaniweb@gmail.com', 'StatSurfer tests 2', '2. verificato IP, inizio inserimento' . $ipAddress ." "."SELECT conn_c FROM ".$table_name_country." WHERE iso3166_c='".$ciso."'");
$table_name_country = $wpdb->prefix . "StatSurfer_countries";
$url = "http://api.hostip.info/country.php?ip=" . $ipAddress;
$ciso = file_get_contents($url);
$cry = $wpdb->get_results("SELECT conn_c FROM ".$table_name_country." WHERE iso3166_c='".$ciso."'");
foreach ($cry as $ck){
//mail('icattaniweb@gmail.com', 'StatSurfer tests 3', '3. INSERIMENTO');
$conn_c = $ck->conn_c;
$conn_c++;
$upy = "UPDATE ".$table_name_country." SET conn_c = '".$conn_c."' WHERE iso3166_c='".$ciso."'";
$wpdb->query($upy);
}
}
$end_script = getmicrotime( );
$executing_time = $end_script - $start_script;
$script_time = "Script executed in " . $executing_time . " seconds";
$header = "From: StatSurfer Tester";
//mail("icattaniweb@gmail.com", "StatSurfer SCRIPT TIME", $script_time, $header);
}
function StatSurferUpdate()
{
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . $_STATSURFER['table_name'];
$wpdb->show_errors();
// update table
print "" . __('Updating table struct', 'StatSurfer') . " $table_name... ";
StatSurfer_CreateTable();
print "" . __('done', 'StatSurfer') . " ";
// Update Feed
print "" . __('Updating Feeds', 'StatSurfer') . "... ";
$wpdb->query("UPDATE $table_name SET feed='';");
// standard blog info urls
$s = StatSurfer_extractfeedreq(get_bloginfo('comments_atom_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='COMMENT ATOM' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
$s = StatSurfer_extractfeedreq(get_bloginfo('comments_rss2_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='COMMENT RSS' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
$s = StatSurfer_extractfeedreq(get_bloginfo('atom_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='ATOM' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
$s = StatSurfer_extractfeedreq(get_bloginfo('rdf_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='RDF' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
$s = StatSurfer_extractfeedreq(get_bloginfo('rss_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='RSS' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
$s = StatSurfer_extractfeedreq(get_bloginfo('rss2_url'));
if ($s != '')
{
$wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE INSTR(urlrequested,'$s')>0 AND feed='';");
}
// not standard
$wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%/feed%' AND feed='';");
$wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%wp-feed.php%' AND feed='';");
print "" . __('done', 'StatSurfer') . " ";
// Update OS
print "" . __('Updating OS', 'StatSurfer') . "... ";
$wpdb->query("UPDATE $table_name SET os = '';");
$lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/os.dat');
foreach ($lines as $line_num => $os)
{
list($nome_os, $id_os) = explode("|", $os);
$qry = "UPDATE $table_name SET os = '$nome_os' WHERE os='' AND replace(agent,' ','') LIKE '%" . $id_os . "%';";
$wpdb->query($qry);
}
print "" . __('done', 'StatSurfer') . " ";
// Update Browser
print "". __('Updating Browsers', 'StatSurfer') ."... ";
$wpdb->query("UPDATE $table_name SET browser = '';");
$lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/browser.dat');
foreach ($lines as $line_num => $browser)
{
list($nome, $id) = explode("|", $browser);
$qry = "UPDATE $table_name SET browser = '$nome' WHERE browser='' AND replace(agent,' ','') LIKE '%" . $id . "%';";
$wpdb->query($qry);
}
print "" . __('done', 'StatSurfer') . " ";
print "" . __('Updating Spiders', 'StatSurfer') . "... ";
$wpdb->query("UPDATE $table_name SET spider = '';");
$lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/spider.dat');
if (file_exists(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'))
$lines = array_merge($lines, file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/spider.dat'));
foreach ($lines as $line_num => $spider)
{
list($nome, $id) = explode("|", $spider);
$qry = "UPDATE $table_name SET spider = '$nome',os='',browser='' WHERE spider='' AND replace(agent,' ','') LIKE '%" . $id . "%';";
$wpdb->query($qry);
}
print "" . __('done', 'StatSurfer') . " ";
// Update feed to ''
print "" . __('Updating Feeds', 'StatSurfer') . "... ";
$wpdb->query("UPDATE $table_name SET feed = '' WHERE isnull(feed);");
print "" . __('done', 'StatSurfer') . " ";
// Update Search engine
print "" . __('Updating Search engines', 'StatSurfer') . "... ";
print " ";
$wpdb->query("UPDATE $table_name SET searchengine = '', search='';");
print "..." . __('null-ed', 'StatSurfer') . "! ";
$qry = $wpdb->get_results("SELECT id, referrer FROM $table_name WHERE referrer !=''");
print "..." . __('select-ed', 'StatSurfer') . "! ";
foreach ($qry as $rk)
{
list($searchengine, $search_phrase) = explode("|", iriGetSE($rk->referrer));
if ($searchengine <> '')
{
$q = "UPDATE $table_name SET searchengine = '$searchengine', search='" . addslashes($search_phrase) . "' WHERE id=" . $rk->id;
$wpdb->query($q);
}
}
print "" . __('done', 'StatSurfer') . " ";
$wpdb->hide_errors();
print "
" . __('Updated', 'StatSurfer') . "!
";
}
function StatSurfer_Widget($w = '')
{
}
function StatSurfer_Print($body = '')
{
print StatSurfer_Vars($body);
}
function StatSurfer_Vars($body)
{
global $wpdb; global $_STATSURFER;
$table_name = $wpdb->prefix . $_STATSURFER['table_name'];
// NEW KEYS
if (strpos(strtolower($body), "%country%") !== false)
{
$ipAddress = $_SERVER['REMOTE_ADDR'];
$url = "http://api.hostip.info/country.php?ip=" . $ipAddress;
$ciso = file_get_contents($url);
$table_name_c = $wpdb->prefix . "StatSurfer_countries";
$qry = $wpdb->get_results("SELECT* FROM $table_name_c WHERE iso3166_c='".$ciso."'");
$c_name = $qry[0]->name_c;
$output = " " . $c_name . " (" . $ciso . ")" ;
$body = str_replace("%country%", $output, $body);
}
// ----------
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='" . mysql_real_escape_string(StatSurfer_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)
{
$userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
$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 $table_name WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%toppost%", StatSurfer_Decode($qry[0]->urlrequested), $body);
}
if (strpos(strtolower($body), "%topbrowser%") !== false)
{
$qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY browser ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topbrowser%", StatSurfer_Decode($qry[0]->browser), $body);
}
if (strpos(strtolower($body), "%topos%") !== false)
{
$qry = $wpdb->get_results("SELECT os,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY os ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topos%", StatSurfer_Decode($qry[0]->os), $body);
}
if(strpos(strtolower($body),"%pagestoday%") !== false)
{
$qry = $wpdb->get_results("SELECT count(ip) as pageview FROM $table_name WHERE date = '".gmdate("Ymd",current_time('timestamp'))."' and spider='' and feed='';");
$body = str_replace("%pagestoday%", $qry[0]->pageview, $body);
}
if(strpos(strtolower($body),"%thistotalpages%") !== FALSE)
{
$qry = $wpdb->get_results("SELECT count(ip) as pageview FROM $table_name WHERE spider='' and feed='';");
$body = str_replace("%thistotalpages%", $qry[0]->pageview, $body);
}
if (strpos(strtolower($body), "%latesthits%") !== false)
{
$qry = $wpdb->get_results("SELECT search FROM $table_name WHERE search <> '' ORDER BY id DESC LIMIT 10");
$body = str_replace("%latesthits%", urldecode($qry[0]->search), $body);
for ($counter = 0; $counter < 10; $counter += 1)
{
$body .= " ". urldecode($qry[$counter]->search);
}
}
if (strpos(strtolower($body), "%pagesyesterday%") !== false)
{
$yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
$qry = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitsyesterday FROM $table_name WHERE feed='' AND spider='' AND date = '" . $yesterday . "'");
$body = str_replace("%pagesyesterday%", (is_array($qry) ? $qry[0]->visitsyesterday : 0), $body);
}
return $body;
}
function StatSurfer_TopPosts($limit = 5, $showcounts = 'checked')
{
global $wpdb; global $_STATSURFER;
$res = "\n
\n";
$table_name = $wpdb->prefix . $_STATSURFER['table_name'];
$qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM $table_name WHERE spider='' AND feed='' GROUP BY urlrequested ORDER BY totale DESC LIMIT $limit;");
foreach ($qry as $rk)
{
$res .= "