diff --git a/data.sql b/data.sql index c54754e9..22e6b6cb 100644 --- a/data.sql +++ b/data.sql @@ -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; diff --git a/main.go b/main.go index caaad5be..e1b1840a 100644 --- a/main.go +++ b/main.go @@ -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} diff --git a/mod_routes.go b/mod_routes.go index 482a0ca1..2f67d42f 100644 --- a/mod_routes.go +++ b/mod_routes.go @@ -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 diff --git a/mysql.go b/mysql.go index 22a9e071..a2e30564 100644 --- a/mysql.go +++ b/mysql.go @@ -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 { diff --git a/reply.go b/reply.go index 86602ca2..6590239c 100644 --- a/reply.go +++ b/reply.go @@ -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 diff --git a/routes.go b/routes.go index 490f23fc..3a60b764 100644 --- a/routes.go +++ b/routes.go @@ -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 " + replyItem.CreatedByName + "" + replyItem.ActionIcon = "🔒︎" + case "unlock": + replyItem.ActionType = "This topic has been reopened by " + replyItem.CreatedByName + "" + replyItem.ActionIcon = "🔓︎" + 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 { diff --git a/template_list.go b/template_list.go index bb5074e0..4c5bd3ce 100644 --- a/template_list.go +++ b/template_list.go @@ -133,47 +133,55 @@ var topic_50 []byte = []byte(`
`) var topic_51 []byte = []byte(` -
-

`) -var topic_57 []byte = []byte(`

- `) -var topic_59 []byte = []byte(`  - `) -var topic_60 []byte = []byte(` `) -var topic_64 []byte = []byte(` `) -var topic_66 []byte = []byte(` `) -var topic_68 []byte = []byte(` -   - `) -var topic_71 []byte = []byte(``) -var topic_72 []byte = []byte(`😀`) -var topic_73 []byte = []byte(``) -var topic_74 []byte = []byte(``) -var topic_75 []byte = []byte(``) -var topic_76 []byte = []byte(`👑`) -var topic_77 []byte = []byte(` +
+ `) +var topic_52 []byte = []byte(` + `) +var topic_53 []byte = []byte(`
`) -var topic_78 []byte = []byte(`
+var topic_54 []byte = []byte(` +
+

`) +var topic_60 []byte = []byte(`

+ `) +var topic_62 []byte = []byte(`  + `) +var topic_63 []byte = []byte(` `) +var topic_67 []byte = []byte(` `) +var topic_69 []byte = []byte(` `) +var topic_71 []byte = []byte(` +   + `) +var topic_74 []byte = []byte(``) +var topic_75 []byte = []byte(`😀`) +var topic_76 []byte = []byte(``) +var topic_77 []byte = []byte(``) +var topic_78 []byte = []byte(``) +var topic_79 []byte = []byte(`👑`) +var topic_80 []byte = []byte(` +
`) -var topic_79 []byte = []byte(` +var topic_81 []byte = []byte(`
+`) +var topic_82 []byte = []byte(`
+var topic_83 []byte = []byte(`' type="hidden" />
diff --git a/template_topic.go b/template_topic.go index 4e87987d..016d17cd 100644 --- a/template_topic.go +++ b/template_topic.go @@ -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) } diff --git a/templates/topic.html b/templates/topic.html index a8cb6366..dccd92ae 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -32,7 +32,12 @@ {{if .Topic.Tag}}{{.Topic.Tag}}{{else}}{{.Topic.Level}}👑{{end}}

-
{{range .ItemList}} +
{{range .ItemList}}{{if .ActionType}} +
+ {{.ActionIcon}} + {{.ActionType}} +
+{{else}}

{{.ContentHtml}}

{{.CreatedByName}}  @@ -43,7 +48,7 @@ {{if .LikeCount}}{{.LikeCount}}😀{{end}} {{if .Tag}}{{.Tag}}{{else}}{{.Level}}👑{{end}}
-{{end}}
+{{end}}{{end}}
{{if .CurrentUser.Perms.CreateReply}}