public function doPostEdit()
{
$weiba = D('weiba_post')->where('post_id=' . intval($_POST['post_id']))->field('post_uid')->find();
if (CheckPermission('weiba_normal', 'weiba_edit')) {
//判断编辑帖子权限
if ($weiba['post_uid'] != $this->mid) {
//判断是否本人
if (!CheckWeibaPermission('', $weiba['weiba_id'])) {
//判断管理员或圈主
$this->error('对不起,您没有权限进行该操作!', true);
}
}
} else {
$this->error('对不起,您没有权限进行该操作!', true);
}
$is_lock = M('weiba_blacklist')->where('weiba_id=' . $weiba['weiba_id'] . ' and uid=' . $this->mid)->find();
if ($is_lock) {
$this->error('您是黑名单用户无法编辑帖子', true);
}
$checkContent = str_replace(' ', '', $_POST['content']);
$checkContent = str_replace('<br />', '', $checkContent);
$checkContent = str_replace('<p>', '', $checkContent);
$checkContent = str_replace('</p>', '', $checkContent);
$checkContents = preg_replace('/<img(.*?)src=/i', 'img', $checkContent);
$checkContents = preg_replace('/<embed(.*?)src=/i', 'img', $checkContents);
if (strlen(t($_POST['title'])) == 0) {
$this->error('帖子标题不能为空', true);
}
if (strlen(t($checkContents)) == 0) {
$this->error('帖子内容不能为空', true);
}
preg_match_all('/./us', t($_POST['title']), $match);
if (count($match[0]) > 25) {
//汉字和字母都为一个字
$this->error('帖子标题不能超过25个字', true);
}
$post_id = intval($_POST['post_id']);
$data['title'] = t($_POST['title']);
$data['content'] = h($_POST['content']);
/* # 格式化emoji */
$data['title'] = formatEmoji(true, $data['title']);
$data['content'] = formatEmoji(true, $data['content']);
$data['attach'] = '';
if ($_POST['attach_ids']) {
$attach = explode('|', $_POST['attach_ids']);
foreach ($attach as $k => $a) {
if (!$a) {
unset($attach[$k]);
}
}
$attach = array_map('intval', $attach);
$data['attach'] = serialize($attach);
}
$res = D('weiba_post')->where('post_id=' . $post_id)->save($data);
if ($res !== false) {
$post_detail = D('weiba_post')->where('post_id=' . $post_id)->find();
if (intval($_POST['log']) == 1) {
D('log')->writeLog($post_detail['weiba_id'], $this->mid, '编辑了帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”', 'posts');
}
//同步到分享
$feedInfo = D('feed_data')->where('feed_id=' . $post_detail['feed_id'])->find();
$datas = unserialize($feedInfo['feed_data']);
$datas['content'] = '【' . $data['title'] . '】' . getShort(t($checkContent), 100) . ' ';
$datas['body'] = $datas['content'];
$data1['feed_data'] = serialize($datas);
$data1['feed_content'] = $datas['content'];
$feed_id = D('feed_data')->where('feed_id=' . $post_detail['feed_id'])->save($data1);
model('Cache')->rm('fd_' . $post_detail['feed_id']);
//清空转发此帖子分享的缓存
$repost_list = model('Feed')->where(array('app_row_table' => 'weiba_post', 'app_row_id' => $post_id, 'is_repost' => 1))->field('feed_id')->findAll();
if ($repost_list) {
foreach ($repost_list as $value) {
model('Cache')->rm('fd_' . $value['feed_id']);
}
}
return $this->ajaxReturn($post_id, '编辑成功', 1);
} else {
$this->error('编辑失败', true);
}
}