"; } } function DateSelector($inName, $useDate=0) { /* create array so we can name months */ $monthName = array(1=> "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); /* if date invalid or not supplied, use current time */ if($useDate == 0) { $useDate = Time(); } /* make year selector */ echo ""; /* make month selector */ echo ""; /* make day selector */ echo ""; } function getmicrotime(){ list( $usec, $sec) = explode( " ", microtime()); return ( ( float)$usec + ( float)$sec); } /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ if ($_GET['StatSurfer_action'] == 'exportnow') { StatSurferExportNow(); } function iri_add_pages() { // Create table if it doesn't exist global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { StatSurfer_CreateTable(); update_option('StatSurfer_showcharts','checked'); } // add submenu $mincap = get_option('StatSurfer_mincap'); if ($mincap == '') { $mincap = 'level_8'; } add_menu_page('StatSurfer', 'StatSurfer', $mincap, __FILE__, 'StatSurfer'); add_submenu_page(__FILE__, __('Details', 'StatSurfer'), __('Details', 'StatSurfer'), $mincap, 'details', 'StatSurferDetails'); add_submenu_page(__FILE__, __('Spy', 'StatSurfer'), __('Spy', 'StatSurfer'), $mincap, 'spy', 'StatSurferSpy'); add_submenu_page(__FILE__, __('Goals', 'StatSurfer'), __('Goals', 'StatSurfer'), $mincap, 'goals', 'StatSurferGoals'); add_submenu_page(__FILE__, __('Map', 'StatSurfer'), __('Map', 'StatSurfer'), $mincap, 'map', 'StatSurferMap'); //add_submenu_page(__FILE__, __('Export', 'StatSurfer'), __('Export', 'StatSurfer'), $mincap, 'export', 'StatSurferExport'); add_submenu_page(__FILE__, __('Options', 'StatSurfer'), __('Options', 'StatSurfer'), $mincap, 'options', 'StatSurferOptions'); add_submenu_page(__FILE__, __('User Agents', 'StatSurfer'), __('User Agents', 'StatSurfer'), $mincap, 'agents', 'StatSurferAgents'); //add_submenu_page(__FILE__, __('StatSurferUpdate', 'StatSurfer'), __('StatSurferUpdate', 'StatSurfer'), $mincap, 'up', 'StatSurferUpdate'); } function permalinksEnabled() { global $wpdb; global $_STATSURFER; $result = $wpdb->get_row('SELECT `option_value` FROM `' . $wpdb->prefix . 'options` WHERE `option_name` = "permalink_structure"'); if ($result->option_value != '') { return true; } else { return false; } } function my_substr($str, $x, $y = 0) { if($y == 0) { $y = strlen($str) - $x; } if(function_exists('mb_substr')) { return mb_substr($str, $x, $y); } else { return substr($str, $x, $y); } } function StatSurfer() { if ($_GET['StatSurfer_action'] == 'export') { StatSurferExport(); } elseif ($_GET['StatSurfer_action'] == 'map') { StatSurferMap(); } elseif ($_GET['StatSurfer_action'] == 'up') { StatSurferUpdate(); } elseif ($_GET['StatSurfer_action'] == 'spy') { StatSurferSpy(); } elseif ($_GET['StatSurfer_action'] == 'details') { StatSurferDetails(); } elseif ($_GET['StatSurfer_action'] == 'options') { StatSurferOptions(); } elseif ($_GET['StatSurfer_action'] == 'overview') { StatSurferMain(); } elseif ($_GET['StatSurfer_action'] == 'agents') { StatSurferAgents(); } elseif ($_GET['StatSurfer_action'] == 'goals') { StatSurferGoals(); } elseif ($_GET['StatSurfer_action'] == 'add_goal') { StatSurferAddGoals(); } elseif ($_GET['StatSurfer_action'] == 'del_goal') { StatSurferDelGoals(); } elseif ($_GET['StatSurfer_action'] == 'show_goal') { StatSurferShowGoals(); } else { StatSurferMain(); } } //____________________________________________________________________________________// //__dashboard_widget__________________________________________________________________// //____________________________________________________________________________________// if( !class_exists( 'StatSurfer_DashboardWidget') ) { class StatSurfer_DashboardWidget { function StatSurferDashWidget(){ StatSurfer_DashboardWidget_Tabel(); } function StatSurferDashWidget_Loader(){ wp_add_dashboard_widget('statsurfer', 'StatSurfer', array( 'StatSurfer_DashboardWidget', 'StatSurferDashWidget' )); } } add_action( 'wp_dashboard_setup', array( 'StatSurfer_DashboardWidget', 'StatSurferDashWidget_Loader' ) ); } function StatSurfer_DashboardWidget_Tabel(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; // OVERVIEW table $unique_color = "#114477"; $web_color = "#3377B6"; $rss_color = "#f38f36"; $spider_color = "#83b4d8"; $thismonth = gmdate('Ym', current_time('timestamp')); $yesterday = gmdate('Ymd', current_time('timestamp') - 86400); $today = gmdate('Ymd', current_time('timestamp')); $tlm[0] = my_substr($lastmonth, 0, 4); $tlm[1] = my_substr($lastmonth, 4, 2); print "
"; print ""; echo ""; //############################################################################################### // VISITORS ROW print ""; //TOTAL $qry_total = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors FROM $table_name WHERE feed='' AND spider='' "); print "\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 "\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"; print ""; //############################################################################################### // PAGEVIEWS ROW print ""; //TOTAL $qry_total = $wpdb->get_row(" SELECT count(date) as pageview FROM $table_name WHERE feed='' AND spider='' "); print "\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 "\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"; print ""; //############################################################################################### // SPIDERS ROW print ""; //TOTAL $qry_total = $wpdb->get_row("SELECT count(date) as spiders FROM $table_name WHERE feed='' AND spider<>''"); print "\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 "\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 "\n"; print ""; //############################################################################################### // FEEDS ROW print ""; //TOTAL $qry_total = $wpdb->get_row("SELECT count(date) as feeds FROM $table_name WHERE feed<>'' AND spider=''"); print "\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 "\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 "\n"; print "
" . __('Total', 'StatSurfer') . " " . __('This month', 'StatSurfer') . " " . __('Yesterday', 'StatSurfer') . "
" . __('Today', 'StatSurfer') . "
" . gmdate('M, Y', current_time('timestamp')) . " " . gmdate('d M, Y', current_time('timestamp') - 86400) . " " . gmdate('d M, Y', current_time('timestamp')) . "
" . __('Visitors', 'StatSurfer') . "
" . $qry_total->visitors . "" . $qry_tmonth->visitors . $qry_tmonth->change . "" . $qry_y->visitors . "" . $qry_t->visitors . "
" . __('Pageviews', 'StatSurfer') . "
" . $qry_total->pageview . "" . $qry_tmonth->pageview . $qry_tmonth->change . "" . $qry_y->pageview . "" . $qry_t->pageview . "
" . __('Spiders', 'StatSurfer') . "
" . $qry_total->spiders . "" . $qry_tmonth->spiders . $qry_tmonth->change . "" . $qry_y->spiders . "" . $qry_t->spiders . "
" . __('Feeds', 'StatSurfer') . "
" . $qry_total->feeds . "" . $qry_tmonth->feeds . $qry_tmonth->change . "" . $qry_y->feeds . "" . $qry_t->feeds . "

\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 '\n"; } print '

" . gmdate('d', current_time('timestamp') - 86400 * $gg) . '
' . gmdate('M', current_time('timestamp') - 86400 * $gg) . "
'; print '
'; } //____________________________________________________________________________________// //____________________________________________________________________________________// //MAPS function StatSurferMap(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . "StatSurfer_countries"; print "

