<?php
/*
EditorTools文章采集发布助手
----------------------------------
本文件不需要做任何改动，以下参数说明为在“ET软件-发布配置”中修改参数时使用。

文件名
ETpost.php
phpwind6.0文章发布接口文件，请复制在论坛根目录使用，为保密，请自行修改文件名
（发布成功返回1）

注：以下参数名后“=”号为示范而用，参数名本身不含“=”号

主要参数
pwuser 		会员名
pwpwd 		密码
atc_title	主题标题
atc_content 	内容

主要附加参数
fid=2		论坛版块编号(取值为您要发布的版面FID编号) 

可选参数
p_type=0		主题分类（值为您的主题分类编号，如论坛未设必选主题分类，可以不用）
atc_autourl=0	是否自动分析url，是为1，否为0
atc_usesign=1	是否使用签名，是为1，否为0
atc_convert=0	是否Wind Code自动转换，是为1，否为0
atc_anonymous=0	是否匿名帖，是为1，否为0
digest=0		是否精华帖，0：普通帖，1：精华1，2：精华2
atc_hide=0		是否隐藏附件(回复后可见)，是为1，否为0


ET发布配置-文章检查网址处，可以如下填写
http://您的网址/ETpost.php

自在工坊 ET.Zzcity.net
----------------------------------

*/




define('SCR','post');
//require_once('global.php');
//ET替换GLOBAL.PHP开始

/**
*
*  Copyright (c) 2003-06  PHPWind.net. All rights reserved.
*  Support : http://www.phpwind.net
*  This software is the proprietary information of PHPWind.com.
*
*/
error_reporting(E_ERROR | E_PARSE);
set_magic_quotes_runtime(0);
function_exists('date_default_timezone_set') && date_default_timezone_set('Etc/GMT+0');

$defined_vars = get_defined_vars();
foreach ($defined_vars as $_key => $_value) {
	if(!in_array($_key,array('GLOBALS','_POST','_GET','_COOKIE','_SERVER','_FILES','wind_in'))){
		${$_key} = '';
		unset(${$_key});
	}
}
unset($_key,$_value,$defined_vars);

$t_array = explode(' ',microtime());
$P_S_T	 = $t_array[0] + $t_array[1];

define('R_P',__FILE__ ? getdirname(__FILE__).'/' : './');
define('D_P',R_P);

if(!get_magic_quotes_gpc()){
	Add_S($_POST);
	Add_S($_GET);
	Add_S($_COOKIE);
}

Add_S($_FILES);

if($_SERVER['HTTP_X_FORWARDED_FOR']){
	$onlineip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	$c_agentip=1;
} elseif($_SERVER['HTTP_CLIENT_IP']){
	$onlineip = $_SERVER['HTTP_CLIENT_IP'];
	$c_agentip=1;
} else{
	$onlineip = $_SERVER['REMOTE_ADDR'];
	$c_agentip=0;
}

$onlineip  = preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',$onlineip) ? $onlineip : 'Unknown';
$timestamp = time();

if(defined('AJAX')){
	require_once(R_P.'require/ajaxfunc.php');
}
require_once(R_P.'require/defend.php');
$db_cvtime != 0 && $timestamp += $db_cvtime*60;

if($db_debug){
	error_reporting(E_ALL ^ E_NOTICE);
}
$wind_version = "6.0";
$db_olsize	  = 96;


!$_SERVER['PHP_SELF'] && $_SERVER['PHP_SELF']=$_SERVER['SCRIPT_NAME'];
$REQUEST_URI  = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
if(strpos($_SERVER['PHP_SELF'],$db_dir)!==false){
	$tmp=substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['PHP_SELF'],$db_dir));
} else{
	$tmp=$_SERVER['PHP_SELF'];
}
$db_bbsurl="http://$_SERVER[HTTP_HOST]".substr($tmp,0,strrpos($tmp,'/'));

$fid	  = (int)GetGP('fid');
//$tid	  = (int)GetGP('tid');
$tid	  = 0;	//ET增加
$db_obstart == 1 && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();

require_once(D_P.'data/sql_config.php');
$imgpath	= $db_http		!= 'N' ? $db_http	   : $db_picpath;
$attachpath = $db_attachurl != 'N' ? $db_attachurl : $db_attachname;
$imgdir		= R_P.$db_picpath;
$attachdir	= R_P.$db_attachname;
$pw_posts   = 'pw_posts';
$pw_tmsgs   = 'pw_tmsgs';


if(D_P != R_P && $db_http != 'N'){
	$R_url=substr($db_http,-1)=='/' ?  substr($db_http,0,-1) : $db_http;
	$R_url=substr($R_url,0,strrpos($R_url,'/'));
} else{
	$R_url=$db_bbsurl;
}

if($db_pptifopen && $db_ppttype == 'client'){
	$loginurl	= "$db_pptserverurl/$db_pptloginurl?forward=".rawurlencode($db_bbsurl);
	$loginouturl= "$db_pptserverurl/$db_pptloginouturl&forward=".rawurlencode($db_bbsurl);
	$regurl		= "$db_pptserverurl/$db_pptregurl?forward=".rawurlencode($db_bbsurl);
} else{
	$loginurl	= "login.php";
	$loginouturl= "login.php?action=quit";
	$regurl		= "register.php";
}

if(GetCookie('lastvisit')){
	list($c_oltime,$lastvisit,$lastpath) = explode("\t",GetCookie('lastvisit'));
	($onbbstime=$timestamp-$lastvisit)<$db_onlinetime && $c_oltime+=$onbbstime;
} else{
	$lastvisit=$lastpath='';
	$c_oltime=0;
}

$ol_offset = GetCookie('ol_offset');
$skinco	   = GetCookie('skinco');
//if($db_refreshtime && $REQUEST_URI==$lastpath && $onbbstime<$db_refreshtime){
//	!GetCookie('winduser') && $groupid='guest';
//	$manager=TRUE;
//	$skin = $skinco ? $skinco : $db_defaultstyle;
//	Showmsg("refresh_limit");
//}
$H_url =& $db_wwwurl;
$B_url =& $db_bbsurl;


if($db_bbsifopen==0 && !defined('CK')){
	require_once(R_P.'require/bbsclose.php');
}

$t		= array('hours'=>gmdate('G',$timestamp+$db_timedf*3600));
$tddays = get_date($timestamp,'j');
$tdtime	= (floor($timestamp/3600)-$t['hours'])*3600;
$montime= $tdtime-($tddays-1)*86400;

$olid	= GetCookie('olid');
$runfc	= 'N';
$lastpos=SCR=='thread' ? 'F'.$fid : (SCR=='read' ? 'T'.$tid : (SCR=='index' ? 'index':'other'));
if($timestamp-$lastvisit>$db_onlinetime || GetCookie('lastpos') && $lastpos != GetCookie('lastpos')){
	$runfc='Y';
	Cookie('lastpos',$lastpos);
}

