<?php
require_once 'Config.php';
/**
 * 新闻内容类
 *
 * @author Wzb
 *        
 */
class USL_NewsShow extends USL_Base {
	/**
	 * 标签
	 *
	 * @var string
	 */
	private $_tag;
	
	/**
	 * 根类别ID
	 *
	 * @var int
	 */
	private $_rootSortId;
	
	/**
	 * 新闻对象
	 *
	 * @var object
	 */
	private $_newsObj;
	
	/**
	 * 排版样式
	 *
	 * @var string
	 */
	private $_stype;
	
	/**
	 * 构造类
	 *
	 * @param string $tag 标签
	 * @param int $theId ID
	 */
	public function __construct($theId) {
		parent::__construct ();
		$this->init ( $theId );
		$this->setNews ();
		$this->setWeiZhi ();
	}
	
	/**
	 * 初始化
	 *
	 * @param int $theId 新闻ID
	 */
	private function init($theId) {
		$this->_newsObj = BLL_News::getOne ( $theId );
		if (count ( $this->_newsObj ) == 0) {
			die ( COM_OftenJavaScript::showInfo ( "该信息不存在!" ) );
		}
		$this->_rootSortId = $this->getRootSortId ( "1,900", $this->_newsObj ['sort'] );
		//var_dump($this->_rootSortId);
		$this->_stype = "NewsShow";
		switch ($this->_rootSortId) {
			
			case 1 : // 案例中心
				$this->_tag = "production";
				break;
			
			default :
				die ( COM_OftenJavaScript::showInfo ( "该类别不在配置中!" ) );
				break;
		}
		$this->_weizhi = $this->_tag;
	}
	
	/**
	 * 设置变量值
	 */
	public function _assignContent() {
		parent::_showComm ();
		$this->_tpl->assign ( "webName", $this->_webStr ); // 网站标题
		$this->_tpl->assign ( "theKeyWords", $this->_keywords ); // 网站关键字
		$this->_tpl->assign ( "theDescription", $this->_description ); // 网站描述
		$this->_tpl->assign ( "thisName", $this->_thisName ); // 栏目名称
		$this->_tpl->assign ( "leftNav", $this->_leftNav ); // 左侧导航
		$this->_tpl->assign ( "address", $this->_address ); // 当前位置
		$this->_tpl->assign ( "newsObj", $this->_newsObj ); // 新闻对象
		$this->_tpl->assign ( "stype", $this->_stype ); // 排版样式
		$this->_tpl->assign ( "preNextObj", $this->getOnePreNext () ); // 获取上一篇，下一篇
		
		$newsObjs=$this->_newsObj;
		$gaikuang=nl2br($newsObjs['gaikuang']);
		$this->_tpl->assign("gaikuang",$gaikuang);
	}
	
	/**
	 * 设置系列新闻内容常规信息
	 */
	private function setNews() {
		$sortObj = BLL_NewsSort::getOne ( $this->_newsObj ['sort'], 'id,SortName' );
		$this->_weizhi = $this->_weizhi . '_' . $sortObj ['id'];
		$this->_thisName = $sortObj ['SortName'];
		$this->_webStr = COM_OftenFunction::setWebName ( $this->_newsObj ['title'] . '-' );
		$this->_keywords = $this->_newsObj ['title'];
		$this->_description = COM_OftenFunction::CutStr ( COM_OftenFunction::noHtml ( $this->_newsObj ['content'] ), 200 );
		// 注意设置这里的内容页图片宽度限制PX
		$this->_newsObj ['content'] = str_replace ( array ("<img","<IMG" ), "<img onload=\"resize(this,700)\"", $this->_newsObj ['content'] );
	}
	
	/**
	 * 设置位置信息
	 */
	private function setWeiZhi() {
		$rootObj = BLL_NewsSort::getOne ( $this->_rootSortId, "id,sortName" );
		switch ($this->weizhiRoot ()) {
			// 在这里进行 “ 当前位置 、左侧导航 ” 的非常规设置!!!!!
			default :
				$this->_leftNav = USL_LeftNav::_NewsSortList ( $rootObj ['id'], $rootObj ['sortName'], $this->_tag, $this->_newsObj ['sort'] );
				break;
		}
		
		// 这里是根据左侧导航推理出当前位置，一般不需要修改
		$this->_address [] = array ("title" => $rootObj ['sortName'],"url" => "News_List.php?tag=" . $this->_tag );
		if ($rootObj ['id'] != $this->_newsObj ['sort']) {
			$this->getAddress ( $this->_leftNav ['list'], $this->_address );
			$nowSortObj = BLL_NewsSort::getOne ( $this->_newsObj ['sort'], "id,sortName" );
			$this->_address [] = array ("title" => $nowSortObj ['sortName'],"url" => "News_List.php?tag=" . $this->_tag . "&theId=" . $nowSortObj ['id'] );
		}
	}
	
	/**
	 * 获取上一篇与下一篇
	 */
	private function getOnePreNext() {
		$theArray = BLL_News::getOnePreNext ( $this->_newsObj );
		$theArray [2] = 'News_List.php?tag=' . $this->_tag . '&theId=' . $this->_newsObj ['sort'];
		return $theArray;
	}
	
	/**
	 * 获取某类别的根路径
	 *
	 * @param string $sortList 类别范围,多个用逗号分开
	 * @param int $currentId 当前类别ID
	 * @param bool $isFrist（不需要赋值，递归使用）
	 * @param array $allList（不需要赋值，递归使用）
	 * @return int
	 */
	private function getRootSortId($sortList, $currentId, $isFrist = true, $allList = array()) {
		if (strpos ( ",$sortList,", ",$currentId," ) !== false) {
			return $currentId;
		} else {
			if ($isFrist) {
				$allList = BLL_NewsSort::getList ( 0, 'id,pid,serialNum' );
			}
			$tempPid = array_merge ( array_filter ( $allList, create_function ( '$one', "return \$one['id']==$currentId;" ) ) );
			if (count ( $tempPid ) <= 0) {
				return - 1;
			} else {
				return $this->getRootSortId ( $sortList, $tempPid [0] ['pid'], false, $allList );
			}
		}
	}
}

// 实例化
$configObj = BLL_WebSet::getOne ();
$thisPage = new USL_NewsShow ( array_key_exists ( 'theId', $_GET ) ? intval ( $_GET ['theId'] ) : 0 );
$thisPage->_assignContent ();
$thisPage->_tpl->display ( "Tpl/News_Show.tpl" );
?>