<?php
//---------------------------用户自定义标签函数文件
/*
参数说明：
user_FieldFun：函数名
$mid：系统模型ID
$f：字段名
$isadd：值为1时是增加信息;值为0时是修改信息
$isq：值为0时是后台处理;值为1时是前台处理
$value：字段原内容
$cs：字段附加参数，字段处理函数处设置的参数内容
*/
function user_TogTitle($mid,$f,$isadd,$isq,$value,$cs){
        $value=$_POST['writer'].$_POST['befrom'];
        return $value;
}
///////////////////////功能函数////////////////////////////////////////////////////////////////
//格式化资源地址列表  没有影片名和地址分割的部分进行重组 自动生成影片分集名称


function returnbiaoqing($str){
                $str=str_replace('{憨笑}','<img src="/gbook/images/icons/01.gif">',$str);
                $str=str_replace('{色}','<img src="/gbook/images/icons/02.gif">',$str);
                $str=str_replace('{抓狂}','<img src="/gbook/images/icons/03.gif">',$str);
                $str=str_replace('{呲牙}','<img src="/gbook/images/icons/04.gif">',$str);
                $str=str_replace('{调皮}','<img src="/gbook/images/icons/05.gif">',$str);
                $str=str_replace('{亲亲}','<img src="/gbook/images/icons/06.gif">',$str);
                $str=str_replace('{害羞}','<img src="/gbook/images/icons/07.gif">',$str);
                $str=str_replace('{可爱}','<img src="/gbook/images/icons/08.gif">',$str);
                $str=str_replace('{酷}','<img src="/gbook/images/icons/09.gif">',$str);
                $str=str_replace('{疑问}','<img src="/gbook/images/icons/10.gif">',$str);
                $str=str_replace('{发呆}','<img src="/gbook/images/icons/11.gif">',$str);
                $str=str_replace('{闭嘴}','<img src="/gbook/images/icons/12.gif">',$str);
                $str=str_replace('{晕}','<img src="/gbook/images/icons/13.gif">',$str);
                return $str;

}


function returninfotags($r){
	global $public_r;
	$tags=$r[classtype];
	$rr=explode('|',$tags);
	$html='';
	for($i=0;$i<count($rr);$i++){
		$type=$rr[$i];
		if($type){
				$tpinyin=ReturnPinyinFun($type);
				$url=$public_r[newsurl].'list/'.$tpinyin.'-'.$r[classid].'-0-0-0-0/';
				$html.='<a href="'.$url.'" target="_blank">'.$type.'</a>  ';
		}
	
	
	}
	return $html;
}

function indexgetclasstype($classid){
	global $public_r;
	$publicname='add_classtype_'.$classid;
	$str=$public_r[$publicname];
	$r=explode("\r\n",$str);
	$html='';
	for($i=0;$i<16;$i++){
	$tpinyin=ReturnPinyinFun($r[$i]);
	$title=$r[$i];
	$url=$public_r[newsurl].'list/'.$tpinyin.'-'.$classid.'-0-0-0-0/';
	$html.='<span><a href="'.$url.'" target="_blank">'.$title.'</a></span>';
	}
	return $html;
	//return $public_r[add_classtype_1];
}
function indexgetclassarea($classid){
	global $public_r;
	$str=$public_r[add_moviediqu];
	$r=explode("\r\n",$str);
	$html='';
	for($i=0;$i<8;$i++){
	$diqui=$i+1;
	$title=$r[$i];
	$url=$public_r[newsurl].'list/0-'.$classid.'-'.$diqui.'-0-0-0/';
	$html.='<span><a href="'.$url.'" target="_blank">'.$title.'</a></span>';
	}
	return $html;
}
function indexgetclasstime($classid){
	global $public_r;
    $y=date('Y',time());
	for($i=0;$i<4;$i++){
			$thisy=$y-$i;
	$url=$public_r[newsurl].'list/0-'.$classid.'-0-0-'.$thisy.'-0/';
	if($i!=3){
		$name=$thisy;
	}
	else{
		$name='更早';
		$url=$public_r[newsurl].'list/0-'.$classid.'-0-0-19001969-0/';
		
	}
	$html.='<span><a href="'.$url.'" target="_blank">'.$name.'</a></span>';
	}
	return $html;
	
}






function returnmoviestr($str){
	global $public_r,$movie_config;
			//缺省无影片分集名的命名格式   0为纯数字  1为第几集
			$nametype=0;
			include("movie_config.php"); 
			$str=str_replace("\r\n",$r_exp,$str);
			$r=explode($r_exp,$str);
			$num=count($r);
			$returnstr='';
			for($i=0;$i<$num;$i++){
					$namestr=$i+1;
					if($nametype==0){  $namestr=$namestr; }
					elseif($nametype==1){  $namestr='第'.$namestr.'集'; }
					$thestr=$r[$i];
					$rr=explode($f_exp,$r[$i]);
					$r1=$rr[1]?$rr[1]:$rr[0];
					$r0=$rr[1]?$rr[0]:$namestr;
					if($r0&&$r1){
					$returnstr.=$r0.$f_exp.$r1.$r_exp;
					}
					
			}
			$returnstr=substr($returnstr,0,strlen($returnstr)-strlen($r_exp));	
		
	return $returnstr;	
}
function return_movielist_all($add){
	global $public_r,$movie_config;
	include(ECMS_PATH.'e/class/movie_config.php');
	$path=$movie_config[playhtmldir].'/'.str_replace('/index','',$add[filename]);
	$str=$add[movieshow];
	$tr=explode($d_exp,$str);
	$htmlstring='';
	for($i=0;$i<count($tr);$i++){
				$mstr=$tr[$i];
				$tt=explode($t_exp,$mstr);
				$movietype=$tt[0];
				$moviestr=$tt[1];
				$rr=explode($r_exp,$moviestr);
				$temp=$movie_config[movielisttemp];
				$tempr=explode('[!--slum.exp--]',$temp);
				$temp1=$tempr[0];
				$temp2=$tempr[2];
				$tempd=$tempr[1];
				$ar='';
				for($j=0;$j<count($rr);$j++){
						$ii=$i+1;
						$jj=$j+1;
						$thismovie=explode($f_exp,$rr[$j]);
						$moviename=$thismovie[0];
						$string=$tempd;
						$url=$public_r[newsurl].$path.'/'.$add[id].'-'.$ii.'-'.$jj.$movie_config[playhtmltype][1];
						$string=str_replace('[!--name--]',$moviename,$string);
						$string=str_replace('[!--url--]',$url,$string);
						$string=str_replace('','',$string);
						$ar.=$string;
						
						
				}
				
						$htmlstring.=$temp1.$ar.$temp2;				
						$htmlstring=str_replace('[!--movietypecn--]',return_thismovietypecn($movietype,$movie_config),$htmlstring);
						$htmlstring=str_replace('[!--movietypestr--]',return_thismovietypestr($movietype,$movie_config),$htmlstring);
						$htmlstring=str_replace('[!--movietypeclass--]',return_thismovietypeclass($movietype,$movie_config),$htmlstring);
						$htmlstring=str_replace('[!--typeid--]',$i,$htmlstring);				
	
	
	}
	return $htmlstring;
	
}



