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

class News extends Api_Controller{
   
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('my_api');
        $this->load->model('news_model');
       
    }

    public function shownews_list()
    {

        //$page=$this->input->post('page');
        $tpage=$this->get_param('page');
        $page = $tpage ? $tpage : 1;
        //$uid=1989;
        $page = $page < 1 ? 1 : $page;
        $result=array();
        $temp=array();
        $pic=array();
        //$data['page']=$page;
        $limit = 20;
        $offset=($page-1)*10;
        $temp=$this->news_model->getlist_jiekou($limit,$offset);
        $attacurlkey=$this->news_model->getattacurl(1);
        $attacurlkey=unserialize($attacurlkey);
        if($attacurlkey['on']==0){
           $attacurl=$this->news_model->getattacurl(0);
           $attacurl="http://".$_SERVER['HTTP_HOST'].'/'.$attacurl.'/';
        }else{
           $attacurl="http://".$attacurlkey['host'].'/'.$attacurlkey['attachurl'].'/';
        }
        foreach ($temp as $key=>$value) {
            if($value['pictype']==0){
                $pic=$attacurl.$value['pic'];
                $pics=array();
            }elseif($value['pictype']==1){
                $pic=json_decode($value['pic'],true);
                $pic=$pic[0];
                $pics=array();
            }else{
                $pic='';
                $pics= json_decode($value['pic'],true);  
            }
           $result[]=array('tid'=>$value['id'],"subject"=>$value["title"],"pic"=>$pic,"pics"=>$pics,"date"=>format_date($value['create_time']),'views'=>$value['views']);
             } 
            $this->odz_result(array('newslist'=>$result));
    }
}
