Skip to content

Commit

Permalink
增加邮箱
Browse files Browse the repository at this point in the history
  • Loading branch information
suliang committed May 2, 2017
1 parent ad54175 commit e0acd64
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
6 changes: 2 additions & 4 deletions application/controllers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ public function ajax_addcommentAction()
{
$blogid = (int)$this->getRequest()->getpost("blogid");
$content = $this->getRequest()->getpost("content");
$nickname = $this->getRequest()->getpost("nickname");
$email = $this->getRequest()->getpost("email");

if($blogid >= 0 && $content && $nickname)
if($blogid >= 0 && $content)
{
$content = htmlspecialchars($content);
$nickname = htmlspecialchars($nickname);
$result = $this->commentmodel->addcomment($content,$blogid,0,$email,$nickname);
$result = $this->commentmodel->addcomment($content,$blogid,0,$email);
if($result)
{
$data = array('status'=>1,'info'=>array('content'=>'成功'));
Expand Down
8 changes: 5 additions & 3 deletions application/models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ public function commentcount($reply = false)
return $this->db->get_one($sql,'c');
}

public function addcomment($content,$blogid,$replyid = 0,$email = '',$nickname = '')
public function addcomment($content,$blogid,$replyid = 0,$email = '')
{
$this->redis->remove(__CLASS__);
if(!$nickname)
if(!$email)
{
//管理员回复
$this->db->update('comment',['replyid'=>-1],'id = '.$replyid);
$data = ['replyid'=>$replyid,'content'=>$content,'blogid'=>$blogid];
return $this->db->insert('comment',$data);
}
else
{
$data = ['replyid'=>$replyid,'content'=>$content,'nickname'=>$nickname,'email'=>$email,'blogid'=>$blogid];
//游客在详情页发评论
$data = ['replyid'=>$replyid,'content'=>$content,'email'=>$email,'blogid'=>$blogid];
return $this->db->safeinsert('comment',$data);
}

Expand Down
8 changes: 3 additions & 5 deletions application/views/index/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<div style="float:right"><a href="javascript:void(0)" class="reply_the_comment">回复</a></div>
</div>
<?php
echo $value['nickname'],' : ',$value['content'];
echo $value['content'];
if(array_key_exists('reply',$value))
{
echo "<div class='text-primary' style='border-top:1px dashed RGB(214,214,214);padding: 5px'>管理员回复:";
Expand All @@ -74,10 +74,8 @@
<form name="comment" id="commentform">
<div style=" margin-top: 10px;">
<input type="hidden" id="blogid" value="<?=$blog['id']?>">
<textarea name="comment" id="comment_textarea" placeholder="请发表您的评论" class="form-control"></textarea>
</div>
<div style=" margin-top: 10px;">
<input type="text" id="email" placeholder="请输入您的邮箱,便于作者回复后通知您" class="form-control">
内容:<textarea name="comment" id="comment_textarea" placeholder="请发表您的评论" class="form-control"></textarea>
邮箱:<input type="text" id="email" placeholder="请输入您的邮箱,便于作者回复后通知您" class="form-control">
<button type="button" class="btn btn-primary" id="post_comment">发表</button>
</div>

Expand Down
1 change: 0 additions & 1 deletion blog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ CREATE TABLE `comment` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`blogid` int(11) DEFAULT NULL,
`content` varchar(240) DEFAULT '',
`nickname` char(24) DEFAULT '',
`createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`replyid` int(11) DEFAULT '0' COMMENT '-1 已被回复 0 未被回复 >0 回复的那个id',
PRIMARY KEY (`id`),
Expand Down
5 changes: 2 additions & 3 deletions public/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ $(function() {
}
$.post(
BASE_URL+"comment/ajax_addcomment",
{ "blogid": blogid, "content":content, "nickname":'test', "email":email },
{ "blogid": blogid, "content":content, "email":email },
function(data){
if(data.status == 1)
{
newfloor = parseInt(lastfloor) + parseInt(1)
$("form").before("<div class='commentlist' style='border-bottom:1.5px solid RGB(188,188,188)'><div><span name='floor'>"+newfloor+"</span> 楼 就在刚才</div>"+content+"</div>")
$("#commentform").before("<div class='commentlist' style='border-bottom:1.5px solid RGB(188,188,188)'><div><span name='floor'>"+newfloor+"</span> 楼 就在刚才</div>"+content+"</div>")
$("#comment_textarea").val("")
$("#nickname").val("")
}
else
{
Expand Down

0 comments on commit e0acd64

Please sign in to comment.