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

class Topic extends Mocuz_Controller{
    private $source = array(
        '1' => '站长自建',
        '2' => '云话题',
        '3' => '用户自建',
        '4' => '全部'
    );
    public function __construct()
    {
        parent::__construct();
    }

//下发时把云平台图片存储到站台本地
public  function get_image($server_url,$temp){
     $this->load->helper('url');
     $path = './uploads/sharecircle/'. date('Ym') . '/' . date('d') . '/';
     $patha='/uploads/sharecircle/'. date('Ym') . '/' . date('d') . '/';
     if (!is_dir($path)) {
        mkdir($path,0777,true);
     }
     $random = date('His').rand(0,1000);
     $fen=explode('.', $server_url);

     $url = $path.$random.".".end($fen);
     $content = file_get_contents($server_url);
     file_put_contents($url, $content);
     $url=base_url().$patha.$random.".".end($fen);
     return $url;
}  
    //云话题
    public function cloud_topic($type_search='',$keywords_search='',$stime_search='', $etime_search='')
    { 
        $type_search = empty($type_search) ? (empty($_POST['type_search']) ? '' : $_POST['type_search']) : $type_search;
        $keywords_search = empty($keywords_search) ? (empty($_POST['keywords_search']) ? '' : $_POST['keywords_search']) : $keywords_search;
        $stime_search = empty($stime_search) ? (empty($_POST['stime_search']) ? '' : $_POST['stime_search']) : $stime_search;
        $etime_search = empty($etime_search) ? (empty($_POST['etime_search']) ? '' : $_POST['etime_search']) : $etime_search;
        //$pageSize = empty($pageSize) ? (empty($_POST['pageSize']) ? '' : $_POST['pageSize']) : $pageSize;
        $data = array();
        $id_list=array();
        $types = array();
        $params = array();
        $ret = array();
        $list_info = array();
        $para=array();
        $this->load->library('curl_data');
        $ret = $this->curl_data->get_topic_type($para);
        $type_count=count($ret['data']);
        $type_countb=count($ret['data'])+1;
        if(isset($ret['data'])&&$ret['data']){
        $quanbu=array($type_count=>array('id'=>$type_countb,'tname'=>'全部'));
        $ret['data']=array_merge($ret['data'],$quanbu);
        $data['topic_type'] = $ret['data'];
        }
       
        if (!empty($data['topic_type'])) {
            foreach ($data['topic_type'] as $value) {
                $types[$value['id']] = $value['tname'];
            }
        }
        $type_searchb=$type_search;
        //按搜索条件查询
        if( !empty($type_search)){
            if($type_search==$type_countb){
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }else{
                $where[]= "typeid = " . $type_search;
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }  
        }
        if( !empty($keywords_search)){
            $params['title'] = $keywords_search;
        }
        if( !empty($stime_search)){
            $params['beginTime'] = strtotime($stime_search);
        }
        if( !empty($etime_search)){
            $params['endTime'] =(strtotime($etime_search) + 24*60*60);
        }
        if($type_searchb==$type_countb){
            $type_searchb='';
        }
        $params['urlSite']="http://".$_SERVER['HTTP_HOST']."/";
        $params['topicTypeId'] = $type_searchb;
        $params['title']=$keywords_search;
        $params['beginTime']=$stime_search;
        $params['endTime']=$etime_search;
        //$params['host']=$_SERVER['HTTP_HOST'];

        $config ['uri_segment'] = 8;
        $offset = $this->uri->segment(8);
        // print_r($offset);
        if(isset($offset)&&!empty($offset)){
            $params['pageNow']=1;
            $arr =$this->curl_data->get_cloud_topic_list($params);
            $pageSize=$arr['page']['pageSize'];
            $params['pageNow']=intval($offset/$pageSize)+1;
        }else{
            $params['pageNow']=1;
        }
        
        if(empty($type_search)){
            $type_search=0;
        }
        if(empty($keywords_search)){
            $keywords_search=0;
        }
        if(empty($pageSize)){
            $pageSize=0;
        }
        if(empty($stime_search)){
            $stime_search=0;
        }
        if(empty($etime_search)){
            $etime_search=0;
        }
        //话题列表
        #配置分页信息
        $this->load->library('pagination');
        $config['base_url'] = site_url(
            'sharecircle/topic/cloud_topic/' . $type_search
            . '/' . $keywords_search . '/' . $stime_search . '/' . $etime_search
        );
        $list_info=$this->curl_data->get_cloud_topic_list($params);
        $config['total_rows'] = $list_info['page']['totalCount'];
        $config['per_page'] = $list_info['page']['pageSize'];
        $config['first_link'] = '首页';
        $config['first_tag_open'] = '<li id="first">';
        $config['first_tag_close'] = '</li>';
        $config['last_link'] = '末页';
        $config['last_tag_open'] = '<li id="last">';
        $config['last_tag_close'] = '</li>';
        $config['next_link'] = '下一页';
        $config['next_tag_open'] = '<li id="down">';
        $config['next_tag_close'] = '</li>';
        $config['prev_link'] = '上一页';
        $config['prev_tag_open'] = '<li id="top">';
        $config['prev_tag_close'] = '</li>';
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<div class="wrap"><div class="fenye"><ul>';
        $config['full_tag_close'] = '</ul></div></div>';
        #初始化分页类
        $this->pagination->initialize($config);
        #生成分页信息
        $data['pageinfo'] = $this->pagination->create_links();
          if (!empty($list_info['topicDataArray'])) {
            foreach ($list_info['topicDataArray'] as $key => $value) {
                if (!empty($types)) {
                    $list_info['topicDataArray'][$key]['type_name'] = $types[$value['typeid']];
                }else{
                    $list_info['topicDataArray'][$key]['type_name'] ='';
                }
            }
        }
        $fenyelist=array();
        $fenyelist['type_search']=$type_search;
        $fenyelist['keywords_search']=$keywords_search;
        $fenyelist['stime_search']=$stime_search;
        $fenyelist['etime_search']=$etime_search;
        $fenyelist['offset']=$offset;
        $data['val']=$fenyelist;
        $list=$list_info['topicDataArray'];
        $data['topic_list'] =$list;
        $this->load->view('common/innerheader');
        $this->load->view('sharecircle/cloud_topic',$data);
    }
    //云话题下发
    public function xf_topic(){
        $titles=array();
        $this->load->model('sharecircle/topic_model', 'topic');
        $tid=$this->input->post('tid');
        $tit=$this->input->post('titles');
        $titles=explode("||,", $tit);
        foreach ($titles as $king => $box) {
            $temp='';
            $temp=$this->topic->check_by_title($box);
            if($temp){
                 echo $this->json(0,'失败',0);
                 continue;
            }
        }
        $params=array();
        $topic_id=array();
        $params['tidList']= $tid;
        $params['urlSite']="http://".$_SERVER['HTTP_HOST']."/";
        $params['code']=rand(100,10000);
        $params['encode']=md5("2".$params['code']."8");
        $this->load->library('curl_data');
        $wsdl="http://yunhuati.mocuz.com:8080/serviceForOld/topicManagementController/getIssuedTopic.do";
        $rettopic =$this->curl_data->post($wsdl, $params, 0);
        $tipic=json_decode($rettopic,true);
        foreach ($tipic['topicIssuedDataArray'] as $key => $value) {
        $data=array();
        $data['uid']=$value['tid'];
        if($value['listimg']){
            $listimg=$this->get_image($value['listimg'],'listimg');
        }else{
            $listimg='';
        }
        if($value['detailimg']){
            $detailimg=$this->get_image($value['detailimg'],'detailimg');
        }else{
          $detailimg='';  
        }
        $data['listimg'] = $listimg;
        $data['detailimg'] = $detailimg;
        $data['title'] = $value['title'];
        $data['typeid'] = $value['typeid'];
        $data['sourceid'] = 2;
        $data['createtime'] =strtotime(date("Y-m-d H:i:s",time()));
        $topic_id[] =  $this->topic->insert($data);
        }
        echo $this->json(1,'成功',count($topic_id));         
    }