Connections' Map

"; print "
World Map
"; $sel_countries = ""; $val_countries = ""; $first_check=1; $total_conn = 0; $count_countries = 0; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE conn_c<>0 ORDER BY conn_c DESC"); foreach ($qry as $rk){ if($rk->iso3166_c!='EU'){ if($first_check==1){ $max_val = $rk->conn_c; } $first_check=0; $val = ($rk->conn_c)*100/$max_val; $val = round($val,0); $sel_countries .= $rk->iso3166_c; $val_countries .= $val . ","; } $total_conn = $total_conn + $rk->conn_c; $count_countries = $count_countries + 1; } $val_countries=my_substr($val_countries,0,strlen($val_countries)-1); echo ""; echo "
"; echo "
"; print "\n"; echo "
"; echo "
"; print "\n"; echo "
"; echo "
"; print "\n"; echo "
"; echo "
"; $list = 1; echo "
"; $table_name_c = $wpdb->prefix . "StatSurfer_countries"; $qry_count_countries = $wpdb->get_row("SELECT count(id_c) as total FROM $table_name_c"); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "

Countries' datas

Known Countries (included Europen Union)".$qry_count_countries->total."
Countries connected".$count_countries."
Total Connections (only from known countries)".$total_conn."
Connections' mean"; if($count_countries == 0){ echo "-"; } else{ echo round(($total_conn/$count_countries),0); } echo "
"; echo "
"; echo ""; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE conn_c<>0 ORDER BY conn_c DESC"); foreach ($qry as $rk){ echo ""; $list++; } echo "
"; echo $list; echo ""; echo $rk->name_c; echo ""; print ""; echo ""; echo $rk->iso3166_c; echo ""; echo $rk->conn_c; //echo ""; //echo $rk->w_conn_c; echo "
"; echo "
"; print "
"; } function StatSurferMap_update(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; $table_name_country = $wpdb->prefix . "StatSurfer_countries"; $tsStart = get_option('StatSurfer_lastmaptimestamp'); $tsEnd = current_time('timestamp'); //update_option('StatSurfer_lastmaptimestamp', $tsEnd); $qry = $wpdb->get_results("SELECT ip FROM ".$table_name." WHERE timestamp>".$tsStart." AND timestamp<=".$tsEnd." ORDER BY timestamp ASC"); foreach ($qry as $rk){ $url = "http://api.hostip.info/country.php?ip=" . $rk->ip; $ciso = file_get_contents($url); $cry = $wpdb->get_results("SELECT conn_c FROM ".$table_name_country." WHERE iso3166_c='".$ciso."'"); foreach ($cry as $ck){ $conn_c = $ck->conn_c; $conn_c++; $upy = "UPDATE ".$table_name_country." SET conn_c = '".$conn_c."' WHERE iso3166_c='".$ciso."'"; $wpdb->query($upy); } } } function StatSurferOptions() { if ($_POST['saveit'] == 'yes') { update_option('StatSurfer_showcharts', $_POST['StatSurfer_showcharts']); update_option('StatSurfer_collectloggeduser', $_POST['StatSurfer_collectloggeduser']); update_option('StatSurfer_autodelete', $_POST['StatSurfer_autodelete']); update_option('StatSurfer_daysinoverviewgraph', $_POST['StatSurfer_daysinoverviewgraph']); update_option('StatSurfer_mincap', $_POST['StatSurfer_mincap']); update_option('StatSurfer_donotcollectspider', $_POST['StatSurfer_donotcollectspider']); update_option('StatSurfer_autodelete_spider', $_POST['StatSurfer_autodelete_spider']); // update database too //StatSurfer_CreateTable(); print "

" . __('Saved', 'StatSurfer') . "!

"; } else { global $_STATSURFER; // echo $_STATSURFER['table_name']; ?>


General settings
"; print ""; print ""; ?>
Show charts under details' tables
" . __('Collect data about logged users, too.', 'StatSurfer') . "
" . __('Do not collect spiders visits', 'StatSurfer') . "