function return_thismovielist($add,$movie_config,$movieid,$typeid,$path){
	global $empire,$class_r,$public_r,$dbtbpre;
	$html=$movie_config[thismovielisthtml];
	if($add){
			$mt=$add[0];
			$mr=$add[1];
			$rr=explode($movie_config[r_exp],$mr);
			$countrr=count($rr);
			$returnstr='';
			$thishtml='';
			for($playi=0;$playi<$countrr;$playi++){
			//处理播放标签	
			$thisrr=explode($movie_config[f_exp],$rr[$playi]);
			$moviename=$thisrr[0];
			$moviedata=$thisrr[1];
			$typeii=$typeid+1;
			$playii=$playi+1;
			$movieurl=$public_r[newsurl].$path.'/'.$movieid.'-'.$typeii.'-'.$playii.$movie_config[playhtmltype][1];
			$thishtml=str_replace('[!--name--]',$moviename,$html);
			$thishtml=str_replace('[!--url--]',$movieurl,$thishtml);
			$returnstr.=$thishtml;
						
			}
			
			return $returnstr;
	}
	else{
		return;
	}
}


function return_thismovietypecn($add,$movie_config){
	if(!$add){ return; }
	$typer=explode(',',$movie_config[movietype]);
	$typecnr=explode(',',$movie_config[movietypecn]);
	for($i=0;$i<count($typer);$i++){
			$thistype=$typer[$i];
			if($thistype==$add){
					return $typecnr[$i];			
			}
	}
	
}


function return_thismovietypeclass($add,$movie_config){
	$add=str_replace('bdhd','baidu',$add);
	$addclass='p_'.$add;
	return $addclass;
}

function return_thismovietypestr($add,$movie_config){
	if(!$add){ return; }
	if($add=='bdhd'){
	$str='(  <a href="'.$movie_config[bdhddownurl].'" target="_blank">'.$movie_config[bdhdstr].'</a> )';
	}
	elseif($add=='qvod'){
	$str='(  <a href="'.$movie_config[qvoddownurl].'" target="_blank">'.$movie_config[qvodstr].'</a> )';	
	}
	else{
		$addtype=$add.'str';
		$showstr=$movie_config[$addtype];
		if(!$showstr) $showstr='无需安装任何插件，即可快速播放';
		$str='（  '.$showstr.'  ）';
	}
	
	return $str;
}


//列表模板之列表式分页
function user_ShowListPage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search=""){
 global $fun_r,$public_r;
 if($num<=$line)
 {
  $pager['showpage']='';
  return $pager;
 }
 $firstpage='共'.$num.'条数据 页次:'.$page.'/'.$totalpage.'页';
 $endpage='<input type="input" name="page" size="4" class="pagego"  /><input type="button" value="跳转" onclick="getPageGoUrl('.$totalpage.',\'page\',2,\'index.html\')" class="pagebtn" />';
 $page_line=$public_r['listpagelistnum'];
 $snum=2;
 //首页
 if($page<>1)
 {
  $toppage='<a class="first" href="'.$dolink.'index'.$type.'">首页</a>';
 }
 else
 {
  $toppage='<span class="first disabled" >首页</span>';
 }

	//上一页
	if($page<>1)
	{
		
		$pagepr=$page-1;
		if($pagepr==1)
		{
			$prido="index".$type;

		}
		else
		{
			$prido="index_".$pagepr.$type;
		}
		$prepage='<a class="prev" href="'.$dolink.$prido.'">上一页</a>';
		
	}
	else
				$prepage='<span class="prev disabled">上一页</span>';


 //下一页
 if($page!=$totalpage)
 {
  $pagenex=$page+1;
  $nextpage='<a class="next" href="'.$dolink.'index_'.$pagenex.$type.'">下一页</a>';


  $lastpage='<a class="last" href="'.$dolink.'index_'.$totalpage.$type.'">尾页</a>';


 }
        else
        {
  $pagenex=$page+1;
  $nextpage='<span class="next disabled">下一页</span>';
  $lastpage='<span class="last disabled">尾页</span>';


        }
         //中间页
 $starti=$page-$snum<1?1:$page-$snum;
 $no=0;
 for($i=$starti;$i<=$totalpage&&$no<$page_line;$i++)
 {
        $no++;
  if($page==$i)
  {
   $is_1='<span class="current">';
   $is_2='</span>';
  }
  elseif($i==1)
  {
   $is_1='<a href="'.$dolink.'index'.$type.'">';
   $is_2="</a>";
  }
  else
  {
   $is_1='<a href="'.$dolink.'index_'.$i.$type.'">';
   $is_2="</a>";
  }
  $returnstr.=$is_1.$i.$is_2;
 }
 $returnstr=$toppage.$prepage.$returnstr.$nextpage.$lastpage.$endpage;
 $pager['showpage']=$returnstr;
 return $pager;
}


