<?php
/*
EditorTools自动采集助手-帝国CMS(empirecms) v5.1(GBK、UTF-8)新闻类文章检查接口
----------------------------------
文件名
etchk.php
empirecms v5.1文章检查文件，请复制在empirecms v5.1网站/e/admin目录使用，为保密，请自行修改文件名


主要参数
keyboard		   文章标题
classid			   栏目编号(请对照后台栏目管理查看栏目ID)
vercode		           安全校验码，请自行设定，本项用以防止接口被他人利用，如果需要进行更多校验，请自行填加相关代码。
*/

$vercode='';	//此处取值请自行修改

/*



ET发布配置-文章检查网址处，填写参考如下：
http://您的网址/e/admin/etchk.php?vercode=&classid=&keyboard=<%title%>

*/

if ($_REQUEST['vercode']!=$vercode){
exit("[err]invalid vercode[/err]");
}



require("../class/connect.php");
include("../class/db_sql.php");
include("../class/config.php");
include("../class/class.php");
include("../class/q_functions.php");
$link=db_connect();
$empire=new mysqlquery();

//处理关键字
function SearchDoKeyboardVar($keyboard){
	$keyboard=RepPostVar2(trim($keyboard));
	$keyboard=str_replace('  ','',$keyboard);
	return $keyboard;
}

//返回SQL
function SearchDoKeyboard($f,$hh,$keyboard){
	$where='';
	$keyboard=SearchDoKeyboardVar($keyboard);
	if(empty($keyboard))
	{
		return "";
	}
	if(!empty($hh))
	{
		if($hh=='LT')//小于
		{
			$where=$f."<'".$keyboard."'";
		}
		elseif($hh=='GT')//大于
		{
			$where=$f.">'".$keyboard."'";
		}
		elseif($hh=='EQ')//等于
		{
			$where=$f."='".$keyboard."'";
		}
		elseif($hh=='LE')//小于等于
		{
			$where=$f."<='".$keyboard."'";
		}
		elseif($hh=='GE')//大于等于
		{
			$where=$f.">='".$keyboard."'";
		}
		elseif($hh=='NE')//不等于
		{
			$where=$f."<>'".$keyboard."'";
		}
		elseif($hh=='IN')//包含
		{
			$kr=explode(' ',$keyboard);
			$kcount=count($kr);
			$kbs='';
			$dh='';
			for($i=0;$i<$kcount;$i++)
			{
				if(empty($kr[$i]))
				{
					continue;
				}
				if($kbs)
				{
					$dh=',';
				}
				$kbs.=$dh."'".$kr[$i]."'";
			}
			if($kbs)
			{
				$where=$f." IN (".$kbs.")";
			}
			else
			{
				return '';
			}
		}
		elseif($hh=='BT')//范围
		{
			$keyboard=ltrim($keyboard);
			if(!strstr($keyboard,' '))
			{
				return '';
			}
			$kr=explode(' ',$keyboard);
			if(!trim($kr[0])||!trim($kr[1]))
			{
				return '';
			}
			$where=$f." BETWEEN '".$kr[0]."' and '".$kr[1]."'";
		}
		else//相似
		{
			$where=$f." LIKE '%".str_replace(" ","%",$keyboard)."%'";
		}
	}
	else
	{
		$where=$f." LIKE '%".str_replace(" ","%",$keyboard)."%'";
	}
	return $where;
}

//变量
if($_GET['searchget']==1)
{
	$_POST=$_GET;
}

//搜索栏目及表
$classid=RepPostVar($_POST['classid']);
//$s_tbname=RepPostVar($_POST['tbname']);
$s_tbname="news";

//$s_tempid=(int)$_POST['tempid'];
$trueclassid=0;
$add="";
if($classid)//按栏目
{
		$trueclassid=intval($classid);
		$add=" and classid='$trueclassid'";
}
//表不存在
$tbnamenum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$s_tbname' limit 1");
if(!$tbnamenum)
{
exit("[err]news table is not exist[/err]");
}
$tbname=$s_tbname;

//关键字
$keyboard=$_POST['keyboard'];
	$keyboard=trim($keyboard);
	if(empty($keyboard))
	{
		exit("[err]no subject[err]");
	}


//字段
$searchclass="title";

$allwhere=$searchclass."='".$keyboard."' ".$add;
$query="select count(*) as total from {$dbtbpre}ecms_".$tbname." where ".$allwhere;
    $search_num=$empire->gettotal($query);
	if(empty($search_num))
	{
		echo("[no]");
	}
	else
	{
		echo("[yes]");
	}
db_close();
$empire=null;
?>