Export stats (CSV file)
(YYYYMMDD)
(YYYYMMDD)
>
capabilities as $cap => $grant) { print ""; } } function StatSurferExport() { ?>

(csv)

(YYYYMMDD)
(YYYYMMDD)
>
prefix . $_STATSURFER['table_name']; $filename = get_bloginfo('title') . "-StatSurfer_" . $_GET['from'] . "-" . $_GET['to'] . ".csv"; header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=$filename"); header('Content-Type: text/plain charset=' . get_option('blog_charset'), true); $qry = $wpdb->get_results("SELECT * FROM $table_name WHERE date>='" . (date("Ymd", strtotime(my_substr($_GET['from'], 0, 8)))) . "' AND date<='" . (date("Ymd", strtotime(my_substr($_GET['to'], 0, 8)))) . "';"); $del = my_substr($_GET['del'], 0, 1); print "date" . $del . "time" . $del . "ip" . $del . "urlrequested" . $del . "agent" . $del . "referrer" . $del . "search" . $del . "nation" . $del . "os" . $del . "browser" . $del . "searchengine" . $del . "spider" . $del . "feed\n"; foreach ($qry as $rk) { print '"' . $rk->date . '"' . $del . '"' . $rk->time . '"' . $del . '"' . $rk->ip . '"' . $del . '"' . $rk->urlrequested . '"' . $del . '"' . $rk->agent . '"' . $del . '"' . $rk->referrer . '"' . $del . '"' . urldecode($rk->search) . '"' . $del . '"' . $rk->nation . '"' . $del . '"' . $rk->os . '"' . $del . '"' . $rk->browser . '"' . $del . '"' . $rk->searchengine . '"' . $del . '"' . $rk->spider . '"' . $del . '"' . $rk->feed . '"' . "\n"; } die(); } function StatSurferMain() { global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; print "

Dates Selector

"; print ""; if(isset($_GET['find_statDay'])){ print ""; print ""; } print "
Select a day "; print "
"; print ""; DateSelector("find_stat"); print ""; print "
"; print "
"; print "ATTENTION! You are looking the stats of " . $_GET['find_statYear'] . "/" . $_GET['find_statMonth'] . "/" . $_GET['find_statDay'] . " Return to today"; print "
"; if(isset($_GET['find_statDay'])) $timestamp = mktime(11,0,0,$_GET['find_statMonth'],$_GET['find_statDay'],$_GET['find_statYear']); else $timestamp = current_time('timestamp'); // OVERVIEW table $unique_color = "#114477"; $web_color = "#3377B6"; $rss_color = "#f38f36"; $spider_color = "#83b4d8"; $lastmonth = StatSurfer_lastmonth(); $thismonth = gmdate('Ym', $timestamp); $yesterday = gmdate('Ymd', $timestamp - 86400); $today = gmdate('Ymd', $timestamp); $tlm[0] = my_substr($lastmonth, 0, 4); $tlm[1] = my_substr($lastmonth, 4, 2); print "

" . __('Overview', 'StatSurfer') . "

"; print ""; //############################################################################################### // VISITORS ROW print ""; //TOTAL $qry_total = $wpdb->get_row(" SELECT count(DISTINCT ip) AS visitors FROM $table_name WHERE feed='' AND spider='' "); print "\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 "\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"; //TARGET $qry_tmonth->target = round($qry_tmonth->visitors / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t'))); if ($qry_lmonth->visitors <> 0) { $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->visitors) - 100, 1); if ($pt >= 0) $pt = "+" . $pt; $qry_tmonth->added = " (" . $pt . "%)"; } 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 "\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"; print ""; //############################################################################################### // PAGEVIEWS ROW print ""; //TOTAL $qry_total = $wpdb->get_row(" SELECT count(date) as pageview FROM $table_name WHERE feed='' AND spider='' "); print "\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 "\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"; //TARGET $qry_tmonth->target = round($qry_tmonth->pageview / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t'))); if ($qry_lmonth->pageview <> 0) { $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->pageview) - 100, 1); if ($pt >= 0) $pt = "+" . $pt; $qry_tmonth->added = " (" . $pt . "%)"; } 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 "\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"; print ""; //############################################################################################### // SPIDERS ROW print ""; //TOTAL $qry_total = $wpdb->get_row(" SELECT count(date) as spiders FROM $table_name WHERE feed='' AND spider<>'' "); print "\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 "\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"; //TARGET $qry_tmonth->target = round($qry_tmonth->spiders / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t'))); if ($qry_lmonth->spiders <> 0) { $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->spiders) - 100, 1); if ($pt >= 0) $pt = "+" . $pt; $qry_tmonth->added = " (" . $pt . "%)"; } 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 "\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 "\n"; print ""; //############################################################################################### // FEEDS ROW print ""; //TOTAL $qry_total = $wpdb->get_row(" SELECT count(date) as feeds FROM $table_name WHERE feed<>'' AND spider='' "); print "\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 "\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"; //TARGET $qry_tmonth->target = round($qry_tmonth->feeds / (time() - mktime(0,0,0,date('m'),date('1'),date('Y'))) * (86400 * date('t'))); if ($qry_lmonth->feeds <> 0) { $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->feeds) - 100, 1); if ($pt >= 0) $pt = "+" . $pt; $qry_tmonth->added = " (" . $pt . "%)"; } 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 "\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 "\n"; print "
" . __('Total', 'StatSurfer') . " " . __('Last month', 'StatSurfer') . "
" . gmdate('M, Y', gmmktime(0, 0, 0, $tlm[1], 1, $tlm[0])) . "
" . __('This month', 'StatSurfer') . "
" . gmdate('M, Y', $timestamp) . "
" . __('Target', 'StatSurfer') . " " . __('This month', 'StatSurfer') . "
" . gmdate('M, Y', $timestamp) . "
" . __('Yesterday', 'StatSurfer') . "
" . gmdate('d M, Y', $timestamp - 86400) . "
" . __('Today', 'StatSurfer') . "
" . gmdate('d M, Y', $timestamp) . "
" . __('Visitors', 'StatSurfer') . "
" . $qry_total->visitors . "" . $qry_lmonth->visitors . "" . $qry_tmonth->visitors . $qry_tmonth->change . "" . $qry_tmonth->target . $qry_tmonth->added . "" . $qry_y->visitors . "" . $qry_t->visitors . "
" . __('Pageviews', 'StatSurfer') . "
" . $qry_total->pageview . "" . $qry_lmonth->pageview . "" . $qry_tmonth->pageview . $qry_tmonth->change . "" . $qry_tmonth->target . $qry_tmonth->added . "" . $qry_y->pageview . "" . $qry_t->pageview . "
" . __('Spiders', 'StatSurfer') . "
" . $qry_total->spiders . "" . $qry_lmonth->spiders . "" . $qry_tmonth->spiders . $qry_tmonth->change . "" . $qry_tmonth->target . $qry_tmonth->added . "" . $qry_y->spiders . "" . $qry_t->spiders . "
" . __('Feeds', 'StatSurfer') . "
" . $qry_total->feeds . "" . $qry_lmonth->feeds . "" . $qry_tmonth->feeds . $qry_tmonth->change . "" . $qry_tmonth->target . $qry_tmonth->added . "" . $qry_y->feeds . "" . $qry_t->feeds . "

\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 '\n"; } print '

" . gmdate('d', current_time('timestamp') - 86400 * $gg) . '
' . gmdate('M', current_time('timestamp') - 86400 * $gg) . "
'; print '
'; // END OF OVERVIEW //################################################################################################### //----------------------------------------------------------------------------------------------------// //--- Other Graphs -----------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------// $monthName = array(1=> "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $monthNameNumber = array(1=> "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"); print "
"; echo "
"; echo ""; echo "

Month by month

Year by year

"; $gdays = 12; $cMonth = gmdate('m', current_time('timestamp')); $cMonthID = (int)$cMonth; $cYearID = (int)gmdate('Y', current_time('timestamp')); if($cMonthID==12){ $cMonthID = 1; } else{ $cMonthID = $cMonthID + 1; $cYearID--; } print ''; $dataTab = array(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0); $dataTOT = array(0,0,0,0,0,0,0,0,0,0,0,0); for($i=0;$i<12;$i++){ $startDate = $cYearID . $monthNameNumber[$cMonthID] . "00"; $endDate = $cYearID . $monthNameNumber[$cMonthID] . "32"; //TOTAL VISITORS $qry_visitors = $wpdb->get_row(" SELECT count(DISTINCT ip) AS total FROM $table_name WHERE feed='' AND spider='' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_visitors = $qry_visitors->total; $ID= 0 + (4*$i); $dataTab[$ID]=$px_visitors; $sub_tot = $px_visitors; //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 > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_pageviews = $qry_pageviews->total; $ID= 1 + (4*$i); $dataTab[$ID]=$px_pageviews; $sub_tot = $sub_tot + $px_pageviews; //TOTAL SPIDERS $qry_spiders = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed='' AND spider<>'' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_spiders = $qry_spiders->total; $ID= 2 + (4*$i); $dataTab[$ID]=$px_spiders; $sub_tot = $sub_tot + $px_spiders; //TOTAL FEEDS $qry_feeds = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed<>'' AND spider='' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_feeds = $qry_feeds->total; $ID= 3 + (4*$i); $dataTab[$ID]=$px_feeds; $sub_tot = $sub_tot + $px_feeds; $dataTOT[$i]=$sub_tot; $cMonthID++; if($cMonthID == 13){ $cMonthID = 1; $cYearID++; } } $cMonth = gmdate('m', current_time('timestamp')); $cMonthID = (int)$cMonth; $cYearID = (int)gmdate('Y', current_time('timestamp')); if($cMonthID==12){ $cMonthID = 1; } else{ $cMonthID = $cMonthID + 1; $cYearID--; } $ID = 0; $maxxday = $dataTOT[0]; for($i=0;$i<12;$i++){ if($dataTOT[$i]>$maxxday) $maxxday = $dataTOT[$i]; } if ($maxxday == 0) { $maxxday = 1; } $gd = (90 / $gdays) . '%'; for($i=0;$i<12;$i++){ $px_visitors = round($dataTab[$ID] * 100 / $maxxday); $px_pageviews = round($dataTab[$ID+1] * 100 / $maxxday); $px_spiders = round($dataTab[$ID+2] * 100 / $maxxday); $px_feeds = round($dataTab[$ID+3] * 100 / $maxxday); $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors; print '\n"; $ID = $ID + 4; $cMonthID++; if($cMonthID == 13){ $cMonthID = 1; $cYearID++; } } print '

" . $monthName[$cMonthID] . '
' . $cYearID . "
'; echo "
"; //YEAR $gdays = 5; $cYearID = (int)gmdate('Y', current_time('timestamp')); print ''; $dataTab = array(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0); $dataTOT = array(0,0,0,0,0); $c = 0; for($i=4;$i>(-1);$i--){ $startDate = ($cYearID - $i) . "00" . "00"; $endDate = ($cYearID - $i) . "13" . "32"; //TOTAL VISITORS $qry_visitors = $wpdb->get_row(" SELECT count(DISTINCT ip) AS total FROM $table_name WHERE feed='' AND spider='' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_visitors = $qry_visitors->total; $ID= 0 + (4*$c); $dataTab[$ID]=$px_visitors; $sub_tot = $px_visitors; //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 > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_pageviews = $qry_pageviews->total; $ID= 1 + (4*$c); $dataTab[$ID]=$px_pageviews; $sub_tot = $sub_tot + $px_pageviews; //TOTAL SPIDERS $qry_spiders = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed='' AND spider<>'' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_spiders = $qry_spiders->total; $ID= 2 + (4*$c); $dataTab[$ID]=$px_spiders; $sub_tot = $sub_tot + $px_spiders; //TOTAL FEEDS $qry_feeds = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed<>'' AND spider='' AND date > '" . $startDate . "' AND date < '" . $endDate . "' "); $px_feeds = $qry_feeds->total; $ID= 3 + (4*$c); $dataTab[$ID]=$px_feeds; $sub_tot = $sub_tot + $px_feeds; $dataTOT[4-$i]=$sub_tot; $c++; } $ID = 0; $maxxday = $dataTOT[0]; for($i=0;$i<5;$i++){ if($dataTOT[$i]>$maxxday) $maxxday = $dataTOT[$i]; } if ($maxxday == 0) { $maxxday = 1; } $gd = (90 / $gdays) . '%'; for($i=4;$i>(-1);$i--){ $px_visitors = round($dataTab[$ID] * 100 / $maxxday); $px_pageviews = round($dataTab[$ID+1] * 100 / $maxxday); $px_spiders = round($dataTab[$ID+2] * 100 / $maxxday); $px_feeds = round($dataTab[$ID+3] * 100 / $maxxday); $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors; print '\n"; $ID = $ID + 4; } print '
'; print "

" . ($cYearID - $i) . "
 
'; echo "

"; echo "
"; //----------------------------------------------------------------------------------------------------// //----------------------------------------------------------------------------------------------------// $querylimit = "LIMIT 20"; echo "
"; echo ""; echo "
"; // Last Search terms print "

" . __('Last search terms', 'StatSurfer') . "

"; 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 "\n"; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('Terms', 'StatSurfer') . "" . __('Engine', 'StatSurfer') . "" . __('Result', 'StatSurfer') . "
" . irihdate($rk->date) . "" . $rk->time . "" . StatSurfer_Abbrevia(urldecode($rk->search), 50) . "" . $rk->searchengine . "urlrequested : '') . "'>" . __('page viewed', 'StatSurfer') . "
"; echo "
"; // Referrer print "

