<?php
//引入心情模块公共方法
require_once("foundation/fcontent_format.php");

//语言包引入
$rf_langpackage=new recaffairlp;

$lp_t_0=$rf_langpackage->rf_s_type_0;
$lp_t_1=$rf_langpackage->rf_s_type_1;
$lp_t_2=$rf_langpackage->rf_s_type_2;
$lp_t_3=$rf_langpackage->rf_s_type_3;
$lp_t_4=$rf_langpackage->rf_s_type_4;
$lp_t_5=$rf_langpackage->rf_s_type_5;
$lp_t_6=$rf_langpackage->rf_s_type_6;
$lp_t_7=$rf_langpackage->rf_s_type_7;
$lp_t_9=$rf_langpackage->rf_s_type_9;

//表定义区
$t_recent_affair=$tablePreStr.'recent_affair';
$t_share=$tablePreStr.'share';

//更新动态显示格式定义

//头像
$uico_affair_log=$rf_langpackage->rf_ico.'</div>
<div class="listbody left"><img onerror=parent.pic_error(this) src="{ico_url}" align="top">'
                 .'<div class="listtime tool_2">{date_time}';
                 
//心情              
$umood_affair_log=$rf_langpackage->rf_mood.'</div>
<div class="listbody left">{mood_txt}'
                  .'<div class="listtime tool_8">{date_time}';
                 
//日志
$ublog_affair_log=$rf_langpackage->rf_w_blog.'<a href="home.php?h={uid}&app=blog_show&id={blog_id}" target="_blank">{blog_title}</a></div>
<div class="listbody left">{blog_centent}'
				 .'<div class="listtime tool_1" style="clear:both">{date_time}';
                 
//相册
$uphoto_affair_log=$rf_langpackage->rf_photo.'</div>
             <div class="listbody left">{photos_centent}'
               .'<div class="listtime tool_2">{date_time}';
                 
//群组                
$ugroup_creat_affair_log=$rf_langpackage->rf_group.'</div>
             <div class="listbody left">{group}'
                 .'<div class="listtime tool_10">{date_time}';
 
//加入群组             
$ugroup_joined_affair_log=$rf_langpackage->rf_j_group.'</div>
             <div class="listbody left">{group}'
                 .'<div class="listtime tool_10">{date_time}';

//投票               
$upoll_creat_affair_log=$rf_langpackage->rf_poll.'<a href="home.php?h={uid}&app=poll_show&p_id={poll_id}" target="_blank">{poll_subject}</a></div>
              <div class="listbody left">{poll_option}'
								.'<div class="listtime tool_6">{date_time}';
								
//参与投票
$upoll_joined_affair_log=$rf_langpackage->rf_join_poll.'<a href="home.php?h={uid}&app=poll_show&p_id={poll_id}" target="_blank">{poll_subject}</a></div>
             <div class="listbody left">'
			  .'<div class="listtime tool_6">{date_time}';
			  
//分享新鲜事
$ushare_inner_blog_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left">{blog_content}';
             
$ushare_inner_photo_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left"><a href="home.php?h={hoster_id}&app={address}" target="_blank"><img onerror=parent.pic_error(this) src="{photo_src}"/></a>';

$ushare_inner_album_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left"><a href="home.php?h={hoster_id}&app={address}" target="_blank"><img onerror=parent.pic_error(this) src="{a_skin}"/></a>';

$ushare_inner_poll_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left">{poll_content}';

$ushare_inner_group_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left">{group_content}';
             
$ushare_inner_subject_affair_log=$rf_langpackage->rf_inner_share.'</div>
             <div class="listbody left">{subject_content}';

$ushare_outer_link_affair_log=$rf_langpackage->rf_link_share.'</div>
             <div class="listbody left"><a href="{link_content}" target="_blank">{link_content}</a>';

$ushare_outer_music_affair_log=$rf_langpackage->rf_outer_share.'</div>
             <div class="listbody left"><div class="music_player"><a href="home.php?h={uid}&app=share_show&s_id={s_id}" target="_blank"></a></div>';

$ushare_outer_movie_affair_log=$rf_langpackage->rf_outer_share.'</div>
             <div class="listbody left"><div class="movie_player" style="background:url({src}) no-repeat;"><a href="home.php?h={uid}&app=share_show&s_id={s_id}" target="_blank"></a></div>';

