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

//读取模板文件内容
function GetTemp($tpl,$ids){
	$tplpath=_SYC_ROOT_.S_Templateurl.$tpl;
	if(file_exists($tplpath)){
		$Mark_Text=@file_get_contents($tplpath);
		$Mark_Text=Common_Mark($Mark_Text,$ids);
		return $Mark_Text;
		}
	else{
		die("".$tpl."模板文件不存在!");
		}	
	}
//头部和底部
function topandbottom($Mark_Text){
	$top_txt=@file_get_contents(_SYC_ROOT_.S_Templateurl."head.html");
	$bottom_txt=@file_get_contents(_SYC_ROOT_.S_Templateurl."bottom.html");
	$Mark_Text=str_replace('{syccms:head}',$top_txt,$Mark_Text);
	$Mark_Text=str_replace('{syccms:bottom}',$bottom_txt,$Mark_Text);
	return $Mark_Text;
	}

//同用标签解析
function Common_Mark($Mark_Text,$IDs,$Mode='0'){
	global $db;
	
	if(!IsNul($Mark_Text)) die("模板文件无内容！！");
	$TempImg =S_SitePath.substr(substr(S_Templateurl,0,strlen(S_Templateurl)-1),0,strrpos(substr(S_Templateurl,0,strlen(S_Templateurl)-1),'/')+1);
	preg_match_all('/{sycself:([\S]+?)}/',$Mark_Text,$Arrself);
	if(!empty($Arrself[1])){
		for($i=0;$i<count($Arrself[1]);$i++){
			$sqlself="select S_SelfLable from s_label where S_Name='".$Arrself[1][$i]."'";
			$row=$db->getrow($sqlself);
			if($row){
				$Mark_Text=ReplaceStr($Mark_Text,$Arrself[0][$i],$row['S_SelfLable']);
				}
			}
		}
	unset($Arrself);	
	$Mark_Text  = topandbottom($Mark_Text);	
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:webname}",S_SiteName);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:weburl}",S_SiteDomain);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:path}",S_SitePath);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:notice}",stripslashes(html_entity_decode(S_SiteNotice))); 
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:keyword}",HotSearch(S_Keywords));
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:mail}",S_Adminmail); 
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:qq}",S_AdminQQ);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:stat}",html_entity_decode(stripslashes(S_SiteCount)));
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:tempurl}",$TempImg);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:icp}",S_SiteICP);
	if(S_Webmode=='0'){
		$TopicLinkShow=S_SitePath.S_Stlistfolder."/index.html";
	}else{
		$TopicLinkShow=S_SitePath.S_Dtname."/";
		}
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:topiclink}",$TopicLinkShow);
		//获取到影片总量
		$VideoCount=$db->getOne("select count(S_ID) from s_video where S_IsHide<>1",true);		
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:vodcount}",$VideoCount);
		//获取到影片今日更新数量
		$date_vd=date("Y-m-d");
		$VideoDay=$db->getOne("select count(S_ID) from s_video where S_IsHide<>1 and S_AddTime>'".$date_vd."'");
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:vodcountday}",$VideoDay);
		//获取到当日文章更新数量
		$ArtDay=$db->getOne("select count(S_ID) as recount from s_article where S_IsHide<>1 and S_AddTime>'".$date_vd."'");
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:artcountday}",$ArtDay);
		//获取文章总量
		$ArtCount=$db->getOne("select count(S_ID) as recount from s_article where S_IsHide<>1");
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:artcount}",$ArtCount);
	$Mark_Text  = ReplaceStr($Mark_Text,"{syccms:addlink}",S_SitePath."js/link.php");
	if($Mode=='1'){		
		return $Mark_Text;	
		}
	else{
		return Data_Mark($Mark_Text,$IDs);
		}	
	}

//数据处理
function Data_Mark($Mark_Text,$IDs){
	global $db;
	if(!IsNul($Mark_Text)) die("模板文件没有内容！！");
	preg_match_all('/{syccms:([\S]+)\s+(.*?)}([\s\S]+?){\/syccms:\1}/',$Mark_Text,$Mark_Arr);
	//print_r($Mark_Arr);
	if(!empty($Mark_Arr)){
		for($i=0;$i<count($Mark_Arr[0]);$i++){
			$table='s_'.$Mark_Arr[1][$i];
			$para=$Mark_Arr[2][$i];
			$sql=Mark_Sql($table,$para,$IDs);//sql语句的组织返回
			$result=$db->query($sql);
			$resultcount=$db->num_rows($result);
			if($result){
				if($resultcount==0){
					$Data_Content="无相关的数据!";
					$Mark_Text=ReplaceStr($Mark_Text,$Mark_Arr[0][$i],$Data_Content);
				}else{
					$Data_Content='';$Data_Content_Temp='';$sorti=1;
					while($row=$db->fetch_array($result)){	
						switch($table){
							case 's_video':$Data_Content.=datavideo($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti);break;
							case 's_class':$Data_Content.=dataclass($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti);break;
							case 's_type':$Data_Content.=datatype($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti);break;
							case 's_topic':$Data_Content.=datatopic($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti);break;
							case 's_link':$Data_Content.=datalink($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti);break;
							case 's_article':$Data_Content.=dataart($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti); break;
							}//end switch
							$sorti=$sorti+1;
						}//end while
						
					}//end if($resultcount)	
				$Mark_Text=ReplaceStr($Mark_Text,$Mark_Arr[0][$i],$Data_Content);	
				}//end if($result)	
			}//end for
		} 
	//if(S_Webmode==1) $Mark_Text.=timing();
	$Mark_Text=labelif($Mark_Text);
	return $Mark_Text;
	}
	