" . __('Last referrers', 'StatSurfer') . "

"; 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 "\n"; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('URL', 'StatSurfer') . "" . __('Result', 'StatSurfer') . "
" . irihdate($rk->date) . "" . $rk->time . "" . StatSurfer_Abbrevia($rk->referrer, 35) . "urlrequested : '') . "'>" . __('page viewed', 'StatSurfer') . "
"; echo "
"; // Last pages print "

" . __('Last pages', 'StatSurfer') . "

"; 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 "\n"; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('Page', 'StatSurfer') . "" . __('What', 'StatSurfer') . "
" . irihdate($rk->date) . "" . $rk->time . "" . StatSurfer_Abbrevia(StatSurfer_Decode($rk->urlrequested), 60) . " " . $rk->os . " " . $rk->browser . " " . $rk->spider . "
"; // Tabella Last hits print "

" . __('Last hits', 'StatSurfer') . "

"; print ""; $fivesdrafts = $wpdb->get_results("SELECT * FROM $table_name WHERE (os<>'' OR feed<>'') order by id DESC $querylimit"); foreach ($fivesdrafts as $fivesdraft) { print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('IP', 'StatSurfer') . "" . __('Threat', 'StatSurfer') . "" . __('Domain', 'StatSurfer') . "" . __('Page', 'StatSurfer') . "" . __('OS', 'StatSurfer') . "" . __('Browser', 'StatSurfer') . "" . __('Feed', 'StatSurfer') . "
" . irihdate($fivesdraft->date) . "" . $fivesdraft->time . "" . $fivesdraft->ip . "" . $fivesdraft->threat_score; if ($fivesdraft->threat_score > 0) { print "/"; if ($fivesdraft->threat_type == 0) print "Sp"; // Spider else { if (($fivesdraft->threat_type & 1) == 1) print "S"; // Suspicious if (($fivesdraft->threat_type & 2) == 2) print "H"; // Harvester if (($fivesdraft->threat_type & 4) == 4) print "C"; // Comment spammer } } print "" . $fivesdraft->nation . "" . StatSurfer_Abbrevia(StatSurfer_Decode($fivesdraft->urlrequested), 30) . "" . $fivesdraft->os . "" . $fivesdraft->browser . "" . $fivesdraft->feed . "
"; // Last Agents print "

" . __('Last agents', 'StatSurfer') . "

"; 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 "\n"; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('Agent', 'StatSurfer') . "" . __('What', 'StatSurfer') . "
" . irihdate($rk->date) . "" . $rk->time . "" . $rk->agent . " " . $rk->os . " " . $rk->browser . " " . $rk->spider . "
"; // Last Spiders print "

" . __('Last spiders', 'StatSurfer') . "