    //全部话题
    public function all_topic($type_search='',$keywords_search='',$source_search='',$stime_search='', $etime_search='')
    {
        $type_search = empty($type_search) ? (empty($_POST['type_search']) ? '' : $_POST['type_search']) : $type_search;
        $keywords_search = empty($keywords_search) ? (empty($_POST['keywords_search']) ? '' : $_POST['keywords_search']) : $keywords_search;
        $source_search = empty($source_search) ? (empty($_POST['source_search']) ? '' : $_POST['source_search']) : $source_search;
        $stime_search = empty($stime_search) ? (empty($_POST['stime_search']) ? '' : $_POST['stime_search']) : $stime_search;
        $etime_search = empty($etime_search) ? (empty($_POST['etime_search']) ? '' : $_POST['etime_search']) : $etime_search;
        $data = array();
        $types = array();
        $where = array();
//        echo $type_search;echo '<br>';echo $keywords_search;
        //话题类型
        $this->load->library('curl_data');
//        $ret = array(
//            'status' => 1,
//            'data' => array(
//                array('id' => 1, 'tname' => '骑车'),
//                array('id' => 2, 'tname' => '美容'),
//                array('id' => 3, 'tname' => '旅游'),
//                array('id' => 4, 'tname' => '回家'),
//                array('id' => 10, 'tname' => '其他'),
//            )
//        );
        $para=array();
        $this->load->library('curl_data');
        $ret = $this->curl_data->get_topic_type($para);
        // echo "<pre>";
        // print_r($ret['data']);die;
        $type_count=count($ret['data']);
        $type_countb=count($ret['data'])+1;
        $quanbu=array($type_count=>array('id'=>$type_countb,'tname'=>'全部'));
        if(isset($ret['data'])&&$ret['data']){
        $ret['data']=array_merge($ret['data'],$quanbu);
        $data['topic_type'] = $ret['data'];
        }
        if (!empty($data['topic_type'])) {
            foreach ($data['topic_type'] as $value) {
                $types[$value['id']] = $value['tname'];
            }
        }

        //按搜索条件查询
        $keywords_search=urldecode($keywords_search);
        if( !empty($type_search)){
            if($type_search==$type_countb){
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }else{
                $where[]= "typeid = " . $type_search;
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }  
        }
        if( !empty($keywords_search)){
            $where[]= "title like '%" . $keywords_search . "%'";
        }
        if( !empty($source_search)){
            if($source_search==4){
                //显示搜索选项
            $data['source_name_search'] = $this->source[$source_search];
            }else{
                $where[]= "sourceid = " . $source_search;
            //显示搜索选项
            $data['source_name_search'] = $this->source[$source_search];
            } 
        }
        if( !empty($stime_search)){
            $where[]= "createtime >= " . strtotime($stime_search);
        }
        if( !empty($etime_search)){
            $where[]= "createtime < " . (strtotime($etime_search) + 24*60*60);
        }
        $where[] = "isdelete = 0";
        //话题列表
        #配置分页信息
        $this->load->library('pagination');
        if(empty($type_search)){
          $type_search=0;
        }
        if(empty($keywords_search)){
          $keywords_search=0;
        }
        if(empty($source_search)){
           $source_search=0;
        }
        if(empty($stime_search)){
            $stime_search=0;
        }
        if(empty($etime_search)){
            $etime_search=0;
        }
        $config['base_url'] = site_url(
            'sharecircle/topic/all_topic/' . $type_search
            . '/' . $keywords_search . '/' . $source_search
            . '/' . $stime_search . '/' . $etime_search
        );
        $config ['uri_segment'] = 9;
        $offset = $this->uri->segment(9);
        $this->load->model('sharecircle/topic_model', 'topic');
        $config['total_rows'] = $this->topic->total($where);
//        $config['per_page'] = 50;
//        $config['uri_segment'] = 4;
        $config['per_page'] = 15;

        $config['first_link'] = '首页';
        $config['first_tag_open'] = '<li id="first">';
        $config['first_tag_close'] = '</li>';

        $config['last_link'] = '末页';
        $config['last_tag_open'] = '<li id="last">';
        $config['last_tag_close'] = '</li>';

        $config['next_link'] = '下一页';
        $config['next_tag_open'] = '<li id="down">';
        $config['next_tag_close'] = '</li>';

        $config['prev_link'] = '上一页';
        $config['prev_tag_open'] = '<li id="top">';
        $config['prev_tag_close'] = '</li>';
        $config['num_links'] = 15;

        $config['full_tag_open'] = '<div class="wrap"><div class="fenye"><ul>';
        $config['full_tag_close'] = '</ul></div></div>';

        #初始化分页类
        $this->pagination->initialize($config);

        #生成分页信息
        $data['pageinfo'] = $this->pagination->create_links();
        $limit = $config["per_page"];
        $fields = "id,title,typeid,sourceid,extracount,buzzcount,involcount,concerncount,isrec,createtime";

        $list_info = $this->topic->get_topic_list($where, $fields, $limit, $offset);
        $this->load->helper('my_api');
        if (!empty($list_info)) {
            foreach ($list_info as $key => $value) {
                if (!empty($types)) {
                    $list_info[$key]['type_name'] = $types[$value['typeid']];
                }else{
                    $list_info[$key]['type_name'] ='';
                }
                $list_info[$key]['title'] = $value['title'];
                $list_info[$key]['source_name'] = $this->source[$value['sourceid']];
                $list_info[$key]['create_time'] = date('Y-m-d H:i:s', $value['createtime']);
            }
        }
        $data['topic_list'] = $list_info;
        $fenyelist=array();
        $fenyelist['type_search']=$type_search;
        $fenyelist['keywords_search']=$keywords_search;
        $fenyelist['source_search']=$source_search;
        $fenyelist['stime_search']=$stime_search;
        $fenyelist['etime_search']=$etime_search;
        $fenyelist['offset']=$offset;
        $data['val']=$fenyelist;
        $data['fenyelist']=json_encode($fenyelist);
        $this->load->view('common/innerheader');
        $this->load->view('sharecircle/all_topic',$data);
    }

