www.gusucode.com > 搜一次CMS电影程序 PHP 1.5源码程序 > include/function.php

    <?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 5.X
' 官方网站: http://www.syccms.com
' 官方论坛:http://bbs.syccms.com
' 版权所有: 搜一次开发团队    无痕(QQ:512591)
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息;
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
session_start();
date_default_timezone_set('PRC');//设置为默认时区为中国
function ss_timing_start ($name = 'default') {
      global $ss_timing_start_times;
      $ss_timing_start_times[$name] = explode(' ', microtime());
}
function ss_timing_stop ($name = 'default') {
      global $ss_timing_stop_times;
      $ss_timing_stop_times[$name] = explode(' ', microtime());
}
function ss_timing_current ($name = 'default') {
      global $ss_timing_start_times, $ss_timing_stop_times;
      if (!isset($ss_timing_start_times[$name])) {
          return 0;
      }
      if (!isset($ss_timing_stop_times[$name])) {
          $stop_time = explode(' ', microtime());
      }
      else {
          $stop_time = $ss_timing_stop_times[$name];
      }
      $current = $stop_time[1] - $ss_timing_start_times[$name][1];
      $current += $stop_time[0] - $ss_timing_start_times[$name][0];
      return $current;
}
ss_timing_start();


function IsNum($str){
	if( is_numeric($str) ){
		return true;}
	else{
		return false;}	
}

function IsNul($str){
	if (!is_string($str)) return false; //是否是字符串类型 
	if (empty($str)) return false; //是否已设定 
	if ($str=='') return false; //是否为空 
	return true; 
}

function str_encode($str){
	$str=ReplaceStr($str,"<","&lt;");
	$str=ReplaceStr($str,">","&gt;");
	$str=ReplaceStr($str,"'","&apos;");
	$str=ReplaceStr($str," ","&nbsp;");
	$str=ReplaceStr($str,"\r\n","<br>");
	$str=ReplaceStr($str,"\"","&quot;");
	$str=ReplaceStr($str,"&","&amp;");
	return $str;
	}
function str_decode($str){
	$str=ReplaceStr($str,"&lt;","<");
	$str=ReplaceStr($str,"&gt;",">");
	$str=ReplaceStr($str,"&apos;","'");
	$str=ReplaceStr($str,"&nbsp;"," ");
	$str=ReplaceStr($str,"<br>","\r\n");
	$str=ReplaceStr($str,"&quot;","\"");
	$str=ReplaceStr($str,"&amp;","&");
	return $str;	
	}	

function SafeRequest($key,$mode,$isfilter=''){
	set_magic_quotes_runtime(0);
	$magic= get_magic_quotes_gpc();	
	switch ($mode){
		case 'post':
			$value=isset($_POST[$key]) ? $magic?trim($_POST[$key]):addslashes(trim($_POST[$key])) : '';
			break;
		case 'get':
			$value=isset($_GET[$key]) ? $magic?trim($_GET[$key]):addslashes(trim($_GET[$key])) : '';
			break;
		default:
			$value=isset($_POST[$key]) ? $magic?trim($_POST[$key]):addslashes(trim($_POST[$key])) : '';
			if($value==""){
				$value=isset($_GET[$key]) ? $magic?trim($_GET[$key]):addslashes(trim($_GET[$key])) : '';
				}
			break;
		}
	if($isfilter!=''){
		$value=str_encode($value);
		}
		
	return $value;	
}

function RequestBox($key){
		$array =isset($_POST[$key]) ? $_POST[$key] : '';
		if($array==""){
			$value="0";
			}
		else{
			for($i=0;$i<count($array);$i++){
				$value=implode(',',$array);   
			} 
		}	
		return $value;
	}

function ReplaceStr($text,$search,$replace){
	if(empty($text)) $text="";
	$result_text=str_replace($search,$replace,$text);
	return $result_text;
}

function spandir($dir){
	$spandirpos=strrpos($dir,'/');
	$spandir=substr($dir,0,$spandirpos+1);
	if(!file_exists("../../".$spandir)){
		mkdir("../../".$spandir,0777,true);
		}
	}

