<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/

include_once("../include/label.php");
include_once("../include/config.php");
include_once("../include/userset.php");
$Param=$_SERVER['QUERY_STRING'];

if($Param=="") {
	if(S_Webmode==1 && file_exists(_SYC_ROOT_.S_Templateurl."vodindex.html")){
		$cache_id ="vodindex_";
		if(!($cache_opt->start($cache_id))){
			 echo GetTemp("vodindex.html",0);
			$cache_opt->end();
		}		
	}else{
		header("Location:index.html");	
		}
	die();	
	}
	
//判断是否需要自动转向静态
if((stristr($Param,S_UrlList) or stristr($Param,S_UrlContent)) && S_Webmode==0){
	$ID=SafeRequest("ID","get");
	if($ID==""){
		if(stristr($Param,S_UrlList) && S_Slists!='1'){
			$ID=ReplaceStr($Param,S_UrlList,"");
			$ID=preg_replace("/.".S_Dvsuffix."(.*?)$/",'',$ID);
			$Page=SafeRequest("pages","get");
			if(!IsNum($Page)) $Page=1;
			if(!IsNum($ID)) die("参数传输错误1"); 
			$headerhtml=LinkClassUrl("s_video",$ID,1,$Page,S_SLists);
			header("Location:$headerhtml");
			}
		elseif(stristr($Param,S_UrlContent)){
			$ID=ReplaceStr($Param,S_UrlContent,"");
			$ID=preg_replace("/.".S_Dvsuffix."(.*?)$/",'',$ID);
			if(!IsNum($ID)) die("参数传输错误2");
			$sql="select S_ClassID from s_video where S_ID=$ID";
			$row=$db->getRow($sql);
			$headerhtml=LinkUrl("s_video",$row['S_ClassID'],1,$ID);
			header("Location:$headerhtml");
		 }elseif(S_Slists!='1'){
			 die("参数传输错误咯3");
			 }	
	}else{
		if(stristr($ID,S_UrlList) && S_Slists!='1'){		
		 	$ID=ReplaceStr($ID,S_UrlList,"");
			if(!IsNum($ID)) die("参数传输错误4");
			$Page=SafeRequest("pages","get");
			if(!IsNum($Page)) $Page=1;			
			$headerhtml=LinkClassUrl("s_video",$ID,1,$Page,S_SLists);
			header("Location:$headerhtml");
		  }elseif(stristr($ID,S_UrlContent)){
		  	$ID=ReplaceStr($ID,S_UrlContent,"");
		 	if(!IsNum($ID)) die("参数传输错误5");
			$Page=SafeRequest("pages","get");
			if(!IsNum($Page)) $Page=1;	
			$sql="select S_ClassID from s_video where S_ID=$ID";
			$row=$db->getRow($sql);
			$headerhtml=LinkUrl("s_video",$row['S_ClassID'],1,$ID);
			header("Location:$headerhtml");			
		}elseif(S_Slists!='1'){
			 die("参数传输错误咯6");
			}		
		
		}
		
}

if (stristr($Param,"play")){
	  $cache_id =$Param;
	  if(!($cache_opt->start($cache_id))){
		   echo PlayShow($Param);
		  $cache_opt->end();
	  }
	die();		 
}	

if(S_Webmode==1 or S_Slists=='1'){
	$ID=SafeRequest("ID","get");
	$pages = isset($_GET['pages']) ? (intval($_GET['pages']) ? intval($_GET['pages']) : 1) : 1;
	if($ID==""){
		if(stristr($Param,S_UrlList)){
			$ID=ReplaceStr($Param,S_UrlList,"");
			$ID=preg_replace("/.".S_Dvsuffix."(.*?)$/",'',$ID);
			if(!IsNum($ID)) die("参数传输错误7"); 
			//缓存区
			$cache_id ='l_'.$ID."_".$pages;
			if(!($cache_opt->start($cache_id))){
				 echo SpanVideoList($ID);
				$cache_opt->end();
			}
		}elseif(stristr($Param,S_UrlContent)){
			$ID=ReplaceStr($Param,S_UrlContent,"");
			$ID=preg_replace("/.".S_Dvsuffix."(.*?)$/",'',$ID);
			if(!IsNum($ID)) die("参数传输错误8");
			$pages=SafeRequest("pages","get");
		  	$cache_id ='c_'.$ID."_".$pages;
			if(!($cache_opt->start($cache_id))){
				 echo SpanVideoShow($ID);
				 /*echo("<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$ID."'></script>");*/
				$cache_opt->end();
			}
		}else{
			die("参数传输错误!9");
			}
	}else{	
		if(stristr($ID,S_UrlList)){		
			  $ID=ReplaceStr($ID,S_UrlList,"");
			  if(!IsNum($ID)){die("参数传输错误10");}	
			  $cache_id ='l_'.$ID."_".$pages;;
			  if(!($cache_opt->start($cache_id))){
				   echo SpanVideoList($ID);	
				   $cache_opt->end();
			  }
		} elseif(stristr($ID,S_UrlContent)){
			  $ID=ReplaceStr($ID,S_UrlContent,"");
			  if(!IsNum($ID)){die("参数传输错误11");}
			  $cache_id ='c_'.$ID."_".$pages;
			  if(!($cache_opt->start($cache_id))){
				   echo SpanVideoShow($ID);
				   /*echo("<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$ID."'></script>");*/
				  $cache_opt->end();
			  }		
		  }else{
		 	 die("参数传输错误!12");
		  }		  
	}	
}