function datavideo($para,$label,$row,$sorti){//文件内容，标签参数，标签内容
	preg_match_all('/\[video:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		for($i=0;$i<count($field_arr[0]);$i++){
			$comment="<script type='text/javascript' language='javascript'>var tentpath='".S_SitePath."';var S_ID=".$row['S_ID'].";var types=1;window.jQuery || document.write(unescape(\"%3Cscript%20type%3D%22text/javascript%22%20src%3D%22%0A\")+tentpath+unescape(\"js/jquery.js%22%3E%3C/script%3E\"));</script><script language='javascript' src='".S_SitePath."js/comments.js'></script><div id='av_comment'><div style='padding:5px;text-align:center;'><img src='".S_SitePath."images/faces/loading.gif'/>&nbsp;&nbsp;评论载入中，请稍候.....</div></div>";
			$dingv="<script language=\"javascript\"> var path='".S_SitePath."'; var id=".$row['S_ID']."; var type=1;window.jQuery || document.write(unescape(\"%3Cscript%20type%3D%22text/javascript%22%20src%3D%22%0A\")+path+unescape(\"js/jquery.js%22%3E%3C/script%3E\"));</script><script language=\"javascript\" src=\"".S_SitePath."js/ding.js\"></script><div style=\"height:30px;\"><a  onClick=\"ding(".$row['S_ID'].");\" style=\"cursor:pointer;\"><img src=\"".S_SitePath."images/common/ding.png\" border=\"0\">顶</a><span id=\"ding\"><img src=\"".S_SitePath."images/common/load.gif\"></span>&nbsp;&nbsp;<a  onClick=\"cai(".$row['S_ID'].");\" style=\"cursor:pointer;\"><img src=\"".S_SitePath."images/common/cai.png\" border=\"0\">踩</a><span id=\"cai\"><img src=\"".S_SitePath."images/common/load.gif\"></span></div>";
			switch($field_arr[1][$i]){
				case 'link':$datatmp=ReplaceStr($datatmp,'[video:link]',LinkUrl("s_video",$row['S_ClassID'],1,$row['S_ID']));break;
				case 'pic':$datatmp=ReplaceStr($datatmp,'[video:pic]',picshow($row['S_Pic']));break;
				case 'id':$datatmp=ReplaceStr($datatmp,'[video:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[video:i]',$sorti);break;
				case 'color':$datatmp=ReplaceStr($datatmp,'[video:color]',$row['S_Color']);break;
				case 'year':$datatmp=ReplaceStr($datatmp,'[video:year]',$row['S_Year']);break;
				case 'source':$datatmp=ReplaceStr($datatmp,'[video:source]',$row['S_Source']);break;
				case 'stars':$datatmp=ReplaceStr($datatmp,'[video:stars]',$row['S_Reco']);break;
				case 'hits':$datatmp=ReplaceStr($datatmp,'[video:hits]',$row['S_Hits']);break;
				case 'hitsday':$datatmp=ReplaceStr($datatmp,'[video:hitsday]',$row['S_HitsDay']);break;
				case 'hitsmon':$datatmp=ReplaceStr($datatmp,'[video:hitsmon]',$row['S_HitsMon']);break;
				case 'hitsweek':$datatmp=ReplaceStr($datatmp,'[video:hitsweek]',$row['S_HitsWeek']);break;
				case 'area':$datatmp=ReplaceStr($datatmp,'[video:area]',$row['S_Area']);break;
				case 'language':$datatmp=ReplaceStr($datatmp,'[video:language]',$row['S_Language']);break;
				case 'playlink':$datatmp=ReplaceStr($datatmp,'[video:playlink]',PlayLink($row['S_ID'],0,0));break;
				case 'classlink':$datatmp=ReplaceStr($datatmp,"[video:classlink]",LinkClassUrl("s_class",$row['S_ClassID'],1,1,S_Slists));
				case 'classname':$datatmp=ReplaceStr($datatmp,"[video:classname]",getclass($row['S_ClassID']));break;
				case 'classid':$datatmp=ReplaceStr($datatmp,"[video:classid]",$row['S_ClassID']);break;
				case 'comment':$datatmp=ReplaceStr($datatmp,"[video:comment]",$comment);break;
				case 'updown':$datatmp=ReplaceStr($datatmp,"[video:updown]",$dingv);break;
				case 'puterr':
					$messc=urlencode(convert_encoding("管理员，你好《".$row['S_Name']."》视频有错误，请修正一下！谢谢",'UTF-8','GBK'));
					$datatmp=ReplaceStr($datatmp,"[video:puterr]",S_SitePath."gbook.php?id=".$row['S_ID']."&content=".$messc."");
					break;
				case 'name':
					$name=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Name']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$name);break;
					break;
				case 'direct':
					$direct=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Direct']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$direct);break;
					break;					
				case 'remark':
					if(!IsNul($row['S_Remark'])) $row['S_Remark']='全集'; 
					$remark=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Remark']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$remark);break;					
					break;
				case 'content':
					$content=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Content']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$content);break;				
					break;
				case 'author':
					$author=HotSearch(getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Author']));
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$author);break;				
					break;	
				case 'time':
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],date(ReplaceStr($field_arr[3][$i],'f','i'),strtotime($row['S_AddTime'])));
					break;
				}//end switch		
			}//end for
			//$Mark_Text=ReplaceStr($Mark_Text,$para,$data);
		}
		unset($field_arr);
		return $datatmp;		
	}
	
function dataart($para,$label,$row,$sorti){
	preg_match_all('/\[article:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		for($i=0;$i<count($field_arr[0]);$i++){
			$comment="<script type='text/javascript' language='javascript'>var tentpath='".S_SitePath."';var S_ID=".$row['S_ID'].";var types=2;window.jQuery || document.write(unescape(\"%3Cscript%20type%3D%22text/javascript%22%20src%3D%22%0A\")+tentpath+unescape(\"js/jquery.js%22%3E%3C/script%3E\"));</script><script language='javascript' src='".S_SitePath."js/comments.js'></script><div id='av_comment'><div style='padding:5px;text-align:center;'><img src='".S_SitePath."images/faces/Loading.gif'/>&nbsp;&nbsp;评论载入中，请稍候.....</div></div>";
			$dinga="<script language=\"javascript\"> var path='".S_SitePath."'; var id=".$row['S_ID']."; var type=2;window.jQuery || document.write(unescape(\"%3Cscript%20type%3D%22text/javascript%22%20src%3D%22%0A\")+path+unescape(\"js/jquery.js%22%3E%3C/script%3E\"));</script><script language=\"javascript\" src=\"".S_SitePath."js/ding.js\"></script><div style=\"height:30px;\"><a  onClick=\"ding(".$row['S_ID'].");\" style=\"cursor:pointer;\"><img src=\"".S_SitePath."images/common/ding.png\" border=\"0\">顶</a><span id=\"ding\"><img src=\"".S_SitePath."images/common/load.gif\"></span>&nbsp;&nbsp;<a  onClick=\"cai(".$row['S_ID'].");\" style=\"cursor:pointer;\"><img src=\"".S_SitePath."images/common/cai.png\" border=\"0\">踩</a><span id=\"cai\"><img src=\"".S_SitePath."images/common/load.gif\"></span></div>";
			switch($field_arr[1][$i]){
				case 'link':$datatmp=ReplaceStr($datatmp,'[article:link]',LinkUrl("s_article",$row['S_ClassID'],2,$row['S_ID']));break;
				case 'pic':$datatmp=ReplaceStr($datatmp,'[article:pic]',picshow($row['S_Pic'],'2'));break;
				case 'id':$datatmp=ReplaceStr($datatmp,'[article:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[article:i]',$sorti);break;
				case 'color':$datatmp=ReplaceStr($datatmp,'[article:color]',$row['S_Color']);break;
				case 'source':$datatmp=ReplaceStr($datatmp,'[article:source]',$row['S_Source']);break;
				case 'stars':$datatmp=ReplaceStr($datatmp,'[article:stars]',$row['S_Reco']);break;
				case 'hits':$datatmp=ReplaceStr($datatmp,'[article:hits]',$row['S_Hits']);break;
				case 'hitsday':$datatmp=ReplaceStr($datatmp,'[article:hitsday]',$row['S_HitsDay']);break;
				case 'hitsmon':$datatmp=ReplaceStr($datatmp,'[article:hitsmon]',$row['S_HitsMon']);break;
				case 'hitsweek':$datatmp=ReplaceStr($datatmp,'[article:hitsweek]',$row['S_HitsWeek']);break;
				case 'classlink':$datatmp=ReplaceStr($datatmp,"[article:classlink]",LinkClassUrl("s_class",$row['S_ClassID'],2,1,S_Slists));
				case 'classname':$datatmp=ReplaceStr($datatmp,"[article:classname]",getclass($row['S_ClassID']));break;
				case 'classid':$datatmp=ReplaceStr($datatmp,"[video:classid]",$row['S_ClassID']);break;
				case 'comment':$datatmp=ReplaceStr($datatmp,"[article:comment]",$comment);break;
				case 'updown':$datatmp=ReplaceStr($datatmp,"[article:updown]",$dinga);	break;		
				case 'name':
					$name=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Name']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$name);break;
					break;
				case 'remark':
					if(!IsNul($row['S_Remark'])) $row['S_Remark']='全集'; 
					$remark=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Remark']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$remark);break;					
					break;
				case 'content':
					$content=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Content']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$content);break;				
					break;
				case 'author':
					$author=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Author']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$author);break;				
					break;	
				case 'time':
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],date(ReplaceStr($field_arr[3][$i],'f','i'),strtotime($row['S_AddTime'])));
					
					break;
				}//end switch		
			}//end for
			//$Mark_Text=ReplaceStr($Mark_Text,$para,$data);
		}
		unset($field_arr);
		return $datatmp;		
	}
	
function dataclass($para,$label,$row,$sorti){
	global $db;
	preg_match_all('/\[class:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		preg_match('/{syccms:type\s+([\s\S]+?)}([\s\S]+?){\/syccms:type}/',$label,$type_arr);//判断是否二级分类嵌套
		if(!empty($type_arr)){
			$sqltype=Mark_Sql("s_type",$type_arr[1],$row['S_ID']);
			$typeresult=$db->query($sqltype);
			$typenums=$db->num_rows($typeresult);
			if($typeresult && $typenums>0){
				//print_r($type_arr);
				$typei=1;
				while($row2=$db->fetch_array($typeresult)){
					$data_type.=datatype($type_arr[2],$type_arr[2],$row2,$typei);
					$typei=$typei+1;
					}
				$datatmp=ReplaceStr($datatmp,$type_arr[0],$data_type);
			}else{
				$datatmp=ReplaceStr($datatmp,$type_arr[0],'');	
					}
			}
		for($i=0;$i<count($field_arr[0]);$i++){
			switch($field_arr[1][$i]){
				case 'name':$datatmp=ReplaceStr($datatmp,'[class:name]',$row['S_Name']);break;
				case 'link':
					if($row['S_SystemID']=='2'){
						$datatmp=ReplaceStr($datatmp,'[class:link]',LinkClassUrl("s_class",$row['S_ID'],2,1,S_Slists));	
					}else{
						$datatmp=ReplaceStr($datatmp,'[class:link]',LinkClassUrl("s_class",$row['S_ID'],1,1,S_Slists));	
						}
					break;
				case 'count':$datatmp=ReplaceStr($datatmp,'[class:count]',getclasscount($row['S_ID']));break;
				case 'id':$datatmp=ReplaceStr($datatmp,'[class:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[class:i]',$sorti);break;
				}	
			}
	}
		unset($field_arr);
		return $datatmp;	
}

function datatype($para,$label,$row,$sorti){
	preg_match_all('/\[type:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		for($i=0;$i<count($field_arr[0]);$i++){
			switch($field_arr[1][$i]){
				case 'name':$datatmp=ReplaceStr($datatmp,'[type:name]',$row['S_Name']);break;			
				case 'link':
					if($row['S_SystemID']=='2'){
						$datatmp=ReplaceStr($datatmp,'[type:link]',LinkClassUrl("s_class",$row['S_ID'],2,1,S_Slists));	
					}else{
						$datatmp=ReplaceStr($datatmp,'[type:link]',LinkClassUrl("s_class",$row['S_ID'],1,1,S_Slists));	
						}
					break;
				case 'count':$datatmp=ReplaceStr($datatmp,'[type:count]',getclasscount($row['S_ID']));break;
				case 'id':$datatmp=ReplaceStr($datatmp,'[type:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[type:i]',$sorti);break;
				}
			}
	}
		unset($field_arr);
		return $datatmp;	
}

function datatopic($para,$label,$row,$sorti){
	preg_match_all('/\[topic:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		for($i=0;$i<count($field_arr[0]);$i++){
			switch($field_arr[1][$i]){
				case 'name':
					$name=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Name']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$name);break;
					break;					
				case 'id':$datatmp=ReplaceStr($datatmp,'[topic:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[topic:i]',$sorti);break;
				case 'color':$datatmp=ReplaceStr($datatmp,'[topic:color]',$row['S_Color']);break;
				case 'hits':$datatmp=ReplaceStr($datatmp,'[topic:hits]',$row['S_Hits']);break;
				case 'link':$datatmp=ReplaceStr($datatmp,'[topic:link]',LinkClassUrl("s_topic",$row['S_ID'],$row['S_SystemID'],1,S_Slists));break;
				case 'pic':$datatmp=ReplaceStr($datatmp,'[topic:pic]',picshow($row['S_Pic'],'3'));break;
				case 'stars':$datatmp=ReplaceStr($datatmp,'[topic:stars]',$row['S_Reco']);break;
				case 'remark':
					$remark=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Remark']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$remark);break;
					break;
				case 'content':
					$content=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Content']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$content);break;
					break;
				case 'time':
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],date(ReplaceStr($field_arr[3][$i],'f','i'),strtotime($row['S_AddTime'])));
					break;					
				}
			}
	}
		unset($field_arr);
		return $datatmp;		
}
	