"; print ""; print ""; print ""; print ""; print ""; print ""; 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 ""; print ""; print ""; print ""; print "\n"; } print "
" . __('Date', 'StatSurfer') . "" . __('Time', 'StatSurfer') . "" . __('Spider', 'StatSurfer') . "" . __('Page', 'StatSurfer') . "" . __('Agent', 'StatSurfer') . "
" . irihdate($rk->date) . "" . $rk->time . "" . $rk->spider . "" . StatSurfer_Abbrevia(StatSurfer_Decode($rk->urlrequested), 30) . " " . $rk->agent . "
"; print "
"; print " " . __('StatSurfer table size', 'StatSurfer') . ": " . iritablesize($wpdb->prefix . $_STATSURFER['table_name']) . "
"; print " " . __('StatSurfer current time', 'StatSurfer') . ": " . current_time('mysql') . "
"; print " " . __('RSS2 url', 'StatSurfer') . ": " . get_bloginfo('rss2_url') . ' (' . StatSurfer_extractfeedreq(get_bloginfo('rss2_url')) . ")
"; print " " . __('ATOM url', 'StatSurfer') . ": " . get_bloginfo('atom_url') . ' (' . StatSurfer_extractfeedreq(get_bloginfo('atom_url')) . ")
"; print " " . __('RSS url', 'StatSurfer') . ": " . get_bloginfo('rss_url') . ' (' . StatSurfer_extractfeedreq(get_bloginfo('rss_url')) . ")
"; print " " . __('COMMENT RSS2 url', 'StatSurfer') . ": " . get_bloginfo('comments_rss2_url') . ' (' . StatSurfer_extractfeedreq(get_bloginfo('comments_rss2_url')) . ")
"; print " " . __('COMMENT ATOM url', 'StatSurfer') . ": " . get_bloginfo('comments_atom_url') . ' (' . StatSurfer_extractfeedreq(get_bloginfo('comments_atom_url')) . ")
"; } function StatSurferDetails() { global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; $querylimit = "LIMIT 10"; echo "
"; echo "
"; // Top days iriValueTable_pers_1("date", __('Top days', 'StatSurfer'), 13); echo ""; // Top Days - Unique visitors iriValueTable_pers_1("date", __('Top Days - Unique visitors', 'StatSurfer'), 5, "distinct", "ip", "AND feed='' and spider=''"); echo "
"; // Top Days - Pageviews iriValueTable_pers_1("date", __('Top Days - Pageviews', 'StatSurfer'), 5, "", "urlrequested", "AND feed='' and spider=''"); echo "
"; echo "
"; echo ""; echo "
''"); echo ""; // Browser iriValueTable_pers_1("browser", __('Browser', 'StatSurfer'), 0, "", "", "AND feed='' AND spider='' AND browser<>''"); echo "
"; echo "
"; // Feeds iriValueTable_pers_1("feed", __('Feeds', 'StatSurfer'), 5, "", "", "AND feed<>''"); echo "
"; echo ""; echo "
''"); echo ""; // Search terms iriValueTable_pers_1("search", __('Top search terms', 'StatSurfer'), 15, "", "", "AND search<>''"); echo "
"; 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); ?>
"; echo ""; echo ""; echo ""; } ?>
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 . ' '; } } } ?>
"; print ""; print " " . $rk->ip . " "; print "
"; print "
" . $rk->os . ", " . $rk->browser; print "
"; if ($rk->nation){ print "
" . gethostbyaddr($rk->ip) . ""; } print "
" . $rk->agent . ""; print "
"; echo "
"; echo ""; $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 ""; print ""; print ""; print ""; echo ""; } echo "
" . irihdate($details->date) . " " . $details->time . "
urlrequested, 'index.php') === FALSE) ? $details->urlrequested : '') . "' target='_blank'>" . StatSurfer_Decode($details->urlrequested) . ""; if ($details->searchengine != '') { print "
" . __('arrived from', 'StatSurfer') . " " . $details->searchengine . " " . __('searching', 'StatSurfer') . " " . urldecode($details->search) . ""; } elseif ($details->referrer != '' && strpos($details->referrer, get_option('home')) === false) { print "
" . __('arrived from', 'StatSurfer') . " " . $details->referrer . ""; } print "
"; echo "
prefix . $_STATSURFER['table_name']; $f['urlrequested'] = __('URL Requested', 'StatSurfer'); $f['agent'] = __('Agent', 'StatSurfer'); $f['referrer'] = __('Referrer', 'StatSurfer'); $f['search'] = __('Search terms', 'StatSurfer'); $f['searchengine'] = __('Search engine', 'StatSurfer'); $f['os'] = __('Operative system', 'StatSurfer'); $f['browser'] = __('Browser', 'StatSurfer'); $f['spider'] = __('Spider', 'StatSurfer'); $f['ip'] = __('IP', 'StatSurfer'); ?>

"; print ""; print ""; print ""; print ""; print ""; } ?>
" . __('Field', 'StatSurfer') . " " . __('Group by', 'StatSurfer') . " " . __('Sort by', 'StatSurfer') . ", " . __('if contains', 'StatSurfer') . "

>
>
>
>
 
name=searchsubmit>

" . __('Results', 'StatSurfer') . ""; $sql = "SELECT $fields FROM $table_name $where $groupby $orderby $limit;"; // print "$sql
"; print ""; for ($i = 1; $i <= 3; $i++) { if ($_GET["where$i"] != '') { print ""; } } if ($groupby != '') { print ""; } print ""; $qry = $wpdb->get_results($sql, ARRAY_N); foreach ($qry as $rk) { print ""; for ($i = 1; $i <= 3; $i++) { print ""; } print ""; } print "
" . ucfirst($_GET["where$i"]) . "" . __('Count', 'StatSurfer') . "
"; if ($_GET["where$i"] == 'urlrequested') { print StatSurfer_Decode($rk[$i - 1]); } else { print $rk[$i - 1]; } print "
"; print "

sql: $sql
"; } } function StatSurfer_Abbrevia($s, $c) { $res = ""; if (strlen($s) > $c) { $res = "..."; } return my_substr($s, 0, $c) . $res; } function StatSurfer_Where($ip) { $url = "http://api.hostip.info/get_html.php?ip=$ip"; $res = file_get_contents($url); if ($res === false) { return(array('', '')); } $res = str_replace("Country: ", "", $res); $res = str_replace("\nCity: ", ", ", $res); $nation = preg_split('/\(|\)/', $res); print "( $ip $res )"; return(array($res, $nation[1])); } function StatSurfer_Decode($out_url) { if(!permalinksEnabled()) { if ($out_url == '') { $out_url = __('Page', 'StatSurfer') . ": Home"; } if (my_substr($out_url, 0, 4) == "cat=") { $out_url = __('Category', 'StatSurfer') . ": " . get_cat_name(my_substr($out_url, 4)); } if (my_substr($out_url, 0, 2) == "m=") { $out_url = __('Calendar', 'StatSurfer') . ": " . my_substr($out_url, 6, 2) . "/" . my_substr($out_url, 2, 4); } if (my_substr($out_url, 0, 2) == "s=") { $out_url = __('Search', 'StatSurfer') . ": " . my_substr($out_url, 2); } if (my_substr($out_url, 0, 2) == "p=") { $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A); $out_url = $post_id_7['post_title']; } if (my_substr($out_url, 0, 8) == "page_id=") { $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A); $out_url = __('Page', 'StatSurfer') . ": " . $post_id_7['post_title']; } } else { if ($out_url == '') { $out_url = __('Page', 'StatSurfer') . ": Home"; } else if (my_substr($out_url, 0, 9) == "category/") { $out_url = __('Category', 'StatSurfer') . ": " . get_cat_name(my_substr($out_url, 9)); } else if (my_substr($out_url, 0, 8) == "//") // not working yet { //$out_url = __('Calendar', 'StatSurfer') . ": " . my_substr($out_url, 4, 0) . "/" . my_substr($out_url, 6, 7); } else if (my_substr($out_url, 0, 2) == "s=") { $out_url = __('Search', 'StatSurfer') . ": " . my_substr($out_url, 2); } else if (my_substr($out_url, 0, 2) == "p=") // not working yet { $post_id_7 = get_post(my_substr($out_url, 2), ARRAY_A); $out_url = $post_id_7['post_title']; } else if (my_substr($out_url, 0, 8) == "page_id=") // not working yet { $post_id_7 = get_page(my_substr($out_url, 8), ARRAY_A); $out_url = __('Page', 'StatSurfer') . ": " . $post_id_7['post_title']; } } return $out_url; } function StatSurfer_URL() { $urlRequested = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''); if ($urlRequested == "") { // SEO problem! $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : ''); } if (my_substr($urlRequested, 0, 2) == '/?') { $urlRequested = my_substr($urlRequested, 2); } if ($urlRequested == '/') { $urlRequested = ''; } return $urlRequested; } function irigetblogurl() { $prsurl = parse_url(get_bloginfo('url')); return $prsurl['scheme'] . '://' . $prsurl['host'] . ((!permalinksEnabled()) ? $prsurl['path'] . '/?' : ''); } // Converte da data us to default format di Wordpress function irihdate($dt = "00000000") { return mysql2date(get_option('date_format'), my_substr($dt, 0, 4) . "-" . my_substr($dt, 4, 2) . "-" . my_substr($dt, 6, 2)); } function iritablesize($table) { global $wpdb; global $_STATSURFER; $res = $wpdb->get_results("SHOW TABLE STATUS LIKE '$table'"); foreach ($res as $fstatus) { $data_lenght = $fstatus->Data_length; $data_rows = $fstatus->Rows; } return number_format(($data_lenght / 1024 / 1024), 2, ",", " ") . " MB ($data_rows records)"; } function irirgbhex($red, $green, $blue) { $red = 0x10000 * max(0, min(255, $red + 0)); $green = 0x100 * max(0, min(255, $green + 0)); $blue = max(0, min(255, $blue + 0)); // convert the combined value to hex and zero-fill to 6 digits return "#" . str_pad(strtoupper(dechex($red + $green + $blue)), 6, "0", STR_PAD_LEFT); } function iriValueTable($fld, $fldtitle, $limit = 0, $param = "", $queryfld = "", $exclude = "") { /* Maddler 04112007: param addedd */ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; if ($queryfld == '') { $queryfld = $fld; } print "

$fldtitle

"; print ""; $rks = $wpdb->get_var("SELECT count($param $queryfld) as rks FROM $table_name WHERE 1=1 $exclude;"); if ($rks > 0) { $sql = "SELECT count($param $queryfld) as pageview, $fld FROM $table_name WHERE 1=1 $exclude GROUP BY $fld ORDER BY pageview DESC"; if ($limit > 0) { $sql = $sql . " LIMIT $limit"; } $qry = $wpdb->get_results($sql); $tdwidth = 650; $red = 131; $green = 180; $blue = 216; $deltacolor = round(250 / count($qry), 0); // $chl=""; // $chd="t:"; foreach ($qry as $rk) { $pc = round(($rk->pageview * 100 / $rks), 1); if ($fld == 'date') { $rk->$fld = irihdate($rk->$fld); } if ($fld == 'urlrequested') { $rk->$fld = StatSurfer_Decode($rk->$fld); } if ($fld == 'search') { $rk->$fld = urldecode($rk->$fld); } // $chl.=urlencode(my_substr($rk->$fld,0,50))."|"; // $chd.=($tdwidth*$pc/100)."|"; print ""; echo ""; print "\n"; $red = $red + $deltacolor; $blue = $blue - ($deltacolor / 2); } } print "
" . __('Visits', 'StatSurfer') . "%
" . my_substr($rk->$fld, 0, 50); if (strlen("$rk->fld") >= 50) { print "..."; } print "" . $rk->pageview . "$pc%
"; print "
\n"; // $chl=my_substr($chl,0,strlen($chl)-1); // $chd=my_substr($chd,0,strlen($chd)-1); // print "\n"; print "
\n"; } /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ function iriValueTable_pers_1($fld, $fldtitle, $limit = 0, $param = "", $queryfld = "", $exclude = "") { global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; if ($queryfld == '') { $queryfld = $fld; } print "

$fldtitle

"; print ""; $rks = $wpdb->get_var("SELECT count($param $queryfld) as rks FROM $table_name WHERE 1=1 $exclude;"); if ($rks > 0) { $sql = "SELECT count($param $queryfld) as pageview, $fld FROM $table_name WHERE 1=1 $exclude GROUP BY $fld ORDER BY pageview DESC"; if ($limit > 0) { $sql = $sql . " LIMIT $limit"; } $qry = $wpdb->get_results($sql); $tdwidth = 240; $red = 131; $green = 180; $blue = 216; $deltacolor = round(250 / count($qry), 0); $chdl=""; $chd="t:"; $pc_s = 0; $pc_count = 0; foreach ($qry as $rk) { $pc = round(($rk->pageview * 100 / $rks), 1); if ($fld == 'date') { $rk->$fld = irihdate($rk->$fld); } if ($fld == 'urlrequested') { $rk->$fld = StatSurfer_Decode($rk->$fld); } if ($fld == 'search') { $rk->$fld = urldecode($rk->$fld); } if($pc_count < 8){ $chdl.=urlencode(my_substr($rk->$fld,0,50))."|"; $chd.=($tdwidth*$pc/100).","; $pc_s = $pc_s + $pc; $pc_count++; } print ""; echo ""; print "\n"; $red = $red + $deltacolor; $blue = $blue - ($deltacolor / 2); } } if(get_option(StatSurfer_showcharts)=='checked'){ echo ""; } print "
" . __('Visits', 'StatSurfer') . "%
" . my_substr($rk->$fld, 0, 50); if (strlen("$rk->fld") >= 50) { print "..."; } print "" . $rk->pageview . "$pc%
"; print "
"; if($pc_s < 100){ $chdl .= "Other|"; $chd .= (100-$pc_s)."|"; } $chdl=my_substr($chdl,0,strlen($chl)-1); $chd=my_substr($chd,0,strlen($chd)-1); print "\n"; echo "
\n"; print "
\n"; } /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------*/ function iriDomain($ip) { $host = gethostbyaddr($ip); if (ereg('^([0-9]{1,3}\.){3}[0-9]{1,3}$', $host)) { return ""; } else { return my_substr(strrchr($host, "."), 1); } } function iriGetQueryPairs($url) { $parsed_url = parse_url($url); $tab = parse_url($url); $host = $tab['host']; if (key_exists("query", $tab)) { $query = $tab["query"]; $query = str_replace("&", "&", $query); $query = urldecode($query); $query = str_replace("?", "&", $query); return explode("&", $query); } else { return null; } } function iriGetOS($arg) { $arg = str_replace(" ", "", $arg); $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); if (strpos($arg, $id_os) === false) continue; // riconosciuto return $nome_os; } return ''; } function iriGetBrowser($arg) { $arg = str_replace(" ", "", $arg); $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/browser.dat'); foreach ($lines as $line_num => $browser) { list($nome, $id) = explode("|", $browser); if (strpos($arg, $id) === false) continue; // riconosciuto return $nome; } return ''; } function iriCheckBanIP($arg) { if (file_exists(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/banips.dat')) $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '-custom/banips.dat'); else $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/banips.dat'); if ($lines !== false) { foreach ($lines as $banip) { if (@preg_match('/^' . rtrim($banip, "\r\n") . '$/', $arg)){ return true; } // riconosciuto, da scartare } } return false; } function iriGetSE($referrer = null) { $key = null; $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/searchengines.dat'); foreach ($lines as $line_num => $se) { list($nome, $url, $key) = explode("|", $se); if (strpos($referrer, $url) === false) continue; // trovato se $variables = iriGetQueryPairs($referrer); $i = count($variables); while ($i--) { $tab = explode("=", $variables[$i]); if ($tab[0] == $key) { return($nome . "|" . urlencode($tab[1])); } } } return null; } function iriGetSpider($agent = null) { $agent = str_replace(" ", "", $agent); $key = null; $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, $key) = explode("|", $spider); if (strpos($agent, $key) === false) continue; // trovato return $nome; } return null; } function StatSurfer_lastmonth() { if(isset($_GET['find_statDay'])) $timestamp = mktime(11,0,0,$_GET['find_statMonth'],$_GET['find_statDay'],$_GET['find_statYear']); else $timestamp = current_time('timestamp'); $ta = getdate($timestamp); $year = $ta['year']; $month = $ta['mon']; // go back 1 month; $month = $month - 1; if ($month === 0) { // if this month is Jan // go back a year $year = $year - 1; $month = 12; } // return in format 'YYYYMM' return sprintf($year . '%02d', $month); } function StatSurferGoals() { StatSurferCheckGoals(); print "

Goals

"; print ""; print ""; print ""; print "
Set a new goal
"; //Form ?>
Goal name   Goal value
INSTRUCTION:
- Set the name of the new goal
- Set the value of the goal
- Choose the connections types you want to count
- Choose the type of goal: with the first type you can see if in a certain period of time, you have defined, you have reached a certain number of connections, with the second one, you can set daily goals, the system will tell you the day in which you have reached this goal
Coon. type Visitors Pageviews Spieders Feeds
Goal type Type 1 Type 2
   Start Date
   End Date

"; global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . "StatSurfer_goals"; echo "
"; echo "

Open Goals

"; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE result_g='Y' ORDER BY id_g DESC"); foreach ($qry as $rk){ print ""; print ""; print ""; print ""; print ""; print "
".$rk->name_g."
"; if($rk->start_date_g=="0000-00-00"){ $type = "Goals type: 2"; $time = " in one day"; } else{ $type = "Goals type: 1"; $time = " from " . $rk->start_date_g . " to " . $rk->end_date_g . ""; } print $type . "
"; print "" . $rk->goal_g . " "; $conn_type = $rk->conn_type_g; if($conn_type=="IIII") echo " total visits"; else{ if($conn_type[0]=="I") echo " visitors,"; if($conn_type[1]=="I") echo " pageviews,"; if($conn_type[2]=="I") echo " spiders,"; if($conn_type[3]=="I") echo " feeds,"; } echo $time . "
"; StatSurferPartialGoal($rk->id_g); print "
"; } echo "
"; echo "

Last Closed Goals

"; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE result_g<>'Y' ORDER BY end_date_g DESC LIMIT 0,5"); foreach ($qry as $rk){ print ""; print ""; print ""; print ""; print ""; print "
".$rk->name_g."
"; if($rk->start_date_g=="0000-00-00"){ $type = "Goals type: 2"; $time = " in one day"; } else{ $type = "Goals type: 1"; $time = " from " . $rk->start_date_g . " to " . $rk->end_date_g . ""; } print $type . "
"; print "" . $rk->goal_g . " "; $conn_type = $rk->conn_type_g; if($conn_type=="IIII") echo " total visits"; else{ if($conn_type[0]=="I") echo " visitors,"; if($conn_type[1]=="I") echo " pageviews,"; if($conn_type[2]=="I") echo " spiders,"; if($conn_type[3]=="I") echo " feeds,"; } echo $time . "
"; StatSurferPartialGoal($rk->id_g); print "
"; } echo "See all goals"; echo "
"; echo "
"; } function StatSurferPartialGoal($id_g){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . "StatSurfer_goals"; $table_StatSurfer = $wpdb->prefix . $_STATSURFER['table_name']; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." WHERE id_g='".$id_g."'"); foreach ($qry as $rk){ if($rk->result_g=='Y'){ $pc = ($rk->partial_g*100)/$rk->goal_g; echo "Your partial result is " . $rk->partial_g . " (" . round($pc,2) . "%)"; if($rk->start_date_g!='0000-00-00'){ if($rk->partial_g>$rk->goal_g) echo " You have already reached this goal"; } } else{ $pc = ($rk->partial_g*100)/$rk->goal_g; echo "Result: " . $rk->partial_g . " (" . round($pc,2) . "%)"; if($rk->result_g=='G') echo " You have reached this goal"; if($rk->result_g=='R') echo " You have faild this goal"; if($rk->start_date_g=='0000-00-00') echo " at " . $rk->end_date_g . ""; } } } function StatSurferShowGoals(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . "StatSurfer_goals"; $table_StatSurfer = $wpdb->prefix . $_STATSURFER['table_name']; print "

All goals

"; echo "Return to the goals page"; echo ""; $i=0; $qry = $wpdb->get_results("SELECT* FROM ".$table_name." ORDER BY id_g DESC"); foreach ($qry as $rk){ if($i==0) echo ""; echo ""; $i++; if($i==3){ $i=0; echo ""; } } if($i!=0) echo ""; echo "
"; print ""; print ""; print ""; print ""; print ""; print "
".$rk->name_g."
"; if($rk->start_date_g=="0000-00-00"){ $type = "Goals type: 2"; $time = " in one day"; } else{ $type = "Goals type: 1"; $time = " from " . $rk->start_date_g . " to " . $rk->end_date_g . ""; } print $type . "
"; print "" . $rk->goal_g . " "; $conn_type = $rk->conn_type_g; if($conn_type=="IIII") echo " total visits"; else{ if($conn_type[0]=="I") echo " visitors,"; if($conn_type[1]=="I") echo " pageviews,"; if($conn_type[2]=="I") echo " spiders,"; if($conn_type[3]=="I") echo " feeds,"; } echo $time . "
"; StatSurferPartialGoal($rk->id_g); print "
"; echo "
"; 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 "

Goals

"; print ""; print ""; print ""; print "
Goal insertion
"; if($control==1) echo "Goal correctly inserted"; else echo "ERROR! " . $control_msg . "!"; echo "
"; print "
"; } function StatSurferDelGoals(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . "StatSurfer_goals"; $results = $wpdb->query("DELETE FROM " . $table_name . " WHERE id_g='".$_GET['gid']."'"); StatSurferGoals(); } function StatSurfer_CreateTable() { global $wpdb; global $_STATSURFER; global $wp_db_version; $table_name_statpress = $wpdb->prefix . "statpress"; $qry = $wpdb->get_results("SELECT ip FROM ".$table_name_statpress.""); $ctr=0; foreach ($qry as $rk) { $ctr++; } if($ctr> 1){ update_option('statsurfer_statpress','statpress'); } else{ update_option('statsurfer_statpress','statsurfer'); } $table_name = $wpdb->prefix . "StatSurfer"; $sql_createtable = "CREATE TABLE " . $table_name . " ( id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, date TINYTEXT, time TINYTEXT, ip TINYTEXT, urlrequested TEXT, agent TEXT, referrer TEXT, search TEXT, nation TINYTEXT, os TINYTEXT, browser TINYTEXT, searchengine TINYTEXT, spider TINYTEXT, feed TINYTEXT, user TINYTEXT, timestamp TINYTEXT, threat_score SMALLINT, threat_type SMALLINT, UNIQUE KEY id (id) );"; if ($wp_db_version >= 5540) $page = 'wp-admin/includes/upgrade.php'; else $page = 'wp-admin/upgrade-functions.php'; require_once(ABSPATH . $page); dbDelta($sql_createtable); StatSurfer_CreateTable_Goals(); StatSurfer_CreateTable_Countries(); } function StatSurfer_CreateTable_Countries(){ global $wpdb; global $_STATSURFER; global $wp_db_version; $table_name_c = $wpdb->prefix . "StatSurfer_countries"; $sql_createtable = "CREATE TABLE " . $table_name_c . " ( id_c MEDIUMINT(9) NOT NULL AUTO_INCREMENT, iso3166_c VARCHAR(2), name_c TINYTEXT, conn_c INT(20), UNIQUE KEY id_c (id_c) );"; if ($wp_db_version >= 5540) $page = 'wp-admin/includes/upgrade.php'; else $page = 'wp-admin/upgrade-functions.php'; require_once(ABSPATH . $page); dbDelta($sql_createtable); $qry = $wpdb->get_results("SELECT* FROM ".$table_name_c .""); $control = 1; foreach ($qry as $rk){ $control = 0; } if($control==1){ StatSurfer_CreateTable_Countries_iRow(); } } function StatSurfer_CreateTable_Countries_iRow(){ global $wpdb; global $_STATSURFER; global $wp_db_version; $table_name = $wpdb->prefix . "StatSurfer_countries"; $lines = file(ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/data/countrylist.dat'); foreach($lines as $country_line){ list($iso3166, $name) = explode("|", $country_line); $insert = "INSERT INTO " . $table_name . " (name_c, iso3166_c, conn_c) "; $insert .= "VALUES ('".$name."','".$iso3166."','0')"; $results = $wpdb->query($insert); } update_option('StatSurfer_lastmaptimestamp', 0); //StatSurfer_CreateTable_Countries_fCompiler(); } function StatSurfer_CreateTable_Countries_fCompiler(){ global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; $table_name_country = $wpdb->prefix . "StatSurfer_countries"; if($_GET['StatSurfer_action']!='StatSurfer_CreateTable_Countries_fCompiler'){ $timestamp = current_time('timestamp'); $lStart = 0; $lEnd = 50; $lPage = 1; } else{ $timestamp = $_GET['my_timestamp']; $lPage = $_GET['my_page']; $lEnd = $lPage * 50; $lStart = $lEnd - 50; } $end = 1; $qry_string = "SELECT DISTINCT ip FROM ".$table_name." WHERE timestamp<=".$timestamp." ORDER BY timestamp ASC LIMIT ".$lStart.",50 "; $qry = $wpdb->get_results($qry_string); foreach ($qry as $rk){ $end = 0; $url = "http://api.hostip.info/country.php?ip=" . $rk->ip; $ciso = file_get_contents($url); $cry = $wpdb->get_results("SELECT conn_c FROM ".$table_name_country." WHERE iso3166_c='".$ciso."'"); foreach ($cry as $ck){ $conn_c = $ck->conn_c; $conn_c++; $upy = "UPDATE ".$table_name_country." SET conn_c = '".$conn_c."' WHERE iso3166_c='".$ciso."'"; $wpdb->query($upy); } } if($end == 1){ update_option('StatSurfer_lastmaptimestamp', $timestamp); echo "muore"; } else{ $lPage++; $dir = 'admin.php?page=statsurfer/statsurfer.php&StatSurfer_action='.'StatSurfer_CreateTable_Countries_fCompiler'; $dir .= '&my_timestamp=' . $timestamp; $dir .= '&my_page=' . $lPage; //echo ""; redirect($dir); } } function StatSurfer_CreateTable_Goals(){ global $wpdb; global $_STATSURFER; global $wp_db_version; $table_name_goals = $wpdb->prefix . "StatSurfer_goals"; $sql_createtable = "CREATE TABLE " . $table_name_goals . " ( id_g MEDIUMINT(9) NOT NULL AUTO_INCREMENT, name_g TINYTEXT, conn_type_g TINYTEXT, goal_g INT(20), partial_g INT(20), start_date_g DATE, end_date_g DATE, result_g TINYTEXT, UNIQUE KEY id_g (id_g) );"; if ($wp_db_version >= 5540) $page = 'wp-admin/includes/upgrade.php'; else $page = 'wp-admin/upgrade-functions.php'; require_once(ABSPATH . $page); dbDelta($sql_createtable); } function StatSurfer_is_feed($url) { if (stristr($url,get_bloginfo('comments_atom_url')) != FALSE) { return 'COMMENT ATOM'; } elseif (stristr($url,get_bloginfo('comments_rss2_url')) != FALSE) { return 'COMMENT RSS'; } elseif (stristr($url,get_bloginfo('rdf_url')) != FALSE) { return 'RDF'; } elseif (stristr($url,get_bloginfo('atom_url')) != FALSE) { return 'ATOM'; } elseif (stristr($url,get_bloginfo('rss_url')) != FALSE) { return 'RSS'; } elseif (stristr($url,get_bloginfo('rss2_url')) != FALSE) { return 'RSS2'; } elseif (stristr($url,'wp-feed.php') != FALSE) { return 'RSS2'; } elseif (stristr($url,'/feed') != FALSE) { return 'RSS2'; } return ''; } function StatSurferAgents() { global $wpdb; global $_STATSURFER; $table_name = $wpdb->prefix . $_STATSURFER['table_name']; $query = "SELECT date, MAX(time), ip, COUNT(*) as count, agent"; $query .= " FROM " . $table_name; $query .= " WHERE spider = '' AND browser = ''"; $query .= " GROUP BY date, ip, agent"; $query .= " ORDER BY date DESC"; $result = $wpdb->get_results($query); print "

" . __('Unknown User Agents', 'StatSurfer') . "

"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; foreach ($result as $line) { $col = 0; print ''; foreach ($line as $col_value) { $col++; if ($col == 1) print ''; else if ($col == 3) print ""; else print ''; } print ''; } print '
" . __('Date', 'StatSurfer') . "" . __('Last Time', 'StatSurfer') . "" . __('IP', 'StatSurfer') . "" . __('Count', 'StatSurfer') . "" . __('User Agent', 'StatSurfer') . "
' . irihdate($col_value) . '" . $col_value . "' . $col_value . '
'; } 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 .= "
  • urlrequested : '') . "'>" . StatSurfer_Decode($rk->urlrequested) . "
  • \n"; if (strtolower($showcounts) == 'checked') { $res .= " (" . $rk->totale . ")"; } } return "$res