require_once Pcv(R_P.'require/db_'.$database.'.php');
$db = new DB($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
unset($dbhost,$dbuser,$dbpw,$dbname,$pconnect,$manager_pwd);
//list($winduid,$windpwd,$safecv) = explode("\t",StrCode(GetCookie('winduser'),'DECODE'));

//ET增加用户校验开始
$pwpwd=GETGP('pwpwd');
$pwuser=GETGP('pwuser');


$chkpassword=md5($pwpwd);
$men=$db->get_one("SELECT m.uid,m.password,m.groupid,m.memberid,m.yz,md.onlineip FROM pw_members m LEFT JOIN pw_memberdata md ON md.uid=m.uid WHERE username='$pwuser' and password='$chkpassword'");
if($men){
$pwuid=$men['uid'];
}
else
{
echo('[err]帐号密码不匹配[/err]');
exit;
}
$windid=$pwuser;
$winduid=$pwuid;

//ET增加用户校验结束

//if(is_numeric($winduid) && strlen($windpwd)>=16){
	$winddb	  = User_info();
	$winduid  = $winddb['uid'];
	$groupid  = $winddb['groupid'];
	$userrvrc = (int)($winddb['rvrc']/10);
	$windid	  = $winddb['username'];
	$_datefm  = $winddb['datefm'];
	$_timedf  = $winddb['timedf'];
	$skin	  = $winddb['style'] ? $winddb['style'] : $db_defaultstyle;
	$winddb['onlineip']=substr($winddb['onlineip'],0,strpos($winddb['onlineip'],'|'));
	$groupid=='-1' && $groupid=$winddb['memberid'];
	if($winddb['showsign'] && (!$winddb['starttime'] && $db_signmoney && strpos($db_signgroup,",$groupid,") !== false && $winddb['currency'] > $db_signmoney || $winddb['starttime'] && $winddb['starttime'] != $tdtime)){
		require_once(R_P.'require/Signfunc.php');
		Signfunc($winddb['showsign'],$winddb['starttime'],$winddb['currency']);
	}
	
//} else{
//	$skin	 = $db_defaultstyle;
//	$groupid = 'guest';
//	$winddb  = $windid = $winduid = $_datefm = $_timedf = '';
//}
//if($db_ifsafecv && strpos($db_safegroup,",$groupid,")!==false && !$safecv && !defined('PRO')){
//	Showmsg('safecv_prompt');
//}
if($db_ads && !$windid && (is_numeric($_GET['u']) || ($_GET['a'] && strlen($_GET['a'])<16)) && strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])===false){
	InitGP(array('u','a'));
	Cookie('userads',"$u\t$a\t".md5($_SERVER['HTTP_REFERER']));
} elseif(GetCookie('userads') && $db_ads=='1'){
	list($u,$a)=explode("\t",GetCookie('userads'));
	if(is_numeric($u) || ($a && strlen($a)<16)){
		require_once(R_P.'require/userads.php');
	}
}

$_GET['skinco'] && $skinco=$_GET['skinco'];
$_POST['skinco'] && $skinco=$_POST['skinco'];
if($skinco && file_exists(D_P."data/style/$skinco.php") && strpos($skinco,'..')===false){
	$skin=$skinco;
	Cookie('skinco',$skinco);
}
if($db_columns && !defined('W_P') && !defined('SIMPLE') && !defined('COL')){
	if(!GetCookie('columns')){
		$j_columns=$db_columns==2 ? 1 : '';
		Cookie('columns',$db_columns);
	}
	if(($j_columns || GetCookie('columns')==2) && (strpos($_SERVER['HTTP_REFERER'],$db_bbsurl)===false || strpos($_SERVER['HTTP_REFERER'],'admin.php')!==false)){
		strpos($REQUEST_URI,'index.php')===false ? Cookie('columns','1') : ObHeader("columns.php?action=columns");
	}
}
//Ipban();

Cookie('lastvisit',$c_oltime."\t".$timestamp."\t".$REQUEST_URI);

unset($db_whybbsclose,$db_whycmsclose,$db_ipban,$db_diy);
if($groupid!='guest'){
	if(file_exists(D_P."data/groupdb/group_$groupid.php")){
		require_once Pcv(D_P."data/groupdb/group_$groupid.php");
	} else{
		require_once(D_P."data/groupdb/group_1.php");
	}
} else{
	require_once(D_P."data/groupdb/group_2.php");
}
if(!defined('SCR')){
	define('SCR','other');
}
$SCR = SCR;
$header_ad=$footer_ad='';
if(SCR != 'read'){
	$advertdb = AdvertInit(SCR,$fid);
	if(is_array($advertdb['header'])){
		$header_ad = $advertdb['header'][array_rand($advertdb['header'])]['code'];
	}
	if(is_array($advertdb['footer'])){
		$footer_ad = $advertdb['footer'][array_rand($advertdb['footer'])]['code'] .'<br />';
	}
	unset($advertdb['header'],$advertdb['footer']);
}
//if($_SERVER['REQUEST_METHOD']=='POST' && strpos($REQUEST_URI,'login.php')===false && strpos($REQUEST_URI,'register.php')===false){
//	$referer_a=parse_url($_SERVER['HTTP_REFERER']);
//	$s_host=$_SERVER['HTTP_HOST'];
//	strpos($s_host,':') && $s_host = substr($s_host,0,strpos($s_host,':'));
//    if($referer_a['host'] && $referer_a['host']!=$s_host){
//		Showmsg('undefined_action');
//	}
//}
if($groupid=='guest' && $db_guestdir && (SCR=='thread' && $db_guestthread || SCR=='read'&& !$_GET['uid'] && $db_guestread || SCR=='index' && $db_guestindex) && $db_bbsifopen){
	require_once(R_P.'require/guestfunc.php');
	getguestcache();
}

