diff --git a/README.md b/README.md index 51f30cee..bfa338e7 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,12 @@ We're looking for ways to clean-up the plugin system so that all of them (except # Images ![Tempra Simple Theme](https://github.com/Azareal/Gosora/blob/master/images/tempra-simple.png) +![Tempra Simple Topic List](https://github.com/Azareal/Gosora/blob/master/images/topic-list.png) + ![Tempra Conflux Theme](https://github.com/Azareal/Gosora/blob/master/images/tempra-conflux.png) +![Tempra Conflux Mobile](https://github.com/Azareal/Gosora/blob/master/images/tempra-conflux-mobile-320px.png) + ![Cosmo Conflux Theme](https://github.com/Azareal/Gosora/blob/master/images/cosmo-conflux.png) ![Cosmo Theme](https://github.com/Azareal/Gosora/blob/master/images/cosmo.png) diff --git a/images/tempra-conflux-topic-list.png b/images/tempra-conflux-topic-list.png new file mode 100644 index 00000000..d6581b3f Binary files /dev/null and b/images/tempra-conflux-topic-list.png differ diff --git a/images/topic-list.PNG b/images/topic-list.PNG deleted file mode 100644 index da856fbc..00000000 Binary files a/images/topic-list.PNG and /dev/null differ diff --git a/images/topic-list.png b/images/topic-list.png new file mode 100644 index 00000000..7988d281 Binary files /dev/null and b/images/topic-list.png differ diff --git a/main.go b/main.go index 51afc0c0..5e011c0a 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func compile_templates() { log.Print("Compiling the templates") - topic := TopicUser{1,"Blah",template.HTML("Hey there!"),0,false,false,"",0,"","127.0.0.1",0,"","",no_css_tmpl,0,"","","","",58} + topic := TopicUser{1,"Blah",template.HTML("Hey there!"),0,false,false,"Date","Date",0,"","127.0.0.1",0,"","",no_css_tmpl,0,"","","","",58} var replyList []Reply replyList = append(replyList, Reply{0,0,"",template.HTML("Yo!"),0,"","",0,0,"",no_css_tmpl,0,"","","","",0,"127.0.0.1"}) @@ -74,11 +74,13 @@ func compile_templates() { forums_page := ForumsPage{"Forum List",user,noticeList,forumList,0} forums_tmpl := c.compile_template("forums.html","templates/","ForumsPage", forums_page, varList) - var topicList []TopicUser - topicList = append(topicList, TopicUser{1,"Topic Title","The topic content.",1,false,false,"",1,"","127.0.0.1",0,"Admin","","",0,"","","","",58}) - topics_page := TopicsPage{"Topic List",user,noticeList,topicList,""} + var topicsList []TopicsRow + topicsList = append(topicsList, TopicsRow{1,"Topic Title","The topic content.",1,false,false,"Date","Date",1,"","127.0.0.1",0,"Admin","","",0,"","","","",58,"General"}) + topics_page := TopicsPage{"Topic List",user,noticeList,topicsList,""} topics_tmpl := c.compile_template("topics.html","templates/","TopicsPage", topics_page, varList) + var topicList []TopicUser + topicList = append(topicList, TopicUser{1,"Topic Title","The topic content.",1,false,false,"Date","Date",1,"","127.0.0.1",0,"Admin","","",0,"","","","",58}) forum_item := Forum{1,"General Forum",true,"all",0,"",0,"",0,""} forum_page := ForumPage{"General Forum",user,noticeList,topicList,forum_item,1,1,nil} forum_tmpl := c.compile_template("forum.html","templates/","ForumPage", forum_page, varList) diff --git a/mysql.go b/mysql.go index 0edb2ead..373c70b9 100644 --- a/mysql.go +++ b/mysql.go @@ -118,25 +118,25 @@ func init_database(err error) { } log.Print("Preparing get_forum_topics statement.") - get_forum_topics_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy desc") + get_forum_topics_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy desc") if err != nil { log.Fatal(err) } log.Print("Preparing get_forum_topics_offset statement.") - get_forum_topics_offset_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid WHERE topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC limit ?, " + strconv.Itoa(items_per_page)) + get_forum_topics_offset_stmt, err = db.Prepare("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid WHERE topics.parentID = ? order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC limit ?, " + strconv.Itoa(items_per_page)) if err != nil { log.Fatal(err) } log.Print("Preparing create_topic statement.") - create_topic_stmt, err = db.Prepare("insert into topics(parentID,title,content,parsed_content,createdAt,ipaddress,createdBy) VALUES(?,?,?,?,NOW(),?,?)") + create_topic_stmt, err = db.Prepare("insert into topics(parentID,title,content,parsed_content,createdAt,lastReplyAt,ipaddress,createdBy) VALUES(?,?,?,?,NOW(),NOW(),?,?)") if err != nil { log.Fatal(err) } log.Print("Preparing create_report statement.") - create_report_stmt, err = db.Prepare("INSERT INTO topics(title,content,parsed_content,createdAt,createdBy,data,parentID) VALUES(?,?,?,NOW(),?,?,1)") + create_report_stmt, err = db.Prepare("INSERT INTO topics(title,content,parsed_content,createdAt,lastReplyAt,createdBy,data,parentID) VALUES(?,?,?,NOW(),NOW(),?,?,1)") if err != nil { log.Fatal(err) } @@ -148,7 +148,7 @@ func init_database(err error) { } log.Print("Preparing add_replies_to_topic statement.") - add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ? WHERE tid = ?") + add_replies_to_topic_stmt, err = db.Prepare("UPDATE topics SET postCount = postCount + ?, lastReplyAt = NOW() WHERE tid = ?") if err != nil { log.Fatal(err) } @@ -525,7 +525,7 @@ func init_database(err error) { fill_forum_id_gap(i, forum.ID) } - if forum.LastTopicID != 0 { + /*if forum.LastTopicID != 0 { forum.LastTopicTime, err = relative_time(forum.LastTopicTime) if err != nil { log.Fatal(err) @@ -533,7 +533,7 @@ func init_database(err error) { } else { forum.LastTopic = "None" forum.LastTopicTime = "" - } + }*/ log.Print("Adding the " + forum.Name + " forum") forums = append(forums,forum) diff --git a/images/new-topic-list.PNG b/old-images/new-topic-list.PNG similarity index 100% rename from images/new-topic-list.PNG rename to old-images/new-topic-list.PNG diff --git a/pages.go b/pages.go index 579e77a3..db61fa48 100644 --- a/pages.go +++ b/pages.go @@ -28,7 +28,7 @@ type TopicsPage struct Title string CurrentUser User NoticeList []string - ItemList []TopicUser + ItemList []TopicsRow ExtData interface{} } diff --git a/routes.go b/routes.go index 08dfe094..e559054d 100644 --- a/routes.go +++ b/routes.go @@ -100,17 +100,17 @@ func route_topics(w http.ResponseWriter, r *http.Request){ } } - var topicList []TopicUser - rows, err := db.Query("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where parentID in("+strings.Join(fidList,",")+") order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC") + var topicList []TopicsRow + rows, err := db.Query("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.lastReplyAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid where parentID in("+strings.Join(fidList,",")+") order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC") //rows, err := get_topic_list_stmt.Query() if err != nil { InternalError(err,w,r) return } - topicItem := TopicUser{ID: 0,} + topicItem := TopicsRow{ID: 0,} for rows.Next() { - err := rows.Scan(&topicItem.ID, &topicItem.Title, &topicItem.Content, &topicItem.CreatedBy, &topicItem.Is_Closed, &topicItem.Sticky, &topicItem.CreatedAt, &topicItem.ParentID, &topicItem.CreatedByName, &topicItem.Avatar) + err := rows.Scan(&topicItem.ID, &topicItem.Title, &topicItem.Content, &topicItem.CreatedBy, &topicItem.Is_Closed, &topicItem.Sticky, &topicItem.CreatedAt, &topicItem.LastReplyAt, &topicItem.ParentID, &topicItem.CreatedByName, &topicItem.Avatar) if err != nil { InternalError(err,w,r) return @@ -124,8 +124,23 @@ func route_topics(w http.ResponseWriter, r *http.Request){ topicItem.Avatar = strings.Replace(noavatar,"{id}",strconv.Itoa(topicItem.CreatedBy),1) } + if topicItem.ParentID >= 0 { + topicItem.ForumName = forums[topicItem.ParentID].Name + } else { + topicItem.ForumName = "" + } + + /*topicItem.CreatedAt, err = relative_time(topicItem.CreatedAt) + if err != nil { + InternalError(err,w,r) + }*/ + topicItem.LastReplyAt, err = relative_time(topicItem.LastReplyAt) + if err != nil { + InternalError(err,w,r) + } + if hooks["trow_assign"] != nil { - topicItem = run_hook("trow_assign", topicItem).(TopicUser) + topicItem = run_hook("trow_assign", topicItem).(TopicsRow) } topicList = append(topicList, topicItem) } @@ -185,7 +200,7 @@ func route_forum(w http.ResponseWriter, r *http.Request){ var topicList []TopicUser topicItem := TopicUser{ID: 0} for rows.Next() { - err := rows.Scan(&topicItem.ID, &topicItem.Title, &topicItem.Content, &topicItem.CreatedBy, &topicItem.Is_Closed, &topicItem.Sticky, &topicItem.CreatedAt, &topicItem.ParentID, &topicItem.CreatedByName, &topicItem.Avatar) + err := rows.Scan(&topicItem.ID, &topicItem.Title, &topicItem.Content, &topicItem.CreatedBy, &topicItem.Is_Closed, &topicItem.Sticky, &topicItem.CreatedAt, &topicItem.LastReplyAt, &topicItem.ParentID, &topicItem.CreatedByName, &topicItem.Avatar) if err != nil { InternalError(err,w,r) return @@ -199,6 +214,11 @@ func route_forum(w http.ResponseWriter, r *http.Request){ topicItem.Avatar = strings.Replace(noavatar,"{id}",strconv.Itoa(topicItem.CreatedBy),1) } + topicItem.LastReplyAt, err = relative_time(topicItem.LastReplyAt) + if err != nil { + InternalError(err,w,r) + } + if hooks["trow_assign"] != nil { topicItem = run_hook("trow_assign", topicItem).(TopicUser) } @@ -229,12 +249,23 @@ func route_forums(w http.ResponseWriter, r *http.Request){ } var forumList []Forum + var err error group := groups[user.Group] //fmt.Println(group.CanSee) for _, fid := range group.CanSee { //fmt.Println(forums[fid]) - if forums[fid].Active && forums[fid].Name != "" { - forumList = append(forumList, forums[fid]) + forum := forums[fid] + if forum.Active && forum.Name != "" { + if forum.LastTopicID != 0 { + forum.LastTopicTime, err = relative_time(forum.LastTopicTime) + if err != nil { + InternalError(err,w,r) + } + } else { + forum.LastTopic = "None" + forum.LastTopicTime = "" + } + forumList = append(forumList, forum) } } diff --git a/template_forum.go b/template_forum.go index aae49de0..55a5e609 100644 --- a/template_forum.go +++ b/template_forum.go @@ -95,16 +95,18 @@ if item.Is_Closed { w.Write(forum_22) } w.Write(forum_23) +w.Write([]byte(item.LastReplyAt)) +w.Write(forum_24) } } else { -w.Write(forum_24) -if tmpl_forum_vars.CurrentUser.Perms.CreateTopic { w.Write(forum_25) -w.Write([]byte(strconv.Itoa(tmpl_forum_vars.Forum.ID))) +if tmpl_forum_vars.CurrentUser.Perms.CreateTopic { w.Write(forum_26) -} +w.Write([]byte(strconv.Itoa(tmpl_forum_vars.Forum.ID))) w.Write(forum_27) } w.Write(forum_28) +} +w.Write(forum_29) w.Write(footer_0) } diff --git a/template_list.go b/template_list.go index 543afa80..0001b432 100644 --- a/template_list.go +++ b/template_list.go @@ -405,12 +405,19 @@ var topics_6 []byte = []byte(`"> `) var topics_8 []byte = []byte(` `) -var topics_9 []byte = []byte(`🔒︎`) -var topics_10 []byte = []byte(` +var topics_9 []byte = []byte(``) +var topics_11 []byte = []byte(` `) +var topics_12 []byte = []byte(`🔒︎`) +var topics_13 []byte = []byte(` + `) +var topics_14 []byte = []byte(` `) -var topics_11 []byte = []byte(`
There aren't any topics yet.
`) -var topics_12 []byte = []byte(` +var topics_15 []byte = []byte(`
There aren't any topics yet.`) +var topics_16 []byte = []byte(` Start one?`) +var topics_17 []byte = []byte(`
`) +var topics_18 []byte = []byte(` `) var forum_0 []byte = []byte(`
`) var forum_21 []byte = []byte(` `) -var forum_22 []byte = []byte(`🔒︎`) +var forum_22 []byte = []byte(`🔒︎`) var forum_23 []byte = []byte(` + `) +var forum_24 []byte = []byte(`
`) -var forum_24 []byte = []byte(`
There aren't any topics in this forum yet.`) -var forum_25 []byte = []byte(` Start one?`) -var forum_27 []byte = []byte(`
`) -var forum_28 []byte = []byte(` +var forum_25 []byte = []byte(`
There aren't any topics in this forum yet.`) +var forum_26 []byte = []byte(` Start one?`) +var forum_28 []byte = []byte(`
`) +var forum_29 []byte = []byte(` `) diff --git a/template_profile.go b/template_profile.go index 609431b3..e71179bf 100644 --- a/template_profile.go +++ b/template_profile.go @@ -1,7 +1,7 @@ /* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */ package main -import "io" import "strconv" +import "io" func init() { template_profile_handle = template_profile diff --git a/template_topic_alt.go b/template_topic_alt.go index 0ee3cff5..cb82e6fc 100644 --- a/template_topic_alt.go +++ b/template_topic_alt.go @@ -1,8 +1,8 @@ /* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */ package main +import "html/template" import "io" import "strconv" -import "html/template" func init() { template_topic_alt_handle = template_topic_alt diff --git a/template_topics.go b/template_topics.go index 274ab14a..e42c7c91 100644 --- a/template_topics.go +++ b/template_topics.go @@ -61,14 +61,27 @@ w.Write([]byte(strconv.Itoa(item.ID))) w.Write(topics_7) w.Write([]byte(item.Title)) w.Write(topics_8) -if item.Is_Closed { +if item.ForumName != "" { w.Write(topics_9) -} +w.Write([]byte(strconv.Itoa(item.ParentID))) w.Write(topics_10) -} -} else { +w.Write([]byte(item.ForumName)) w.Write(topics_11) } +if item.Is_Closed { w.Write(topics_12) +} +w.Write(topics_13) +w.Write([]byte(item.LastReplyAt)) +w.Write(topics_14) +} +} else { +w.Write(topics_15) +if tmpl_topics_vars.CurrentUser.Perms.CreateTopic { +w.Write(topics_16) +} +w.Write(topics_17) +} +w.Write(topics_18) w.Write(footer_0) } diff --git a/templates/forum.html b/templates/forum.html index a9915af1..b8a21b9a 100644 --- a/templates/forum.html +++ b/templates/forum.html @@ -8,7 +8,8 @@
{{range .ItemList}}
- {{.Title}} {{if .Is_Closed}}🔒︎{{end}} + {{.Title}} {{if .Is_Closed}}🔒︎{{end}} + {{.LastReplyAt}}
{{else}}
There aren't any topics in this forum yet.{{if .CurrentUser.Perms.CreateTopic}} Start one?{{end}}
{{end}}
diff --git a/templates/topics.html b/templates/topics.html index 1631b77d..1ba9a523 100644 --- a/templates/topics.html +++ b/templates/topics.html @@ -4,8 +4,10 @@
{{range .ItemList}}
- {{.Title}} {{if .Is_Closed}}🔒︎{{end}} + {{.Title}} {{if .ForumName}}{{.ForumName}} {{end}} + {{if .Is_Closed}}🔒︎{{end}} + {{.LastReplyAt}}
- {{else}}
There aren't any topics yet.
{{end}} + {{else}}
There aren't any topics yet.{{if .CurrentUser.Perms.CreateTopic}} Start one?{{end}}
{{end}}
{{template "footer.html" . }} \ No newline at end of file diff --git a/topic.go b/topic.go index 1d834dc1..5b41d52f 100644 --- a/topic.go +++ b/topic.go @@ -25,6 +25,7 @@ type TopicUser struct Is_Closed bool Sticky bool CreatedAt string + LastReplyAt string ParentID int Status string // Deprecated. Marked for removal. IpAddress string @@ -40,3 +41,31 @@ type TopicUser struct URLName string Level int } + +type TopicsRow struct +{ + ID int + Title string + Content interface{} + CreatedBy int + Is_Closed bool + Sticky bool + CreatedAt string + LastReplyAt string + ParentID int + Status string // Deprecated. Marked for removal. + IpAddress string + PostCount int + + CreatedByName string + Avatar string + Css template.CSS + ContentLines int + Tag string + URL string + URLPrefix string + URLName string + Level int + + ForumName string //TopicsRow +} diff --git a/utils.go b/utils.go index e03d67e5..e836e566 100644 --- a/utils.go +++ b/utils.go @@ -21,6 +21,9 @@ func GenerateSafeString(length int) (string, error) { } func relative_time(in string) (string, error) { + if in == "" { + return "", nil + } layout := "2006-01-02 15:04:05" t, err := time.Parse(layout, in) if err != nil { @@ -30,9 +33,20 @@ func relative_time(in string) (string, error) { diff := time.Since(t) hours := diff.Hours() seconds := diff.Seconds() + weeks := int(hours / 24 / 7) + months := int(hours / 24 / 31) switch { - case (hours / 24) > 7: - return t.Format("Mon Jan 2 2006"), err + case months > 11: + //return t.Format("Mon Jan 2 2006"), err + return t.Format("Jan 2 2006"), err + case months > 1: + return fmt.Sprintf("%d months ago", months), err + case months == 1: + return "a month ago", err + case weeks > 1: + return fmt.Sprintf("%d weeks ago", weeks), err + case int(hours / 24) == 7: + return "a week ago", err case int(hours / 24) == 1: return "1 day ago", err case int(hours / 24) > 1: