<?php
error_reporting(0);
close_browse();
if (!eregi($_SERVER['SERVER_NAME'], $_SERVER['HTTP_REFERER'])) {exit();}
global $db, $CcTvAi_com_userid;
if ($CcTvAi_com_userid) {
	$cd_uid=SafeRequest("uid", "post");
	$cd_bid=SafeRequest("bid", "post");
	$cd_note=unescape(SafeRequest("note", "post"));
	if(preg_match("/".cd_messagereplace."/i",$cd_note)){
		exit('50001');
		}
	$cd_replayUser=unescape(SafeRequest("replayUser", "post"));
	if(!IsNumID($CcTvAi_com_userid)) {exit();}
	if(!IsNumID($cd_uid)) {exit();}
	if(!IsNumID($cd_bid)) {exit();}
	$CcTvAi_com_a=explode("[", $cd_replayUser);
	$CcTvAi_com_b=str_replace("回复@", "", $CcTvAi_com_a[0]);
	$CcTvAi_com_c=str_replace("]", "", isset($CcTvAi_com_a[1]) ? $CcTvAi_com_a[1] : NULL);
	$cd_unames=$CcTvAi_com_b;
	$cd_uids=$CcTvAi_com_c;
	$cd_replayUsers='';
	if ($cd_replayUser) {
		$cd_replayUsers='<a href="' . linkweburl($cd_uids, $cd_unames) . '" target="_blank" style="float:none;">@' . $cd_unames . '</a> ';
	}
	if ($cd_note=="") {
		exit('10007');
	} else {
		if (mb_strlen($cd_note, 'UTF8')>140) {
			exit('10006');
		}
		$cookies="comment_add_" . $CcTvAi_com_userid;
		if (!empty($_COOKIE[$cookies])) {
			exit('10002');
		} else {
			$sql="select cd_id,cd_uid,cd_uname from " . tname('blog') . " where cd_id='$cd_bid'";
			if ($row=$db->getrow($sql)) {
				setcookie($cookies, "have", time()+30);
				//入库
				$setarr=array(
					'cd_channel' => 9,
					'cd_dataid' => $cd_bid,
					'cd_content' => $cd_replayUsers . $cd_note,
					'cd_uid' => $CcTvAi_com_userid,
					'cd_uname' => $CcTvAi_com_username,
					'cd_uip' => getonlineip(),
					'cd_addtime' => date('Y-m-d H:i:s')
				);
				inserttable('comment', $setarr, 1);
				$db->query("update " . tname('blog') . " set cd_commentnum=cd_commentnum+1 where cd_id='$cd_bid'");
				if ($row['cd_uid']!=$CcTvAi_com_userid) {
					if ($cd_replayUser) {
						$cd_data='回复了您在&nbsp;<strong>您</strong>&nbsp;说说中的评论&nbsp;<a href="' . cd_webpath .cd_webmlsinger. '/index.php?ac=miniblog&id=' . $row['cd_uid'] . '&day=' . $cd_bid . '" target="_blank">查看详情</a>';
					} else {
						$cd_data='评论了你的说说&nbsp;<a href="' . cd_webpath .cd_webmlsinger. '/index.php?ac=miniblog&id=' . $row['cd_uid'] . '&day=' . $cd_bid . '" target="_blank">查看详情</a>';
					}
					//入库
					$setarr=array(
						'cd_uid' => $CcTvAi_com_userid,
						'cd_uname' => $CcTvAi_com_username,
						'cd_uids' => $row['cd_uid'],
						'cd_unames' => $row['cd_uname'],
						'cd_icon' => 'miniblog',
						'cd_data' => $cd_data,
						'cd_dataid' => $cd_bid,
						'cd_state' => 1,
						'cd_addtime' => date('Y-m-d H:i:s')
					);
					inserttable('notice', $setarr, 1);
				} else {
					//入库
					$setarr=array(
						'cd_uid' => $CcTvAi_com_userid,
						'cd_uname' => $CcTvAi_com_username,
						'cd_uids' => $cd_uids,
						'cd_unames' => GetAlias("cctvai_user", "cd_name", "cd_id", $cd_uids),
						'cd_icon' => 'miniblog',
						'cd_data' => '回复了您在&nbsp;<strong>TA</strong>&nbsp;说说中的评论&nbsp;<a href="' . cd_webpath .cd_webmlsinger. '/index.php?ac=miniblog&id=' . $row['cd_uid'] . '&day=' . $cd_bid . '" target="_blank">查看详情</a>',
						'cd_dataid' => $cd_bid,
						'cd_state' => 1,
						'cd_addtime' => date('Y-m-d H:i:s')
					);
					inserttable('notice', $setarr, 1);
				}
			} else {
				exit('10004');
			}
		}
	}
	echo '<ul>';
	$query=$db->query("select * from " . tname('comment') . " where cd_channel=9 and cd_dataid='$cd_bid' order by cd_addtime desc LIMIT 0,100");
	$num=$db->num_rows($query);
	while ($rows=$db->fetch_array($query)) {
		echo '<li>';
		echo '<div class="avatar"><a href="' . linkweburl($rows['cd_uid'], $rows['cd_uname']) . '" target="_blank"><img class="avatar-34" src="' . linkuserphoto($rows['cd_uid'], 48) . '"/></a></div>';
		echo '<div class="content">';
		echo '<div class="note"><a href="' . linkweburl($rows['cd_uid'], $rows['cd_uname']) . '" target="_blank">' . GetAlias("cctvai_user", "cd_name", "cd_id", $rows['cd_uid']) . '</a>&nbsp;' . $rows['cd_content'] . '</div>';
		echo '<div class="time">发表于:' . datetime($rows['cd_addtime']) . '</div>';
		echo '<div class="replay">';
		if ($rows['cd_uid']==$CcTvAi_com_userid) {
			echo '<span></span>';
		} else {
			echo '<a id="comment" class="comment" authorId="' . $rows['cd_uid'] . '" nickname="' . GetAlias("cctvai_user", "cd_name", "cd_id", $rows['cd_uid']) . '" cid="' . $rows['cd_id'] . '">回复</a>';
		}
		if ($cd_uid==$CcTvAi_com_userid) {
			echo '<span cid="' . $rows['cd_id'] . '" class="dell" title="删除"></span>';
		} else {
			echo '<span></span>';
		}
		echo '</div>';
		echo '</div>';
		echo '</li>';
	}
	echo '</ul>';
	echo '<div id="nums" type="hidden" num="' . $num . '"></div>';
?>
	<script type="text/javascript">
	$(document).ready(function(){
		miniblogLib.miniblogDelInit(".info");
		miniblogLib.commentDelInit();
		miniblogLib.replayUserInit();
		miniblogLib.replayUserDelInit();
	});
	</script>
<?php
} else {
	exit('20001');
}
?>