<?php
/*
strin字符串$str是否精确匹配数组，editorprocess 编辑器内容处理：内链 图片 加alt,title 图片分级，strippattern  去除固定开头结尾的串（注释），strreppattern 替换固定开头结尾的串，为新的固定开头结尾，filereplace 文件内容替换，getStrbyTag 通过匹配首串 和尾串 获得中间首串 和尾串 的字符串，writeTag  将某文件标签tag 替换成 字符串内容，只有1对标志串适用，deep_in_array 二维数组中查询查值，cpoldproname 复制 旧的产品文件名 到 /page/$productPic.html  旧产品详细页文件名兼容，get_product_cate_pics 获得某类下所有产品的图片及连接，editorPath后台编辑器中的内链与图片转换成相对路径，catepro1某类产品是否是1个，是返回其url 否则 ">1" ； 文章funccatear1，getproductfolder获取产品文件夹，getpiclink获得产品的图片路径 和 链接，funccatearnum某类文章数量，getcatetotal查此大类中类数，replalltext替换产品、文章、单页等数据库中文本内容 

*/
/*================= 字符串函数 ========================*/

/*
根据当前语种获得菜单项翻译
*/
function getlangmemu($menustr){
	include('constant.php');

	//$lang=str_replace("/","",$_SESSION['landir']);
	$lang=$lang==""?"en":$lang;
	$lang=$lang2!=""?$lang2:$lang; //qitayuzhong 
	
	//echo $lang."--".$menustr."--".$langmenu[$lang][$menustr]."<br/>";
	return $langmenu[$lang][strtolower($menustr)];
}

/*
根据产品$productID获得多语种上跳路径
*/
function getdda($productID){
	$proa=getpiclink($productID,"");
	$countsl=substr_count($proa['picsrc'],'/');
	$dda=$countsl==4?"../../../":($countsl==3?"../../":($countsl==2?"../":""));
	$dda.="../"; //语言层
    return $dda;
}
/*
字符串$str是否精确匹配
数组$stack里 的项目
*/
function strin($str,$stack,$ignorecase=true){
	$str=trim($str);
	if($ignorecase)$str=strtolower($str);

	//echo $str."--1--".$stack[0]."<br/>";
	for($i=0;$i< count($stack);$i++){ 
		if($ignorecase) $stacki=strtolower($stack[$i]); else $stacki= $stack[$i] ;
		if( $str==trim($stacki))return true;
	}
    return false;
}

/*
在数组$stack里 的每个项目
是否是字符串$str一部分
*/
function strinclude($str,$stack,$ignorecase=true){
	$str=trim($str);
	if($ignorecase)$str=strtolower($str);
	 

	//echo $str."--1--".$stack[0]."<br/>";
	for($i=0;$i< count($stack);$i++){ 
		if($ignorecase)$stacki=strtolower($stack[$i]);
		if(!( strpos($str,trim( $stacki ))===false))return true;
	}
    return false;
}	


function ggdecode($str){
    $str=str_replace("\\x26lt;","<",$str);
    $str=str_replace("\\x3d","=",$str);
    $str=str_replace("\\x26#39;","'",$str);
    $str=str_replace("\\x26gt;",">",$str);
    return$str;
}
/*
------------------------------------------------------
编辑器内容宏提花处理
返回处理好的字符串
------------------------------------------------------
*/
function replmactext($str){ 
	global $config_row;
	require('constant.php');
	$lsm_web=$lsm_web==""?$_SERVER['SERVER_NAME']:$lsm_web;//constant没设置用config companyNameCn
	$lsm_name=$lsm_name==""?$config_row['companyNameCn']:$lsm_name;
	$lsm_email=$lsm_email==""?$config_row['email']:$lsm_email;
	$str =str_replace("~thisweb~",$lsm_web,$str); 
	$str =str_replace("~name~",$lsm_name,$str); 
	$str =str_replace("~email~",$lsm_email,$str); 
	return $str;

}
/*
------------------------------------------------------
编辑器内容处理
$str,$phpself $_SERVER['PHP_SELF']
返回处理好的字符串
------------------------------------------------------
*/
function editorprocess($str,$phpself,$alt,$title){ 
	$opendb=new mydb();
	//$str = str_replace("''","'",$str ); 
	//$str = str_replace("'","''",$str ); //处理单引号
	$str =str_replace("'","&#039;",$str); 
	$str = strreppattern($str ); //video 代码
	$str = strreppattern($str ); //video 代码
	//编辑器中的内链与图片转换成相对路径
	$str = editorPath('http://'.$_SERVER['HTTP_HOST'].$phpself, $str);//内链
	$str = editorPath($phpself, $str);//图片
	$str = addAltTitle($alt,$title, $str); //图片添加alt,title
	$str = editorsrcset($str); //图片分级处理
	$srcstr="</video>";
	if(strlen($str)-strrpos($str,$srcstr)<=16) $str.="<br/>"; //视频在尾部 加 换行以便删除 2	
	$str = deployvideo($str); //视频控制
	 
	//内链
	$in_sql="SELECT * FROM ls_internal where enable=1 ";
	$in_query=$opendb->query($in_sql);
	while ($in_rows=mysqli_fetch_assoc($in_query)){
		$stitle = $in_rows['title'];
		$surl = $in_rows['url'];
		if($stitle!="" && $surl!="") $str = internal_keyword_link($str,$stitle,$surl);
	}
	return $str;
}
/*------------------------------------------------------
处理名称里面的特殊字符 / '
*/
function clearname($name ) {
	$name =str_replace("\\"," ",$name  );
	$name =str_replace("'","&#039;",$name); 
	
	//$name =str_replace("''","'",$name ); //回源两个单引号
	//$name =str_replace("'","''",$name );
	return trim($name) ;
}
/* treeoperatefiles 函数群
部署视频，uedit将编辑器上传的视频，加入控件，使之可以播放
uedit  上传视频 适合 flv 视频，可处理多flv段视频,最多6个
返回 产品字段
*/
function deployvideo($videostr,$i=1){  //uedit  上传视频 适合 flv 视频
require('constant.php');
 if(strpos($videostr,$videorepl)===false) $videostr=str_replace('controls=""',$videorepl ,$videostr); 
 return $videostr;
}
/*
------------------------------------------------------
$str	编辑器内容
返回处理好的字符串，增加size 22-4-28
程序功能： 编辑器图片处理成 小尺寸，并加 srcset 不同尺寸加载处理
------------------------------------------------------
*/
function editorsrcset($str){
	$str1='<img src="';
	$str2='"';
	if(!strpos($str,"srcset=")===false) $str=strippattern($str,' srcset="','"'); //去除srcset
	//echo $str; exit;
	$p = "%".$str1."(.*?)".$str2."%si";
	preg_match_all($p, $str, $arr);
	$temarr = $arr[1];
	foreach($temarr as $val){
		$srcsetstr=srcsetpic($val); 
		$str= str_replace($str1.$val.$str2, $str1.$val.$str2.$srcsetstr.$addstr, $str);
	}
	return $str;
}

/*
图片处理成多个小尺寸图，支持更新图，已存在跳过
根据constant 的$picsas，返回<img srcset 串
<img src=$imgstr
*/
function srcsetpic($img,$folder=""){
	include('constant.php');

	$na=explode(",",$picnas);
	$sa=explode(",",$picsas);
	$imgstr21=' srcset= "'.$_SESSION['dda'].$img.$picsamax ; //多语
	//$imgstr21=' srcset= "';
	$addf=$folder==""?"":"../".$folder;
	$img1=$addf.$img;
	$imgtime=filemtime ($img1);
	list($width, $height, $type, $attr) = getimagesize($img1);
	for($i = 0; $i < count($sa) ; $i++)
	{if(!strpos($img,$na[$i])===false) return; } //本身是小图，返回

	for($i = 0; $i <  count($sa) ; $i++)
	{	
		if($width<=$sa[$i])continue; // 大图<缩小尺寸， 跳过
		$repl=substr($img,strrpos($img,"."));
		$toFile=str_replace($repl,str_replace(".",$na[$i],$repl),$img);
		$toFile1=$addf.$toFile;
		
		//if($folder!=""){echo $folder."--".$img1."--".$toFile1;exit;}
		if(file_exists($toFile1)) $totime=filemtime ($toFile1); else $totime=0;
		if( $totime<$imgtime ) ImageResize($img1,$sa[$i],$sa[$i]/$width*$height,$toFile1,false,8);
		//没改过
		//echo $img1."--2--".$toFile1."<br/>";
		//$imgstr21.=' '.$sa[$i].'w, '.$_SESSION['dda'].$toFile;
		$imgstr21.=$_SESSION['dda'].$toFile.' '.$sa[$i].'w, ';
		//echo $imgstr21." -- ".$sa[$i]."<br/>";
		 
	}
	//$imgstr21.=' 50w"'; //最小大小
	$imgstr21.='"'.$picsasize;  //size
	//echo $imgstr21."<br/>";
	return $imgstr21;
}

//去除固定开头结尾的串（注释）
//$content 输入字符串
//$str1="<!--" 开始
//$str2="-->" 结束

function strippattern($content,$str1="<!--",$str2="-->"){		 
		$p = "%".$str1."(.*?)".$str2."%si";    //正则表达式
		preg_match_all($p, $content, $arr);
		$temarr = $arr[1];

		foreach($temarr as $val){
			$content = str_replace($str1.$val.$str2, "", $content);
			$content = str_replace("\r\n\r\n", "\r\n", $content); //去掉双空行
		}
		return  $content;
};

//替换固定开头结尾的串，为新的固定开头结尾，中间有特征串，视频mp4 处理
//$content 输入字符串
//$str1 源开始
//$end1 源结束
//$str2  替换开始
//$end2  替换结束

