/** * 帖子发布跟编辑。 */ 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 quit() { $aGroupId = I('group_id', 0, 'intval'); $this->requireLogin(); $this->requireGroupExists($aGroupId); $this->checkAuth(); $uid = is_login(); // 判断是否是创建者,创建者无法退出 $group = D('Group')->getGroup($aGroupId); if ($group['uid'] == $uid) { $this->error('创建者无法退出群组'); } // 判断是否在该群组内 if (is_joined($aGroupId) == 0) { $this->error('你不在该群组中'); } $res = D('GroupMember')->delMember(array('group_id' => $aGroupId, 'uid' => $uid)); if ($res) { //添加到最新动态 $dynamic['group_id'] = $aGroupId; $dynamic['uid'] = $uid; $dynamic['type'] = 'quit'; D('GroupDynamic')->addDynamic($dynamic); S('group_is_join_' . $aGroupId . '_' . $uid, null); S('group_member_count_' . $group['id'], null); $this->success('退出成功', 'refresh'); } else { $this->error('退出失败'); } }