function refreshto($URL,$content,$statime=1){
	if(defined('AJAX'))	Showmsg($content);
	global $db_ifjump;
	$URL=str_replace('&#61;','=',$URL);
	if($db_ifjump && $statime>0){
		ob_end_clean();
		global $tplpath,$fid,$imgpath,$db_obstart,$db_bbsname,$skin,$B_url;
		$index_name =& $db_bbsname;
		$index_url =& $B_url;
		$db_obstart == 1 && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();
		if(file_exists(D_P."data/style/$skin.php") && strpos($skin,'..')===false){
			include_once Pcv(D_P."data/style/$skin.php");
		}else{
			include_once(D_P."data/style/wind.php");
		}
		@extract($GLOBALS, EXTR_SKIP);
		require_once GetLang('refreshto');
		$lang[$content] && $content=$lang[$content];
		@require PrintEot('refreshto');
		exit;
	} else{
		ObHeader($URL);
	}
}
function ObHeader($URL){
	global $db_obstart,$db_bbsurl,$db_htmifopen;
	if($db_htmifopen && strtolower(substr($URL,0,4))!='http'){
		$URL="$db_bbsurl/$URL";
	}
	ob_end_clean();
	if($db_obstart){
		header("Location: $URL");exit;
	} else{
		ob_start();
		echo "<meta http-equiv='refresh' content='0;url=$URL'>";exit;
	}
}
function Showmsg($msg_info,$dejump=0){
	@extract($GLOBALS, EXTR_SKIP);
	global $stylepath,$tablewidth,$mtablewidth,$tplpath;
	require_once GetLang('msg');
	$lang[$msg_info] && $msg_info=$lang[$msg_info];
	if(defined('AJAX')){
		echo $msg_info;ajax_footer();
	}
	define('MSG',1);
	require_once(R_P.'require/header.php');
	require_once PrintEot('showmsg');
	exit;
}
function GetLang($lang,$EXT="php"){
	global $tplpath;
	//if(!$lang) $lang='N';
	$path=R_P."template/$tplpath/lang_$lang.$EXT";
	!file_exists($path) && $path=R_P."template/wind/lang_$lang.$EXT";
	return $path;
}
function PrintEot($template,$EXT="htm"){
	//Copyright (c) 2003-06 PHPWind
	global $tplpath;
	if(!$template) $template=N;
	$path=R_P."template/$tplpath/$template.$EXT";
	!file_exists($path) && $path=R_P."template/wind/$template.$EXT";
	return $path;
}
function Cookie($ck_Var,$ck_Value,$ck_Time = 'F',$p = true,$ck_Httponly = false){
	global $db_ckpath,$db_ckdomain,$timestamp;
	!$db_ckpath && $db_ckpath = '/';
	$p && $ck_Var = CookiePre().'_'.$ck_Var;
	if ($ck_Time=='F') {
		$ck_Time = $timestamp+31536000;
	} else {
		($ck_Value=='' && $ck_Time==0) && $ck_Time = $timestamp-31536000;
	}
	$https = $_SERVER['REQUEST_URI'] ? @parse_url($_SERVER['REQUEST_URI']) : array();
	if (empty($https['scheme'])) {
		if ($_SERVER['HTTP_SCHEME']) {
			$https['scheme'] = $_SERVER['HTTP_SCHEME'];
		} else {
			$https['scheme'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http';
		}
	}
	$ck_Secure = $https['scheme'] == 'https' ? true : false;
	if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
		return setcookie($ck_Var, $ck_Value, $ck_Time, $db_ckpath, $db_ckdomain, $ck_Secure, $httponly);
	} else {
		return setcookie($ck_Var, $ck_Value, $ck_Time, $db_ckpath.($ck_Httponly ? '; HttpOnly' : ''), $db_ckdomain, $ck_Secure);
	}
}
function GetCookie($Var){
    return $_COOKIE[CookiePre().'_'.$Var];
}
function CookiePre(){
	return substr(md5($GLOBALS['db_sitehash']),0,5);
}
function Ipban(){
	global $db_ipban,$onlineip,$imgpath,$stylepath;
	if($db_ipban){
		$baniparray=explode(",",$db_ipban);
		foreach($baniparray as $banip){
			if(!$banip)continue;
			$banip=trim($banip);
			if(strpos(','.$onlineip.'.',','.$banip.'.')!==false){
				Showmsg('ip_ban');
			}
		}
	}
}
function P_unlink($filename){
	strpos($filename,'..')!==false && exit('Forbidden');
	return @unlink($filename);
}
function readover($filename,$method='rb'){
	strpos($filename,'..')!==false && exit('Forbidden');

	$filedata = '';
	if ($handle = @fopen($filename,$method)) {
		flock($handle,LOCK_SH);
		$filedata = @fread($handle,filesize($filename));
		fclose($handle);
	}
	return $filedata;
}
function writeover($filename,$data,$method="rb+",$iflock=1,$check=1,$chmod=1){
	//Copyright (c) 2003-06 PHPWind
	$check && strpos($filename,'..')!==false && exit('Forbidden');
	touch($filename);
	$handle=fopen($filename,$method);
	if($iflock){
		flock($handle,LOCK_EX);
	}
	fwrite($handle,$data);
	if($method=="rb+") ftruncate($handle,strlen($data));
	fclose($handle);
	$chmod && @chmod($filename,0777);
}
function openfile($filename){
	$filedata=readover($filename);
	$filedata=str_replace("\n","\n<:wind:>",$filedata);
	$filedb=explode("<:wind:>",$filedata);
	$count=count($filedb);
	if($filedb[$count-1]==''||$filedb[$count-1]=="\r"){unset($filedb[$count-1]);}
	if(empty($filedb)){$filedb[0]="";}
	return $filedb;
}
function Update_ol(){
	global $runfc,$db_online;
	if($runfc == 'Y'){
		if($db_online) Sql_ol(); else Txt_ol();
		$runfc = '';
	}
}
function Txt_ol(){
	global $ol_offset,$winduid,$db_ipstates,$isModify;
	require_once(R_P.'require/userglobal.php');
	if($winduid != ''){
		list($alt_offset,$isModify) = addonlinefile($ol_offset,$winduid);
	} else{
		list($alt_offset,$isModify) = addguestfile($ol_offset);
	}
	if($alt_offset!=$ol_offset)Cookie('ol_offset',$alt_offset);
	if($db_ipstates && ((!GetCookie('ipstate') && $isModify===1) || (GetCookie('ipstate') && GetCookie('ipstate')<$GLOBALS['tdtime']))){
		require_once(R_P.'require/ipstates.php');
	}
}
function Sql_ol(){
	global $db,$olid,$fid,$tid,$timestamp,$windid,$winduid,$onlineip,$groupid,$wind_in,$db_onlinetime,$db_ipstates;
	$ifhide = GetCookie('hideid') ? 1 : 0;
	if($olid){
		$sqladd=$winduid ? "(uid='$winduid' OR olid='$olid' AND uid=0 AND ip='$onlineip')" : "olid='$olid' AND ip='$onlineip'";
		$db->update("UPDATE pw_online SET username='$windid',lastvisit='$timestamp',fid='$fid',tid='$tid',groupid='$groupid',action='$wind_in',ifhide='$ifhide',uid='$winduid',ip='$onlineip' WHERE $sqladd");
		if($winduid && $db->affected_rows() > 1){
			$db->update("DELETE FROM pw_online WHERE uid='$winduid' AND olid!='$olid'");
		}
	} elseif(!$_COOKIE){
		$db->update("UPDATE pw_online SET username='$windid',lastvisit='$timestamp',fid='$fid',tid='$tid',groupid='$groupid',action='$wind_in',ifhide='$ifhide',uid='$winduid' WHERE ip='$onlineip'");
	}
	if(!$olid && $_COOKIE || $db->affected_rows()==0){
		$db->update("DELETE FROM pw_online WHERE uid!=0 AND uid='$winduid' OR lastvisit<($timestamp-$db_onlinetime)");
		$rt=$db->get_one("SELECT MAX(olid) AS olid FROM pw_online");
		$olid=$rt['olid']+1;
		$db->update("REPLACE INTO pw_online (olid,username,lastvisit,ip,fid,tid,groupid,action,ifhide,uid) VALUES ('$olid','$windid','$timestamp','$onlineip','$fid','$tid','$groupid','$wind_in','$ifhide','$winduid')");
		Cookie('olid',$olid);
	}
}
function footer(){
	global $db,$db_obstart,$db_footertime,$db_htmifopen,$P_S_T,$mtablewidth,$db_ceoconnect,$wind_version,$imgpath,$stylepath,$footer_ad,$db_union,$timestamp,$db_icp,$db_icpurl,$advertdb,$groupid,$db_guestindex,$db_guestthread,$db_guestread;
	if(defined('AJAX'))	ajax_footer();
	Update_ol();
	if($db){
		$qn=$db->query_num;
	}
	$ft_gzip=($db_obstart==1 ? "Gzip enabled" : "Gzip disabled").$db_union[3];
	if ($db_footertime == 1){
		$t_array	= explode(' ',microtime());
		$totaltime	= number_format(($t_array[0]+$t_array[1]-$P_S_T),6);
		$wind_spend	= "Total $totaltime(s) query $qn,";
	}
	$ft_time=get_date($timestamp,'m-d H:i');
	$db_icp && $db_icp = "<a href=\"http://www.miibeian.gov.cn\" target=\"_blank\">$db_icp</a>";
	require PrintEot('footer');
	if($advertdb['float'] || $advertdb['popup'] || $advertdb['leftfloat'] || $advertdb['rightfloat']){
		$leftfloat = $advertdb['leftfloat'][array_rand($advertdb['leftfloat'])];
		$rightfloat= $advertdb['rightfloat'][array_rand($advertdb['rightfloat'])];
		$floatAd = $advertdb['float'][array_rand($advertdb['float'])];
		$popupAd = $_COOKIE['hidepop'] ? '' : $advertdb['popup'][array_rand($advertdb['popup'])];
		require PrintEOT('advert');
	}
	$output = str_replace(array('<!--<!---->','<!---->',"\r",substr(R_P,0,-1)),'',ob_get_contents());
	$output.="<script language=\"JavaScript\" src=\"http://init.phpwind.com/init.php?sitehash={$GLOBALS[db_sitehash]}&v=$wind_version&c=0\"></script>";
	if($db_htmifopen){
		$output = preg_replace(
			"/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'>\s]+\.php\?[^\"\'>\s]+)([\"|\']?)/ies",
			"Htm_cv('\\3','<a\\1href=\"')",

			$output
		);
	}
	ob_end_clean();
	$db_obstart == 1 && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();
	if($groupid == 'guest' && !defined('MSG') && (SCR=='thread' && $db_guestthread || SCR=='read'&& !$_GET['uid'] && $db_guestread || SCR=='index' && !$_GET['cateid'] && $db_guestindex)){
		require_once(R_P.'require/guestfunc.php');
		creatguestcache($output);
	} else{
		echo $output; unset($output);exit;
	}
}
function Htm_cv($url,$tag){
	global $db_dir,$db_ext;
	if(ereg("^http|ftp|telnet|mms|rtsp|admin.php|rss.php",$url)===false){
		if(strpos($url,'#')!==false){
			$add = substr($url,strpos($url,'#'));
		}
		$url = str_replace(
			array('.php?','=','&',$add),
			array($db_dir,'-','-',''),
			$url
		).$db_ext.$add;
	}
	return stripslashes($tag).$url.'"';
}
function User_info(){
	global $db,$timestamp,$db_onlinetime,$winduid,$windpwd,$safecv,$db_ifonlinetime,$c_oltime,$onlineip,$db_ipcheck,$tdtime,$montime,$db_ifsafecv;
	$ct = $sqladd = $sqltab = '';
		if(in_array(SCR,array('index','read','thread','post'))){
		$sqladd = SCR=='post' ? ",md.postcheck,sr.visit,sr.post,sr.reply" : ",sr.visit";
		$sqltab = "LEFT JOIN pw_singleright sr ON m.uid=sr.uid";
	}
	$detail = $db->get_one("SELECT m.uid,m.username,m.password,m.safecv,m.email,oicq,m.groupid,m.memberid,m.groups,m.icon,m.regdate,m.honor,m.timedf,m.style,m.datefm,m.t_num,m.p_num,m.yz,m.newpm,m.newrp,m.showsign,m.payemail,md.postnum,md.rvrc,md.money,md.credit,md.currency,md.lastvisit,md.thisvisit,md.onlinetime,md.lastpost,md.todaypost,md.monthpost,md.onlineip,md.uploadtime,md.uploadnum,md.editor,md.starttime $sqladd FROM pw_members m LEFT JOIN pw_memberdata md ON m.uid=md.uid $sqltab WHERE m.uid='$winduid'");
	if(strpos($detail['onlineip'],$onlineip)===false){
		$iparray=explode(".",$onlineip);
		if(strpos($detail['onlineip'],$iparray[0].'.'.$iparray[1])===false) $loginout='Y';
	}

//	if(!$detail || PwdCode($detail['password'])!=$windpwd || $db_ifsafecv && $safecv!=$detail['safecv'] || ($loginout=='Y' && $db_ipcheck==1)){
//		unset($detail);
//		$GLOBALS['groupid']='guest';
//		require_once(R_P.'require/checkpass.php');
//		Loginout();
//		Showmsg('ip_change');
//	} else{

		unset($detail['password']);
		if($timestamp-$detail['lastvisit']>$db_onlinetime || $timestamp-$detail['lastvisit']>3600){
			if(!GetCookie('hideid')){
				$ct="lastvisit='$timestamp',thisvisit='$timestamp'";
				$detail['lastvisit'] = $detail['thisvisit'] = $timestamp;
			}
			if($db_ifonlinetime == 1 && $ct && $c_oltime > 0){
				if($c_oltime > $db_onlinetime*1.2){
					$c_oltime = $db_onlinetime;
				}
				$ct     .= ",onlinetime=onlinetime+'$c_oltime'";
				if($detail['lastvisit']>$montime){
					$ct .= ",monoltime=monoltime+'$c_oltime'";
				} else{
					$ct .= ",monoltime='$c_oltime'";
				}
				$c_oltime = 0;
			}
			$ct && $db->update("UPDATE pw_memberdata SET $ct WHERE uid='$winduid'");
		}
//	}
	return $detail;
}
function PwdCode($pwd){
	return md5($_SERVER["HTTP_USER_AGENT"].$pwd.$GLOBALS['db_hash']);
}
function SafeCheck($CK,$PwdCode,$var='AdminUser',$expire=1800){
	global $timestamp;
	$t	= $timestamp - $CK[0];
	if($t > $expire || $CK[2] != md5($PwdCode.$CK[0])){
		Cookie($var,'',0);
		return false;
	} else{
		$CK[0] = $timestamp;
		$CK[2] = md5($PwdCode.$timestamp);
		$Value = implode("\t",$CK);
		$$var  = StrCode($Value);
		Cookie($var,StrCode($Value));
		return true;
	}
}
function StrCode($string,$action='ENCODE'){
	$key	= substr(md5($_SERVER["HTTP_USER_AGENT"].$GLOBALS['db_hash']),8,18);
	$string	= $action == 'ENCODE' ? $string : base64_decode($string);
	$len	= strlen($key);
	$code	= '';
	for($i=0; $i<strlen($string); $i++){
		$k		= $i % $len;
		$code  .= $string[$i] ^ $key[$k];
	}
	$code = $action == 'DECODE' ? $code : base64_encode($code);
	return $code;
}
function substrs($content,$length,$add='Y'){
	global $db_charset;
	if($length && strlen($content)>$length){
		if($db_charset!='utf-8'){
			$retstr='';
			for($i = 0; $i < $length - 2; $i++){
				$retstr .= ord($content[$i]) > 127 ? $content[$i].$content[++$i] : $content[$i];
			}
			$add=='Y' && $retstr .= ' ..';
			return $retstr;
		} else{
			return utf8_trim(substr($content,0,$length)).($add=='Y' ? ' ..' : '');
		}
	}
	return $content;
}
function utf8_trim($str) {
	$len = strlen($str);
	for($i=strlen($str)-1;$i>=0;$i-=1){
		$hex .= ' '.ord($str[$i]);
		$ch   = ord($str[$i]);
		if(($ch & 128)==0)	return substr($str,0,$i);
		if(($ch & 192)==192)return substr($str,0,$i);
	}
	return($str.$hex);
}
function get_date($timestamp,$timeformat=''){
	global $db_datefm,$db_timedf,$_datefm,$_timedf;
	$date_show=$timeformat ? $timeformat : ($_datefm ? $_datefm : $db_datefm);
	if($_timedf){
		$offset = $_timedf=='111' ? 0 : $_timedf;
	} else{
		$offset = $db_timedf=='111' ? 0 : $db_timedf;
	}
	return gmdate($date_show,$timestamp+$offset*3600);
}
function Add_S(&$array){
	if (is_array($array)) {
		foreach ($array as $key => $value) {
			if (!is_array($value)) {
				$array[$key] = addslashes($value);
			} else {
				Add_S($array[$key]);
			}
		}
	}
}
function Char_cv($msg){
	$msg = str_replace('&amp;','&',$msg);
	$msg = str_replace('&nbsp;',' ',$msg);
	$msg = str_replace('"','&quot;',$msg);
	$msg = str_replace("'",'&#39;',$msg);
	$msg = str_replace("<","&lt;",$msg);
	$msg = str_replace(">","&gt;",$msg);
	$msg = str_replace("\t","&nbsp; &nbsp; ",$msg);
	$msg = str_replace("\r","",$msg);
	$msg = str_replace("  ","&nbsp; ",$msg);
	return $msg;
}
function GdConfirm($code){
	Cookie('cknum','',0);
	if(!$code || !SafeCheck(explode("\t",StrCode(GetCookie('cknum'),'DECODE')),$code,'cknum',1800)){
		Showmsg('check_error');
	}
}
function AdvertInit($SCR,$fid){
	global $timestamp,$db_advertdb;
	$newadvert = array();
	foreach($db_advertdb as $key=>$val){
		foreach($val as $k=>$v){
			if(!$v['endtime'] || $v['endtime'] < $timestamp){
				continue;
			}
			if($SCR == 'index' && strpos(",$v[fid],",",-1,")!==false){
				$newadvert[$key][]=$v;
			} elseif($SCR == 'thread' && strpos(",$v[fid],",",-2,")!==false){
				$newadvert[$key][]=$v;
			} elseif($SCR == 'read' && strpos(",$v[fid],",",-3,")!==false){
				$newadvert[$key][]=$v;
			} elseif(strpos(",$v[fid],",",-4,")!==false){
				$newadvert[$key][]=$v;
			} elseif($fid && strpos(",$v[fid],",",$fid,")!==false){
				$newadvert[$key][]=$v;
			}
		}
	}
	return $newadvert;
}
function readad($ads,$lou,$p){
	if(!$ads || !is_array($ads) || !$lou) return false;
	shuffle($ads);
	foreach($ads as $k=>$v){
		if($v['position']==$p && (strpos(",$v[lou],",',-1,')!==false || strpos(",$v[lou],",",$lou,")!==false)){
			return $v['code'];
		}
	}
	return false;
}
function admincheck($forumadmin,$fupadmin,$username){
	if(!$username){
		return false;
	}
	if($forumadmin && strpos($forumadmin,",$username,")!==false){
		return true;
	}
	if($fupadmin && strpos($fupadmin,",$username,")!==false){
		return true;
	}
	return false;
}
function getdirname($path){
	if(strpos($path,'\\')!==false){
		return substr($path,0,strrpos($path,'\\'));
	} elseif(strpos($path,'/')!==false){
		return substr($path,0,strrpos($path,'/'));
	} else{
		return '/';
	}
}
function allowcheck($allowgroup,$groupid,$groups,$fid='',$allowforum=''){
	if(@strpos($allowgroup,','.$groupid.',')!==false){
		return true;
	}
	if($groups){
		$groupids=explode(',',substr($groups,1,-1));
		foreach($groupids as $key=>$val){
			if(@strpos($allowgroup,','.$val.',')!==false){
				return true;
			}
		}
	}
	if($fid && $allowforum && strpos(",$allowforum,",",$fid,")!==false){
		return true;
	}
	return false;
}
function geturl($attachurl,$type=''){
	global $attachdir,$attachpath,$db_ftpweb,$attach_url;
	if(file_exists($attachdir.'/'.$attachurl)){
		return array($attachpath.'/'.$attachurl,'Local');
	}
	if ($db_ftpweb && !$attach_url || $type=='lf') {
		return array($db_ftpweb.'/'.$attachurl,'Ftp');
	}
	if (!$db_ftpweb && !is_array($attach_url)) {
		return array($attach_url.'/'.$attachurl,'att');
	}
	if (!$db_ftpweb && count($attach_url)==1) {
		return array($attach_url[0].'/'.$attachurl,'att');
	}
	if($type=='show'){
		return ($db_ftpweb || $attach_url) ? 'imgurl' : 'nopic';
	}
	if($db_ftpweb && @$fp=fopen($db_ftpweb.'/'.$attachurl,'rb')){
		@fclose($fp);
		return array($db_ftpweb.'/'.$attachurl,'Ftp');
	}
	if(!empty($attach_url)){
		foreach($attach_url as $value){
			if ($value==$db_ftpweb) continue;
			if (@$fp=fopen($value.'/'.$attachurl,'rb')) {
				@fclose($fp);
				return array($value.'/'.$attachurl,'att');
			}
		}
	}
	return false;
}
function randstr($lenth){
	mt_srand((double)microtime() * 1000000);
	for($i=0;$i<$lenth;$i++){
		$randval.= mt_rand(0,9);
	}
	$randval=substr(md5($randval),mt_rand(0,32-$lenth),$lenth);
	return $randval;
}
function num_rand($lenth){
	mt_srand((double)microtime() * 1000000);
	for($i=0;$i<$lenth;$i++){
		$randval.= mt_rand(0,9);
	}
	return $randval;
}
function PwStrtoTime($time){
	global $db_timedf;
	return function_exists('date_default_timezone_set') ? strtotime($time) - $db_timedf*3600 : strtotime($time);
}
function Pcv($filename,$ifcheck=1){
	$tmpname = strtolower($filename);
	if (strpos($tmpname,'http://')!==false || ($ifcheck && strpos($tmpname,'..')!==false)) {
		exit('Forbidden');
	}
	return $filename;
}
function showfacedesign($usericon,$usehtml='1'){
	global $imgpath,$attachpath,$attachdir,$db_ftpweb,$db_upload;
	$user_a  = explode('|',$usericon);
	$faceurl = '';
	(int)$user_a[1] < 1 && $user_a[1] = 1;
	if($user_a[1] == 3 && !preg_match('/^[0-9]+/',$user_a[0])){
		$user_a[1] = 1;
	} elseif($user_a[1] == 2 && substr($user_a[0],0,4)!='http'){
		$user_a[1] = 1;
	}
	$facetype = $user_a[1];
	if($user_a[4]){
		$faceurl = "$imgpath/pig.gif";
	} elseif($user_a[1] == '3' && $user_a[0]){
		if($db_ftpweb && !file_exists("$attachdir/upload/$user_a[0]")){
			$faceurl = $db_ftpweb;
		} else{
			$faceurl = $attachpath;
		}
		$faceurl .= "/upload/$user_a[0]";
	} elseif($user_a[1] == '2' && $user_a[0]){
		$faceurl = $user_a[0];
	} elseif($user_a[1] == '1' && $user_a[0]){
		$faceurl = "$imgpath/face/$user_a[0]";
	}
	if(empty($faceurl) || strpos($faceurl,'<')!==false){
		$faceurl = "$imgpath/face/none.gif";
	}
	list(,$db_imglen,$db_imgwidth,) = explode("\t",$db_upload);
	(int)$db_imglen < 1 && $db_imglen = 100;
	(int)$db_imgwidth < 1 && $db_imgwidth = 100;
	(!$user_a[2] || $user_a[2] > $db_imgwidth) && $user_a[2] = $db_imgwidth;
	(!$user_a[3] || $user_a[3] > $db_imglen) && $user_a[3] = $db_imglen;
	if($usehtml){
		$imaurl = "src=\"$faceurl\"";
		if($user_a[1] == '2' || $user_a[1] == '3'){
			$user_a[2] && $imaurl .= " width=\"$user_a[2]\"";
			$user_a[3] && $imaurl .= " height=\"$user_a[3]\"";
		}
		return "<img class=\"pic\" $imaurl border=\"0\" />";
	} else{
		return array($facetype,$faceurl,$user_a[2],$user_a[3]);
	}
}
function GetTtable($tid){
	global $db_tlist;
	if(!$db_tlist) return 'pw_tmsgs';
	$tlistdb = unserialize($db_tlist);
	foreach($tlistdb as $key=>$value){
		if($key>0 && $tid>$value){
			return 'pw_tmsgs'.(int)$key;
		}
	}
	return 'pw_tmsgs';
}
function GetPtable($tbid,$tid=''){
	if($GLOBALS['db_plist'] && $tbid=='N' && $tid){
		@extract($GLOBALS['db']->get_one("SELECT ptable AS tbid FROM pw_threads WHERE tid='$tid'"));
	}
	if($GLOBALS['db_plist'] && $tbid && is_numeric($tbid) && strpos(",{$GLOBALS[db_plist]},",",$tbid,")!==false){
		return 'pw_posts'.$tbid;
	}
	return 'pw_posts';
}
function InitGP($keys,$method='GP',$htmcv=0){
	!is_array($keys) && $keys = array($keys);
	foreach($keys as $val){
		$GLOBALS[$val] = NULL;
		if($method!='P' && isset($_GET[$val])){
			$GLOBALS[$val] = $_GET[$val];
		} elseif($method!='G' && isset($_POST[$val])){
			$GLOBALS[$val] = $_POST[$val];
		}
		$htmcv && $GLOBALS[$val] = Char_cv($GLOBALS[$val]);
	}
}
function GetGP($key,$method='GP'){
	if($method=='G' || $method!='P' && isset($_GET[$key])){
		return $_GET[$key];
	}
	return $_POST[$key];
}