function strreppattern($content,$str1="<embed ",$end1=" />",$str2="<video ",$end2=" controls='' />",$flag=".mp4"){		 
		$p = "%".$str1."(.*?)".$end1."%si";    //正则表达式
		preg_match_all($p, $content, $arr);
		$temarr = $arr[1];

		foreach($temarr as $val){
			 
			if(!(strpos($val,$flag)===false)) $content = str_replace($str1.$val.$end1, $str2.$val.$end2, $content);
			 
		}
		return  $content;
};

//二维数组中查询查值，返回 查到的一维数组  翻译系统用到
function deep_in_array($value, $array) {
	$cars = array();
	foreach($array as $k=>$val){
		if($val['translate_name'] == $value){
			$cars = $val;
			return $cars;
		}
	}
	return $cars;
}

//1,2 维数组是否包含某值，区分大小写
function deep_in_array12($value, $array) {
    foreach($array as $item) {
        if(!is_array($item)) {
            if ($item == $value) {
                return true;
            } else {
                continue;
            }
        }
        if(in_array($value, $item)) {
            return true;
        } else if(deep_in_array($value, $item)) {
            return true;
        }
    }
    return false;
}

/*------------------------------------------------------
修改关键词分隔符为英文,
*/
function clearkeywords($siteKeywords ) {
	$siteKeywords =str_replace("'","\'",$siteKeywords  );
	$siteKeywords =str_replace("，",",",$siteKeywords );
	$siteKeywords =str_replace("、",",",$siteKeywords );
	$siteKeywords =str_replace("|",",",$siteKeywords );
	$siteKeywords =str_replace("\r\n",",",$siteKeywords );
	$siteKeywords =str_replace(",,,,",",",$siteKeywords );
	$siteKeywords =str_replace(",,",",",$siteKeywords );
	$siteKeywords =str_replace("-",",",$siteKeywords );
	$siteKeywords =trim(str_replace(" - ",",",$siteKeywords ));
	return $siteKeywords ;
}


/*
getStrbyTag 通过匹配首串 和尾串 获得中间首串 和尾串 的字符串
$headTag,$tailTag 首串和尾串
true 包括首尾串
返回获得的串
$imgwidth=getStrbyTag('width=',' ',$newsImgStr,false);
*/

function getStrbyTag($headTag,$tailTag,$str,$includeHeadTail=true)
{
		$midStr=substr($str,strpos($str,$headTag),strlen($str));
		$gotStr=strtolower(substr($midStr,0,strpos($midStr,$tailTag)+strlen($tailTag)));
		
		if(!$includeHeadTail)
		{
			$gotStr=str_replace($headTag,"",$gotStr);
			$gotStr=str_replace($tailTag,"",$gotStr);
			
		}
		//echo "1--".$gotStr."--1";
		return $gotStr;
}

/*
------------------------------------------------------
参数：
$filename  //生成文件名
$tagBegin,$tagEnd  //开始和结束标志
$replaceStr  //替换字符串
程序功能：将某文件标签tag 替换成 字符串内容，只有1对标志串适用
------------------------------------------------------
*/
function writeTag($filename,$tagBegin,$tagEnd,$replaceStr)
{
	if(!file_exists($filename))
	{
		echo "源文件".$filename."不存在！请设计好后重新生成。</br></br>";
		return;
	}

	
	$fp       = fopen ($filename,"r");
	$content  = fread ($fp,filesize ($filename));
	$len=strlen($content);
	$position1 = strpos ($content,$tagBegin);
	$content1  = substr ($content,0,$position1);	//前半部分
	
	$position2= strpos ($content,$tagEnd);
	$content2  = substr ($content,$position2,($len-$position2));	//后半部分
	$newContent = $content1.$tagBegin.$replaceStr.$content2;
	
	fclose ($fp); //关闭指针	
	
	$handle   = fopen ($filename,"w"); //打开文件指针，创建文件
		  /*
		　检查文件是否被创建且可写
		  */
		
	if (!is_writable ($filename))
	{ 
		echo "<script>alert('文件：".$filename."不可写，请检查其属性后重试！');history.go(-1);</script>";
	}
	if (!fwrite ($handle,$newContent))
	{  //将信息写入文件
		echo "<script>alert('生成文件".$filename."失败！');history.go(-1);</script>";
	} 
	fclose ($handle); //关闭指针
}

//段落文字与处理函数，英文预处理：中文标点 换英文，标点后加空格，替换特殊符号

/*================= 类别函数 ========================*/
/*
------------------------------------------------------
旧产品详细页文件名兼容，复制 旧的产品文件名 到 /page/$productPic.html
------------------------------------------------------
*/
function cpoldproname($profilename,$productpic)
{
	$profolder=substr($profilename,0,strrpos($profilename,"/"));
	if(!is_dir($profolder)) mkdir($profolder);
	$oldpro=substr($productpic,0,strrpos($productpic,"."));
	if($oldpro=="")return false;
	$pagefolder=$profolder."/page";
	if(!is_dir($pagefolder)){  mkdir($pagefolder, 0755); chmod($pagefolder, 0755);}
	$oldprofilename=$pagefolder."/".$oldpro.".html" ;
	if(file_exists($oldprofilename))   unlink($oldprofilename); 
	if(copy($profilename,$oldprofilename)) {
		$oldstr=array("'../",'"../',"'images/",'"images/',"'thumbnails/",'"thumbnails/',);
		$newstr=array("'../../",'"../../',"'../images/",'"../images/',"'../thumbnails/",'"../thumbnails/',);
		filereplace($oldprofilename,$oldstr,$newstr); //加一层路径
		return true; 
	}
	else return false;
	
}
// 文件内容替换， 文件 $file1 中  $oldstr1 替换为 $newstr1
function filereplace($file1,$oldstr1,$newstr1)
{
	if(file_exists($file1)) 
	{
		$allfile= file_get_contents($file1); 
		$allfile=str_replace($oldstr1,$newstr1,$allfile,$i);
		if(file_put_contents($file1,$allfile))
		{
			return $i; //替换次数
		}else{
			return false;
		}
		 
	}else{
		return false;
 	}

}
// 获得某类下第一个产品的记录 for get_allcatepics
function get_product_class_rows($classpro_rowsID)
{
	require_once('inc/conn.php');
	$opendb=new mydb();

	$product_class_sql="select * from ls_products where branchID=0 and productID=".$classpro_rowsID." and AdditionalAttributesClassPro&1   order by Num ASC";	//定义 AdditionalAttributesClassPro 属性
	$product_class_query=$opendb->query($product_class_sql);
	$product_class_num=mysqli_num_rows($product_class_query);
	if($product_class_num>=1) //已定义classpro 展示产品
	{
		$product_class_rows=mysqli_fetch_assoc($product_class_query);
	}
	else  //未定义classpro 展示产品，直接选一个
	{
		$product_class_sql="select * from ls_products where  branchID=0 and productID=".$classpro_rowsID." and enable=1  order by ID desc";
		$product_class_query=$opendb->query($product_class_sql);
		$product_class_num=mysqli_num_rows($product_class_query);
		if($product_class_num>=1) //已定义classpro 展示产品
		{
			$product_class_rows=mysqli_fetch_assoc($product_class_query);
		}
	}
	return $product_class_rows;
}
	
// 获得某类下所有产品的图片及连接
function get_product_cate_pics($catepics_rowsID,$thisfolder)
{
	$s_catepics="";
	require_once('inc/conn.php');
	$opendb=new mydb();
	global $ls_catepicsPicW;

	$catepics_sql="select * from ls_products where branchID=0 and  productID=".$catepics_rowsID." and enable=1  order by ID desc";
	$catepics_query=$opendb->query($catepics_sql);
	$catepics_num=mysqli_num_rows($catepics_query);
	if($catepics_num>=1) //已定义catepics 展示产品
	{
		while($catepics_rows=mysqli_fetch_assoc($catepics_query))
		{
			$catepics_piclink=getpiclink($catepics_rows['ID'],$catepics_rows['productPic']); //
			//echo $catepics_rows['ID']."--".$catepics_piclink['picsrc']; // /thumbnails/1361107436.jpg  带/

			$s_catepics.="<li class=\"class_dt\"><a href=\"../".$thisfolder.$catepics_piclink['piclink']."\"><img src='../".$thisfolder.$catepics_piclink['picsrc']."' width='".$ls_catepicsPicW."' border='0'></a> </li> \r\n";	//每类产品一行
			//echo $s_catepics;
			
		}
	}
	else
	{
		//$s_catepics="No products in cate ".$catepics_rowsID;
	}

return $s_catepics;
}

//后台编辑器中的内链与图片转换成相对路径
function editorPath($urlPath, $specification){
	if(strpos($urlPath, "/ls_admin") == 0){
		return str_replace("src=\"/ls_admin", "src=\"../ls_admin", $specification);
	}else{
		return str_replace(substr($urlPath, 0, strpos($urlPath, "/ls_admin")), "..", $specification);
	}
}

/*查询大类下是否有小类*/
function query_subcate($cateid){
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$midcate_pic_sql="SELECT * FROM `ls_products` WHERE `midcateID`=".$cateid."";
	$midcate_pic_query=$opendb->query($midcate_pic_sql);
	
	while($midcate_pic_rows=mysqli_fetch_assoc($midcate_pic_query)){
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `subcateID`=".$midcate_pic_rows['ID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		
		$subcate_pic_rows=mysqli_fetch_assoc($subcate_pic_query);
		if($subcate_pic_rows){
			return true;
		}else{
			return false;
		}
	}
}

/* 获得ls_function video 1行 */
function funcvideorow($cateName)
{
	require('inc/constant.php');
	require_once('inc/conn.php');
	$opendb=new mydb();
	$menuar_sql="SELECT * FROM ls_functioncates where functionName='video' and cateName='".$cateName."' ";
 
	$menuar_query=$opendb->query($menuar_sql);
	$menuar_num=mysqli_num_rows($menuar_query); //总数
	$menuar_rows=mysqli_fetch_assoc($menuar_query);
	return $menuar_rows; 
}
/*
------------------------------------------------------
是否是ls_article的大类
$functionName 大类名
------------------------------------------------------
*/
function ifarfunc($functionName="")
{
	require('inc/constant.php');
	require_once('inc/conn.php');
	$opendb=new mydb();
	$menuar_sql="SELECT * FROM ls_article where functionName='".$functionName."' ";
 
	$menuar_query=$opendb->query($menuar_sql);
	$menuar_num=mysqli_num_rows($menuar_query); //总数
	$menuar_rows=mysqli_fetch_assoc($menuar_query);
	$catename=$menuar_rows['cateName'];
	//if($catename !="") if(strpos($defaultmenu,$cateName)===false);
	if($catename==""  ) return true; else return false; 
}