function datalink($para,$label,$row,$sorti){
	preg_match_all('/\[link:\s*([0-9a-zA-Z]+)([\s]*[len|style]*)[=]??([\da-zA-Z\-\\\\:\s]*)\]/',$para,$field_arr);
	$datatmp=$label;
	if(!empty($field_arr)){
		for($i=0;$i<count($field_arr[0]);$i++){
			switch($field_arr[1][$i]){
				case 'name':
					$name=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Name']);
					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$name);break;
					break;					
				case 'id':$datatmp=ReplaceStr($datatmp,'[link:id]',$row['S_ID']);break;
				case 'i':$datatmp=ReplaceStr($datatmp,'[link:i]',$sorti);break;
				case 'url':$datatmp=ReplaceStr($datatmp,'[link:url]',$row['S_Url']);break;
				case 'pic':$datatmp=ReplaceStr($datatmp,'[link:pic]',$row['S_Pic']);break;
				}
			}
	}
		unset($field_arr);
		return $datatmp;		
	}	
//sql组织
function Mark_Sql($table,$para,$ids){
	$loop='';$order='';$sort='';$start='';$classid='';$state='';$stars='';$topicid='';$group='';$hide='';$class='';
	preg_match_all('/([a-z0-9]+)=([a-z0-9|,]+)/',$para,$para_arr);
	if(!empty($para_arr)){
		for($i=0;$i<count($para_arr[0]);$i++){
			switch($para_arr[1][$i]){
				case 'loop':$loop=$para_arr[2][$i];break;
				case 'order':$order=$para_arr[2][$i];break;
				case 'sort':$sort=$para_arr[2][$i];break;
				case 'start':$start=$para_arr[2][$i];break;
				case 'classid':$classid=$para_arr[2][$i];break;
				case 'state':$state=$para_arr[2][$i];break;
				case 'stars':$stars=$para_arr[2][$i];break;
				case 'topicid':$topicid=$para_arr[2][$i];break;
				case 'group':$group=$para_arr[2][$i];break;
				case 'hide':$hide=$para_arr[2][$i];break;
				case 'class':$class=$para_arr[2][$i];break;				
				}
		}
			$sql="select * from `$table` where 1=1 ";
			if(isset($order)=="" or $order!="asc") $order="desc";	
			switch($table){
				case 's_video':
					if(isset($start)=="" or $start==0) $start=1;
					switch ($sort){
						case 'id':$sort="S_ID"; break;
						case 'hits':$sort="S_Hits"; break;
						case 'stars':$sort="S_Reco"; break;
						case 'rand':$sort="rand()"; break;
						case 'ding':$sort="S_Apex"; break;
						case 'cai':$sort="S_Tread"; break;
						case 'hitsday':$sort="S_HitsDay"; break;
						case 'hitsmon':$sort="S_HitsMon"; break;
						case 'hitsweek':$sort="S_HitsWeek"; break;
						default:$sort="UNIX_TIMESTAMP(S_AddTime)"; break;
					}		
				  	if($classid!="all" and $classid!="" and $classid!="auto"){
						$classid=getChild($classid);
						$sql.=" and S_ClassID in ($classid) ";
					  }elseif($classid=="auto" and $ids!=""){
					 	$ids=getChild($ids);
					 	$sql.=" and S_ClassID in($ids) ";
					  }	
					  
					 if($topicid!="all" and $topicid!="" and $topicid!="auto" ){
						 $sql.=" and S_Topic in ($topicid)";
					 }elseif($topicid=='auto'){
						 $sql.=" and S_Topic in ($ids)";
					 }
					 
				  	if($state=="true")  $sql.=" and S_Remark<>'' and S_IsEnd=1 ";
				  	if($stars!="" and $stars!="all") $sql.=" and  S_Reco in (".$stars.")";
				  	$sql.=" and S_IsHide=0 and S_ClassID<>0  Order by ".$sort." ".$order." ";  						  
					if($loop!="all" and $loop!="") $sql.="limit ".($start-1).",".($loop)."";
					break;
				case 's_article':
					if(isset($start)=="" or $start==0) $start=1;
					switch ($sort){
						case 'id':$sort="S_ID"; break;
						case 'hits':$sort="S_Hits"; break;
						case 'stars':$sort="S_Reco"; break;
						case 'rand':$sort="rand()"; break;
						case 'ding':$sort="S_Apex"; break;
						case 'cai':$sort="S_Tread"; break;
						case 'hitsday':$sort="S_HitsDay"; break;
						case 'hitsmon':$sort="S_HitsMon"; break;
						case 'hitsweek':$sort="S_HitsWeek"; break;
						default:$sort="UNIX_TIMESTAMP(S_AddTime)"; break;
					}
												
				  	if($classid!="all" and $classid!="" and $classid!="auto"){
						$classid=getChild($classid);
						$sql.=" and S_ClassID in ($classid) ";
					  }elseif($classid=="auto" and $ids!=""){
					 	$ids=getChild($ids);
					 	$sql.=" and S_ClassID in($ids) ";
					  }
					 
					 if($topicid!="all" and $topicid!="" and $topicid!="auto" ){
						 $sql.=" and S_Topic in ($topicid)";
					 }elseif($topicid=='auto'){
						 $sql.=" and S_Topic in ($ids)";
					 }
					  
				  	if($state=="true")  $sql.=" and S_Remark<>'' and S_IsEnd=1 ";
				  	if($stars!="" and $stars!="all") $sql.=" and  S_Reco in (".$stars.")";
				  	$sql.=" and S_IsHide=0 and S_ClassID<>0  Order by ".$sort." ".$order." ";  						  
					if($loop!="all" and $loop!="") $sql.="limit ".($start-1).",".($loop)."";				
					break;
				case 's_class':
					//
					if($sort=="" or $sort=="id"){
						$sort="S_ID";
					}elseif($sort=="turn"){
						$sort="S_TheOrder";
					}else{
						$sort="S_ID";
						}	
					if($classid!="all" and $classid!="" and $classid!="auto"){
						if($group=="article"){
							$sql.=" and S_ID in ($classid) and S_SystemID=2";
						}else{
							$sql.=" and S_ID in ($classid) and S_SystemID=1";
							}					
						}
					else{
						if($group=="article"){
							$sql.=" and S_FatherID=0 and S_SystemID=2";
							}
						else{
							$sql.=" and S_FatherID=0 and S_SystemID=1";
							}	
						}
					$sql.=" and S_IsHide=0 order by ".$sort." ".$order.""	;					
					//
					break;
				case 's_type':
					//
					if($sort=="" or $sort=="id"){
						$sort="S_ID";
					}elseif($sort=="turn"){
						$sort="S_TheOrder";
					}else{
						$sort="S_ID";
						}				
				  	$sql="select * from s_class where 1=1 ";
				  	if($classid!="all" and $classid!="" and $classid!="auto"){				
						  $sql.=" and S_ID in ($classid) ";				
					  }
				  	elseif($classid=="auto"){
						  $sql.=" and S_FatherID=".$ids." ";		
					  }
					 $sql.=" order by ".$sort." ".$order." "	;
					//
					break;
				case 's_link':
				//
					if($sort=="" or $sort=="id"){
						$sort="S_ID";
					}elseif($sort=="turn"){
						$sort="S_TheOrder";
					}else{
						$sort="S_ID";
						}
					if($classid!="all" and $classid!="")$sql.=" and  S_ClassID in ($classid) ";
					$sql.=" and S_IsVerify=0 and S_IsIndex=0";	
					$sql.=" Order by ".$sort." ".$order." ";
					if($loop!="all" and $loop!="") $sql.="limit ".($loop)."";
					//
					break;
				case 's_topic':
					//
					if($sort=="" or $sort=="time"){
						$sort="UNIX_TIMESTAMP(S_AddTime)";
						}elseif($sort=="id"){
							$sort="S_ID";
						}elseif($sort=="hits"){
							$sort="S_Hits";
						}elseif($sort=="stars"){
							$sort="S_Reco";
						}else{
							$sort="UNIX_TIMESTAMP(S_AddTime)";
							}	
					if($topicid!="all" and $topicid!="" and $topicid!="auto" ){
						if($group=="video"){
							$sql.=" and S_ID in ($topicid) and S_SystemID=1";
							}
						elseif($group=="article"){
							$sql.=" and S_ID in ($topicid) and S_SystemID=2";
							}
						else{
							$sql.=" and S_ID in ($topicid)";
							}	
						}
					elseif($topicid=='auto'){
						$sql.=" and S_ID in ($ids)";
						}	
					else{
						if($group=="video"){
							$sql.=" and S_SystemID=1";
							}
						elseif($group=="article"){
							$sql.=" and S_SystemID=2";
							}					
						}	
					$sql.=" Order by ".$sort." ".$order." ";
					if($loop!="all" and $loop!="") $sql.="limit ".($loop)."";					
					//
					break;
				}
				unset($para_arr);
				return $sql;
			
		}
	}

