<?php
error_reporting(0);
global $db, $CcTvAi_com_userid;
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
if ($CcTvAi_com_userid) {
	$cd_type=SafeRequest("type", "post"); //好友动态=>0全部动态 1分享音乐 2收藏音乐 3发表说说 4上传照片
	$cd_cid=SafeRequest("cid", "post"); //动态=>0好友动态 2全站动态 3我的动态
	if(!IsNumID($CcTvAi_com_userid)) {exit();}
	if(!IsNumID($cd_cid)) {exit();}
	if(!IsNumID($cd_cid)) {exit();}
	switch ($cd_type) {
		case '1':
			$typename="发布音乐";
			$typesql="cd_icon='dance'";
			break;
		case '2':
			$typename="收藏音乐";
			$typesql="cd_icon='favorites'";
			break;
		case '3':
			$typename="发表说说";
			$typesql="cd_icon='miniblog'";
			break;
		case '4':
			$typename="上传照片";
			$typesql="cd_icon='album'";
			break;
		case '5':
			$typename="发布视频";
			$typesql="cd_icon='video'";
			break;
		default:
			$typename="任何";
			$typesql="cd_icon!=''";
			break;
	}
	if ($cd_cid=="0") { //好友动态
		$query=$db->query("select * from " . tname('feed') . " where cd_uid in(" . GetFolloWing($CcTvAi_com_userid, 0) . ") and $typesql order by cd_addtime desc LIMIT 0,100");
		$num=$db->num_rows($query);
		if ($num==0) {
			echo '<div class="feed_item">还没有' . $typename . '动态！</div>';
		} else {
			while ($row=$db->fetch_array($query)) {
				if (!IsNumID($row['cd_uid'])) {
					exit();
				}
				$user=$db->getrow("select cd_nicheng,cd_checkmusic,cd_checkmm,cd_grade,cd_viprank from " . tname('user') . " where cd_id='" . $row['cd_uid'] . "'");
				$cd_data=preg_replace("/\[em:(\d+)]/is", "<img src=\"" . cd_webpath . "user/static/images/emot/e\\1.gif\" class=\"emotImg\">", $row['cd_data']);
				echo '<ul class="all">';
				echo '<li>';
				echo '<div class="avatar"><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank"><img src="' . linkuserphoto($row['cd_uid'], 48) . '"/></a></div>';
				echo '<div class="feedContent">';
				echo '<div class="feedName"><a href="javascript:;" style="float:left;"><img width="16" height="16" class="feedIcon" src="' . cd_webpath . 'user/static/space/images/icon/icon_mini_' . $row['cd_icon'] . '.gif" /></a><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank">' . $user['cd_nicheng'] . '</a>' . CheckCertify($user['cd_checkmusic'], $user['cd_checkmm'], $user['cd_grade'], $user['cd_viprank']) . '&nbsp;' . $row['cd_title'] . '&nbsp;<span class="createTime">(' . datetime($row['cd_addtime']) . ')</span></div>';
				if ($row['cd_icon']=='album') {
					$query=$db->query("select cd_id,cd_url from " . tname('pic') . " where cd_uid='" . $row['cd_uid'] . "' order by cd_addtime desc LIMIT 0,4");
					while ($rows=$db->fetch_array($query)) {
						echo '<a class="img" href="' . cd_webpath .cd_webmlsinger. '/' . rewrite_url('index.php?ac=album&id=' . $row['cd_uid'] . '&day=' . $rows['cd_id']) . '" target="_blank"><img onerror="$call(function(){libs.imageError(this);}, this)" src="' . getalbumthumb($rows['cd_url'], 1) . '" class="summaryimg" /></a>';
					}
				} else {
					echo '<div class="line" iCount="1">';
					echo '<div class="detail">' . $cd_data . '</div>';
					echo '</div>';
				}
				echo '<div class="more"><a href="' . cd_webpath .cd_webmlsinger. '/' . rewrite_url('index.php?ac=feed&id=' . $row['cd_uid']) . '" target="_blank">查看' . GetAlias("cctvai_user", "cd_nicheng", "cd_id", $row['cd_uid']) . '更多动态&raquo;</a></div>';
				echo '</li>';
				echo '</ul>';
			}
		}
	} elseif ($cd_cid=="2") { //全站动态
		$query=$db->query("select * from " . tname('feed') . " where $typesql order by cd_addtime desc LIMIT 0,100");
		$num=$db->num_rows($query);
		if ($num==0) {
			echo '<div class="feed_item">还没有' . $typename . '动态！</div>';
		} else {
			while ($row=$db->fetch_array($query)) {
				if (!IsNumID($row['cd_uid'])) {
					exit();
				}
				$user=$db->getrow("select cd_nicheng,cd_checkmusic,cd_checkmm,cd_grade,cd_viprank from " . tname('user') . " where cd_id='" . $row['cd_uid'] . "'");
				$cd_data=preg_replace("/\[em:(\d+)]/is", "<img src=\"" . cd_webpath . "user/static/images/emot/e\\1.gif\" class=\"emotImg\">", $row['cd_data']);
				echo '<ul class="all">';
				echo '<li>';
				echo '<div class="avatar"><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank"><img src="' . linkuserphoto($row['cd_uid'], 48) . '"/></a></div>';
				echo '<div class="feedContent">';
				echo '<div class="feedName"><a href="javascript:;" style="float:left;"><img width="16" height="16" class="feedIcon" src="' . cd_webpath . 'user/static/space/images/icon/icon_mini_' . $row['cd_icon'] . '.gif" /></a><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank">' . $user['cd_nicheng'] . '</a>' . CheckCertify($user['cd_checkmusic'], $user['cd_checkmm'], $user['cd_grade'], $user['cd_viprank']) . '&nbsp;' . $row['cd_title'] . '&nbsp;<span class="createTime">(' . datetime($row['cd_addtime']) . ')</span></div>';
				if ($row['cd_icon']=='album') {
					$query=$db->query("select cd_id,cd_url from " . tname('pic') . " where cd_uid='" . $row['cd_uid'] . "' order by cd_addtime desc LIMIT 0,4");
					while ($rows=$db->fetch_array($query)) {
						echo '<a class="img" href="' . cd_webpath .cd_webmlsinger. '/' . rewrite_url('index.php?ac=album&id=' . $row['cd_uid'] . '&day=' . $rows['cd_id']) . '" target="_blank"><img onerror="$call(function(){libs.imageError(this);}, this)" src="' . getalbumthumb($rows['cd_url'], 1) . '" class="summaryimg" /></a>';
					}
				} else {
					echo '<div class="line" iCount="1">';
					echo '<div class="detail">' . $cd_data . '</div>';
					echo '</div>';
				}
				echo '<div class="more"><a href="' . cd_webpath .cd_webmlsinger. '/' . rewrite_url('index.php?ac=feed&id=' . $row['cd_uid']) . '" target="_blank">查看' . GetAlias("cctvai_user", "cd_nicheng", "cd_id", $row['cd_uid']) . '更多动态&raquo;</a></div>';
				echo '</li>';
				echo '</ul>';
			}
		}
	} elseif ($cd_cid=="3") { //我的动态
		$db->query("delete from ".tname('feed')." where DATEDIFF(DATE(cd_addtime),'".date('Y-m-d')."')<=-".cd_userfeedday."");
		$query=$db->query("select * from " . tname('feed') . " where cd_uid='" . $CcTvAi_com_userid . "' order by cd_addtime desc LIMIT 0,100");
		$num=$db->num_rows($query);
		if ($num==0) {
			echo '<div class="feed_item">您还没有最新动态！</div>';
		} else {
			echo '<ul class="me">';
			while ($row=$db->fetch_array($query)) {
				if (!IsNumID($row['cd_uid'])) {
					exit();
				}
				$user=$db->getrow("select cd_nicheng,cd_checkmusic,cd_checkmm,cd_grade,cd_viprank from " . tname('user') . " where cd_id='" . $row['cd_uid'] . "'");
				$cd_data=preg_replace("/\[em:(\d+)]/is", "<img src=\"" . cd_webpath . "user/static/images/emot/e\\1.gif\" class=\"emotImg\">", $row['cd_data']);
				echo '<li>';
				echo '<div class="time"><em>' . date('Y', strtotime($row['cd_addtime'])) . '</em>' . date('m', strtotime($row['cd_addtime'])) . '/' . date('d', strtotime($row['cd_addtime'])) . '</div>';
				echo '<i class="square"></i>';
				echo '<div class="feedContent">';
				echo '<div class="feedName"><a href="javascript:;" style="float:left;"><img width="16" height="16" class="feedIcon" src="' . cd_webpath . 'user/static/space/images/icon/icon_mini_' . $row['cd_icon'] . '.gif" /></a><a href="' . linkweburl($row['cd_uid'], $row['cd_uname']) . '" target="_blank">' . $user['cd_nicheng'] . '</a>' . CheckCertify($user['cd_checkmusic'], $user['cd_checkmm'], $user['cd_grade'], $user['cd_viprank']) . '&nbsp;' . $row['cd_title'] . '&nbsp;<span class="createTime">(' . datetime($row['cd_addtime']) . ')</span></div>';
				if ($row['cd_icon']=='album') {
					$query=$db->query("select cd_id,cd_url from " . tname('pic') . " where cd_uid='" . $row['cd_uid'] . "' order by cd_addtime desc LIMIT 0,4");
					while ($rows=$db->fetch_array($query)) {
						echo '<a class="img" href="' . cd_webpath .cd_webmlsinger. '/' . rewrite_url('index.php?ac=album&id=' . $row['cd_uid'] . '&day=' . $rows['cd_id']) . '" target="_blank"><img onerror="$call(function(){libs.imageError(this);}, this)" src="' . getalbumthumb($rows['cd_url'], 1) . '" class="summaryimg" /></a>';
					}
				} else {
					echo '<div class="detail">' . $cd_data . '</div>';
				}
				echo '</div>';
				echo '</div>';
				echo '</li>';
			}
			echo '</ul>';
		}
		echo '<input type="hidden" name="feedItem" id="feedItem" cid="' . $cd_cid . '"/>';
	}
} else {
	exit('20001');
}
?>