onclickfun.php
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
//信息統計
function InfoOnclick($classid,$id){
global $empire,$dbtbpre,$public_r;
if(!$classid||!$id)
{
return '';
}
$var='ecookieinforecord';
$val=$classid.'-'.$id;
if(!eCheckOnclickCookie($var,$val))
{
return '';
}
$r=$empire->fetch1("select tbname,tid from {$dbtbpre}enewsclass where classid='$classid'");
if(empty($r[tbname]))
{
return '';
}
if($public_r['onclicktype']==0)
{
$empire->query("update {$dbtbpre}ecms_".$r[tbname]." set onclick=onclick+1 where id='$id'");
}
elseif($public_r['onclicktype']==1)
{
$filename=ECMS_PATH.'e/data/filecache/onclick/ocinfo'.$r[tid].'.log';
eAddUpdateOnclick($id,$filename);
eDoUpdateOnclick($dbtbpre.'ecms_'.$r[tbname],'id','onclick',$filename);
}
}
//欄目統計
function ClassOnclick($classid){
global $empire,$dbtbpre,$public_r;
if(!$classid)
{
return '';
}
$var='ecookieclassrecord';
$val=$classid;
if(!eCheckOnclickCookie($var,$val))
{
return '';
}
if($public_r['onclicktype']==0)
{
$empire->query("update {$dbtbpre}enewsclass set onclick=onclick+1 where classid='$classid'");
}
elseif($public_r['onclicktype']==1)
{
$filename=ECMS_PATH.'e/data/filecache/onclick/occlass.log';
eAddUpdateOnclick($classid,$filename);
eDoUpdateOnclick($dbtbpre.'enewsclass','classid','onclick',$filename);
}
}
//專題統計
function ZtOnclick($ztid){
global $empire,$dbtbpre,$public_r;
if(!$ztid)
{
return '';
}
$var='ecookieztrecord';
$val=$ztid;
if(!eCheckOnclickCookie($var,$val))
{
return '';
}
if($public_r['onclicktype']==0)
{
$empire->query("update {$dbtbpre}enewszt set onclick=onclick+1 where ztid='$ztid'");
}
elseif($public_r['onclicktype']==1)
{
$filename=ECMS_PATH.'e/data/filecache/onclick/oczt.log';
eAddUpdateOnclick($ztid,$filename);
eDoUpdateOnclick($dbtbpre.'enewszt','ztid','onclick',$filename);
}
}
//加入點擊緩存
function eAddUpdateOnclick($id,$filename){
if(@$fp=fopen($filename,'a'))
{
fwrite($fp,"$id\n");
fclose($fp);
}
}
//更新點擊緩存
function eDoUpdateOnclick($table,$idf,$onclickf,$filename){
global $empire,$dbtbpre,$public_r;
if(!file_exists($filename))
{
return '';
}
if(filesize($filename)>=$public_r['onclickfilesize']*1024||time()-filectime($filename)>=$public_r['onclickfiletime']*60)
{
$lr=$ocr=array();
if(@$lr=file($filename))
{
if(!@unlink($filename))
{
if($fp=@fopen($filename,'w'))
{
fwrite($fp,'');
fclose($fp);
}
}
$lr=array_count_values($lr);
foreach($lr as $id => $oc)
{
$ocr[$oc].=($id>0)?','.intval($id):'';
}
foreach($ocr as $oc => $ids)
{
$empire->query("UPDATE LOW_PRIORITY $table SET $onclickf=$onclickf+'$oc' WHERE $idf IN (0$ids)");
}
}
}
}
//COOKIE點擊驗證
function eCheckOnclickCookie($var,$val){
$doupdate=1;
$onclickrecord=getcvar($var);
if(strstr($onclickrecord,','.$val.','))
{
$doupdate=0;
}
else
{
$newval=empty($onclickrecord)?','.$val.',':$onclickrecord.$val.',';
esetcookie($var,$newval);
}
if(empty($_COOKIE))
{
$doupdate=0;
}
return $doupdate;
}
?>