function user_dtShowListPage($num,$page,$dolink,$type,$totalpage,$line,$ok,$search=""){
 global $fun_r,$public_r;
 $type='.html';
 $dolink='';
 if($num<=$line)
 {
  $pager['showpage']='';
  return ;
 }
 $totalpage=ceil($num/$line);//取得总页数
 $firstpage='共'.$num.'条数据 页次:'.$page.'/'.$totalpage.'页';
 $endpage='<input type="input" name="page" size="4"  class="pagego" /><input type="button"  value="跳转" onclick="getPageGoUrl('.$totalpage.',\'page\',2,\'index.html\')" class="pagebtn" />';
 $page_line=$public_r['listpagelistnum'];
 $snum=2;
 
 //首页
 if($page<>1)
 {
  $toppage='<a class="first" href="'.$dolink.'index'.$type.'">首页</a>';
 }
 else
 {
  $toppage='<span class="first disabled" >首页</span>';
 }


	//上一页
	if($page<>1)
	{
	
		$pagepr=$page-1;
		if($pagepr==1)
		{
			$prido="index".$type;

		}
		else
		{
			$prido="index_".$pagepr.$type;
		}
		$prepage='<a class="prev" href="'.$dolink.$prido.'">上一页</a>';
		
	}
	else
				$prepage='<span class="prev disabled">上一页</span>';


 //下一页
 if($page!=$totalpage)
 {
  $pagenex=$page+1;
  $nextpage='<a class="next" href="'.$dolink.'index_'.$pagenex.$type.'">下一页</a>';


  $lastpage='<a class="last" href="'.$dolink.'index_'.$totalpage.$type.'">尾页</a>';


 }
        else
        {
  $pagenex=$page+1;
  $nextpage='<span class="next disabled">下一页</span>';
  $lastpage='<span class="last disabled">尾页</span>';


        }
         //中间页
 $starti=$page-$snum<1?1:$page-$snum;
 $no=0;
 for($i=$starti;$i<=$totalpage&&$no<$page_line;$i++)
 {
        $no++;
  if($page==$i)
  {
   $is_1='<span class="current">';
   $is_2='</span>';
  }
  elseif($i==1)
  {
   $is_1='<a href="'.$dolink.'index'.$type.'">';
   $is_2="</a>";
  }
  else
  {
   $is_1='<a href="'.$dolink.'index_'.$i.$type.'">';
   $is_2="</a>";
  }
  $returnstr.=$is_1.$i.$is_2;
 }
 $returnstr=$toppage.$prepage.$returnstr.$nextpage.$lastpage.$endpage;
 $returnstr=str_replace('index',$search,$returnstr);
 $pager['showpage']=$returnstr;
 return $returnstr;
}


//自定义分页
function diy_listpage($num,$line,$page,$search=''){
	global $fun_r;
	if($num<=$line)
	{
		return '';
	}
	$page_line=6;
	$search=htmlspecialchars($search,ENT_QUOTES);
	$url=$_SERVER['PHP_SELF'].'?page';
	$snum=2;//最小页数
	$totalpage=ceil($num/$line);//取得总页数
	$firststr='<a title="'.$fun_r['trecord'].'">&nbsp;共<b>'.$num.'</b>条信息 </a>&nbsp;&nbsp;';
	//上一页
	if($page<>0)
	{
		$toppage='<a href="'.$url.'=0'.$search.'">TOP</a>&nbsp;';
		$pagepr=$page-1;
		$prepage='<a href="'.$url.'='.$pagepr.$search.'">PREV</a>';
	}
	//下一页
	if($page!=$totalpage-1)
	{
		$pagenex=$page+1;
		$nextpage='&nbsp;<a href="'.$url.'='.$pagenex.$search.'">NEXT</a>';
		$lastpage='&nbsp;<a href="'.$url.'='.($totalpage-1).$search.'">LAST</a>';
	}
	$starti=$page-$snum<0?0:$page-$snum;
	$no=0;
	for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
	{
		$no++;
		if($page==$i)
		{
			$is_1="<b>";
			$is_2="</b>";
		}
		else
		{
			$is_1='<a href="'.$url.'='.$i.$search.'">';
			$is_2="</a>";
		}
		$pagenum=$i+1;
		$returnstr.="&nbsp;".$is_1.$pagenum.$is_2;
	}
	$returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
	return $returnstr;
}

//搜索 动态分页
function searchlistpage($num,$line,$page_line,$start,$page,$search,$isgbook=''){
	global $fun_r;
	if($num<=$line)
	{
		return '';
	}
	$search=htmlspecialchars($search,ENT_QUOTES);
	$url=$_SERVER['PHP_SELF'].'?page';
	$snum=2;//最小页数
	$totalpage=ceil($num/$line);//取得总页数
	$pagea=$page+1;
	
 $totalpage=ceil($num/$line);//取得总页数
 $firstpage='<span>共'.$num.'条数据 页次:'.$pagea.'/'.$totalpage.'页</span>';
 $endpage='<span></span>';
 $gbookstart='<label>共<strong>'.$num.'</strong>条留言，<strong>'.$line.'</strong>条/页';
	//上一页
	if($page<>0)
	{
		$toppage='<a href="'.$url.'=0'.$search.'" class="first">首页</a>';
		$pagepr=$page-1;
		$prepage='<a href="'.$url.'='.$pagepr.$search.'" class="prev">上一页</a>';
	}
	//下一页
	if($page!=$totalpage-1)
	{
		$pagenex=$page+1;
		$nextpage='<a href="'.$url.'='.$pagenex.$search.'" class="next">下一页</a>';
		$lastpage='<a href="'.$url.'='.($totalpage-1).$search.'" class="last">尾页</a>';
	}
	$starti=$page-$snum<0?0:$page-$snum;
	$no=0;
	for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
	{
		$no++;
		if($page==$i)
		{
			$is_1='<span class="current">';
			$is_2="</span>";
		}
		else
		{
			$is_1='<a href="'.$url.'='.$i.$search.'">';
			$is_2="</a>";
		}
		$pagenum=$i+1;
		$returnstr.=$is_1.$pagenum.$is_2;
	}
	if($isgbook==1){
	$returnstr=$gbookstart.$toppage.$prepage.$returnstr.$nextpage.$lastpage;
	}
	else{
	$returnstr=$toppage.$prepage.$returnstr.$nextpage.$lastpage;
	}
	return $returnstr;
}


