diff --git a/src/manage.go b/src/manage.go
index 4ea482f2..85ad2ec9 100644
--- a/src/manage.go
+++ b/src/manage.go
@@ -565,6 +565,7 @@ var manage_functions = map[string]ManageFunction{
html += "Admin stuff
\nManage staff
\n" +
"Execute SQL statement(s)
\n" +
"Rebuild front page
\n" +
+ "Rebuild threads
\n" +
"Add/edit/delete boards
\n"
}
if rank >= 2 {
@@ -715,76 +716,38 @@ var manage_functions = map[string]ManageFunction{
//html += manage_functions["rebuildfront"].Callback()+"\n
\n"
return
}},
- "rebuildposts": {
+ "rebuildthreads": {
Permissions:3,
Callback: func() (html string) {
initTemplates()
// variables for sections table
- var posts []interface{}
-
- results,err := db.Start("SELECT * FROM `"+config.DBprefix+"posts` WHERE `deleted_timestamp` IS NULL;")
- if err != nil {
- error_log.Write(err.Error())
- return err.Error()
- }
+ op_posts := getPostArr("`deleted_timestamp` IS NULL AND `parentid` = 0")
+ board_arr := getBoardArr("")
+ sections_arr := getSectionArr("")
- rows, err := results.GetRows()
- if err != nil {
- error_log.Write(err.Error())
- return err.Error()
- }
-
- if len(rows) > 0 {
- for _, row := range rows {
- var post PostTable
- post.IName = "post"
- post.ID,_ = strconv.Atoi(string(row[0].([]byte)))
- post.BoardID,_ = strconv.Atoi(string(row[1].([]byte)))
- post.ParentID,_ = strconv.Atoi(string(row[2].([]byte)))
- post.Name = string(row[3].([]byte))
- post.Tripcode = string(row[4].([]byte))
- post.Email = string(row[5].([]byte))
- post.Subject = string(row[6].([]byte))
- post.Message = string(row[7].([]byte))
- post.Password = string(row[8].([]byte))
- post.Filename = string(row[9].([]byte))
- post.FilenameOriginal = string(row[10].([]byte))
- post.FileChecksum = string(row[11].([]byte))
- post.Filesize = string(row[12].([]byte))
- post.ImageW,_ = strconv.Atoi(string(row[13].([]byte)))
- post.ImageH,_ = strconv.Atoi(string(row[14].([]byte)))
- post.ThumbW,_ = strconv.Atoi(string(row[15].([]byte)))
- post.ThumbH,_ = strconv.Atoi(string(row[16].([]byte)))
- post.IP = string(row[17].([]byte))
- post.Tag = string(row[18].([]byte))
- post.Timestamp = string(row[19].([]byte))
- post.Autosage,_ = strconv.Atoi(string(row[20].([]byte)))
- post.PosterAuthority,_ = strconv.Atoi(string(row[21].([]byte)))
- if row[23] == nil {
- post.Bumped = ""
- } else {
- post.Bumped = string(row[23].([]byte))
+ for _,post := range op_posts {
+ op_post := post.(PostTable)
+ op_id := strconv.Itoa(op_post.ID)
+ var board_dir string
+ for _,board_i := range board_arr {
+ board := board_i.(BoardsTable)
+ if board.ID == op_post.BoardID {
+ board_dir = board.Dir
+ break
}
- post.Stickied = (string(row[24].([]byte)) == "1")
- post.Locked = (string(row[25].([]byte)) == "1")
- post.Reviewed = (string(row[26].([]byte)) == "1")
- if row[27] == nil {
- post.Sillytag = false
- } else {
- post.Sillytag = (string(row[27].([]byte)) == "1")
- }
- posts = append(posts, post)
}
+ thread_posts := getPostArr("(`parentid` = "+op_id+" OR `id` = "+op_id+")")
+
var interfaces []interface{}
interfaces = append(interfaces, config)
- interfaces = append(interfaces, posts)
- interfaces = append(interfaces, &Wrapper{IName:"boards", Data: getBoardArr()})
- interfaces = append(interfaces, &Wrapper{IName:"sections", Data: getSectionArr()})
+ interfaces = append(interfaces, thread_posts)
+ interfaces = append(interfaces, &Wrapper{IName:"boards", Data: board_arr})
+ interfaces = append(interfaces, &Wrapper{IName:"sections", Data: sections_arr})
wrapped := &Wrapper{IName: "threadpage",Data: interfaces}
- os.Remove("html/threaded.html")
- thread_file,err := os.OpenFile("html/threaded.html",os.O_CREATE|os.O_RDWR,0777)
+ os.Remove("html/"+board_dir+"/res/"+op_id+".html")
+ thread_file,err := os.OpenFile("html/"+board_dir+"/res/"+op_id+".html",os.O_CREATE|os.O_RDWR,0777)
err = img_thread_tmpl.Execute(thread_file,wrapped)
if err == nil {
if err != nil {
@@ -793,8 +756,6 @@ var manage_functions = map[string]ManageFunction{
return "Posts rebuilt successfully.
"
}
}
- } else {
- // no posts
}
return
}},
diff --git a/src/template.go b/src/template.go
index 706323a7..526f0b6d 100644
--- a/src/template.go
+++ b/src/template.go
@@ -29,6 +29,9 @@ var funcMap = template.FuncMap{
"stringEq": func(a, b string) bool {
return a == b
},
+ "stringNeq": func(a, b string) bool {
+ return a != b
+ },
"intEq": func(a, b int) bool {
return a == b
},
diff --git a/src/types.go b/src/types.go
index 749fa410..9be7452d 100644
--- a/src/types.go
+++ b/src/types.go
@@ -57,29 +57,29 @@ type BannedTripcodesTable struct {
type BoardsTable struct {
IName string
- ID uint8
- Order uint8
+ ID int
+ Order int
Dir string
- Type uint8
- FirstPost uint
- UploadType uint8
+ Type int
+ FirstPost int
+ UploadType int
Title string
Subtitle string
Description string
Section int
MaxImageSize int
- MaxPages uint8
+ MaxPages int
Locale string
DefaultStyle string
Locked bool
CreatedOn string
Anonymous string
ForcedAnon string
- MaxAge uint
- MarkPage uint8
- AutosageAfter uint
- NoImagesAfter uint
- MaxMessageLength uint
+ MaxAge int
+ MarkPage int
+ AutosageAfter int
+ NoImagesAfter int
+ MaxMessageLength int
EmbedsAllowed string
RedirectToThread bool
ShowId bool
@@ -157,9 +157,9 @@ type PollResultsTable struct {
type PostTable struct {
IName string
- ID uint
- BoarID uint8
- ParentID uint
+ ID int
+ BoardID int
+ ParentID int
Name string
Tripcode string
Email string
@@ -170,15 +170,15 @@ type PostTable struct {
FilenameOriginal string
FileChecksum string
Filesize string
- ImageW uint16
- ImageH uint16
- ThumbW uint16
- ThumbH uint16
+ ImageW int
+ ImageH int
+ ThumbW int
+ ThumbH int
IP string
Tag string
Timestamp string
- Autosage uint8
- PosterAuthority uint8
+ Autosage int
+ PosterAuthority int
DeletedTimestamp string
Bumped string
Stickied bool
diff --git a/src/util.go b/src/util.go
index 525b6181..7eafaf12 100644
--- a/src/util.go
+++ b/src/util.go
@@ -56,8 +56,11 @@ func bcrypt_sum(str string) string {
return hash
}
-func getBoardArr() (boards []interface{}) {
- results,err := db.Start("SELECT * FROM `"+config.DBprefix+"boards` ORDER BY `order`;")
+func getBoardArr(where string) (boards []interface{}) {
+ if where == "" {
+ where = "1"
+ }
+ results,err := db.Start("SELECT * FROM `"+config.DBprefix+"boards` WHERE "+where+" ORDER BY `order`;")
if err != nil {
error_log.Write(err.Error())
return
@@ -67,7 +70,6 @@ func getBoardArr() (boards []interface{}) {
error_log.Write(err.Error())
return
}
-
for _,row := range rows {
var board BoardsTable
board.IName = "board"
@@ -105,8 +107,70 @@ func getBoardArr() (boards []interface{}) {
return
}
-func getSectionArr() (sections []interface{}) {
- results,err := db.Start("SELECT * FROM `"+config.DBprefix+"sections` ORDER BY `order`;")
+func getPostArr(where string) (posts []interface{}) {
+ if where == "" {
+ where = "1"
+ }
+ results,err := db.Start("SELECT * FROM `"+config.DBprefix+"posts` WHERE "+where+";")
+ if err != nil {
+ error_log.Write(err.Error())
+ return
+ }
+
+ rows, err := results.GetRows()
+ if err != nil {
+ error_log.Write(err.Error())
+ return
+ }
+
+ for _, row := range rows {
+ var post PostTable
+ post.IName = "post"
+ post.ID,_ = strconv.Atoi(string(row[0].([]byte)))
+ post.BoardID,_ = strconv.Atoi(string(row[1].([]byte)))
+ post.ParentID,_ = strconv.Atoi(string(row[2].([]byte)))
+ post.Name = string(row[3].([]byte))
+ post.Tripcode = string(row[4].([]byte))
+ post.Email = string(row[5].([]byte))
+ post.Subject = string(row[6].([]byte))
+ post.Message = string(row[7].([]byte))
+ post.Password = string(row[8].([]byte))
+ post.Filename = string(row[9].([]byte))
+ post.FilenameOriginal = string(row[10].([]byte))
+ post.FileChecksum = string(row[11].([]byte))
+ post.Filesize = string(row[12].([]byte))
+ post.ImageW,_ = strconv.Atoi(string(row[13].([]byte)))
+ post.ImageH,_ = strconv.Atoi(string(row[14].([]byte)))
+ post.ThumbW,_ = strconv.Atoi(string(row[15].([]byte)))
+ post.ThumbH,_ = strconv.Atoi(string(row[16].([]byte)))
+ post.IP = string(row[17].([]byte))
+ post.Tag = string(row[18].([]byte))
+ post.Timestamp = string(row[19].([]byte))
+ post.Autosage,_ = strconv.Atoi(string(row[20].([]byte)))
+ post.PosterAuthority,_ = strconv.Atoi(string(row[21].([]byte)))
+ if row[23] == nil {
+ post.Bumped = ""
+ } else {
+ post.Bumped = string(row[23].([]byte))
+ }
+ post.Stickied = (string(row[24].([]byte)) == "1")
+ post.Locked = (string(row[25].([]byte)) == "1")
+ post.Reviewed = (string(row[26].([]byte)) == "1")
+ if row[27] == nil {
+ post.Sillytag = false
+ } else {
+ post.Sillytag = (string(row[27].([]byte)) == "1")
+ }
+ posts = append(posts, post)
+ }
+ return
+}
+
+func getSectionArr(where string) (sections []interface{}) {
+ if where == "" {
+ where = "1"
+ }
+ results,err := db.Start("SELECT * FROM `"+config.DBprefix+"sections` WHERE "+where+" ORDER BY `order`;")
if err != nil {
error_log.Write(err.Error())
return
@@ -116,7 +180,6 @@ func getSectionArr() (sections []interface{}) {
error_log.Write(err.Error())
return
}
-
for _,row := range rows {
var section BoardSectionsTable
section.IName = "section"
diff --git a/templates/img_thread.html b/templates/img_thread.html
index 6233a8ab..4cd1d6d6 100644
--- a/templates/img_thread.html
+++ b/templates/img_thread.html
@@ -2,9 +2,12 @@
{{$op := getInterface $post_arr 0}}
+{{$boardid := $op.BoardID}}
+{{$board := getInterface $board_arr.Data $op.BoardID}}
+