/**
* 添加评论内容
*
* @access public
* @param object $cmt
* @return void
*/
function add_comment($cmt)
{
/* 评论是否需要审核 */
$status = 1 - $GLOBALS['_CFG']['comment_check'];
$user_id = empty($_SESSION['user_id']) ? 0 : $_SESSION['user_id'];
$email = empty($cmt->email) ? $_SESSION['email'] : trim($cmt->email);
$user_name = empty($cmt->username) ? $_SESSION['user_name'] : trim($cmt->username);
$email = htmlspecialchars($email);
$user_name = htmlspecialchars($user_name);
//file_put_contents('test.txt',$cmt->nimingis);
$nimingis=$cmt->nimingis;
if($nimingis){
$user_id=0;
$user_name= str_mid_replace($_SESSION['user_name']);
}
/* 保存评论内容 */
$sql = "INSERT INTO " .$GLOBALS['ecs']->table('comment') .
"(comment_type, id_value, email, user_name, content, comment_rank, add_time, ip_address, status, parent_id, user_id) VALUES " .
"('" .$cmt->type. "', '" .$cmt->id. "', '$email', '$user_name', '" .$cmt->content."', '".$cmt->rank."', ".gmtime().", '".real_ip()."', '$status', '0', '$user_id')";
$result = $GLOBALS['db']->query($sql);
clear_cache_files('comments_list.lbi');
/*if ($status > 0)
{
add_feed($GLOBALS['db']->insert_id(), COMMENT_GOODS);
}*/
return $result;
}
//字符串截取
function str_mid_replace($string) {
if (! $string || !isset($string[1])) return $string;
$len = strlen($string);
$starNum = floor($len / 2);
$noStarNum = $len - $starNum;
$leftNum = ceil($noStarNum / 2);
$rightNum = $noStarNum - $leftNum;
$result = substr($string, 0, $leftNum);
$result .= str_repeat('*', $starNum);
$result .= substr($string, $len-$rightNum);
return $result;
}