News.class.php 4.94 KB
<?php
/**
 * 默认控制器
 */
class Controller_News extends Controller_Abstract
{
    
    public function indexAction()
    {
        $requestTag =  trim($this->_request->tag);//标签
        $limit = 40;
        $tag = $requestTag;
        if($requestTag == '视频')
        {
        	//html5视频为手机视频
        	if($this->_platform == 'android' || $this->_platform == 'iphone')
        	{
        		$tag = '手机视频';
        	}
        }
        if($this->_platform == 'android' || $this->_platform == 'iphone')
        {
        	$exceptTags = array('视频');
        }
        else
        {
        	$exceptTags = array('手机视频');
        }
        $total = Facade_News::getTotal($tag, $exceptTags);
        $page = new Lib_Helper_Pagination($total, $limit);
        if ($tag)
        {
            $page->setParames(array('tag' => $requestTag)) ;
        }
        $tagKeys = Facade_News::$types;
        $list = Facade_News::getList($tag, $page->getOffset(), $limit, $exceptTags);
        $this->_view['list'] = $list;
        $newTags = Facade_News::getTags();
        $this->_view['total'] = 0;
        $tags = array();
        foreach($tagKeys as $tagKey)
        {
        	$tags[$tagKey] = array('tag' => $tagKey, 'num'=> 0);
        	foreach($newTags as $newTag)
        	{
        		if($newTag['tag'] == '手机视频')//手机视频变成视频,HTML5
        		{
        			$newTag['tag'] = '视频';
        		}
        		if($tagKey == $newTag['tag'])
        		{
        			 $tags[$tagKey] = $newTag;
        		}
        	}	
        }
        $this->_view['tags'] = $tags;
        foreach($this->_view['tags'] as $val)
        {
        	$this->_view['total']  += $val['num'];
        }
        $page->setOptions(array('afterAppend' => 'setLayout'));
        $this->_view['pagination'] = $page->getPagination();
        $this->_view['current_tag'] = $requestTag;
        /***设置网站的SEO信息***/
        $seo = C('APP.Seo');
        $this->setTitle($seo['channel_news_title']);
        $this->setKeywords($seo['channel_news_keywords']);
        $this->setDescription($seo['channel_news_description']);
        $seo = null; unset($seo);
    }
    
    public function getnewsAction()
    {
    	$tag = $this->_request->query('tag','');
    	$total = Facade_News::getTotal($tag);
    	$page = new Lib_Helper_Pagination($total);
    	list($offset, $limit) = $page->getLimit();
    	$page->setPageSize($limit)->setParames(array('tag' => $tag))->setModel('autoload2', '#img_flow')
    	->setOptions(array('afterAppend' => 'setLayout'));
    	if(!empty($tag))
    	{
    		$list = Facade_News::getList(tag, $page->getOffset(), $limit);
    	}
    	else
    	{
    		$list = Facade_News::getAllNews($page->getOffset(), $limit);
    	}
    	$this->_view['list'] = $list;
    	$this->_view['pagination'] = $page->getPagination();
    }
    
    /**
     * 详情页
     */
    public function detailAction()
    {
        $id = intval($this->_request->id);
        if (empty($id))
        {
            return $this->_redirect('news/index');
        }
        $info = Facade_News::getOneById($id);
        if (!$info)
        {
            return $this->_redirect('news/index');
        }
        $info['title'] = strip_tags($info['title']);
        //增加浏览量
        Facade_News::updateHits($id);
        
        //获取上一个
        $prev = Facade_News::getPrevNews($id);
        if ($prev)
        {
            if ($prev['thumb'])
            {
                $thumb = Lib_Images::getImageUrl($prev['thumb'], '0138x0075','fragmentimg'); 
            }
            else
            {
                $thumb = SITE_IMG.'/pic01.png';
            }
            $prev['thumb'] = $thumb ;
            $prev['title'] = Util_StringHelper::substr_cn( $this->stripTags($prev['title']),20 );
            $prev['desc'] = Util_StringHelper::substr_cn( $this->stripTags($prev['content']),40 );
            
        }  
        //获取下一个
        $next = Facade_News::getNextNews($id);
        if ($next)
        {
            if ($next['thumb'])
            {
                $thumb = Lib_Images::getImageUrl($next['thumb'], '0138x0075','fragmentimg'); 
            }
            else
            {
                $thumb = SITE_IMG.'/pic01.png';
            }
            $next['thumb'] = $thumb ;
            $next['title'] = Util_StringHelper::substr_cn( $this->stripTags($next['title']),20 );
            $next['desc'] = Util_StringHelper::substr_cn( $this->stripTags($next['content']),40 );
        }
        $this->_view['tags'] = Facade_News::$types;
        $this->_view['next'] = $next ; 
        $this->_view['prev'] = $prev ; 
        $this->_view['info'] = $info ;
        $this->_view['current_tag'] = $this->_request->query('current_tag', '');
        /***设置网站的SEO信息***/
        $seo = C('APP.Seo');
        $this->setTitle($info['title']);
        $this->setKeywords($seo['channel_news_keywords']);
        $this->setDescription($seo['channel_news_description']);
    }
}