//文章分类列表
function SpanArticleList($ids){
	global $db;
	//获取分类名和id
	$data_content="";
	$sql="select S_ID,S_Name,S_Template from s_class where S_ID=".$ids."";
	$row=$db->getRow($sql);
	if($row){
		if(IsNul($row['S_Template']) && file_exists(_SYC_ROOT_.S_Templateurl.$row['S_Template'])){
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl.$row['S_Template']);
			}
		else{
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."artlist.html");
			}	
		}else{
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."artlist.html");
			}
	$Mark_Text=topandbottom($Mark_Text);
	$Mark_Text=ReplaceStr($Mark_Text,"[article:classname]",$row['S_Name']);
	$Mark_Text=ReplaceStr($Mark_Text,"[article:classlink]",LinkClassUrl("s_class",$row['S_ID'],2,1,S_Slists));
	$Mark_Text=ReplaceStr($Mark_Text,"[article:classid]",$row['S_ID']);
	//预先除了分页
	$pagenum=getpagenum($Mark_Text);
	preg_match_all('/{syccms:article(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/syccms:article}/',$Mark_Text,$page_arr);//判断是否有分页标识
	if(!empty($page_arr) && !empty($page_arr[2])){
		$sqlstr=Mark_Sql("s_article",$page_arr[1][0],$ids);
		$Arr=spanpage($sqlstr,$page_arr[2][0],$pagenum);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
		if($recount==0){
			$data_content="<div align=center><strong><font style=font-size:12px;>该分类暂无数据！</font></strong></div>";
		}else{
			if($result){
				$sorti=1;
				while ($row2 = $db ->fetch_array($result)){
					$datatmp=dataart($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
					$sorti=$sorti+1;
					$data_content.=$datatmp;
					}
				}
			}// end if recount
		$Mark_Text=Page_Mark($Mark_Text,$Arr);	
		$Mark_Text=ReplaceStr($Mark_Text,$page_arr[0][0],$data_content);
		unset($Arr);
		}
	unset($page_arr);
	$Mark_Text=	Common_Mark($Mark_Text,$ids);
	return $Mark_Text;	
	}
//专题内容页面
function SpanTopicShow($ids){
	global $db;
	$data_content="";
	$sqlstr2="select * from s_topic where S_ID=".$ids."";
	$row=$db->getrow($sqlstr2);
	if($row){
		if($row['S_SystemID']==1){
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodtopic.html");
			$Table="s_video";
		}else{
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."arttopic.html");
			$Table="s_article";
			}
		$Mark_Text=topandbottom($Mark_Text);
		$Mark_Text=ReplaceStr($Mark_Text,"[topic:name]",$row['S_Name']);
		$Mark_Text=ReplaceStr($Mark_Text,"[topic:content]",$row['S_Content']);
		$Mark_Text=ReplaceStr($Mark_Text,"[topic:link]",LinkClassUrl("s_topic",$row['S_ID'],$row['S_SystemID'],1,S_Slists));
		$pagenum=getpagenum($Mark_Text);
		preg_match_all('/{syccms:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/syccms:video}/',$Mark_Text,$page_arr);//判断是否有分页标识
		if(!empty($page_arr) && !empty($page_arr[2])){
			$sqlstr=Mark_Sql($Table,$page_arr[1][0],$ids);
			//die($sqlstr);
			$Arr=spanpage($sqlstr,$page_arr[2][0],$pagenum);//sql,每页显示条数
			$result=$db->query($Arr[2]);
			$recount=$db->num_rows($result);
			if($recount==0){
				$data_content="<div align=center><strong><font style=font-size:12px;>该分类暂无数据！</font></strong></div>";
			}else{
				if($result){
					$sorti=1;
					while ($row2 = $db ->fetch_array($result)){
						switch($Table){
							case 's_video':$datatmp=datavideo($page_arr[0][0],$page_arr[3][0],$row2,$sorti);break;
							case 's_article':$datatmp=dataart($page_arr[0][0],$page_arr[3][0],$row2,$sorti);break;
							default :$datatmp=datavideo($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
							}
						$sorti=$sorti+1;
						$data_content.=$datatmp;
						}
					}
				}// end if recount
			$Mark_Text=Page_Mark($Mark_Text,$Arr);	
			$Mark_Text=ReplaceStr($Mark_Text,$page_arr[0][0],$data_content);
			unset($Arr);
			}
		unset($page_arr);
		$Mark_Text=	Common_Mark($Mark_Text,$ids);
		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=6></script>";//增加人气
		return $Mark_Text;		
	}else{
		return "专题数据加载出错";
		}
	}