/*
------------------------------------------------------
某类产品是否是1个，是返回其url 否则 ">1"
$productID 类ID
$folder  产品路径，
------------------------------------------------------
*/
function catepro1($productID,$folder="")
{
	require('inc/constant.php');
	require_once('inc/conn.php');
	$opendb=new mydb();
	$menuar_sql="SELECT * FROM ls_products where productID='".$productID."'   order by Num desc";
	 
	$menuar_query=$opendb->query($menuar_sql);
	$menuar_num=mysqli_num_rows($menuar_query); //总数
	if($menuar_num==1){ //1篇文章 直接打开详细
		$menuar_rows=mysqli_fetch_assoc($menuar_query);
		$filename=$menuar_rows['filename']==""?clearFolder(strtolower(pathProName($menuar_rows['productName'])))."-".$menuar_rows['ID'].'.html':$menuar_rows['filename']; //21-7-28
		$menufunc_url="../". ($folder==""? getproductfolder($productID):$folder).'/'.$filename; //21-7-28
		
		//echo $menuar_sql."--".$functionName."--".$cateName."--".$menufunc_url; exit;
		return $menufunc_url;
	}
	return ">1";
}

/*
------------------------------------------------------
参数：
$productID  字段  productID 值
$file  相对与于根目录的目录路径
程序功能：获取产品文件夹
------------------------------------------------------
*/
function getproductfolder($productID)
{

	$opendb=new mydb();
	require('char_set.php');
	if($productID=="")	return; //没有跳过
	
 
	
	$search_subcate_sql="select * from ls_products where ID = ".$productID."";
	$search_subcate_query=$opendb->query($search_subcate_sql);
	$search_subcate_rows=mysqli_fetch_assoc($search_subcate_query);
	
	if($search_subcate_rows['subcateName']=="")
	{
		if($search_subcate_rows['midcateName']=="")//??
		{
			$procate=$search_subcate_rows['cateName'];
			$procateid=$search_subcate_rows['ID'];
		
			$file=$search_subcate_rows['cateFolders'];
		
		}
		else //??+??
		{
			if($search_subcate_rows['midcateID']=="")	return; //没有跳过

			$search_cate_sql="select * from ls_products where ID = ".$search_subcate_rows['midcateID']."";
			$search_cate_query=$opendb->query($search_cate_sql);
			$search_cate_rows=mysqli_fetch_assoc($search_cate_query);

		//??????
			$file=$search_cate_rows['cateFolders']."/".$search_subcate_rows['midcateFolders'];
		
		}
		
	}
	else//??+??+??
	{
	  $procate=$search_subcate_rows['subcateName'];
	  $procateid=$search_subcate_rows['ID'];
	  //????
	  	//if($search_subcate_rows['subcateID']=="" || $search_midcate_rows['midcateID']=="")	return; //没有跳过

		$search_midcate_sql="select * from ls_products where ID = ".$search_subcate_rows['subcateID']."";
		$search_midcate_query=$opendb->query($search_midcate_sql);
		$search_midcate_rows=mysqli_fetch_assoc($search_midcate_query);
	  
	  //????
		$search_cate_sql="select * from ls_products where ID = ".$search_midcate_rows['midcateID']."";
		$search_cate_query=$opendb->query($search_cate_sql);
		$search_cate_rows=mysqli_fetch_assoc($search_cate_query);
		
					//??????
		$file=$search_cate_rows['cateFolders']."/".$search_midcate_rows['midcateFolders']."/".$search_subcate_rows['subcateFolders'];
	}
	 
	return($file);			
}

// 获得上级目录名
// $productID  字段  productID 值
function getproductpath($productID)
{

	$opendb=new mydb();
	require('char_set.php');
	if($productID=="")	return; //没有跳过

	$search_subcate_sql="select * from ls_products where ID = ".$productID."";
	$search_subcate_query=$opendb->query($search_subcate_sql);
	$search_subcate_rows=mysqli_fetch_assoc($search_subcate_query);
	
	if($search_subcate_rows['subcateName']=="")
	{
		if($search_subcate_rows['midcateName']=="")//??
		{
			$procate=$search_subcate_rows['cateName'];
			$procateid=$search_subcate_rows['ID'];
			$file=$search_subcate_rows['cateFolders'];
		}else{
			if($search_subcate_rows['midcateID']=="")	return; //没有跳过
			$search_cate_sql="select * from ls_products where ID = ".$search_subcate_rows['midcateID']."";
			$search_cate_query=$opendb->query($search_cate_sql);
			$search_cate_rows=mysqli_fetch_assoc($search_cate_query);
			$file=$search_subcate_rows['midcateFolders'];
		}
	}else{
	  $procate=$search_subcate_rows['subcateName'];
	  $procateid=$search_subcate_rows['ID'];

		$search_midcate_sql="select * from ls_products where ID = ".$search_subcate_rows['subcateID']."";
		$search_midcate_query=$opendb->query($search_midcate_sql);
		$search_midcate_rows=mysqli_fetch_assoc($search_midcate_query);

		$search_cate_sql="select * from ls_products where ID = ".$search_midcate_rows['midcateID']."";
		$search_cate_query=$opendb->query($search_cate_sql);
		$search_cate_rows=mysqli_fetch_assoc($search_cate_query);
		
		$file=$search_subcate_rows['subcateFolders'];

	}
	return($file);			
}