function cnsubstr($str,$strlen=10) { 

if(empty($str)||!is_numeric($strlen)){
	$strlen=10; 
} 
$strlen=intval($strlen*2);
if(strlen($str)<=$strlen){ 
return $str; 
} 

$last_word_needed=substr($str,$strlen-1,1); 
if(!ord($last_word_needed)>128){ 
$needed_sub_sentence=substr($str,0,$strlen); 
return $needed_sub_sentence; 
}else{ 
for($i=0;$i<$strlen;$i++){ 
if(ord($str[$i])>128){ 
$i++; 
} 
}//end of for 
$needed_sub_sentence=substr($str,0,$i); 
return $needed_sub_sentence; 
} 
} 

function DateDiff($d1,$d2=""){   //日期比较函数$d2-$d1
 	if(is_string($d1))$d1=strtotime($d1);
 	if(is_string($d2))$d2=strtotime($d2);
 	return ($d2-$d1);
 }

function getpagerow($mysql,$pagesize){
	global $db;
	$url=$_SERVER["QUERY_STRING"];
	if(stristr($url,'&pages')){
		$url=preg_replace('/&pages=([\S]+?)$/','',$url);
	}
	if(stristr($url,'pages')){
		$url=preg_replace('/pages=([\S]+?)$/','',$url);
	}
	if(IsNul($url)){$url.="&";}

	$pages=SafeRequest("pages","get");
	$pagesok=$pagesize;//每页显示记录数
    if (!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0){
    $pages=1;
	}
  	$sqlstr=$mysql;
  	$res=$db -> query($sqlstr);
 	$nums= $db -> num_rows($res);
	if($nums==0){$nums=1;}
 	$str="总<font color=red>".$nums."</font>条记录&nbsp;";
    $pagejs=ceil($nums/$pagesok);//总页数
  
    if($pages>$pagejs){
     $pages=$pagejs;
    }
  
    $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;
	$str.="当前<font color=red>".$pages."/</font>".$pagejs."页&nbsp;";                                                              ;
	$result = $db -> query($sql);
	$str.= "<a href=?".$url."pages=1>第一页</a>";
	if($pagejs<=10){
  		for($i=1;$i<=$pagejs;$i++){
   			$str.="<a href='?".$url."pages=".$i."'>".$i."</a>&nbsp;";
 	 	}
	}
	else{
 		if($pages>=12){
 			for($i=$pages-5;$i<=$pages+6;$i++){
   				if($i<=$pagejs){
   					$str.="<a href='?".$url."pages=".$i."'>".$i."</a>&nbsp;";
    			}
  			}
  			if($i<=$pagejs){ 
    			$str.="....";
	    		$str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>&nbsp;";
   			}
   		}
  		else{
  			for($i=1;$i<=12;$i++){
    			$str.="<a href='?".$url."pages=".$i." '>".$i."</a>&nbsp;";
 		} 
 				if($i<=$pagejs){ 
      				$str.="....";
	  				$str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>&nbsp;";
    			}
 		 }
	}

	$str.="<a href=?".$url."pages=".($pages+1).">下一页</a>&nbsp;";
	$str.="<a href=?".$url."pages=".$pagejs.">最后页</a>&nbsp;";
	$str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick=window.location='?".$url."pages='+gopage.value+''>GO>></a>&nbsp;";
	 while ($row = $db -> fetch_array($result) ){}
	 $arr=array($str,$result,$sql,$pagejs);
	 return $arr;
}

  
class iFile {       
        
    private $Fp;       
    private $Pipe; //(fopen,popen)(f,p)       
    private $File;       
    private $OpenMode; //(r,r+,w,w+,a,a+,b)       
    private $Data;       
        