//ET替换GLOBAL.PHP结束

require_once(R_P.'require/forum.php');
include_once(D_P.'data/bbscache/cache_post.php');
/**
//* 版块缓冲文件
*/
$foruminfo = $db->get_one("SELECT * FROM pw_forums f LEFT JOIN pw_forumsextra fe USING(fid) WHERE f.fid='$fid' AND type<>'category'");
!$foruminfo && Showmsg('data_error');
$forumset  = unserialize($foruminfo['forumset']);
$creditset = $foruminfo['creditset'];
wind_forumcheck($foruminfo);
if($foruminfo['allowreward'] && $forumset['rewarddb']){
	list($rw_b_val,$rw_a_val)=explode(',',$forumset['rewarddb']);
	!$rw_b_val && $rw_b_val=1;
}
//if($db_recycle && $fid==$db_recycle){
//	showmsg('post_recycle');
//}


list($db_moneyname,$db_moneyunit,$db_rvrcname,$db_rvrcunit,$db_creditname,$db_creditunit)=explode("\t",$db_credits);
/*
//* 获取管理权限
*/
if($groupid==3 || $groupid==4 || admincheck($foruminfo['forumadmin'],$foruminfo['fupadmin'],$windid)){
	$admincheck=1;
} else{
	$admincheck=0;
}
!$windid && $admincheck=0;
if($windid != $manager && $groupid != 3 && !$foruminfo['allowvisit'] && !admincheck($foruminfo['forumadmin'],$foruminfo['fupadmin'],$windid)){
	forum_creditcheck();
}
//if($forumset['allowtime'] && !$admincheck && !allowcheck($forumset['allowtime'],",$t[hours],",'')){
//	Showmsg('forum_allowtime');
//}
list($uploadcredit,$uploadmoney,,)=explode("\t",$forumset['uploadset']);


