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(`