plfun.php
9.33 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
//發表評論
function AddPl($username,$password,$nomember,$key,$saytext,$id,$classid,$repid,$add){
global $empire,$dbtbpre,$public_r,$class_r,$level_r;
//驗證本時間允許操作
eCheckTimeCloseDo('pl');
//驗證IP
eCheckAccessDoIp('pl');
$id=(int)$id;
$repid=(int)$repid;
$classid=(int)$classid;
//驗證碼
$keyvname='checkplkey';
if($public_r['plkey_ok'])
{
ecmsCheckShowKey($keyvname,$key,1);
}
$username=RepPostVar($username);
$password=RepPostVar($password);
$muserid=(int)getcvar('mluserid');
$musername=RepPostVar(getcvar('mlusername'));
$mgroupid=(int)getcvar('mlgroupid');
if($muserid)//已登陸
{
$cklgr=qCheckLoginAuthstr();
if($cklgr['islogin'])
{
$username=$musername;
}
else
{
$muserid=0;
}
}
else
{
if(empty($nomember))//非匿名
{
if(!$username||!$password)
{
printerror("FailPassword","history.go(-1)",1);
}
$ur=$empire->fetch1("select ".eReturnSelectMemberF('userid,salt,password,checked,groupid')." from ".eReturnMemberTable()." where ".egetmf('username')."='$username' limit 1");
if(empty($ur['userid']))
{
printerror("FailPassword","history.go(-1)",1);
}
if(!eDoCkMemberPw($password,$ur['password'],$ur['salt']))
{
printerror("FailPassword","history.go(-1)",1);
}
if($ur['checked']==0)
{
printerror("NotCheckedUser",'',1);
}
$muserid=$ur['userid'];
$mgroupid=$ur['groupid'];
}
else
{
$muserid=0;
}
}
if($public_r['plgroupid'])
{
if(!$muserid)
{
printerror("GuestNotToPl","history.go(-1)",1);
}
if($level_r[$mgroupid][level]<$level_r[$public_r['plgroupid']][level])
{
printerror("NotLevelToPl","history.go(-1)",1);
}
}
//專題
$doaction=$add['doaction'];
if($doaction=='dozt')
{
if(!trim($saytext)||!$classid)
{
printerror("EmptyPl","history.go(-1)",1);
}
//是否關閉評論
$r=$empire->fetch1("select ztid,closepl,checkpl,restb from {$dbtbpre}enewszt where ztid='$classid'");
if(!$r['ztid'])
{
printerror("ErrorUrl","history.go(-1)",1);
}
if($r['closepl'])
{
printerror("CloseClassPl","history.go(-1)",1);
}
//審核
if($r['checkpl'])
{$checked=1;}
else
{$checked=0;}
$restb=$r['restb'];
$pubid='-'.$classid;
$id=0;
$pagefunr=eReturnRewritePlUrl($classid,$id,'dozt',0,0,1);
$returl=$pagefunr['pageurl'];
}
else//信息
{
if(!trim($saytext)||!$id||!$classid)
{
printerror("EmptyPl","history.go(-1)",1);
}
//表存在
if(empty($class_r[$classid][tbname]))
{
printerror("ErrorUrl","history.go(-1)",1);
}
//是否關閉評論
$r=$empire->fetch1("select classid,stb,restb from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
if(!$r['classid']||$r['classid']!=$classid)
{
printerror("ErrorUrl","history.go(-1)",1);
}
if($class_r[$r[classid]][openpl])
{
printerror("CloseClassPl","history.go(-1)",1);
}
//單信息關閉評論
$pubid=ReturnInfoPubid($classid,$id);
$finfor=$empire->fetch1("select closepl from {$dbtbpre}ecms_".$class_r[$classid][tbname]."_data_".$r['stb']." where id='$id' limit 1");
if($finfor['closepl'])
{
printerror("CloseInfoPl","history.go(-1)",1);
}
//審核
if($class_r[$classid][checkpl])
{$checked=1;}
else
{$checked=0;}
$restb=$r['restb'];
$pagefunr=eReturnRewritePlUrl($classid,$id,'doinfo',0,0,1);
$returl=$pagefunr['pageurl'];
}
//設置參數
$plsetr=$empire->fetch1("select pltime,plsize,plincludesize,plclosewords,plmustf,plf,plmaxfloor,plquotetemp from {$dbtbpre}enewspl_set limit 1");
if(strlen($saytext)>$plsetr['plsize'])
{
$GLOBALS['setplsize']=$plsetr['plsize'];
printerror("PlSizeTobig","history.go(-1)",1);
}
$time=time();
$saytime=$time;
$pltime=getcvar('lastpltime');
if($pltime)
{
if($time-$pltime<$plsetr['pltime'])
{
$GLOBALS['setpltime']=$plsetr['pltime'];
printerror("PlOutTime","history.go(-1)",1);
}
}
$sayip=egetip();
$eipport=egetipport();
$username=str_replace("\r\n","",$username);
$username=RepPostStr($username);
$saytext=nl2br(RepFieldtextNbsp(RepPostStr($saytext)));
if($repid)
{
$saytext=RepPlTextQuote($repid,$saytext,$plsetr,$restb);
CkPlQuoteFloor($plsetr['plmaxfloor'],$saytext);//驗證樓層
}
//過濾字符
$saytext=ReplacePlWord($plsetr['plclosewords'],$saytext);
if($level_r[$mgroupid]['plchecked'])
{
$checked=0;
}
$ret_r=ReturnPlAddF($add,$plsetr,0);
//主表
$sql=$empire->query("insert into {$dbtbpre}enewspl_".$restb."(pubid,username,sayip,saytime,id,classid,checked,zcnum,fdnum,userid,isgood,saytext,eipport".$ret_r['fields'].") values('$pubid','".$username."','$sayip','$saytime','$id','$classid','$checked',0,0,'$muserid',0,'".addslashes($saytext)."','$eipport'".$ret_r['values'].");");
$plid=$empire->lastid();
if($doaction!='dozt')
{
//信息表加1
$usql=$empire->query("update {$dbtbpre}ecms_".$class_r[$classid][tbname]." set plnum=plnum+1 where id='$id' limit 1");
}
//更新新評論數
DoUpdateAddDataNum('pl',$restb,1);
//設置最後發表時間
$set1=esetcookie("lastpltime",time(),time()+3600*24);
ecmsEmptyShowKey($keyvname);//清空驗證碼
if($sql)
{
$reurl=DoingReturnUrl($returl,$_POST['ecmsfrom']);
printerror("AddPlSuccess",$reurl,1);
}
else
{printerror("DbError","history.go(-1)",1);}
}
//替換回復
function RepPlTextQuote($repid,$saytext,$pr,$restb){
global $public_r,$empire,$dbtbpre,$fun_r;
$quotetemp=stripSlashes($pr['plquotetemp']);
$r=$empire->fetch1("select userid,username,saytime,saytext from {$dbtbpre}enewspl_".$restb." where plid='$repid'");
if(empty($r['username']))
{
$r['username']=$fun_r['nomember'];
}
if($r['userid'])
{
$r['username']="<a href=\"$public_r[newsurl]e/space/?userid=$r[userid]\" target=\"_blank\">$r[username]</a>";
}
$quotetemp=str_replace('[!--plid--]',$repid,$quotetemp);
$quotetemp=str_replace('[!--pltime--]',date('Y-m-d H:i:s',$r['saytime']),$quotetemp);
$quotetemp=str_replace('[!--username--]',$r['username'],$quotetemp);
$quotetemp=str_replace('[!--pltext--]',$r['saytext'],$quotetemp);
$restr=$quotetemp.$saytext;
return $restr;
}
//去掉原引用
function RepYPlQuote($text){
$preg_str="/<div (.+?)<\/div>/is";
$text=preg_replace($preg_str,"",$text);
return $text;
}
//驗證引用樓數
function CkPlQuoteFloor($plmaxfloor,$saytext){
if(!$plmaxfloor)
{
return '';
}
$fr=explode('<div',$saytext);
$fcount=count($fr)-1;
if($fcount>$plmaxfloor)
{
printerror('PlOutMaxFloor','history.go(-1)',1);
}
}
//禁用字符
function ReplacePlWord($plclosewords,$text){
global $empire,$dbtbpre;
if(empty($text))
{
return $text;
}
toCheckCloseWord($text,$plclosewords,'HavePlCloseWords');
return $text;
}
//返回字段
function ReturnPlAddF($add,$pr,$ecms=0){
global $empire,$dbtbpre;
$fr=explode(',',$pr['plf']);
$count=count($fr)-1;
$ret_r['fields']='';
$ret_r['values']='';
for($i=1;$i<$count;$i++)
{
$f=$fr[$i];
$fval=RepPostStr($add[$f]);
//必填
if(strstr($pr[plmustf],','.$f.','))
{
if(!trim($fval))
{
$chfr=$empire->fetch1("select fname from {$dbtbpre}enewsplf where f='$f' limit 1");
$GLOBALS['msgmustf']=$chfr['fname'];
printerror('EmptyPlMustF','',1);
}
}
$fval=nl2br(RepFieldtextNbsp($fval));
$ret_r['fields'].=",".$f;
$ret_r['values'].=",'".addslashes($fval)."'";
}
return $ret_r;
}
//支持/反對評論
function DoForPl($add){
global $empire,$dbtbpre,$class_r;
$classid=(int)$add['classid'];
$id=(int)$add['id'];
$plid=(int)$add['plid'];
$dopl=(int)$add['dopl'];
$doajax=(int)$add['doajax'];
//專題
$doaction=$add['doaction'];
if($doaction=='dozt')
{
if(!$classid||!$plid)
{
$doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
}
$infor=$empire->fetch1("select ztid,restb from {$dbtbpre}enewszt where ztid='$classid'");
if(!$infor['ztid'])
{
$doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
}
$pubid='-'.$classid;
}
else//信息
{
if(!$classid||!$id||!$plid||!$class_r[$classid][tbname])
{
$doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
}
$infor=$empire->fetch1("select classid,restb from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' limit 1");
if(!$infor['classid'])
{
$doajax==1?ajax_printerror('','','ErrorUrl',1):printerror('ErrorUrl','',1);
}
$pubid=ReturnInfoPubid($classid,$id);
}
//連續發表
if(getcvar('lastforplid'.$plid))
{
$doajax==1?ajax_printerror('','','ReDoForPl',1):printerror('ReDoForPl','',1);
}
if($dopl==1)
{
$f='zcnum';
$msg='DoForPlGSuccess';
}
else
{
$f='fdnum';
$msg='DoForPlBSuccess';
}
$sql=$empire->query("update {$dbtbpre}enewspl_".$infor['restb']." set ".$f."=".$f."+1 where plid='$plid' and pubid='$pubid'");
if($sql)
{
esetcookie('lastforplid'.$plid,$plid,time()+30*24*3600); //最後發佈
if($doajax==1)
{
$nr=$empire->fetch1("select ".$f." from {$dbtbpre}enewspl_".$infor['restb']." where plid='$plid' and pubid='$pubid'");
ajax_printerror($nr[$f],$add['ajaxarea'],$msg,1);
}
else
{
printerror($msg,$_SERVER['HTTP_REFERER'],1);
}
}
else
{
$doajax==1?ajax_printerror('','','DbError',1):printerror('DbError','',1);
}
}
?>