prefix . "statpress"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { iri_StatPress_CreateTable(); } # add submenu $mincap=get_option('statpress_mincap'); if($mincap == '') { $mincap="level_8"; } // ORIG add_submenu_page('index.php', 'StatPress', 'StatPress', 8, 'statpress', 'iriStatPress'); add_menu_page('StatPress', 'StatPress', $mincap, __FILE__, 'iriStatPress'); add_submenu_page(__FILE__, __('Overview','statpress'), __('Overview','statpress'), $mincap, __FILE__, 'iriStatPress'); add_submenu_page(__FILE__, __('Details','statpress'), __('Details','statpress'), $mincap, __FILE__ . '&statpress_action=details', 'iriStatPress'); add_submenu_page(__FILE__, __('Spy','statpress'), __('Spy','statpress'), $mincap, __FILE__ . '&statpress_action=spy', 'iriStatPress'); add_submenu_page(__FILE__, __('Search','statpress'), __('Search','statpress'), $mincap, __FILE__ . '&statpress_action=search', 'iriStatPress'); add_submenu_page(__FILE__, __('Export','statpress'), __('Export','statpress'), $mincap, __FILE__ . '&statpress_action=export', 'iriStatPress'); add_submenu_page(__FILE__, __('Options','statpress'), __('Options','statpress'), $mincap, __FILE__ . '&statpress_action=options', 'iriStatPress'); add_submenu_page(__FILE__, __('StatPressUpdate','statpress'), __('StatPressUpdate','statpress'), $mincap, __FILE__ . '&statpress_action=up', 'iriStatPress'); add_submenu_page(__FILE__, __('Empty','statpress'), __('Empty','statpress'), $mincap, __FILE__ . '&statpress_action=empty', 'iriStatPress'); // add_submenu_page(__FILE__, __('Support','statpress'), __('Support','statpress'), $mincap, 'http://www.irisco.it/forums/forum.php?id=1'); } function iriStatPress() { ?>

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

"; } else { ?>

"; print ""; ?>
".__('Collect data about logged users, too.','statpress')."
".__('Do not collect spiders visits','statpress')."

capabilities as $cap => $grant) { print ""; } } function iriStatPressExport() { ?>

(csv)

(YYYYMMDD)
(YYYYMMDD)
>
prefix . "statpress"; $filename=get_bloginfo('title' )."-statpress_".$_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(substr($_GET['from'],0,8))))."' AND date<='".(date("Ymd",strtotime(substr($_GET['to'],0,8))))."';"); $del=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.'"'.$rk->search.'"'.$del.'"'.$rk->nation.'"'.$del.'"'.$rk->os.'"'.$del.'"'.$rk->browser.'"'.$del.'"'.$rk->searchengine.'"'.$del.'"'.$rk->spider.'"'.$del.'"'.$rk->feed.'"'."\n"; } die(); } function iriStatPressMain() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; # Tabella OVERVIEW $unique_color="#114477"; $web_color="#3377B6"; $rss_color="#f38f36"; $spider_color="#83b4d8"; $lastmonth = iri_StatPress_lastmonth(); $thismonth = gmdate('Ym', current_time('timestamp')); $yesterday = gmdate('Ymd', current_time('timestamp')-86400); $today = gmdate('Ymd', current_time('timestamp')); $tlm[0]=substr($lastmonth,0,4); $tlm[1]=substr($lastmonth,4,2); print "

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

