<?php
require_once WEBROOT.'include/function.php';

$iid = htmlspecialchars($_GET['iid'],ENT_QUOTES);

if(empty($iid)) $iid = "1295833210"; //默认IID

if(checkpingbi($numidpb,$iid)){
	echo("<script language=\"javascript\">alert('对不起，该商品已被屏蔽。');location.href='".$sitetitleurl."/gotourl.php';</script>");	
	exit;
}

if(!intval($iid)) {
	echo("<script language=\"javascript\">location.href='".$sitetitleurl."/gotourl.php';</script>");	
	exit;
}

$Taoapi->method = 'taobao.taobaoke.items.detail.get';
$Taoapi->fields = 'desc,auction_point,stuff_status,has_invoice,has_warranty,has_showcase,property_alias,input_pids,input_str,type,seller_cids,props,input_pids,cid,title,post_fee,express_fee,ems_fee,location,click_url,shop_click_url,seller_credit_score,nick,pic_url,price,cid,num,list_time,delist_time,location,props_name,stuff_status';
$Taoapi->num_iids = $iid;
$Taoapi->pid = $userpiddp;
$TaoapiItem = $Taoapi->Send('get','xml')->getArrayData();

$taobaoke_items = $TaoapiItem["taobaoke_item_details"]["taobaoke_item_detail"];
$pro_item = $taobaoke_items;
$volumn = $taobaoke_items["volumn"];
$result_item = $taobaoke_items["item"];
$props = $result_item['props'];
$stuff_status = $result_item['stuff_status'];
$props_name = $result_item['props_name'];
$title = $result_item['title'];
$nick = $result_item['nick'];
$post_fee = $result_item['post_fee'];
$express_fee = $result_item['express_fee'];

if($express_fee=="0.00"){
	$express_fee = "卖家包邮";
}

$ems_fee = $result_item['ems_fee'];
$catid = $result_item['cid'];
$desc = $result_item['desc'];
$num = $result_item['num'];
$price = $result_item['price'];
$pic_path = $result_item['pic_url'];
$list_time = $result_item['list_time'];
$delist_time = $result_item['delist_time'];

$click_url = $taobaoke_items['click_url'];
$shop_click_url = $taobaoke_items['shop_click_url'];
$seller_credit_score = $taobaoke_items['seller_credit_score'];
$city = $result_item['location']['city'];
$state = $result_item['location']['state'];
$level = $seller_credit_score;

$cat_name = Newiconv("GBK","UTF-8","所有分类");
$result_subcats_count = 0;
if(isset($taobaoke_items) && $catid != 0)
{
	$Taoapi->method = 'taobao.itemcats.get';
	$Taoapi->fields = 'cid,name,parent_cid,status';
	$Taoapi->cids = $catid;
	$TaoapiCat = $Taoapi->Send('get','xml')->getArrayData();
	$result_cat = $TaoapiCat["item_cats"]['item_cat'];
	$cat_name  = $result_cat['name'];
	$parent_cid = $result_cat['parent_cid'];
	
	$listurl = getsearchurl("",$catid);

	if(Show_product_catid){
		$Taoapi->method = 'taobao.itemcats.get';
		$Taoapi->fields = 'cid,name,parent_cid';
		$Taoapi->parent_cid = $parent_cid;
		$TaoapiSubCats = $Taoapi->Send('get','xml')->getArrayData();
	}

}else{
	echo("<script language=\"javascript\">location.href='".$sitetitleurl."/gotourl.php';</script>");	
	exit;
}
$result_subcats = "";
$result_subcats_count = 0;

if(isset($TaoapiSubCats["item_cats"]["item_cat"])){
	$result_subcats = $TaoapiSubCats["item_cats"]["item_cat"];
	$result_subcats_count = count($result_subcats);
}

//查询失败的情况。
if(isset($taobaoke_items) && is_array($click_url)){
	
		$Taoapi->method = 'taobao.taobaoke.items.convert';
		$Taoapi->fields = 'num_iid,click_url,shop_click_url';
		$Taoapi->pid = $userpiddp;
		$Taoapi->num_iids = $iid;
		$TaoapiClickItem = $Taoapi->Send('get','xml')->getArrayData();
	$click_url = $TaoapiClickItem["taobaoke_items"]["taobaoke_item"]["click_url"];
	$shop_click_url = $TaoapiClickItem["taobaoke_items"]["taobaoke_item"]["shop_click_url"];
}