InitGP(array('action','special','article','pid','p_type'));
$replacedb = array();
//$special   = (int)$special;
$special   = 0;	//ET增加

$secondurl = "thread.php?fid=$fid";
$top_post  = 0;
//!$action && $action = "new";
$action = "new";	//ET增加
/**
////* 调查版块只允许发起投票
*/
//if($foruminfo['f_type']=='vote' && $action=='new' && $special!='1' && !$admincheck){
//	Showmsg('post_vote_only');
//}
//list($db_openpost,$db_poststart,$db_postend)=explode("\t",$db_openpost);
//if($db_openpost==1 && $groupid != 3 && $groupid != 4){
//	if($db_poststart < $db_postend && ($t['hours'] < $db_poststart || $t['hours'] >= $db_postend)){
//		Showmsg('post_openpost');
//	} elseif($db_poststart > $db_postend && ($t['hours'] < $db_poststart && $t['hours'] >= $db_postend)){
//		Showmsg('post_openpost');
//	}
//}


/**
////* 禁止受限制用户发言
*/
//if($groupid=='6'){
//	$bandb=$db->get_one("SELECT * FROM pw_banuser WHERE uid='$winduid'");
//	if(!$bandb){
//		$db->update("UPDATE pw_members SET groupid='-1' WHERE uid='$winduid'");
//	} elseif($bandb['type']==1 && $timestamp-$bandb['startdate']>$bandb['days']*86400){
//		$db->update("DELETE FROM pw_banuser WHERE uid='$winduid'");
//		$db->update("UPDATE pw_members SET groupid='-1' WHERE uid='$winduid'");
//	} else{
//		if($bandb['type']==1){
//			$s_date=get_date($bandb['startdate']);
//			$e_date=$bandb['startdate']+$bandb['days']*86400;
//			$e_date=get_date($e_date);
//			Showmsg('ban_info1');
//		} else{
//			if($bandb['type']==3){
//				Cookie('force',$winduid);
//				Showmsg('ban_info3');
//			} else{
//				Showmsg('ban_info2');
//			}
//		}
//	}
//}
//if(GetCookie('force') && $winduid != GetCookie('force')){
//	$force=GetCookie('force');
//	$bandb=$db->get_one("SELECT type FROM pw_banuser WHERE uid='$force'");
//	if($bandb['type']==3){
//		Showmsg('ban_info3');
//	} else{
//		Cookie('force','',0);
//	}
//}
///**
////* 需要验证用户只有通过管理员验证后才能发帖
//*/
//if($groupid=='7'){
//	Showmsg('post_check');
//}
///*
////* 新注册会员发帖时间限制
//*/
//if($db_postallowtime && $timestamp-$winddb['regdate']<$db_postallowtime*60){
//	Showmsg('post_newrg_limit');
//}
//$userlastptime = $groupid != 'guest' ?  $winddb['lastpost'] : GetCookie('userlastptime');
///**
////* 灌水预防
//*/
//$tdtime  >= $winddb['lastpost'] && $winddb['todaypost'] = 0;
//$montime >= $winddb['lastpost'] && $winddb['monthpost'] = 0;
//if($_G['postlimit'] && $winddb['todaypost'] >= $_G['postlimit']){
//	Showmsg('post_gp_limit');
//}
//if($action!="modify" && !$SYSTEM['postpers'] && $gp_postpertime && $timestamp>=$userlastptime && $timestamp-$userlastptime<=$gp_postpertime){
//	Showmsg('post_limit');
//}

