1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-20 09:26:23 -07:00

working on thread/post building

This commit is contained in:
Joshua Merrell 2013-05-29 13:43:12 -07:00
parent dbafe32abd
commit 6eeaae787a
5 changed files with 123 additions and 93 deletions

View file

@ -565,6 +565,7 @@ var manage_functions = map[string]ManageFunction{
html += "<b>Admin stuff</b><br />\n<a href=\"javascript:void(0)\" id=\"staff\" class=\"staffmenu-item\">Manage staff</a><br />\n" +
"<a href=\"javascript:void(0)\" id=\"executesql\" class=\"staffmenu-item\">Execute SQL statement(s)</a><br />\n" +
"<a href=\"javascript:void(0)\" id=\"rebuildfront\" class=\"staffmenu-item\">Rebuild front page</a><br />\n" +
"<a href=\"javascript:void(0)\" id=\"rebuildthreads\" class=\"staffmenu-item\">Rebuild threads</a><br />\n" +
"<a href=\"javascript:void(0)\" id=\"manageboards\" class=\"staffmenu-item\">Add/edit/delete boards</a><br />\n"
}
if rank >= 2 {
@ -715,76 +716,38 @@ var manage_functions = map[string]ManageFunction{
//html += manage_functions["rebuildfront"].Callback()+"\n<br />\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.<br />"
}
}
} else {
// no posts
}
return
}},

View file

@ -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
},

View file

@ -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

View file

@ -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"

View file

@ -2,9 +2,12 @@
<!DOCTYPE html>
{{$op := getInterface $post_arr 0}}
{{$boardid := $op.BoardID}}
{{$board := getInterface $board_arr.Data $op.BoardID}}
<html>
<head>
<title>Test</title>
<title>{{$board.Title}}</title>
<script type="text/javascript" src="/javascript/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/javascript/msgpack.js"></script>
<script type="text/javascript">
@ -25,8 +28,8 @@
{{end}} </ul>
</div>
<div id="top-pane">
<span id="board-title">Test</span><br />
<span id="board-subtitle">Testing subtitle</span>
<span id="board-title">{{$board.Title}}</span><br />
<span id="board-subtitle">{{$board.Subtitle}}</span>
</div>
<hr />
<div id="threadlinks-top">
@ -43,7 +46,7 @@
<a href="#">Open Quick Reply box</a>
<table id="postbox-static">
<form name="postform" action="/post" method="POST">
<tr><td class="postblock">Name</td><td><input type="text" name="postname" maxlength="75" size="28" value="Name" onFocus="if(this.value=='Name') {this,value= ''}" onBlur="if(this.value == '') { this.value = 'Name' }"/></td></tr>
<tr><td class="postblock">Name</td><td><input type="text" name="postname" maxlength="75" size="28" value="Name" onFocus="if(this.value=='Name') {this,value= ''}" onBlur="if(this.value == '') {this.value = 'Name'}"/></td></tr>
<tr><td class="postblock">Email</td><td><input type="text" name="postemail" maxlength="75" size="28" /></td></tr>
<tr><td class="postblock">Subject</td><td><input type="text" name="postsubject" maxlength="75" size="35" /><input type="submit" value="Post"/></td></tr>
<tr><td class="postblock">Message</td><td><textarea rows="4" cols="48" name="postmsg"></textarea></td></tr>
@ -56,9 +59,9 @@
<hr />
<div id="content">
<div class="thread" id="74769">
<span class="file-info">File: <a href="135710945820.jpg">135710945820.jpg</a> - (142.91KB , 756x888 , Chibi_Series___Flower_Forte_by_kubus_sama.jpg )</span><br />
<img src="135710945820s.jpg" width="170" height="200" class="thumbnail"/>
<label class="post-info"><input type="checkbox" id="74769" /> <span class="subject">Sup</span> <span class="postername"><a href="mailto:admin@lunachan.net">Zeke Roa</a></span><span class="tripcode">!ska.Jj.P5I</span> Tue, January 01, 2013 10:50 PM <a href="74769">No.</a> <a href="74769">74769</a></label> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span></span><br />
{{if stringNeq $op.Filename ""}}<span class="file-info">File: <a href="135710945820.jpg">135710945820.jpg</a> - (142.91KB , 756x888 , Chibi_Series___Flower_Forte_by_kubus_sama.jpg )</span><br />
<img src="135710945820s.jpg" width="170" height="200" class="thumbnail"/>{{end}}
<label class="post-info"><input type="checkbox" id="74769" /> <span class="subject">{{$op.Subject}}</span> <span class="postername"><a href="mailto:{{$op.Email}}">{{$op.Name}}</a></span><span class="tripcode">!{{$op.Tripcode}}</span> Tue, January 01, 2013 10:50 PM <a href="74769">No.</a> <a href="74769">74769</a></label> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">&#9660;</a>]</span></span><br />
<div class="posttext">
{{$op.Message}}
</div>