    //推荐话题管理
    public function recommend($type_search='',$keywords_search='',$source_search='',$stime_search='', $etime_search='')
    {
        $type_search = empty($type_search) ? (empty($_POST['type_search']) ? '' : $_POST['type_search']) : $type_search;
        $keywords_search = empty($keywords_search) ? (empty($_POST['keywords_search']) ? '' : $_POST['keywords_search']) : $keywords_search;
        $source_search = empty($source_search) ? (empty($_POST['source_search']) ? '' : $_POST['source_search']) : $source_search;
        $stime_search = empty($stime_search) ? (empty($_POST['stime_search']) ? '' : $_POST['stime_search']) : $stime_search;
        $etime_search = empty($etime_search) ? (empty($_POST['etime_search']) ? '' : $_POST['etime_search']) : $etime_search;
        $data = array();
        $types = array();
        $where = array();
        //话题类型
        $para=array();
        $this->load->library('curl_data');
        $ret = $this->curl_data->get_topic_type($para);
        $type_count=count($ret['data']);
        $type_countb=count($ret['data'])+1;
        if(isset($ret['data'])&&$ret['data']){
        $quanbu=array($type_count=>array('id'=>$type_countb,'tname'=>'全部'));
        $ret['data']=array_merge($ret['data'],$quanbu);
        $data['topic_type'] = $ret['data'];
            }
        if (!empty($data['topic_type'])) {
            foreach ($data['topic_type'] as $value) {
                $types[$value['id']] = $value['tname'];
            }
        }

        //按搜索条件查询
          if( !empty($type_search)){
            if($type_search==$type_countb){
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }else{
                $where[]= "typeid = " . $type_search;
                  //显示搜索选项
            $data['type_name_search'] = $types[$type_search];
            }  
        }
        if( !empty($keywords_search)){
            $where[]= "title like '%" . $keywords_search . "%'";
        }
           if( !empty($source_search)){
            if($source_search==4){
                //显示搜索选项
            $data['source_name_search'] = $this->source[$source_search];
            }else{
                $where[]= "sourceid = " . $source_search;
            //显示搜索选项
            $data['source_name_search'] = $this->source[$source_search];
            } 
        }
        if( !empty($stime_search)){
            $where[]= "createtime >= " . strtotime($stime_search);
        }
        if( !empty($etime_search)){
            $where[]= "createtime < " . (strtotime($etime_search) + 24*60*60);
        }
        $where[] = "isrec = 1";
        $where[] = "isdelete = 0";

        //话题列表
        #配置分页信息
        if(empty($type_search)){
           $type_search=0;
        }
        if(empty($keywords_search)){
           $keywords_search=0;
        }
        if(empty($source_search)){
           $source_search=0;
        }
        if(empty($stime_search)){
           $stime_search=0;
        }
        if(empty($etime_search)){
           $etime_search=0;
        }
        $this->load->library('pagination');
        $config['base_url'] = site_url(
            'sharecircle/topic/recommend/' . $type_search
            . '/' . $keywords_search . '/' . $source_search
            . '/' . $stime_search . '/' . $etime_search
        );
        $offset = $this->uri->segment(9);
        $this->load->model('sharecircle/topic_model', 'topic');
        $config['total_rows'] = $this->topic->total($where);
        $config['per_page'] = 15;

        $config['first_link'] = '首页';
        $config['first_tag_open'] = '<li id="first">';
        $config['first_tag_close'] = '</li>';

        $config['last_link'] = '末页';
        $config['last_tag_open'] = '<li id="last">';
        $config['last_tag_close'] = '</li>';

        $config['next_link'] = '下一页';
        $config['next_tag_open'] = '<li id="down">';
        $config['next_tag_close'] = '</li>';

        $config['prev_link'] = '上一页';
        $config['prev_tag_open'] = '<li id="top">';
        $config['prev_tag_close'] = '</li>';
        $config['num_links'] = 15;

        $config['full_tag_open'] = '<div class="wrap"><div class="fenye"><ul>';
        $config['full_tag_close'] = '</ul></div></div>';

        #初始化分页类
        $this->pagination->initialize($config);

        #生成分页信息
        $data['pageinfo'] = $this->pagination->create_links();
        $limit = $config["per_page"];
        $fields = "id,title,typeid,sourceid,extracount,buzzcount,involcount,concerncount,isrec,createtime";

        $list_info = $this->topic->get_topic_list($where, $fields, $limit, $offset);
        if (!empty($list_info)) {
            foreach ($list_info as $key => $value) {
                if (!empty($types)) {
                    $list_info[$key]['type_name'] = $types[$value['typeid']];
                }else{
                    $list_info[$key]['type_name'] ='';
                }
                $list_info[$key]['source_name'] = $this->source[$value['sourceid']];
                $list_info[$key]['create_time'] = date('Y-m-d H:i:s', $value['createtime']);
            }
        }
        $data['topic_list'] = $list_info;
         $fenyelist=array();
        $fenyelist['type_search']=$type_search;
        $fenyelist['keywords_search']=$keywords_search;
        $fenyelist['source_search']=$source_search;
        $fenyelist['stime_search']=$stime_search;
        $fenyelist['etime_search']=$etime_search;
        $fenyelist['offset']=$offset;
        $data['val']=$fenyelist;
//        print_r($types);
        $this->load->view('common/innerheader');
        $this->load->view('sharecircle/recommend',$data);
    }

