IndexAction::doPost PHP Méthode

doPost() public méthode

执行发布帖子
public doPost ( )
    public function doPost()
    {
        //检测用户是否被禁言
        if ($isDisabled = model('DisableUser')->isDisableUser($this->mid, 'post')) {
            $this->error('您已被禁言!', $type);
        }
        if ($_GET['post_type'] == 'index') {
            $type = false;
        } else {
            $type = true;
        }
        $weibaid = intval($_POST['weiba_id']);
        if (!CheckPermission('weiba_normal', 'weiba_post')) {
            $this->error('对不起,您没有权限进行该操作!', $type);
        }
        $is_lock = M('weiba_blacklist')->where('weiba_id=' . $weibaid . ' and uid=' . $this->mid)->find();
        if ($is_lock) {
            $this->error('您是黑名单用户没有发帖权限', $type);
        }
        $weibaid = intval($_POST['weiba_id']);
        if (!$weibaid) {
            $this->error('请选择微吧,等待返回选择微吧', $type);
        }
        $weiba = D('weiba')->where('weiba_id=' . $weibaid)->find();
        //黑名单功能添加
        if (!CheckPermission('core_admin', 'admin_login')) {
            switch ($weiba['who_can_post']) {
                case 1:
                    $map['weiba_id'] = $weibaid;
                    $map['follower_uid'] = $this->mid;
                    $res = D('weiba_follow')->where($map)->find();
                    if (!$res && !CheckPermission('core_admin', 'admin_login')) {
                        $this->error('对不起,您没有发帖权限,请关注该微吧!', $type);
                    }
                    break;
                case 2:
                    $map['weiba_id'] = $weibaid;
                    $map['level'] = array('in', '2,3');
                    $weiba_admin = D('weiba_follow')->where($map)->order('level desc')->field('follower_uid')->findAll();
                    if (!in_array($this->mid, getSubByKey($weiba_admin, 'follower_uid')) && !CheckPermission('core_admin', 'admin_login')) {
                        $this->error('对不起,您没有发帖权限,仅限该吧管理员发帖!', $type);
                    }
                    break;
                case 3:
                    $map['weiba_id'] = $weibaid;
                    $map['level'] = 3;
                    $weiba_admin = D('weiba_follow')->where($map)->order('level desc')->field('follower_uid')->find();
                    if ($this->mid != $weiba_admin['follower_uid'] && !CheckPermission('core_admin', 'admin_login')) {
                        $this->error('对不起,您没有发帖权限,仅限该吧吧主发帖!', $type);
                    }
                    break;
            }
        }
        $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);
        $checkContents = RemoveXSS($checkContents);
        if (strlen(t($_POST['title'])) == 0) {
            $this->error('帖子标题不能为空,等待返回添加标题', $type);
        }
        if (strlen(t($checkContents)) == 0) {
            $this->error('帖子内容不能为空,等待返回添加内容', $type);
        }
        preg_match_all('/./us', t($_POST['title']), $match);
        if (count($match[0]) > 25) {
            //汉字和字母都为一个字
            $this->error('帖子标题不能超过25个字,等待返回修改标题', $type);
        }
        /* # 帖子内容 */
        $content = h($_POST['content']);
        if (get_str_length($content) >= 20000) {
            $this->error('帖子内容过长!无法发布!');
        }
        unset($content);
        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);
        }
        $data['weiba_id'] = $weibaid;
        $data['title'] = t($_POST['title']);
        $data['content'] = h($_POST['content']);
        $data['post_uid'] = $this->mid;
        $data['post_time'] = time();
        $data['last_reply_uid'] = $this->mid;
        $data['last_reply_time'] = $data['post_time'];
        $data['feed_id'] = 0;
        /* # 格式化emoji */
        $data['title'] = formatEmoji(true, $data['title']);
        $data['content'] = formatEmoji(true, $data['content']);
        $filterTitleStatus = filter_words($data['title']);
        if (!$filterTitleStatus['status']) {
            $this->error($filterTitleStatus['data'], $type);
        }
        $data['title'] = $filterTitleStatus['data'];
        $filterContentStatus = filter_words($data['content']);
        if (!$filterContentStatus['status']) {
            $this->error($filterContentStatus['data'], $type);
        }
        $data['content'] = addslashes($filterContentStatus['data']);
        $res = D('weiba_post')->add($data);
        if ($res) {
            D('Weiba')->setNewcount($weibaid);
            D('weiba')->where('weiba_id=' . $data['weiba_id'])->setInc('thread_count');
            //同步到分享
            // $feed_id = D('weibaPost')->syncToFeed($res,$data['title'],t($checkContent),$this->mid);
            $feed_id = model('Feed')->syncToFeed('weiba', $this->mid, $res);
            D('weiba_post')->where('post_id=' . $res)->setField('feed_id', $feed_id);
            //$this->assign('jumpUrl', U('weiba/Index/postDetail',array('post_id'=>$res)));
            //$this->success('发布成功');
            $result['id'] = $res;
            $result['feed_id'] = $feed_id;
            //添加积分
            model('Credit')->setUserCredit($this->mid, 'publish_topic');
            //更新发帖数
            D('UserData')->updateKey('weiba_topic_count', 1);
            if ($_GET['post_type'] == 'index') {
                $this->success('发布成功');
            } else {
                return $this->ajaxReturn($result, '发布成功', 1);
            }
        } else {
            $this->error('发布失败,等待返回修改发布', $type);
        }
    }