    function iFile($File,$Mode = 'r',$Data4Write='',$Pipe = 'f'){       
        $this -> File = $File;       
        $this -> Pipe = $Pipe;       
        if($Mode == 'dr'){       
            $this -> OpenMode = 'r';       
            $this -> OpenFile();       
            $this -> getFileData();       
        }else{       
            $this -> OpenMode = $Mode;       
            $this -> OpenFile();       
        }       
        if($this->OpenMode=='w'&$Data4Write!=''){       
            $this -> WriteFile($Data4Write,$Mode = 3);       
        }       
    }       
        
    function OpenFile(){       
        if ($this -> OpenMode == 'r'||$this -> OpenMode == 'r+'){       
            if($this->CheckFile()){       
                if ($this -> Pipe == 'f') {       
                    $this->Fp = fopen($this -> File, $this -> OpenMode);       
                } elseif ($Pipe == 'p') {       
                    $this->Fp = popen($this -> File, $this -> OpenMode);       
                }else{       
                    Die("请检查文件打开参数3,f:fopen()");       
                }       
            } else {       
                Die("文件访问错误,请检查文件是否存在!");       
            }       
        } else {       
            if ($this -> Pipe == 'f') {       
                $this->Fp = fopen($this -> File, $this -> OpenMode);       
            } elseif ($Pipe == 'p') {       
                $this->Fp = popen($this -> File, $this -> OpenMode);       
            } else {       
                Die("请检查文件打开参数3,f:fopen()");       
            }       
        }       
    }       
        
        
    function CloseFile(){       
        if ($this->Pipe == 'f'){       
            @fclose($this->Fp);       
        } else {       
            @pclose($this->Fp);       
        }       
    }       
        
    function getFileData(){       
        @flock($this->Fp, 1);       
        $Content = fread($this->Fp, filesize($this->File));       
        $this->Data = $Content;       
    }       
        
        
    function CheckFile(){       
        if (file_exists($this -> File)) { return true; } else { return false; }       
    }       
        
    function WriteFile($Data4Write,$Mode = 3){       
        @flock($this->Fp,$Mode);       
        fwrite($this->Fp,$Data4Write);       
        $this->CloseFile();       
        return true;       
    }   
}

function playadd($type= ''){//type:1后台根目录 2 后台子目录 3前台 4后台2级子目录
$xmlpath=_SYC_ROOT_.'include/play.xml';
$doc = new DOMDocument();
$doc->load($xmlpath);   
$player = $doc->getElementsByTagName( "play" );
$str="";
foreach( $player as $player )   
{   
$marks = $player->getElementsByTagName( "mark" ); 
if(function_exists("mb_convert_encoding")){
	$mark =  mb_convert_encoding($marks->item(0)->nodeValue,"GBK","UTF-8");  
	}
else{
	$mark = iconv( "UTF-8",  "GBK//IGNORE" , $marks->item(0)->nodeValue);
	}	   
$dess = $player->getElementsByTagName( "des" );   
if(function_exists("mb_convert_encoding")){
	$des = mb_convert_encoding($dess->item(0)->nodeValue,"GBK","UTF-8");     
	}
else{
	$des = iconv( "UTF-8",  "GBK//IGNORE" , $dess->item(0)->nodeValue);
	}	 
  
$playfroms = $player->getElementsByTagName( "playfrom" );   
$playfrom = $playfroms->item(0)->nodeValue;   
 $str.="$mark--$des--$playfrom|";
}   
$playarr=explode("|",$str);
return $playarr;
}



function playaddshow($playadd,$playfrom){
		$playarr=explode('$$',$playfrom);
		for($j=0;$j<count($playarr);$j++){
			for($i=0;$i<count($playadd)-1;$i++){
				$playfromarr=explode("--",$playadd[$i]);
				if($playfromarr[2]==$playarr[$j]){
					return  $playfromarr[0]."&nbsp;";
					}
			}

			}
	}
	
