<?php
/**
 * 资讯模块
 * @copyright reginx.com
 * $Id$
 */
class art_mod extends mogvs_mod {
    
	public function __call($p1, $p2){
		$sname = substr($p1, 0, -3);
        $sname = filter::text(str_replace(' ' , '' , $sname));
		if(preg_match('/^[0-9a-zA-Z\_\-]+$/i', $sname)){
			$art = art_lib::get($sname);
			if(empty($art)){
				$this->show404(1 , '该资讯不存在 !');
			}
			if(!empty($art['tag'])){
			    $art['tag'] = explode(',' , $art['tag']);
			    $art['tag'] = OBJ('tag_tab')->fields("id,name")->rkey('id')->where("name in ('" . join("','" , $art['tag']) ."')")->getall();
			    if(isset($this->conf['utype']) && $this->conf['utype']){
			        // 默认英文url模式
			        foreach ((array)$art['tag'] as $k => $v){
			            $art['tag'][$k]['url'] = core::url('tag-%s' , $v['name']);
			        }
			    }else{
			        // 数字模式
			        foreach ((array)$tmp as $k => $v){
			            $art['tag'][$k]['url'] =  core::url('tag-%d' , $v['id']);
			        }
			    }
			}
			$cat = api_lib::getcat($art['cat']);
			$this->assign('cat', $cat);
			$active = $urhere = array();
			if(!empty($cat['pcat'])){
				foreach($cat['pcat'] as $k => $v){
					if(empty($active)){
						$active = $k;
					}
					$urhere[$k] = $v['name'];
				}
			}else{
				$active = $cat['sname'];
			}
			$urhere[$cat['sname']] = $cat['name'];
			$urhere['cur'] =  $art['name'];
			$views = $this->get('vart' , 'C');
			if(!isset($views[$art['id']])){
			    core::getobj('art_tab')->exec("update art_tab set views = views + 1 where id = {$art['id']}");
			    setcookie ("vart[{$art['id']}]", REQUEST_TIME , REQUEST_TIME + 86400);
			}
			$this->assign('active', 'art');
			$this->assign('urhere', $urhere);
			$this->assign('ptitle', $art['name'] . '_' . $cat['name'] . '_资讯');
			$this->assign('skey'  , $art['key']);
			$this->assign('sdesc' , $art['name'] . $cat['name'] . ',' . $art['desc']);
			$this->assign('art'   , $art);
			$this->assign('np'    , art_lib::getnp($art['id'] , $art['cat']));
			$this->display('art/art.tpl.html');
		}
		$this->show404(1 , '该资讯不存在 !');
	}
}
?>