Added the lock and unlock moderation action posts.

This commit is contained in:
Azareal 2017-04-02 14:00:40 +01:00
parent 42eb509448
commit 2dbeef4694
9 changed files with 160 additions and 81 deletions

View File

@ -95,6 +95,7 @@ CREATE TABLE `replies`(
`ipaddress` varchar(200) DEFAULT '0.0.0.0.0' not null,
`likeCount` int DEFAULT 0 not null,
`words` int DEFAULT 1 not null,
`actionType` varchar(20) DEFAULT '' not null,
primary key(`rid`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;

View File

@ -53,7 +53,7 @@ func compile_templates() {
topic := TopicUser{1,"Blah","Hey there!",0,false,false,"Date","Date",0,"","127.0.0.1",0,1,"",default_group,"",no_css_tmpl,0,"","","","",58,false}
var replyList []Reply
replyList = append(replyList, Reply{0,0,"","Yo!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1})
replyList = append(replyList, Reply{0,0,"","Yo!",0,"",default_group,"",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1",false,1,"",""})
var varList map[string]VarItem = make(map[string]VarItem)
tpage := TopicPage{"Title",user,noticeList,replyList,topic,1,1,false}

View File

@ -4,6 +4,7 @@ import "log"
import "fmt"
import "strings"
import "strconv"
import "net"
import "net/http"
import "html"
import "encoding/json"
@ -29,7 +30,8 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
return
}
err = db.QueryRow("select parentID from topics where tid = ?", tid).Scan(&fid)
var old_is_closed bool
err = db.QueryRow("select parentID, is_closed from topics where tid = ?", tid).Scan(&fid,&old_is_closed)
if err == sql.ErrNoRows {
PreErrorJSQ("The topic you tried to edit doesn't exist.",w,r,is_js)
return
@ -58,6 +60,37 @@ func route_edit_topic(w http.ResponseWriter, r *http.Request) {
return
}
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
LocalError("Bad IP",w,r,user)
return
}
if old_is_closed != is_closed {
var action string
if is_closed {
action = "lock"
} else {
action = "unlock"
}
_, err = create_action_reply_stmt.Exec(tid,action,ipaddress,user.ID)
if err != nil {
InternalError(err,w,r)
return
}
_, err = add_replies_to_topic_stmt.Exec(1, tid)
if err != nil {
InternalError(err,w,r)
return
}
_, err = update_forum_cache_stmt.Exec(topic_name, tid, user.Name, user.ID, 1)
if err != nil {
InternalError(err,w,r)
return
}
}
err = topics.Load(tid)
if err != nil {
LocalErrorJSQ("This topic no longer exists!",w,r,user,is_js)
@ -1803,14 +1836,14 @@ func route_panel_groups_create_submit(w http.ResponseWriter, r *http.Request){
group_type := r.PostFormValue("group-type")
if group_type == "Admin" {
if !user.Perms.EditGroupAdmin {
LocalError("You need the EditGroupAdmin permission can create admin groups",w,r,user)
LocalError("You need the EditGroupAdmin permission to create admin groups",w,r,user)
return
}
is_admin = true
is_mod = true
} else if group_type == "Mod" {
if !user.Perms.EditGroupSuperMod {
LocalError("You need the EditGroupSuperMod permission can create admin groups",w,r,user)
LocalError("You need the EditGroupSuperMod permission to create admin groups",w,r,user)
return
}
is_mod = true

View File

@ -25,6 +25,7 @@ var get_forum_topics_offset_stmt *sql.Stmt
var create_topic_stmt *sql.Stmt
var create_report_stmt *sql.Stmt
var create_reply_stmt *sql.Stmt
var create_action_reply_stmt *sql.Stmt
var add_replies_to_topic_stmt *sql.Stmt
var remove_replies_from_topic_stmt *sql.Stmt
var add_topics_to_forum_stmt *sql.Stmt
@ -158,7 +159,7 @@ func init_database(err error) {
}
log.Print("Preparing get_topic_replies_offset statement.")
get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page))
get_topic_replies_offset_stmt, err = db.Prepare("select replies.rid, replies.content, replies.createdBy, replies.createdAt, replies.lastEdit, replies.lastEditBy, users.avatar, users.name, users.group, users.url_prefix, users.url_name, users.level, replies.ipaddress, replies.likeCount, replies.actionType from replies left join users on replies.createdBy = users.uid where tid = ? limit ?, " + strconv.Itoa(items_per_page))
if err != nil {
log.Fatal(err)
}
@ -199,6 +200,12 @@ func init_database(err error) {
log.Fatal(err)
}
log.Print("Preparing create_action_reply statement.")
create_action_reply_stmt, err = db.Prepare("INSERT INTO replies(tid,actionType,ipaddress,createdBy) VALUES(?,?,?,?)")
if err != nil {
log.Fatal(err)
}
log.Print("Preparing add_replies_to_topic statement.")
add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ?, lastReplyAt = NOW() WHERE tid = ?")
if err != nil {

View File

@ -25,6 +25,8 @@ type Reply struct /* Should probably rename this to ReplyUser and rename ReplySh
IpAddress string
Liked bool
LikeCount int
ActionType string
ActionIcon string
}
type ReplyShort struct

View File

@ -301,7 +301,7 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
return
}
// Get the topic..
// Get the topic...
topic, err := get_topicuser(tid)
if err == sql.ErrNoRows {
NotFound(w,r)
@ -369,7 +369,7 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
replyItem := Reply{Css: no_css_tmpl}
for rows.Next() {
err := rows.Scan(&replyItem.ID, &replyItem.Content, &replyItem.CreatedBy, &replyItem.CreatedAt, &replyItem.LastEdit, &replyItem.LastEditBy, &replyItem.Avatar, &replyItem.CreatedByName, &replyItem.Group, &replyItem.URLPrefix, &replyItem.URLName, &replyItem.Level, &replyItem.IpAddress, &replyItem.LikeCount)
err := rows.Scan(&replyItem.ID, &replyItem.Content, &replyItem.CreatedBy, &replyItem.CreatedAt, &replyItem.LastEdit, &replyItem.LastEditBy, &replyItem.Avatar, &replyItem.CreatedByName, &replyItem.Group, &replyItem.URLPrefix, &replyItem.URLName, &replyItem.Level, &replyItem.IpAddress, &replyItem.LikeCount, &replyItem.ActionType)
if err != nil {
InternalError(err,w,r)
return
@ -405,6 +405,21 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
replyItem.URL = replyItem.URL + replyItem.URLName
}
}*/
// We really shouldn't have inline HTML, we should do something about this...
if replyItem.ActionType != "" {
switch(replyItem.ActionType) {
case "lock":
replyItem.ActionType = "This topic has been locked by <a href='" + build_profile_url(replyItem.CreatedBy) + "'>" + replyItem.CreatedByName + "</a>"
replyItem.ActionIcon = "&#x1F512;&#xFE0E"
case "unlock":
replyItem.ActionType = "This topic has been reopened by <a href='" + build_profile_url(replyItem.CreatedBy) + "'>" + replyItem.CreatedByName + "</a>"
replyItem.ActionIcon = "&#x1F513;&#xFE0E"
default:
replyItem.ActionType = replyItem.ActionType + " has happened"
replyItem.ActionIcon = ""
}
}
replyItem.Liked = false
if hooks["rrow_assign"] != nil {
@ -516,7 +531,7 @@ func route_profile(w http.ResponseWriter, r *http.Request){
replyLiked := false
replyLikeCount := 0
replyList = append(replyList, Reply{rid,puser.ID,replyContent,parse_message(replyContent),replyCreatedBy,replyCreatedByName,replyGroup,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","","",0,"",replyLiked,replyLikeCount})
replyList = append(replyList, Reply{rid,puser.ID,replyContent,parse_message(replyContent),replyCreatedBy,replyCreatedByName,replyGroup,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","","",0,"",replyLiked,replyLikeCount,"",""})
}
err = rows.Err()
if err != nil {

View File

@ -133,47 +133,55 @@ var topic_50 []byte = []byte(`
</div><br />
<div class="rowblock post_container" style="overflow: hidden;">`)
var topic_51 []byte = []byte(`
<div class="rowitem passive deletable_block editable_parent post_item" style="`)
var topic_52 []byte = []byte(`background-image:url(`)
var topic_53 []byte = []byte(`), url(/static/white-dot.jpg);background-position: 0px `)
var topic_54 []byte = []byte(`-1`)
var topic_55 []byte = []byte(`0px;background-repeat:no-repeat, repeat-y;background-size:128px;padding-left:136px;`)
var topic_56 []byte = []byte(`">
<p class="editable_block user_content" style="margin:0;padding:0;">`)
var topic_57 []byte = []byte(`</p>
<a href="/user/`)
var topic_58 []byte = []byte(`" class="username real_username">`)
var topic_59 []byte = []byte(`</a>&nbsp;
`)
var topic_60 []byte = []byte(`<a href="/reply/like/submit/`)
var topic_61 []byte = []byte(`" class="mod_button" title="Love it" style="color:#202020;"><button class="username" style="`)
var topic_62 []byte = []byte(`background-color:/*#eaffea*/#D6FFD6;`)
var topic_63 []byte = []byte(`">😀</button></a>&nbsp;`)
var topic_64 []byte = []byte(`<a href="/reply/edit/submit/`)
var topic_65 []byte = []byte(`" class="mod_button" title="Edit Reply"><button class="username edit_item">🖊️</button></a>&nbsp;`)
var topic_66 []byte = []byte(`<a href="/reply/delete/submit/`)
var topic_67 []byte = []byte(`" class="mod_button" title="Delete Reply"><button class="username delete_item">🗑️</button></a>&nbsp;`)
var topic_68 []byte = []byte(`
<a href="/report/submit/`)
var topic_69 []byte = []byte(`?session=`)
var topic_70 []byte = []byte(`&type=reply" class="mod_button" title="Flag Reply"><button class="username report_item">🚩</button></a>&nbsp;
`)
var topic_71 []byte = []byte(`<a class="username hide_on_micro" style="float: right;color:#505050;border-left:none;padding-left:5px;padding-right:5px;font-size:17px;">`)
var topic_72 []byte = []byte(`</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;margin-left:5px;" title="Like Count">😀</a>`)
var topic_73 []byte = []byte(`<a class="username hide_on_micro" style="float: right;color:#505050;font-size:16px;">`)
var topic_74 []byte = []byte(`</a>`)
var topic_75 []byte = []byte(`<a class="username hide_on_micro level">`)
var topic_76 []byte = []byte(`</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;" title="Level">👑`)
var topic_77 []byte = []byte(`</a>
<div class="rowitem passive deletable_block editable_parent post_item" style="padding:14px;text-align:center;background-color:rgb(255,245,245);">
<span class="action_icon" style="font-size: 18px;padding-right: 5px;">`)
var topic_52 []byte = []byte(`</span>
<span>`)
var topic_53 []byte = []byte(`</span>
</div>
`)
var topic_78 []byte = []byte(`</div>
var topic_54 []byte = []byte(`
<div class="rowitem passive deletable_block editable_parent post_item" style="`)
var topic_55 []byte = []byte(`background-image:url(`)
var topic_56 []byte = []byte(`), url(/static/white-dot.jpg);background-position: 0px `)
var topic_57 []byte = []byte(`-1`)
var topic_58 []byte = []byte(`0px;background-repeat:no-repeat, repeat-y;background-size:128px;padding-left:136px;`)
var topic_59 []byte = []byte(`">
<p class="editable_block user_content" style="margin:0;padding:0;">`)
var topic_60 []byte = []byte(`</p>
<a href="/user/`)
var topic_61 []byte = []byte(`" class="username real_username">`)
var topic_62 []byte = []byte(`</a>&nbsp;
`)
var topic_63 []byte = []byte(`<a href="/reply/like/submit/`)
var topic_64 []byte = []byte(`" class="mod_button" title="Love it" style="color:#202020;"><button class="username" style="`)
var topic_65 []byte = []byte(`background-color:/*#eaffea*/#D6FFD6;`)
var topic_66 []byte = []byte(`">😀</button></a>&nbsp;`)
var topic_67 []byte = []byte(`<a href="/reply/edit/submit/`)
var topic_68 []byte = []byte(`" class="mod_button" title="Edit Reply"><button class="username edit_item">🖊️</button></a>&nbsp;`)
var topic_69 []byte = []byte(`<a href="/reply/delete/submit/`)
var topic_70 []byte = []byte(`" class="mod_button" title="Delete Reply"><button class="username delete_item">🗑️</button></a>&nbsp;`)
var topic_71 []byte = []byte(`
<a href="/report/submit/`)
var topic_72 []byte = []byte(`?session=`)
var topic_73 []byte = []byte(`&type=reply" class="mod_button" title="Flag Reply"><button class="username report_item">🚩</button></a>&nbsp;
`)
var topic_74 []byte = []byte(`<a class="username hide_on_micro" style="float: right;color:#505050;border-left:none;padding-left:5px;padding-right:5px;font-size:17px;">`)
var topic_75 []byte = []byte(`</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;margin-left:5px;" title="Like Count">😀</a>`)
var topic_76 []byte = []byte(`<a class="username hide_on_micro" style="float: right;color:#505050;font-size:16px;">`)
var topic_77 []byte = []byte(`</a>`)
var topic_78 []byte = []byte(`<a class="username hide_on_micro level">`)
var topic_79 []byte = []byte(`</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;" title="Level">👑`)
var topic_80 []byte = []byte(`</a>
</div>
`)
var topic_79 []byte = []byte(`
var topic_81 []byte = []byte(`</div>
`)
var topic_82 []byte = []byte(`
<div class="rowblock">
<form action="/reply/create/" method="post">
<input name="tid" value='`)
var topic_80 []byte = []byte(`' type="hidden" />
var topic_83 []byte = []byte(`' type="hidden" />
<div class="formrow">
<div class="formitem"><textarea name="reply-content" placeholder="Insert reply here"></textarea></div>
</div>

View File

@ -1,8 +1,8 @@
// Code generated by. DO NOT EDIT.
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
package main
import "strconv"
import "io"
import "strconv"
func init() {
template_topic_handle = template_topic
@ -156,70 +156,78 @@ w.Write(topic_49)
w.Write(topic_50)
if len(tmpl_topic_vars.ItemList) != 0 {
for _, item := range tmpl_topic_vars.ItemList {
if item.ActionType != "" {
w.Write(topic_51)
if item.Avatar != "" {
w.Write([]byte(item.ActionIcon))
w.Write(topic_52)
w.Write([]byte(item.Avatar))
w.Write([]byte(item.ActionType))
w.Write(topic_53)
if item.ContentLines <= 5 {
} else {
w.Write(topic_54)
}
if item.Avatar != "" {
w.Write(topic_55)
w.Write([]byte(item.Avatar))
w.Write(topic_56)
if item.ContentLines <= 5 {
w.Write(topic_57)
}
w.Write(topic_58)
w.Write([]byte(string(item.Css)))
}
w.Write(topic_56)
w.Write([]byte(item.ContentHtml))
w.Write(topic_57)
w.Write([]byte(strconv.Itoa(item.CreatedBy)))
w.Write(topic_58)
w.Write([]byte(item.CreatedByName))
w.Write(topic_59)
if tmpl_topic_vars.CurrentUser.Perms.LikeItem {
w.Write([]byte(item.ContentHtml))
w.Write(topic_60)
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write([]byte(strconv.Itoa(item.CreatedBy)))
w.Write(topic_61)
if item.Liked {
w.Write([]byte(item.CreatedByName))
w.Write(topic_62)
}
if tmpl_topic_vars.CurrentUser.Perms.LikeItem {
w.Write(topic_63)
}
if tmpl_topic_vars.CurrentUser.Perms.EditReply {
w.Write(topic_64)
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write(topic_64)
if item.Liked {
w.Write(topic_65)
}
if tmpl_topic_vars.CurrentUser.Perms.DeleteReply {
w.Write(topic_66)
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write(topic_67)
}
w.Write(topic_68)
if tmpl_topic_vars.CurrentUser.Perms.EditReply {
w.Write(topic_67)
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write(topic_68)
}
if tmpl_topic_vars.CurrentUser.Perms.DeleteReply {
w.Write(topic_69)
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write(topic_70)
if item.LikeCount > 0 {
}
w.Write(topic_71)
w.Write([]byte(strconv.Itoa(item.LikeCount)))
w.Write([]byte(strconv.Itoa(item.ID)))
w.Write(topic_72)
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write(topic_73)
if item.LikeCount > 0 {
w.Write(topic_74)
w.Write([]byte(strconv.Itoa(item.LikeCount)))
w.Write(topic_75)
}
if item.Tag != "" {
w.Write(topic_73)
w.Write([]byte(item.Tag))
w.Write(topic_74)
} else {
w.Write(topic_75)
w.Write([]byte(strconv.Itoa(item.Level)))
w.Write(topic_76)
}
w.Write([]byte(item.Tag))
w.Write(topic_77)
}
}
} else {
w.Write(topic_78)
if tmpl_topic_vars.CurrentUser.Perms.CreateReply {
w.Write([]byte(strconv.Itoa(item.Level)))
w.Write(topic_79)
w.Write([]byte(strconv.Itoa(tmpl_topic_vars.Topic.ID)))
}
w.Write(topic_80)
}
}
}
w.Write(topic_81)
if tmpl_topic_vars.CurrentUser.Perms.CreateReply {
w.Write(topic_82)
w.Write([]byte(strconv.Itoa(tmpl_topic_vars.Topic.ID)))
w.Write(topic_83)
}
w.Write(footer_0)
}

View File

@ -32,7 +32,12 @@
{{if .Topic.Tag}}<a class="username hide_on_micro" style="float:right;color:#505050;font-size:16px;">{{.Topic.Tag}}</a>{{else}}<a class="username hide_on_micro level">{{.Topic.Level}}</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;" title="Level">👑</a>{{end}}
</div>
</div><br />
<div class="rowblock post_container" style="overflow: hidden;">{{range .ItemList}}
<div class="rowblock post_container" style="overflow: hidden;">{{range .ItemList}}{{if .ActionType}}
<div class="rowitem passive deletable_block editable_parent post_item" style="padding:14px;text-align:center;background-color:rgb(255,245,245);">
<span class="action_icon" style="font-size: 18px;padding-right: 5px;">{{.ActionIcon}}</span>
<span>{{.ActionType}}</span>
</div>
{{else}}
<div class="rowitem passive deletable_block editable_parent post_item" style="{{if .Avatar}}background-image:url({{.Avatar}}), url(/static/white-dot.jpg);background-position: 0px {{if le .ContentLines 5}}-1{{end}}0px;background-repeat:no-repeat, repeat-y;background-size:128px;padding-left:136px;{{.Css}}{{end}}">
<p class="editable_block user_content" style="margin:0;padding:0;">{{.ContentHtml}}</p>
<a href="/user/{{.CreatedBy}}" class="username real_username">{{.CreatedByName}}</a>&nbsp;
@ -43,7 +48,7 @@
{{if .LikeCount}}<a class="username hide_on_micro" style="float: right;color:#505050;border-left:none;padding-left:5px;padding-right:5px;font-size:17px;">{{.LikeCount}}</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;margin-left:5px;" title="Like Count">😀</a>{{end}}
{{if .Tag}}<a class="username hide_on_micro" style="float: right;color:#505050;font-size:16px;">{{.Tag}}</a>{{else}}<a class="username hide_on_micro level">{{.Level}}</a><a class="username hide_on_micro" style="color:#505050;float:right;opacity:0.85;" title="Level">👑{{end}}</a>
</div>
{{end}}</div>
{{end}}{{end}}</div>
{{if .CurrentUser.Perms.CreateReply}}
<div class="rowblock">
<form action="/reply/create/" method="post">