/*
根据产品分类ID获得产品的图片路径 和 链接，支持中类下产品
返回$propiclink  路径 和 链接 数组
$productpic="" 则选第1个产品的图片Num ASC
$classpro 搜索附加串
*/
function getpiclink($productID,$productpic="",$productfile="",$classpro="")
{
//echo "func-".$productfile."--pic-".$productpic." id:" .$productID."<br/>";

	require_once('conn.php');
	$opendb=new mydb();
	require_once('char_set.php');
	global $SmallFoldersProducts,$showproductsFolders;
	//echo "==".$SmallFoldersProducts."==";
	if($productpic==""){ //第1个产品的图片
		$pic_sql="select * from ls_products where productID=".$productID.$classpro." and enable=1 order by Num ASC ";
		//echo $pic_sql;
		$pic_query=$opendb->query($pic_sql);
		$pic_myrows=mysqli_fetch_assoc($pic_query);
		if($pic_myrows['ID']=="")  //return false; //没有跳过  查中类  22-5-7
		{
			$pic_sqlm1="select * from ls_products where midcateID=".$productID." and enable=1 order by Num ASC ";
			//echo $pic_sql1."<br/>";
			$pic_querym1=$opendb->query($pic_sqlm1);
			while($pic_myrowsm1=mysqli_fetch_assoc($pic_querym1)){
				$pic_sqlm2="select * from ls_products where productID=".$pic_myrowsm1['ID'].$classpro." and enable=1 order by Num ASC ";
				//echo $pic_sql2."<br/>";
				$pic_querym2=$opendb->query($pic_sqlm2);
				$pic_myrowsm2=mysqli_fetch_assoc($pic_querym2);
				if($pic_myrowsm2['ID']=="")  continue; //没有跳过  查中类
				$pic_myrows=$pic_myrowsm2; //找到传递给 $pic_myrows
				$productID=$pic_myrowsm1['ID'];break; //找到第一个跳出循环
				//echo $pic_myrowsm1['ID']."<br/>"; 
					
			}
			if($pic_myrows=="") return false;
		}
		$productpic=$pic_myrows['productPic'];
		//echo $productpic."<br/>";
		$proptname1=pathProName($pic_myrows['productName']);
		$proptname1=strtolower($proptname1);
		$filenamepro=clearFolder($proptname1)."-".$pic_myrows['ID'].".html";
	}
	if($productID=="")return false; //没有跳过
	$productfile=$productfile==""?$filenamepro:$productfile;
	

	$pic_sql="select * from ls_products where ID=".$productID." ";
	$pic_query=$opendb->query($pic_sql);
	$pic_myrows=mysqli_fetch_assoc($pic_query);

	if($pic_myrows['subcateFolders']=="")
	{
		if($pic_myrows['midcateFolders']=="") //产品在大类下
		{
			$picsrc=$pic_myrows['cateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows['cateFolders']."/".$productfile; //trim(str_replace(substr($productpic,-4),"",$productpic)).".html" 2020-9-16
		}
		else//产品在中类下
		{
		
			$pic_sql="select * from ls_products where ID=".$pic_myrows['midcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows2=mysqli_fetch_assoc($pic_query);

			$picsrc=$pic_myrows2['cateFolders']."/".$pic_myrows['midcateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows2['cateFolders']."/".$pic_myrows['midcateFolders']."/".$productfile; //trim(str_replace(substr($productpic,-4),"",$productpic)).".html"
		}
	}
	else//产品在小类下
	{
			$pic_sql="select * from ls_products where ID=".$pic_myrows['subcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows2=mysqli_fetch_assoc($pic_query);

			$pic_sql="select * from ls_products where ID=".$pic_myrows2['midcateID']."";
			$pic_query=$opendb->query($pic_sql);
			$pic_myrows3=mysqli_fetch_assoc($pic_query);
			
			$picsrc=$pic_myrows3['cateFolders']."/".$pic_myrows2['midcateFolders']."/".$pic_myrows['subcateFolders']."/".$SmallFoldersProducts."/".$productpic;
			$piclink=$pic_myrows3['cateFolders']."/".$pic_myrows2['midcateFolders']."/".$pic_myrows['subcateFolders']."/".$productfile; //trim(str_replace(substr($productpic,-4),"",$productpic)).".html"
	}	
	
	//echo $ID.$picsrc."--".$piclink;
	//die();
	$propiclink=array("picsrc"=>$picsrc,"piclink"=>$piclink);
	//var_dump($propiclink);
	return $propiclink;
}


/*
------------------------------------------------------
某类文章是否是1篇，是返回其url 或 ">1"
$functionName 大类名
$cateName  中类名，
------------------------------------------------------
*/
function funccatear1($functionName="",$cateName="",$folder="")
{
	require('inc/constant.php');
	require_once('inc/conn.php');
	$opendb=new mydb();
	if($functionName!="" && $cateName!="" )	$menuar_sql="SELECT * FROM ls_article where functionName='".$functionName."' and cateName='".$cateName."' order by Num desc";
	else	if($functionName!="" && $cateName=="") $menuar_sql="SELECT * FROM ls_article   where functionName='".$functionName."' order by Num desc";
		else return "functionName is empty!";
		
	if( $functionName=="新闻分类") {$menuar_sql="SELECT * FROM ls_news   where cate='news'  and enable=1 order by Num desc";$folder="newspage";}
	if($functionName=="博客分类" ) {$menuar_sql="SELECT * FROM ls_news   where cate='blog'  and enable=1 order by Num desc";$folder="blog";}
	if($functionName=="常见问题") {$menuar_sql="SELECT * FROM ls_news   where cate='faq'  and enable=1 order by Num desc";$folder="faqpage";}
		
	$menuar_query=$opendb->query($menuar_sql);
	$menuar_num=mysqli_num_rows($menuar_query); //总数
	if($menuar_num==1){ //1篇文章 直接打开详细
		$menuar_rows=mysqli_fetch_assoc($menuar_query);
		$menufunc_url= ($folder==""? getarfolder($functionName,$cateName):$folder).'/'.$ars_show.$menuar_rows['ID'].'.html';
		
		//echo $menuar_sql."--".$functionName."--".$cateName."--".$menufunc_url; exit;
		return $menufunc_url;
	}
	return ">1";
}

/*
------------------------------------------------------
返回类别的folder
$functionName 大类名
$cateName  中类名，
------------------------------------------------------
*/
function getarfolder($functionName="",$cateName="")
{
	require_once('inc/conn.php');
	$opendb=new mydb();
	if($functionName!="" && $cateName!="" )	$menuar_sql="SELECT * FROM  ls_functioncates   where functionName='".$functionName."' and cateName='".$cateName."'   order by Num desc";
	else
		if($functionName!="" && $cateName=="") $menuar_sql="SELECT * FROM  ls_functioncates where functionName='".$functionName."'   order by Num desc";
		else return "functionName is empty!";
	
	$menuar_query=$opendb->query($menuar_sql);
	$menuar_rows=mysqli_fetch_assoc($menuar_query);
	return $menuar_rows['folder'];
}

/*
------------------------------------------------------
某类文章数量 21-3-19
$functionName 大类名
$cateName  中类名，
------------------------------------------------------
*/
function funccatearnum($functionName="",$cateName="")
{
	require('inc/constant.php');
	require_once('inc/conn.php');
	$opendb=new mydb();
	$functionName=str_replace("'","''",$functionName);
	$cateName=str_replace("'","''",$cateName);
	if(  $cateName=="products" )	$menuar_sql="select count(*) as ctrows FROM ls_products where (productName!='' or productName is not NULL) and enable=1 order by Num desc";	
	else 	if( $cateName=="news" || $cateName=="faq"  || $cateName=="blog"   ) $menuar_sql="select count(*) as ctrows FROM ls_news where cate='".$cateName."' and enable=1 order by Num desc"; 
	else 	if( $cateName=="video"    ) $menuar_sql="select count(*) as ctrows FROM ls_video where enable=1 order by Num desc"; 
	else 	if( $cateName=="download"    ) $menuar_sql="select count(*) as ctrows FROM ls_download where enable=1 order by Num desc"; 
	else	if($functionName!="" && $cateName!="" )	$menuar_sql="select count(*) as ctrows FROM ls_article where functionName='".$functionName."' and cateName='".$cateName."' and enable=1 order by Num desc"; 
			else
				if($functionName!="" && $cateName=="") $menuar_sql="select count(*) as ctrows FROM ls_article where functionName='".$functionName."' and enable=1 order by Num desc";
				else return "functionName is empty!";
	//echo $menuar_sql;
	$menuar_query=$opendb->query($menuar_sql);
	$row = mysqli_fetch_assoc($menuar_query);					  
	$menuar_num= $row['ctrows']; //总数
	return $menuar_num;
}
/*
------------------------------------------------------
参数：
$cateName 大类名，为空查所有大类数量；不空查此大类中类数
$midcatename  中类名，
------------------------------------------------------
*/
function getcatetotal($catename="",$midcatename="")
{
	if($catename==""){
		$select_sql2="select * from ls_products where cateName!='' ";
		$select_query2=$opendb->query($select_sql2);
		$select_rows2=mysqli_num_rows($select_query2); //总产品数
		return $select_rows2;
	}else{
		if($midcatename==""){
			$select_sql2="select * from ls_products where cateName!='".$catename."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysqli_num_rows($select_query2); //总产品数
			return $select_rows2;
		}
	}
}

/*
------------------------------------------------------
返回大类及其子类下产品数量
参数：
$cateID 大类ID
------------------------------------------------------
*/
function cateprototal($cateid)
{
	require_once('inc/conn.php');
	$opendb=new mydb();
	
	$rows=0;
	$select_sql2="SELECT * FROM `ls_products` WHERE `midcateID`=".$cateid."  order by Num";
	$select_query2=$opendb->query($select_sql2);
	$select_rows2=mysqli_num_rows($select_query2);  
	if( $select_rows2==0 ){
		$select_sql21="SELECT * FROM `ls_products` WHERE `productID`=".$cateid."  order by Num";
		$select_query21=$opendb->query($select_sql21);
		$rows=mysqli_num_rows($select_query21); 
	
	}else{
		while($midcate_rows=mysqli_fetch_assoc($select_query2)){
			  $select_sql22="select * from ls_products where productID='".$midcate_rows['ID']."' ";
			  $select_query22=$opendb->query($select_sql22);
			  $select_rows22=mysqli_num_rows($select_query22); //总产品数
			  $rows+=$select_rows22;
		}
   }
	return $rows;
}



/*================= 文件夹函数 ========================*/

/*删除文件夹及文件函数*/
function deldir($dir){
	$dh = opendir($dir);
	while ($file = readdir($dh)){
		if ($file != "." && $file != ".."){
			$fullpath = $dir . "/" . $file;
			if (!is_dir($fullpath)){
				unlink($fullpath);         
			}else{
				deldir($fullpath);
			}
		}
	}
	closedir($dh); 
	if (rmdir($dir)){  
		return true;   
	}else{
		return false;
	}
}

/*------------------------------------------------------
//  递归建立文件夹及子文件夹
//　使用方法crmkdir($folder)  $folder 多级文件夹
------------------------------------------------------*/
function crmkdir($folder)
{
	$mkfolder="";
	$allfolder=explode("/",$folder);
	for($i=0;$i<= count($allfolder);$i++)
	{
		if($allfolder[$i]=="..")
		{
			if($i==0)
			{
				$mkfolder=$allfolder[$i];
			}
			else
			{
				$mkfolder=$mkfolder."/".$allfolder[$i];
			}
		}
		else
		{
			$mkfolder=$mkfolder."/".$allfolder[$i];
			//echo 	$mkfolder."--";
			if(!file_exists($mkfolder))
			{
				mkdir($mkfolder);
			}
		}
		
	}
	
}


/*================= 文件函数 ========================*/

/*------------------------------------------------------
参数：
$varstr   log内容行
程序功能：写入\lslog.txt
------------------------------------------------------*/

function writemsglog($varstr)
{
	$filename="../lslog.txt";
	$handle = fopen ($filename,"a+");
	fwrite($handle,$varstr); 
 	fclose ($handle);
}

/*
------------------------------------------------------
参数：
$filename 
&$str  content str 的引用
程序功能：写入类下产品页ini文件
------------------------------------------------------
*/
function writegeneralfile($filename,&$str)// 避免字符串太大不方便传递值，只传递引用
{
	$content=$str;
	if (is_file ($filename))
	{ 
	   @unlink ($filename); //若文件已存在，则删除
	}

	$handle   = fopen($filename,"w"); //打开文件指针，
		  /*
		　检查文件是否被创建且可写
		  */
	if (!is_writable ($filename))
	{ 
		echo "文件：".$filename."不可写，请检查其属性后重试！";
	}
	if (!fwrite ($handle,$content))
	{  //将信息写入文件
		fclose ($handle); //关闭指针
		return false;
	} 
	else
	{ 
		fclose ($handle); //关闭指针
		return true;
	}

}

/*
------------------------------------------------------
参数：
$varstr   	变量名
$valuestr 	变量值变量类型 str
$vartype 	 or 
参数举例	 	writeconstant("lsVer", 1.181 ,"int","","//----版本号参数");	
程序功能：	写入参数文件函数 constant
如果没有插入标志，先插入插入标志;如果没有这个变量，那么 插入这个变量
------------------------------------------------------
*/

function writeconstant($varstr,$valuestr,$vartype="str",$oprconstant="modify",$insertflag="//----insert flag9",$filename="../ls_admin/inc/constant.php")
{
	
	$handle = fopen($filename,"r");
	$partstr="";
	$partstr0="";
	$modifyOK=false;	//是否成功修改，插入
	while (!feof ($handle)) 
	{
		$partstr0 =  fgets ($handle, 3000);
		//echo rawurlencode($partstr0);
		if(($oprconstant=="modify" || $oprconstant=="" )&& strpos(trim($partstr0),"\$".$varstr."=")===0 )  // 空参数认为是modify
		{
			if($vartype=="str")
			{$partstr0="	\$".$varstr."=\"".$valuestr."\";\r\n";}
			else
			{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}
			$modifyOK=true;
		}
		
		if($oprconstant=="insert" && strpos(trim($partstr0),$insertflag)===0 && strpos($partstr0,$insertflag."end")===false  )	//插入标志行后面
		{
			if($vartype=="str")
			{$partstr0="	\$".$varstr."='".$valuestr."';\r\n";}
			else
			{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}	
			$partstr0="	".$insertflag."\r\n".$partstr0;
			$modifyOK=true;
		}

		$partstr.=$partstr0;
	}
	//echo strlen($partstr);
	fclose ($handle);
	
	if(!$modifyOK && $oprconstant=="insert")  //如果没有插入标志，先插入插入标志
	{
		if($vartype=="str")
		{$partstr0="	\$".$varstr."=\"".$valuestr."\";\r\n";}
		else
		{$partstr0="	\$".$varstr."=".$valuestr.";\r\n";}	
		$partstr0="\r\n	".$insertflag."\r\n".$partstr0;
		$partstr=str_replace("?>",$partstr0."?>",$partstr);
		$modifyOK=true;
	}
	
	writegeneralfile($filename,$partstr); // write the constant.php
	if(!$modifyOK) writeconstant($varstr,$valuestr,$vartype,"insert",$insertflag,$filename);  //如果没有修改成功，则没有这个变量，那么 插入这个变量
}

/*
------------------------------------------------------
参数：
$currentProgram   目前运行程序
$currentFunction 目前功能
$parameter  参数
程序功能：写入日志函数
------------------------------------------------------
*/

function writelog($currentProgram,$currentFunction,$parameter,$username='admin')
{

	global $logSpace,$logStat;
	if($logStat=='stop'){return;}

	$opendb=new mydb();

	$select_sql2="select * from ls_log ";
	$select_query2=$opendb->query($select_sql2);
	$select_rows2=mysqli_num_rows($select_query2); //总数

	if($select_rows2>=$logSpace)
	{
		$del_sql="delete  from  ls_log where 1 limit 30";
		$insert_query=$opendb->query($del_sql);	
	}
	$currentFunction=str_replace("'","`",$currentFunction);
	$parameter=str_replace("'","`",$parameter);

	$insert_sql="insert into ls_log(currentDateTime,currentProgram,currentFunction,parameter,memo,ip,username) values ('".date('Y-m-d G:i:s')."','".$currentProgram."','".$_SESSION['username'].": `".$currentFunction."`','".$parameter."','','".$_SESSION['username']." ".$_SERVER['REMOTE_ADDR']."','".$username."')";
	//echo $insert_sql;
	$insert_query=$opendb->query($insert_sql);	
}

/*
------------------------------------------------------
参数：
$table 表
$id id
$url  文件名
$ifdel 删除标志，0则上线后1个月内删除，否则数据表删除，并ls_writefiles做记录
$del_ar数组 delitems函数处理的定义文件，主图字段，文本字段等
程序功能：删除产品、文章、新闻、博客、单页、下载、genelpic等项目，或者在ls_writefiles标记删除项目
删除数据表响应行，删除主图，删除数据字段上传的图片或文件，调整后续num。其他项目在调用文件删除。
------------------------------------------------------
*/

function delitems($table,$id,$url,$ifdel=1)
{
	$opendb=new mydb();
	$del_ar = array(
		'ls_products'=>array("productPic","productSpecification,canshu,basicInfo,additionalInfo",""),  
		'ls_article'=>array("","articleText,articleBrief","downloadName"), 
		'ls_news'=>array("","newsText",""), 
		'ls_singlepages'=>array("","pageText,pageBrief",""), 
		'ls_download'=>array("","pageText,pageBrief","downloadName") 
	);
	if(ifdel==1 || $ls_debug){ //明确删除，或者上线>31天
	
		
	}else{
		$select_sql2="update ls_writefiles set enable=0 where fromtable='".$table."' and fromlineid=".$id." ";
		$select_query2=$opendb->query($select_sql2);
		if(mysqli_affected_rows()==0){
		  $insert_sql="insert into ls_writefiles(createtime,lastmod,fromtable,fromlineid,url,enable,priority,changefreq) values ('".date('Y-m-d G:i:s')."','".date('Y-m-d G:i:s')."','".$table."',".$id." ,'".$url."',0,0.64,'monthly')";
		  //echo $insert_sql;
		  $insert_query=$opendb->query($insert_sql);	
		}
	}
}

/* 目录树遍历， 替换文件多个关键词
$directory 起始目录
$srca,$obja 源关键词组 目标关键词组，$srca为""则是处理limitwords，否则替换php
$ext 替换文件扩展名，没有依赖$srca，$srca没有则是 htm,html
$repltotal 返回值，替换数量
*/
function treereplacefiles($directory,$srca="",$obja="",$ext="" ) 
{ 
	if($srca==""){
		require_once('inc/ls_limitwords.php');  //为空，使用禁用词库
		$thisext="htm";
	}else{ $thisext="php"; }
	$thisext=$ext==""?$thisext:$ext;
	//var_dump( 	$srca ,$obja ,$ext);exit;
	$mydir=dir($directory);  // php 目录类
	if(!file_exists($directory)) { echo $directory."不存在！已退出。<br/><br/>"; return;}
	static $repltotal=0; $repltotal1=0;
		
	while($file=$mydir->read())
	{ 
		//echo $file."<br/>";;
		if(($file!=".") and ($file!=".."))
		{ 
			if((is_dir("$directory/$file")) )
			{
				treereplacefiles("$directory/$file",$srca,$obja,$ext); //递归查询目录
			}
			else
			{ 
				$wrdirectory=str_replace($directoryRoot,"","$directory");
				$wrdirectoryfile="$wrdirectory/$file";
				//$wrdirectoryfile=$file;
				
				$fileext=getfileext($file);
				
				if($fileext==$thisext){
					$repltotal1=writereplacestr($wrdirectoryfile,$srca,$obja,$srcb ,$objb );
					$repltotal+=$repltotal1;
					echo  $wrdirectoryfile." $repltotal1 <br/>";
				}
			} 
			
		}
	} 
	$mydir->close(); 
	return $repltotal ;
	
} 

/*
------------------------------------------------------
参数：
$srca= array(	'1' => $initCreatTypeHost,  //替换 192.168.2.20 为 域名
				'2' => '2.20', ); 
$obja= array(	'1' => $clearURL,
				'2' => $clearURL,); 

$filename  文件名
$stra 要替换的源字符数串数组
$obja 替换的目标字符数串数组
$srcatotal 出现次数，返回值
$srcb="",$objb="" 需要替回的词
程序功能 读入文件$filename替换 源数组 $srca 为目标数组 $obja

------------------------------------------------------
*/
function writereplacestr($filename,$srca,$obja,$srcb="",$objb="")
{
	$srcatotal=0;
	$fp       = fopen ($filename,"r");
	$content  = fread ($fp,filesize ($filename));
	
	 for($i=0;$i< count($srca);$i++){   
		$srcatotal+=substr_count($content,$srca[$i]);
  		$content  = str_replace($srca[$i],$obja[$i],$content);
		//echo "--".$srca[$i]."--".$obja[$i]."==<br/><br/>\r\n\r\n";
    }
	if($srcb!=""){
		 for($i=0;$i< count($srcb);$i++){    //替换回来
			if(!(strpos($content,$srcb[$i])===false)){
				$content  = str_replace($srcb[$i],$objb[$i],$content);
			}
		}
	}


	$handle   = fopen ($filename,"w"); //打开文件指针，创建文件
	if (!is_writable ($filename))
	{ 
		echo "文件：".$filename."不可写，请检查其属性后重试！";
	}
	if (!fwrite ($handle,$content))
	{  //将信息写入文件
		echo "生成文件".$filename."失败！";
	} 
  	else
	{
	  	//echo "生成".$filename."<br>";
	}

	fclose ($handle); //关闭指针
	fclose ($fp); //关闭指针
	return $srcatotal;
}
	
/* 获得文件扩展名  */
function getfileext($url) 
{ 
	$path=parse_url($url); 
	$filepath=str_replace("./","",str_replace("../","",$path['path']));
	$str=substr($filepath,(strrpos($filepath,'.')+1)); 
	return $str; 
} 

/* 目录树遍历， 操作文件，输出到输出目录
$directory 起始目录
$outputDir 输出目录
$nocopyfiles 跳过文件
$operateFunction 操作函数 
 */
function treeoperatefiles($directory,$noOperateFunction="nomycopyfile",$operateFunction="mycopyfile" ) 
{ 
	global $directoryRoot;
	$mydir=dir($directory);  // php 目录类
		
	while($file=$mydir->read())
	{ 
		//echo $file;
		if(($file!=".") AND ($file!=".."))
		{ 
			if((is_dir("$directory/$file")) )
			{
				treeoperatefiles("$directory/$file",$noOperateFunction,$operateFunction ); //递归查询目录
			}
			else
			{ 
				$wrdirectory=str_replace($directoryRoot,"","$directory");
				$wrdirectoryfile="$wrdirectory/$file";
				//echo $operateFunction."--". $noOperateFunction."--".$wrdirectoryfile."<br/>";
				if($noOperateFunction("$wrdirectoryfile","") )
				{
					// echo "$wrdirectoryfile"."----<br/>";
					if((strpos(iconv('GB2312', 'UTF-8', $file),"拷贝")===false) )
					//已更新目录下的已更新文件
					{ 
							if(!file_exists("$outputDir$wrdirectory")){crmkdir("$outputDir$wrdirectory");}  //
							// echo "$outputDir$wrdirectory/$file"."--<br/>";
							$operateFunction("$directory/$file","$outputDir$wrdirectory/$file");  //拷贝文件
					
					}
				}
			} 
			
		}
	} 
	$mydir->close(); 
	return ;
	
} 

//复制文件
function mycopyfile($file1,$file2)
{copy($file1,$file2);}

function nomycopyfile($file1,$file2)
{
	$file2= array("Templates1/brand.html","Templates2/brand.html","Templates3/brand.html","Templates4/brand.html","Templates1/management.html","Templates2/management.html","Templates3/management.html","Templates4/management.html"); 
	if(!in_array($file1,$file2))
	{return true;}
	else
	{return false;}
	
}
//
// 文件内容替换，多语种替换，文件 $file1 中  $oldstr1 替换为 $newstr1
function replmutilang($file1,$file2)
{
	global $oldstr1,$newstr1,$totalfile,$totalstr;
	if(file_exists($file1)) 
	{
		$allfile= file_get_contents($file1); 
		$coutstr=substr_count($allfile, $oldstr1);
		 
		if($coutstr!=0)
		{
			$allfile=str_replace($oldstr1,$newstr1,$allfile);
			if(file_put_contents($file1,$allfile))
			{
				$totalfile++;
				$totalstr+=$coutstr;
				echo "已替换："." ".$file1."，".$oldstr1."->".$newstr1."<br/>";
			}else{
				echo "替换："." ".$file1."，".$oldstr1."->".$newstr1."失败<br/>";
			}
		}
	}

}


function noreplmutilang($file1,$file2)
{
	$file2= array("html","htm","js","php"); 
	$file3= array("ls_admin","images","css","inc","widget","vplayer","ueditor","styles","scripts","phpqrcode","qr","login-img","kindeditor-4.1.10","player","linkedin","img","font-awesome","code","bootstrap","backupdb","ls_mantain","mail","motif","revolvingpics","Templates","Templates1","video","update",".htaccess","update"); // 跳过文件夹
	
	if(in_array($file1,$file3)){return false;}

	if(in_array(getfileext($file1),$file2) )
	{return true;}
	else
	{
		//echo getfileext($file1)."--".$file1;
		return false;}
	
}

/* 目录树遍历, 拷贝文件
//用法：   
// xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录   
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录   
//参数说明：   
// $source:源目录名   
// $destination:目的目录名   
// $child:复制时，是不是包含的子目录
// $nocopyFile 无需复制的文件、目录（/folder）放到数组里
// $nocopyext 不考的文件类型
// $del_  _和 副本不拷
 */
function xCopy($source, $destination,$nocopyFile=array(), $child=true,$nocopyext="",$del_=false)
{   
   	//var_dump($nocopyFile);
	if(!is_dir($source)){   
	echo("Error:the $source is not a direction!<br/>");   
	return 0;   
	}   
	
	if(!is_dir($destination)){   
	mkdir($destination,0777);   
	}   
	 
	$handle=dir($source);   
	while($entry=$handle->read()) {   
	if(($entry!=".")&&($entry!="..")){   
	if(is_dir($source."/".$entry)){   
		if($child)
		{
			if(!in_array("/".$entry,$nocopyFile )) //检查复制目录   
			xCopy($source."/".$entry,$destination."/".$entry,$nocopyFile,$child,$nocopyext);  
			 
		}
		
	}   
	else{   
		if(!in_array($entry,$nocopyFile ))  //检查复制文件 
		if( $nocopyext!="" && strpos($entry,$nocopyext)===false || $nocopyext=="" )
			if(!$del_){
				if(copy($source."/".$entry,$destination."/".$entry))   
					{$ls_msg.="copy ".($source."/".$entry)."--".$source."/".$entry."--".$destination."/".$entry." ok <br/>";}
			}else{
				if(strpos($source."/".$entry,"_")===false && strpos($source."/".$entry,"副本")===false && strpos($source."/".$entry,"拷贝于")===false && strpos($source."/".$entry,"bak")===false){
					if(copy($source."/".$entry,$destination."/".$entry))   
					{$ls_msg.="copy ".($source."/".$entry)."--".$source."/".$entry."--".$destination."/".$entry." ok <br/>";}
				}else{ // unlink($source."/".$entry);
				}
			}
	}   
	}   
	}   
	 echo $ls_msg; 
	return 1;   
}  

/* 目录树遍历, 拷贝文件
//用法：   
// xCopyincrease 新增加拷贝，有变化的拷贝  
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录   
//参数说明：   
// $source:源目录名   
// $destination:目的目录名   
// $child:复制时，是不是包含的子目录
// $nocopyFile 无需复制的文件、目录（/folder）放到数组里
// $skipprefix 无需复制的文件、目录包含就跳过
// $increasecopyfiles  目录里新增的拷贝
// $changecopyfiles 目录里变化的拷贝
 */
function xCopyincrease($source, $destination,$nocopyFile=array(), $child=true,$skipprefix,$increasecopyfiles,$changecopyfiles)
{   
   	//var_dump($nocopyFile);
	if(!is_dir($source)){   
	echo("Error:the $source is not a direction!<br/>");   
	return 0;   
	}   
	 include("inc/constant.php");
	// echo $transFlags;
	$handle=dir($source);   
	while($entry=$handle->read()) {   
		if(($entry!=".")&&($entry!="..")){   
			  if(is_dir($source."/".$entry)) {    //目录 
			 
				  if($child) { //跳过不考的  
					  if(!in_array("/".$entry,$nocopyFile ))  {
						 $scr32=substr($source,3,2); //跳过多语种
						 $scr21=substr($source,2,1);
						 $scr51=substr($source,5,1);
						//echo $scr32."--".$scr21."--".$scr51."==";
						//  if(strpos( $destination,$scr3)===false)
						if( strpos( $transFlags,$scr32)===false&&  $scr21!="/"&&  $scr51!="/" )xCopyincrease($source."/".$entry,$destination."/".$entry,$nocopyFile,$child,$skipprefix,$increasecopyfiles,$changecopyfiles);
					  }
				  }
			  }   
			  else
			  {    
			  	  //echo $source."/".$entry."----".$destination."/".$entry."  <br/>";
			  		//文件//检查复制文件 
				  if(!in_array($entry,$nocopyFile )){
					  $thisfold=substr($source,(strrpos($source,"/")+1));
					  //sha1_file 比较文件散列值判断文件不同
					  if( strin($thisfold,$changecopyfiles)&& !( substr($entry,0,1)==$skipprefix)  ){ 
					  //echo $destination."/".$entry."<br/>";
					  		if(!file_exists($destination."/".$entry ) )  {  //不存在目标文件，复制
							
								 if( copy($source."/".$entry,$destination."/".$entry))
								  	{$ls_msg.="copy ".$source."/".$entry." -- ". $destination."/".$entry." ok <br/>";}
							}else{
								if(sha1_file($source."/".$entry )!=  sha1_file($destination."/".$entry ) ){   //sha1_file 比较文件散列值判断文件不同
									if(copy($source."/".$entry,$destination."/".$entry))
										{$ls_msg.="copy ".$source."/".$entry." -- ". $destination."/".$entry." ok <br/>";}
								}
							}
					  }
					  else { //增量复制
						  if( strin($thisfold,$increasecopyfiles )   ){ 
							  if(!file_exists($destination."/".$entry ) )  { //不存在
								  if(copy($source."/".$entry,$destination."/".$entry)) 
								  	{$ls_msg.="copy ".$source."/".$entry." -- ".  $destination."/".$entry." ok <br/>";}
							  }
						  }
					  }
				  }
			  }   
		}   
	}   
	echo "".$ls_msg;
	return 1;   
}  
/* 目录树遍历, 根据源目录文件，删除目标目录文件
//用法：   
// xdel("feiy","feiy2",1):删除feiy下的文件到 feiy2,包括子目录   
// xdel("feiy","feiy2",0):删除feiy下的文件到 feiy2,不包括子目录   
//参数说明：   
// $source:源目录名   
// $destination:目的目录名   
// $child:删除时，是不是包含的子目录
// $nocopyFile 无需复制的文件、目录（/folder）放到数组里
 */
function xdel($source, $destination,$nocopyFile=array(), $child=true)
{   
   	//var_dump($nocopyFile);
	if(!is_dir($source)){   
	echo("Error:the $source is not a direction!<br/>");   
	return 0;   
	}   
	if(rmdir( $destination))   
	{$ls_msg.="del ".$destination." ok <br/>";}

	$handle=dir($source);   
	while($entry=$handle->read()) {   
	if(($entry!=".")&&($entry!="..")){   
	if(is_dir($source."/".$entry)){   
		if($child)
		{
			if(rmdir( $destination."/".$entry))   
			{$ls_msg.="del ".$destination." ok <br/>";}
			if(!in_array("/".$entry,$nocopyFile )) //检查复制目录   
			xdel($source."/".$entry,$destination."/".$entry,$nocopyFile,$child);  
		}
	}   
	else{   
		if(!in_array($entry,$nocopyFile ))  //检查复制文件 
		if(file_exists($destination."/".$entry))
			if(unlink( $destination."/".$entry))   
				{$ls_msg.="del ". $destination."/".$entry." ok <br/>";}
	}   
	}   
	}   
	 echo $ls_msg;
	return 1;   
}  

//获取 网站主目录 .20 下用	
function midfolder($thisfolder){
	$mid=substr($thisfolder,1);
	$mid=substr($mid,0,strpos($mid,"/ls_admin") );
	return $mid;
	
}

/*删除指定目录下的文件，不删除目录文件夹*/
function delfolder($dirName){
    if(file_exists($dirName) && $handle=opendir($dirName)){
        while(false!==($item = readdir($handle))){
            if($item!= "." && $item != ".."){
                if(file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)){
                    delfolder($dirName.'/'.$item);
                }else{
                    if(unlink($dirName.'/'.$item)){
                        return true;
                    }
                }
            }
        }
        closedir( $handle);
    }
}

//根据关键词 获得产品页链接，先 类别 后产品
function  getproducturl($keyw){
	$opendb=new mydb();
	$sql="SELECT * FROM `ls_products` WHERE lower(cateName)='".strtolower($keyw)."' or  lower(midcateName)='".strtolower($keyw)."' or  lower(subcateName)='".strtolower($keyw)."' or  lower(productName)='".strtolower($keyw)."'  and enable=1     order by ID desc";
	 
	$query=$opendb->query($sql);
	$Num=1;
	while($rows=mysqli_fetch_assoc($query)){
		if($rows['cateName']!=""||$rows['midcateName']!=""||$rows['subcateName']!="")
		{
			if($rows['cateName']!=""){
				$writeurl1="/".$rows['cateFolders']."/";
			}
			if($rows['midcateName']!=""){
				$writeurl1=getproductpath($rows['midcateID'])."/".$rows['midcateFolders']."/";
			}
			$writeurl2="products_".$rows['ID'].".html";
			$keywords=$rows['cateKeywords'];
		}
		else{
			 $writeurl1=getproductfolder($rows['productID'])."/".$rows['productName']."_".$rows['ID'].".html";
			 $writeurl2="productsshow_".$rows['ID'].".html";
			 $keywords=str_replace("'","''",$rows['productKeywords']);
		}
		$Num++;
	}
	return  $writeurl1;
	//return $writeurl2;
}

//测试url 打开是否正常，如果显示为200则正常，如果显示其它值表示不正常；$timeout后面的3是设置超时秒数
function httptest($url){
	//设置最大执行时间是8秒
	$maxtime=ini_get('max_execution_time') ;
	
	ini_set('max_execution_time',8);
	$ch = curl_init();
	$timeout = 4;
	
	if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
   		 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	}
	
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	curl_setopt($ch,CURLOPT_URL,$url);
	
	curl_exec($ch);
	return $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
	curl_close($ch);
	ini_set('max_execution_time', $maxtime);
}

//根据产品productID, 查询大类名称
function get_cateName($productID){
	
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$midcate_pic_sql="SELECT * FROM `ls_products` WHERE ID = ".$productID."";
	$midcate_pic_query=$opendb->query($midcate_pic_sql);
	$midcate_pic_rows=mysqli_fetch_assoc($midcate_pic_query);
	
	if($midcate_pic_rows['cateName'] != "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] == ""){  //大类
		return $midcate_pic_rows['cateName'];
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] != "" && $midcate_pic_rows['subcateName'] == ""){  //中类
		
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `ID`=".$midcate_pic_rows['midcateID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		$subcate_pic_rows=mysqli_fetch_assoc($subcate_pic_query);
		
		return $subcate_pic_rows['cateName'];
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] != ""){  //小类
		
		$subcate_sql="SELECT * FROM `ls_products` WHERE `ID`=".$midcate_pic_rows['subcateID']."";
		$subcate_query=$opendb->query($subcate_sql);
		$subcate_rows=mysqli_fetch_assoc($subcate_query);
		
		$subcate_pic_sql="SELECT * FROM `ls_products` WHERE `ID`=".$subcate_rows['midcateID']."";
		$subcate_pic_query=$opendb->query($subcate_pic_sql);
		$subcate_pic_rows=mysqli_fetch_assoc($subcate_pic_query);
		
		return $subcate_pic_rows['cateName'];
	}

}