function playselect($playadd,$play){
			$str="";
			for($i=0;$i<count($playadd)-1;$i++){
				$playfromarr=explode("--",$playadd[$i]);
				if($play==$playfromarr[2]){
					$str.="<option value='".$playfromarr[2]."' selected='selected'>".$playfromarr[0]."--".$playfromarr[1]."</option>";
				}
				else{
					$str.="<option value='".$playfromarr[2]."'>".$playfromarr[0]."--".$playfromarr[1]."</option>";
					}
		}
		return $str;
	}
	
function playselect2($playadd,$play){
			$str="";
			for($i=0;$i<count($playadd)-1;$i++){
				$playfromarr=explode("--",$playadd[$i]);
				if($play==$playfromarr[2]){
					$str.="<option value='?action=orderbyplay&source=".$playfromarr[2]."' selected='selected'>".$playfromarr[0]."</option>";
				}
				else{
					$str.="<option value='?action=orderbyplay&source=".$playfromarr[2]."'>".$playfromarr[0]."</option>";
					}
		}
		return $str;
	}	
	
function LinkUrl($Table,$ClassID,$SystemID,$ID){
	$Table=strtolower($Table);
	switch(S_Webmode){
		case '1':
			if($Table=='s_video'){				
				if(S_Dvmode==1){$linkurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlContent.$ID;}
				else{$linkurl=S_SitePath.S_Dvname."/?".S_UrlContent.$ID.".".S_Dvsuffix;}	
				}
			elseif($Table=='s_article'){
				if(S_Dnmode==1){$linkurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlContent.$ID;}
				else{$linkurl=S_SitePath.S_Dnname."/?".S_UrlContent.$ID.".".S_Dnsuffix;}
			}
			elseif($Table=='s_topic'){
					if(S_Dtmode==1){$linkurl=S_SitePath.S_Dtname."/index.php?ID=".S_UrlContent.$ID;}
					else{$linkurl=S_SitePath.S_Dtname."/?".S_UrlContent.$ID.".".S_Dtsuffix;}						
				}
			elseif($Table=='s_class'){
				if($SystemID==1){
					if(S_Dvmode==1){$linkurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlList.$ID;}
					else{$linkurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;}	
					}
				elseif($SystemID==2){
					if(S_Dnmode==1){$linkurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlList.$ID;}
					else{$linkurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;}	
					}						
				}	
			break;		
		case '0':
			if($Table=='s_class'){
				if($SystemID==1){
					$folder=S_Svlistfolder;
					$suffix=S_Svcontentsuffix;
					}
				elseif($SystemID==2){					
						$folder = S_Sncontentfolder;
						$suffix = S_Sncontentsuffix;
					}	
				}
			elseif($Table=='s_video'){
					$folder = S_Svcontentfolder;
					$suffix= S_Svcontentsuffix;
					$SystemID=1;				
				}
			elseif($Table=='s_article'){
					$folder = S_Sncontentfolder;
					$suffix = S_Sncontentsuffix;
					$SystemID=2;				
				}
			elseif($Table=='s_topic'){
					$folder = S_Stlistfolder;
					$suffix= S_Stcontentsuffix ;					
				}
			$linkurl=LinkContent($SystemID,$folder,$ClassID,$suffix,$ID,$Table);
		}
		return $linkurl;
	}	

function LinkContent($SystemID,$folder,$ClassID,$suffix,$ID,$Table){
	$Table=strtolower($Table);
	if(S_Createid==2){$ID=md5($ID);}
	switch(S_Getcreate){
		case '1':
			$linkcontent=S_SitePath.$folder."/".$ID.".".$suffix;	
			break;
		case '2':
		  if($Table=="s_topic"){
			  $AliasName=GetAlias("s_topic",$ClassID);
			  }
		 elseif($Table=='s_video'){
			  $AliasName=GetAlias("s_class",$ClassID);
			 }
		 elseif($Table=='s_article'){
			  $AliasName=GetAlias("s_class",$ClassID);
			 }	 
		 elseif($Table=='s_class'){
			 if($SystemID==1){$AliasName=GetAlias("s_class",$ClassID);}
			 if($SystemID==2){$AliasName=GetAlias("s_class",$ClassID);} 
			 }
		  $linkcontent=S_SitePath.$folder."/".$AliasName.$ID.".".$suffix;			
			break;
		case '3':
			if($Table=='s_topic'){
				$AliasName=GetAlias("s_topic",$ClassID);
				}
			elseif($Table=='s_video'){
				$AliasName=GetAlias("s_class",$ClassID);
				}	
			elseif($Table=='s_article'){
				 $AliasName=GetAlias("s_class",$ClassID);
				}
			elseif($Table=='s_class'){
				if($SystemID==1){$AliasName=GetAlias("s_class",$ClassID);}
				if($SystemID==2){$AliasName=GetAlias("s_class",$ClassID);}
				}
		   $linkcontent=S_SitePath.$folder."/".$AliasName."/".$ID.".".$suffix;
			
		}	
		return $linkcontent;
	}