"; 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 '" . $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 '" . $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 / date("d", current_time('timestamp')) * 30); 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 = '$yesterday' "); print "\n"; #TODAY $qry_t = $wpdb->get_row(" SELECT count(DISTINCT ip) AS visitors FROM $table_name WHERE feed='' AND spider='' AND date = '$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 '" . $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 '" . $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 / date("d", current_time('timestamp')) * 30); 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 = '$yesterday' "); print "\n"; #TODAY $qry_t = $wpdb->get_row(" SELECT count(date) as pageview FROM $table_name WHERE feed='' AND spider='' AND date = '$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 '" . $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 '" . $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 / date("d", current_time('timestamp')) * 30); 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 = '$yesterday' "); print "\n"; #TODAY $qry_t = $wpdb->get_row(" SELECT count(date) as spiders FROM $table_name WHERE feed='' AND spider<>'' AND date = '$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 '" . $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 '" . $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 / date("d", current_time('timestamp')) * 30); 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 = '".$yesterday."' "); print "\n"; $qry_t = $wpdb->get_row(" SELECT count(date) as feeds FROM $table_name WHERE feed<>'' AND spider='' AND date = '$today' "); print "\n"; print "
". __('Total','statpress'). " ". __('Last month','statpress'). "
" . gmdate('M, Y',gmmktime(0,0,0,$tlm[1],1,$tlm[0])) ."
". __('This month','statpress'). "
" . gmdate('M, Y', current_time('timestamp')) ."
Target ". __('This month','statpress'). "
" . gmdate('M, Y', current_time('timestamp')) ."
". __('Yesterday','statpress'). "
" . gmdate('d M, Y', current_time('timestamp')-86400) ."
". __('Today','statpress'). "
" . gmdate('d M, Y', current_time('timestamp')) ."
". __('Visitors','statpress'). "
" . $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','statpress'). "
" . $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
" . $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
".$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 # last "N" days graph NEW $gdays=get_option('statpress_daysinoverviewgraph'); if($gdays == 0) { $gdays=20; } // $start_of_week = get_settings('start_of_week'); $start_of_week = get_option('start_of_week'); print ''; $qry = $wpdb->get_row(" SELECT count(date) as pageview, date FROM $table_name GROUP BY date HAVING date >= '".gmdate('Ymd', current_time('timestamp')-86400*$gdays)."' ORDER BY pageview DESC LIMIT 1 "); $maxxday=$qry->pageview; if($maxxday == 0) { $maxxday = 1; } # Y $gd=(90/$gdays).'%'; for($gg=$gdays-1;$gg>=0;$gg--) { #TOTAL VISITORS $qry_visitors = $wpdb->get_row(" SELECT count(DISTINCT ip) AS total FROM $table_name WHERE feed='' AND spider='' AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."' "); $px_visitors = round($qry_visitors->total*100/$maxxday); #TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!) $qry_pageviews = $wpdb->get_row(" SELECT count(date) as total FROM $table_name WHERE feed='' AND spider='' AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."' "); $px_pageviews = round($qry_pageviews->total*100/$maxxday); #TOTAL SPIDERS $qry_spiders = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed='' AND spider<>'' AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."' "); $px_spiders = round($qry_spiders->total*100/$maxxday); #TOTAL FEEDS $qry_feeds = $wpdb->get_row(" SELECT count(ip) AS total FROM $table_name WHERE feed<>'' AND spider='' AND date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."' "); $px_feeds = round($qry_feeds->total*100/$maxxday); $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors; print '\n"; } print '

".gmdate('d', current_time('timestamp')-86400*$gg) . ' ' . gmdate('M', current_time('timestamp')-86400*$gg) . "
'; print '
'; # END OF OVERVIEW #################################################################################################### $querylimit="LIMIT 10"; # Tabella Last hits print "

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

"; 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','statpress'). "". __('Time','statpress'). "IP". __('Domain','statpress'). "". __('Page','statpress'). "OSBrowserFeed
". irihdate($fivesdraft->date) ."". $fivesdraft->time ."". $fivesdraft->ip ."". $fivesdraft->nation ."". iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested),30) ."". $fivesdraft->os . "". $fivesdraft->browser . "". $fivesdraft->feed . "
"; # Last Search terms print "

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

"; 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','statpress')."".__('Time','statpress')."".__('Terms','statpress')."". __('Engine','statpress'). "". __('Result','statpress'). "
".irihdate($rk->date)."".$rk->time."".$rk->search."".$rk->searchengine."urlrequested."'>". __('page viewed','statpress'). "
"; # Referrer print "

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

"; 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','statpress')."".__('Time','statpress')."".__('URL','statpress')."".__('Result','statpress')."
".irihdate($rk->date)."".$rk->time."".iri_StatPress_Abbrevia($rk->referrer,80)."urlrequested."'>". __('page viewed','statpress'). "
"; # Last Agents print "

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

"; 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','statpress')."".__('Time','statpress')."".__('Agent','statpress')."".__('What','statpress')."
".irihdate($rk->date)."".$rk->time."".$rk->agent." ".$rk->os. " ".$rk->browser." ".$rk->spider."
"; # Last pages print "

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

"; print ""; $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM $table_name WHERE (spider='' AND feed='') ORDER BY id DESC $querylimit"); foreach ($qry as $rk) { print "\n"; } print "
".__('Date','statpress')."".__('Time','statpress')."".__('Page','statpress')."".__('What','statpress')."
".irihdate($rk->date)."".$rk->time."".iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested),60)." ".$rk->os. " ".$rk->browser." ".$rk->spider."
"; # Last Spiders print "

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

"; print ""; $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM $table_name WHERE (spider<>'') ORDER BY id DESC $querylimit"); foreach ($qry as $rk) { print "\n"; } print "
".__('Date','statpress')."".__('Time','statpress')."".__('Spider','statpress')."".__('Agent','statpress')."
".irihdate($rk->date)."".$rk->time."".$rk->spider." ".$rk->agent."
"; print "
"; print " StatPress table size: ".iritablesize($wpdb->prefix . "statpress")."
"; print " StatPress current time: ".current_time('mysql')."
"; print " RSS2 url: ".get_bloginfo('rss2_url').' ('.iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')).")
"; } function iri_StatPress_extractfeedreq($url) { list($null,$q)=explode("?",$url); list($res,$null)=explode("&",$q); return $res; } function iriStatPressDetails() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; $querylimit="LIMIT 10"; # Top days iriValueTable("date","Top days",5); # O.S. iriValueTable("os","O.S.",0,"","","AND feed='' AND spider='' AND os<>''"); # Browser iriValueTable("browser","Browser",0,"","","AND feed='' AND spider='' AND browser<>''"); # Feeds iriValueTable("feed","Feeds",5,"","","AND feed<>''"); # SE iriValueTable("searchengine","Search engines",10,"","","AND searchengine<>''"); # Search terms iriValueTable("search","Top search terms",20,"","","AND search<>''"); # Top referrer iriValueTable("referrer","Top referrer",10,"","","AND referrer<>'' AND referrer NOT LIKE '%".get_bloginfo('url')."%'"); # Countries iriValueTable("nation","Countries (domains)",10,"","","AND nation<>'' AND spider=''"); # Spider iriValueTable("spider","Spiders",10,"","","AND spider<>''"); # Top Pages iriValueTable("urlrequested","Top pages",5,"","urlrequested","AND feed='' and spider=''"); # Top Days - Unique visitors iriValueTable("date","Top Days - Unique visitors",5,"distinct","ip","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */ # Top Days - Pageviews iriValueTable("date","Top Days - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */ # Top IPs - Pageviews iriValueTable("ip","Top IPs - Pageviews",5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */ } function iriStatPressSpy() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; # Spy $today = gmdate('Ymd', current_time('timestamp')); $yesterday = gmdate('Ymd', current_time('timestamp')-86400); print "

".__('Spy','statpress')."