//专题列表页面
function SpanTopicList(){
	global $db;
	$data_content="";
	$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."topic.html");
	$Mark_Text=topandbottom($Mark_Text);
	$pagenum=getpagenum($Mark_Text);
	preg_match_all('/{syccms:topic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/syccms:topic}/',$Mark_Text,$page_arr);//判断是否有分页标识
	if(!empty($page_arr) && !empty($page_arr[2])){
		$sqlstr=@Mark_Sql("s_topic",$page_arr[1][0],$ids);
		$Arr=spanpage($sqlstr,$page_arr[2][0],$pagenum);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
		if($recount==0){
			$data_content="<div align=center><strong><font style=font-size:12px;>暂无专题数据！</font></strong></div>";
		}else{
			if($result){
				$sorti=1;
				while ($row2 = $db ->fetch_array($result)){
					$datatmp=datatopic($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
					$sorti=$sorti+1;
					$data_content.=$datatmp;
					}
				}
			}// end if recount
		$Mark_Text=Page_Mark($Mark_Text,$Arr);	
		$Mark_Text=ReplaceStr($Mark_Text,$page_arr[0][0],$data_content);
		unset($Arr);
		}
	unset($page_arr);
	$Mark_Text=	@Common_Mark($Mark_Text,$ids);
	return $Mark_Text;	
	}
//视频内容页面
function SpanVideoShow($ids){
	global $db;
	$playadd=playadd();
	$stars="";
	$sql="select * from s_video where S_ID=".$ids."";
	$row=$db->getRow($sql);
	if($row){
		$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodshow.html");
		$Mark_Text=topandbottom($Mark_Text);
		$Mark_Text= Span_Playlist($Mark_Text,$row['S_ID'],$row['S_Source'],$row['S_VData']);
		$Mark_Text=Common_Mark($Mark_Text,$row['S_ClassID']);
		if (stripos($Mark_Text, '[video:pre]')) {
			$pre = $db->getRow('select S_ID,S_Name,S_ClassID from s_video where S_ClassID='.$row['S_ClassID'].' and S_AddTime<\''.$row['S_AddTime'].'\' order by S_ID desc limit 1');
			$prestr = $pre!=false ? '<a href="'.LinkUrl("s_video",$pre['S_ClassID'],1,$pre['S_ID']).'">'.$pre['S_Name'].'</a>' : '<span class="pageprenex">前面没有了</span>';
			$Mark_Text=ReplaceStr($Mark_Text,'[video:pre]',$prestr);
		}
		if (stripos($Mark_Text, '[video:next]')) {
			$next = $db->getRow('select S_ID,S_Name,S_ClassID from s_video where S_ClassID='.$row['S_ClassID'].' and S_AddTime>\''.$row['S_AddTime'].'\' order by S_ID desc limit 1');
			$nextstr = $next!=false ? '<a href="'.LinkUrl("s_video",$next['S_ClassID'],1,$next['S_ID']).'">'.$next['S_Name'].'</a>' : '<span class="pageprenex">后面没有了</span>';
			$Mark_Text=ReplaceStr($Mark_Text,'[video:next]',$nextstr);
		}
		$Mark_Text=ReplaceStr($Mark_Text,'[video:hits]',"<font id=\"hits_dyn\">".$row['S_Hits']."</font>");//预处理动态人气
		$Mark_Text=datavideo($Mark_Text,$Mark_Text,$row,'1');
		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=3></script>";//增加人气
		return $Mark_Text;
	}else{
		return "对不起,找不到相关的数据信息!";
		}
	}
//新闻内容页面
function SpanArticleShow($ids){
	global $db;
	$stars="";
	$sql="select * from s_article where S_ID=".$ids."";
	$row=$db->getRow($sql);
	if($row){
		$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."artshow.html");

		$Mark_Text=topandbottom($Mark_Text);
		$Mark_Text=Common_Mark($Mark_Text,$row['S_ClassID']);
		if (stripos($Mark_Text, '[article:pre]')) {
			$pre = $db->getRow('select S_ID,S_Name,S_ClassID from s_article where S_ClassID='.$row['S_ClassID'].' and S_AddTime<\''.$row['S_AddTime'].'\' order by S_ID desc limit 1');
			$prestr = $pre!=false ? '<a href="'.LinkUrl("s_article",$pre['S_ClassID'],1,$pre['S_ID']).'">'.$pre['S_Name'].'</a>' : '<span class="pageprenex">前面没有了</span>';
			$Mark_Text=ReplaceStr($Mark_Text,'[article:pre]',$prestr);
		}
		if (stripos($Mark_Text, '[article:next]')) {
			$next = $db->getRow('select S_ID,S_Name,S_ClassID from s_article where S_ClassID='.$row['S_ClassID'].' and S_AddTime>\''.$row['S_AddTime'].'\' order by S_ID desc limit 1');
			$nextstr = $next!=false ? '<a href="'.LinkUrl("s_article",$next['S_ClassID'],1,$next['S_ID']).'">'.$next['S_Name'].'</a>' : '<span class="pageprenex">后面没有了</span>';
			$Mark_Text=ReplaceStr($Mark_Text,'[article:next]',$nextstr);
		}
		$Mark_Text=ReplaceStr($Mark_Text,'[article:hits]',"<font id=\"hits_dyn\">".$row['S_Hits']."</font>");//预处理动态人气
		$Mark_Text=dataart($Mark_Text,$Mark_Text,$row,'1');
		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=4></script>";//增加人气
		return $Mark_Text;
	}else{
		return "对不起,找不到相关的数据信息!";
		}
	}	
