<?php

require_once("conn.php");

require_once("function.php");

//读取模板文件内容

function GetTemp($tpl,$ids){

	$tplpath=_CHSHDJ_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(_CHSHDJ_ROOT_.S_Templateurl."head.html");

	$bottom_txt=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."bottom.html");

	$Mark_Text=str_replace('{chshdjcms:head}',$top_txt,$Mark_Text);

	$Mark_Text=str_replace('{chshdjcms: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('/{chshdjcmsself:([\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,"{chshdjcms:webname}",S_SiteName);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:weburl}",S_SiteDomain);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:path}",S_SitePath);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:stat}",html_entity_decode(stripslashes(S_SiteCount)));

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:notice}",stripslashes(html_entity_decode(S_SiteNotice)));

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:keyword}",HotSearch(S_Keywords));

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:mail}",S_Adminmail); 

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:qq}",S_AdminQQ);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:tel}",S_Admindel);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:tempurl}",$TempImg);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:classid}",0);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms: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,"{chshdjcms:topiclink}",$TopicLinkShow);

	$VideoCount="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=vc'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:vodcount}",$VideoCount);

	$VideoDay="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=vd'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:vodcountday}",$VideoDay);

	$ArtDay="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=ad'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:artcountday}",$ArtDay);

	$ArtCount="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=ac'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:artcount}",$ArtCount);

	$UserCount="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=uc'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:usercount}",$UserCount);

	$UserDay="<script type='text/javascript' language='javascript' src='".S_SitePath."js/count.php?action=ud'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:usercountday}",$UserDay);

	$UserDt="<script src='".S_SitePath."user/user_dt.php'></script>";

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:userdt}",$UserDt);

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:addlink}",S_SitePath."js/link.php");

	if(S_Dvmode==1){

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djnews}",S_SitePath."toplist/?ac=news");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:dj5x}",S_SitePath."toplist/?ac=5x");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djplay}",S_SitePath."toplist/?ac=play");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djhits}",S_SitePath."toplist/?ac=hits");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djri}",S_SitePath."toplist/?ac=rhits");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djzhou}",S_SitePath."toplist/?ac=zhits");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djyue}",S_SitePath."toplist/?ac=yhits");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djding}",S_SitePath."toplist/?ac=ding");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djcai}",S_SitePath."toplist/?ac=cai");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djfav}",S_SitePath."toplist/?ac=fav");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djdown}",S_SitePath."toplist/?ac=down");

        }else{

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djnews}",S_SitePath."toplist/djnews.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:dj5x}",S_SitePath."toplist/dj5x.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djplay}",S_SitePath."toplist/djplay.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djhits}",S_SitePath."toplist/djhits.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djri}",S_SitePath."toplist/djri.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djzhou}",S_SitePath."toplist/djzhou.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djyue}",S_SitePath."toplist/djyue.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djding}",S_SitePath."toplist/djding.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djcai}",S_SitePath."toplist/djcai.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djfav}",S_SitePath."toplist/djfav.html");

	$Mark_Text  = ReplaceStr($Mark_Text,"{chshdjcms:djdown}",S_SitePath."toplist/djdown.html");

        }

	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('/{chshdjcms:([\S]+)\s+(.*?)}([\s\S]+?){\/chshdjcms:\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;

							case 's_users':$Data_Content.=datausers($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti); break;

							case 's_pic':$Data_Content.=datapic($Mark_Arr[0][$i],$Mark_Arr[3][$i],$row,$sorti); break;

							case 's_blog':$Data_Content.=datablog($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;</script><script language='javascript' src='".S_SitePath."js/jquery.js'></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;</script><script language=\"javascript\" src=\"".S_SitePath."js/jquery.js\"></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 'shits':$datatmp=ReplaceStr($datatmp,'[video:shits]',$row['S_Favhits']);break;

				case 'xhits':$datatmp=ReplaceStr($datatmp,'[video:xhits]',$row['S_Downhits']);break;

				case 'rhits':$datatmp=ReplaceStr($datatmp,'[video:rhits]',$row['S_Rhits']);break;

				case 'zhits':$datatmp=ReplaceStr($datatmp,'[video:zhits]',$row['S_Zhits']);break;

				case 'yhits':$datatmp=ReplaceStr($datatmp,'[video:yhits]',$row['S_Yhits']);break;

				case 'dhits':$datatmp=ReplaceStr($datatmp,'[video:dhits]',$row['S_Apex']);break;

				case 'chits':$datatmp=ReplaceStr($datatmp,'[video:chits]',$row['S_Tread']);break;

				case 'area':$datatmp=ReplaceStr($datatmp,'[video:area]',$row['S_Area']);break;

				case 'language':$datatmp=ReplaceStr($datatmp,'[video:language]',$row['S_Language']);break;

				case 'keywords':$datatmp=ReplaceStr($datatmp,'[video:keywords]',HotSearch($row['S_Keywords']));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 'username':$datatmp=ReplaceStr($datatmp,"[video:username]",$row['S_Direct']);break;

				case 'ulink':$datatmp=ReplaceStr($datatmp,"[video:ulink]",linkweburl(1,$row['S_Direct']));break;

				case 'uqq':$datatmp=ReplaceStr($datatmp,"[video:uqq]",getuser('qq',$row['S_Direct']));break;

				case 'usex':$datatmp=ReplaceStr($datatmp,"[video:usex]",getuser('sex',$row['S_Direct']));break;

				case 'ucity':$datatmp=ReplaceStr($datatmp,"[video:ucity]",getuser('city',$row['S_Direct']));break;

				case 'unichen':$datatmp=ReplaceStr($datatmp,"[video:unichen]",getuser('nichen',$row['S_Direct']));break;

				case 'upic':$datatmp=ReplaceStr($datatmp,"[video:upic]",getuser('pic',$row['S_Direct']));break;

				case 'uid':$datatmp=ReplaceStr($datatmp,"[video:uid]",getuser('uid',$row['S_Direct']));break;

				case 'xzds':$datatmp=ReplaceStr($datatmp,"[video:xzds]",$row['S_IsEnd']);break;

				case 'dx':$datatmp=ReplaceStr($datatmp,"[video:dx]",$row['S_Dx']);break;

				case 'yz':$datatmp=ReplaceStr($datatmp,"[video:yz]",$row['S_Yz']);break;

				case 'btime':$datatmp=ReplaceStr($datatmp,"[video:btime]",$row['S_Btime']);break;

				case 'url':$datatmp=ReplaceStr($datatmp,"[video:url]",$row['S_VData']);break;

				case 'qurl':$datatmp=ReplaceStr($datatmp,"[video:qurl]",playurl($row['S_VData'],$row['S_AddPath']));break;

				case 'fwdid':$datatmp=ReplaceStr($datatmp,"[video:fwdid]",$row['S_AddPath']);break;

				case 'playtime':$datatmp=ReplaceStr($datatmp,"[video:playtime]",datetime($row['S_Playtime']));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 '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;</script><script language='javascript' src='".S_SitePath."js/jquery.js'></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;</script><script language=\"javascript\" src=\"".S_SitePath."js/jquery.js\"></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]',"<script src=".S_SitePath."js/hits.php?id=".$row['S_ID']."&type=4></script>");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 'username':$datatmp=ReplaceStr($datatmp,"[article:username]",$row['S_Author']);break;

				case 'ulink':$datatmp=ReplaceStr($datatmp,"[article:ulink]",linkweburl(1,$row['S_Author']));break;

				case 'uqq':$datatmp=ReplaceStr($datatmp,"[article:uqq]",getuser('qq',$row['S_Author']));break;

				case 'usex':$datatmp=ReplaceStr($datatmp,"[article:usex]",getuser('sex',$row['S_Author']));break;

				case 'ucity':$datatmp=ReplaceStr($datatmp,"[article:ucity]",getuser('city',$row['S_Author']));break;

				case 'unichen':$datatmp=ReplaceStr($datatmp,"[article:unichen]",getuser('nichen',$row['S_Author']));break;

				case 'upic':$datatmp=ReplaceStr($datatmp,"[article:upic]",getuser('pic',$row['S_Author']));break;

				case 'uid':$datatmp=ReplaceStr($datatmp,"[article:uid]",getuser('uid',$row['S_Author']));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 '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('/{chshdjcms:type\s+([\s\S]+?)}([\s\S]+?){\/chshdjcms: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 'fxgs':$datatmp=ReplaceStr($datatmp,'[topic:fxgs]',$row['S_Fxgs']);break;

				case 'year':$datatmp=ReplaceStr($datatmp,'[topic:year]',$row['S_Year']);break;

				case 'yuyan':$datatmp=ReplaceStr($datatmp,'[topic:yuyan]',$row['S_Language']);break;

				case 'area':$datatmp=ReplaceStr($datatmp,'[topic:area]',$row['S_Area']);break;

				case 'username':$datatmp=ReplaceStr($datatmp,'[topic:username]',$row['S_Keywords']);break;

				case 'unichen':$datatmp=ReplaceStr($datatmp,'[topic:unichen]',getuser('nichen',$row['S_Keywords']));break;

				case 'ulink':$datatmp=ReplaceStr($datatmp,'[topic:ulink]',linkweburl(1,$row['S_Keywords']));break;

				case 'link':$datatmp=ReplaceStr($datatmp,'[topic:link]',LinkClassUrl("s_topic",$row['S_ID'],$row['S_SystemID'],1));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 datausers($para,$label,$row,$sorti){

	preg_match_all('/\[users:\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,'[users:id]',$row['S_ID']);break;

				case 'i':$datatmp=ReplaceStr($datatmp,'[users:i]',$sorti);break;

				case 'hits':$datatmp=ReplaceStr($datatmp,'[users:hits]',$row['S_Hits']);break;

				case 'zhits':$datatmp=ReplaceStr($datatmp,'[users:zhits]',"<script src=".S_SitePath."js/hits.php?id=".$row['S_ID']."&type=8></script>");break;

				case 'qq':$datatmp=ReplaceStr($datatmp,'[users:qq]',$row['S_QQ']);break;

				case 'loghits':$datatmp=ReplaceStr($datatmp,'[users:loghits]',$row['S_LogNum']);break;

				case 'email':$datatmp=ReplaceStr($datatmp,'[users:email]',$row['S_Email']);break;

				case 'sex':$datatmp=ReplaceStr($datatmp,'[users:sex]',getuser('sex',$row['S_Name']));break;

				case 'link':$datatmp=ReplaceStr($datatmp,'[users:link]',linkweburl($row['S_ID'],$row['S_Name']));break;

				case 'pic':$datatmp=ReplaceStr($datatmp,'[users:pic]',piclink('logo',$row['S_Logo'],'big'));break;

				case 'coin':$datatmp=ReplaceStr($datatmp,'[users:coin]',$row['S_Coin']);break;

				case 'city':$datatmp=ReplaceStr($datatmp,'[users:city]',$row['S_City']);break;

				case 'fg':$datatmp=ReplaceStr($datatmp,'[users:fg]',$row['S_Fg']);break;

				case 'zc':$datatmp=ReplaceStr($datatmp,'[users:zc]',$row['S_Zc']);break;

				case 'type':$datatmp=ReplaceStr($datatmp,'[users:type]',getuser('tid',$row['S_Name']));break;

				case 'level':$datatmp=ReplaceStr($datatmp,'[users:level]',userleve($row['S_Type']));break;

				case 'fscount':$datatmp=ReplaceStr($datatmp,'[users:fscount]',getusercount($row['S_Name'],'fs'));break;

				case 'hycount':$datatmp=ReplaceStr($datatmp,'[users:hycount]',getusercount($row['S_Name'],'hy'));break;

				case 'musiccount':$datatmp=ReplaceStr($datatmp,'[users:musiccount]',getusercount($row['S_Name'],'music'));break;

				case 'blogcount':$datatmp=ReplaceStr($datatmp,'[users:blogcount]',getusercount($row['S_Name'],'blog'));break;

				case 'dtcount':$datatmp=ReplaceStr($datatmp,'[users:dtcount]',getusercount($row['S_Name'],'dt'));break;

				case 'nichen':

					$nichen=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_RealName']);

					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],$nichen);break;

					break;

				case 'time':

					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],date(ReplaceStr($field_arr[3][$i],'f','i'),strtotime($row['S_CreateTime'])));

					break;	

				case 'logtime':

					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],date(ReplaceStr($field_arr[3][$i],'f','i'),strtotime($row['S_LogTime'])));

					break;				

				}

			}

	}

		unset($field_arr);

		return $datatmp;		

}