function LinkClassUrl($Table,$ID,$SystemID,$Page,$Lists=''){
	$Table=strtolower($Table);
	$PageMD=$Page;
	switch(S_Webmode){
		case '0':
			if($Lists=='1'){
				if(!IsNum($Page)){$Page=1;}
				if($Table=="s_class"){
					if($SystemID==1){
						if(S_Dvmode==1){$linkclassurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlList.$ID;}
						else{$linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;}	
					}
					elseif($SystemID==2){
						if(S_Dnmode==1){$linkclassurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlList.$ID;}
						else{$linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;}					
						}	
					}
				elseif($Table=="s_video"){
						if(S_Dvmode==1){
							$linkclassurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlList.$ID."&Page=".$Page;
							}
						else{
							$linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID."_".$Page.".".S_Dvsuffix;
							}	
					}	
				elseif($Table=="s_article"){
						if(S_Dnname==1){
							$linkclassurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlList.$ID."&Page=".$Page;
							}
						else{
							$linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID."_".$Page.".".S_Dnsuffix;
							}	
					}
				elseif($Table=="s_topic"){
					if(S_Dtmode==1){
						 $linkclassurl=S_SitePath.S_Dtname."/index.php?ID=".S_UrlList.$ID;
						}
					else{
						$linkclassurl=S_SitePath.S_Dtname."/?".S_UrlList.$ID.".".S_Dtsuffix;
						}	
					}				
			}else{
				if($Table=="s_class" or $Table=="s_video" or $Table=="s_article"){
					if($SystemID==1){
						$folder=S_Svlistfolder;
						$suffix= S_Svcontentsuffix;
						}
					elseif($SystemID==2){
						$folder=S_Snlistfolder;
						$suffix= S_Stcontentsuffix;						
						}	
				}
				elseif($Table=="s_topic"){
					$folder=S_Stlistfolder;
					$suffix= S_Sncontentsuffix;					
				}
				$linkclassurl=LinkClassContent($SystemID,$folder,$ID,$PageMD,$suffix,$Table);		
			}

			break;
		case '1':
			if(!IsNum($Page)){$Page=1;}
			if($Table=="s_class"){
				if($SystemID==1){
					if(S_Dvmode==1){$linkclassurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlList.$ID;}
					else{$linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;}	
				}
				elseif($SystemID==2){
					if(S_Dnmode==1){$linkclassurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlList.$ID;}
					else{$linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;}					
					}	
				}
			elseif($Table=="s_video"){
					if(S_Dvmode==1){
						$linkclassurl=S_SitePath.S_Dvname."/index.php?ID=".S_UrlList.$ID."&Page=".$Page;
						}
					else{
						$linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID."_".$Page.".".S_Dvsuffix;
						}	
				}	
			elseif($Table=="s_article"){
					if(S_Dnname==1){
						$linkclassurl=S_SitePath.S_Dnname."/index.php?ID=".S_UrlList.$ID."&Page=".$Page;
						}
					else{
						$linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID."_".$Page.".".S_Dnsuffix;
						}	
				}
			elseif($Table=="s_topic"){
				if(S_Dtmode==1){
					 $linkclassurl=S_SitePath.S_Dtname."/index.php?ID=".S_UrlList.$ID;
					}
				else{
					$linkclassurl=S_SitePath.S_Dtname."/?".S_UrlList.$ID.".".S_Dtsuffix;
					}	
				}
		}
		return $linkclassurl;
	}