//视频分类列表
function SpanVideoList($ids){
	global $db;
	//获取分类名和id
	$data_content="";
	$sql="select S_ID,S_Name,S_Template from s_class where S_ID=".$ids."";
	$row=$db->getRow($sql);
	if($row){
		if(IsNul($row['S_Template']) && file_exists(_SYC_ROOT_.S_Templateurl.$row['S_Template'])){
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl.$row['S_Template']);
			}
		else{
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodlist.html");
			}	
		}else{
			$Mark_Text=@file_get_contents(_SYC_ROOT_.S_Templateurl."vodlist.html");
			}
	$Mark_Text=topandbottom($Mark_Text);
	$Mark_Text=ReplaceStr($Mark_Text,"[video:classname]",$row['S_Name']);
	$Mark_Text=ReplaceStr($Mark_Text,"[video:classlink]",LinkClassUrl("s_class",$row['S_ID'],1,1,S_Slists));
	$Mark_Text=ReplaceStr($Mark_Text,"[video:classid]",$row['S_ID']);
	//预先除了分页
	$pagenum=getpagenum($Mark_Text);
	preg_match_all('/{syccms:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/syccms:video}/',$Mark_Text,$page_arr);//判断是否有分页标识
	if(!empty($page_arr) && !empty($page_arr[2])){
		$sqlstr=Mark_Sql("s_video",$page_arr[1][0],$ids);
		$Arr=spanpage($sqlstr,$page_arr[2][0],$pagenum);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$recount=$db->num_rows($result);
		if($recount==0){
			$data_content="<div align=center><strong><font style=font-size:12px;>该分类暂无数据！</font></strong></div>";
		}else{
			if($result){
				$sorti=1;
				while ($row2 = $db ->fetch_array($result)){
					$datatmp=datavideo($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
					$sorti=$sorti+1;
					$data_content.=$datatmp;
					}
				}
			}// end if recount
		$Mark_Text=Page_Mark($Mark_Text,$Arr);	
		$Mark_Text=ReplaceStr($Mark_Text,$page_arr[0][0],$data_content);
		unset($Arr);
		}
	unset($page_arr);
	$Mark_Text=	Common_Mark($Mark_Text,$ids);
	return $Mark_Text;
	}
//图片处理
function picshow($url,$mode='1'){
	if(stristr($url,"http://")==false){
		if($url==""){
			$url=S_SitePath."images/nopic.gif";
			}
  		else{
			switch($mode){
				case '1':$url=S_SitePath."images/".S_Vimgfolder."/".$url;break;
				case '2':$url=S_SitePath."images/".S_Aimgfolder."/".$url;break;
				case '3':$url=S_SitePath."images/".S_Timgfolder."/".$url;break;
				default:$url=S_SitePath."images/".S_Vimgfolder."/".$url;break;
				}
	  		}							
		}
	return $url;
}
//连载
function remarkshow($remark){
	if(!IsNul($remark)) $remark="全集";
	return $remark;
	}
//播放连接
function PlayLink($ID,$group,$ji){
	if(S_Webmode==1){
		$playlink=S_SitePath.S_Dvname."/?play".$ID."_".$group."_".$ji."".".".S_Svcontentsuffix;
	}elseif(S_Webmode==0  && S_IsStaticPlay==0){
		$playlink=S_SitePath.S_PlayFolder."/".$ID."/play".$ID."_".$group."_".$ji.".".S_Svcontentsuffix;
	}else{
		$playlink=S_SitePath.S_Dvname."/?play".$ID."_".$group."_".$ji."".".".S_Svcontentsuffix;
		}	
	return $playlink;
	}

//长度控制
function getlen($para='',$val='',$res=''){//控制符号：如len ,控制内容值 如:5，控制的记录:name
	if(!empty($para) && !empty($val)){
		if(is_numeric($val)){
			$cont=cnsubstr($res,intval($val));
		}else{
			$cont=$res;
			}
	}else{
		$cont=$res;
		}
	return $cont;	
}
//获取分类名称	
function getclass($id=''){
	global $db;
	$sql="select S_Name from s_class where S_ID=$id";
	$row=$db->getRow($sql);
	if($row){
		return $row['S_Name'];
	}else{
		return "未知分类";	
		}
	}
//获取分类视频数目
function getclasscount($id='',$type='1'){
	global $db;
	if($type=='1'){
		$sql="select count(S_ID) as rc from s_video where S_ClassID=$id";
	}else{
		$sql="select count(S_ID) as rc from s_article where S_ClassID=$id";
		}
	$row=$db->getRow($sql);
	if($row){
		return $row['rc'];
	}else{
		return "获取失败";
		}
	}
//获取分页数目	
function getpagenum($Mark_Text){
	preg_match('/\{syccms:(pagenum)\s*([a-zA-Z=]*)\s*([\d]*)\}/',$Mark_Text,$pagearr);
	if(!empty($pagearr)){
		if(trim($pagearr[3])!=""){
			$pagenum=$pagearr[3];
			}
		else{
			$pagenum=10;
			}	
	}else{
		$pagenum=10;
		}
		unset($pagearr);
		return $pagenum;
	}
	
function spanpage($mysql,$pagesize,$pagenum=10){
	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;}
    $pagejs=ceil($nums/$pagesok);//总页数
    if($pages>$pagejs){
     $pages=$pagejs;
    }
    $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;
	$result = $db -> query($sql);
	$str="";
	$first="?".$url."pages=1";
	$pageup="?".$url."pages=".($pages-1)."";
	$pagenext="?".$url."pages=".($pages+1)."";
	$last="?".$url."pages=".$pagejs."";
	$pagelist="<select  onchange=javascript:window.location=this.options[this.selectedIndex].value;>\r\n<option value='0'>跳转</option>\r\n";
	for($k=1;$k<=$pagejs;$k++){
		$pagelist.="<option value='?".$url."pages=".$k."'>第".$k."页</option>\r\n";
		}
	$pagelist.="</select>";	
	if($pagejs<=$pagenum){
  		for($i=1;$i<=$pagejs;$i++){
   			$str.="<a href='?".$url."pages=".$i."'>".$i."</a>&nbsp;";
 	 	}
	}
	else{
 		if($pages>=($pagenum)){
 			for($i=$pages-intval($pagenum/2);$i<=$pages+(intval($pagenum/2));$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<=$pagenum;$i++){
    			$str.="<a href='?".$url."pages=".$i." '>".$i."</a>&nbsp;";
 		} 
 				if($i<=$pagejs){ 
      				$str.="....";
	  				$str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>&nbsp;";
    			}
 		 }
	}
	 while ($row = $db -> fetch_array($result) ){ }
	 $arr=array($str,$result,$sql,$nums,$pagelist,$pages,$pagejs,$first,$pageup,$pagenext,$last,$pagesok);
	  @mysql_free_result($res);
	 return $arr;
}

function Page_Mark($Mark_Text,$Arr){
		$Mark_Text=preg_replace('/\{syccms:pagenum(.*?)\}/','{syccms:pagenum}',$Mark_Text);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagedata}',$Arr[3]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagedown}',$Arr[9]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagenow}',$Arr[5]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagecout}',$Arr[6]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagelist}',$Arr[4]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagesize}',$Arr[11]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagefirst}',$Arr[7]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pageup}',$Arr[8]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagenum}',$Arr[0]);
		$Mark_Text=ReplaceStr($Mark_Text,'{syccms:pagelast}',$Arr[10]);	
		return $Mark_Text;
	}
	
//播放列表
function Span_Playlist($Mark_Text,$ID,$S_Source,$S_VData,$path='',$IsPlay='',$Group=''){
	global $db;
	$playadd=playadd($path);
	$Play_Content="";
	$Source_Arr=explode('$$',$S_Source);
	$Data_Arr=explode('$$$',$S_VData);
	preg_match_all("/{syccms:playlist\s+([\s\S]+?)}([\s\S]+?){\/syccms:playlist}/",$Mark_Text,$Play_Arr);
	if(!empty($Play_Arr) && !empty($Play_Arr[0])){
		preg_match_all('/([a-z0-9]+)=([a-z0-9|,]+)/',$Play_Arr[1][0],$Param_Arr);
		for($kk=0;$kk<count($Param_Arr[1]);$kk++){
			$IsAuto=0;
			if($Param_Arr[2][$kk]=="auto"){
				$IsAuto=1;
				break;
				}
			}
		if($IsAuto=='1'){
		$Play_Content_Temp=$Play_Arr[2][0];
		$Play_Content_Temp=ReplaceStr($Play_Content_Temp,"[playlist:name]",playaddshow($playadd,$Source_Arr[$Group]));
		$Play_Content_Temp=ReplaceStr($Play_Content_Temp,"[playlist:i]",($Group+1));		
		$DataList_Arr=explode('#',$Data_Arr[$Group]);
		$Play_Content2="";
		$Play_Content2_Temp="";
		for($j=0;$j<count($DataList_Arr);$j++){
			$ListName=explode('$',$DataList_Arr[$j]);
			if(count($ListName)==1){
				$ListName[0]="第".($j+1)."集";
				$ListName[1]=$DataList_Arr[$j];
				}
			preg_match_all("/{syccms:playurl\s+([\s\S]+?)}([\s\S]+?){\/syccms:playurl}/",$Play_Arr[2][0],$PlayList_Arr);
			
			$Play_Content2_Temp=$PlayList_Arr[2][0];
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playlist:i]",($i+1));
			if(IsNum($IsPlay) && $IsPlay==$j){
				$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:name]","<font color=red>".$ListName[0]."</font>");
			}else{
				$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:name]",$ListName[0]);
				}	
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:add]",$DataList_Arr[$j]);
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:url]",PlayLink($ID,$Group,$j));
			$Play_Content2.=$Play_Content2_Temp;									
			}
			$temp_play_list=ReplaceStr($PlayList_Arr[0][0],"[playlist:i]",($i+1));
			$Play_Content_Temp=ReplaceStr($Play_Content_Temp,$temp_play_list,$Play_Content2);
			$Play_Content.=$Play_Content_Temp;	
			
			$Mark_Text=ReplaceStr($Mark_Text,$Play_Arr[0][0],$Play_Content);
			$Mark_Text=ReplaceStr($Mark_Text,'[playlist:len]',count($Source_Arr));
			return $Mark_Text;
			die();
		
	}
	//
	for($i=0;$i<count($Source_Arr);$i++){
		$Play_Content_Temp=$Play_Arr[2][0];
		$Play_Content_Temp=ReplaceStr($Play_Content_Temp,"[playlist:name]",playaddshow($playadd,$Source_Arr[$i]));
		$Play_Content_Temp=ReplaceStr($Play_Content_Temp,"[playlist:i]",($i+1));
		//die($Play_Content_Temp);
		$DataList_Arr=explode('#',$Data_Arr[$i]);
		$Play_Content2="";
		$Play_Content2_Temp="";
		for($j=0;$j<count($DataList_Arr);$j++){
			$ListName=explode('$',$DataList_Arr[$j]);
			if(count($ListName)==1){
				$ListName[0]="第".($j+1)."集";
				$ListName[1]=$DataList_Arr[$j];
				}
			preg_match_all("/{syccms:playurl\s+([\s\S]+?)}([\s\S]+?){\/syccms:playurl}/",$Play_Arr[2][0],$PlayList_Arr);
			$Play_Content2_Temp=$PlayList_Arr[2][0];
			
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playlist:i]",($i+1));
			if(IsNum($IsPlay) && $IsPlay==$j){
				$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:name]","<font color=red>".$ListName[0]."</font>");
			}else{
				$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:name]",$ListName[0]);
				}	
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:add]",$DataList_Arr[$j]);
			$Play_Content2_Temp=ReplaceStr($Play_Content2_Temp,"[playurl:url]",PlayLink($ID,$i,$j));
			$Play_Content2.=$Play_Content2_Temp;									
			}
		$temp_play_list=ReplaceStr($PlayList_Arr[0][0],"[playlist:i]",($i+1));
		$Play_Content_Temp=ReplaceStr($Play_Content_Temp,$temp_play_list,$Play_Content2);
		$Play_Content.=$Play_Content_Temp;	
		}
	$Mark_Text=ReplaceStr($Mark_Text,$Play_Arr[0][0],$Play_Content);
	$Mark_Text=ReplaceStr($Mark_Text,'[playlist:len]',count($Source_Arr));
		}
	return $Mark_Text;
	}
	
//if标签处理
function labelif($Mark_Text){
	$prg='/{if:(.*?)}(.*?){end if}/';
	preg_match_all($prg,$Mark_Text,$arr);
	if(!empty($arr[0]) && !empty($arr[0][0])){
		for($i=0;$i<count($arr[0]);$i++){
			$else=explode('{else}',$arr[2][$i]);
			if(count($else)==2){
				$evalstr="if(".$arr[1][$i]."){ return '".$else[0]."';}else{return '".$else[1]."';}";	
				$str=eval($evalstr);
				$Mark_Text=ReplaceStr($Mark_Text,$arr[0][$i],$str);
			}else{
				$evalstr="if(".$arr[1][$i]."){ return '".$arr[2][$i]."' ;}";
				$str=eval($evalstr);
				$Mark_Text=ReplaceStr($Mark_Text,$arr[0][$i],$str);
				
			}
		}
	}
	return $Mark_Text;
}
?>