<?php


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'));


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 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 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 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 Pcv($filename,$ifcheck=1){
	$tmpname = strtolower($filename);
	if (strpos($tmpname,'http://')!==false || ($ifcheck && strpos($tmpname,'..')!==false)) {
		exit('Forbidden');
	}
	return $filename;
}

function GetGP($key,$method='GP'){
	if($method=='G' || $method!='P' && isset($_GET[$key])){
		return $_GET[$key];
	}
	return $_POST[$key];
}

function GdConfirm($code){
	Cookie('cknum','',0);
//	if(!$code || !SafeCheck(explode("\t",StrCode(GetCookie('cknum'),'DECODE')),$code,'cknum',1800)){
//		Showmsg('check_error');
//	}
}


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


$keyword = Char_cv($keyword);
if ($keyword =='') {
echo('[err]标题为空[/err]');
exit;


}

$query =$db->query("SELECT * FROM pw_threads WHERE subject='$keyword' LIMIT 1");
if ($db->num_rows($query)>0){
echo('1');
}
else
{
echo('0');
}


exit;

?>