    public function recommend_topic()
    {
        $this->load->model('sharecircle/topic_model', 'topic');
        $this->topic->update(array('isrec' => 1), $this->input->post('tid'));
        echo $this->json(1,'成功');
    }

    public function cancel_rec()
    {
        $this->load->model('sharecircle/topic_model', 'topic');
        $this->topic->update(array('isrec' => 0), $this->input->post('tid'));
        echo $this->json(1,'成功');
    }

    public function del_topic()
    {
        $ids = $this->input->post('tids');
        $this->load->model('sharecircle/topic_model', 'topic');
        $this->topic->bantch_delete($ids);
        echo $this->json(1,'成功');
    }

    public function new_topic(){
//        $base_url = base_url();
        $data = array();
        $para=array();
        $this->load->library('curl_data');
        $ret = $this->curl_data->get_topic_type($para);
        $data['topic_type'] = $ret['data'];
//        print_r($data);
//        die();
        $this->load->view('common/innerheader',$data);
        $this->load->view('sharecircle/new_topic',$data);
        $this->load->view('common/footer');
    }

    public function new_ct_topic(){

    }


    public function update_topic(){
        $tid=$this->input->post('tid');
        $fenye=$this->input->post('fenye');
        $data = array();
        $para=array();
        $this->load->library('curl_data');
        $ret = $this->curl_data->get_topic_type($para);
        $data['topic_type'] = $ret['data'];
        if (!empty($tid)) {
            $this->load->model('sharecircle/topic_model', 'topic');
            $data['topic_info'] = $this->topic->get_one($tid,'');
//            $data['topic_info']['listimg_array'] = explode(',', $data['topic_info']['listimg']);
//            $data['topic_info']['detailimg_array'] = explode(',', $data['topic_info']['detailimg']);
        }
//        echo '<pre>';
//        print_r($data);
//        die();
        $data['fenye']=$fenye;
        $this->load->view('common/innerheader',$data);
        $this->load->view('sharecircle/update_topic',$data);
        $this->load->view('common/footer');
    }