if(!is_array($taobaoke_items)){
	
	    $desc = Newiconv("GBK", "UTF-8","当前系统查询数据失败。请联系网站管理员。");

	
	//redirect_to($rootroad."/s8.php?title=".urlencode($S8Keys));	
}
if(isset($taobaoke_items) && Show_product_hotlist){
	$Taoapi->method = 'taobao.taobaoke.items.get';
	$Taoapi->fields = 'iid,volume,num_iid,title,nick,pic_url,price,click_url,shop_click_url,seller_credit_score,commission,commission_rate,commission_num,commission_volume';
	$Taoapi->pid = $userpiddp;
	$Taoapi->cid = $catid;
	$Taoapi->page_no = 1;
	$Taoapi->page_size = Show_product_hotlistnum;
	$Taoapi->sort = "commissionNum_desc";
	$Taoapi->start_price = 1;
	$Taoapi->end_price = 10000;
	$Taoapi->start_credit = $shoplevelstart;
	$Taoapi->end_credit  = $shoplevelend;
	$Taoapi->start_commissionRate  = $stratmoneyKeys;
	$Taoapi->end_commissionRate  = $endmoneyKeys;
	if($ismall=="1")$Taoapi->mall_item = "true";
	if(!empty($defaultarea)){
		$Taoapi->area = $defaultarea;
	}
	
	$TaoapiItems = $Taoapi->Send('get','xml')->getArrayData();
	$taobaokeItem = $TaoapiItems["taobaoke_items"]["taobaoke_item"];;
}
if(isset($taobaoke_items) && Show_product_propvalue) {
	$props = $props;
	$Taoapi->method = 'taobao.itempropvalues.get';
	$Taoapi->cid = $catid;
	$Taoapi->fields = 'prop_name,name,status,sort_order';
	$Taoapi->pvs = $props;
	$itempropvalues = $Taoapi->Send('get','xml')->getArrayData();
	$props = $itempropvalues['prop_values']['prop_value'];
}
//屏蔽

$title =Newiconv("GBK","UTF-8", setsplitkeyword($searchkeypb,Newiconv("UTF-8","GBK",$title),"***"));

$desc =Newiconv("GBK","UTF-8", setsplitkeyword($searchkeypb,Newiconv("UTF-8","GBK",$desc),"***"));

if(checkpingbi($catidpb,$catid)){
	exit("<script language=\"javascript\">alert('对不起，该商品类别已被屏蔽。');location.href='".$sitetitleurl."';</script>");	
}

//过滤标题
for($i = 0; $i < count($taobaokeItem); $i++) {
	if(!isset($taobaokeItem[$i]["title"])) break;
	$taousernick = Newiconv("utf-8","gbk",$taobaokeItem[$i]["nick"]);
	$taobaokeItem[$i]["title"] =Newiconv("GBK","UTF-8", setsplitkeyword($searchkeypb,Newiconv("UTF-8","GBK",$taobaokeItem[$i]["title"]),"***"));
	$taobaokeItem[$i]["title"] =str_replace("'","'",Newiconv("GBK","UTF-8", Newiconv("UTF-8","GBK",(strip_tags($taobaokeItem[$i]["title"])))));
	$taobaokeItem[$i]["taodiurl"] = getproducturl($taobaokeItem[$i]["num_iid"]);
	$taobaokeItem[$i]["taodishopurl"] = getshopurl($taousernick);
}

if($product_title=="")$product_title = "{商品名}_{网站名}";
if($product_keyword=="")$product_keyword = "{商品类别名},{商品名}";
if($product_discription=="")$product_discription = "{商品名},希望您能在{网站名},找淘称心如意的宝贝";

$tihuanarr = array();
$tihuanarr["{商品类别名}"] = Newiconv("UTF-8","GBK",$cat_name);
$tihuanarr["{商品名}"] = Newiconv("UTF-8","GBK",$title);
$tihuanarr["{网站名}"] = $sitetitle;
$tihuanarr["{商品价格}"] = $price;
$tihuanarr["{掌柜名}"] = Newiconv("UTF-8", "GBK",$nick);
$tihuanarr["{所在地}"] = Newiconv("UTF-8", "GBK",$state);
$tihuanarr["{剩余数量}"] = $num;
$tihuanarr["{上架时间}"] = $list_time;


$page_title = strtr($product_title,$tihuanarr); 
$page_keyword = strtr($product_keyword,$tihuanarr); 
$page_discription = strtr($product_discription,$tihuanarr); 

$WYCdeschead = stripslashes(html_entity_decode(strtr($WYCdeschead,$tihuanarr),ENT_QUOTES)); 
$WYCdescfooter = stripslashes(html_entity_decode(strtr($WYCdescfooter,$tihuanarr),ENT_QUOTES)); 
if(is_array($click_url) || empty($click_url)){
	$click_url = $rootroad."/s8.php?title=".urlencode(Newiconv("UTF-8", "GBK",$title))."&cat=".$catid;
}
if(is_array($shop_click_url) || empty($shop_click_url)){
	$shop_click_url = $rootroad."/s8.php?title=".urlencode(Newiconv("UTF-8", "GBK",$title))."&cat=".$catid;
}

function writeDesc($type){
	global $desc;
	global $WYCdeschead;
	global $WYCdescfooter;
	global $arraykeywords;
	global $arraykeywords;
	global $WYCdescJs;
	
		if($type!="UTF-8"){
			
				$pat = "/<(\/?)(script|i?frame|style|html|body|title|link|a|meta|\?|\%)([^>]*?)>/isU";
				$descclear = preg_replace($pat,"",$desc);
				
				$html = Newiconv("UTF-8", "GBK",$descclear);
				
				$html = $WYCdeschead.$html.$WYCdescfooter;
				
				$str = explode(",",$arraykeywords["产品关键字替换"]["keyword"]);
				
				
				
				
				$replacestartarr = array();
				$replaceendarr = array();
				foreach($str as $val){
					if(!empty($str)){
						$replacestartarr[]="/".$val."/";
						$replaceendarr[]="<a href=".getsearchurl($val)."><b>".$val."</b></a>";
					}
				} 
				
				$html = preg_replace($replacestartarr,$replaceendarr, $html, 1);
				
				
				if($WYCdescJs==1){
				
				$descclear = strip_tags($html);
				$allhtml = base64_encode($html);
				
				$descclear = preg_replace($replacestartarr,$replaceendarr, $descclear, 1);
				
				
				echo $descclear ;
			?>
				
				<script language="javascript" type="text/javascript">
				str = "<?php echo $allhtml;?>";
				tihuan();
				</script>
			<?php }else{
				echo($html);
			}
		
		}else{
				$pat = "/<(\/?)(script|i?frame|style|html|body|title|link|a|meta|\?|\%)([^>]*?)>/isU";
				$descclear = preg_replace($pat,"",$desc);
				
				$html = Newiconv("UTF-8", "GBK",$descclear);
				$html = $WYCdeschead.$html.$WYCdescfooter;
			
				$str = explode(",",$arraykeywords["产品关键字替换"]["keyword"]);
				
				$replacestartarr = array();
				$replaceendarr = array();
				foreach($str as $val){
					if(!empty($str)){
						$replacestartarr[]="/".$val."/";
						$replaceendarr[]="<a href=".getsearchurl($val)."><b>".$val."</b></a>";
					}
				} 
				
				$html = preg_replace($replacestartarr,$replaceendarr, $html, 1);
				
				if($WYCdescJs==1){
				
				$descclear = strip_tags($html);
				$allhtml = base64_encode($html);
				
				$descclear = preg_replace($replacestartarr,$replaceendarr, $descclear, 1);
				
				
				echo $descclear ;
			?>
				
				<script language="javascript" type="text/javascript">
				str = "<?php echo $allhtml;?>";
				tihuan();
				</script>
			<?php }else{
				$html = Newiconv("GBK","UTF-8", $html);
				echo($html);
			}	
	}
}

require_once WEBROOT.'include/functiondaohang.php';

//加载模板
require_once WEBROOT.'template/'.$templatefolder.'/product.php';

showend();

?>
