Added #rid for linking to a specific post. Added a forum_exists function. Removed the null bytes from the posts The report system now uses #rid, #tid and numeric mentions instead of raw HTML. Improved the custom parser to take control characters into account. It also now parses items at the start of the post. Fixed the padding on the buttons on the profiles. #tid now takes into account whether the topic it links to exists.
88 lines
1.6 KiB
Go
88 lines
1.6 KiB
Go
package main
|
|
//import "fmt"
|
|
import "database/sql"
|
|
import _ "github.com/go-sql-driver/mysql"
|
|
|
|
type ForumAdmin struct
|
|
{
|
|
ID int
|
|
Name string
|
|
Active bool
|
|
Preset string
|
|
TopicCount int
|
|
|
|
PresetLang string
|
|
PresetEmoji string
|
|
}
|
|
|
|
type Forum struct
|
|
{
|
|
ID int
|
|
Name string
|
|
Active bool
|
|
Preset string
|
|
TopicCount int
|
|
LastTopic string
|
|
LastTopicID int
|
|
LastReplyer string
|
|
LastReplyerID int
|
|
LastTopicTime string
|
|
}
|
|
|
|
type ForumSimple struct
|
|
{
|
|
ID int
|
|
Name string
|
|
Active bool
|
|
Preset string
|
|
}
|
|
|
|
func create_forum(forum_name string, active bool, preset string) (int, error) {
|
|
var fid int
|
|
err := forum_entry_exists_stmt.QueryRow().Scan(&fid)
|
|
if err != nil && err != sql.ErrNoRows {
|
|
return 0, err
|
|
}
|
|
if err != sql.ErrNoRows {
|
|
_, err = update_forum_stmt.Exec(forum_name, active, preset, fid)
|
|
if err != nil {
|
|
return fid, err
|
|
}
|
|
forums[fid].Name = forum_name
|
|
forums[fid].Active = active
|
|
forums[fid].Preset = preset
|
|
return fid, nil
|
|
}
|
|
|
|
res, err := create_forum_stmt.Exec(forum_name, active, preset)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
fid64, err := res.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
fid = int(fid64)
|
|
|
|
forums = append(forums, Forum{fid,forum_name,active,preset,0,"",0,"",0,""})
|
|
return fid, nil
|
|
}
|
|
|
|
func delete_forum(fid int) error {
|
|
_, err := delete_forum_stmt.Exec(fid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
forums[fid].Name = ""
|
|
return nil
|
|
}
|
|
|
|
func forum_exists(fid int) bool {
|
|
//fmt.Println(fid)
|
|
//fmt.Println(fid <= forumCapCount)
|
|
//fmt.Println(fid >= 0)
|
|
//fmt.Println(forums[fid].Name!="")
|
|
return (fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!=""
|
|
}
|