function dtlistpage($num,$line,$page,$file){
	global $fun_r;
	$search=htmlspecialchars($search,ENT_QUOTES);
	$url=$_SERVER['PHP_SELF'].'?page=';
	$snum=2;//最小页数
	$page_line=6;
	$totalpage=ceil($num/$line);//取得总页数
	//$firststr='<a title="'.$fun_r['trecord'].'">&nbsp;<b>'.$num.'</b> </a>&nbsp;&nbsp;';
	$thispage=$page+1;
	$firststr='共<strong>'.$num.'</strong>留言，当前第<strong>'.$thispage.'</strong>页，共<strong>'.$totalpage.'</strong>页';
	//上一页
	if($page<>0)
	{
		$toppage='<span><a href="'.url.'=0'.$file.'" class="first" title="首页"><em>首页</em></a>';
		$pagepr=$page-1;
	    $prepage='<a href="'.$url.$pagepr.$file.'" class="prev" title="上一页"><em>上一页</em></a>';
	}
		else
		{   
		        $toppage='<span><a class="first" title="首页"><em>首页</em></a>';
		        $prepage='<a class="prev" title="上一页"><em>上一页</em></a>';
		}
	//下一页
	if($page!=$totalpage-1)
	{
		$pagenex=$page+1;
		$nextpage='<a href="'.$url.$pagenex.$file.'" class="next" title="下一页"><em>下一页</em></a>';
		$lastpage='<a href="'.$url.($totalpage-1).$file.'" class="last" title="尾页"><em>尾页</em></a></span>';
	}
	else
	{   
		$nextpage='<a class="next" title="下一页"><em>下一页</em></a>';
		$lastpage='<a class="last" title="尾页"><em>尾页</em></a></span>';
	}
	$starti=$page-$snum<0?0:$page-$snum;
	$no=0;
	for($i=$starti;$i<$totalpage&&$no<$page_line;$i++)
	{
		$no++;
		if($page==$i)
		{
			$is_1='<span>[';
			$is_2=']</span>';
		}
		else if ($i==0)
		{
			$is_1='<a href="'.$url.$file.'">[';
			$is_2="]</a>";			
		}
		else
		{
			$is_1='<a href="'.$url.$i.$file.'">[';
			$is_2="]</a>";
		}
		$pagenum=$i+1;
		$returnstr.="&nbsp;".$is_1.$pagenum.$is_2;
	}
	$returnstr=$firststr.$toppage.$prepage.$returnstr.$nextpage.$lastpage;

	return $returnstr;
}



//  @slum  
/////////////////////////////////////////信息增加//////////////////////////////////////////////////////

function delimgbq($mid,$f,$isadd,$isq,$value,$cs){
$img=$_POST[titlepic];
$img=str_replace('<img src=','',$img);
$img=str_replace('/>','',$img);
$img=str_replace(' />','',$img);
$img=str_replace('">','',$img);
$img=str_replace('>','',$img);
$img=str_replace('\"','',$img);
$img=str_replace('"','',$img);
$img=str_replace("'",'',$img);
$img=str_replace("\\",'',$img);
$img=stripslashes($img);
return $img;
}


