mirror of https://github.com/halo-dev/halo
🎨 评论支持换行
parent
975aa8278e
commit
1d2fdfbbec
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
||||||
import cc.ryanc.halo.model.domain.Post;
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
import cc.ryanc.halo.model.domain.User;
|
import cc.ryanc.halo.model.domain.User;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||||
import cc.ryanc.halo.model.enums.CommentStatusEnum;
|
import cc.ryanc.halo.model.enums.CommentStatusEnum;
|
||||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||||
|
@ -27,10 +28,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
@ -150,10 +148,11 @@ public class CommentController extends BaseController {
|
||||||
*
|
*
|
||||||
* @param commentId 被回复的评论
|
* @param commentId 被回复的评论
|
||||||
* @param commentContent 回复的内容
|
* @param commentContent 回复的内容
|
||||||
* @return 重定向到/admin/comments
|
* @return JsonResult
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/reply")
|
@PostMapping(value = "/reply")
|
||||||
public String replyComment(@RequestParam("commentId") Long commentId,
|
@ResponseBody
|
||||||
|
public JsonResult replyComment(@RequestParam("commentId") Long commentId,
|
||||||
@RequestParam("postId") Long postId,
|
@RequestParam("postId") Long postId,
|
||||||
@RequestParam("commentContent") String commentContent,
|
@RequestParam("commentContent") String commentContent,
|
||||||
@RequestParam("userAgent") String userAgent,
|
@RequestParam("userAgent") String userAgent,
|
||||||
|
@ -182,7 +181,7 @@ public class CommentController extends BaseController {
|
||||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
||||||
comment.setCommentDate(DateUtil.date());
|
comment.setCommentDate(DateUtil.date());
|
||||||
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
||||||
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(commentContent)));
|
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(commentContent).replace("<br/>", "<br/>")));
|
||||||
comment.setCommentAgent(userAgent);
|
comment.setCommentAgent(userAgent);
|
||||||
comment.setCommentParent(commentId);
|
comment.setCommentParent(commentId);
|
||||||
comment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
comment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
||||||
|
@ -191,10 +190,11 @@ public class CommentController extends BaseController {
|
||||||
|
|
||||||
//邮件通知
|
//邮件通知
|
||||||
new EmailToAuthor(comment, lastComment, post, user, commentContent).start();
|
new EmailToAuthor(comment, lastComment, post, user, commentContent).start();
|
||||||
|
return new JsonResult(1, "回复成功!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("回复评论失败:{}", e.getMessage());
|
log.error("回复评论失败:{}", e.getMessage());
|
||||||
|
return new JsonResult(0, "回复失败!");
|
||||||
}
|
}
|
||||||
return "redirect:/admin/comments";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -127,10 +127,10 @@ public class FrontCommentController {
|
||||||
if (comment.getCommentParent() > 0) {
|
if (comment.getCommentParent() > 0) {
|
||||||
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
||||||
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
||||||
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent())));
|
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||||
} else {
|
} else {
|
||||||
//将评论内容的字符专为安全字符
|
//将评论内容的字符专为安全字符
|
||||||
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent())));
|
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotEmpty(comment.getCommentAuthorUrl())) {
|
if (StrUtil.isNotEmpty(comment.getCommentAuthorUrl())) {
|
||||||
comment.setCommentAuthorUrl(URLUtil.formatUrl(comment.getCommentAuthorUrl()));
|
comment.setCommentAuthorUrl(URLUtil.formatUrl(comment.getCommentAuthorUrl()));
|
||||||
|
|
|
@ -38,10 +38,10 @@ $('#comment-submit').click(function () {
|
||||||
async: false,
|
async: false,
|
||||||
data: {
|
data: {
|
||||||
'postId': $('input[name=postId]').val(),
|
'postId': $('input[name=postId]').val(),
|
||||||
'commentContent': $('textarea[name=commentContent]').val(),
|
'commentContent': formatContent(content.val()),
|
||||||
'commentAuthor': $('input[name=commentAuthor]').val(),
|
'commentAuthor': author.val(),
|
||||||
'commentAuthorEmail': $('input[name=commentAuthorEmail]').val(),
|
'commentAuthorEmail': email.val(),
|
||||||
'commentAuthorUrl': $('input[name=commentAuthorUrl]').val(),
|
'commentAuthorUrl': url.val(),
|
||||||
'commentAgent': navigator.userAgent,
|
'commentAgent': navigator.userAgent,
|
||||||
'commentParent': $('input[name=commentParent]').val()
|
'commentParent': $('input[name=commentParent]').val()
|
||||||
},
|
},
|
||||||
|
@ -78,12 +78,22 @@ $('.comment-cancel-reply').click(function () {
|
||||||
$('#commentContent').attr("placeholder","");
|
$('#commentContent').attr("placeholder","");
|
||||||
$(".comment-cancel-reply").hide();
|
$(".comment-cancel-reply").hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载头像
|
||||||
|
*/
|
||||||
function loadAvatar() {
|
function loadAvatar() {
|
||||||
$(".comment-author-avatar").attr("src","//gravatar.loli.net/avatar/"+md5(localStorage.getItem("email"))+"?s=256&d="+avatarType);
|
$(".comment-author-avatar").attr("src","//gravatar.loli.net/avatar/"+md5(localStorage.getItem("email"))+"?s=256&d="+avatarType);
|
||||||
if($('input[name=commentAuthorEmail]').val()!='' && $('input[name=commentAuthorEmail]').val()!=null){
|
if($('input[name=commentAuthorEmail]').val()!='' && $('input[name=commentAuthorEmail]').val()!=null){
|
||||||
$(".comment-author-avatar").attr("src","//gravatar.loli.net/avatar/"+md5($('input[name=commentAuthorEmail]').val())+"?s=256&d="+avatarType);
|
$(".comment-author-avatar").attr("src","//gravatar.loli.net/avatar/"+md5($('input[name=commentAuthorEmail]').val())+"?s=256&d="+avatarType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化ua信息
|
||||||
|
* @param string
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
var parser = new UAParser();
|
var parser = new UAParser();
|
||||||
function show_ua(string){
|
function show_ua(string){
|
||||||
parser.setUA(string);
|
parser.setUA(string);
|
||||||
|
@ -95,3 +105,15 @@ function show_ua(string){
|
||||||
var os = uua.os.name + ' ' + uua.os.version;
|
var os = uua.os.name + ' ' + uua.os.version;
|
||||||
return '<span class="ua">'+browser+'</span><span class="ua">'+os+'</span>';
|
return '<span class="ua">'+browser+'</span><span class="ua">'+os+'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化字符串
|
||||||
|
* @param a a
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function formatContent(a) {
|
||||||
|
a = a.replace(/\r\n/g, '<br/>');
|
||||||
|
a = a.replace(/\n/g, '<br/>');
|
||||||
|
a = a.replace(/\s/g, ' ');
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
|
@ -129,16 +129,16 @@
|
||||||
<h4 class="modal-title"><@spring.message code="common.btn.reply" /></h4>
|
<h4 class="modal-title"><@spring.message code="common.btn.reply" /></h4>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="/admin/comments/reply">
|
<form method="post" action="/admin/comments/reply">
|
||||||
|
<input type="hidden" id="commentId" name="commentId" value=""/>
|
||||||
|
<input type="hidden" id="userAgent" name="userAgent" value=""/>
|
||||||
|
<input type="hidden" id="postId" name="postId" value="" />
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<textarea class="form-control comment-input-content" rows="5" id="commentContent" name="commentContent" style="resize: none"></textarea>
|
<textarea class="form-control comment-input-content" rows="5" id="commentContent" name="commentContent" style="resize: none"></textarea>
|
||||||
<div class="OwO"></div>
|
<div class="OwO"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<input type="hidden" id="commentId" name="commentId" value=""/>
|
|
||||||
<input type="hidden" id="userAgent" name="userAgent" value=""/>
|
|
||||||
<input type="hidden" id="postId" name="postId" value="" />
|
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal"><@spring.message code="common.btn.cancel" /></button>
|
<button type="button" class="btn btn-default" data-dismiss="modal"><@spring.message code="common.btn.cancel" /></button>
|
||||||
<button type="submit" class="btn btn-primary"><@spring.message code="common.btn.define" /></button>
|
<button type="button" class="btn btn-primary" onclick="reply()"><@spring.message code="common.btn.define" /></button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -163,12 +163,49 @@
|
||||||
window.location.href=url;
|
window.location.href=url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示回复模态框
|
||||||
|
*
|
||||||
|
* @param commentId commentId
|
||||||
|
* @param postId postId
|
||||||
|
*/
|
||||||
function replyShow(commentId,postId) {
|
function replyShow(commentId,postId) {
|
||||||
$('#userAgent').val(navigator.userAgent);
|
$('#userAgent').val(navigator.userAgent);
|
||||||
$('#commentId').val(commentId);
|
$('#commentId').val(commentId);
|
||||||
$('#postId').val(postId);
|
$('#postId').val(postId);
|
||||||
$('#commentReplyModal').modal();
|
$('#commentReplyModal').modal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reply() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '/admin/comments/reply',
|
||||||
|
async: false,
|
||||||
|
data: {
|
||||||
|
'commentId': $("#commentId").val(),
|
||||||
|
'userAgent': $("#userAgent").val(),
|
||||||
|
'postId': $("#postId").val(),
|
||||||
|
'commentContent': formatContent($("#commentContent").val())
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if(data.code==1){
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化字符串
|
||||||
|
* @param a a
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function formatContent(a) {
|
||||||
|
a = a.replace(/\r\n/g, '<br/>');
|
||||||
|
a = a.replace(/\n/g, '<br/>');
|
||||||
|
a = a.replace(/\s/g, ' ');
|
||||||
|
return a;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
<#include "module/_footer.ftl">
|
<#include "module/_footer.ftl">
|
||||||
|
|
Loading…
Reference in New Issue