function datapic($para,$label,$row,$sorti){

	preg_match_all('/\[pic:\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 'id':$datatmp=ReplaceStr($datatmp,'[pic:id]',$row['S_ID']);break;

				case 'i':$datatmp=ReplaceStr($datatmp,'[pic:i]',$sorti);break;

				case 'link':$datatmp=ReplaceStr($datatmp,'[pic:link]',piclinkurl($row['S_ID'],$row['S_User']));break;

				case 'url':$datatmp=ReplaceStr($datatmp,'[pic:url]',$row['S_Url']);break;

				case 'uname':$datatmp=ReplaceStr($datatmp,'[pic:uname]',$row['S_User']);break;

				case 'unichen':$datatmp=ReplaceStr($datatmp,'[pic:unichen]',getuser('nichen',$row['S_User']));break;

				case 'ulink':$datatmp=ReplaceStr($datatmp,'[pic:ulink]',linkweburl(1,$row['S_User']));break;

				case 'upic':$datatmp=ReplaceStr($datatmp,'[pic:upic]',getuser('pic',$row['S_User']));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 datablog($para,$label,$row,$sorti){

	preg_match_all('/\[blog:\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 'id':$datatmp=ReplaceStr($datatmp,'[blog:id]',$row['S_ID']);break;

				case 'i':$datatmp=ReplaceStr($datatmp,'[blog:i]',$sorti);break;

				case 'uname':$datatmp=ReplaceStr($datatmp,'[blog:uname]',$row['S_User']);break;

				case 'unichen':$datatmp=ReplaceStr($datatmp,'[blog:unichen]',getuser('nichen',$row['S_User']));break;

				case 'ulink':$datatmp=ReplaceStr($datatmp,'[blog:ulink]',linkweburl(1,$row['S_User']));break;

				case 'upic':$datatmp=ReplaceStr($datatmp,'[blog:upic]',getuser('pic',$row['S_User']));break;

				case 'content':

					$content=getlen($field_arr[2][$i],$field_arr[3][$i],$row['S_Content']);

					$datatmp=ReplaceStr($datatmp,$field_arr[0][$i],facehtml($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;

					if($sort=="" or $sort=="time"){

						$sort="UNIX_TIMESTAMP(S_AddTime)";

						}elseif($sort=="id"){

							$sort="S_ID";

						}elseif($sort=="hits"){

							$sort="S_Hits";

						}elseif($sort=="rhits"){

							$sort="S_Rhits";

						}elseif($sort=="zhits"){

							$sort="S_Zhits";

						}elseif($sort=="yhits"){

							$sort="S_Yhits";

						}elseif($sort=="shits"){

							$sort="S_Favhits";

						}elseif($sort=="xhits"){

							$sort="S_Downhits";

						}elseif($sort=="stars"){

							$sort="S_Reco";

						}elseif($sort=="rand"){

							$sort='rand()';

						}elseif($sort="dhits"){

							$sort="S_Apex";

						}elseif($sort="play"){

							$sort="S_Playtime";

						}elseif($sort="kstime"){

							$sort="UNIX_TIMESTAMP(S_kstime)";

						}else{

							$sort="UNIX_TIMESTAMP(S_AddTime)";

						}			

				  	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)";

					 }elseif($topicid=='all'){

						 $sql.=" and S_Topic >0";

					 }

					 

				  	if($state=="true")  $sql.=" and S_Remark<>'' and S_IsEnd=1 ";

				  	if($stars!="" and $stars!="all") $sql.=" and  S_Reco in (".$stars.")";

                                        if($stars == 6) $sql.=" and  datediff(NOW(), s_kstime) >=0 and  datediff(NOW(), s_jstime) <=0";

				  	$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;

					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";

						}elseif($sort=="rand"){

							$sort='rand()';

						}elseif($sort="ding"){

							$sort="S_Apex";

						}else{

							$sort="UNIX_TIMESTAMP(S_AddTime)";

						}

												

				  	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";

							}	

						}

					//if($loop!="all" and $loop!="") $sql.="limit ".($loop)."";

					$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_users':

				//

					if(isset($start)=="" or $start==0) $start=1;

					if($sort=="" or $sort=="time"){

						$sort="UNIX_TIMESTAMP(S_CreateTime)";

						}elseif($sort=="id"){

							$sort="S_ID";

						}elseif($sort=="hits"){

							$sort="S_Hits";

						}elseif($sort=="dhits"){

							$sort="S_Dhits";

						}elseif($sort=="coin"){

							$sort="S_Coin";

						}else{

							$sort="UNIX_TIMESTAMP(S_CreateTime)";

							}

				  	if($classid!="all" and $classid!="" and $classid!="auto"){				

						  $sql.=" and S_Tid in ($classid) ";				

					  }

					$sql.=" and S_State<>1";	

					$sql.=" Order by ".$sort." ".$order." ";

					if($loop!="all" and $loop!="") $sql.="limit ".($start-1).",".($loop)."";

					//

					break;

					break;

				case 's_pic':

				//

					if($sort=="" or $sort=="time"){

						$sort="UNIX_TIMESTAMP(S_AddTime)";

						}elseif($sort=="id"){

							$sort="S_ID";

						}else{

							$sort="UNIX_TIMESTAMP(S_AddTime)";

						}	

					$sql.=" Order by ".$sort." ".$order." ";

					if($loop!="all" and $loop!="") $sql.="limit ".($loop)."";

					//

					break;

					break;

				case 's_blog':

				//

					if($sort=="" or $sort=="time"){

						$sort="UNIX_TIMESTAMP(S_AddTime)";

						}elseif($sort=="id"){

							$sort="S_ID";

						}else{

							$sort="UNIX_TIMESTAMP(S_AddTime)";

						}	

					$sql.=" Order by ".$sort." ".$order." ";

					if($loop!="all" and $loop!="") $sql.="limit ".($loop)."";

					//

					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['S_ID']=="")	return "对不起,找不到相关的数据信息!";

	if($row){

		if(IsNul($row['S_Template']) && file_exists(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template'])){

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template']);

			}

		else{

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."artlist.html");

			}	

		}else{

			$Mark_Text=@file_get_contents(_CHSHDJ_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('/{chshdjcms:article(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms: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(_CHSHDJ_ROOT_.S_Templateurl."vodtopic.html");

			$Table="s_video";

		}else{

			$Mark_Text=@file_get_contents(_CHSHDJ_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:hits]","<script src=".S_SitePath."js/hits.php?id=".$ids."&type=6></script>");

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:time]",$row['S_AddTime']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:stars]",$row['S_Reco']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:username]",$row['S_Keywords']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:ulink]",linkweburl(1,$row['S_Keywords']));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:unichen]",getuser('nichen',$row['S_Keywords']));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:pic]",picshow($row['S_Pic'],'3'));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:time]",$row['S_AddTime']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:fxgs]",$row['S_Fxgs']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:year]",$row['S_Year']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:yuyan]",$row['S_Language']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:area]",$row['S_Area']);

		$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('/{chshdjcms:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms: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=12></script>";//增加人气

		return $Mark_Text;		

	}else{

		return "专题数据加载出错";

		}

	}