function urlkey($mid,$f,$isadd,$isq,$value,$cs){
	$add=$_POST;
	$urlkey=$add[urlkey];
	return $urlkey;
}
function addmovie($mid,$f,$isadd,$isq,$value,$cs){
	$r=array();
	$k_exp='|&$%$&|';
	$add=$_POST;
	$movieshow=$add[movieshow]?$add[movieshow]:'';
	$mt=$add[movietype];
	$mr=$add[moviefrom];
	if(!$movieshow&&$mr){
			include(ECMS_PATH.'e/class/movie_config.php');
			$mtnum=count($mt);
			$mrnum=count($mr);
			
		   $str='';
			for($i=0;$i<$mtnum;$i++){
				
				if($mr[$i]&&$mt[$i]){
					$mr[$i]=returnmoviestr($mr[$i]);   //如果没有分集名称返回分集名称
					if($mr[$i]){
							$str.=$mt[$i].$t_exp.$mr[$i].$d_exp;
					}
				}
			}
			$str=substr($str,0,strlen($str)-strlen($d_exp));
			$str=str_replace("\r\n",$r_exp,$str);
			$movieshow=$str;
	
	
	}
	return $movieshow;
	
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

//增加信息接口

function AddNewsMovie($add,$userid,$username){
	global $empire,$class_r,$class_zr,$bclassid,$public_r,$dbtbpre,$emod_r;

	$editor=1;
	$add[classid]=(int)$add[classid];
	$userid=(int)$userid;
	if(!$add[title]||!$add[classid])
	{
		printerror("EmptyTitle","history.go(-1)");
	}
	//操作权限
	$doselfinfo=CheckLevel($userid,$username,$add[classid],"news");
	if(!$doselfinfo['doaddinfo'])//增加权限
	{
		printerror("NotAddInfoLevel","history.go(-1)");
	}
	$ccr=$empire->fetch1("select classid,modid,listdt,haddlist,sametitle,addreinfo,wburl,repreinfo from {$dbtbpre}enewsclass where classid='$add[classid]' and islast=1 limit 1");
	if(!$ccr['classid']||$ccr['wburl'])
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	if($ccr['sametitle'])//验证标题重复
	{
		if(ReturnCheckRetitle($add))
		{
			printerror("ReInfoTitle","history.go(-1)");
	    }
    }
	$add=DoPostInfoVar($add);//返回变量
	$ret_r=ReturnAddF($add,$class_r[$add[classid]][modid],$userid,$username,0,0,1);//返回自定义字段
	$newspath=FormatPath($add[classid],$add[newspath],1);//查看目录是否存在，不存在则建立
	//审核权限
	if(!$doselfinfo['docheckinfo'])
	{
		$add['checked']=$class_r[$add[classid]][checked];
	}
	//必须审核
	if($doselfinfo['domustcheck'])
	{
		$add['checked']=0;
	}
	//推荐权限
	if(!$doselfinfo['dogoodinfo'])
	{
		$add['isgood']=0;
		$add['firsttitle']=0;
		$add['istop']=0;
	}
	//签发
	$isqf=0;
	if($class_r[$add[classid]][wfid])
	{
		$add[checked]=0;
		$isqf=1;
	}
	$newstime=empty($add['newstime'])?time():to_time($add['newstime']);
	$truetime=time();
	$lastdotime=$truetime;
	//是否生成
	$havehtml=0;
	if($add['checked']==1&&$ccr['addreinfo'])
	{
		$havehtml=1;
	}
	//返回关键字组合
	if($add['info_diyotherlink'])
	{
		$keyid=DoPostDiyOtherlinkID($add['info_keyid']);
	}
	else
	{
		$keyid=GetKeyid($add[keyboard],$add[classid],0,$class_r[$add[classid]][link_num]);
	}
	
$urlkey=$add[urlkey];
$selectquery="select id,urlkey,classid,stb,filename from {$dbtbpre}ecms_movie where urlkey='$urlkey' order by id desc limit 1";
$selr=$empire->fetch1($selectquery);
$updatecid=$selr[classid];
$updateid=$selr[id];
$upstb=$selr[stb];
if($updateid){
		$upmovieshow=$add[movieshow];
		$stbr=$empire->fetch1("select movieshow from {$dbtbpre}ecms_movie_data_".$upstb." where id='$updateid' limit 1");
		$oldmovieshowcheck=md5($stbr[movieshow]);
		$newmovieshowcheck=md5($upmovieshow);
			if($oldmovieshowcheck!=$newmovieshowcheck){  //验证数据是否一致
				$newstime=time();
				$add[id]=$updateid;
				$add[classid]=$selr[classid];
				$add[filename]=$selr[filename];
				$playurl=getplayurl($add);					
				$upsql1="update {$dbtbpre}ecms_movie set newstime='$newstime',type='$add[type]',typeset='$add[typeset]',lastdotime='$newstime',havehtml='0',playurl='$playurl',introduction='$add[introduction]' where id='$updateid'";
				$upsql2="update {$dbtbpre}ecms_movie_data_".$upstb." set movieshow='$upmovieshow' where id='$updateid'";
				$upsql3="update {$dbtbpre}ecms_movie_index set newstime='$newstime',lastdotime='$newstime',havehtml='0' where id='$updateid'";
				$upnews=$empire->query($upsql1);
				$upnewsstb=$empire->query($upsql2);
				$upnewsindex=$empire->query($upsql3);
					if($upnews&&$upnewsstb&&$upnewsindex){

					    	//增加信息是否生成文件
					    	if($ccr['addreinfo']&&$add['checked'])
							{
							GetHtml($updatecid,$updateid,'',0);
							}
							addremindsend($add[classid],$add[id]);//添加订阅更新发送队列
							printerror("AddNewsSuccess","AddNews.php?enews=AddNews&ecmsnfrom=$add[ecmsnfrom]&bclassid=$add[bclassid]&classid=$add[classid]");
					}
					else
					{
					printerror("DbError","");
					}


			}       //验证数据是否一致
			else{   //如果数据一样 跳过
			printerror("AddNewsSuccess","AddNews.php?enews=AddNews&ecmsnfrom=$add[ecmsnfrom]&bclassid=$add[bclassid]&classid=$add[classid]");
			}

}
else{		
	
	
	
	//附加链接参数
	$addecmscheck=empty($add['checked'])?'&ecmscheck=1':'';
	//索引表
	$sql=$empire->query("insert into {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]."_index(classid,checked,newstime,truetime,lastdotime,havehtml) values('$add[classid]','$add[checked]','$newstime','$truetime','$lastdotime','$havehtml');");
	$id=$empire->lastid();
	$pubid=ReturnInfoPubid($add['classid'],$id);
	$infotbr=ReturnInfoTbname($class_r[$add[classid]][tbname],$add['checked'],$ret_r['tb']);
	//主表
	$infosql=$empire->query("insert into ".$infotbr['tbname']."(id,classid,ttid,onclick,plnum,totaldown,newspath,filename,userid,username,firsttitle,isgood,ispic,istop,isqf,ismember,isurl,truetime,lastdotime,havehtml,groupid,userfen,titlefont,titleurl,stb,fstb,restb,keyboard".$ret_r['fields'].") values('$id','$add[classid]','$add[ttid]','$add[onclick]',0,'$add[totaldown]','$newspath','$filename','$userid','".addslashes($username)."','$add[firsttitle]','$add[isgood]','$add[ispic]','$add[istop]','$isqf',0,'$add[isurl]','$truetime','$lastdotime','$havehtml','$add[groupid]','$add[userfen]','".addslashes($add[my_titlefont])."','".addslashes($add[titleurl])."','$ret_r[tb]','$public_r[filedeftb]','$public_r[pldeftb]','".addslashes($add[keyboard])."'".$ret_r['values'].");");
	//副表
	$finfosql=$empire->query("insert into ".$infotbr['datatbname']."(id,classid,keyid,dokey,newstempid,closepl,haveaddfen,infotags".$ret_r['datafields'].") values('$id','$add[classid]','$keyid','$add[dokey]','$add[newstempid]','$add[closepl]',0,'".addslashes($add[infotags])."'".$ret_r['datavalues'].");");
	//更新栏目信息数
	AddClassInfos($add['classid'],'+1','+1',$add['checked']);
	//更新新信息数
	DoUpdateAddDataNum('info',$class_r[$add['classid']]['tid'],1);
	//签发
	if($isqf==1)
	{
		InfoInsertToWorkflow($id,$add[classid],$class_r[$add[classid]][wfid],$userid,$username);
	}
	//更新附件表
	UpdateTheFile($id,$add['filepass'],$add['classid'],$public_r['filedeftb']);
	//取第一张图作为标题图片
	if($add['getfirsttitlepic']&&empty($add['titlepic']))
	{
		$firsttitlepic=GetFpicToTpic($add['classid'],$id,$add['getfirsttitlepic'],$add['getfirsttitlespic'],$add['getfirsttitlespicw'],$add['getfirsttitlespich'],$public_r['filedeftb']);
		if($firsttitlepic)
		{
			$addtitlepic=",titlepic='".addslashes($firsttitlepic)."',ispic=1";
		}
	}
	//文件命名
	if($add['filename'])
	{
		$filename=$add['filename'];
	}
	else
	{
		$filename=ReturnInfoFilename($add[classid],$id,'',$add[tpinyin]);
	}
	//信息地址
	$updateinfourl='';
	if(!$add['isurl'])
	{
		$infourl=GotoGetTitleUrl($add['classid'],$id,$newspath,$filename,$add['groupid'],$add['isurl'],$add['titleurl']);
		$updateinfourl=",titleurl='$infourl'";
	}
	
	/*slum add*/
	$add[filename]=$filename;
	$add[id]=$id;
	$playurl=getplayurl($add);
	$usql=$empire->query("update ".$infotbr['tbname']." set filename='$filename'".$updateinfourl.$addtitlepic.",playurl='$playurl' where id='$id'");
	//slum add end
	//替换图片下一页
	if($add['repimgnexturl'])
	{
		UpdateImgNexturl($add[classid],$id,$add['checked']);
	}
	//投票
	AddInfoVote($add['classid'],$id,$add);
	//加入专题
	InsertZtInfo($add['ztids'],$add['zcids'],$add['oldztids'],$add['oldzcids'],$add['classid'],$id,$newstime);
	//TAGS
	if($add[infotags]&&$add[infotags]<>$add[oldinfotags])
	{
		eInsertTags($add[infotags],$add['classid'],$id,$newstime);
	}
	//增加信息是否生成文件
	if($ccr['addreinfo']&&$add['checked'])
	{
		GetHtml($add['classid'],$id,'',0);
	}
	//生成上一篇
	if($ccr['repreinfo']&&$add['checked'])
	{
		$prer=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id<$id and classid='$add[classid]' order by id desc limit 1");
		GetHtml($add['classid'],$prer['id'],$prer,1);
	}
	//生成栏目
	if($ccr['haddlist']&&$add['checked'])
	{
		hAddListHtml($add['classid'],$ccr['modid'],$ccr['haddlist'],$ccr['listdt']);//生成信息列表
		if($add['ttid'])//生成标题分类列表
		{
			ListHtml($add['ttid'],'',5);
		}
	}
	//同时发布
	$copyclassid=$add[copyclassid];
	$cpcount=count($copyclassid);
	if($cpcount)
	{
		$copyids=AddInfoToCopyInfo($add[classid],$id,$copyclassid,$userid,$username,$doselfinfo);
		if($copyids)
		{
			UpdateInfoCopyids($add['classid'],$id,$copyids);
		}
	}
	if($sql)
	{
		//返回地址
		if($add['ecmsfrom']&&(stristr($add['ecmsfrom'],'ListNews.php')||stristr($add['ecmsfrom'],'ListAllInfo.php')))
		{
			$ecmsfrom=$add['ecmsfrom'];
		}
		else
		{
			$ecmsfrom=$add['ecmsnfrom']==1?"ListNews.php?bclassid=$add[bclassid]&classid=$add[classid]":"ListAllInfo.php?tbname=".$class_r[$add[classid]][tbname];
		}
		$GLOBALS['ecmsadderrorurl']=$ecmsfrom.$addecmscheck;
		insert_dolog("classid=$add[classid]<br>id=".$id."<br>title=".$add[title],$pubid);//操作日志
		printerror("AddNewsSuccess","AddNews.php?enews=AddNews&ecmsnfrom=$add[ecmsnfrom]&bclassid=$add[bclassid]&classid=$add[classid]".$addecmscheck);
	}
	else
	{
		printerror("DbError","");
	}
	}
}


//生成信息


function makedir($npath){

	$path=ECMS_PATH;
	$returnpath="";
	$r=explode("/",$npath);
	$count=count($r);
	for($i=0;$i<$count;$i++){
		if($i>0)
		{
			$returnpath.="/".$r[$i];
		}
		else
		{
			$returnpath.=$r[$i];
		}
		$createpath=$path.$returnpath;
		$mk=DoMkdir($createpath);
		if(empty($mk))
		{
			printerror2("建立目录失败","");
		}
	}
	return $returnpath;
}

function makelistdir($npath){

	$returnpath="";
	$r=explode("/",$npath);
	$count=count($r);
	for($i=0;$i<$count;$i++){
		if($i>0)
		{
			$returnpath.="/".$r[$i];
		}
		else
		{
			$returnpath.=$r[$i];
		}
		$createpath=$returnpath;
		$mk=DoMkdir($createpath);
		if(empty($mk))
		{
			printerror2("建立目录失败","");
		}
	}
	
}

//生成信息页面 type=0 播放资源js  1分页 2 信息页
function makehtml($add,$type=0){
	global $public_r,$class_r,$class_zr,$fun_r,$empire,$dbtbpre,$emod_r,$class_tr,$level_r,$etable_r;
	$mid=$class_r[$add[classid]]['modid'];
	$tbname=$class_r[$add[classid]][tbname];
include('movie_config.php'); 
if(!$movie_config[isfenhtml]){ return TRUE; }
$playhtmldir=$movie_config[playhtmldir];
$path=$playhtmldir.'/'.str_replace('/index','',$add[filename]);
				makedir($path);	
				$GLOBALS['navclassid']=$add[classid];
				$GLOBALS['navinfor']=$add;
				$GLOBALS['movieconfig']=$movie_config;
				
				$newstemp_r=GetNewsTemp($movie_config[playtemp][$type]);
				$newstemptext=$newstemp_r[temptext];
				$formatdate=$newstemp_r[showdate];

				
				
	//页面
	$pagetitle=htmlspecialchars($add[title]);
	$url=ReturnClassLink($add[classid]);//导航
	$newstemptext=Info_ReplaceSvars($newstemptext,$url,$add[classid],$pagetitle,$add[keyboard],$pagetitle);				
				
	//变量
	$tempf=$emod_r[$mid]['tempf'];
	if($pf&&strstr($add[$pf],$expage))
	{
		$tempf=str_replace(','.$pf.',',',',$tempf);
	}
	$fr=explode(',',$tempf);
	$fcount=count($fr)-1;
	//变量替换
	$newstempstr=$newstemptext;//模板
	for($i=1;$i<$fcount;$i++)
	{
		$f=$fr[$i];
		$value=$add[$f];
		if($f=='downpath')//下载地址
		{
			if(strstr($newstemptext,'[!--downpath--]'))
			{
				$value=ReturnDownSoftHtml($add);
			}
		}
		elseif($f=='onlinepath')//观看地址
		{
			if(strstr($newstemptext,'[!--onlinepath--]'))
			{
				$value=ReturnOnlinepathHtml($add);
			}
		}
		elseif($f=='morepic')//图片集
		{
			if(strstr($newstemptext,'[!--morepic--]'))
			{
				$value=ReturnMorepicpathHtml($add);
			}
		}
		elseif($f=='newstime')//时间
		{
			if(strstr($newstemptext,'[!--newstime--]'))
			{
				$value=date($formatdate,$value);
			}
		}
		elseif($f=='befrom')//信息来源
		{
			if($docheckrep[1]&&strstr($newstemptext,'[!--befrom--]'))
			{
				$value=ReplaceBefrom($value);
			}
		}
		elseif($f=='writer')//作者
		{
			if($docheckrep[2]&&strstr($newstemptext,'[!--writer--]'))
			{
				$value=ReplaceWriter($value);
			}
		}
		elseif($f=='titlepic')//标题图片
		{
			if(empty($value))
			{$value=$public_r[newsurl].'e/data/images/notimg.gif';}
		}
		elseif($f=='title')//标题
		{
		}
		else//正常字段
		{
			if(!strstr($emod_r[$mid]['editorf'],','.$f.','))
			{
				if(strstr($emod_r[$mid]['tobrf'],','.$f.','))//加br
				{
					$value=nl2br($value);
				}
				if(!strstr($emod_r[$mid]['dohtmlf'],','.$f.','))//去除html
				{
					$value=RepFieldtextNbsp(htmlspecialchars($value));
				}
			}
		}
		$newstempstr=str_replace('[!--'.$f.'--]',$value,$newstempstr);
	}


	//固定变量
	$newstempstr=str_replace('[!--id--]',$add[id],$newstempstr);
	$newstempstr=str_replace('[!--classid--]',$add[classid],$newstempstr);
	$newstempstr=str_replace('[!--class.name--]',$class_r[$add[classid]][classname],$newstempstr);
	$newstempstr=str_replace('[!--ttid--]',$add[ttid],$newstempstr);
	$newstempstr=str_replace('[!--tt.name--]',$class_tr[$add[ttid]][tname],$newstempstr);
	$newstempstr=str_replace('[!--onclick--]',$add[onclick],$newstempstr);
	$newstempstr=str_replace('[!--userfen--]',$add[userfen],$newstempstr);
	$newstempstr=str_replace('[!--username--]',$add[username],$newstempstr);
	//带链接的用户名
	if($add[ismember]==1&&$add[userid])
	{
		$newstempstr=str_replace('[!--linkusername--]',"<a href='".$public_r[newsurl]."e/space/?userid=".$add[userid]."' target=_blank>".$add[username]."</a>",$newstempstr);
	}
	else
	{
		$newstempstr=str_replace('[!--linkusername--]',$add[username],$newstempstr);
	}
	$newstempstr=str_replace('[!--userid--]',$add[userid],$newstempstr);
	$newstempstr=str_replace('[!--other.link--]',$keyboardtext,$newstempstr);
	$newstempstr=str_replace('[!--news.url--]',$public_r[newsurl],$newstempstr);
	$newstempstr=str_replace('[!--plnum--]',$add[plnum],$newstempstr);
	$newstempstr=str_replace('[!--totaldown--]',$add[totaldown],$newstempstr);
	$newstempstr=str_replace('[!--keyboard--]',$add[keyboard],$newstempstr);
	//链接
	$titleurl=sys_ReturnBqTitleLink($add);
	$newstempstr=str_replace('[!--titleurl--]',$titleurl,$newstempstr);
	$newstempstr=str_replace('[!--page.stats--]',$onclick,$newstempstr);
	$classurl=sys_ReturnBqClassname($add,9);
	$newstempstr=str_replace('[!--class.url--]',$classurl,$newstempstr);
	//下一篇
	if(strstr($newstemptext,'[!--info.next--]'))
	{
		$next_r=$empire->fetch1("select titleurl,groupid,classid,newspath,filename,id,title from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id>$add[id] and classid='$add[classid]' and checked=1 order by id limit 1");
		if(empty($next_r[id]))
		{
			$infonext="<a href='".$classurl."'>".$fun_r['HaveNoNextLink']."</a>";
		}
		else
		{
			//链接
			$nexttitleurl=sys_ReturnBqTitleLink($next_r);
			$infonext="<a href='".$nexttitleurl."'>".$next_r[title]."</a>";
		}
		$newstempstr=str_replace('[!--info.next--]',$infonext,$newstempstr);
	}
	//上一篇
	if(strstr($newstemptext,'[!--info.pre--]'))
	{
		$next_r=$empire->fetch1("select titleurl,groupid,classid,newspath,filename,id,title from {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." where id<$add[id] and classid='$add[classid]' and checked=1 order by id desc limit 1");
		if(empty($next_r[id]))
		{
			$infonext="<a href='".$classurl."'>".$fun_r['HaveNoNextLink']."</a>";
		}
		else
		{
			//链接
			$nexttitleurl=sys_ReturnBqTitleLink($next_r);
			$infonext="<a href='".$nexttitleurl."'>".$next_r[title]."</a>";
		}
		$newstempstr=str_replace('[!--info.pre--]',$infonext,$newstempstr);
	}
	//投票
	if(strstr($newstemptext,'[!--info.vote--]'))
	{
		$myvotetext=sys_GetInfoVote($add[classid],$add[id]);
		$newstempstr=str_replace('[!--info.vote--]',$myvotetext,$newstempstr);
	}
	//评分
	if(strstr($newstemptext,'[!--pinfopfen--]'))
	{
		$pinfopfen=$add[infopfennum]?round($add[infopfen]/$add[infopfennum]):0;
		$newstempstr=str_replace('[!--pinfopfen--]',$pinfopfen,$newstempstr);
		$newstempstr=str_replace('[!--infopfennum--]',$add[infopfennum],$newstempstr);
	}



	$string=$newstempstr;//模板		
	if($type==0){ //生成播放资源js
	$file=ECMS_PATH.$path.'/'.$add[id].$movie_config[playhtmltype][$type];
	WriteFiletext($file,$string);	
	$showfile=$public_r[newsurl].$path.'/'.$add[id].$movie_config[playhtmltype][$type];
	}
	
	if($type==1){  //生成分页
		

	$moviename='';
	$moviedata='';
	$typei='';
	$playi='';
	$moviestr=$add[movieshow];
	$movier=explode($d_exp,$moviestr);
	$typenum=count($movier);
	$mt='';
	$mr='';
	$typei=0;
	for($typei;$typei<$typenum;$typei++){
			
			$kr=explode($t_exp,$movier[$typei]);
			$mt=$kr[0];
			$mr=$kr[1];
			
			$rr=explode($r_exp,$mr);
			$countrr=count($rr);
			$playi=0;
			for($playi;$playi<$countrr;$playi++){
			$string=$newstempstr;//模板		
			//处理播放标签	
			$thisrr=explode($f_exp,$rr[$playi]);
			$moviename=$thisrr[0];
			$moviedata=$thisrr[1];

			$typeii=$typei+1;
			$playii=$playi+1;
            //echo $typei.'|||'.$playi.'<br />';
			$showfile=$public_r[newsurl].$path.'/'.$add[id].'-'.$typeii.'-'.$playii.$movie_config[playhtmltype][$type];	
			$string=str_replace('[!--thismovietypeid--]',$typei,$string);
			$string=str_replace('[!--thismovieplayid--]',$playi,$string);
			$string=str_replace('[!--thismovieurl--]',$showfile,$string);
			$string=str_replace('[!--thismoviename--]',$moviename,$string);
			$string=str_replace('[!--thismoviedata--]',$moviedata,$string);
			$string=str_replace('[!--thismovielist--]',return_thismovielist($kr,$movie_config,$add[id],$typei,$path),$string);
			$string=str_replace('[!--thismovietype--]',$mt,$string);
			$string=str_replace('[!--thismovietypecn--]',return_thismovietypecn($mt,$movie_config),$string);
			$string=str_replace('[!--thismovietypeclass--]',return_thismovietypeclass($mt,$movie_config),$string);
			$string=str_replace('[!--thismovietypestr--]',return_thismovietypestr($mt,$movie_config),$string);
			//处理播放标签
				
			
	$file=ECMS_PATH.$path.'/'.$add[id].'-'.$typeii.'-'.$playii.$movie_config[playhtmltype][$type];
	
	WriteFiletext($file,$string);		
			
			}
	
		}
	}//esle type=1;
	
	
	if($type==2){ //生成信息页
 
		$file=GetInfoFilename($add[classid],$add[id]);	
		$infofiletype=$class_r[$add[classid]]['filetype'];
		if(strstr('index',$file)){
		$dir=ReturnInfoSPaths($file,$infofiletype);
		}
		else{
		
		$dir=str_replace($r['filename'].$infofiletype,'',$file);
		}
		$mk=makelistdir($dir);
								  
		WriteFiletext($file,$string);		
	
	}

   if(empty($add['havehtml']))
	{
		$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]." set havehtml=1 where id='$add[id]' limit 1");
		$empire->query("update {$dbtbpre}ecms_".$class_r[$add[classid]][tbname]."_index set havehtml=1 where id='$add[id]' limit 1");
	}	


return TRUE;


}

function ReturnInfoSPaths($filename,$type){
	return str_replace('/index'.$type,'',$filename);
}

function getplayurl($add){		
       global $public_r,$class_r,$d_exp,$t_exp,$r_exp,$movie_config;	 
	   if(!$movie_config){	include(ECMS_PATH.'e/class/movie_config.php'); }
	   $playdir=$movie_config[playhtmldir];
		$moviestr=$add[movieshow];
		$movier=explode($d_exp,$moviestr);
		$movietype=count($movier)-1;
		$lt=$movietype+1;
		$lmt=$movier[$movietype];
		$lmtr=explode($t_exp,$lmt);
		$st=$lmtr[1];
		$str=explode($r_exp,$st);
		$lnum=count($str);	
		$id=$add[id];
		$infopath=str_replace('/index','',$add[filename]);
		$playurl=$public_r[newsurl].$playdir.'/'.$infopath.'/'.$id.'-'.$lt.'-'.$lnum.$class_r[$add[classid]]["filetype"];
		return $playurl;
 
}
function getplayname($add){		
       global $public_r,$class_r,$d_exp,$t_exp,$r_exp,$movie_config;	 
	   if(!$movie_config){	include(ECMS_PATH.'e/class/movie_config.php'); }
	   $playdir=$movie_config[playhtmldir];
		$moviestr=$add[movieshow];
		$movier=explode($d_exp,$moviestr);
		$movietype=count($movier)-1;
		$lt=$movietype+1;
		$lmt=$movier[$movietype];
		$lmtr=explode($t_exp,$lmt);
		$st=$lmtr[1];
		$str=explode($r_exp,$st);
		$lnum=count($str);	
		$name=$str[$lnum];
		$id=$add[id];
		$name=$name?$name:$add[typeset];
		return $name; 
}

function addremindsend($classid,$id){
global $empire,$public_r,$dbtbpre;
$squery="select userid from {$dbtbpre}movie_remind where classid='$classid' and movieid='$id'";
$query=$empire->query($squery);
	while($rr=$empire->fetch($query)){
			$userid=$rr[userid];
			$users.=$userid.',';
			
	}
	$users=substr($users,0,strlen($users)-1);
	$a=insertremindsend($users,$classid,$id);
	if($a) return true;
}

function insertremindsend($users,$classid,$id){
	global $empire,$public_r,$dbtbpre;	
	$havesend=0;
	$query="insert into {$dbtbpre}movie_remind_send (classid,movieid,users,havesend) values ('$classid','$id','$users','0')";
	$num=$empire->gettotal("select count(*) as total from {$dbtbpre}movie_remind_send where classid='$classid' and movieid='$id'");
	if($num){
	$query="update {$dbtbpre}movie_remind_send set users='$users',havesend='0' where classid='$classid' and movieid='$id' ";	
	}
	$up=$empire->query($query);
	if($up) return true;	
}
?>