IndexAction::index_post_list PHP Méthode

index_post_list() private méthode

帖子列表
private index_post_list ( $post_type, $p )
    private function index_post_list($post_type, $p)
    {
        $maps['is_del'] = 0;
        //剔除不符合微吧ID
        $fwid = D('weiba')->where('is_del=1 OR status=0')->order($order)->select();
        $fids = getSubByKey($fwid, 'weiba_id');
        if ($fids) {
            $maps['weiba_id'] = array('not in', $fids);
        }
        switch ($post_type) {
            case 'reply':
                $order = 'top desc,last_reply_time desc ';
                $list = D('weiba_post')->where($maps)->order($order)->findpage(20);
                $this->assign('type', 'reply');
                $this->assign('post_count', D('weiba_post')->where($maps)->count());
                break;
            case 'hot':
                $order = 'top desc,reply_all_count desc ';
                $list = D('weiba_post')->where($maps)->order($order)->findpage(20);
                $this->assign('type', 'hot');
                $this->assign('post_count', D('weiba_post')->where($maps)->count());
                break;
            case 'digest':
                $order = 'top desc,post_time desc ';
                $maps['digest'] = 1;
                $list = D('weiba_post')->where($maps)->order($order)->findpage(20);
                $this->assign('type', 'digest');
                $this->assign('post_count', D('weiba_post')->where($maps)->count());
                break;
            case 'top':
                $sfollow = D('weiba_follow')->where('follower_uid=' . $this->mid)->findAll();
                if ($sfollow) {
                    $idlist = getSubByKey($sfollow, 'weiba_id');
                    foreach ($idlist as $k => $vo) {
                        if (in_array($vo, $fids)) {
                            unset($idlist[$k]);
                        }
                    }
                    $maps['weiba_id'] = array('in', $idlist);
                }
                $order = ' top desc, post_time desc';
                $list = D('weiba_post')->where($maps)->order($order)->findpage(20);
                $this->assign('type', 'top');
                $this->assign('post_count', D('weiba_post')->where($maps)->count());
                break;
            default:
                //new
                $order = 'is_index_time desc';
                $maps['is_index'] = 1;
                $list = D('weiba_post')->where($maps)->order($order)->findpage(5);
                $this->assign('type', 'new');
                $this->assign('post_count', D('weiba_post')->where($maps)->count());
                break;
        }
        $weiba_ids = getSubByKey($list['data'], 'weiba_id');
        $nameArr = $this->_getWeibaName($weiba_ids);
        foreach ($list['data'] as $k => $v) {
            $list['data'][$k]['weiba'] = $nameArr[$v['weiba_id']];
            $list['data'][$k]['user'] = model('User')->getUserInfo($v['post_uid']);
            $list['data'][$k]['replyuser'] = model('User')->getUserInfo($v['last_reply_uid']);
            // $images = matchImages($v['content']);
            // $images[0] && $list['data'][$k]['image'] = array_slice( $images , 0 , 5 );
            $image = getEditorImages($v['content']);
            !empty($image) && ($list['data'][$k]['image'] = array($image));
            //匹配图片的src
            preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $v['content'], $match);
            foreach ($match[1] as $imgurl) {
                $imgurl = $imgurl;
                if (!empty($imgurl)) {
                    $list['data'][$k]['img'][] = $imgurl;
                }
            }
            $is_digg = M('weiba_post_digg')->where('post_id=' . $v['post_id'] . ' and uid=' . $this->mid)->find();
            $list['data'][$k]['digg'] = $is_digg ? 'digg' : 'undigg';
            $list['data'][$k]['content'] = t($list['data'][$k]['content']);
            //dump($userinfo);avatar_small,avatar_tiny
            $list['data'][$k]['image'] = $list['data'][$k]['user']['avatar_middle'];
            //首页帖子图片换成缩略图
            // $index_img_url = getImageUrlByAttachId($list['data'][$k]['index_img'], 700, 310);
            // $index_img_info = getThumbImage($index_img_url,700,310,true,false);
            $list['data'][$k]['index_img'] = getImageUrlByAttachId($list['data'][$k]['index_img'], 700, 260);
            /* 解析emoji */
            $list['data'][$k]['title'] = formatEmoji(false, $list['data'][$k]['title']);
            $list['data'][$k]['content'] = formatEmoji(false, $list['data'][$k]['content']);
        }
        return $list;
    }