list(,,$postgd)=explode("\t",$db_gdcheck);
list(,,$postq)=explode("\t",$db_qcheck);
$_G['uploadtype'] && $db_uploadfiletype = $_G['uploadtype'];
$db_uploadfiletype = !empty($db_uploadfiletype) ? unserialize($db_uploadfiletype) : array();

//if(!$_POST['step']){
//	$editor  = $winddb['editor'] ? 'wysiwyg' : 'textmode';
//	$verify  = substr(md5($winduid.$db_hash.$fid),0,8);
//	!is_numeric($db_attachnum) && $db_attachnum=1;
//	$htmlpost   = ($foruminfo['allowhide'] && $gp_allowhidden) ? '' : "disabled";
//	$ifanonymous= ($forumset['anonymous'] && $_G['anonymous']) ? '' : "disabled";
//	$groupid   =='guest' && $userrvrc = 0;
//	$atc_title  = $atc_content = $ifmailck = '';
//	$uploadfiletype = $uploadfilesize = ' ';
//	foreach($db_uploadfiletype as $key=>$value){
//		$uploadfiletype .= $key.' ';
//		$uploadfilesize .= $key.':'.$value.'KB; ';
//	}
////	*
////	* 标题表情
////	
//	$icondb=array(
//		'1'=>'1.gif',	'2'=>'2.gif',
//		'3'=>'3.gif',	'4'=>'4.gif',
//		'5'=>'5.gif',	'6'=>'6.gif',
//		'7'=>'7.gif',	'8'=>'8.gif'
//	);
//} elseif($_POST['step']){
//	$postcheck = $_POST['verify']==substr(md5($winduid.$db_hash.$fid),0,8) ? 1 : 0;
//	if($postcheck==0){
//		if($action!='reply' || $foruminfo['allowhtm']==0 || $_POST['verify']!='verify'){
//			Showmsg('illegal_request');
//		}
//	}
//	!$windid && $windid='guest';
//	$winddb['postnum'] < $postgd && GdConfirm($_POST['gdcode']);
//	if($winddb['postnum'] < $postq && $db_question && $_POST['qanswer'] != $db_answer[$_POST['qkey']]){
//		Showmsg('qcheck_error');
//	}
	require_once(R_P.'require/bbscode.php');
	require_once(R_P.'require/postfunc.php');