    public function pic_delete(){
        echo '{}';
    }

    public function save_topic($id = ''){
        $param = $_POST;
        $fenye=isset($_POST['fenyelist']) ? $_POST['fenyelist'] : null;
        if(isset($fenye)&&$fenye){
            $fenyelist=json_decode($fenye,true);
            $fenyelist['keywords_search']=urldecode($fenyelist['keywords_search']);
        }
        $data = array();
        $rules_config = array(
            array(
                'field' => 'title',
                'label' => '标题',
                'rules' => 'trim|required|max_length[255]'
            ),
            array(
                'field' => 'typeid',
                'label' => '类型',
                'rules' => 'trim|required'
            ),
        );

        $this->load->library('form_validation', $rules_config);
        $this->form_validation->set_data($param);


        if($this->form_validation->run() == FALSE)
        {
            print_r($this->form_validation->error_array());
        }
        else
        {
            $data['listimg'] = $param['listimg'];
            $data['detailimg'] = $param['detailimg'];
//            $data['listimg'] = implode('|', $param['listimgs']);
//            $data['detailimg'] = implode('|', $param['detailimgs']);
            $data['title'] = $param['title'];
            $data['typeid'] = $param['typeid'];
            $data['sourceid'] = 1;
            $data['extracount'] = isset($param['extracount']) ? $param['extracount'] : 0;
            $data['createtime'] = time();
            $this->load->model('sharecircle/topic_model', 'topic');
            $topic_id = $id ? $this->topic->update($data, $id) : $this->topic->insert($data);
        }
        if(!$fenye){
            redirect('sharecircle/topic/all_topic');
        }
         if(empty($fenyelist['offset'])){
                   redirect("sharecircle/topic/all_topic/".$fenyelist['type_search'].'/'.$fenyelist['keywords_search'].'/'.$fenyelist['source_search'].'/'.$fenyelist['stime_search'].'/'.$fenyelist['etime_search']); 
                }else{
                    redirect("sharecircle/topic/all_topic/".$fenyelist['type_search'].'/'.$fenyelist['keywords_search'].'/'.$fenyelist['source_search'].'/'.$fenyelist['stime_search'].'/'.$fenyelist['etime_search'].'/'.$fenyelist['offset']); 
                }
        }
        
   

