<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php 
	//...根据产品ls_keywords， 生成
	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');

	$title_sql = "select * from ls_keywords where enable=1 ";
	$title_query = $opendb->query($title_sql);
	echo mysql_num_rows($title_query); exit;
	$skiptitle=array();
	$skiptable=array();
	$allgenpic=explode(",","certificate,download,management,workshop,packing,certificate,history,rd");
	
	while($rowstable=mysql_fetch_assoc($title_query))
	{		
		$kwid=trim($rowstable['ID']);
		$keyword=strtolower(trim($rowstable['keyword']));
		$productsidpool=trim($rowstable['products']) ;
		$newsidpool=trim($rowstable['news']) ;		
		$blogidpool=trim($rowstable['blog']) ;
		$genpicidpool=trim($rowstable['genpic']) ; 
		
		echo $kwid."==".$keyword."  ";
		if($keyword=="")continue;
		$title_sql1 = "select * from ls_writefiles";
		$title_query1 = $opendb->query($title_sql1);
		
		while($title_value1 = mysql_fetch_assoc($title_query1))
		{	
				$kwpage=trim($title_value1['url']);
				$fromtable=trim($title_value1['fromtable']);
				$wfid=trim($title_value1['ID']);
				
				if($kwpage=="")continue;
				if(!strin($fromtable,$skiptable))
				{
			
					$fp = fopen($kwpage,"r");
					$procontent  = fread($fp,filesize ($kwpage)); //
					$bodypos=strpos($procontent,"<body>");	
					$bodypos2=strpos($procontent,"</body>");	
					$keywordpos=strpos($procontent,$keyword);
					echo $keyword."---".$keywordpos."---".$bodypos."---".$bodypos."---".$kwpage."<br/>";
					if($keywordpos>$bodypos && $keywordpos<$bodypos2) //如果关键词在有效范围
					{ // 记录 ls_writefiles 中 id
							switch($fromtable){ // 分类记录
							case "ls_products"	:  $productsidpool.= ($productsidpool==""? $wfid:$productsidpool.",".$wfid ); break;
							case "ls_news"		:  $newsidpool.= ($newsidpool==""? $wfid:$newsidpool.",".$wfid);  break;
							case "ls_article"	:  if(!(strpos($kwpage,"blog")===false))$blogidpool.=($blogidpool==""? $wfid:$blogidpool.",".$wfid); break;
							default	:  
								for($i=0;$i<count($allgenpic);$i++){
									if(!(strpos($kwpage,$allgenpic[$i])===false)) $genpicidpool.=($genpicidpool==""? $wfid:$genpicidpool.",".$wfid);   
							}
								
					 }
					 fclose ($fp);
							
				}
					
			} //ls_writefiles
			 
			 
		}
		$update_sql = "update ls_keywords set products='".$productsidpool."', news='".$newsidpool."', blog='".$blogidpool."', genpic='".$genpicidpool."' where ID=".$kwid." ";
		$title_query = $opendb->query($update_sql);
		if( $title_query )  $ls_msg.= $keyword."相关页面 ".$productsidpool.", ".$newsidpool.",".$blogidpool.",".$genpicidpool."<br/><br/>";
		 
	}
	
	if($ls_msg=="")$ls_msg="没有关键词相关页面"; else $ls_msg.=" 添加成功！";
	 echo $ls_msg;
	


?>
<title>1getkwspage</title>
</head>

<body>
</body>
</html>