/** * 帖子发布跟编辑。 */ public function doEdit() { $aPostId = I('post.post_id', 0, 'intval'); $aGroupId = I('post.group_id', 0, 'intval'); $aTitle = I('post.title', '', 'text'); $aCategory = I('post.category', 0, 'intval'); $attach_ids = I('post.attach_ids', '', 'text'); if ($attach_ids) { $aContent = I('post.content', '', 'filter_content'); $img_ids = explode(',', $attach_ids); //把图片和内容结合 // dump($img_ids); foreach ($img_ids as &$v) { $v = D('Picture')->where(array('status' => 1))->getById($v); if (!is_bool(strpos($v['path'], 'http://'))) { $v = $v['path']; } else { $v = getRootUrl() . substr($v['path'], 1); } $v = '<p><img src="' . $v . '" style=""/></p><br>'; } $img_ids = implode('', $img_ids); $aContent = $img_ids . $aContent; $contentHandler = new ContentHandlerModel(); $aContent = $contentHandler->filterHtmlContent($aContent); //把图片和内容结合END } else { $aContent = I('post.content', '', 'filter_content'); } if (is_joined($aGroupId) != 1) { $this->error('您无发布帖子权限'); } //判断是不是编辑模式 $isEdit = $aPostId ? true : false; //如果是编辑模式,确认当前用户能编辑帖子 $this->requireLogin(); $this->requireGroupExists($aGroupId); if ($isEdit) { $this->requirePostExists($aPostId); $this->checkActionLimit('edit_group_post', 'GroupPost', $aPostId, is_login(), true); $this->checkAuth('Group/Index/edit', get_post_admin($aPostId), '您无编辑帖子权限'); } else { $this->checkActionLimit('add_group_post', 'GroupPost', 0, is_login(), true); $this->checkAuth('Group/Index/addPost', -1, '您无添加帖子权限'); } if (empty($aGroupId)) { $this->error('请选择帖子所在的群组'); } if (empty($aTitle)) { $this->error('请填写帖子标题'); } if (empty($aContent)) { $this->error('请填写帖子内容'); } $model = M('GroupPost'); $cover = get_pic($aContent); $cover = $cover == null ? '' : $cover; $len = modC('SUMMARY_LENGTH', 50); if ($isEdit) { $data = array('id' => $aPostId, 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory); $result = $model->editPost($data); //添加到最新动态 $dynamic['group_id'] = $aGroupId; $dynamic['uid'] = is_login(); $dynamic['type'] = 'update_post'; $dynamic['row_id'] = $aPostId; M('GroupDynamic')->addDynamic($dynamic); if (!$result) { $this->error('编辑失败:' . $model->getError()); } } else { $data = array('uid' => is_login(), 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory); $result = $model->createPost($data); if (!$result) { $this->error('发表失败。'); } $aPostId = $result; //添加到最新动态 $dynamic['group_id'] = $aGroupId; $dynamic['uid'] = is_login(); $dynamic['type'] = 'post'; $dynamic['row_id'] = $aPostId; M('GroupDynamic')->addDynamic($dynamic); //增加活跃度 M('Group')->where(array('id' => $aGroupId))->setInc('activity'); M('GroupMember')->where(array('group_id' => $aGroupId, 'uid' => is_login()))->setInc('activity'); } //实现发布帖子发布图片轻博客(公共内容) $group = M('Group')->getGroup($aGroupId); $this->sendWeibo($aPostId, $isEdit, $group); //显示成功消息 $message = $isEdit ? '编辑成功。' : '发表成功。' . cookie('score_tip'); $this->success($message, U('Group/Index/detail', array('id' => $aPostId))); }
public function doEdit() { $aPostId = I('post.post_id', 0, 'intval'); $aGroupId = I('post.group_id', 0, 'intval'); $aTitle = I('post.title', '', 'text'); $aContent = I('post.content', '', 'filter_content'); $aCategory = I('post.category', 0, 'intval'); if (is_joined($aGroupId) != 1) { $this->error('您无编辑帖子权限'); } //判断是不是编辑模式 $isEdit = $aPostId ? true : false; //如果是编辑模式,确认当前用户能编辑帖子 $this->requireLogin(); $this->requireGroupExists($aGroupId); if ($isEdit) { $this->requirePostExists($aPostId); $this->checkActionLimit('edit_group_post', 'GroupPost', $aPostId, is_login(), true); $this->checkAuth('Group/Index/edit', get_post_admin($aPostId), '您无编辑帖子权限'); } else { $this->checkActionLimit('add_group_post', 'GroupPost', 0, is_login(), true); $this->checkAuth('Group/Index/addPost', -1, '您无添加帖子权限'); } if (empty($aGroupId)) { $this->error('请选择帖子所在的群组'); } if (empty($aTitle)) { $this->error('请填写帖子标题'); } if (empty($aContent)) { $this->error('请填写帖子内容'); } $model = D('GroupPost'); $cover = get_pic($aContent); $cover = $cover == null ? '' : $cover; $len = modC('SUMMARY_LENGTH', 50); if ($isEdit) { $data = array('id' => $aPostId, 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory); $result = $model->editPost($data); //添加到最新动态 $dynamic['group_id'] = $aGroupId; $dynamic['uid'] = is_login(); $dynamic['type'] = 'update_post'; $dynamic['row_id'] = $aPostId; D('GroupDynamic')->addDynamic($dynamic); if (!$result) { $this->error('编辑失败:' . $model->getError()); } } else { $data = array('uid' => is_login(), 'title' => $aTitle, 'summary' => mb_substr(text($aContent), 0, $len, 'utf-8'), 'cover' => $cover, 'content' => $aContent, 'parse' => 0, 'group_id' => $aGroupId, 'cate_id' => $aCategory); $result = $model->createPost($data); if (!$result) { $this->error('发表失败。'); } $aPostId = $result; //添加到最新动态 $dynamic['group_id'] = $aGroupId; $dynamic['uid'] = is_login(); $dynamic['type'] = 'post'; $dynamic['row_id'] = $aPostId; D('GroupDynamic')->addDynamic($dynamic); //增加活跃度 D('Group')->where(array('id' => $aGroupId))->setInc('activity'); D('GroupMember')->where(array('group_id' => $aGroupId, 'uid' => is_login()))->setInc('activity'); } //实现发布帖子发布图片微博(公共内容) $group = D('Group')->getGroup($aGroupId); $this->sendWeibo($aPostId, $isEdit, $group); //显示成功消息 $message = $isEdit ? '编辑成功。' : '发表成功。' . cookie('score_tip'); $this->success($message, U('Group/Index/detail', array('id' => $aPostId))); }