<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Post extends Api_Controller{

    //禁言用户组ID
    public $groupids_banned = array(4, 5, 6);
    public function __construct()
    {
        parent::__construct();
    }

    //发帖
    public function sendpost() {
        $user_groupid = $this->user->checkLogin();
        if (!$user_groupid) {
            $this->odz_error('User is not login');
        } elseif (in_array($user_groupid, $this->groupids_banned)) {
            $this->odz_error('您已被禁言');
        }
        $uid = $this->user->uid;
        $username = $this->user->username;
        $content = trim($this->input->post('content', true));
        $platform = $this->input->post('platform');

        $pic_arr = array();
        $pic_count = 0;
        $pos = 0;
        $topics = array();
        $topic_ids = array();
        $tids_new = array();
        $tids_old = array();
        $ret = '';
        $data = array();

        if (empty($uid) || empty($username)) {
            $this->odz_error('params error');
        }

        $this->load->library('api_upload');
        $pic_arr = $this->api_upload->upload_imgs();
        if (empty($pic_arr)) {
            $this->odz_error('image is not exist.');
        } else {
            $pic_count = count($pic_arr);
        }

        //解析帖子内容 #***##***#***********
        $ret = preg_match_all('/\#(.*?)\#/', $content, $matchs);
        //关键词过滤
        $this->load->model('keywords_model', 'keywords');
        $where=array();
        $where[]="isdelete=0";
        $field="keyword";
        $error=0;
        $keywords=$this->keywords->get_keywords($where,$field,'','');
        foreach ($keywords as $king => $box) {
            $temp=strstr($content, $box['keyword']);
            if($temp){
                $error=1;
                break;
            }
        }
        if($error==1){
             $this->odz_error('您的发帖中含有敏感词，请注意用语哦');
        }
        if (!$ret) {
            //新建一个不属于任何话题的帖子
            $data = array(
                'uid' => $uid,
                'username' => $username,
                'content' => $content,
                'platform' => $platform,
                'sourceid' => 2,
                'createtime' => time()
            );
            $this->load->model('sharecircle/post_model', 'post');
            $new_post_id = $this->post->insert($data);
        } else {
            $topics = $matchs[1];
            //当话题不存在时，添加话题，添加用户参与话题记录，
            //当话题已存在时，更新话题图片数，人气，页显人气，参与人数，添加用户参与话题记录
            $this->load->helper('url');
            $img_default = base_url(). 'assets/images/topic_default.png';
            $this->load->model('sharecircle/topic_model', 'topic');
            foreach($topics as $value) {
                $ret_check = array();
                $ret_check = $this->topic->check_by_title($value);
                if (empty($ret_check)) {
                    $data = array(
                        'uid' => $uid,
                        'username' => $username,
                        'title' => $value,
                        'typeid' => 5,
                        'listimg' => $img_default,
                        'detailimg' => $img_default,
                        'sourceid' => 3,
                        'buzzcount' => 1,
                        'involcount' => 1,
                        'extracount' => 1,
                        'piccount' => $pic_count,
                        'createtime' => time()
                    );
                    $tids_new[] = $this->topic->insert($data);
                } else {
                    $tids_old[] = $ret_check['id'];
                }
            }
            //添加帖子
            $data = array(
                'uid' => $uid,
                'username' => $username,
                'content' => $content,
                'platform' => $platform,
                'sourceid' => 2,
                'createtime' => time()
            );
            $this->load->model('sharecircle/post_model', 'post');
            $new_post_id = $this->post->insert($data);

            //对已经存在的话题，更新话题图片数，人气，页显人气（已设置时更新），参与人数（第一次参与）
            $this->load->model('sharecircle/topic_participation_model', 'participation');
            if (!empty($tids_old)) {
                //检测当前用户是否参与过这些话题,返回参与过的话题ID
                $tids_part = $this->participation->check_by_tids($tids_old, $uid);
                foreach ($tids_old as $tid) {
                    //增加话题图片数，人气+1，页显人气+1
                    $param = array(
                        'buzzcount' => 1,
                        'extracount' => 1,
                        'piccount' => $pic_count
                    );
                    //没参与过的话题，话题参与人数+1
                    if (!in_array($tid, $tids_part)) {
                        $param['involcount'] = 1;
                    }
                    $this->topic->increase_batch($param, $tid);
                }
            }

            $topic_ids = array_merge($tids_new, $tids_old);
            if (!empty($topic_ids) && !empty($new_post_id)) {
                $this->load->model('sharecircle/topic_post_model', 'topic_post');

                foreach($topic_ids as $tid) {
                    //添加话题和帖子的关联关系
                    $data = array(
                        'tid' => $tid,
                        'pid' => $new_post_id,
                        'createtime' => time()
                    );
                    $this->topic_post->insert($data);

                    //添加话题参与记录表
                    $this->participation->replace(array(
                        'tid' => $tid,
                        'uid' => $uid,
                        'username' => $username,
                        'createtime' => time()
                    ));
                }
            }
        }

        //添加帖子图片
        $this->load->model('sharecircle/post_img_model', 'post_img');
        foreach ($pic_arr as $value) {
            $data = array(
                'postid' => $new_post_id,
                'width' => $value['width'],
                'height' => $value['height'],
                'path' => $value['url'],
                'createtime' => time()
            );
            $this->post_img->insert($data);
        }
        $this->odz_result('', '发布成功');
    }

    //帖子详情分享页(h5)
    public function post_detail_share($postid) {
        $this->load->helper('my_api');
        $this->load->helper('url_helper');
        $post_info = array();
        $post_info = $this->get_post_detail($postid);
//        echo '<pre>';
//        print_r($post_info);
//        die();

        $this->load->view('sharecircle/h5/post_detail_share', $post_info);
    }

    public function get_post_detail($postid) {
        $limit = 10; //每页评论数
        $post_info = array();
        $ret = array();
        $tids = array();
        $topic_titles = array();
        $like_info = array();

        $this->load->model('sharecircle/post_model', 'post');
        $post_info = $this->post->get_one($postid);
        if (empty($post_info)) {
            $this->json(1, 'The post is not exist');
        }
        if ($this->user->uid) {
            $post_info['login_flag'] = 1; //已登录
        } else {
            $post_info['login_flag'] = 2; //未登录
        }
        //添加用户等级
//        $post_info['usergroup_level'] = $this->user->usergroup_level($post_info['uid']);

        //笑脸，为帖子内容中的话题添加蓝色样式
        $content = smiley_parse($post_info['content'], asset_url('h5/images/smilies'));
        $post_info['content_style'] = preg_replace('/(\#.*?\#)/', '<span class="topic_title">$1</span>', $content);

        $this->load->model('sharecircle/post_img_model', 'post_img');
        $post_info['img_arr'] = $this->post_img->get_img_by_pid($postid);
        if (!empty($post_info['img_arr'])) {
            $post_info['img_arr_json'] = json_encode($post_info['img_arr']);
        } else {
            $post_info['img_arr_json'] = null;
        }

        $post_info['ctime_format'] = format_date($post_info['createtime']);

        if ($post_info['platform'] === 'ios') {
            $post_info['platform_v'] = 'iPhone';
        } else {
            $post_info['platform_v'] = 'Andriod';
        }
        $post_info['domain'] = 'http://' . $_SERVER['HTTP_HOST'];
        $post_info['timestamp'] = time();

        $this->load->model('sharecircle/post_like_model', 'post_like');
        if ($this->user->uid) {
            //检测是否已关注
//            $this->load->model('sharecircle/follow_model', 'follow');
//            $post_info['is_followed'] = $this->follow->is_followed($this->user->uid, $post_info['uid']);
            //检测当前用户是否已点赞该贴
            $post_info['is_liked'] = $this->post_like->is_liked($this->user->uid, $postid);
        } else {
//            $post_info['is_followed'] = false;
            $post_info['is_liked'] = false;
        }

        //获取最新的9个点赞用户
        $like_info = array();
        $like_info = $this->post_like->get_by_postid($postid, 9);
        $post_info['like_users'] = $like_info;
        /*if (count($like_info) < 10) {
            $post_info['like_users'] = $like_info;
            $post_info['like_more'] = 'no';
        } else {
            $post_info['like_users'] = array_slice($like_info, 0, 9);
            $post_info['like_more'] = 'yes';
        }*/

        //获取10条最新评论
        $comments = array();
        $comments = $this->get_comment_info($postid, $this->user->uid, $limit);
        /*if ($post_info['comment']['total'] > $limit) {
            $post_info['comment']['is_end'] = false;
        } else {
            $post_info['comment']['is_end'] = true;
        }*/

        //获取所有用户的用户等级
        $uids = array();
        $userlevel = array();
        $uids[] = $post_info['uid'];
        if (!empty($comments['comment_list'])) {
            foreach ($comments['comment_list'] as $key => $value) {
                $uids[] = $value['uid'];
            }
        }
        $userlevel = $this->user->usergroup_level_by_uids($uids);

        $post_info['usergroup_level'] = $userlevel[$post_info['uid']];
        if (!empty($comments['comment_list'])) {
            foreach ($comments['comment_list'] as $key => $value) {
                $comments['comment_list'][$key]['usergroup_level'] = $userlevel[$value['uid']];
            }
        }
        $post_info['comment'] = $comments;

//        echo '<pre>';
//        print_r($post_info);
//        die();
        return $post_info;
    }

    /*public function first_img() {
        $postid = $this->input->post('postid');
        $result = array();
        $this->load->model('sharecircle/post_img_model', 'post_img');
        $result = $this->post_img->get_first_img($postid);
        if (empty($result)) {
            echo $this->json(0, '失败');
        } else {
            echo $this->json(1,'成功',$result);
        }
    }*/

    //帖子详情页(h5)
    public function post_detail($postid, $simulation = 0) {
        //禁言
        $is_banned = 'no';
        if (isset($_SERVER['HTTP_MOCUZAUTH']) && !empty($_SERVER['HTTP_MOCUZAUTH'])) {
            //已登录
            $user_groupid = $this->user->checkLogin($_SERVER['HTTP_MOCUZAUTH']);
            if (!empty($user_groupid) && in_array($user_groupid, $this->groupids_banned)) {
                $is_banned = 'yes';
            }
        } elseif ($simulation == '1') {
            //模拟登陆
            $this->user->uid = 'ceshi';
            $this->user->username = '测试用户';
        }

        $this->load->helper('my_api');
        $this->load->helper('url_helper');

        $post_info = array();
        $post_info = $this->get_post_detail($postid);

        $this->load->model('sharecircle/post_model', 'post');   //累积帖子浏览量
        $this->post->countAdd($postid);

        $post_info['is_banned'] = $is_banned;
        $post_info['sharelink'] = site_url() . '?/api/sharecircle/post/post_detail_share/' . $post_info['id'];

        $this->load->view('sharecircle/h5/post_detail', $post_info);
    }

    //滑动加载更多评论
    public function comment_more() {
        $postid = $this->input->post('postid');
        $uid = $this->input->post('uid');
        $total_showed = $this->input->post('total');

        $this->load->helper('my_api');
        $this->load->helper('url_helper');
        $limit = 10; //每页评论数
        $comment_info = array();
        $comment_info = $this->get_comment_info($postid, $uid, $limit, $total_showed);
        if (empty($comment_info['comment_list'])) {
            echo $this->json(0,'没有更多内容');
        }
        $comment_info['limit'] = $limit;
        if ($comment_info['total'] > $total_showed + count($comment_info['comment_list'])) {
            $comment_info['is_end'] = false;
        } else {
            $comment_info['is_end'] = true;
        }

        //获取所有用户的用户等级
        $uids = array();
        $userlevel = array();
        foreach ($comment_info['comment_list'] as $key => $value) {
            $uids[] = $value['uid'];
        }
        $userlevel = $this->user->usergroup_level_by_uids($uids);
        foreach ($comment_info['comment_list'] as $key => $value) {
            $comment_info['comment_list'][$key]['usergroup_level'] = $userlevel[$value['uid']];
        }

//        echo '<pre>';
//        print_r($comment_info);die();

        echo $this->json(1,'成功',$comment_info);
    }

    //获取评论内容
    public function get_comment_info($postid, $uid, $limit, $offset = 0) {
        $total = 0;
        $cids = array();
        $cids_liked = array();
        $comment_info = array();
        $this->load->model('sharecircle/comment_model', 'comment');
        $total = $this->comment->get_total_by_postid($postid);
        if ($total > 0 && $total > $offset) {
            $comment_info = $this->comment->get_by_postid($postid, $limit, $offset);
            //检测当前用户对这几条评论是否点赞过
            if (!empty($comment_info)) {
                $this->load->helper('my_api');
                foreach ($comment_info as $key => $value) {
                    $cids[] = $value['id'];
                    $comment_info[$key]['ctime_format'] = format_date($value['createtime']);
                    //添加用户等级
//                    $comment_info[$key]['usergroup_level'] = $this->user->usergroup_level($value['uid']);
                    $comment_info[$key]['content_smily'] = smiley_parse($value['content'], asset_url('h5/images/smilies'));
                }
                if (!empty($uid)) {
                    $this->load->model('sharecircle/comment_like_model', 'comment_like');
                    $cids_liked = $this->comment_like->is_liked_ids($uid, $cids);
                    foreach ($comment_info as $key => $value) {
                        if (!empty($cids_liked) && in_array($value['id'], $cids_liked)) {
                            $comment_info[$key]['is_liked'] = true;
                        } else {
                            $comment_info[$key]['is_liked'] = false;
                        }
                    }
                }
            }

        }
        return array('comment_list' => $comment_info, 'total' => $total);
    }

    public function smilies_switch() {
        $message = $this->input->post('message', true);
        $this->load->helper('my_api');
        $this->load->helper('url_helper');
        $message = smiley_parse($message, asset_url('h5/images/smilies'));
        echo $this->json(1,'成功',$message);
    }

    //关注
    public function follow() {
        $uid = $this->input->post('uid');
        $fuid = $this->input->post('fuid');
        $fusername = $this->input->post('fusername');

        $is_followed = null;
        $this->load->model('sharecircle/follow_model', 'follow');
        $is_followed = $this->follow->follow($uid, $fuid, $fusername);
        echo $this->json(1,'成功',array('is_followed' => $is_followed));
    }

    //点赞
    public function like() {
        $postid = $this->input->post('postid');
        $uid = $this->input->post('uid');
        $username = $this->input->post('username');
        $to_uid = $this->input->post('to_uid');
        if (empty($postid) || empty($uid) || empty($username) || empty($to_uid)) {
            echo $this->json(0, 'params error');
        }

        $this->load->model('sharecircle/post_like_model', 'post_like');
        $this->post_like->like($postid, $uid, $username);

        $this->load->model('sharecircle/post_model', 'post');
        $this->post->increase('likecount', $postid, 1);

        //添加话题参与记录表，相关话题人气+1，页显人数+1,参与人数（第一次参与）+1
        $this->update_part($postid, $uid, $username);

        //获取设备token用来推送
        $result = array();
        $device_info = array();
        $this->load->model('user_model');
        $device_info = $this->user_model->get_devicetoken($to_uid);
        if (!empty($device_info)) {
            $result['devicelist'] = base64_encode(json_encode($device_info));
        } else {
            $result['devicelist'] = '';
        }
//        $result['item'] = 'post_like';
        echo $this->json(1, '成功', $result);
    }

    //添加话题参与记录表，相关话题人气+1，页显人数+1,参与人数（第一次参与）+1
    public function update_part($postid, $uid, $username) {
        //先获取跟此贴相关的所有话题ID
        $ret = array();
        $tids = array();
        $topic_show = array();
        $this->load->model('sharecircle/topic_post_model', 'topic_post');
        $ret = $this->topic_post->get_tids_by_pid($postid);
        if (!empty($ret)) {
            foreach ($ret as $value) {
                $tids[] = $value['tid'];
            }
            //获取参与过的话题ID
            $this->load->model('sharecircle/topic_participation_model', 'participation');
            $tids_part = $this->participation->check_by_tids($tids, $uid);
            /*//获取这些话题的页显人数
            $topic_show = $this->topic->get_by_tids($tids, 'id, extracount');
            if (!empty($topic_show)) {
                foreach ($topic_show as $value) {
                    $tids_show[$value['id']] = $value['extracount'];
                }
            }*/

            $this->load->model('sharecircle/topic_model', 'topic');
            foreach ($tids as $tid) {
                //人气+1, 页显人数+1
                $param = array(
                    'buzzcount' => 1,
                    'extracount' => 1
                );
                //没参与过的话题，添加用户参与话题记录，话题参与人数+1
                if (!in_array($tid, $tids_part)) {
                    $param['involcount'] = 1;
                    $this->participation->insert(array(
                        'tid' => $tid,
                        'uid' => $uid,
                        'username' => $username,
                        'createtime' => time()
                    ));
                }
                $this->topic->increase_batch($param, $tid);
            }
        }
    }

    //获取帖子点赞用户
    public function post_like_users() {
        $postid = $this->get_param('postid');
        $users = array();
        $uids = array();
        $signatures = array();
        $user_signatures = array();
        $this->load->model('sharecircle/post_like_model', 'post_like');
        $this->load->model('user_model');
        $users = $this->post_like->get_by_postid($postid, 999999);
        if (!empty($users)) {
            foreach ($users as $key => $value) {
                $uids[] = $value['uid'];
            }
            $signatures = $this->user_model->get_user_signature_from_discuz($uids);
            if (!empty($signatures)) {
                foreach ($signatures as $value) {
                    $user_signatures[$value['uid']] = $value['sightml'];
                }
            }
            $avatar_head = UC_API."/avatar.php?";
            foreach ($users as $key => $value) {
                $users[$key]['avatar'] = $avatar_head . "uid=".$value['uid']."&size=small&random=".time();
                if (!empty($user_signatures[$value['uid']])) {
                    $users[$key]['signature'] = $user_signatures[$value['uid']];
                } else {
                    $users[$key]['signature'] = '这个人很懒，什么也没留下';
                }
            }
        }

//        echo '<pre>';
//        print_r($users);
        $this->odz_result(array('users' => $users));
    }

    //点赞客户端
    public function like_kh() {
        $user_groupid = $this->user->checkLogin($this->get_param('auth'));
        if (!$user_groupid) {
            $this->odz_error('User is not login');
        } elseif (in_array($user_groupid, $this->groupids_banned)) {
            $this->odz_error('您已被禁言');
        }
         /*if(!$this->user->checkLogin($this->get_param('auth'))){
            $this->odz_error('User is not login');
        }*/
        $uid = $this->user->uid;
        $username = $this->user->username;
        $postid = $this->get_param('postid');
        $to_uid = $this->get_param('to_uid');
        $this->load->model('sharecircle/post_like_model', 'post_like');
        $this->post_like->like($postid, $uid, $username);
        $this->load->model('sharecircle/post_model', 'post');
        $this->post->increase('likecount', $postid, 1);

        //添加话题参与记录表，相关话题参与人数+1，页显人数大于0（已使用）时+1
        $this->update_part($postid, $uid, $username);

        //获取设备token用来推送
        $result = array();
        $device_info = array();
        $this->load->model('user_model');
        $device_info = $this->user_model->get_devicetoken($to_uid);
        if (!empty($device_info)) {
            $result['pushstatus'] = 1;
            $result['devicelist'] = base64_encode(json_encode($device_info));
        }
        $this->odz_result($result);
    }
    //根据uid查询该用户发的所有的帖子
    public function get_posts_by_uid(){
        $this->load->helper('my_api');
        $this->load->helper('url_helper');
        $gag=0;//用户禁言与否
        $user_groupid=$this->user->checkLogin($this->get_param('auth'));
        if(!$user_groupid){
            if(!$this->get_param('uid')){
                $this->odz_error('User is not login');
            }
        }elseif (in_array($user_groupid, $this->groupids_banned)) {
            $gag=1;
        }
        $tpage=$this->get_param('page');
        $page = $tpage ? $tpage : 1;
        $page = $page < 1 ? 1 : $page;
        $pagesize=10;
        $offset = ($page - 1) * $pagesize;
        $uid = $this->get_param('uid') ? $this->get_param('uid') : $this->user->uid;
        $where=array();
        $where[]='isdelete=0';
        $where[]="uid=$uid";
        $fileds = 'id,uid,username,content,likecount,responsecount,createtime';
         $this->load->model('sharecircle/post_model', 'post');
        $post_pagecount=$this->post->get_count($where);
        $posts_info=$this->post->get_post_lists($where,$fileds,$pagesize,$offset);
        $uids=array();
        $postids=array();
         foreach ($posts_info as $he => $da) {
                $postids[]=$da['id'];
                $uids[]=$da['uid'];
            }
        if($postids){
            $uids=array_unique($uids);
            $this->load->model('sharecircle/post_like_model', 'post_like');
            $this->load->model('sharecircle/post_img_model', 'post_img');
            $this->load->model('sharecircle/comment_model', 'comment');
            $temp=$this->post_like->get_by_postids($postids);//点赞情况
            $userlevels=$this->user->get_usergroup_levels($uids);//用户等级
            //$topicid=$this->topic_post->get_tids_by_pids($postids);//帖子话题id
            $postimgs=array();
            $postimgs=$this->post_img->get_img_by_pids($postids,'');//帖子图片
            foreach ($posts_info as &$value) {
                $postimg=array();
                $value['showtime']=format_date($value['createtime']);
                $rep=$this->comment->get_by_postid($value['id'],6);//帖子回复
                // $temp=$this->post_like->get_by_postid($value['id'],'');
                // $topicid=$this->topic_post->get_tids_by_pid($value['id']);//帖子话题id
                // $postimgs=$this->post_img->get_post_img_by_postid($value['id']);
                if($postimgs){
                   foreach ($postimgs as $kit => $vit) {
                    if($vit['postid']==$value['id']){
                   $path_thumb=$vit['path'].".small.jpg";
                   $postimg[]=array('height'=>$vit['height'],'thumb'=>$path_thumb,'thumb_image'=>$vit['path'],'weight'=>$vit['width']);
                    }
                } 
                }
                $repls=array();
                $likeusername=array();
                $prat=0;//获取点赞图标亮否
                $praid='';//获取要点击点赞时的用户id
                if($temp){
                    foreach ($temp as $king => $box) {
                    if($box['postid']==$value['id']){
                    $likeusername[]=$box['username'];
                    if($box['uid']==$uid){
                        $prat=1;
                    }
                    }
                   
                } 
                }
                 if($prat==0){
                    $praid=$uid;
                }
                if($rep){
                   foreach ($rep as $k => $v) {
                       $repl=array();
                       $repl['author']=$v['username'];
                       $repl['authorid']= $v['uid'];
                       $repl['requtename']=$v['to_username'];
                       $repl['message']= $v['content'];
                       $repl['pid']= $v['postid'];
                       $repls[] = $repl;
                } 
                }
                $value['praiselist']=$likeusername;
                $value['message']=$value['content'];
                unset($value['content']);
                $value['sortlist']=$postimg;
                $value['pratimes']=count($temp);
                $value['prat']=$praid;
                $value['gag']=$gag;
                $value['praid']=$prat;
                $value['replies']=count($repls);
                $value['replylist']=$repls;
                $value['usergroup_level'] = $userlevels[$value['uid']];
                $value['avatar']=UC_API."/avatar.php?uid=".$value['uid']."&size=small&random=".time();
                $value['sharetext']="分享的内容";
                $value['weiurl']=base_url()."index.php?/api/sharecircle/post/post_detail_share/".$value['id'];
                $value['createtime']=format_date($value['createtime']);
                $value['authorid']=$value['uid'];
                $value['author']=$value['username'];
                unset($value['createtime']);
                unset($value['uid']);
                unset($value['username']);
            }
            unset($value);

        }
            $result['posts']=$posts_info;
            $result['posts_pagecount']=$post_pagecount;
            $result['posts_totalpage']=ceil($post_pagecount/$pagesize);
           $this->odz_result($result);

    }
    //热门帖子（人气）
    public function post_hot(){
            $result=array();
            $tpage=$this->get_param('page');
            $tpagesize=$this->get_param('pagesize');
            $pagesize=$tpagesize ? $tpagesize : 10;
            $page = $tpage ? $tpage : 1;
            $offset = ($page - 1) * $pagesize;
            $where=array();
            $hot_post=array();
            $temp=array();
            $this->load->model('sharecircle/post_model', 'post');
            $this->load->model('sharecircle/post_img_model', 'post_img');
            $this->load->model('sharecircle/post_like_model', 'post_like');
            $where[]='isdelete=0';
            $fileds = 'id,content,username,uid,readcount';
            $total=$this->post->get_count($where);
            $query=$this->post->get_post_list($where,$fileds, $pagesize, $offset);
            foreach ($query as $value) {
                $img=$this->post_img->get_img_by_pid($value['id']);
                $temp=$this->post_like->get_by_postid($value['id'],'');
                $hot_post[]=array(
                    'id'=>$value['id'],
                    'content'=>$value['content'],
                    'uid'=>$value['uid'],
                    'username'=>$value['username'],
                    'sortlist'=>array('height'=>$img[0]['height'],'thumb_image'=>$img[0]['path'],'weight'=>$img[0]['width']),
                    'readcount'=>$value['readcount'],
                    'likes'=>count($temp)
                    );
            }
            $result['hot_post']=$hot_post;
            $result['totalpage']=ceil($total/$pagesize);
            $this->odz_result($result);
    }



}
