<?php

if(! defined('OT_ROOT')) {
	exit('Access Denied');
}


class AppTplDiy{

	// 栏目项目
	public static function UserNews($paraStr,$judGet=true){
		global $DB,$tpl;

		$judCache = false;
		$cacheName='diy_UserNews'. $paraStr .'_'. strlen($tpl->webPathPart);

		list($num,$scoreType,$score,$judDate,$judType) = explode(',',$paraStr);
		$num = intval($num);
		$scoreType = intval($scoreType);
		$score = intval($score);
		if ($num<1){ $num = 8; }
		if ($scoreType<1 || $scoreType>3){ $scoreType = 1; }

		if ($retStr = Cache::CheckWebCache($cacheName)){ $judCache = true; }
		if ($judCache == false){

			$retStr = '';
			$retStr .= '<ul>'. PHP_EOL;
			if ($num>0){
				$todayDate = TimeDate::Get('date');
				$typeID = 0;
				$redDay = $tpl->tplSysArr['TS_redTimeDay']-1;

				$itemexe = $DB->query('select IF1.IF_ID,IF2.IF_time,IF2.IF_theme,IF2.IF_userID,IF2.IF_typeStr,IF2.IF_themeStyle,IF2.IF_URL,IF2.IF_isEncUrl,IF2.IF_infoTypeDir,IF2.IF_datetimeDir from (select IF_ID from '. OT_dbPref .'info where IF_state=1 and IF_isAudit=1 and IF_userID>=1'. OT_TimeInfoWhereStr .' order by IF_time DESC limit 0,'. $num .') as IF1 inner join '. OT_dbPref .'info as IF2 on IF1.IF_ID=IF2.IF_ID order by IF2.IF_time DESC');
				$itemRow = $itemexe->fetchAll();
				if ($itemRow){
					$rowCount = count($itemRow);
					for ($i=0; $i<$rowCount; $i++){
						if (! in_array($judDate,array(false,0,'false'))){
							if (TimeDate::Diff('d',$itemRow[$i]['IF_time'],$todayDate) <= $redDay){ $newTimeClass = 'font2_1'; }else{ $newTimeClass = 'font1_1'; }
							$dateStr = '<div class="right '. $newTimeClass .'">&ensp;'. TimeDate::Get('m-d',$itemRow[$i]['IF_time']) .'</div>';
						}else{
							$dateStr = '';
						}
						if (! in_array($judType,array(false,0,'false'))){
							$typeArr = explode(',',$itemRow[$i]['IF_typeStr']);
							if (count($typeArr)>=3){
								$typeID = $typeArr[count($typeArr)-2];
							}
							$currTypeArr = self::InfoTypeCN($itemRow[$i]['IF_typeStr']);
							$typeStr = '<a href="'. Url::ListID('',$currTypeArr['htmlName'],$typeID,0) .'" class="font2_1">['. $currTypeArr['theme'] .']</a>';
						}else{
							$typeStr = '';
						}
						if ($itemRow[$i]['IF_URL'] != ''){
							$hrefStr = Url::NewsUrl($itemRow[$i]['IF_URL'],$itemRow[$i]['IF_isEncUrl'],$itemRow[$i]['IF_ID'],$tpl->webPathPart);
						}else{
							$hrefStr = Url::NewsID($itemRow[$i]['IF_infoTypeDir'],$itemRow[$i]['IF_datetimeDir'],$itemRow[$i]['IF_ID']);
						}
						$username = $DB->GetOne('select UE_username from '. OT_dbPref .'users where UE_ID='. $itemRow[$i]['IF_userID'] .' and UE_score'. $scoreType .'>='. $score);
						if (strlen($username) > 0){ $username .= ' | '; }
						$retStr .= '
						<li>
							'. $dateStr . $typeStr .'<a href="'. $hrefStr .'" class="font1_1" style="'. $itemRow[$i]['IF_themeStyle'] .'" target="_blank" title="'. Str::MoreReplace($itemRow[$i]['IF_theme'],'input') .'">'. $username . $itemRow[$i]['IF_theme'] .'</a>
						</li>
						';
					}
				}
				unset($itemexe);
			}
			$retStr .= '</ul>'. PHP_EOL;

			Cache::WriteWebCache($cacheName,$retStr);

		}

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

}


?>