22650aad27
Added Attachments. Added Attachment Media Embeds. Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing. Added petabytes as a unit and cleaned up a few of the friendly units. Refactored the username change logic to make it easier to maintain. Refactored the avatar change logic to make it easier to maintain. Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on! Snuck some CSS Variables into Tempra Conflux. Added the GroupCache interface to MemoryGroupStore. Added the Length method to MemoryGroupStore. Added support for a site short name. Added the UploadFiles permission. Renamed more functions. Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow. Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler. Added support for if statements operating on slices and maps for the template compiler. Fixed a security exploit in reply editing. Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports. Fixed buttons having blue outlines on focus on Shadow. Refactored the topic creation logic to make it easier to maintain. Made a few responsive fixes, but there's still more to do in the following commits!
128 lines
2.8 KiB
Go
128 lines
2.8 KiB
Go
package main
|
|
|
|
//import "fmt"
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
type ForumAdmin struct {
|
|
ID int
|
|
Name string
|
|
Desc string
|
|
Active bool
|
|
Preset string
|
|
TopicCount int
|
|
PresetLang string
|
|
}
|
|
|
|
type Forum struct {
|
|
ID int
|
|
Link string
|
|
Name string
|
|
Desc string
|
|
Active bool
|
|
Preset string
|
|
ParentID int
|
|
ParentType string
|
|
TopicCount int
|
|
|
|
LastTopic *Topic
|
|
LastTopicID int
|
|
LastReplyer *User
|
|
LastReplyerID int
|
|
LastTopicTime string // So that we can re-calculate the relative time on the spot in /forums/
|
|
|
|
//LastLock sync.RWMutex // ? - Is this safe to copy? Use a pointer to it? Should we do an fstore.Reload() instead?
|
|
}
|
|
|
|
// ? - What is this for?
|
|
type ForumSimple struct {
|
|
ID int
|
|
Name string
|
|
Active bool
|
|
Preset string
|
|
}
|
|
|
|
// Copy gives you a non-pointer concurrency safe copy of the forum
|
|
func (forum *Forum) Copy() (fcopy Forum) {
|
|
//forum.LastLock.RLock()
|
|
fcopy = *forum
|
|
//forum.LastLock.RUnlock()
|
|
return fcopy
|
|
}
|
|
|
|
/*func (forum *Forum) GetLast() (topic *Topic, user *User) {
|
|
forum.LastLock.RLock()
|
|
topic = forum.LastTopic
|
|
if topic == nil {
|
|
topic = &Topic{ID: 0}
|
|
}
|
|
|
|
user = forum.LastReplyer
|
|
if user == nil {
|
|
user = &User{ID: 0}
|
|
}
|
|
forum.LastLock.RUnlock()
|
|
return topic, user
|
|
}
|
|
|
|
func (forum *Forum) SetLast(topic *Topic, user *User) {
|
|
forum.LastLock.Lock()
|
|
forum.LastTopic = topic
|
|
forum.LastReplyer = user
|
|
forum.LastLock.Unlock()
|
|
}*/
|
|
|
|
// TODO: Write tests for this
|
|
func (forum *Forum) Update(name string, desc string, active bool, preset string) error {
|
|
if name == "" {
|
|
name = forum.Name
|
|
}
|
|
preset = strings.TrimSpace(preset)
|
|
_, err := updateForumStmt.Exec(name, desc, active, preset, forum.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if forum.Preset != preset || preset == "custom" || preset == "" {
|
|
err = permmapToQuery(presetToPermmap(preset), forum.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
_ = fstore.Reload(forum.ID)
|
|
return nil
|
|
}
|
|
|
|
// TODO: Replace this sorting mechanism with something a lot more efficient
|
|
// ? - Use sort.Slice instead?
|
|
type SortForum []*Forum
|
|
|
|
func (sf SortForum) Len() int {
|
|
return len(sf)
|
|
}
|
|
func (sf SortForum) Swap(i, j int) {
|
|
sf[i], sf[j] = sf[j], sf[i]
|
|
}
|
|
func (sf SortForum) Less(i, j int) bool {
|
|
return sf[i].ID < sf[j].ID
|
|
}
|
|
|
|
// ! Don't use this outside of tests and possibly template_init.go
|
|
func makeDummyForum(fid int, link string, name string, desc string, active bool, preset string, parentID int, parentType string, topicCount int) *Forum {
|
|
return &Forum{ID: fid, Link: link, Name: name, Desc: desc, Active: active, Preset: preset, ParentID: parentID, ParentType: parentType, TopicCount: topicCount}
|
|
}
|
|
|
|
func buildForumURL(slug string, fid int) string {
|
|
if slug == "" {
|
|
return "/forum/" + strconv.Itoa(fid)
|
|
}
|
|
return "/forum/" + slug + "." + strconv.Itoa(fid)
|
|
}
|
|
|
|
func getForumURLPrefix() string {
|
|
return "/forum/"
|
|
}
|