//根据产品productID, 返回数组：大类cate，中类midcate，小类subcate 及产品productID 串
//$backvar: cate midcate subcate,$str: or productID=... ,$backdir:../../
function getprocate($productID){
	$opendb=new mydb();
	require('char_set.php');
	require('constant.php');
	$midcate_pic_sql="SELECT * FROM `ls_products` WHERE ID = ".$productID."";
	 
	$midcate_pic_query=$opendb->query($midcate_pic_sql);
	$midcate_pic_rows=mysqli_fetch_assoc($midcate_pic_query);
	
	if($midcate_pic_rows['cateName'] != "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] == ""){  //大类
		$catestr=" cateName!='' ";
		$backvar=  "cate"   ; $backdir="";
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] != "" && $midcate_pic_rows['subcateName'] == ""){  //中类
		$catestr="  midcateName!='' and midcateID=".$midcate_pic_rows['midcateID'];
		$backvar=  "midcate" ; $backdir="../";
	}elseif($midcate_pic_rows['cateName'] == "" && $midcate_pic_rows['midcateName'] == "" && $midcate_pic_rows['subcateName'] != ""){  //小类
		$catestr=" subcateName!=''  and sudcateID=".$midcate_pic_rows['subcateID'];
		$backvar=  "subcate"  ; $backdir="../../";
	}
	$str="";
	$sql="SELECT * FROM `ls_products` WHERE id< (".$midcate_pic_rows['ID'].")   and enable=1 and ".$catestr." order by ID asc limit " . $relacatenum ;  
	 
	$query=$opendb->query($sql);
	while($rows=mysqli_fetch_assoc($query)){
		$str.=	" productID= ".$rows['ID']." or ";
	}
	$str1="";
	$sql="SELECT * FROM `ls_products` WHERE id> (".$midcate_pic_rows['ID'].")   and enable=1 and ".$catestr." order by ID desc limit " . $relacatenum ;
	//echo $sql."<br/>";
	$query=$opendb->query($sql);
	while($rows=mysqli_fetch_assoc($query)){
		$str1 =	" productID= ".$rows['ID']." or ".$str1 ;
	}
	if($str1!="")$str.=$str1;
	//echo $str."<br/>";
	
	if($str!="" && substr($str,-3)=="or ")   $str=substr($str,0,-3); //去掉最后 or 
	//echo $str;
	return	array($backvar,$str,$backdir);

}