//	if(@include(D_P."data/bbscache/wordsfb.php")){
//		foreach($wordsfb as $key => $value){
//			$banword = (string) stripslashes($key);
//			if(strpos($_POST['atc_title'],$banword)!==false){
//				Showmsg('title_wordsfb');
//			} elseif(strpos($_POST['atc_content'],$banword)!==false){
//				Showmsg('content_wordsfb');
//			} elseif(strpos($_POST['atc_tags'],$banword)!==false){
//				Showmsg("tag_wordsfb");
//			}
//		}
//		foreach($replace as $key => $value){
//			$banword = (string) stripslashes($key);
//			if(strpos($_POST['atc_title'],$banword)!==false){
//				Showmsg('post_wordsfb');
//			} elseif(strpos($_POST['atc_tags'],$banword)!==false){
//				Showmsg("tag_wordsfb");
//			}
//		}
//	}
	list($lastip,$ipfrom) = explode("\t",str_replace('<','&lt;',$ipfrom));
	if($lastip != md5($onlineip)){
		$ipfrom = cvipfrom($onlineip);
		$ipfrom = str_replace("\n","",$ipfrom);
		Cookie('ipfrom',md5($onlineip)."\t".$ipfrom);
	}
	$atc_usesign=$_POST['atc_usesign'] ? 1 : 0;
//	if($gp_htmlcode && $_POST['atc_html']){
		$atc_usesign+=2;
//	}
//	*
//	* 得到父版块id
//	
	$fatherid=$foruminfo['type']=='sub' ? $foruminfo['fup']:'';
//}

//默认动漫表情处理
if($db_windmagic && ($action == 'new' || ($action == 'modify' && $pid == 'tpc'))){
	$cachefile = D_P."data/bbscache/myshow_default.php";
	$mDef      = '';
	if(!file_exists($cachefile) || $timestamp - @filemtime($cachefile) > 43200){
		$url = "http://dm.phpwind.net/misc/custom/recommend_2.xml";
		$data = "";
		if(ini_get('allow_url_fopen')){
			if(function_exists('file_get_contents')){
				$data = @file_get_contents($url);
			} else{
				$data = @implode('',@file($url));
			}
		}
		if($data && strpos($data,'<?xml')===0){
			$name   = array();
			$id     = array();
			$T      = '';
			$maxnum = 8;
			$xml_parser = xml_parser_create();
			xml_parse_into_struct($xml_parser,$data,$arr_vals);
			xml_parser_free($xml_parser);
			foreach($arr_vals as $v){
				if($v['tag'] == 'ITEM' && $v['attributes']){
					$name[] = $v['attributes']['NAME'];
				} elseif($v['tag'] == 'CODE'){
					$id[] = $v['value'];
				}
			}
			if($db_charset!='utf-8'){
				require_once(R_P.'wap/chinese.php');
				$chs = new Chinese('UTF-8',$db_charset);
				foreach($name as $k=>$v){
					$name[$k] = $chs->Convert($v);
				}
			}
			foreach($id as $k=>$v){
				$T .= $T ? ",$v : '$name[$k]'" : "$v : '$name[$k]'";
				if(!$maxnum--)break;
			}
			$C = "<?php\r\n\t\$mDef = \"$T\";\r\n?>";
			writeover($cachefile,$C);
		}
	}
	@include_once(D_P."data/bbscache/myshow_default.php");
}

//if($action=="new"){
//	require_once(R_P.'require/postnew.php');

//ET替换require_once(R_P.'require/postnew.php')开始

!function_exists('readover') && exit('Forbidden');

##主题分类
$t_typedb=array();
$t_per=0;$t_exits=0;
$t_db=$foruminfo['t_type'];
if($t_db){
	$t_typedb = explode("\t",$t_db);
	$t_typedb = array_unique ($t_typedb);
	$t_per=$t_typedb[0];unset($t_typedb[0]);
	foreach($t_typedb as $value){
		if($value) $t_exits=1;
	}
}
$db_forcetype = $t_exits && $t_per=='2' && !$admincheck ? 1 : 0; // 是否需要强制主题分类

//if($foruminfo['allowpost'] && !$admincheck && !allowcheck($foruminfo['allowpost'],$groupid,$winddb['groups'],$fid,$winddb['post'])){
//	Showmsg('postnew_forum_right');
//}
//if($special=='1' && !$foruminfo['allowpost'] && !$admincheck && $gp_allownewvote==0){
//	Showmsg('postnew_group_vote');
//} elseif($special=='2'){
//	!($forumset['allowactive'] && $gp_allowactive) && showmsg('postnew_group_active');
//	$sel_0='checked';$sel_1=$sel_2='';
//}
//if(!$foruminfo['allowpost'] && !$admincheck && $gp_allowpost==0){
//	Showmsg('postnew_group_right');
//}
//if(!$_POST['step']){
	
//	if($special==3 && $foruminfo['allowreward'] && $_G['allowreward']){
//		$creditselect = '<option value="rvrc">'.$db_rvrcname.'</option>';
//		$creditselect.= '<option value="money">'.$db_moneyname.'</option>';
//		$creditselect.= '<option value="credit">'.$db_creditname.'</option>';
//		require_once(D_P.'data/bbscache/creditdb.php');
//		foreach($_CREDITDB as $key=>$val){
//			$creditselect.="<option value=\"$key\">$val[0]</option>";
//		}
//	}
//	/******** 悬赏 ********/
//
//	require_once(R_P.'require/header.php');
//	$guidename = forumindex($foruminfo['fup']);
//	list($msg_guide,$forumlist) = headguide($guidename);
//	if($winddb['payemail']){
//		list(,$payemail) = explode("\t",$winddb['payemail']);
//		$winddb['email'] = $payemail;
//	}
//	require_once PrintEot('post');footer();
//} elseif($_POST['step']==2){
	##主题分类
	//强制分类
	if(!$p_type || empty($t_typedb[$p_type]) || ($t_per==0 && !$admincheck)){
		$w_type=0;
	} else{
		$w_type=$p_type;
	}
	$db_forcetype && $w_type=='0' && Showmsg('force_tid_select');
	InitGP(array('atc_anonymous','atc_iconid','atc_email','atc_newrp','digest','atc_tags','atc_hide','magicid','magicname'),'P');
	$atc_tags = ($db_iftag && $atc_tags) ? check_tag($atc_tags) : '';
	list($atc_title,$atc_content,$ifconvert,$ifwordsfb)=check_data($action);