\n"; } function widget_StatSurfer_init($args) { if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control')) return; // Multifunctional StatSurfer pluging function widget_StatSurfer_control() { $options = get_option('widget_StatSurfer'); if (!is_array($options)) $options = array('title' => 'StatSurfer', 'body' => 'Visits today: %visits%'); if ($_POST['StatSurfer-submit']) { $options['title'] = strip_tags(stripslashes($_POST['StatSurfer-title'])); $options['body'] = stripslashes($_POST['StatSurfer-body']); update_option('widget_StatSurfer', $options); } $title = htmlspecialchars($options['title'], ENT_QUOTES); $body = htmlspecialchars($options['body'], ENT_QUOTES); // the form echo '

'; echo '

' . __('Body:', 'widgets') . '

'; echo '
%totalvisits% %visits% %thistotalvisits% %os% %browser% %ip% %since% %visitorsonline% %usersonline% %toppost% %topbrowser% %topos%
'; } function widget_StatSurfer($args) { extract($args); $options = get_option('widget_StatSurfer'); $title = $options['title']; $body = $options['body']; echo $before_widget; print($before_title . $title . $after_title); print StatSurfer_Vars($body); echo $after_widget; } register_sidebar_widget('StatSurfer', 'widget_StatSurfer'); register_widget_control(array('StatSurfer', 'widgets'), 'widget_StatSurfer_control', 300, 210); // Top posts function widget_StatSurfertopposts_control() { $options = get_option('widget_StatSurfertopposts'); if (!is_array($options)) { $options = array('title' => 'StatSurfer TopPosts', 'howmany' => '5', 'showcounts' => 'checked'); } if ($_POST['StatSurfertopposts-submit']) { $options['title'] = strip_tags(stripslashes($_POST['StatSurfertopposts-title'])); $options['howmany'] = stripslashes($_POST['StatSurfertopposts-howmany']); $options['showcounts'] = stripslashes($_POST['StatSurfertopposts-showcounts']); if ($options['showcounts'] == "1") { $options['showcounts'] = 'checked'; } update_option('widget_StatSurfertopposts', $options); } $title = htmlspecialchars($options['title'], ENT_QUOTES); $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES); $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES); // the form echo '