//专题列表页面

function SpanTopicList(){

	global $db;

	$data_content="";

	$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."topic.html");

	$Mark_Text=topandbottom($Mark_Text);

	$pagenum=getpagenum($Mark_Text);

	preg_match_all('/{chshdjcms:topic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms: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){

		if(IsNul($row['S_Templay']) && file_exists(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Templay'])){

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Templay']);



		}else{

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."play.html");

		}	

		$Mark_Text=topandbottom($Mark_Text);

		$Mark_Text=Common_Mark($Mark_Text,$row['S_ClassID']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:player]',PlayFormSel($row['S_VData'],$row['S_Source'],$row['S_AddPath'],$row['S_ID']));

		$Mark_Text=ReplaceStr($Mark_Text,'[video:hits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&type=5></script>");//预处理动态人气

		$Mark_Text=datavideo($Mark_Text,$Mark_Text,$row,'1');

		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=3></script>";//增加人气

		$Mark_Text=ReplaceStr($Mark_Text,'[video:shits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=shits></script>");

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=xhits></script>");

		$Mark_Text=ReplaceStr($Mark_Text,'[video:rhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=rhits></script>");

		$Mark_Text=ReplaceStr($Mark_Text,'[video:zhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=zhits></script>");

		$Mark_Text=ReplaceStr($Mark_Text,'[video:yhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=yhits></script>");

		$Mark_Text=ReplaceStr($Mark_Text,'[video:dx]',$row['S_Dx']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:btime]',$row['S_Btime']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:yz]',$row['S_Yz']);

		//舞曲上下曲开始

		$rowu=$db->getrow("Select S_ID,S_Name,S_ClassID  from s_video where S_ID<$ids and S_IsEnd=0 order by S_ID desc");

		if($rowu){

		$Mark_Text=ReplaceStr($Mark_Text,'[video:sid]',$rowu['S_ID']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:sname]',$rowu['S_Name']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:slink]',LinkUrl('s_video',$rowu['S_ClassID'],1,$rowu['S_ID']));

		}else{

		$Mark_Text=ReplaceStr($Mark_Text,'[video:sid]','0');

		$Mark_Text=ReplaceStr($Mark_Text,'[video:sname]','没有了');

		$Mark_Text=ReplaceStr($Mark_Text,'[video:slink]','#');

		}

		$rowd=$db->getrow("Select S_ID,S_Name,S_ClassID  from s_video where S_ID>$ids and S_IsEnd=0 order by S_ID asc");

		if($rowd){

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xid]',$rowd['S_ID']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xname]',$rowd['S_Name']);

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xlink]',LinkUrl('s_video',$rowd['S_ClassID'],1,$rowd['S_ID']));

		}else{

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xid]','0');

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xname]','没有了');

		$Mark_Text=ReplaceStr($Mark_Text,'[video:xlink]','#');

		}

		return $Mark_Text;

	}else{

		return "对不起,找不到相关的数据信息!";

		}

	}

