IndexAction::_post_list PHP Method

_post_list() private method

帖子列表
private _post_list ( $post_type, $limit )
    private function _post_list($post_type, $limit)
    {
        $db_prefix = C('DB_PREFIX');
        switch ($post_type) {
            case 'reply':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 ) AND ( a.`is_del` = 0 ) ORDER BY a.last_reply_time desc LIMIT " . $limit;
                break;
            case 'hot':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`is_del` = 0 ) ORDER BY a.reply_all_count desc LIMIT " . $limit;
                break;
            case 'digest':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`digest` = 1 ) AND ( a.`is_del` = 0 ) ORDER BY a.post_time desc LIMIT " . $limit;
                break;
            case 'recommend':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`recommend` = 1 ) AND ( a.`is_del` = 0 ) ORDER BY a.recommend_time desc LIMIT " . $limit;
                break;
            case 'top':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`top` = 2 ) AND ( a.`is_del` = 0 ) ORDER BY a.last_reply_time desc LIMIT " . $limit;
                break;
            case 'nrecommend':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`top` = 2 ) AND ( a.`is_del` = 0 ) ORDER BY a.top_time desc LIMIT " . $limit;
                break;
            case 'topandrecomment':
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`recommend` = 1 ) AND ( a.`is_del` = 0 ) ORDER BY a.top desc,a.last_reply_time desc";
                break;
            default:
                //new
                $sql = "SELECT a.* FROM `{$db_prefix}weiba_post` a, `{$db_prefix}weiba` b WHERE a.weiba_id=b.weiba_id AND ( b.`is_del` = 0 ) AND ( b.`status` = 1 )  AND ( a.`is_del` = 0 ) ORDER BY a.post_time desc LIMIT " . $limit;
                break;
        }
        $post_list = D('weiba_post')->query($sql);
        $weiba_ids = getSubByKey($post_list, 'weiba_id');
        $nameArr = $this->_getWeibaName($weiba_ids);
        foreach ($post_list as $k => $v) {
            $post_list[$k]['weiba'] = $nameArr[$v['weiba_id']];
            $post_list[$k]['user'] = model('User')->getUserInfo($v['post_uid']);
            $post_list[$k]['replyuser'] = model('User')->getUserInfo($v['last_reply_uid']);
            // $images = matchImages($v['content']);
            // $images[0] && $post_list[$k]['image'] = array_slice( $images , 0 , 5 );
            $image = getEditorImages($v['content']);
            !empty($image) && ($post_list[$k]['image'] = array($image));
            //匹配图片的src
            preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $v['content'], $match);
            foreach ($match[1] as $imgurl) {
                $imgurl = $imgurl;
                if (!empty($imgurl)) {
                    $post_list[$k]['img'][] = $imgurl;
                }
            }
            /* 解析emoji */
            $post_list[$k]['title'] = formatEmoji(false, $v['title']);
            $post_list[$k]['content'] = formatEmoji(false, $v['content']);
        }
        return $post_list;
    }