ECSHOP 默认的程序 是 当用户登录后,对商品商品评价是不是能匿名评价的。
有些店铺设置了只能登录评价,但客户又不想显示自己的账号名称。这时候 这功能 就可以派上用场了
1在 comment.php 的底部 把 add_comment 方法替换成以下代码
/** * 添加评论内容 * * @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; } |
2。在comments.lbi 中的 submitComment 方法中增加
1 |
cmt.nimingis = frm.elements[‘nimingis‘].checked; |
3.在html代码中增加
<!--{if $smarty.session.user_name}--> <tr> <td width="64" align="right">是否匿名:</td> <td width="631">{$lang.anonymous}<input type="checkbox" name="nimingis" value="" ></td> </tr> <!--{/if}--> |