<?
	//...根据产品ls_products的单个keywords生成关键词页面， 内容Templates1/productskws.html,替换关键词
	
	/*session_start(); 
	require_once('../inc/conn.php');
	require_once('../inc/constant.php');
	require_once('../inc/ls_syscode.php');
	require_once('../inc/check.php');
	$ls_msg="";
	
	$opendb=new mydb();
	require_once('../inc/char_set.php');*/
	
	$thiskeywords=$products_rows['productKeywords'];
	$keywords11=str_replace("|",",", $thiskeywords);
	$relikeywords=explode(",",$keywords11);
	$keywordstags='';
	$keywordstagslist="";	
	$j=1;
	$index_path="../".$templates_var."/productskws.html";
	$fp = fopen($index_path,"r");
	$tagcontent  = fread($fp,filesize ($index_path));
 	//var_dump($relikeywords);
	
	for($i=0;$i<count($relikeywords);$i++){
		$sqlreli="select * from ls_products where   enable=1 and ID != ".$products_rows['ID']." order by ID DESC    ";
		//echo $sqlreli;
		$queryreli=$opendb->query($sqlreli);
		$k=0;
		while($rowsreli=mysql_fetch_assoc($queryreli))
		{
			$mykeyword=trim($relikeywords[$i]);
			if($mykeyword=="") continue; // 没有关键词跳过
			$mykeyword=strtolower(cleartranslate($mykeyword)); //去除<translate>
			
			$getkeywords=$rowsreli['productKeywords']!=""?$rowsreli['productKeywords']:($rowsreli['cateKeywords']!=""? $rowsreli['cateKeywords']:"");
			if($getkeywords=="") continue; // 没有关键词跳过
			$keywordsa= explode(",",str_replace("|",",",$getkeywords));
			 
			if(strin($mykeyword,$keywordsa)){ //  关键词相同，不包含本页
				 
				$tagfilename="../products/".clearFolder($mykeyword).".html";
			    //echo "<br/>".$tagfilename."----<br/>";

				if($k==0){
					$keywordstags.='<a href="'.$tagfilename.'" target="_blank">'.$mykeyword.'</a>,';
				}
				$k++;
				$productpicrp=$rowsreli['productPic'];
				$filename=$rowsreli['filename']==""?clearFolder(strtolower(pathProName($rowsreli['productName'])))."-".$rowsreli['ID'].".html":$rowsreli['filename'];
				$piclinkrp=getpiclink($rowsreli['productID'],$productpicrp,$filename );
				//var_dump($piclinkrp);
				
				$propicrp=$piclinkrp['picsrc'];
				$prolinkrp=$piclinkrp['piclink'];
	
				$keywordstagslist.="<div class=\"col-lg-4 col-md-4 col-sm-6 col-xs-12\">
				<div class=\"thumbnail\"><div class=\"img-pic\">
				<a href=\"../".$prolinkrp." \"  title=\"<translate>".$rowsreli['productName']."</translate>\" target=\"_blank\" class=\"c-img-height\">
				<img src=\"../".$propicrp."\" alt='<translate>".$rowsreli['productName']."</translate>' title='<translate>".$rowsreli['productName']."</translate>' class=\"img-responsive\"  /></a>
				</div>
				<div class=\"caption pro-name\"><h5>
				<a href=\"../".$prolinkrp." \" title='<translate>".$rowsreli['productName']."</translate>' ><translate>".$rowsreli['productName']."</translate></a>
				</h5>
				</div>
				</div>
				</div>";
				//echo $mykeyword."=== $tagfilename <br/><br/>";

				if($j>=$reliProNum) break; //超出数量	
				 
				$j++;
				$rlallID.=$rowsreli['ID'].",";
				
				
				
				//relativedtags
				$ls_relatedtags="";
				$sqlrelitags="select * from ls_tags where   catename='".$rowsreli['productName']."' and enable=1 order by ID DESC    ";
				
				$queryrelitags=$opendb->query($sqlrelitags);
				 
				while($rowsrelitags=mysql_fetch_assoc($queryrelitags))
				{
					$ls_relatedtags.="<a href=\"..".$rowsrelitags['wholepath']."/".$rowsrelitags['filename']." \"  title=\"<translate>".$rowsrelitags['tags']."</translate>\" target=\"_blank\"  >
				 ".strtolower(cleartranslate($rowsrelitags['tags']))." </a>, ";
				}
				
				
				$seed=fmod($j,count($protextseed));
				$ls_protext=$protextseed[$seed];
				$ls_protext=str_replace("{999999}",$mykeyword,$ls_protext); 
				
				$tagcontent = str_replace("{ls_protext}",$ls_protext,$tagcontent); //相关内容
				$tagcontent=str_replace("{ls_relatedtags}",$ls_relatedtags,$tagcontent);  //相关tags
				$tagcontent = str_replace("{ls_pro}",$keywordstagslist,$tagcontent); //相关tags
				$tagcontent= str_replace("{ls_proname_nonintegrate}",$mykeyword,$tagcontent); 
				
				$tagcontent  = str_replace("{ls_title}",$ls_protitle,$tagcontent);
				$tagcontent  = str_replace("{ls_keywords}",$ls_prokeywords,$tagcontent);
				$tagcontent  = str_replace("{ls_prodescription}",$ls_prodescription,$tagcontent);
				$tagcontent  = str_replace("{ls_url}",$ls_prourl,$tagcontent);
				$tagcontent  = str_replace("{ls_banner}",$ls_probanner,$tagcontent);
				$tagcontent  = str_replace("{ls_menu}",$ls_menu,$tagcontent);
				
				$tagcontent  = str_replace("{ls_statistics}",$statistics,$tagcontent);
				$tagcontent  = str_replace("{ls_onlines}",$onlines,$tagcontent);
				$tagcontent  = str_replace("{ls_maps}",$maps,$tagcontent);
				$tagcontent  = str_replace("{ls_share}",$share,$tagcontent);
				$tagcontent  = str_replace("{ls_onlinechart}",$onlinechart,$tagcontent);
				$tagcontent  = str_replace("{ls_shield}",$shield,$tagcontent);
				$tagcontent  = str_replace("{ls_procate}",$ls_procate,$tagcontent);
				$tagcontent  = str_replace("{ls_s_cate}",$ls_s_cate,$tagcontent);
				$tagcontent  = str_replace("{ls_p_cate}",$ls_p_cate,$tagcontent);
				$tagcontent  = str_replace("{ls_languages}",$ls_languages,$tagcontent);
				$tagcontent  = str_replace("{ls_f_cate}",$ls_f_cate,$tagcontent);
				$tagcontent  = str_replace("{ls_indicatebar}",$ls_indicatebar,$tagcontent);
				$tagcontent  = str_replace("{ls_description}",$ls_description,$tagcontent);
				$tagcontent  = str_replace("{ls_foot}",$ls_foot,$tagcontent);
				$tagcontent  = str_replace("{ls_revo}",$lspro_revo,$tagcontent);
				$tagcontent  = str_replace("{ls_motif}",$s_m3_cate,$tagcontent);
				
				$tagcontent  = str_replace("{ls_relative_news}",$relative_new,$tagcontent);
				$tagcontent  = str_replace("{ls_site_cate}",$site_cate,$tagcontent);
				$tagcontent  = str_replace("{ls_weiboshare}",$facebook_twitter_share,$tagcontent);
				$tagcontent  = str_replace("{ls_weibo}",$ls_facebook_twitter,$tagcontent);
				
			 
					 
				$writeurl=($ls_canonical==""? str_replace("..","",$tagfilename):$ls_canonical);
				$writeimportent=true;
				//$writeurl=$_SERVER['HTTP_HOST'].str_replace("..","",$filename);
				$writeurl=str_replace("..","",$filename);
				//$writeimportent=true;
				include("../_inc_when_write_file.php");
				
				$catename=$rowsreli['productName'];  //产品名
				$url="..".$rowsreli['wholepath']."/". $rowsreli['filename']; //产品路径
				
				$select_sql="select * from ls_tags   where tags='".$mykeyword."' ";
	//更新 ;
				$select_query=$opendb->query($select_sql);	
				$mynum = mysql_num_rows($select_query);
				if($mynum==0){
					$insert_sql="insert into ls_tags(tags,url,catename,date,wholepath,filename,enable) values ('".$mykeyword."','".$url."','".$catename."','".date('Y-m-d H:i:s')."','/products' ,'".str_replace("../products/","",$tagfilename)."',1)";
			//echo $insert_sql;
					$insert_query=$opendb->query($insert_sql);
					
				}else{
					$modi_sql="update ls_tags set tags='".$mykeyword."',url='".$url."', catename='".$catename."',   date='".date('Y-m-d H:i:s')."', wholepath='/products' , filename='".str_replace("../products/","",$tagfilename)."',enable='1' where tags='".$mykeyword."' ";
		//echo $modi_sql;
					$modi_query=$opendb->query($modi_sql);
				}
				

				$handle   = fopen($tagfilename,"w"); //打开文件指针
		
				if (!fwrite ($handle,$tagcontent ))
				{  //将信息写入文件
					 if($ls_debug)  echo "生成".$tagfilename."失败！<br/>";
				} 
				else
				{
					  echo "生成<a href='".$tagfilename."' target='_blank'>".$tagfilename."</a>";
					  if($ls_debug) echo " - - -  - - - ".basename($_SERVER['PHP_SELF'])." ， 行号： ".($ls_lineno==""?__LINE__:$ls_lineno) ;
					  echo "<br>";
				}
			
				fclose ($handle); //关闭指针
			}
		}
		 
		
	}
	
	//echo $keywordstagslist ;
	
	//$procontent = str_replace("{keywordstags}",$keywordstags,$procontent); //新闻等 相关产品 ?

?>