//舞曲下载页

function SpanDjDown($ids){

	global $db;

	$stars="";

	$sql="select * from s_video where s_ID=".$ids."";

	$row=$db->getRow($sql);

	if($row){

	$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."down.html");

	$Mark_Text=topandbottom($Mark_Text);

	$Mark_Text=Common_Mark($Mark_Text,$row["S_ClassID"]);

	$Mark_Text=datavideo($Mark_Text,$Mark_Text,$row,'1');

	$Mark_Text=ReplaceStr($Mark_Text,'[video:dx]',$row['S_Dx']);

	$Mark_Text=ReplaceStr($Mark_Text,'[video:btime]',$row['S_Btime']);

	$Mark_Text=ReplaceStr($Mark_Text,'[video:yz]',$row['S_Yz']);

	$Mark_Text=ReplaceStr($Mark_Text,'[video:shits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=shits></script>");

	$Mark_Text=ReplaceStr($Mark_Text,'[video:xhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=xhits></script>");

	$Mark_Text=ReplaceStr($Mark_Text,'[video:rhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=rhits></script>");

	$Mark_Text=ReplaceStr($Mark_Text,'[video:zhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=zhits></script>");

	$Mark_Text=ReplaceStr($Mark_Text,'[video:yhits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&ac=yhits></script>");

	$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:userlogin}',$userlogin);

		return $Mark_Text;

	}else{

		return "<br>对不起，您下载的数据不存在或已被管理员删除!</p>";

	}

}

//新闻内容页面

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(_CHSHDJ_ROOT_.S_Templateurl."artshow.html");

		$Mark_Text=topandbottom($Mark_Text);

		$Mark_Text=Common_Mark($Mark_Text,$row['S_ClassID']);

		$Mark_Text=ReplaceStr($Mark_Text,'[article:hits]',"<script src=".S_SitePath."js/hits.php?id=".$ids."&type=4></script>");//预处理动态人气

		$Mark_Text=dataart($Mark_Text,$Mark_Text,$row,'1');

		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=11></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['S_ID']=="")	return "对不起,找不到相关的数据信息!";

	if($row){

		if(IsNul($row['S_Template']) && file_exists(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template'])){

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template']);

			}

		else{

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."list.html");

			}	

		}else{

			$Mark_Text=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."list.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('/{chshdjcms:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms: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 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 getuser($Uid,$Name){

	global $db;

	$sql="select S_ID,S_Name,S_Logo,S_QQ,S_Tid,S_City,S_Sex,S_RealName,S_Type from s_users where S_Name='".$Name."'";

	$row=$db->getRow($sql);

	if($row){

		if($Uid=='pic'){

			return piclink('logo',$row['S_Logo'],'big');

		}elseif($Uid=='qq'){

			return $row['S_QQ'];

		}elseif($Uid=='uid'){

			return $row['S_ID'];

		}elseif($Uid=='city'){

			return $row['S_City'];

		}elseif($Uid=='nichen'){

			return $row['S_RealName'];

		}elseif($Uid=='tid'){

		    if($row['S_Tid']==1){

			return "<font color=red>音乐人</font>";

			}else{

			return "会员";

		        }

		}elseif($Uid=='sex'){

		    if($row['S_Sex']==1){

			return "男";

			}else{

			return "女";

		        }

		}

	}else{

			return "未知";	

	}		

}

//获取会员级别

function userleve($Did) {

	global $db;

	$sql="select S_Name from s_usersgroup where S_ID=".$Did."";

	$row=$db->getRow($sql);

	if($row){



		return $row['S_Name'];

	}else{

		return "未知";

	}

}

//获取分类名称		

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 playurl($Url,$Path){

                    global $db;

                   if  ($Path==0){

                                  return $Url;

	     }else{

	     $sql="Select *  from S_pathip where S_ID=".$Path."";

                    $row=$db->getrow($sql);

                              if($row){

                                       $Url=$row['S_AddPath'].$Url;

                                       return $Url;

	                }else{



                                       return $Url;

	                }

	     }

}

//获取会员粉丝数目

function getusercount($name='',$type){

	global $db;

	if($type=='fs'){

		$sql="select count(S_ID) as rc from s_friend  where S_nameb='".$name."'";

	}elseif($type=='hy'){

		$sql="select count(S_ID) as rc from s_friend  where S_namea='".$name."'";

	}elseif($type=='music'){

		$sql="select count(S_ID) as rc from s_video  where S_Direct='".$name."'";

	}elseif($type=='blog'){

		$sql="select count(S_ID) as rc from s_blog  where S_User='".$name."'";

	}elseif($type=='dt'){

		$sql="select count(S_ID) as rc from s_dt  where S_User='".$name."'";

		}

	$row=$db->getRow($sql);

	if($row){

		return $row['rc'];

	}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('/\{chshdjcms:(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."' class='kd'>".$i."</a>";

 	 	}

	}

	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."' class='kd'>".$i."</a>";

    			}

  			}

  			if($i<=$pagejs){ 

    			//$str.="....";

	    		$str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>";

   			}

   		}

  		else{

  			for($i=1;$i<=$pagenum;$i++){

    			$str.="<a href='?".$url."pages=".$i." ' class='kd'>".$i."</a>";

 		} 

 				if($i<=$pagejs){ 

      				//$str.="....";

	  				$str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>";

    			}

 		 }

	}

	 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('/\{chshdjcms:pagenum(.*?)\}/','{chshdjcms:pagenum}',$Mark_Text);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagedata}',$Arr[3]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagedown}',$Arr[9]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagenow}',$Arr[5]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagecout}',$Arr[6]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagelist}',$Arr[4]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagesize}',$Arr[11]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagefirst}',$Arr[7]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pageup}',$Arr[8]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagenum}',$Arr[0]);

		$Mark_Text=ReplaceStr($Mark_Text,'{chshdjcms:pagelast}',$Arr[10]);	

		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;

}

?>