<?php

//标签页
class tagsMod extends commonMod
{
    public function __construct()
    {
        parent::__construct();

    }

    //标签点击记录
    public function index()
    {
        
		if (is_numeric($_GET[0])) {
		$tag_get = $_GET[0];
		$condition["id"] = $tag_get;
		}else{
		$tag_get = in(urldecode($_GET[0]));

        if(!is_utf8($tag_get))     
        {         
        $tag_get=auto_charset($tag_get,'gbk','utf-8');     
        } 
		$condition["tag"] = $tag_get;
		}
		
        if (empty($tag_get)) {
            $this->error404();
        }
        
        $tag = $this->model->table('content_tag')->where($condition)->find();

        if (empty($tag['id'])) {
            $this->errormsg('无此TAG信息');
        }
        
        if (empty($tag['aid'])) {
            $this->errormsg('无此TAG相关文章');
        }
        
        $listRows = 20;
        
        $url = __URL__ . '/index/'.$tag['id'].'-page-{page}.html'; //分页基准网址
        $page = new Page();
        $cur_page = $page->getCurPage($url);
        $limit_start = ($cur_page - 1) * $listRows;
        $limit = $limit_start . ',' . $listRows;
        
        $where = 'WHERE A.id in (' . $tag['aid'] . ')';
        $sql = "SELECT A.*,B.pid,B.type as ctype,B.name as cname,B.seoname as cseoname,B.pinyin as cpinyin FROM {$this->model->pre}content A LEFT JOIN {$this->model->pre}channel B ON A.cid=B.id {$where} ORDER BY A.hits DESC, A.id DESC LIMIT {$limit}";//查询tag的文章信息
        $loop = $this->model->query($sql); //执行查询
        
        $count = $this->model->table('content')->where('id in ('.$tag['aid'].')')->count();
        
        $data['hot'] = in($tag['hot']) + 1; //点击数+1
        $this->model->table('content_tag')->data($data)->where('id=' . $tag['id'])->update();
        
        $this->assign('info', $tag);
        $this->assign('loop', $loop); //内容循环
        $this->assign('page', $this->page($url, $count, $listRows));
        
        if($this->config['LANG_OPEN']==1){
        $this->display(__LANG__.'/tags');
        }else{
        $this->display('tags');
        }

    }


}

?>