wecenter添加评论支持匿名回复功能
1、
ALTER TABLE `aws_answer_comments`
ADD COLUMN `anonymous` tinyint(1) NULL AFTER `time`,
ADD INDEX `anonymous` (`anonymous`) ;
2、\static\js\aw_template.js
283
'commentBox' :
'<div class="aw-comment-box" id="{{comment_form_id}}">'+
'<div class="aw-comment-list"><p align="center" class="aw-padding10"><i class="aw-loading"></i></p></div>'+
'<form action="{{comment_form_action}}" method="post" onsubmit="return false">'+
'<div class="aw-comment-box-main">'+
'<textarea class="aw-comment-txt form-control" rows="2" name="message" placeholder="' + _t('评论一下') + '..."></textarea>'+
'<div class="aw-comment-box-btn">'+
'<span class="pull-right">'+
'<label><input type="checkbox" name="anonymous" value="1">匿名评论</label>'+
'<a href="javascript:;" class="btn btn-mini btn-success" onclick="AWS.User.save_comment($(this));">' + _t('评论') + '</a>'+
'<a href="javascript:;" class="btn btn-mini btn-gray close-comment-box">' + _t('取消') + '</a>'+
'</span>'+
'</div>'+
'</div>'+
'</form>'+
'</div>',
3、\app\question\ajax.php
283
$this->model('answer')->insert_answer_comment($_GET['answer_id'], $this->user_id, $_POST['message'], $_POST['anonymous']);
4、\models\answer.php
657
public function insert_answer_comment($answer_id, $uid, $message, $anonymous = 0)
671
$comment_id = $this->insert('answer_comments', array(
'uid' => intval($uid),
'answer_id' => intval($answer_id),
'message' => htmlspecialchars($message),
'time' => time(),
'anonymous' => intval($anonymous)
));
5、\views\fesiong\question\ajax\comments.tpl.htm
<?php if (sizeof($this->comments) > 0) { ?>
<ul>
<?php foreach ($this->comments AS $key => $val) { ?>
<li>
<?php if ($val['anonymous'] == 0) { ?>
<a class="aw-user-name" href="people/<?php echo $val['url_token']; ?>" data-id="<?php echo $val['uid']; ?>"><img src="<?php echo get_avatar_url($val['uid'], 'min'); ?>" alt="" /></a>
<?php } else { ?>
<a class="aw-user-img aw-border-radius-5" href="javascript:;"><img src="<?php echo G_STATIC_URL; ?>/common/avatar-mid-img.png" alt="<?php _e('匿名用户'); ?>" /></a>
<?php } ?>
<div>
<?php if ($this->user_id) { ?>
<p class="clearfix">
<span class="pull-right"><?php if (($val['uid'] == $this->user_id AND !$this->question['lock']) OR $this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator']) { ?>
<a href="javascript:;" onclick="AWS.User.remove_comment($(this).parent(), '<?php echo $val['question_id'] > 0 ? 'question' : 'answer'; ?>', <?php echo $val['id']; ?>);"><?php _e('删除'); ?></a> <?php } ?>
<?php if ($val['anonymous'] == 0) { ?>
<a href="javascript:;" onclick="$(this).parents('.aw-comment-box').find('form textarea').insertAtCaret('@<?php echo $val['user_name']; ?>:');$(this).parents('.aw-comment-box').find('form').show().find('textarea').focus();$.scrollTo($(this).parents('.aw-comment-box').find('form'), 300, {queue:true});"><?php _e('回复'); ?></a>
<?php }else{ ?>
<a href="javascript:;" onclick="$(this).parents('.aw-comment-box').find('form textarea').insertAtCaret('@匿名用户:');$(this).parents('.aw-comment-box').find('form').show().find('textarea').focus();$.scrollTo($(this).parents('.aw-comment-box').find('form'), 300, {queue:true});"><?php _e('回复'); ?></a>
<?php } ?>
</span>
<?php } ?>
<?php if ($val['anonymous'] == 0) { ?>
<a href="people/<?php echo $val['url_token']; ?>" class="aw-user-name author" data-id="<?php echo $val['uid']; ?>"><?php echo $val['user_name']; ?></a>
<?php } else { ?>
<a class="aw-user-name" href="javascript:;"><?php _e('匿名用户'); ?></a>
<?php } ?>
• <span><?php echo date_friendly($val['time']); ?></span>
</p>
<p class="clearfix"><?php echo nl2br($val['message']); ?></p>
</div>
</li>
<?php } ?>
</ul>
<?php } ?>
6、
ALTER TABLE `aws_article_comments`
ADD COLUMN `anonymous` tinyint(1) NULL AFTER `votes`,
ADD INDEX `anonymous` (`anonymous`) ;
7、\views\fesiong\article\index.tpl.htm
197
<label class="pull-right"><input type="checkbox" name="anonymous" value="1">匿名回复</label>
8、\app\article\ajax.php
94
$comment_id = $this->model('publish')->publish_article_comment($_POST['article_id'], $message, $this->user_id, $_POST['at_uid'], $_POST['anonymous']);
9、\models\publish.php
365
public function publish_article_comment($article_id, $message, $uid, $at_uid = null, $anonymous = 0)
372
$comment_id = $this->insert('article_comments', array(
'uid' => intval($uid),
'article_id' => intval($article_id),
'message' => htmlspecialchars($message),
'add_time' => time(),
'at_uid' => intval($at_uid),
'anonymous' => intval($anonymous)
));
10、\views\fesiong\article\ajax\comment.tpl.htm
<div class="aw-item" id="answer_list_<?php echo $this->comment_info['id']; ?>">
<div class="mod-head">
<?php if ($this->comment_info['anonymous'] == 0) { ?>
<a class="aw-user-img aw-border-radius-5" href="people/<?php echo $this->comment_info['user_info']['url_token']; ?>">
<img src="<?php echo get_avatar_url($this->comment_info['uid'], 'mid'); ?>" alt="<?php echo $this->comment_info['user_info']['user_name']; ?>" />
</a>
<?php } else { ?>
<a class="aw-user-img aw-border-radius-5" href="javascript:;">
<img src="<?php echo G_STATIC_URL; ?>/common/avatar-mid-img.png" alt="<?php _e('匿名用户'); ?>" />
</a>
<?php } ?>
<p>
<?php if ($this->comment_info['anonymous'] == 0) { ?>
<a href="people/<?php echo $this->comment_info['user_info']['url_token']; ?>"><?php echo $this->comment_info['user_info']['user_name']; ?></a>
<?php } else { ?>
<a href="javascript:;"><?php _e('匿名用户'); ?></a>
<?php } ?>
<?php if ($this->comment_info['at_user_info']) { ?> <?php _e('回复'); ?> <a href="people/<?php echo $this->comment_info['at_user_info']['url_token']; ?>"><?php echo $this->comment_info['at_user_info']['user_name']; ?></a><?php } ?>
</p>
</div>
<div class="mod-body">
<?php echo nl2br($this->comment_info['message']); ?>
</div>
<div class="mod-footer">
<div class="meta">
<span class="pull-right text-color-999"><?php echo date_friendly($this->comment_info['add_time']); ?></span>
<?php if ($this->user_id) { ?>
<a class="text-color-999 <?php if ($this->comment_info['vote_info']['rating'] == 1) { ?> active<?php } ?>" onclick="AWS.User.article_comment_vote($(this), <?php echo $this->comment_info['id']; ?>, 1)"><i class="icon icon-agree"></i> <?php echo $this->comment_info['votes']; ?> <?php if ($this->comment_info['vote_info']['rating'] == 1) { ?><?php _e('我已赞'); ?><?php } else { ?><?php _e('赞'); ?><?php } ?></a>
<?php if ($this->comment_info['anonymous'] == 0) { ?>
<a class="aw-article-comment text-color-999" data-id="<?php echo $this->comment_info['user_info']['uid']; ?>"><i class="icon icon-comment"></i> <?php _e('回复'); ?></a>
<?php } else { ?>
<a class="aw-article-comment text-color-999" data-id="-1"><i class="icon icon-comment"></i> <?php _e('回复'); ?></a>
<?php } ?>
<?php if ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator']) { ?>
<a class="text-color-999" onclick="AWS.dialog('confirm', {'message' : '<?php _e('确认删除?'); ?>'}, function(){AWS.ajax_request(G_BASE_URL + '/article/ajax/remove_comment/', 'comment_id=<?php echo $this->comment_info['id']; ?>');});"><i class="icon icon-trash"></i> <?php _e('删除'); ?></a>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
11、\views\fesiong\article\index.tpl.htm
128
<?php foreach ($this->comments AS $key => $val) { ?>
<div class="aw-item" id="answer_list_<?php echo $val['id']; ?>">
<div class="mod-head">
<?php if ($val['anonymous'] == 0) { ?>
<a class="aw-user-img aw-border-radius-5" href="people/<?php echo $val['user_info']['url_token']; ?>">
<img src="<?php echo get_avatar_url($val['uid'], 'mid'); ?>" alt="<?php echo $val['user_info']['user_name']; ?>" />
</a>
<?php } else { ?>
<a class="aw-user-img aw-border-radius-5" href="javascript:;">
<img src="<?php echo G_STATIC_URL; ?>/common/avatar-mid-img.png" alt="<?php _e('匿名用户'); ?>" />
</a>
<?php } ?>
<p>
<?php if ($val['anonymous'] == 0) { ?>
<a href="people/<?php echo $val['user_info']['url_token']; ?>"><?php echo $val['user_info']['user_name']; ?></a>
<?php } else { ?>
<a href="javascript:;"><?php _e('匿名用户'); ?></a>
<?php } ?>
<?php if ($val['at_user_info']) { ?> <?php _e('回复'); ?> <a href="people/<?php echo $val['at_user_info']['url_token']; ?>"><?php echo $val['at_user_info']['user_name']; ?></a><?php } ?>
</p>
</div>
<div class="mod-body">
<div class="markitup-box">
<?php echo nl2br($val['message']); ?>
</div>
</div>
<div class="mod-footer">
<div class="meta">
<span class="pull-right text-color-999"><?php echo date_friendly($val['add_time']); ?></span>
<?php if ($this->user_id) { ?>
<a class="text-color-999 <?php if ($val['vote_info']['rating'] == 1) { ?> active<?php } ?>" onclick="AWS.User.article_comment_vote($(this), <?php echo $val['id']; ?>, 1)"><i class="icon icon-agree"></i> <?php echo $val['votes']; ?> <?php if ($val['vote_info']['rating'] == 1) { ?><?php _e('我已赞'); ?><?php } else { ?><?php _e('赞'); ?><?php } ?></a>
<?php if ($val['anonymous'] == 0) { ?>
<a class="aw-article-comment text-color-999" data-id="<?php echo $val['user_info']['uid']; ?>"><i class="icon icon-comment"></i> <?php _e('回复'); ?></a>
<?php } else { ?>
<a class="aw-article-comment text-color-999" data-id="-1"><i class="icon icon-comment"></i> <?php _e('回复'); ?></a>
<?php } ?>
<?php if ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator']) { ?>
<a class="text-color-999" onclick="AWS.dialog('confirm', {'message' : '<?php _e('确认删除?'); ?>'}, function(){AWS.ajax_request(G_BASE_URL + '/article/ajax/remove_comment/', 'comment_id=<?php echo $val['id']; ?>');});"><i class="icon icon-trash"></i> <?php _e('删除'); ?></a>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
12、\static\js\aw_template.js
103
'articleCommentBox' :
'<div class="aw-article-replay-box clearfix">'+
'<form action="'+ G_BASE_URL +'/article/ajax/save_comment/" onsubmit="return false;" method="post">'+
'<div class="mod-body">'+
'<input type="hidden" name="at_uid" value="{{at_uid}}">'+
'<input type="hidden" name="post_hash" value="' + G_POST_HASH + '" />'+
'<input type="hidden" name="article_id" value="{{article_id}}" />'+
'<textarea placeholder="' + _t('写下你的评论...') + '" class="form-control" id="comment_editor" name="message" rows="2"></textarea>'+
'</div>'+
'<div class="mod-footer">'+
'<a href="javascript:;" onclick="AWS.ajax_post($(this).parents(\'form\'));" class="btn btn-normal btn-success pull-right btn-submit">' + _t('回复') + '</a>'+
'<label class="pull-right"><input type="checkbox" name="anonymous" value="1">匿名评论</label>'+
'</div>'+
'</form>'+
'</div>',
更详细的步骤,请参考http://www.kandaoni.com/experience/20
阅读全文
收起全文