"; $sql="SELECT ip,nation,os,browser,agent FROM $table_name WHERE (spider='' AND feed='') AND (date BETWEEN '$yesterday' AND '$today') GROUP BY ip ORDER BY id DESC LIMIT 20"; $qry = $wpdb->get_results($sql); ?>
"; $qry2=$wpdb->get_results("SELECT * FROM $table_name WHERE ip='".$rk->ip."' AND (date BETWEEN '$yesterday' AND '$today') order by id LIMIT 10"); foreach ($qry2 as $details) { print ""; print ""; print ""; print "\n"; } } ?>
"; print ""; print " ".$rk->ip." "; print "ip."');>".__('more info','statpress')."
"; print "
".$rk->os.", ".$rk->browser; // print "
"; print "
"; if($rk->nation) { print "
".gethostbyaddr($rk->ip).""; } print "
".$rk->agent.""; print "
"; print ""; print "
".irihdate($details->date)." ".$details->time."
urlrequested."' target='_blank'>".iri_StatPress_Decode($details->urlrequested).""; if($details->searchengine != '') { print "
".__('arrived from','statpress')." ".$details->searchengine." ".__('searching','statpress')." ".$details->search.""; } elseif($details->referrer != '' && strpos($details->referrer,get_option('home'))===FALSE) { print "
".__('arrived from','statpress')." ".$details->referrer.""; } print "
prefix . "statpress"; $f['urlrequested']=__('URL Requested','statpress'); $f['agent']=__('Agent','statpress'); $f['referrer']=__('Referrer','statpress'); $f['search']=__('Search terms','statpress'); $f['searchengine']=__('Search engine','statpress'); $f['os']=__('Operative system','statpress'); $f['browser']="Browser"; $f['spider']="Spider"; $f['ip']="IP"; ?>

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

>
>
>
 
name=searchsubmit>

".__('Results','statpress').""; $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','statpress')."
"; if($_GET["where$i"] == 'urlrequested') { print iri_StatPress_Decode($rk[$i-1]); } else { print $rk[$i-1]; } print "
"; print "

sql: $sql
"; } } function iri_StatPress_Abbrevia($s,$c) { $res=""; if(strlen($s)>$c) { $res="..."; } return substr($s,0,$c).$res; } function iri_StatPress_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 iri_StatPress_Decode($out_url) { if($out_url == '') { $out_url=__('Page','statpress').": Home"; } if(substr($out_url,0,4)=="cat=") { $out_url=__('Category','statpress').": ".get_cat_name(substr($out_url,4)); } if(substr($out_url,0,2)=="m=") { $out_url=__('Calendar','statpress').": ".substr($out_url,6,2)."/".substr($out_url,2,4); } if(substr($out_url,0,2)=="s=") { $out_url=__('Search','statpress').": ".substr($out_url,2); } if(substr($out_url,0,2)=="p=") { $post_id_7 = get_post(substr($out_url,2), ARRAY_A); $out_url = $post_id_7['post_title']; } if(substr($out_url,0,8)=="page_id=") { $post_id_7=get_page(substr($out_url,8), ARRAY_A); $out_url = __('Page','statpress').": ".$post_id_7['post_title']; } return $out_url; } function iri_StatPress_URL() { $urlRequested = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '' ); if ( $urlRequested == "" ) { // SEO problem! $urlRequested = (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '' ); } if(substr($urlRequested,0,2) == '/?') { $urlRequested=substr($urlRequested,2); } if($urlRequested == '/') { $urlRequested=''; } return $urlRequested; } # Converte da data us to default format di Wordpress function irihdate($dt = "00000000") { return mysql2date(get_option('date_format'), substr($dt,0,4)."-".substr($dt,4,2)."-".substr($dt,6,2)); } function iritablesize($table) { global $wpdb; $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; $table_name = $wpdb->prefix . "statpress"; 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=450; $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 = iri_StatPress_Decode($rk->$fld); } // $chl.=urlencode(substr($rk->$fld,0,50))."|"; // $chd.=($tdwidth*$pc/100)."|"; print ""; // "; print "\n"; $red=$red+$deltacolor; $blue=$blue-($deltacolor / 2); } } print "
".__('Visits','statpress')."
".substr($rk->$fld,0,50); if(strlen("$rk->fld")>=50) { print "..."; } print "".$rk->pageview."$pc%
$pc%
"; print "
\n"; // $chl=substr($chl,0,strlen($chl)-1); // $chd=substr($chd,0,strlen($chd)-1); // print "\n"; print "
\n"; } function iriDomain($ip) { $host=gethostbyaddr($ip); if (ereg('^([0-9]{1,3}\.){3}[0-9]{1,3}$', $host)) { return ""; } else { return 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"]; 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; return $nome_os; // riconosciuto } 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; return $nome; // riconosciuto } return ''; } function iriCheckBanIP($arg){ $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/banips.dat'); foreach($lines as $line_num => $banip) { if(strpos($arg,rtrim($banip,"\n"))===FALSE) continue; return ''; // riconosciuto, da scartare } return $arg; } 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."|".urldecode($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'); foreach($lines as $line_num => $spider) { list($nome,$key)=explode("|",$spider); if(strpos($agent,$key)===FALSE) continue; # trovato return $nome; } return null; } function iri_StatPress_lastmonth() { $ta = getdate(current_time('timestamp')); $year = $ta['year']; $month = $ta['mon']; --$month; // go back 1 month if( $month === 0 ): // if this month is Jan --$year; // go back a year $month = 12; // last month is Dec endif; // return in format 'YYYYMM' return sprintf( $year.'%02d', $month); } function iri_StatPress_CreateTable() { global $wpdb; global $wp_db_version; $table_name = $wpdb->prefix . "statpress"; $sql_createtable = "CREATE TABLE " . $table_name . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, date text, time text, ip text, urlrequested text, agent text, referrer text, search text, nation text, os text, browser text, searchengine text, spider text, feed text, user text, timestamp text, 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); } function iri_StatPress_is_feed($url) { if (stristr($url,get_bloginfo('rdf_url')) != FALSE) { return 'RDF'; } if (stristr($url,get_bloginfo('rss2_url')) != FALSE) { return 'RSS2'; } if (stristr($url,get_bloginfo('rss_url')) != FALSE) { return 'RSS'; } if (stristr($url,get_bloginfo('atom_url')) != FALSE) { return 'ATOM'; } if (stristr($url,get_bloginfo('comments_rss2_url')) != FALSE) { return 'COMMENT RSS'; } if (stristr($url,get_bloginfo('comments_atom_url')) != FALSE) { return 'COMMENT ATOM'; } if (stristr($url,'wp-feed.php') != FALSE) { return 'RSS2'; } if (stristr($url,'/feed/') != FALSE) { return 'RSS2'; } return ''; } function iriStatAppend() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; global $userdata; global $_STATPRESS; 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) == '') { return ''; } // URL (requested) $urlRequested=iri_StatPress_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('statpress_donotcollectspider')=='checked')) { return ''; } if($spider != '') { $os=''; $browser=''; } else { // Trap feeds $feed=iri_StatPress_is_feed(get_bloginfo('url').$_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('statpress_autodelete') != '') { $t=gmdate("Ymd",strtotime('-'.get_option('statpress_autodelete'))); $results = $wpdb->query( "DELETE FROM " . $table_name . " WHERE date < '" . $t . "'"); } if ((!is_user_logged_in()) OR (get_option('statpress_collectloggeduser')=='checked')) { if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { iri_StatPress_CreateTable(); } $insert = "INSERT INTO " . $table_name . " (date, time, ip, urlrequested, agent, referrer, search,nation,os,browser,searchengine,spider,feed,user,timestamp) " . "VALUES ('$vdate','$vtime','$ipAddress','$urlRequested','".addslashes(strip_tags($userAgent))."','$referrer','" . addslashes(strip_tags($search_phrase))."','".iriDomain($ipAddress) . "','$os','$browser','$searchengine','$spider','$feed','$userdata->user_login','$timestamp')"; $results = $wpdb->query( $insert ); } } function iriStatPressUpdate() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; $wpdb->show_errors(); # update table print "Updating table struct $table_name... "; iri_StatPress_CreateTable(); print "".__('done','statpress')."
"; # Update Feed print "Updating Feeds... "; $wpdb->query("UPDATE $table_name SET feed='';"); # not standard $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%/feed/%';"); $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE urlrequested LIKE '%wp-feed.php%';"); # standard blog info urls $s=iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='COMMENT ATOM' WHERE INSTR(urlrequested,'$s')>0;"); } $s=iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='COMMENT RSS' WHERE INSTR(urlrequested,'$s')>0;"); } $s=iri_StatPress_extractfeedreq(get_bloginfo('atom_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='ATOM' WHERE INSTR(urlrequested,'$s')>0;"); } $s=iri_StatPress_extractfeedreq(get_bloginfo('rdf_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='RDF' WHERE INSTR(urlrequested,'$s')>0;"); } $s=iri_StatPress_extractfeedreq(get_bloginfo('rss_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='RSS' WHERE INSTR(urlrequested,'$s')>0;"); } $s=iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')); if($s != '') { $wpdb->query("UPDATE $table_name SET feed='RSS2' WHERE INSTR(urlrequested,'$s')>0;"); } # elim $wpdb->query("UPDATE $table_name SET feed='Y' WHERE (urlrequested LIKE '%feed=%') or (urlrequested LIKE '%wp-rss%') or (urlrequested LIKE '%wp-rdf%') or (urlrequested LIKE '%wp-commentsrss%') or (urlrequested LIKE '%wp-atom%');"); print "".__('done','statpress')."
"; # Update OS print "Updating OSes... "; $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','statpress')."
"; # Update Browser print "Updating Browsers... "; $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','statpress')."
"; # Update Spider print "Updating Spiders... "; $wpdb->query("UPDATE $table_name SET spider = '';"); $lines = file(ABSPATH.'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/def/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','statpress')."
"; # Update feed to '' print "Updating Feeds... "; $wpdb->query("UPDATE $table_name SET feed = '' WHERE isnull(feed);"); print "done
"; # Update Search engine print "Updating Search engines... "; print "
"; $wpdb->query("UPDATE $table_name SET searchengine = '', search='';"); print "...null-ed!
"; $qry = $wpdb->get_results("SELECT id, referrer FROM $table_name"); print "...select-ed!
"; 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','statpress')."
"; $wpdb->hide_errors(); print "
 

".__('Updated','statpress')."!

"; } function iriStatPressEmpty() { global $wpdb; $table_name = $wpdb->prefix . "statpress"; $wpdb->show_errors(); # empty table print "Emptying table struct $table_name... "; $wpdb->query("TRUNCATE $table_name"); print "".__('done','statpress')."
"; $wpdb->hide_errors(); print "
 

".__('Emptied','statpress')."!

"; } function StatPress_Widget($w='') { } function StatPress_Print($body='') { print iri_StatPress_Vars($body); } function iri_StatPress_Vars($body) { global $wpdb; $table_name = $wpdb->prefix . "statpress"; if(strpos(strtolower($body),"%visits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE date = '".gmdate("Ymd",current_time('timestamp'))."' and spider='' and feed='';"); $body = str_replace("%visits%", $qry[0]->pageview, $body); } if(strpos(strtolower($body),"%totalvisits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='';"); $body = str_replace("%totalvisits%", $qry[0]->pageview, $body); } if(strpos(strtolower($body),"%thistotalvisits%") !== FALSE) { $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='".iri_StatPress_URL()."';"); $body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body); } if(strpos(strtolower($body),"%since%") !== FALSE) { $qry = $wpdb->get_results("SELECT date FROM $table_name ORDER BY date LIMIT 1;"); $body = str_replace("%since%", irihdate($qry[0]->date), $body); } if(strpos(strtolower($body),"%os%") !== FALSE) { $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $os=iriGetOS($userAgent); $body = str_replace("%os%", $os, $body); } if(strpos(strtolower($body),"%browser%") !== FALSE) { $browser=iriGetBrowser($userAgent); $body = str_replace("%browser%", $browser, $body); } if(strpos(strtolower($body),"%ip%") !== FALSE) { $ipAddress = $_SERVER['REMOTE_ADDR']; $body = str_replace("%ip%", $ipAddress, $body); } if(strpos(strtolower($body),"%visitorsonline%") !== FALSE) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 minutes', $to_time); $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as visitors FROM $table_name WHERE spider='' and feed='' AND timestamp BETWEEN $from_time AND $to_time;"); $body = str_replace("%visitorsonline%", $qry[0]->visitors, $body); } if(strpos(strtolower($body),"%usersonline%") !== FALSE) { $to_time = current_time('timestamp'); $from_time = strtotime('-4 minutes', $to_time); $qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as users FROM $table_name WHERE spider='' and feed='' AND user<>'' AND timestamp BETWEEN $from_time AND $to_time;"); $body = str_replace("%usersonline%", $qry[0]->users, $body); } if(strpos(strtolower($body),"%toppost%") !== FALSE) { $qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' AND urlrequested LIKE '%p=%' GROUP BY urlrequested ORDER BY totale DESC LIMIT 1;"); $body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body); } if(strpos(strtolower($body),"%topbrowser%") !== FALSE) { $qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' GROUP BY browser ORDER BY totale DESC LIMIT 1;"); $body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body); } if(strpos(strtolower($body),"%topos%") !== FALSE) { $qry = $wpdb->get_results("SELECT os,count(*) as totale FROM wp_statpress WHERE spider='' AND feed='' GROUP BY os ORDER BY totale DESC LIMIT 1;"); $body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body); } return $body; } function iri_StatPress_TopPosts($limit=5, $showcounts='checked') { global $wpdb; $res="\n\n"; } function widget_statpress_init($args) { if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return; // Multifunctional StatPress pluging function widget_statpress_control() { $options = get_option('widget_statpress'); if ( !is_array($options) ) $options = array('title'=>'StatPress', 'body'=>'Visits today: %visits%'); if ( $_POST['statpress-submit'] ) { $options['title'] = strip_tags(stripslashes($_POST['statpress-title'])); $options['body'] = stripslashes($_POST['statpress-body']); update_option('widget_statpress', $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_statpress($args) { extract($args); $options = get_option('widget_statpress'); $title = $options['title']; $body = $options['body']; echo $before_widget; print($before_title . $title . $after_title); print iri_StatPress_Vars($body); echo $after_widget; } register_sidebar_widget('StatPress', 'widget_statpress'); register_widget_control(array('StatPress','widgets'), 'widget_statpress_control', 300, 210); // Top posts function widget_statpresstopposts_control() { $options = get_option('widget_statpresstopposts'); if ( !is_array($options) ) { $options = array('title'=>'StatPress TopPosts', 'howmany'=>'5', 'showcounts'=>'checked'); } if ( $_POST['statpresstopposts-submit'] ) { $options['title'] = strip_tags(stripslashes($_POST['statpresstopposts-title'])); $options['howmany'] = stripslashes($_POST['statpresstopposts-howmany']); $options['showcounts'] = stripslashes($_POST['statpresstopposts-showcounts']); if($options['showcounts'] == "1") {$options['showcounts']='checked';} update_option('widget_statpresstopposts', $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_statpresstopposts($args) { extract($args); $options = get_option('widget_statpresstopposts'); $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 iri_StatPress_TopPosts($howmany,$showcounts); echo $after_widget; } register_sidebar_widget('StatPress TopPosts', 'widget_statpresstopposts'); register_widget_control(array('StatPress TopPosts','widgets'), 'widget_statpresstopposts_control', 300, 110); } load_plugin_textdomain('statpress', 'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/locale'); add_action('admin_menu', 'iri_add_pages'); add_action('plugins_loaded', 'widget_statpress_init'); add_action('send_headers', 'iriStatAppend'); //add_action('wp_head', 'iriStatAppend'); register_activation_hook(__FILE__,'iri_StatPress_CreateTable'); ?>