function LinkClassContent($SystemID,$folder,$ID,$Page,$suffix,$Table){
	$AliasName="";
	switch(S_Getcreate){
		case '1':
			if($ID=='0'){
				$linkclasscontent=S_SitePath.$folder."/".$Page.".".$suffix;
				}
			else{
				$linkclasscontent=S_SitePath.$folder."/".$ID."_".$Page.".".$suffix;
				}	
			
			break;
		case '2':
			if($Table=="s_topic"){
				$AliasName=GetAlias("s_topic",$ID);
				}
			elseif($Table=="s_video" or $SystemID==1){
				$AliasName=GetAlias("s_class",$ID);
				}
			elseif($Table=="s_article" or $SystemID==2){
				$AliasName=GetAlias("s_class",$ID);
				}	
			$linkclasscontent=S_SitePath.$folder."/".$AliasName."_".$Page.".".$suffix;
			break;
		case '3':	
			if($Table=='s_topic'){
				$AliasName=GetAlias("s_topic",$ID);
				}
			elseif($Table=='s_video'  or $SystemID==1){
				$AliasName=GetAlias("s_class",$ID);
				}
			elseif($Table=="s_article" or $SystemID==2){
				$AliasName=GetAlias("s_class",$ID);
				}
			if($Table=='s_topic' and $ID==0){
				$linkclasscontent=S_SitePath.$folder."/".$Page.".".$suffix;
				}
			else{	
				$linkclasscontent=S_SitePath.$folder."/".$AliasName."/".$ID."_".$Page.".".$suffix;
				}
			break;
		}
		return $linkclasscontent;

	}


function GetAlias($Table,$ClassID){
	global $db;
	$sql="select S_AliasName from ".$Table." where S_ID=".$ClassID."";
	$row=$db->getrow($sql);
	if($row){
		$aliasname=$row['S_AliasName'];
		}
	else{
		if($Table=='s_topic'){
			$aliasname="topic";
		}else{
			$aliasname="unknow";
			}
		}	
	return $aliasname;
	}
	
function SpanShow($Table,$ClassID,$SystemID,$ID,$Url){
	if(S_Webmode==0){		
	$SpanShow="<img src='images/span.gif' style='cursor:hand' id='span".$ID."' onclick='spango(".$ID.",\"".$Url."&cid=".$ClassID."\")'>";
	$spanurl=substr(LinkUrl($Table,$ClassID,$SystemID,$ID,$Url),strlen(S_SitePath));
	//判断是否已生成
	if(file_exists("../".$spanurl)){
		$SpanShow="";
		}
	return $SpanShow;
	}
}

function  remote_file_exists($url_file){
	//检测输入
$url_file = trim($url_file);
if (empty($url_file)) { return false; }
$url_arr = parse_url($url_file);
if (!is_array($url_arr) || empty($url_arr)){ return false; }

//获取请求数据
$host = $url_arr['host'];
$path = $url_arr['path'];
$port = isset($url_arr['port']) ? $url_arr['port'] : "80";

//连接服务器
$fp = fsockopen($host, $port, $err_no, $err_str, 30);
if (!$fp){ return false; }

//构造请求协议
$request_str = "GET ".$path." HTTP/1.1\r\n";
$request_str .= "Host: ".$host."\r\n";
$request_str .= "Connection: Close\r\n\r\n";

//发送请求
fwrite($fp, $request_str);
$first_header = fgets($fp, 1024);
fclose($fp);

//判断文件是否存在
if (trim($first_header) == ""){ return false; }
if (!preg_match("/200/", $first_header)){
return false;
}
return true;
}

