mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-20 09:26:23 -07:00
fixed posting bug, added more to template
This commit is contained in:
parent
ebf891e785
commit
ad93c12f3b
4 changed files with 68 additions and 52 deletions
|
@ -735,14 +735,18 @@ var manage_functions = map[string]ManageFunction{
|
|||
success := true
|
||||
for _,post := range op_posts {
|
||||
op_post := post.(PostTable)
|
||||
if buildThread(op_post) != nil {
|
||||
err := buildThread(op_post)
|
||||
if err != nil {
|
||||
success = false
|
||||
html += err.Error()+"<br />"
|
||||
} else {
|
||||
html += strconv.Itoa(op_post.ID)+" built successfully<br />"
|
||||
}
|
||||
}
|
||||
if success {
|
||||
html = "Threads rebuilt successfully."
|
||||
html += "Threads rebuilt successfully."
|
||||
} else {
|
||||
html = "Thread rebuilding failed somewhere (eventually we'll print out all the rebuilt threads."
|
||||
html += "Thread rebuilding failed."
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
|
|
@ -58,18 +58,14 @@ func buildThread(op_post PostTable) (err error) {
|
|||
interfaces = append(interfaces, &Wrapper{IName:"sections", Data: sections_arr})
|
||||
|
||||
wrapped := &Wrapper{IName: "threadpage",Data: interfaces}
|
||||
os.Remove("html/"+board_dir+"/res/"+op_id+".html")
|
||||
os.Remove(path.Join(config.DocumentRoot,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)
|
||||
thread_file,err := os.OpenFile(path.Join(config.DocumentRoot,board_dir+"/res/"+op_id+".html"),os.O_CREATE|os.O_RDWR,0777)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
return img_thread_tmpl.Execute(thread_file,wrapped)
|
||||
}
|
||||
return
|
||||
fmt.Println(thread_file)
|
||||
return err
|
||||
}
|
||||
|
||||
// checks to see if the poster's tripcode/name is banned, if the IP is banned, or if the file checksum is banned
|
||||
|
@ -183,7 +179,7 @@ func getThumbnailSize(w int, h int,size string) (new_w int, new_h int) {
|
|||
}
|
||||
|
||||
// inserts prepared post object into the SQL table so that it can be rendered
|
||||
func insertPost(writer *http.ResponseWriter, post *PostTable) error {
|
||||
func insertPost(writer *http.ResponseWriter, post PostTable) error {
|
||||
post_sql_str := "INSERT INTO `"+config.DBprefix+"posts` (`boardid`,`parentid`,`name`,`tripcode`,`email`,`subject`,`message`,`password`"
|
||||
if post.Filename != "" {
|
||||
post_sql_str += ",`filename`,`filename_original`,`file_checksum`,`filesize`,`image_w`,`image_h`,`thumb_w`,`thumb_h`"
|
||||
|
@ -204,6 +200,7 @@ func insertPost(writer *http.ResponseWriter, post *PostTable) error {
|
|||
} else {
|
||||
post_sql_str += "0);"
|
||||
}
|
||||
//fmt.Println(post_sql_str)
|
||||
_,err := db.Start(post_sql_str)
|
||||
if err != nil {
|
||||
exitWithErrorPage(*writer,err.Error())
|
||||
|
@ -215,7 +212,7 @@ func insertPost(writer *http.ResponseWriter, post *PostTable) error {
|
|||
func makePost(w http.ResponseWriter, r *http.Request) {
|
||||
request = *r
|
||||
writer = w
|
||||
request.ParseForm()
|
||||
|
||||
var post PostTable
|
||||
post.IName = "post"
|
||||
post.ParentID,_ = strconv.Atoi(request.FormValue("threadid"))
|
||||
|
@ -224,7 +221,6 @@ func makePost(w http.ResponseWriter, r *http.Request) {
|
|||
post.Email = db.Escape(request.FormValue("postemail"))
|
||||
post.Subject = db.Escape(request.FormValue("postsubject"))
|
||||
post.Message = db.Escape(request.FormValue("postmsg"))
|
||||
// TODO: change this to a checksum
|
||||
post.Password = md5_sum(request.FormValue("postpassword"))
|
||||
post.IP = request.RemoteAddr
|
||||
post.Timestamp = getSQLDateTime()
|
||||
|
@ -318,8 +314,8 @@ func makePost(w http.ResponseWriter, r *http.Request) {
|
|||
if post.Message == "" && post.Filename == "" {
|
||||
exitWithErrorPage(w,"Post must contain a message if no image is uploaded.")
|
||||
}
|
||||
|
||||
insertPost(&w, &post)
|
||||
fmt.Println("name: "+post.Name)
|
||||
insertPost(&w, post)
|
||||
http.Redirect(writer,&request,"/test/res/1.html",http.StatusFound)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
@ -20,6 +21,24 @@ type FooterData struct {
|
|||
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"add": func(a,b int) int {
|
||||
return a + b
|
||||
},
|
||||
"subtract": func(a,b int) int {
|
||||
return a - b
|
||||
},
|
||||
"len": func(arr []interface{}) int {
|
||||
return len(arr)
|
||||
},
|
||||
"getSlice": func(arr []interface{}, start, end int) []interface{} {
|
||||
slice := arr[start:end]
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
slice = make([]interface{}, 1)
|
||||
}
|
||||
}()
|
||||
return slice
|
||||
},
|
||||
"gt": func(a int, b int) bool {
|
||||
return a > b
|
||||
},
|
||||
|
@ -44,6 +63,13 @@ var funcMap = template.FuncMap{
|
|||
"getInterface":func(in []interface{}, index int) interface{} {
|
||||
return in[index]
|
||||
},
|
||||
"formatTimestamp": func(timestamp string) string {
|
||||
parsed,err := time.Parse("2006-01-02 15:04:05", timestamp)
|
||||
if err != nil {
|
||||
return time.Time{}.Format("Mon, January 02, 2006 15:04 PM")
|
||||
}
|
||||
return parsed.Format("Mon, January 02, 2006 15:04 PM")
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -70,37 +96,37 @@ var (
|
|||
func initTemplates() {
|
||||
global_footer_tmpl_bytes,tmpl_err := ioutil.ReadFile(config.TemplateDir+"/global_footer.html")
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_footer.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_footer.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
global_footer_tmpl_str = string(global_footer_tmpl_bytes)
|
||||
global_footer_tmpl,tmpl_err = template.New("global_footer_tmpl").Funcs(funcMap).Parse(string(global_footer_tmpl_str))
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_footer.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_footer.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
global_header_tmpl_bytes,tmpl_err := ioutil.ReadFile(config.TemplateDir+"/global_header.html")
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_header.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_header.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
global_header_tmpl_str = string(global_header_tmpl_bytes)
|
||||
global_header_tmpl,tmpl_err = template.New("global_header_tmpl").Funcs(funcMap).Parse(string(global_header_tmpl_str))
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_header.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/global_header.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
img_thread_tmpl_bytes,_ := ioutil.ReadFile(path.Join(config.TemplateDir,"img_thread.html"))
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html\": " + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
img_thread_tmpl_str = string(img_thread_tmpl_bytes)
|
||||
img_thread_tmpl,tmpl_err = template.New("img_thread_tmpl").Funcs(funcMap).Parse(img_thread_tmpl_str)
|
||||
if tmpl_err != nil {
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html\"")
|
||||
fmt.Println("Failed loading template \""+config.TemplateDir+"/img_thread.html: \"" + tmpl_err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
{{$config := getInterface .Data 0}}{{$post_arr := getInterface .Data 1}}{{$board_arr := getInterface .Data 2}}{{$section_arr := getInterface .Data 3}}
|
||||
<!DOCTYPE html>
|
||||
|
||||
{{$op := getInterface $post_arr 0}}
|
||||
{{$boardid := $op.BoardID}}
|
||||
{{$board := getInterface $board_arr.Data $op.BoardID}}
|
||||
|
||||
{{$boardid := subtract $op.BoardID 1}}
|
||||
{{$board := getInterface $board_arr.Data $boardid}}
|
||||
<html>
|
||||
<head>
|
||||
<title>{{$board.Title}}</title>
|
||||
|
@ -33,12 +31,12 @@
|
|||
</div>
|
||||
<hr />
|
||||
<div id="threadlinks-top">
|
||||
<a href="board.html" >Return</a><br />
|
||||
<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/board.html" >Return</a><br />
|
||||
<a href="{{$op.ID}}-100.html">First 100 posts</a><br />
|
||||
<a href="{{$op.ID}}+50.html">Last 50 posts</a><br />
|
||||
</div>
|
||||
<div id="right-sidelinks">
|
||||
<a href="catalog.html">Board catalog</a><br />
|
||||
<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/catalog.html">Board catalog</a><br />
|
||||
</div>
|
||||
|
||||
<div id="postbox-area">
|
||||
|
@ -52,7 +50,7 @@
|
|||
<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>
|
||||
<tr><td class="postblock">File</td><td><input name="imagefile" size="31" type="file"><input type="checkbox" id="spoiler"/><label for="spoiler">Spoiler</label></td></tr>
|
||||
<tr><td class="postblock">File</td><td><input name="imagefile" size="31" type="file"><input type="checkbox" id="spoiler" name="spoiler"/><label for="spoiler">Spoiler</label></td></tr>
|
||||
<tr><td class="postblock">Password</td><td><input type="text" name="postpassword" size="14" /> (for post/file deletion)</td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
@ -60,30 +58,22 @@
|
|||
</div>
|
||||
<hr />
|
||||
<div id="content">
|
||||
<div class="thread" id="{{$op.ID}}">
|
||||
{{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="{{$op.ID}}" /> <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="/test/res/{{$op.ID}}.html#{{$op.ID}}">No.</a> <a href="/test/res/{{$op.ID}}.html#i{{$op.ID}}">{{$op.ID}}</a></label> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
<div class="thread" id="{{$op.ID}}">{{range $post_num,$post := $post_arr}}{{if intEq $post_num 0}}
|
||||
{{if stringNeq $post.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="{{$post.ThumbW}}" height="{{$post.ThumbH}}" class="thumbnail"/>{{end}}
|
||||
<label class="post-info"><input type="checkbox" id="{{$post.ID}}" /> <span class="subject">{{$post.Subject}}</span> <span class="postername"><a href="mailto:{{$post.Email}}">{{$post.Name}}</a></span><span class="tripcode">!{{$post.Tripcode}}</span> {{formatTimestamp $post.Timestamp}} <a href="/{{$board.Dir}}/res/{{$post.ID}}.html#{{$post.ID}}">No.</a> <a href="/{{$board.Dir}}/res/{{$post.ID}}.html#i{{$post.ID}}">{{$post.ID}}</a></label> <span class="post-links"> <span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
<div class="posttext">
|
||||
{{$op.Message}}
|
||||
</div>
|
||||
<div class="post" id="74770">
|
||||
<label class="post-info"><input type="checkbox" id="135693079632" /> <span class="postername">Anonymous</span> Tue, January 02, 2013 1:55:PM <a href="135693079632">No.</a> <a href="74770i">74770</a></label> <span class="post-links"><span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
<span class="file-info">File: <a href="135693079632s.png">135693079632s.png</a> - (100.01KB , 200,200, 135693079632s.png )</span><br />
|
||||
<img src="135693079632s.png" width="94" height="125" class="thumbnail" />
|
||||
{{$post.Message}}
|
||||
</div>{{else}}
|
||||
<div class="post" id="{{$post.ID}}">
|
||||
<label class="post-info"><input type="checkbox" id="{{$post.ID}}" /> <span class="postername">{{$post.Name}}</span> {{formatTimestamp $post.Timestamp}} <a href="135693079632">No.</a> <a href="{{$post.ID}}i">{{$post.ID}}</a></label> <span class="post-links"><span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
{{if stringNeq $post.Filename ""}}<span class="file-info">File: <a href="{{$board.Dir}}/src/{{$post.Filename}}">{{$post.Filename}}</a> - (100.01KB , {{$post.ImageW}},{{$post.ImageH}}, {{$post.FilenameOriginal}} )</span><br />
|
||||
<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/src/{{$post.Filename}}" target="_top"><img src="{{$config.SiteWebfolder}}{{$board.Dir}}/src/{{$post.Filename}}" width="{{$post.ThumbW}}" height="{{$post.ThumbH}}" class="thumbnail" /></a>{{end}}
|
||||
|
||||
<div class="posttext">
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br/><br/>
|
||||
<span class="spoiler">Lorem ipsum</span> dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br/>
|
||||
{{$post.Message}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="post" id="74770">
|
||||
<label class="post-info"><input type="checkbox" id="135693079632" /> <span class="postername">Anonymous</span> Tue, January 02, 2013 1:55:PM <a href="135693079632">No.</a> <a href="74770i">74770</a></label> <span class="post-links"><span class="thread-ddown">[<a href="javascript:void(0)">▼</a>]</span></span><br />
|
||||
<div class="posttext">
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
</div>
|
||||
</div>
|
||||
</div>{{end}}{{end}}
|
||||
</div>
|
||||
<hr />
|
||||
<div id="left-bottom-content">
|
||||
|
@ -92,13 +82,13 @@
|
|||
</table>
|
||||
|
||||
<span id="boardmenu-bottom">
|
||||
[ <a href="/test/">test</a> / <a href="/test2/">test2</a> ]
|
||||
[{{range $i, $board := $board_arr.Data}} {{if gt $i 0}}/{{end}} <a href="/{{$board.Dir}}/">{{$board.Dir}}</a> {{end}}]
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div id="right-bottom-content">
|
||||
<span id="threadlinks-bottom">
|
||||
[<a href="board.html">Return</a>] [<a href="{{$op.ID}}-100.html">First 100 posts</a>] [<a href="{{$op.ID}}+50.html">Last 50 posts</a>]
|
||||
[<a href="{{$config.SiteWebfolder}}{{$board.Dir}}/board.html">Return</a>] [<a href="{{$op.ID}}-100.html">First 100 posts</a>] [<a href="{{$op.ID}}+50.html">Last 50 posts</a>]
|
||||
</span>
|
||||
|
||||
<div id="report-delbox">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue