feedback_ajax.php
13.9 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/**
*
* Ajax评论
*
* @version $Id: feedback_ajax.php 1 15:38 2010年7月8日Z tianya $
* @package DedeCMS.Site
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(DEDEINC.'/channelunit.func.php');
AjaxHead();
if($cfg_feedback_forbid=='Y') exit('系统已经禁止评论功能!');
$aid = intval($aid);
if(empty($aid)) exit('没指定评论文档的ID,不能进行操作!');
include_once(DEDEINC.'/memberlogin.class.php');
$cfg_ml = new MemberLogin();
if(empty($dopost)) $dopost = '';
$page = empty($page) || $page<1 ? 1 : intval($page);
$pagesize = 10;
/*----------------------
获得指定页的评论内容
function getlist(){ }
----------------------*/
if($dopost=='getlist')
{
$totalcount = GetList($page);
GetPageList($pagesize, $totalcount);
exit();
}
/*----------------------
发送评论
function send(){ }
----------------------*/
else if($dopost=='send')
{
require_once(DEDEINC.'/charset.func.php');
//检查验证码
if($cfg_feedback_ck=='Y')
{
$svali = strtolower(trim(GetCkVdValue()));
if(strtolower($validate) != $svali || $svali=='')
{
ResetVdValue();
echo '<font color="red">验证码错误,请点击验证码图片更新验证码!</font>';
exit();
}
}
$arcRow = GetOneArchive($aid);
if(empty($arcRow['aid']))
{
echo '<font color="red">无法查看未知文档的评论!</font>';
exit();
}
if(isset($arcRow['notpost']) && $arcRow['notpost']==1)
{
echo '<font color="red">这篇文档禁止评论!</font>';
exit();
}
if( $cfg_soft_lang != 'utf8' )
{
$msg = UnicodeUrl2Gbk($msg);
if(!empty($username)) $username = UnicodeUrl2Gbk($username);
}
//词汇过滤检查
if( $cfg_notallowstr != '' )
{
if(preg_match("#".$cfg_notallowstr."#i", $msg))
{
echo "<font color='red'>评论内容含有禁用词汇!</font>";
exit();
}
}
if( $cfg_replacestr != '' )
{
$msg = preg_replace("#".$cfg_replacestr."#i", '***', $msg);
}
if( empty($msg) )
{
echo "<font color='red'>评论内容可能不合法或为空!</font>";
exit();
}
if($cfg_feedback_guest == 'N' && $cfg_ml->M_ID < 1)
{
echo "<font color='red'>管理员禁用了游客评论!<a href='{$cfg_cmspath}/member/login.php'>点击登录</a></font>";
exit();
}
//检查用户
$username = empty($username) ? '游客' : $username;
if(empty($notuser)) $notuser = 0;
if($notuser==1)
{
$username = $cfg_ml->M_ID > 0 ? '匿名' : '游客';
}
else if($cfg_ml->M_ID > 0)
{
$username = $cfg_ml->M_UserName;
}
else if($username!='' && $pwd!='')
{
$rs = $cfg_ml->CheckUser($username, $pwd);
if($rs==1)
{
$dsql->ExecuteNoneQuery("Update `#@__member` set logintime='".time()."',loginip='".GetIP()."' where mid='{$cfg_ml->M_ID}'; ");
}
$cfg_ml = new MemberLogin();
}
//检查评论间隔时间
$ip = GetIP();
$dtime = time();
if(!empty($cfg_feedback_time))
{
//检查最后发表评论时间,如果未登陆判断当前IP最后评论时间
$where = ($cfg_ml->M_ID > 0 ? "WHERE `mid` = '$cfg_ml->M_ID' " : "WHERE `ip` = '$ip' ");
$row = $dsql->GetOne("SELECT dtime FROM `#@__feedback` $where ORDER BY `id` DESC ");
if(is_array($row) && $dtime - $row['dtime'] < $cfg_feedback_time)
{
ResetVdValue();
echo '<font color="red">管理员设置了评论间隔时间,请稍等休息一下!</font>';
exit();
}
}
$face = 1;
extract($arcRow, EXTR_SKIP);
$msg = cn_substrR(TrimMsg($msg), 500);
$username = cn_substrR(HtmlReplace($username,2), 20);
if(empty($feedbacktype) || ($feedbacktype!='good' && $feedbacktype!='bad'))
{
$feedbacktype = 'feedback';
}
//保存评论内容
if(!empty($fid))
{
$row = $dsql->GetOne("SELECT username,msg from `#@__feedback` WHERE id ='$fid' ");
$qmsg = '{quote}{content}'.$row['msg'].'{/content}{title}'.$row['username'].' 的原帖:{/title}{/quote}';
$msg = addslashes($qmsg).$msg;
}
$ischeck = ($cfg_feedbackcheck=='Y' ? 0 : 1);
$arctitle = addslashes(RemoveXSS($title));
$typeid = intval($typeid);
$feedbacktype = preg_replace("#[^0-9a-z]#i", "", $feedbacktype);
$inquery = "INSERT INTO `#@__feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`, `mid`,`bad`,`good`,`ftype`,`face`,`msg`)
VALUES ('$aid','$typeid','$username','$arctitle','$ip','$ischeck','$dtime', '{$cfg_ml->M_ID}','0','0','$feedbacktype','$face','$msg'); ";
$rs = $dsql->ExecuteNoneQuery($inquery);
if( !$rs )
{
echo "<font color='red'>发表评论出错了!</font>";
//echo $dslq->GetError();
exit();
}
$newid = $dsql->GetLastID();
//给文章评分
if($feedbacktype=='bad')
{
$dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores-{cfg_feedback_sub},badpost=badpost+1,lastpost='$dtime' WHERE id='$aid' ");
}
else if($feedbacktype=='good')
{
$dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores+{$cfg_feedback_add},goodpost=goodpost+1,lastpost='$dtime' WHERE id='$aid' ");
}
else
{
$dsql->ExecuteNoneQuery("UPDATE `#@__archives` SET scores=scores+1,lastpost='$dtime' WHERE id='$aid' ");
}
//给用户增加积分
if($cfg_ml->M_ID > 0)
{
#api{{
if(defined('UC_API') && @include_once DEDEROOT.'/api/uc.func.php')
{
//同步积分
uc_credit_note($cfg_ml->M_LoginID, $cfg_sendfb_scores);
//推送事件
$arcRow = GetOneArchive($aid);
$feed['icon'] = 'thread';
$feed['title_template'] = '<b>{username} 在网站发表了评论</b>';
$feed['title_data'] = array('username' => $cfg_ml->M_UserName);
$feed['body_template'] = '<b>{subject}</b><br>{message}';
$url = !strstr($arcRow['arcurl'],'http://') ? ($cfg_basehost.$arcRow['arcurl']) : $arcRow['arcurl'];
$feed['body_data'] = array('subject' => "<a href=\"".$url."\">$arcRow[arctitle]</a>", 'message' => cn_substr(strip_tags(preg_replace("/\[.+?\]/is", '', $msg)), 150));
$feed['images'][] = array('url' => $cfg_basehost.'/images/scores.gif', 'link'=> $cfg_basehost);
uc_feed_note($cfg_ml->M_LoginID,$feed); unset($arcRow);
}
#/aip}}
$dsql->ExecuteNoneQuery("UPDATE `#@__member` set scores=scores+{$cfg_sendfb_scores} WHERE mid='{$cfg_ml->M_ID}' ");
$row = $dsql->GetOne("SELECT COUNT(*) AS nums FROM `#@__feedback` WHERE `mid`='".$cfg_ml->M_ID."'");
$dsql->ExecuteNoneQuery("UPDATE `#@__member_tj` SET `feedback`='$row[nums]' WHERE `mid`='".$cfg_ml->M_ID."'");
}
$_SESSION['sedtime'] = time();
if($ischeck==0)
{
echo '<font color="red">成功发表评论,但需审核后才会显示你的评论!</font>';
exit();
}
else
{
$spaceurl = '#';
if($cfg_ml->M_ID > 0) $spaceurl = "{$cfg_memberurl}/index.php?uid=".urlencode($cfg_ml->M_LoginID);
$id = $newid;
$msg = stripslashes($msg);
$msg = str_replace('<', '<', $msg);
$msg = str_replace('>', '>', $msg);
helper('smiley');
$msg = RemoveXSS(Quote_replace(parseSmileys($msg, $cfg_cmspath.'/images/smiley')));
//$msg = RemoveXSS(Quote_replace($msg));
if($feedbacktype=='bad') $bgimg = 'cmt-bad.gif';
else if($feedbacktype=='good') $bgimg = 'cmt-good.gif';
else $bgimg = 'cmt-neu.gif';
global $dsql, $aid, $pagesize, $cfg_templeturl;
if($cfg_ml->M_ID==""){
$mface=$cfg_cmspath."/member/templets/images/dfboy.png";
} else {
$row = $dsql->GetOne("SELECT face,sex FROM `#@__member` WHERE mid={$cfg_ml->M_ID} ");
if(empty($row['face']))
{
if($row['sex']=="女") $mface=$cfg_cmspath."/member/templets/images/dfgirl.png";
else $mface=$cfg_cmspath."/member/templets/images/dfboy.png";
}
}
?>
<div class='decmt-box2'>
<ul>
<li> <a href='<?php echo $spaceurl; ?>' class='plpic'><img src='<?php echo $mface;?>' height='40' width='40'/></a> <span class="title"><a href="<?php echo $spaceurl; ?>"><?php echo $username; ?></a></span>
<div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
<div style="clear:both"><?php echo ubb($msg); ?></div>
<div class="newcomment_act"><span class="fr"><span id='goodfb<?php echo $id; ?>'> <a href='#goodfb<?php echo $id; ?>' onclick="postBadGood('goodfb',<?php echo $id; ?>);">支持</a>[0] </span> <span id='badfb<?php echo $id; ?>'> <a href='#badfb<?php echo $id; ?>' onclick="postBadGood('badfb',<?php echo $id; ?>);">反对</a>[0] </span> <span class='quote'>
<!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
<a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
</li>
<div id="ajaxfeedback_<?php echo $id; ?>"></div>
</ul>
</div>
<br style='clear:both' />
<?php
}
exit();
}
/**
* 读取列表内容
*
* @param int $page 页码
* @return string
*/
function GetList($page=1)
{
global $dsql, $aid, $pagesize, $cfg_templeturl,$cfg_cmspath;
$querystring = "SELECT fb.*,mb.userid,mb.face as mface,mb.spacesta,mb.scores,mb.sex FROM `#@__feedback` fb
LEFT JOIN `#@__member` mb on mb.mid = fb.mid WHERE fb.aid='$aid' AND fb.ischeck='1' ORDER BY fb.id DESC";
$row = $dsql->GetOne("SELECT COUNT(*) AS dd FROM `#@__feedback` WHERE aid='$aid' AND ischeck='1' ");
$totalcount = (empty($row['dd']) ? 0 : $row['dd']);
$startNum = $pagesize * ($page-1);
if($startNum > $totalcount)
{
echo "参数错误!";
return $totalcount;
}
$dsql->Execute('fb', $querystring." LIMIT $startNum, $pagesize ");
while($fields = $dsql->GetArray('fb'))
{
if($fields['userid']!='') $spaceurl = $GLOBALS['cfg_memberurl'].'/index.php?uid='.$fields['userid'];
else $spaceurl = '#';
if($fields['username']=='匿名') $spaceurl = '#';
$fields['bgimg'] = 'cmt-neu.gif';
$fields['ftypetitle'] = '该用户表示中立';
if($fields['ftype']=='bad')
{
$fields['bgimg'] = 'cmt-bad.gif';
$fields['ftypetitle'] = '该用户表示差评';
}
else if($fields['ftype']=='good')
{
$fields['bgimg'] = 'cmt-good.gif';
$fields['ftypetitle'] = '该用户表示好评';
}
if(empty($fields['mface']))
{
if($fields['sex']=="女") $fields['mface']=$cfg_cmspath."/member/templets/images/dfgirl.png";
else $fields['mface']=$cfg_cmspath."/member/templets/images/dfboy.png";
}
$fields['face'] = empty($fields['face']) ? 6 : $fields['face'];
$fields['msg'] = str_replace('<', '<', $fields['msg']);
$fields['msg'] = str_replace('>', '>', $fields['msg']);
helper('smiley');
$fields['msg'] = RemoveXSS(Quote_replace(parseSmileys($fields['msg'], $cfg_cmspath.'/images/smiley')));
extract($fields, EXTR_OVERWRITE);
?>
<div class="decmt-box2">
<ul>
<li> <a href='<?php echo $spaceurl; ?>' class='plpic'><img src='<?php echo $mface;?>' height='40' width='40'/></a> <span class="title"><a href="<?php echo $spaceurl; ?>"><?php echo $username; ?></a></span>
<div class="comment_act"><span class="fl"><?php echo GetDateMk($dtime); ?>发表</span></div>
<div style="clear:both"><?php echo ubb($msg); ?></div>
<div class="newcomment_act"><span class="fr"><span id='goodfb<?php echo $id; ?>'> <a href='#goodfb<?php echo $id; ?>' onclick="postBadGood('goodfb',<?php echo $id; ?>);">支持</a>[<?php echo $good; ?>] </span> <span id='badfb<?php echo $id; ?>'> <a href='#badfb<?php echo $id; ?>' onclick="postBadGood('badfb',<?php echo $id; ?>);">反对</a>[<?php echo $bad; ?>] </span> <span class='quote'>
<!--<a href='/plus/feedback.php?aid=<?php echo $id; ?>&fid=<?php echo $id; ?>&action=quote'>[引用]</a>-->
<a href='javascript:ajaxFeedback(<?php echo $id; ?>,<?php echo $id; ?>,"quote");'>[引用]</a> </span></span></div>
</li>
</ul>
<div id="ajaxfeedback_<?php echo $id; ?>"></div>
</div>
<?php
}
return $totalcount;
}
/**
* 获取分页列表
*
* @param int $pagesize 显示条数
* @param int $totalcount 总数
* @return string
*/
function GetPageList($pagesize, $totalcount)
{
global $page;
$curpage = empty($page) ? 1 : intval($page);
$allpage = ceil($totalcount / $pagesize);
if($allpage < 2)
{
echo '';
return ;
}
echo "
<div id='commetpages'>";
echo "<span>总: {$allpage} 页/{$totalcount} 条评论</span> ";
$listsize = 5;
$total_list = $listsize * 2 + 1;
$totalpage = $allpage;
$listdd = '';
if($curpage-1 > 0 )
{
echo "<a href='#commettop' onclick='LoadCommets(".($curpage-1).");'>上一页</a> ";
}
if($curpage >= $total_list)
{
$j = $curpage - $listsize;
$total_list = $curpage + $listsize;
if($total_list > $totalpage)
{
$total_list = $totalpage;
}
}
else
{
$j = 1;
if($total_list > $totalpage) $total_list = $totalpage;
}
for($j; $j <= $total_list; $j++)
{
echo ($j==$curpage ? "<strong>$j</strong> " : "<a href='#commettop' onclick='LoadCommets($j);'>{$j}</a> ");
}
if($curpage+1 <= $totalpage )
{
echo "<a href='#commettop' onclick='LoadCommets(".($curpage+1).");'>下一页</a> ";
}
echo "</div>
";
}