    public function upload_topic($mode){
        $path = '/uploads/sharecircle/' . date('Ym') . '/' . date('d') . '/';
        $config['upload_path']      = FCPATH . $path;
        if (!is_dir($config['upload_path'])) {
            mkdir($config['upload_path'],0777,true);
        }
        $config['allowed_types']    = 'gif|jpg|png';
        $url = base_url();
        $config['file_name'] = date('YmdHis').rand(0,1000);
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('avatar'))
        {
            $error = array('error' => $this->upload->display_errors());
            echo json_encode($error);exit;
        } else {
            $data = $this->upload->data();
            $url = $url.$path.$data['file_name'];

            $thumconfig['image_library'] = 'gd2';
            $thumconfig['maintain_ratio'] = TRUE;
            $thumconfig['source_image'] = FCPATH.$path.$data['file_name'];
            if($mode =="pic")
            {
                $thumconfig['width']     = 720;
                $thumconfig['height']   = 403;
            } elseif ($mode =="small_pics")
            {
                $thumconfig['width']     = 202;
                $thumconfig['height']   = 148;
            }
            $this->load->library('image_lib', $thumconfig);
            $this->image_lib->resize();
            list($width, $height, $type, $attr) = getimagesize($url);
//            $pic['url'] = $url.'|'.$width.'|'.$height;
            $pic['url'] = $url;
            echo json_encode($pic);
            exit;
        }
    }

    public function goback(){
        $param = $_POST;
        $fenye=$_POST['fenyelistback'];
        if(isset($fenye)&&$fenye){
            $fenyelist=json_decode($fenye,true);
            $fenyelist['keywords_search']=urldecode($fenyelist['keywords_search']);
        }
        if(!$fenye){
            redirect('sharecircle/topic/all_topic');
        }
         if(empty($fenyelist['offset'])){
                   redirect("sharecircle/topic/all_topic/".$fenyelist['type_search'].'/'.$fenyelist['keywords_search'].'/'.$fenyelist['source_search'].'/'.$fenyelist['stime_search'].'/'.$fenyelist['etime_search']); 
                }else{
                    redirect("sharecircle/topic/all_topic/".$fenyelist['type_search'].'/'.$fenyelist['keywords_search'].'/'.$fenyelist['source_search'].'/'.$fenyelist['stime_search'].'/'.$fenyelist['etime_search'].'/'.$fenyelist['offset']); 
                }
        }


}
