<?php
class tagAction extends FirstendAction {	
	public function _initialize() {
        parent::_initialize();	
		$this->assign('cid', 'tag');		
		$map['status'] = 1;
		$catelist = D('article_cate')->where($map)->order('ordid asc')->select();
		foreach ($catelist as $key => $val) {
			$catelist[$key] = $val;
		}		
		$this->assign('catelist', $catelist);
		$res = D('article_cate')->field('id,name,ename')->select();
		$cate_list = array();
            foreach ($res as $val) {
                $cate_list[$val['id']] = array($val['name'],$val['ename']);
            }
		$this->_catelist = 	$cate_list;
		$hot = $this->gethot();
		$new = $this->getnew();
		$this->assign('hot', $hot);	
		$this->assign('new', $new);
    }	
	
	public function index(){
		$p = I('p',1, 'intval');
		$page_size = 600;				
		$start = $page_size * ($p - 1) ;		
		$item_list = D('tag')->field('id,k')->order('id desc')->limit($start . ',' . $page_size)->select();
		$this->assign('item_list',$item_list);
		$count = D('tag')->count();		
		$pager = $this->_pager($count, $page_size);
        $page = $pager->share_show();
		$page = str_replace('/tag/index/p/','/rss/',$page);
		$this->assign('page',$page);
		$this->assign('p',$p);		
		$page_seo=array(
			'title' => '热门搜索关键词',
        );
		$this->assign('page_seo', $page_seo);
		$this->display();	
	} 	
	public function gethot(){
		$where['status'] = 1;
		$where['fabu'] = 1;	
		if(C('ftx_img_put')==2){
		$where['mpic'] = array('exp','is not null');
		}
		$item_list = D('article')->where($where)->order('hits desc')->limit(0,8)->select();		
		foreach($item_list as $key=>$val){    
            $item_list[$key] = $val;					
			$item_list[$key]['add_time'] = date('Y-m-d',$val['add_time']);				
			if(C('ftx_a_link')=='md5'){
			$vid = $val['mid'];	
			}else{
			$vid = $val['id'];	
			}
			if(C('ftx_img_put')==1){
			if(!$val['mpic']){	
			$item_list[$key]['pic'] = '/?m=images&id='.$vid.'.'.C('ftx_img_type');	
			}else{
			$item_list[$key]['pic'] = $val['mpic'];		
			}			
			}
			if(C('ftx_img_put')==2){
			$item_list[$key]['pic'] = $val['mpic'];	
			}
			if(C('ftx_url_set')==1){
			$upt = $this->_catelist[$val['cate_id']][1];		
			}else{
			if(C('ftx_c_name')){
			$upt = C('ftx_c_name');	
			}else{
			$upt = 'wen';		
			}			
			}
			$url = '/'.$upt.'/'.$vid.C('URL_HTML_SUFFIX');
			$item_list[$key]['url'] = $url;
        }
		return $item_list;
	}
	public function getnew(){
		$where['status'] = 1;
		$where['fabu'] = 1;	
		if(C('ftx_img_put')==2){
		$where['mpic'] = array('exp','is not null');
		}
		$item_list = D('article')->where($where)->order('id desc')->limit(0,8)->select();		
		foreach($item_list as $key=>$val){    
            $item_list[$key] = $val;				
			$item_list[$key]['add_time'] = date('Y-m-d',$val['add_time']);					
			if(C('ftx_a_link')=='md5'){
			$vid = $val['mid'];	
			}else{
			$vid = $val['id'];	
			}
			if(C('ftx_img_put')==1){
			if(!$val['mpic']){	
			$item_list[$key]['pic'] = '/?m=images&id='.$vid.'.'.C('ftx_img_type');	
			}else{
			$item_list[$key]['pic'] = $val['mpic'];		
			}			
			}
			if(C('ftx_img_put')==2){
			$item_list[$key]['pic'] = $val['mpic'];	
			}
			if(C('ftx_url_set')==1){
			$upt = $this->_catelist[$val['cate_id']][1];		
			}else{
			if(C('ftx_c_name')){
			$upt = C('ftx_c_name');	
			}else{
			$upt = 'wen';		
			}			
			}
			$url = '/'.$upt.'/'.$vid.C('URL_HTML_SUFFIX');
			$item_list[$key]['url'] = $url;
        }
		return $item_list;
	}
	
	
}
?>
