public function addComment()
{
// 返回结果集默认值
$return = array('status' => 0, 'data' => L('PUBLIC_CONCENT_IS_ERROR'));
// 获取接收数据
$data = $_POST;
// 安全过滤
foreach ($data as $key => $val) {
$data[$key] = t($data[$key]);
}
// 评论所属与评论内容
$data['app'] = $data['app_name'];
$data['table'] = $data['table_name'];
$data['content'] = h($data['content']);
// 判断资源是否被删除
$dao = M($data['table']);
$idField = $dao->getPk();
$map[$idField] = $data['row_id'];
$sourceInfo = $dao->where($map)->find();
if (!$sourceInfo) {
$return['status'] = 0;
$return['data'] = '内容已被删除,评论失败';
exit(json_encode($return));
}
// 兼容旧方法
if (empty($data['app_detail_summary'])) {
$source = model('Source')->getSourceInfo($data['table'], $data['row_id'], false, $data['app']);
$data['app_detail_summary'] = $source['source_body'];
$data['app_detail_url'] = $source['source_url'];
$data['app_uid'] = $source['source_user_info']['uid'];
} else {
$data['app_detail_summary'] = $data['app_detail_summary'] . '<a class="ico-details" href="' . $data['app_detail_url'] . '"></a>';
}
// 添加评论操作
$data['comment_id'] = model('Comment')->addComment($data);
if ($data['comment_id']) {
$return['status'] = 1;
$commentInfo = model('Comment')->getCommentInfo($data['comment_id']);
$html = '<dl class="comment_list" id="comment_list" id="comment_list_' . $commentInfo['comment_id'] . '">
<dt><a href="' . $commentInfo['user_info']['space_url'] . '"><img src="' . $commentInfo['user_info']['avatar_tiny'] . '" width="30" height="30"/></a></dt>
<dd>
<p class="cont">' . $commentInfo['user_info']['space_link'] . ':<em>' . str_replace('__THEME__', THEME_PUBLIC_URL, parse_html($commentInfo['content'])) . '<span class="time">' . friendlyDate($commentInfo['ctime']) . '</span><span class="handle"> <a href="javascript:;" onclick="deleteComment(' . $commentInfo['comment_id'] . ');">删除</a>
<a href="javascript:;" onclick="replyComment(\'' . $commentInfo['user_info']['uname'] . '\', ' . $commentInfo['user_info']['uid'] . ', ' . $commentInfo['comment_id'] . ');">回复</a></span></em></p>
</dd>
</dl>';
$return['data'] = $html;
// 去掉回复用户@
$lessUids = array();
if (!empty($data['to_uid'])) {
$lessUids[] = $data['to_uid'];
}
if ($_POST['ifShareFeed'] == 1) {
// 转发到我的分享
unlockSubmit();
$this->_updateToweibo($data, $sourceInfo, $lessUids);
} elseif ($data['comment_old'] != 0) {
// 是否评论给原来作者
unlockSubmit();
$this->_updateToComment($data, $sourceInfo, $lessUids);
}
} else {
$return['data'] = model('Comment')->getError();
}
exit(json_encode($return));
}