//替换产品、文章、单页等数据库中文本内容 
//$func addlink 增加链接,dellink 删除链接,repdir 替换目录
//$var1参数1,$var2参数2:$stitle, $surl; $olddir,$currentdir 
function replalltext($func,$var1,$var2 ){
	$opendb=new mydb();
	$pro_sql = "select * from ls_products where enable = 1 order by Num ";
	$pro_query = $opendb->query($pro_sql);
	while($pro_value = mysqli_fetch_array($pro_query)){
		switch($func)
		{
			case "addlink":
			$productSpecification=internal_keyword_link($pro_value['productSpecification'],$var1,$var2);
			$advantages=internal_keyword_link($pro_value['advantages'],$var1,$var2);
			$characteristics=internal_keyword_link($pro_value['characteristics'],$var1,$var2);
			$parameters=internal_keyword_link($pro_value['parameters'],$var1,$var2);
			$cateBrief=internal_keyword_link($pro_value['cateBrief'],$var1,$var2);
			$cateDetail=internal_keyword_link($pro_value['cateDetail'],$var1,$var2);
			$midcateBrief=internal_keyword_link($pro_value['midcateBrief'],$var1,$var2);
			$midcateDetail=internal_keyword_link($pro_value['midcateDetail'],$var1,$var2);
			$subcateBrief=internal_keyword_link($pro_value['subcateBrief'],$var1,$var2);
			$subcateDetail=internal_keyword_link($pro_value['subcateDetail'],$var1,$var2);
			$canshu=internal_keyword_link($pro_value['canshu'],$var1,$var2);
			$basicInfo=internal_keyword_link($pro_value['basicInfo'],$var1,$var2);
			$additionalInfo=internal_keyword_link($pro_value['additionalInfo'],$var1,$var2);
			break;   
			
			case "dellink":

			$productSpecification=clear_keyword_link($pro_value['productSpecification'], $var1);

			$advantages=clear_keyword_link($pro_value['advantages'],$var1);
			$parameters=clear_keyword_link($pro_value['parameters'],$var1);
			$characteristics=clear_keyword_link($pro_value['characteristics'],$var1);
			$cateBrief=clear_keyword_link($pro_value['cateBrief'],$var1);
			$cateDetail=clear_keyword_link($pro_value['cateDetail'],$var1);
			$midcateBrief=clear_keyword_link($pro_value['midcateBrief'],$var1);
			$midcateDetail=clear_keyword_link($pro_value['midcateDetail'],$var1);
			$subcateBrief=clear_keyword_link($pro_value['subcateBrief'],$var1);
			$subcateDetail=clear_keyword_link($pro_value['subcateDetail'],$var1);
			$canshu=clear_keyword_link($pro_value['canshu'],$var1);
			$basicInfo=clear_keyword_link($pro_value['basicInfo'],$var1);
			$additionalInfo=clear_keyword_link($pro_value['additionalInfo'],$var1);
			break; 
			
			case "repdir":
			$productSpecification=str_replace($var1,$var2,$pro_value['productSpecification']);
			$advantages=str_replace($var1,$var2,$pro_value['advantages']);
			$characteristics=str_replace($var1,$var2,$pro_value['characteristics']);
			$parameters=str_replace($var1,$var2,$pro_value['parameters']);
			$cateBrief=str_replace($var1,$var2,$pro_value['cateBrief']);
			$cateDetail=str_replace($var1,$var2,$pro_value['cateDetail']);
			$midcateBrief=str_replace($var1,$var2,$pro_value['midcateBrief']);
			$midcateDetail=str_replace($var1,$var2,$pro_value['midcateDetail']);
			$subcateBrief=str_replace($var1,$var2,$pro_value['subcateBrief']);
			$subcateDetail=str_replace($var1,$var2,$pro_value['subcateDetail']);
			$canshu=str_replace($var1,$var2,$pro_value['canshu']);
			$basicInfo=str_replace($var1,$var2,$pro_value['basicInfo']);
			$additionalInfo=str_replace($var1,$var2,$pro_value['additionalInfo']);
			break; 
		}
		
		$replacedir_sql=sprintf("update ls_products set productSpecification=%s, characteristics=%s, advantages=%s, parameters=%s, cateBrief=%s, cateDetail=%s, midcateBrief=%s, midcateDetail=%s, subcateBrief=%s, subcateDetail=%s, canshu=%s, basicInfo=%s, additionalInfo=%s where id=%s",   
				GetSQLValueString($productSpecification,"text"),
				GetSQLValueString($characteristics,"text"),
				GetSQLValueString($advantages,"text"),
				GetSQLValueString($parameters,"text"),
				GetSQLValueString($cateBrief,"text"),
				GetSQLValueString($cateDetail,"text"),
				GetSQLValueString($midcateBrief,"text"),
				GetSQLValueString($midcateDetail,"text"),
				GetSQLValueString($subcateBrief,"text"),
				GetSQLValueString($subcateDetail,"text"),
				GetSQLValueString($canshu,"text"),
				GetSQLValueString($basicInfo,"text"),
				GetSQLValueString($additionalInfo,"text"),
				GetSQLValueString($pro_value['ID'],"int")
			);

		$replacedir_query=$opendb->query($replacedir_sql);
	}

	$singlepages_sql = "select * from ls_singlepages where enable = 1 order by Num ";
	$singlepages_query = $opendb->query($singlepages_sql);
	while($value = mysqli_fetch_array($singlepages_query)){
		switch($func)
		{
			case "addlink":
			$pageText=internal_keyword_link($value['pageText'],$var1,$var2);
			break;
			
			case "dellink":
			$pageText=clear_keyword_link($value['pageText'], $var1);
			break;
			
			case "repdir":
			$pageText=str_replace($var1,$var2,$value['pageText']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_singlepages set pageText=%s where id=%s",
				GetSQLValueString($pageText,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //singlepage目录整理
	}
	
	$news_sql = "select * from ls_news where enable = 1 order by Num ";
	$news_query = $opendb->query($news_sql);
	while($value = mysqli_fetch_array($news_query)){
		switch($func)
		{
			case "addlink":
			$newsText=internal_keyword_link($value['newsText'],$var1,$var2);
			break;
			
			case "dellink":
			$newsText=clear_keyword_link($value['newsText'], $var1);
			break;
			
			case "repdir":
			$newsText=str_replace($var1,$var2,$value['newsText']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_news set newsText=%s where id=%s",
				GetSQLValueString($newsText,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //news目录整理
	}
	
	$about_sql="select * from ls_information where inMenu='aboutus' order by ID";
	$about_query=$opendb->query($about_sql);
	$value=mysqli_fetch_array($about_query);
		switch($func)
		{
			case "addlink":
			$content=internal_keyword_link($value['content'],$var1,$var2);
			$homeAbout=internal_keyword_link($value['homeAbout'],$var1,$var2);
			break;
			
			case "dellink":
			$content=clear_keyword_link($value['content'], $var1);
			$homeAbout=clear_keyword_link($value['homeAbout'], $var1);
			break;
			
			case "repdir":
			$content=str_replace($var1,$var2,$value['content']);
			$homeAbout=str_replace($var1,$var2,$value['homeAbout']);
			break;
		}
	
	$replacedir_sql=sprintf("update ls_information  set content=%s,homeAbout=%s where inMenu='aboutus' or  inMenu='notice' ",
			GetSQLValueString($content,"text"),
			GetSQLValueString($homeAbout,"text")
		);
	$replacedir_query=$opendb->query($replacedir_sql);  //aboutus目录整理
	
	$notice_sql="select * from ls_information where inMenu='notice' order by ID";
	$notice_query=$opendb->query($notice_sql);
	$value=mysqli_fetch_array($notice_query);
		switch($func)
		{
			case "addlink":
			$content=internal_keyword_link($value['content'],$var1,$var2);
			break;
			
			case "dellink":
			$content=clear_keyword_link($value['content'], $var1);
			break;
			
			case "repdir":
			$content=str_replace($var1,$var2,$value['content']);
			break;
		}
	
	$replacedir_sql=sprintf("update ls_information  set content=%s where inMenu='notice' ",
			GetSQLValueString($content,"text")
		);
	$replacedir_query=$opendb->query($replacedir_sql);  //notice目录整理
	
	$menu_sql = "select * from ls_menu where enable = 1 order by menuNum ";
	$menu_query = $opendb->query($menu_sql);
	while($value = mysqli_fetch_array($menu_query)){
		switch($func)
		{
			case "addlink":
			$description=internal_keyword_link($value['description'],$var1,$var2);
			break;
			
			case "dellink":
			$description=clear_keyword_link($value['description'], $var1);
			break;
			
			case "repdir":
			$description=str_replace($var1,$var2,$value['description']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_menu set description=%s where id=%s",
				GetSQLValueString($description,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //menu目录整理
	}
	
	$workshop_sql = "select * from ls_workshop where enable = 1 order by Num ";
	$workshop_query = $opendb->query($workshop_sql);
	while($value = mysqli_fetch_array($workshop_query)){
		switch($func)
		{
			case "addlink":
			$workshopText=internal_keyword_link($value['workshopText'],$var1,$var2);
			break;
			
			case "dellink":
			$workshopText=clear_keyword_link($value['workshopText'], $var1);
			break;
			
			case "repdir":
			$workshopText=str_replace($var1,$var2,$value['workshopText']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_workshop set workshopText=%s where id=%s",
				GetSQLValueString($workshopText,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //workshop目录整理
	}
	
	$certificate_sql = "select * from ls_certificate where enable = 1 order by Num ";
	$certificate_query = $opendb->query($certificate_sql);
	while($value = mysqli_fetch_array($certificate_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_certificate set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //certificate目录整理
	}
	
	$qualitycontrol_sql = "select * from ls_qualitycontrol where enable = 1 order by Num ";
	$qualitycontrol_query = $opendb->query($qualitycontrol_sql);
	while($value = mysqli_fetch_array($qualitycontrol_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_qualitycontrol set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //qualitycontrol目录整理
	}
	
	$packing_sql = "select * from ls_packing where enable = 1 order by Num ";
	$packing_query = $opendb->query($packing_sql);
	while($value = mysqli_fetch_array($packing_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_packing set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //packing目录整理
	}
	
	$rd_sql = "select * from ls_rd where enable = 1 order by Num ";
	$rd_query = $opendb->query($rd_sql);
	while($value = mysqli_fetch_array($rd_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_rd set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //rd目录整理
	}
	
	$brand_sql = "select * from ls_brand where enable = 1 order by Num ";
	$brand_query = $opendb->query($brand_sql);
	while($value = mysqli_fetch_array($brand_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_brand set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //brand目录整理
	}
	
	$management_sql = "select * from ls_management where enable = 1 order by Num ";
	$management_query = $opendb->query($management_sql);
	while($value = mysqli_fetch_array($management_query)){
		switch($func)
		{
			case "addlink":
			$Text=internal_keyword_link($value['Text'],$var1,$var2);
			break;
			
			case "dellink":
			$Text=clear_keyword_link($value['Text'], $var1);
			break;
			
			case "repdir":
			$Text=str_replace($var1,$var2,$value['Text']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_management set Text=%s where id=%s",
				GetSQLValueString($Text,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //management目录整理
	}
	
	$functioncates_sql = "select * from ls_functioncates where enable = 1 order by Num ";
	$functioncates_query = $opendb->query($functioncates_sql);
	while($value = mysqli_fetch_array($functioncates_query)){
		switch($func)
		{
			case "addlink":
			$brief=internal_keyword_link($value['brief'],$var1,$var2);
			$detail=internal_keyword_link($value['detail'],$var1,$var2);
			break;
			
			case "dellink":
			$brief=clear_keyword_link($value['brief'], $var1);
			$detail=clear_keyword_link($value['detail'], $var1);
			break;
			
			case "repdir":
			$brief=str_replace($var1,$var2,$value['brief']);
			$detail=str_replace($var1,$var2,$value['detail']);
			break;
		}
		
		$replacedir_sql=sprintf("update ls_functioncates set brief=%s,detail=%s where id=%s",
				GetSQLValueString($brief,"text"),
				GetSQLValueString($detail,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //functioncates目录整理
	}
	
	$article_sql = "select * from ls_article where enable = 1 order by Num ";
	$article_query = $opendb->query($article_sql);
	while($value = mysqli_fetch_array($article_query)){
		switch($func)
		{
			case "addlink":
			$articleText=internal_keyword_link($value['articleText'],$var1,$var2);
			$articleBrief=internal_keyword_link($value['articleBrief'],$var1,$var2);
			break; 
			
			case "dellink":
			$articleText=clear_keyword_link($value['articleText'], $var1);
			$articleBrief=clear_keyword_link($value['articleBrief'], $var1);
			break;
			
			case "repdir":
			$articleText=str_replace($var1,$var2,$value['articleText']);
			$articleBrief=str_replace($var1,$var2,$value['articleBrief']);
			break;
		}
		
		$replacedir_sql=sprintf("update  ls_article  set articleText=%s,articleBrief=%s where id=%s",
				GetSQLValueString($articleText,"text"),
				GetSQLValueString($articleBrief,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //article目录整理
	}
			
	$video_sql = "select * from ls_video where enable = 1 order by Num ";
	$video_query = $opendb->query($video_sql);
	while($value = mysqli_fetch_array($video_query)){
		switch($func)
		{
			case "addlink":
			$videoText=internal_keyword_link($value['videoText'],$var1,$var2);
			break;  
			
			case "dellink":
			$videoText=clear_keyword_link($value['videoText'], $var1);
			break;
			
			case "repdir":
			$videoText=str_replace($var1,$var2,$value['videoText']);
			break;
		}
		
		$replacedir_sql=sprintf("update  ls_video  set videoText=%s  where id=%s",
				GetSQLValueString($videoText,"text"),
				GetSQLValueString($value['ID'],"int")
			);
		$replacedir_query=$opendb->query($replacedir_sql);  //video目录整理
	}
}

/*
根据主题图文件名获得图片栏目位置, $motifPic 文件名， 返回栏目位置名称
*/
function getmotifnav($motifPic){
	$motifnav=substr($motifPic,0,strpos($motifPic,".")); //去扩展名
	$motifnav=str_replace("banner","主题图",$motifnav); 
	$motifnav=strpos($motifnav,"_")===false?"首页 ".$motifnav:str_replace("_"," ",$motifnav);
	return $motifnav;
}	
?>