function PlayShow($addr){
	global $db;
	$playadd=playadd();
	$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodplay.html");
	$Mark_Text=topandbottom($Mark_Text);		
	$addr=ReplaceStr($addr,"play","");
	$addr=trim(ReplaceStr($addr,".".S_Svcontentsuffix,""));
	$Arr=explode('_',$addr);
	$sql="select * from s_video where S_ID=".$Arr[0]."";
	$row=$db->getrow($sql);
	if($row){
		$Mark_Text= Span_Playlist($Mark_Text,$row['S_ID'],$row['S_Source'],$row['S_VData'],'',$Arr[2],$Arr[1]);
		$Mark_Text=Common_Mark($Mark_Text,$row['S_ClassID']);
		//die($Mark_Text);
		$Mark_Text=datavideo($Mark_Text,$Mark_Text,$row,'1');
		$Data_Arr=explode('$$$',$row['S_VData']);
		$Source_Arr=explode('$$',$row['S_Source']);
		$Server_Arr=explode('$',$row['S_AddPath']);
		if(count($Server_Arr)!=count($Source_Arr)){
			$AddPath=0;
			}
		else{
			$AddPath=$Server_Arr[$Arr[1]];
			}	
		$DataList_Arr=explode('#',$Data_Arr[$Arr[1]]);
		$Source=$Source_Arr[$Arr[1]];
		$Data=$DataList_Arr[$Arr[2]];
		if(count($DataList_Arr)>($Arr[2]+1)){
			$DataNext=$DataList_Arr[($Arr[2]+1)];
			$DataNextArr=explode('$',$DataNext);
			if(count($DataNextArr)==2) $DataNext=$DataNextArr[1];
			$urlnext=PlayLink($Arr[0],$Arr[1],($Arr[2]+1));
			}else{
			$DataNext=$DataList_Arr[$Arr[2]];
			$DataNextArr=explode('$',$DataNext);
			if(count($DataNextArr)==2) $DataNext=$DataNextArr[1];			
			$urlnext=PlayLink($Arr[0],$Arr[1],($Arr[2]));
			}
		if($Arr[2]==0){
			$urllast=PlayLink($Arr[0],$Arr[1],0);
			}else{
			$urllast=PlayLink($Arr[0],$Arr[1],($Arr[2]-1));
			}	
		//获取当前集数
		$nowji=explode('$',$Data);
		if(count($nowji)==1){
			$playnum="第".($Arr[2]+1)."集";
			}else{
			$playnum=$nowji[0];
			}
		//die($Mark_Text);
		$Mark_Text=ReplaceStr($Mark_Text,"{syccms:path}",S_SitePath);
		if(S_VipFun==1){
		$Mark_Text=ReplaceStr($Mark_Text,"[video:player]","<script type='text/javascript' src='".S_SitePath."js/base64.js'></script><script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$row["S_ID"]."&art=0'></script>".PlayFormSel($Source,$Data,$AddPath,$DataNext));
		}else{
		$Mark_Text=ReplaceStr($Mark_Text,"[video:player]","<script type='text/javascript' language='javascript' src='".S_SitePath."js/base64.js'>".PlayFormSel($Source,$Data,$AddPath,$DataNext));
		}
		$Mark_Text=ReplaceStr($Mark_Text,"[video:playname]",$playnum);
	    $Mark_Text=ReplaceStr($Mark_Text,"[video:urlnext]",$urlnext);
		$Mark_Text=ReplaceStr($Mark_Text,"[video:urllast]",$urllast);
		$Mark_Text=ReplaceStr($Mark_Text,"{syccms:weburl}",S_SiteDomain);
		}

		
		/*$Mark_Text.="<script type='text/javascript' language='javascript' src='".S_SitePath."users/userded.php?id=".$row["S_ID"]."&art=0'></script>";*/
	return $Mark_Text;	
	}
function PlayFormSel($PlayForm,$Volume,$AddPath,$DataNext){
	$VolumeArr=explode('$',$Volume);
	if(count($VolumeArr)==2){
		$Volume=$VolumeArr[1];
		}
	if($AddPath!=0 && $AddPath!=""){
		$server=trim(GetAddPath($AddPath));
		}
	else{
		$server="";
		}	
	$Mark_Text=@file_get_contents("../js/player/play.html");
	$Mark_Text=ReplaceStr($Mark_Text,'$playshow$',@file_get_contents("../js/player/".$PlayForm.".html"));

	$Mark_Text=ReplaceStr($Mark_Text,'$s_adloadtime$',S_AdLoadTime);
	$Mark_Text=ReplaceStr($Mark_Text,'$width$',S_PlayWidth);
	$Mark_Text=ReplaceStr($Mark_Text,'$height$',S_PlayHeight);
	$Mark_Text=ReplaceStr($Mark_Text,'$uid$',S_UID);
	$Mark_Text=ReplaceStr($Mark_Text,'{syccms:path}',S_SitePath);
	$Mark_Text=ReplaceStr($Mark_Text,'{syccms:webname}',S_SiteName);
if(S_PlayAddrEnc==2){
	$Mark_Text=ReplaceStr($Mark_Text,'$url$','\'+strdecode(\''.base64_encode(iconv('GB18030','UTF-8',$Volume)).'\')+\'');
}else{
	$Mark_Text=ReplaceStr($Mark_Text,'$url$',$Volume);
}
	$Mark_Text=ReplaceStr($Mark_Text,'$server$',$server);
	$Mark_Text=ReplaceStr($Mark_Text,'$urlnext$',$DataNext);
	return $Mark_Text;
	}	

?>