//记录站内日志分享动态
function set_blog_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$blog_id,$blog_title,$blog_content,$comment,$share_id)
{
	global $t_share;
	global $lp_t_0;
	$blog_content=get_blog_lentxt($blog_content);
	$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{title}","{address}","{blog_content}","{uid}"),array($hoster_id,$hoster_name,$lp_t_0,$blog_title,"blog_show&id=".$blog_id,$blog_content,$user_id),$ushare_inner_affair_log);
	
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\" style=\"clear:both\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);
}

//记录站内投票分享动态
function set_poll_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$poll_id,$subject,$option,$comment,$share_id)
{
	global $t_share;
	global $lp_t_4;
$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{title}","{address}","{poll_content}","{uid}"),array($hoster_id,$hoster_name,$lp_t_4,$subject,"poll_show&p_id=".$poll_id,$option,$user_id),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);
}

//记录站内群组分享动态
function set_group_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$g_id,$g_name,$g_resume,$comment,$share_id)
{
	global $t_share;
	global $lp_t_1;
	$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{title}","{address}","{group_content}"),array($hoster_id,$hoster_name,$lp_t_1,$g_name,"group_space&group_id=".$g_id,$g_resume),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}

//记录站内主题分享动态
function set_subject_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$g_id,$subject_id,$subject_title,$subject_content,$comment,$share_id)
{
	global $t_share;
	global $lp_t_9;
	$subject_txt=get_blog_lentxt($subject_content);
	$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{title}","{address}","{subject_content}"),array($hoster_id,$hoster_name,$lp_t_9,$subject_title,"group_sub_show&group_id=".$g_id."&subject_id=".$subject_id,$subject_txt),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\" style=\"clear:both\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);
}

//记录站内相册分享动态
function set_album_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$a_id,$a_name,$a_skin,$comment,$share_id)
{
	global $t_share;
	global $lp_t_2;
	$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{title}","{address}","{a_skin}"),array($hoster_id,$hoster_name,$lp_t_2,$a_name,"photo_list&album_id=".$a_id,$a_skin),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}

//记录站内照片分享动态
function set_photo_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$hoster_id,$hoster_name,$photo_id,$photo_src,$album_id,$p_info,$comment,$share_id)
{
	global $t_share;
	global $lp_t_3;
	$content=str_replace(array("{hoster_id}","{u_name}","{s_type}","{address}","{photo_src}","{title}"),array($hoster_id,$hoster_name,$lp_t_3,"photo_view&photo_id=".$photo_id."&album_id=".$album_id,$photo_src,$p_info),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}

//记录站内网址分享动态
function set_link_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$title_data,$re_link,$comment,$share_id)
{
	global $t_share;
	global $lp_t_5;
	$content=str_replace(array("{link_content}","{title}"),array($re_link,$title_data),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}

//记录站内音频分享动态
function set_music_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$title_data,$re_link,$comment,$share_id)
{
	global $t_share;
	global $lp_t_6;
	$share_data=urlencode($re_link);
	$content=str_replace(array("{s_type}","{title}","{s_id}","{uid}"),array($lp_t_6,$title_data,$share_id,$user_id),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}

//记录站内视频分享动态
function set_movie_share_log($dbo,$user_id,$user_name,$userico,$ushare_inner_affair_log,$title_data,$re_link,$re_thumb,$re_m_link,$comment,$share_id)
{	global $skinUrl;
	global $t_share;
	global $lp_t_7;
	$src_str='skin/'.$skinUrl.'/images/movie.jpg';
	if($re_thumb!=''){
		$src_str=$re_thumb;
	}
	$share_data=urlencode($re_link);
	$content=str_replace(array("{s_type}","{title}","{s_id}","{src}","{uid}"),array($lp_t_7,$title_data,$share_id,$src_str,$user_id),$ushare_inner_affair_log);
	if($comment!=''){
		$content.='<div class=\"clear\"></div><div class=\"left_g left\"></div><div class=\"center_g left\">{comment}</div><div class=\"right_g left\"></div><div class=\"clear\"></div>';
		$content=str_replace("{comment}",$comment,$content);
	}
	$content.='<div class=\"listtime tool_9\">{date_time}';
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'4','',$share_id,5);
	$sql="update $t_share set content='$content' where s_id=$share_id";
	return $dbo->exeUpdate($sql);	
}
	
//记录投票动态
function set_upoll_log($dbo,$user_id,$user_name,$userico,$upoll_affair_log,$last_pid,$subject,$poll_option)
{
	$content=str_replace(array("{poll_subject}","{poll_id}","{poll_option}","{uid}"),array($subject,$last_pid,$poll_option,$user_id),$upoll_affair_log);
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'0','',$last_pid,4);
}