function convert_encoding($str,$nfate,$ofate){
	if(function_exists("mb_convert_encoding")){
		$str=mb_convert_encoding($str,$nfate,$ofate);
		}
	else{
		if($nfate=="GBK") $nfate="GBK//IGNORE";
		$str=iconv($ofate, $nfate , $str);
		}
	return $str;	
	}

function HotSearch($Search_Key){
	$Search_List="";
	$Search_Key1="";
	$Search_Key=trim($Search_Key);
	$Str=" @,@|@_";
	$StrArr=explode('@',$Str);
	for($i=0;$i<=3;$i++){
		if(stristr($Search_Key,$StrArr[$i])){
			$Search_Key1=explode($StrArr[$i],$Search_Key);
			break;
			}
		}
	if(is_array($Search_Key1)){
			for($j=0;$j<count($Search_Key1);$j++){
				$Search_List= $Search_List."<A HREF=\"".S_SitePath."search.php?keyword=".urlencode(convert_encoding($Search_Key1[$j],'UTF-8','GBK'))."\">".$Search_Key1[$j]."</A> ";
				}
	}
	else{
		$Search_List=$Search_Key;
		}	
		return $Search_List;	
	}

function getChild($ClassID){
	if($ClassID!=""){
	global $db;
	$ClassArr=explode(',',$ClassID);
	for($i=0;$i<count($ClassArr);$i++){
		$sql="select S_ID from s_class where S_FatherID=$ClassArr[$i]";
		$result=$db->query($sql);
		if($result){
			while($row=$db->fetch_array($result)){
				$ClassArr[]=$row['S_ID'];
				}
			}
		}
	$ClassID=implode(',',$ClassArr);
	}
	return $ClassID;
}



function geturl($url){
	if(function_exists('curl_init')){
	  $ch = curl_init();
	  $timeout = 30; // set to zero for no timeout
	  curl_setopt ($ch, CURLOPT_URL, $url);
	  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
	  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	  $handles = curl_exec($ch);
	  curl_close($ch);
	  return $handles;
		}
	}

function timing(){
include_once(_SYC_PATH_."/timing_set.php");
date_default_timezone_set('PRC');
$zy_arr=explode(',',t_zy);
$xq_arr=explode(',',t_xq);
$sj_arr=explode(',',t_sj);
$xq=date('w');//当前是星期几0-6
$sj=date('H');//当前时间
$strjs='';
$arr=array("","pipi","ku6-1","ku6-2","qvod","dm456","dvd","qvodzy","vgame","tom59","vtvb","openv","gvodzy","gvodzi","kkwwe","fkvod","ppvod","youku","");
if(t_of==0 &&  $zy_arr[0]!='0'&& t_time!=$xq."--".$sj && in_array($xq,$xq_arr)==true && in_array($sj,$sj_arr)==true){
	for($i=0;$i<count($zy_arr);$i++){
		if($zy_arr[$i]=='18'){
			$strjs.="<script src=\"".S_SitePath."include/timingcollect.php?action=today&Mark=".$zy_arr[$i]."_&ServerUrl=http://www.web9zy.com/aip.asp&Syc=php\"></script>";
			}
		else{
			$strjs.="<script src=\"".S_SitePath."include/timingcollect.php?action=today&Mark=".$zy_arr[$i]."_&ServerUrl=http://video.syccms.cn/".$arr[$zy_arr[$i]]."/api.asp&Syc=php\"></script>";
			}	
	}
		
	$strs="<?php"."\n";
	$strs.="define(\"t_of\",".t_of.");\n";
	$strs.="define(\"t_zy\",\"".t_zy."\");\n";
	$strs.="define(\"t_xq\",\"".t_xq."\");\n";
	$strs.="define(\"t_sj\",\"".t_sj."\");\n";
	$strs.="define(\"t_time\",\"".$xq."--".$sj."\");\n";
	$strs.="?>";
	$fp2=@fopen(_SYC_PATH_."/timing_set.php", "wb+"); 
	@fwrite($fp2,$strs); 
	@fclose($fp2);
	}
return $strjs;	
}
?>