'; echo '

'; echo '

'; echo ''; } function widget_StatSurfertopposts($args) { extract($args); $options = get_option('widget_StatSurfertopposts'); $title = htmlspecialchars($options['title'], ENT_QUOTES); $howmany = htmlspecialchars($options['howmany'], ENT_QUOTES); $showcounts = htmlspecialchars($options['showcounts'], ENT_QUOTES); echo $before_widget; print($before_title . $title . $after_title); print StatSurfer_TopPosts($howmany, $showcounts); echo $after_widget; } register_sidebar_widget('StatSurfer TopPosts', 'widget_StatSurfertopposts'); register_widget_control(array('StatSurfer TopPosts', 'widgets'), 'widget_StatSurfertopposts_control', 300, 110); } // a custom function for loading localization function StatSurfer_load_textdomain() { //check whether necessary core function exists if ( function_exists('load_plugin_textdomain') ) { //load the plugin textdomain load_plugin_textdomain('StatSurfer', 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/locale'); } } // call the custom function on the init hook add_action('init', 'StatSurfer_load_textdomain'); add_action('admin_menu', 'iri_add_pages'); add_action('plugins_loaded', 'widget_StatSurfer_init'); //add_action('wp_head', 'iriStatAppend'); add_action('send_headers', 'iriStatAppend'); register_activation_hook(__FILE__, 'StatSurfer_CreateTable'); ?>