<?php
class InfoAction extends HomeBaseAction {
	//信息首页
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
        $this->display();
    }
    
    //显示信息
    public function read(){
    	header("Content-Type:text/html; charset=utf-8");
    	$m = D('Admin/Info');
    	$data = $m->findinfo($_GET['id']);
    	if(!$data){
    		$this->_empty('read');
    		exit();
    	}
    	$id = $data['InfoID'];
    	//判断频道是否禁用，频道禁用后，不能查看频道的信息
    	$ChannelID = $data['ChannelID'];
    	$mc = D('Admin/Channel');
    	if( !$mc->ChannelIsEnable($ChannelID) ){
    		$this->_empty('read');
    		exit();
    	}
    	
    	$m->IncHit($id); //文章点击次数加1
    	
    	//频道优化设置, 会覆盖网站设置    	
    	$this->assign('InfoID', $data['InfoID']);
    	$this->assign('ChannelID', $ChannelID );
    	$this->assign('ChannelName', ChannelName($ChannelID) );
    	$this->assign('ChannelUrl', ChannelUrl($ChannelID) );
    	$this->assign('ChannelSName', ChannelSName($ChannelID) );
    	$this->assign('SpecialID', $data['SpecialID']);
    	$this->assign('InfoTitle', $data['InfoTitle']);
    	
    	//$this->assign('HasPicture', $data['HasPicture']);
    	$this->assign('InfoPicture', $data['InfoPicture']);
    	//$this->assign('ReadLevel', $data['ReadLevel']);
    	//$this->assign('IsLinkUrl', $data['IsLinkUrl']);
    	$this->assign('LinkUrl', $data['LinkUrl']);
    	$this->assign('InfoTime', $data['InfoTime']);
    	$this->assign('InfoAuthor', $data['InfoAuthor']);
    	
    	$this->assign('InfoHit', $data['InfoHit']+1); //IncHit在读取后，所以点击次数需加1
    	$this->assign('InfoFrom', $data['InfoFrom']);
    	$this->assign('InfoAlbum', $data['InfoAlbum']);
    	$this->assign('InfoRelation', $data['InfoRelation']);
    	
    	//需要控制权限的字段===========================================
    	//获取当前信息的阅读权限
    	$ReadLevel= !empty($data['ReadLevel']) ? $data['ReadLevel'] : get_read_level( $ChannelID );
    	$HasReadLevel = has_read_level( $ReadLevel);
    	$this->assign('HasReadLevel', $HasReadLevel ? 1 : 0);
    	
    		$this->assign('InfoSContent', $data['InfoSContent']);
    		$InfoContent = ParseTag( $data['InfoContent'] );
    		tag('info_content', $InfoContent);
    		$this->assign('InfoContent', $InfoContent);
    		$this->assign('InfoAttachment', $data['InfoAttachment']);   		 
    		$this->assign('HasAttachment', $data['HasAttachment']);
    		//扩展字段变量
    		$this->assign('f1', $data['f1']);
    		$this->assign('f2', $data['f2']);
    		$this->assign('f3', $data['f3']);
    		$this->assign('f4', $data['f4']);
    		$this->assign('f5', $data['f5']);
    	//===========================================================
    	
    	//评论分页信息===================================================
    	if( YdCache::readComment('COMMENT_ENABLE') == 1){
	    	import("ORG.Util.Page");
	    	$mComment = D('Admin/Comment');
	    	$Total = $mComment->getCommentCount($id);  //总记录数
	    	$PageSize = $this->CommentPageSize;
	    	$Page = new Page($Total, $PageSize);
	    	$Page->rollPage = 10;
	    	$ShowPage = $Page->show();
	    	$this->assign('NowPage', $Page->getNowPage()); //分页条
	    	$this->assign('Page', $ShowPage);   //分页条
	    	unset($mComment);
    	}
    	//===========================================================
    	
    	//优化设置======================================================
    	$Title = !empty($data['Title']) ? $data['Title'] : get_title( $ChannelID );
    	$this->assign('Title', $Title );
    	$Keywords = !empty($data['Keywords']) ? $data['Keywords'] : get_keywords( $ChannelID );
    	$this->assign('Keywords', $Keywords);
    	//描述提取规则
    	if( !empty($data['Description']) ){
    		$Description = $data['Description'];
    	}else if( !empty($data['InfoSContent'])  ){
    		$Description = strip_tags( trim($data['InfoSContent']) );
    	}else if( !empty($data['InfoContent'])  ){
    		$list = array('en'=>200, 'cn'=>100);
    		$len = $list[ get_language_mark() ];
    		$Description = strip_tags( $data['InfoContent'] );
    		$search = array('"','&nbsp;');
    		$replace=array("'",'');
    		$Description = str_replace($search, $replace, $Description); 
    		$Description = Left(trim($Description), $len);
    	}
    	$this->assign('Description', $Description);
    	$this->assign('Tag', $data['Tag']);
    	//===========================================================
    	
    	//频道信息
    	$topChannelID = $mc->getTopChannel( $ChannelID );
    	$this->assign('TopChannelID',  $topChannelID);   //顶层频道ID
    	$this->assign('TopHasChild', $mc->hasChildChannel( $topChannelID ) );   //顶层频道ID
    	
    	//上一信息，下一信息==========================================
    	$np = $m->getNextPrevious($ChannelID, $id);
    	$this->assign('HasNext',  $np['next']['HasNext']);
    	$this->assign('NextInfoID',  $np['next']['NextInfoID']);
    	$this->assign('NextInfoTitle',  $np['next']['NextInfoTitle']);
    	$this->assign('NextInfoUrl',  $np['next']['NextInfoUrl'] );
    	
    	$this->assign('HasPrevious',  $np['previous']['HasPrevious']);
    	$this->assign('PreviousInfoID',  $np['previous']['PreviousInfoID']);
    	$this->assign('PreviousInfoTitle',  $np['previous']['PreviousInfoTitle']);
    	$this->assign('PreviousInfoUrl',  $np['previous']['PreviousInfoUrl']  );
    	//======================================================

    	$SitePath = $this->_getSitePath( $ChannelID, 1);
    	$this->assign('SitePath', $SitePath);

    	$IndexTemplate = $m->getReadTemplate( $id );
    	$IndexTemplate = str_ireplace('.html', '', trim($IndexTemplate) );
    	$this->display($IndexTemplate);
    }
    
}
?>