//参与投票
function set_spoll_log($dbo,$user_id,$user_name,$userico,$upoll_affair_log,$last_pid,$subject,$poll_option)
{
	$content=str_replace(array("{poll_subject}","{poll_id}","{uid}"),array($subject,$last_pid,$user_id),$upoll_affair_log);
	set_uaffair_log($dbo,$user_id,$user_name,$content,$userico,'0','','',4);
}

//纪录头像更新动态
function set_uico_log($dbo,$user_id,$user_name,$uico_affair_log,$uico_url)
{
	 $content=str_replace('{ico_url}',$uico_url,$uico_affair_log);
	 set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'1',"","",7);
}

//纪录心情
function set_umood_log($dbo,$user_id,$user_name,$uico_url,$umood_affair_log,$mood_id,$umood_txt)
{
	 $content=str_replace('{mood_txt}',$umood_txt,$umood_affair_log);
	 set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'1','',$mood_id,6);
}

//纪录发表日志
function set_ublog_log($dbo,$user_id,$user_name,$uico_url,$ublog_affair_log,$ublog_title,$ublog_txt,$ublog_id)
{
	$ublog_txt=get_blog_lentxt($ublog_txt);
	$content=str_replace(array('{blog_id}','{blog_title}','{blog_centent}','{uid}'),array($ublog_id,$ublog_title,$ublog_txt,$user_id),$ublog_affair_log);
	set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'3','',$ublog_id,0);
}

//纪录上传照片
function set_uphoto_log($dbo,$user_id,$user_name,$uico_url,$uphoto_affair_log,$album_id,$album_name,$photos_list)
{  
	$url_uname=urlencode($user_name);
	 $photos_centent='';
	 $show_limit=0;
	 foreach($photos_list as $val){
	 	if($show_limit==6){
	 		break;
	 	}
	 	   $str_br='';
	 	   $show_limit++;
	 	   if($show_limit%4==0){
	 	   	  $str_br='<br />';
	 	   }else{
	 	   	  $str_br='';
	 	   }
	 	   $photos_centent=$photos_centent.'<span class="affair_photo"><a href="home.php?h='.$user_id.'&user_name='.$url_uname.'&app=photo_view&photo_id='.$val['id'].'&album_id='.$album_id.'" target="_blank">'
	 	                   .'<img onerror=parent.pic_error(this) src="'.$val['file'].'" width="100"></a></span>'.$str_br;
	 }
	 $album_info='<a href="home.php?h='.$user_id.'&app=photo_list&album_id='.$album_id.'" target="_blank">'.$album_name.'</a>';
	 $content=str_replace('{album}',$album_info,$uphoto_affair_log);
	 $content=str_replace('{photos_centent}',$photos_centent,$content);
	 if($show_limit==1){
	 	set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'2','',$val['id'],3);
	}else{
		set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'2','',$album_id,2);
	}
}

//纪录群组事件
function set_ugroup_log($dbo,$user_id,$user_name,$uico_url,$ugroup_affair_log,$ugroup_id,$ugroup_name)
{  
	 $group_info='<a href="main.php?app=group_space&group_id='.$ugroup_id.'" target="_blank">'.$ugroup_name.'</a>';
	 $content=str_replace('{group}',$group_info,$ugroup_affair_log);
	 set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,'0',"","",1);
}

//动态更新基础方法
function set_uaffair_log($dbo,$user_id,$user_name,$content,$uico_url,$ra_type,$add_time,$for_con_id,$mod_type)
{
	 Global $t_recent_affair;
	 if(!empty($for_con_id)){
		 $sql="delete from $t_recent_affair where user_id=$user_id and for_content_id = '$for_con_id' and mod_type = $mod_type ";
		 $dbo->exeUpdate($sql);
	 }
	 $data_time='';
	 if($add_time!=''){
	 	   $data_time="'".$add_time."'";
 	 }else{
 	 	   $data_time='now()';
	 }
   $sql="insert into $t_recent_affair (type_id,content,user_id,user_name,user_ico,date_time,update_time,for_content_id,mod_type) "
                        ."values ($ra_type,'$content',$user_id,'$user_name','$uico_url',$data_time,now(),'$for_con_id',$mod_type)";

   if($dbo->exeUpdate($sql)){
      return true;
   }else{
   	  return false;
   }
}

function show_affair($affair_time,$affair_content){
	$date_time='(&nbsp;'.format_datetime_txt($affair_time).'&nbsp;)';
	$content=str_replace('{date_time}',$date_time,$affair_content);
	return $content;
}

?>