Skip to content

Commit 28359c2

Browse files
committed
Add read more in comment
1 parent d9ca233 commit 28359c2

19 files changed

+187
-126
lines changed

controller/admin_comment_edit.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (h *BaseHandler) AdminCommentEditPage(ctx *fasthttp.RequestCtx) {
4545
author = evn.CurrentUser
4646
}
4747

48+
evn.ReadMoreBreak = model.ReadMoreBreak
4849
evn.NodeLst = model.NodeGetAll(h.App.Mc, h.App.Db)
4950
evn.DefaultTopic = model.TopicGetById(db, comment.TopicId)
5051
evn.DefaultComment = model.CommentFmt{

controller/admin_comment_review.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (h *BaseHandler) AdminCommentReviewPage(ctx *fasthttp.RequestCtx) {
5959
author = evn.CurrentUser
6060
}
6161

62+
evn.ReadMoreBreak = model.ReadMoreBreak
6263
evn.NodeLst = model.NodeGetAll(h.App.Mc, h.App.Db)
6364
evn.DefaultTopic = model.TopicGetById(db, rec.TopicId)
6465
evn.DefaultComment = model.CommentFmt{

controller/topic_detail.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ func (h *BaseHandler) TopicDetailPage(ctx *fasthttp.RequestCtx) {
6868
evn.ShowAutoAd = true
6969
}
7070

71+
evn.ReadMoreBreak = model.ReadMoreBreak
7172
evn.NodeLst = model.NodeGetAll(h.App.Mc, db)
7273

7374
logoUrl := scf.MainDomain + "/static/logo_112.png"
7475
var imgLst []string
7576

7677
var contentFmt string
7778
// get from mc
79+
var canRead bool
80+
var isPublic bool
7881
if topic.ReadAuthed || topic.ReadReply {
79-
var canRead bool
8082
if curUser.ID > 0 && curUser.Flag > model.FlagReview {
8183
if topic.ReadAuthed || curUser.Flag == model.FlagAdmin || curUser.ID == author.ID {
8284
canRead = true
@@ -98,28 +100,31 @@ func (h *BaseHandler) TopicDetailPage(ctx *fasthttp.RequestCtx) {
98100
contentFmt = util.ContentFmt(publicCon)
99101
contentFmt = strings.ReplaceAll(contentFmt, `" alt="">`, `" alt="`+safeTitle+`">`)
100102
// read more tip
101-
imgLen := util.CountAllImgInContent(privateCon)
102-
actName := "登录"
103-
if curUser.ID > 0 {
104-
if curUser.Flag == model.FlagForbidden {
105-
actName = "解禁"
106-
} else if curUser.Flag == model.FlagReview {
107-
actName = "等待审核"
108-
} else {
109-
if topic.ReadReply {
110-
actName = "回复"
103+
if len(privateCon) > 0 {
104+
imgLen := util.CountAllImgInContent(privateCon)
105+
actName := "登录"
106+
if curUser.ID > 0 {
107+
if curUser.Flag == model.FlagForbidden {
108+
actName = "解禁"
109+
} else if curUser.Flag == model.FlagReview {
110+
actName = "等待审核"
111+
} else {
112+
if topic.ReadReply {
113+
actName = "回复"
114+
}
111115
}
112116
}
117+
contentFmt += `<p>为了防止爬虫,本主题 "` + topic.Title + `" 的发布者已设置浏览权限,需要“` + actName + `”才能继续浏览,剩余的内容包含个` + strconv.Itoa(len(privateCon)) + `字`
118+
if imgLen > 0 {
119+
contentFmt += `,其中包含` + strconv.Itoa(imgLen) + `张图片`
120+
}
121+
contentFmt += `</p>`
113122
}
114-
contentFmt += `<p>为了防止爬虫,本主题 "` + topic.Title + `" 的发布者已设置浏览权限,需要“` + actName + `”才能继续浏览,剩余的内容包含个` + strconv.Itoa(len(privateCon)) + `字`
115-
if imgLen > 0 {
116-
contentFmt += `,其中包含` + strconv.Itoa(imgLen) + `张图片`
117-
}
118-
contentFmt += `</p>`
119123
// find img
120124
imgLst = util.FindAllImgInContent(publicCon)
121125
}
122126
} else {
127+
isPublic = true
123128
mcKey := []byte("ContentFmt:" + tid)
124129
if mcValue, exist := util.ObjCachedGet(h.App.Mc, mcKey, nil, true); exist {
125130
contentFmt = sdb.B2s(mcValue)
@@ -146,7 +151,7 @@ func (h *BaseHandler) TopicDetailPage(ctx *fasthttp.RequestCtx) {
146151
// 帖子评论数
147152
topic.Comments = db.HgetInt(model.CommentNumTbName, tidByte)
148153
if topic.Comments > 0 {
149-
evn.CommentLst = model.GetAllTopicComment(h.App.Mc, db, topic)
154+
evn.CommentLst = model.GetAllTopicComment(h.App.Mc, db, topic, isPublic, canRead)
150155
}
151156

152157
evn.TopicFmt = model.TopicFmt{

controller/topic_icon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *BaseHandler) TopicIconHandle(ctx *fasthttp.RequestCtx) {
9393
}
9494
}
9595

96-
commentLst = model.GetAllTopicComment(h.App.Mc, db, topic)
96+
commentLst = model.GetAllTopicComment(h.App.Mc, db, topic, false, false)
9797

9898
// 图片9宫格
9999
// user uIds

model/comment.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ func CommentAdd(mc *fastcache.Cache, db *sdb.DB, obj Comment) Comment {
118118
return obj
119119
}
120120

121-
func GetAllTopicComment(mc *fastcache.Cache, db *sdb.DB, topic Topic) (objLst []CommentFmt) {
121+
func GetAllTopicComment(mc *fastcache.Cache, db *sdb.DB, topic Topic, isPublic, canRead bool) (objLst []CommentFmt) {
122122
tbName := CommentTbName + strconv.FormatUint(topic.ID, 10)
123123
mcKey := []byte(tbName)
124-
if _, exist := util.ObjCachedGetBig(mc, mcKey, &objLst, false); exist {
125-
return
124+
if isPublic {
125+
if _, exist := util.ObjCachedGetBig(mc, mcKey, &objLst, false); exist {
126+
return
127+
}
126128
}
127129

128130
userMap := map[uint64]User{}
@@ -134,7 +136,19 @@ func GetAllTopicComment(mc *fastcache.Cache, db *sdb.DB, topic Topic) (objLst []
134136
return
135137
}
136138
obj.AddTimeFmt = util.TimeFmt(obj.AddTime, "2006-01-02 15:04")
137-
obj.ContentFmt = util.ContentFmt(obj.Content)
139+
if isPublic {
140+
obj.ContentFmt = util.ContentFmt(obj.Content)
141+
} else {
142+
if canRead {
143+
obj.ContentFmt = util.ContentFmt(obj.Content)
144+
} else {
145+
publicCon, privateCon := util.GetPublicCon(topic.Content)
146+
obj.ContentFmt = util.ContentFmt(publicCon)
147+
if len(privateCon) > 0 {
148+
obj.ContentFmt += `<p>为了防止爬虫,本主题 "` + topic.Title + `" 的发布者已设置浏览权限,需要“登录”或“回复”才能完整浏览,剩余的内容包含个` + strconv.Itoa(len(privateCon)) + `字</p>`
149+
}
150+
}
151+
}
138152
obj.Link = "/t/" + strconv.FormatUint(obj.TopicId, 10) + "#r" + strconv.FormatUint(obj.ID, 10)
139153
objLst = append(objLst, obj)
140154
userMap[obj.UserId] = User{}
@@ -156,7 +170,7 @@ func GetAllTopicComment(mc *fastcache.Cache, db *sdb.DB, topic Topic) (objLst []
156170
}
157171
}
158172

159-
if len(objLst) > 0 {
173+
if isPublic && len(objLst) > 0 {
160174
util.ObjCachedSetBig(mc, mcKey, objLst)
161175
}
162176

views/admin/all_page_data.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type (
4343

4444
CommentEdit struct {
4545
BasePage
46+
ReadMoreBreak string
4647
DefaultTopic model.Topic // 编辑/添加
4748
DefaultUser model.User // 默认作者
4849
DefaultComment model.CommentFmt

views/admin/base.qtpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Page prints a page implementing Page interface.
2020
{%= p.Header() %}
2121
<meta name="HandheldFriendly" content="True">
2222
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1" />
23-
<meta content="yes" name="apple-mobile-web-app-capable" />
23+
<meta name="mobile-web-app-capable" content="yes">
2424
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
2525
<meta name="format-detection" content="telephone=no" />
2626
<link rel="shortcut icon" href="/static/favicon.png" type="image/x-icon" />

views/admin/base.qtpl.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/admin/comment_editnreview.qtpl

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<input id="btn-preview" type="button" value="预览" name="submit" onclick="previewComment(); return false;" class="pure-button button-success" />
1818
<input id="btn-submit" type="submit" value="发表" name="submit" onclick="submitComment(); return false;" class="pure-button pure-button-primary" />
1919
<input id="fileUpload" type="file" accept="image/*,video/*,audio/*" onChange="uploadFile()" class="pure-button" name="fileUpload" style="font-size: .8334em;width: 95px;" />
20+
<button id="insert-break" type="button" class="pure-button">插入分割线</button>
2021
{% if p.PageName == "admin_comment_review" %}
2122
<a href="?act=del" class="pure-button button-warning fr">直接删除</a>
2223
{% endif %}
@@ -33,6 +34,13 @@
3334
var msgEle = document.getElementById("id-msg");
3435
var reviewEle = document.getElementById("id-preview");
3536

37+
document.getElementById("insert-break").addEventListener('click', function (event) {
38+
let break_line = "\n{%s= p.ReadMoreBreak %}\n";
39+
let pos = conEle.selectionStart;
40+
let con = conEle.value;
41+
conEle.value = con.slice(0, pos) + break_line + con.slice(pos);
42+
}, false);
43+
3644
function previewComment() {
3745
var con = conEle.value.trim();
3846
if (con === "") {

0 commit comments

Comments
 (0)