The IP in banip.dat will
be banned from StatPressCN's stat, if tailed with evil and enable
the checkbox below(bottom-middle, current page), the IP will not be permitted to visit the blog forever.
If want to modify banip.dat, make sure you known what will happens then.
".__("Saved","statpresscn").".";
$content = trim($_POST["ipdat"]);//去掉文尾可能存在的空格和空行
$banipsfilename = $path."/wp-content/plugins/statpresscn/def/banips.dat";
if (is_writable($banipsfilename)) {
$handle = fopen ($banipsfilename,"w"); //打开文件指针,创建文件
if (!fwrite ($handle,$content)) { //将信息写入文件
die ("Error ocoured when creating or writing to the file ".$banipsfilename.".");
}
fclose ($handle); //关闭指针
print "Rules have been written to the file $banipsfilename .";
}
//如果设定同步更新.htaccess则执行
if (strlen($_POST['upgradehtaccess']) > 0) {
$filename = $path."/.htaccess";
$lines = file($filename);
$lineshold = Array();
//识别出非ip规则的内容并保留
foreach ($lines as $line_num => $line) {
if (!preg_match("@(Order Deny,Allow|Deny from|#BEGIN ip ban by StatPressCN|#END ip ban by StatPressCN)@i",$line)) {
array_push($lineshold,$line);
}
}//写入ip规则
array_push($lineshold,"#BEGIN ip ban by StatPressCN\n");
array_push($lineshold,"Order Deny,Allow\n");
$badips = heart5_get_eviliplist();//获取最新的恶意ip数据表,因为banips.dat文件已更新,所以需要重新获取
while (list($key,$val) = each($badips)) {
array_push($lineshold,'Deny from '.$key."\n");
}
array_push($lineshold,"#END ip ban by StatPressCN\n");
reset($lineshold);//数组指针归位
$content = '';
while (list($key, $val) = each($lineshold)) {
$content .= $val;
}
$handle = fopen ($filename,"w"); //打开文件指针,创建文件
if (!fwrite ($handle,$content)) { //将信息写入文件
die ("Error occured when creating or writing to the file ".$filename."!");
}
fclose ($handle); //关闭指针
print "The rules have been written to $filename .";
}
}
$badips = heart5_get_eviliplist();
?>
$line) {
if (preg_match("@Deny\s+from\s+(\S+)@i",$line,$matches)) {
if (preg_match("@^\d{1,3}\.\d{1,3}\.\d{1,3}\.(\d{1,3})?$@",trim($matches[1]))) {
$badips[trim($matches[1])] ="<.htaccess>";
}
}
}
}
$banipsfilename = $path."/wp-content/plugins/statpresscn/def/banips.dat";
if (is_readable($banipsfilename)) {
$ips = file($banipsfilename);
$content = "";
foreach ($ips as $ip) {
if (preg_match("@^(\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:\d{1,3})?)(\s+evil)?$@i",trim($ip),$matches)) {
if(strlen($matches[2]) > 0) {
$badips[$matches[1]] .= "";
}
$content .= trim($ip)."\n";
}
}
if(is_writable($banipsfilename)) {
$handle = fopen ($banipsfilename,"w"); //打开文件指针,创建文件
if (!fwrite ($handle,trim($content))) { //将信息写入文件
die ("Error ocoured when creating or writing to the file ".$banipsfilename.".");
}
fclose ($handle); //关闭指针
}
}
return $badips;
}
//begin spider
function iriStatPressSpider() {
?>
Saved.";
$content = trim($_POST["spiderdat"])."\n";//去掉文尾可能存在的空格和空行
$spiderlistarray = Array();
if (preg_match_all("@(.*)\n@",$content,$matches,PREG_SET_ORDER)) {
while(list($i,) = each($matches)) {
$entry = trim($matches[$i][0]);
if (preg_match("@^(.*\|){2}$@",$entry)) {
array_push($spiderlistarray,$entry);
}
}
}
$spiderlistarray = array_unique($spiderlistarray);
sort($spiderlistarray);
reset($spiderlistarray);
$content = '';
foreach ($spiderlistarray as $key=>$val) {
$content .= $val."\n";
}
$content = trim($content);
if (is_writable($spiderfilename)) {
$handle = fopen ($spiderfilename,"w"); //打开文件指针,创建文件
if (!fwrite ($handle,$content)) { //将信息写入文件
die ("Error ocoured when creating or writing to the file ".$spiderfilename.".");
}
fclose ($handle); //关闭指针
print "Rules have been written to the file $spiderfilename .";
}
}
?>
Saved.";
$content = trim($_POST["defipdat"])."\n";//去掉文尾可能存在的空格和空行
$defiplistarray = Array();
if (preg_match_all("@(.*)\n@",$content,$matches,PREG_SET_ORDER)) {
while(list($i,) = each($matches)) {
$entry = trim($matches[$i][0]);
if (preg_match("@^(.*\|){2}$@",$entry)) {
array_push($defiplistarray,$entry);
echo $entry;
}
}
}
$defiplistarray = array_unique($defiplistarray);
sort($defiplistarray);
reset($defiplistarray);
$content = '';
foreach ($defiplistarray as $key=>$val) {
$content .= $val."\n";
}
$content = trim($content);
if (is_writable($defipfilename)) {
$handle = fopen ($defipfilename,"w"); //打开文件指针,创建文件
if (!fwrite ($handle,$content)) { //将信息写入文件
die ("Error ocoured when creating or writing to the file ".$defipfilename.".");
}
fclose ($handle); //关闭指针
print "Rules have been written to the file $defipfilename .";
}
}
?>
prefix . "statpress";
$wpdb->show_errors();
?>
If some error occurred when using StatPressCN, you may send the info below to baiyefeng@gmail.com,
or comment at
StatPressCN Info for debug. All suggestion is gladly appreciated!
Name
Value
StatPressCN Version
blog name
blogsite url
blog charset
blog timezone
rss language
permalink
db version
php version
php timezone
php datetime
';
$timestamp = current_time('timestamp');
$thistime = gmdate('Ymd H:i:s',$timestamp);
$vtoday = gmdate("Ymd",$timestamp);
$vthismonth = gmdate("Ym",$timestamp);
$vthisyear = gmdate("Y",$timestamp);
$vyesterday = gmdate("Ymd",strtotime("-1 day",$timestamp));
$vlastmonth = gmdate("Ym",strtotime("-1 month",$timestamp));
$vlast8month = gmdate("Ym",strtotime("-8 month",$timestamp));
$vlastyear = gmdate("Y",strtotime("-1 year",$timestamp));
echo "now is ".$thistime.", today is ".$vtoday.', this month is '.$vthismonth.', this year is '.$vthisyear.', yesterday is
'.$vyesterday.', last month is '.$vlastmonth.', 8 month ago is '.$vlast8month.', last year is '.$vlastyear;
?>
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(DISTINCT ip) AS visitors
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$today'$normallimit
");
print "
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(date) as pageview
FROM $table_name
WHERE feed=''
AND spider=''
AND date = '$today'$normallimit
");
print "
\n";
#TODAY
$qry_t = $wpdb->get_row("
SELECT count(date) as spiders
FROM $table_name
WHERE feed=''
AND spider!=''
AND date = '$today'$normallimit
");
print "
\n";
$qry_t = $wpdb->get_row("
SELECT count(date) as feeds
FROM $table_name
WHERE feed!=''
AND date = '$today'$normallimit
");
print "
".$qry_t->feeds."
\n";
print "
\n\n";
################################################################################################
################################################################################################
# THE GRAPHS
# last "N" days graph NEW
$gdays=get_option('statpress_daysinoverviewgraph',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)."'
".$normallimit);
$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)."'
".$normallimit);
$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 date = '".gmdate('Ymd', current_time('timestamp')-86400*$gg)."'
");
$px_feeds = round($qry_feeds->total*100/$maxxday);
$px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
print '
';
# END OF OVERVIEW
####################################################################################################
function heart5_short_date($datestr) {
return substr($datestr,4,2)."-".substr($datestr,6,2);
}
$querylimit="LIMIT 15";
# Tabella Last hits
print "
". __('Last hits','statpresscn'). "
". __('Time','statpresscn'). "
".__("IP|Visitor","statpresscn")."
".__('From','statpresscn'). "
". __('Page','statpresscn'). "
". __('OS','statpresscn'). "
". __('Browser','statpresscn'). "
";
print "";
#通过os和feed字段判断是否显示最后浏览信息,。os<>'' OR feed<>''
if (strlen(get_option('statpress_ipsearchtools')) == 0) {
update_option('statpress_ipsearchtools','http://en.utrace.de/?query=');
}
$ipsearchtools = get_option('statpress_ipsearchtools');
$fivesdrafts = $wpdb->get_results("SELECT * FROM $table_name WHERE (feed='')$normallimit order by id DESC $querylimit");
foreach ($fivesdrafts as $fivesdraft) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,ip,referrer,urlrequested,search,searchengine,user FROM $table_name WHERE search!=''$normallimit ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
#增加对feed的判断,应该为空
$qry = $wpdb->get_results("SELECT date,time,ip,referrer,urlrequested,user FROM $table_name WHERE ((referrer NOT LIKE '".get_option('home')."%') AND (referrer !='') AND (searchengine='') AND (feed=''))$normallimit ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT * FROM $table_name WHERE (feed!='' and spider ='' and os !='' and browser!='') ORDER BY id DESC $querylimit");
$qry = $wpdb->get_results("SELECT * FROM $table_name WHERE feed!='' ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
print "";
$qry = $wpdb->get_results("SELECT date,time,ip,nation,agent,os,browser,spider,user FROM $table_name WHERE (agent !='' and feed='') ORDER BY id DESC $querylimit");
foreach ($qry as $rk) {
print "
";
heart5_print_spc_footer();
}
function iri_StatPress_extractfeedreq($url) {//http://localhost/feed/atom
$res = str_replace(get_bloginfo('url'),'',$url);
$res = str_replace("/?","",$res);
return $res;
}
function iriStatPressDetails() {
# Top Pages
iriValueTable("urlrequested",__("Top pages","statpresscn"),10,"","urlrequested","AND feed='' and spider=''");
# Search terms
iriValueTable("search",__("Top search terms","statpresscn"),15,"","","AND search!=''");
# Top referrer,不统计搜索引擎
iriValueTable("referrer",__("Top referrer","statpresscn"),10,"","","AND referrer!='' AND referrer NOT LIKE '%".get_bloginfo('url')."%' AND searchengine=''");
# Feeds
iriValueTable("feed",__("Feeds","statpresscn"),5,"","","AND feed!=''");
# Spider
iriValueTable("spider",__("Spiders","statpresscn"),5,"","","AND spider!=''");
# SE
iriValueTable("searchengine",__("Search engine","statpresscn"),10,"","","AND searchengine!=''");
# Browser
iriValueTable("browser",__("Browser","statpresscn"),10,"","","AND feed='' AND spider='' AND browser!=''");
# O.S.
iriValueTable("os",__("OS","statpresscn"),10,"","","AND feed='' AND spider='' AND os!=''");
# Countries
iriValueTable("nation",__("Countries (city)","statpresscn"),15,"","","AND nation!='' AND spider=''");
# Top days
iriValueTable("date",__("Top days","statpresscn"),10);
# Top Days - Unique visitors
iriValueTable("date",__("Top Days - Unique visitors","statpresscn"),5,"distinct","ip","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
# Top Days - Pageviews
iriValueTable("date",__("Top Days - Pageviews","statpresscn"),5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
# Top IPs - Pageviews
iriValueTable("ip",__("Top IPs - Pageviews","statpresscn"),5,"","urlrequested","AND feed='' and spider=''"); /* Maddler 04112007: required patching iriValueTable */
heart5_print_spc_footer();
}
function iriStatPressSpy($num = 20) {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
# Spy
print "
".__('Spy','statpresscn')."
";
if(!is_numeric($num) && is_numeric(get_option("statpress_spynumber"))) {
$num = get_option("statpress_spynumber");
}else if(!is_numeric($num) && !is_numeric(get_option("statpress_spynumber"))) {
$num = 20;
}
// echo "The number limit is $num";
$sql="SELECT max(id) as id,ip,nation,os,browser,agent,user FROM $table_name WHERE (date >= date_sub(curdate(),interval 1 day)) GROUP BY ip ORDER BY id DESC LIMIT $num";
$qry = $wpdb->get_results($sql);
?>
";
$qry2=$wpdb->get_results("SELECT * FROM $table_name WHERE (date >= date_sub(curdate(),interval 1 day)) and ip='$rk->ip' order by id desc LIMIT 5");
foreach ($qry2 as $details) {
print "
prefix . "statpress";
$normallimit = " and (statuscode !='404' or statuscode is null) ";
# Friends
print "
".__('Friends','statpresscn')."
";
if(!is_numeric($num) && is_numeric(get_option("statpress_friendsnumber"))) {
$num = get_option("statpress_friendsnumber");
}else if(!is_numeric($num) && !is_numeric(get_option("statpress_friendsnumber"))) {
$num = 10;
}
//$sql="SELECT max(id) as id,user,nation,ip,agent FROM $table_name WHERE user<>'' GROUP BY user ORDER BY id DESC LIMIT $num";
$sql = "select max($table_name.id) as maxid,$table_name.*,$wpdb->comments.*
from $wpdb->comments,$wpdb->users,$table_name
where ($table_name.user!='') and
(($table_name.user = $wpdb->comments.comment_author and $wpdb->comments.comment_approved=1)
or ($table_name.user = $wpdb->users.user_login))$normallimit
group by user order by maxid desc limit $num";
$qry = $wpdb->get_results($sql);
?>
get_var("select count(comment_author) from $wpdb->comments where comment_author = '$rk->user' and comment_approved<>1")>0){
// continue;
// }
print "
";
$size = 24;
$email = $wpdb->get_var("select user_email from $wpdb->users where user_login = '$rk->user'");
if(strlen($email)==0) {
$email = $wpdb->get_var("select comment_author_email from $wpdb->comments where comment_author = '$rk->user'");
}
if (function_exists('get_avatar')) {
echo get_avatar($email,$size);
} else {
//alternate gravatar code for < 2.5
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=" .
md5($email) . "&size=" . $size;
echo "";
}
print " $rk->user ";
print " ".__("has left","statpresscn")." ";
$commentleft = $wpdb->get_var("select count(comment_author) from $wpdb->comments where comment_author = '$rk->user'");
print $commentleft." ".($commentleft>1?__("comments","statpresscn"):__("comment","statpresscn"));
if($commentleft > 0) {
print ", ".__("and the latest is","statpresscn")." \"";
$latestcomment = $wpdb->get_row("select * from $wpdb->comments where comment_author = '$rk->user' order by comment_id desc limit 1");
print $latestcomment->comment_content."\" ".__("at","statpresscn")." ".$latestcomment->comment_date;
}
print "; ".__("has visited","statpresscn")." ";
$pagesvisited = $wpdb->get_var("select count(user) from $table_name where user='$rk->user'");
print $pagesvisited." ".($pagesvisited>1?__("pages","statpresscn"):__("page","statpresscn")).", ".__("and the latest","statpresscn")." ".($pagesvisited>1?__("are at below","statpresscn"):__("is at below","statpresscn")).". ";
print "user."');>".__('more info','statpresscn')."";
print "
";
$qry2=$wpdb->get_results("SELECT * FROM $table_name WHERE user='".$rk->user."'$normallimit order by id desc LIMIT 10");
foreach ($qry2 as $details) {
print "
//return sprintf("%d",$hot)." ".$totalvisits." ".$thistotalvisits." ".$qryall[0]->urlrequested;
return $str;//." ".$totalvisits." ".$thistotalvisits." ".$qryall[0]->urlrequested;
}
/* ThisVisits,当前页面访问次数 */
function iri_StatPress_ThisVisits() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='".iri_StatPress_URL()."';");
$thistotalvisits = $qry[0]->pageview;
if($thistotalvisits <= 0) {
$thistotalvisits = 1;
}
return $thistotalvisits;
}
function StatPress_Widget($w='') {
}
function StatPress_Print($body='') {
print iri_StatPress_Vars($body);
}
//widget支持,可以在页面上输出统计信息,以widget的形式。
function iri_StatPress_Vars($body) {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$normallimit = " and (statuscode!='404' or statuscode is null)";
$today = gmdate('Ymd', current_time('timestamp'));
$yesterday = gmdate('Ymd', current_time('timestamp')-86400);
//今天来访者数量
if(stripos($body,"%visits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE date = $today and spider='' and feed=''$normallimit;");
$body = str_replace("%visits%", $qry[0]->pageview, $body);
}
//昨天来访者数量
if(stripos($body,"%yesterdayvisits%") !== FALSE) {
$body = str_replace("%yesterdayvisits%", get_option("statpress_archive_yesterday_visitors"), $body);
}
//来访者数量总计
if(stripos($body,"%totalvisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(DISTINCT(ip)) as pageview FROM $table_name WHERE spider='' and feed=''$normallimit;");
$body = str_replace("%totalvisits%", $qry[0]->pageview, $body);
}
//今天页面访问数量
if(stripos($body,"%pagevisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $table_name WHERE spider='' and feed='' and date=$today$normallimit;");
$body = str_replace("%pagevisits%", $qry[0]->pageview, $body);
}
//昨天页面访问数量总计
if(stripos($body,"%yesterdaypagevisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $table_name WHERE spider='' and feed='' and date = $yesterday$normallimit;");
$body = str_replace("%yesterdaypagevisits%", get_option("statpress_archive_yesterday_pageviews"), $body);
}
//页面访问数量总计
if(stripos($body,"%totalpagevisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $table_name WHERE spider='' and feed=''$normallimit;");
$body = str_replace("%totalpagevisits%", $qry[0]->pageview, $body);
}
//当前页面被访问次数
if(stripos($body,"%thistotalvisits%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $table_name WHERE spider='' and feed='' AND urlrequested='".iri_StatPress_URL()."'$normallimit;");
$body = str_replace("%thistotalvisits%", $qry[0]->pageview, $body);
}
//统计起始日期
if(stripos($body,"%since%") !== FALSE) {
$body = str_replace("%since%", get_option("statpress_date_first_sets"), $body);
}
//操作系统(当前访问者)
if(stripos($body,"%os%") !== FALSE) {
$userAgent = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
$os=iriGetOS($userAgent);
$body = str_replace("%os%", $os, $body);
}
//浏览器(当前访问者)
if(stripos($body,"%browser%") !== FALSE) {
$browser=iriGetBrowser($userAgent);
$body = str_replace("%browser%", $browser, $body);
}
//IP地址(当前访问者)
if(stripos($body,"%ip%") !== FALSE) {
$ipAddress = heart5_getrealip();
$body = str_replace("%ip%", $ipAddress, $body);
}
//FROM何地(当前访问者)
if(stripos($body,"%comefrom%") !== FALSE) {
$comeFrom = iriDomain(heart5_getrealip());
$body = str_replace("%comefrom%", $comeFrom, $body);
}
//%pagesyouvisited%
//if(stripos($body,"%pagesyouvisited%") !== FALSE) {
// $pagesyouvisited = $_SESSION['views'];
// $body = str_replace("%pagesyouvisited%", $pagesyouvisited, $body);
//}
//最近一段时间(10分钟内)的访问者数量,类似于在线人数
if(stripos($body,"%visitorsonline%") !== FALSE) {
$to_time = current_time('timestamp');
$from_time = strtotime('-10 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$normallimit;");
$body = str_replace("%visitorsonline%", $qry[0]->visitors, $body);
}
//最近一段时间(10分钟内)的用户数量,这里用户指的登记在册的内容贡献者或订阅者
if(stripos($body,"%usersonline%") !== FALSE) {
$to_time = current_time('timestamp');
$from_time = strtotime('-10 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$normallimit;");
$body = str_replace("%usersonline%", $qry[0]->users, $body);
}
//访问最多的帖子
if(stripos($body,"%toppost%") !== FALSE) {
$qry = $wpdb->get_results("SELECT urlrequested,count(*) as totale FROM $table_name WHERE spider='' AND feed='' and pvalue !='' and pvalue !=0$normallimit GROUP BY pvalue ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%toppost%", iri_StatPress_Decode($qry[0]->urlrequested), $body);
}
//使用最多的浏览器
if(stripos($body,"%topbrowser%") !== FALSE) {
$qry = $wpdb->get_results("SELECT browser,count(*) as totale FROM $table_name WHERE spider='' AND feed=''$normallimit GROUP BY browser ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topbrowser%", iri_StatPress_Decode($qry[0]->browser), $body);
}
//使用最多的操作系统
if(stripos($body,"%topos%") !== FALSE) {
$qry = $wpdb->get_results("SELECT os,count(*) as totale FROM $table_name WHERE spider='' AND feed=''$normallimit GROUP BY os ORDER BY totale DESC LIMIT 1;");
$body = str_replace("%topos%", iri_StatPress_Decode($qry[0]->os), $body);
}
//订阅数
if(stripos($body,"%feeds%") !== FALSE) {
$body = str_replace("%feeds%", iri_StatPress_FeedCount(), $body);
}
//blog文章总数,add by 蚊子
if(stripos($body,"%blogtotalpost%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(ID) as pageview FROM $wpdb->posts WHERE post_status = 'publish' and post_type = 'post';");
$body = str_replace("%blogtotalpost%", $qry[0]->pageview, $body);
}
//blog页面总数
if(stripos($body,"%blogtotalpage%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(ID) as pageview FROM $wpdb->posts WHERE post_status = 'publish' and post_type = 'page';");
$body = str_replace("%blogtotalpage%", $qry[0]->pageview, $body);
}
//留言者总数
if(stripos($body,"%blogtotalcommentor%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(distinct(comment_author)) as pageview FROM $wpdb->comments WHERE comment_approved = '1';");
$body = str_replace("%blogtotalcommentor%", $qry[0]->pageview, $body);
}
//留言总数
if(stripos($body,"%blogtotalcomment%") !== FALSE) {
$qry = $wpdb->get_results("SELECT count(*) as pageview FROM $wpdb->comments WHERE comment_approved = '1';");
$body = str_replace("%blogtotalcomment%", $qry[0]->pageview, $body);
}
return $body;
}
/* 最高访问量的五个帖子 */
function iri_StatPress_TopPosts($limit=5, $long='', $showcounts='checked') {
global $wpdb;
$res="\n
\n";
$condate = '';
if ($long !='') {
if(strtotime($long)) {
$tmpdate = gmdate("Ymd",strtotime("-".$long,current_time('timestamp')));
$condate = " and date >= '$tmpdate'";
}
}
$table_name = $wpdb->prefix . "statpress";
$sqlstr = "SELECT urlrequested,pvalue,count(*) as totale FROM $table_name WHERE spider='' AND feed='' and pvalue !='' $condate GROUP BY pvalue ORDER BY totale DESC LIMIT $limit;";
//echo $sqlstr;
$qry = $wpdb->get_results($sqlstr);
foreach ($qry as $rk) {
$post = get_post($rk->pvalue);
$post_title = $post->post_title;
$res.="
".$content;
return $content;
}
function iri_update_staturl_based_new_permalink_structure() {
print "
";
$permalink = get_option('permalink_structure');
echo "StatPressCN info:Permalink structure has been set to ";
if (strlen($permalink) > 0) {
echo $permalink;
}else {
echo "default";
}
echo ".";
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$wpdb->show_errors();
# Update UrlRequested
print "".__("Updating URLes","statpresscn")."... ";
// $qry = $wpdb->get_results("SELECT id, ptype, pvalue, urlrequested FROM $table_name
//WHERE urlrequested like '%/'");
// foreach ($qry as $rk) {
// $q="UPDATE $table_name SET urlrequested = \"".substr($rk->urlrequested,0,strlen($rk->urlrequested)-1)."\" WHERE id=".$rk->id;
// $wpdb->query($q);
// }
if (strlen($permalink) > 0) {
$qry = $wpdb->get_results("SELECT id, ptype, pvalue, urlrequested FROM $table_name
WHERE (urlrequested is not null) and (urlrequested != '')");
print "...".count($qry).__("select-ed","statpresscn")."; ";
$d2p = 0;
$p2d = 0;
foreach ($qry as $rk) {
if(strlen($rk->ptype)>0) {
if(($rk->ptype == "post" or $rk->ptype == "page") and $rk->pvalue != '') {
$url = str_replace(get_bloginfo("url"),"",get_permalink($rk->pvalue));
// echo $url." ".$rk->urlrequested." ".$rk->pvalue." ";
if(preg_match("@(/feed(?:/)|/trackback(?:/))$@i",$rk->urlrequested,$matches)) {
$url .= $matches[1];
}
$q="UPDATE $table_name SET urlrequested = \"".$url."\" WHERE id=".$rk->id;
$wpdb->query($q);
$d2p++;
}
}else {
$p = iri_StatPressCN_Url2P($rk->urlrequested);
if($p != false) {
$q = "UPDATE $table_name SET ptype = \"".$p[0]."\",pvalue = \"".$p[1]."\" WHERE id=".$rk->id;
$wpdb->query($q);
$p2d++;
}
}
}
print ($d2p+$p2d)." ".__("sets are updated","statpresscn").". Permalink to default is ".$p2d.", and Default to permalink is ".$d2p;
}else {
$d2p = 0;
$qry = $wpdb->get_results("SELECT id, ptype, pvalue, urlrequested FROM $table_name WHERE pvalue !''");
foreach($qry as $rk) {
if(($rk->urlrequested != "p=".$rk->pvalue) and ($rk->urlrequested != "page_id=".$rk->pvalue)) {
$url = ($rk->ptype == "post")?"p=".$rk->pvalue:"page_id=".$rk->pvalue;
// if(preg_match("@(/feed(?:/)$@i",$rk->urlrequested) > 0){
// $url = "feed=rss2&".$url;
// }
$q="UPDATE $table_name SET urlrequested = \"".$url."\" WHERE id=".$rk->id;
$wpdb->query($q);
$d2p++;
}
}
print __("The permalink structure is set to default","statpresscn").", ".$d2p." ".__("sets are updated","statpresscn");
}
print " ".__('done','statpresscn')." ";
print "
";
}
function iri_update_manuplate_sets_with_spider() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$wpdb->show_errors();
print "".__("Delete sets that have spider if needed","statpresscn").":";
if(!(get_option('statpress_collectspider')=='checked')) {
$setcount = $wpdb->query("delete from $table_name where spider != '';");
heart5_delete_sets_recorded_then_updatearchive_optimize($setcount,__("spider not allow to record","statpresscn"));
print $setcount." sets are deleted. ";
}
print "".__('done','statpresscn')." ";
}
function iri_update_manuplate_sets_autodelete() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$wpdb->show_errors();
$results = $wpdb->get_var( "select count(*) FROM " . $table_name);
//如果statpress_autodelete参数尚未设定或不是数字(有效),则重新初始化
if(get_option('statpress_autodelete')==false||!is_numeric(get_option('statpress_autodelete'))) {
$factor = round(1024*1024/231);
if($results <= 5*$factor){
update_option('statpress_autodelete', 5*$factor);
}else if($results <= 10*$factor){
update_option('statpress_autodelete', 10*$factor);
}else if($results <= 15*$factor){
update_option('statpress_autodelete', 15*$factor);
}else if($results <= 20*$factor){
update_option('statpress_autodelete', 20*$factor);
}else if($results <= 30*$factor){
update_option('statpress_autodelete', 30*$factor);
}else{
update_option('statpress_autodelete', $results+1000);
}
}
//如果实际记录超出了限定值,做删除操作且记录删除数量
if($results > get_option('statpress_autodelete')) {
//确定每次删除的记录数量,最多是最近三天的来访数量
$timestamp = current_time('timestamp');
$threedaysago = gmdate("Ymd",strtotime('-3 days',$timestamp));
$stepnums = $wpdb->get_var( "select count(*) FROM " . $table_name . " where date > '".$threedaysago."'");
if($stepnums > 1000)
$stepnums = 1000;
if(($results - get_option('statpress_autodelete'))>$stepnums){
$delneeded = $results - get_option('statpress_autodelete') + $stepnums;
}else{
$delneeded = $stepnums;
}
//执行删除操作
$delnums = $wpdb->query( "DELETE FROM " . $table_name . " order by id limit $delneeded");
//记录本次删除动作
heart5_delete_sets_recorded_then_updatearchive_optimize($delnums
,__("table size limited",'statpresscn')
.":".get_option('statpress_autodelete')
.":".$results
.":".$stepnums);
}
}
if(get_option('statpress_showrelated') != "") {
add_filter('the_content', 'append_related_to_post');
}
function heart5_delete_sets_recorded_then_updatearchive_optimize($num,$reason){
if($num == 0){
return;
}
global $wpdb;
$timestamp = current_time('timestamp');
$vdate = gmdate("Ymd",$timestamp);
$vtime = gmdate("H:i:s",$timestamp);
$deleterec_array =get_option('statpress_delete_records',Array());
array_push($deleterec_array,Array($vdate." ".$vtime,$num,$reason));
update_option('statpress_delete_records', $deleterec_array);
//做了删除记录的操作,需要先删除归档数据,然后再重新统计归档数据
$wpdb->query( "delete from $wpdb->options where option_name like 'statpress_archive_%'");
heart5_archive_datasets();
heart5_optimize_table();
}
function heart5_dashboard_4_spc() {
$options = get_option('widget_statpress');
$title = $options['title'];
$body = $options['body'];
$body = preg_replace("@%thistotalvisits%@","".__("as many as you can","statpresscn")."(^_^)",$body);
print("
".$title."
");
echo iri_StatPress_Vars($body);
if(get_option('statpress_showspyonwidget') != "") {
echo iriStatPressSpy(8);
}
}
if(get_option('statpress_showhotdepth') != "") {
add_filter('the_content', 'add_hotdepth_to_post');
}
function heart5_del_all_options() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
if(strlen(get_option("statpress_delete_table_when_deactivating"))>0) {
$wpdb->query("DROP TABLE IF EXISTS $table_name");
}
if(strlen(get_option("statpress_delete_options_when_deactivating"))>0) {
$wpdb->query("delete from $wpdb->options where option_name like 'statpress_%'");
}
}
function heart5_notices() {
print "hello, heart5!";
}
function heart5_print_spc_footer() {
global $wpdb;
print " ". __('StatPressCN table size','statpresscn'). ": ".iritablesize($wpdb->prefix . "statpress").";";
// print " ". __('StatPressCN current time','statpresscn'). ": ".current_time('mysql').";";
print " ". __('Query count','statpresscn'). ": ".get_num_queries().";";
// print " ". __('RSS2 url','statpresscn'). ": ".get_bloginfo('rss2_url').' ('.iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')).") ";
// print " stat since ".get_option("statpress_date_since_stat")
// .", and first set is ".get_option("statpress_date_first_sets")
// .", and last year's visitors is ".get_option("statpress_archive_lastyear_visitors")
// .", and today recorded is ".get_option("statpress_archive_today")
// ;
}
function heart5_archive_datasets() {
global $wpdb;
$table_name = $wpdb->prefix . "statpress";
$timestamp = current_time('timestamp');
$vtoday = gmdate("Ymd",$timestamp);
$vthismonth = gmdate("Ym",$timestamp);
$vthisyear = gmdate("Y",$timestamp);
$vyesterday = gmdate("Ymd",strtotime("-1 day",$timestamp));
$vlastmonth = gmdate("Ym",strtotime("-1 month",$timestamp));
$vlastyear = gmdate("Y",strtotime("-1 year",$timestamp));
// delete_option("statpress_archive_today");
// delete_option("statpress_archive_thismonth");
// delete_option("statpress_archive_thisyear");
// delete_option("statpress_date_first_sets");
// delete_option("statpress_date_since_stat");
//如果第一个数据记录的时间未设定,则初始化赋值。
if(!get_option("statpress_date_first_sets")) {
$datefirstsets = $wpdb->get_var("SELECT date FROM $table_name ORDER BY date LIMIT 1;");
if($datefirstsets != null) {
update_option("statpress_date_first_sets",$datefirstsets);
if(!get_option("statpress_date_since_stat")){
update_option("statpress_date_since_stat",$datefirstsets);
}
}else{
update_option("statpress_date_since_stat",$vtoday);
}
}
$normallimit = " and (statuscode!='404' or statuscode is null)";
if((!get_option("statpress_archive_today"))||(get_option("statpress_archive_today")!=$vtoday)) {
update_option("statpress_archive_today",$vtoday);
//访问人次
$vyesterdayvisitors = $wpdb->get_var("
SELECT count(DISTINCT ip)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vyesterday . "%'$normallimit
");
update_option("statpress_archive_yesterday_visitors",$vyesterdayvisitors);
//访问页面数
$vyesterdaypageviews = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vyesterday . "%'$normallimit
");
update_option("statpress_archive_yesterday_pageviews",$vyesterdaypageviews);
//蜘蛛统计
$vyesterdayspiders = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider!=''
AND date LIKE '" . $vyesterday . "%'$normallimit
");
update_option("statpress_archive_yesterday_spiders",$vyesterdayspiders);
//订阅统计
$vyesterdayfeeds = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed!=''
AND date LIKE '" . $vyesterday . "%'$normallimit
");
update_option("statpress_archive_yesterday_feeds",$vyesterdayfeeds);
}
if((!get_option("statpress_archive_thismonth"))||(get_option("statpress_archive_thismonth")!=$vthismonth)) {
update_option("statpress_archive_thismonth",$vthismonth);
//访问人次
$vlastmonthvisitors = $wpdb->get_var("
SELECT count(DISTINCT ip)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vlastmonth . "%'$normallimit
");
update_option("statpress_archive_lastmonth_visitors",$vlastmonthvisitors);
//访问页面数
$vlastmonthpageviews = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vlastmonth . "%'$normallimit
");
update_option("statpress_archive_lastmonth_pageviews",$vlastmonthpageviews);
//蜘蛛统计
$vlastmonthspiders = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider!=''
AND date LIKE '" . $vlastmonth . "%'$normallimit
");
update_option("statpress_archive_lastmonth_spiders",$vlastmonthspiders);
//订阅统计
$vlastmonthfeeds = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed!=''
AND date LIKE '" . $vlastmonth . "%'$normallimit
");
update_option("statpress_archive_lastmonth_feeds",$vlastmonthfeeds);
}
if((!get_option("statpress_archive_thisyear"))||(get_option("statpress_archive_thisyear")!=$vthisyear)) {
update_option("statpress_archive_thisyear",$vthisyear);
//访问人次
$vlastyearvisitors = $wpdb->get_var("
SELECT count(DISTINCT ip)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vlastyear . "%'$normallimit
");
update_option("statpress_archive_lastyear_visitors",$vlastyearvisitors);
//访问页面数
$vlastyearpageviews = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider=''
AND date LIKE '" . $vlastyear . "%'$normallimit
");
update_option("statpress_archive_lastyear_pageviews",$vlastyearpageviews);
//蜘蛛统计
$vlastyearspiders = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed=''
AND spider!=''
AND date LIKE '" . $vlastyear . "%'$normallimit
");
update_option("statpress_archive_lastyear_spiders",$vlastyearspiders);
//订阅统计
$vlastyearfeeds = $wpdb->get_var("
SELECT count(date)
FROM $table_name
WHERE feed!=''
AND date LIKE '" . $vlastyear . "%'$normallimit
");
update_option("statpress_archive_lastyear_feeds",$vlastyearfeeds);
}
}
add_action('admin_menu', 'iri_add_pages');
add_action('plugins_loaded', 'widget_statpresscn_init');//statpress_autodelete
add_action('update_option_permalink_structure','iri_update_staturl_based_new_permalink_structure');
add_action('update_option_statpress_collectspider','iri_update_manuplate_sets_with_spider');
add_action('update_option_statpress_autodelete','iri_update_manuplate_sets_autodelete');
add_action('template_redirect', 'iriStatAppend');
add_action('plugins_loaded', 'heart5_archive_datasets');
add_action("activity_box_end",'heart5_dashboard_4_spc');
//add_action('send_headers', 'iriStatAppend');
//add_action('wp_head', 'iriStatAppend');
//add_action('shutdown', 'iriStatAppend');
//add_action("admin_notices","heart5_notices");
//add_action("admin_footer","heart5_print_spc_footer");
//add_action("shutdown","heart5_notices");
register_activation_hook(__FILE__,'iri_StatPress_CreateTable');
register_deactivation_hook(__FILE__,'heart5_del_all_options');
load_plugin_textdomain('statpresscn', 'wp-content/plugins/'.dirname(plugin_basename(__FILE__)).'/locale');
?>