//	$db_tcheck && $winddb['postcheck'] == tcheck($atc_content) && Showmsg('content_same'); //内容验证

	require_once(R_P.'require/postupload.php');
	$rewardinfo = $magic = '';

//	if($special=="1"){
//		!$_POST['vt_select'] && Showmsg('postfunc_noempty');
//		InitGP(array('vt_select','timelimit','multiplevote','modifiable','mostvotes','previewable'),'P');
//		$votearray = array();
//		$vt_select = Char_cv($vt_select);
//		$vt_select = explode("\n",$vt_select);
//		foreach($vt_select as $voteoption){
//			$voteoption = trim($voteoption);
//			if($voteoption){
//				$votearray['options'][] = array($voteoption,0,array());
//			}
//		}
//		if(count($vt_select) > $db_selcount){
//			Showmsg('vote_num_limit');
//		}
//		if($mostvotes && is_numeric($mostvotes)){
//			$mostvotes>count($vt_select) && $mostvotes=count($vt_select);
//		} else{
//			$mostvotes=count($vt_select);
//		}
//		$timelimit < 0 && $timelimit = 0;
//		$votearray['multiple'] = array($multiplevote,$mostvotes);
//		$voteopts = addslashes(serialize($votearray));
//	} elseif($special=='2'){
//		InitGP(array('act_subject','act_location'),'P',1);
//		InitGP(array('act_starttime','act_deadline','act_endtime','act_num','act_costs','act_sex'),'P');
//		!($act_subject && $act_starttime && $act_deadline) && Showmsg('active_data_empty');
//		$act_starttime= PwStrtoTime($act_starttime);
//		$act_endtime  = PwStrtoTime($act_endtime);
//		$act_deadline = PwStrtoTime($act_deadline);
//		$act_deadline < $timestamp && Showmsg('deadline_limit');
//		$act_deadline > $act_starttime && Showmsg('starttime_limit');
//		$act_endtime && $act_starttime>$act_endtime && Showmsg('endtime_limit');
//		(!is_numeric($act_num) || $act_num<0) && $act_num=0;
//		(!is_numeric($act_costs) || $act_costs<0) && $act_costs=0;
//	} elseif($special=='3' && $foruminfo['allowreward'] && $_G['allowreward']){
//		require_once(R_P.'require/postreward.php');
//	} elseif($special=='4' && $forumset['allowsale']!=2 && $_POST['seller'] && $_POST['subject']){
//		InitGP(array('seller','subject','contact','demo'),'P',1);
//		InitGP(array('price','ordinary_fee','express_fee','method'),'p');
//		$price        = (int)$price;
//		$ordinary_fee = (int)$ordinary_fee;
//		$express_fee  = (int)$express_fee;
//		if(!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$seller)){
//			Showmsg('seller_error');
//		}
//		$ifconvert   = 2;
//		$atc_content = "[payto]
//(seller)$seller(/seller)
//(subject)$subject(/subject)
//(body)$atc_content(/body)
//(price)$price(/price)
//(ordinary_fee)$ordinary_fee(/ordinary_fee)
//(express_fee)$express_fee(/express_fee)
//(contact)$contact(/contact)
//(demo)$demo(/demo)
//(method)$method(/method)
//[/payto]";

//	} elseif(strpos($atc_content,"[payto]")!==false && strpos($atc_content,"[/payto]")!==false){
//		$special = 4;
//	} else{
		$special = 0;
//	}
	
	if(!$SYSTEM['typeadmin']){
		$digest=0;
	}
	if(($foruminfo['f_check'] == 1 || $foruminfo['f_check'] == 3) && $_G['atccheck'] && !$admincheck){
		$ifcheck = 0;
	} else{
		$ifcheck = alarm($atc_title,$atc_content);
	}
	$anonymous  = ($forumset['anonymous'] && $_G['anonymous'] && $atc_anonymous) ? 1 : 0;
	$ifhide		= ($foruminfo['allowhide'] && $gp_allowhidden && $atc_hide) ? 1 : 0;
	$lastposter = $anonymous ? $db_anonymousname : $windid;
	$atc_iconid = (int)$atc_iconid;
	$atc_email  = $db_replysendmail ? (int)$atc_email : 0;
	$db_replysitemail && $atc_newrp && $atc_email +=2;

	$ifmagic	= 0;
	if($db_windmagic && $magicid){
		$magicid	= Char_cv($magicid);
		$magicname	= Char_cv($magicname);
		$ifmagic	= 1;
		$magic		= $magicid."\t".$magicname;
	}

	$db->update("INSERT INTO pw_threads (fid,icon,author,authorid,subject,ifcheck,type,postdate,lastpost,lastposter,hits,replies,topped,digest,special ,ifupload,ifmail,rewardinfo,anonymous,ptable,ifmagic,ifhide) VALUES ('$fid','$atc_iconid','".addslashes($windid)."','$winddb[uid]','$atc_title','$ifcheck','$w_type','$timestamp','$timestamp','".addslashes($lastposter)."','1','0','0','".(int)$digest."','$special','$ifupload','$atc_email','$rewardinfo','$anonymous','$db_ptable','$ifmagic','$ifhide')");
	$tid = $db->insert_id();
	$pw_tmsgs = GetTtable($tid);
	if($db_iftag){
		if($atc_tags){
			insert_tag($tid,$atc_tags);
		}
		$atc_tags .= "\t".relate_tag($atc_title,$atc_content);
	}
	$db->update("INSERT INTO $pw_tmsgs(tid,aid,userip,ifsign,buy,ipfrom,tags,ifconvert,ifwordsfb,content,magic) VALUES('$tid','$attachs','$onlineip','$atc_usesign','','$ipfrom','$atc_tags','$ifconvert','$ifwordsfb','$atc_content','$magic')");
	$digest && $db->update("UPDATE pw_memberdata SET digests=digests+1 WHERE uid='$winduid'");
	if($aids){
		$db->update("UPDATE pw_attachs SET tid='$tid' WHERE aid IN($aids)");
	}
	if($special==1){
		$db->update("INSERT INTO pw_polls (tid,voteopts,modifiable,previewable,timelimit) VALUES ('$tid','$voteopts','$modifiable','$previewable','$timelimit')");
	} elseif($special==2){
		$db->update("INSERT INTO pw_activity (tid,subject,admin,starttime,endtime,location,num,sexneed,costs,deadline) VALUES ('$tid','$act_subject','$winduid','$act_starttime','$act_endtime','$act_location','$act_num','$act_sex','$act_costs','$act_deadline')");
	}
	$top_post=1;
	$t_date=$timestamp;//主题发表时间 bbspostguide 中用到
	bbspostguide();

	unset($j_p);
	if($ifcheck==1){
		if($foruminfo['allowhtm'] && !$foruminfo['cms']){
			include_once(R_P.'require/template.php');
		}
		lastinfo($fid,$foruminfo['allowhtm'],'new',$foruminfo['cms'].'B');
	}
	if(empty($j_p) || $foruminfo['cms']) $j_p = "read.php?tid=$tid";
	//refreshto($j_p,$ifcheck ? 'enter_thread' : 'post_check');
	//ET增加成功信息
	echo(1);
	exit;
	//ET增加成功信息结束
//}



//ET替换require_once(R_P.'require/postnew.php')结束

//} elseif($action=="reply" || $action=="quote"){
//	require_once(R_P.'require/postreply.php');
//} elseif($action=="modify"){
//	require_once(R_P.'require/postmodify.php');
//} else{
//	Showmsg('undefined_action');
//}

?>
