2018-03-17 08:16:43 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"../common"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ForumList(w http.ResponseWriter, r *http.Request, user common.User) common.RouteError {
|
2018-04-22 12:33:56 +00:00
|
|
|
header, ferr := common.UserCheck(w, r, &user)
|
2018-03-17 08:16:43 +00:00
|
|
|
if ferr != nil {
|
|
|
|
return ferr
|
|
|
|
}
|
2018-06-01 05:02:29 +00:00
|
|
|
header.Title = common.GetTitlePhrase("forums")
|
2018-04-22 12:33:56 +00:00
|
|
|
header.Zone = "forums"
|
2018-10-14 05:08:44 +00:00
|
|
|
header.Path = "/forums/"
|
2018-04-22 12:33:56 +00:00
|
|
|
header.MetaDesc = header.Settings["meta_desc"].(string)
|
2018-03-17 08:16:43 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
var forumList []common.Forum
|
|
|
|
var canSee []int
|
|
|
|
if user.IsSuperAdmin {
|
|
|
|
canSee, err = common.Forums.GetAllVisibleIDs()
|
|
|
|
if err != nil {
|
|
|
|
return common.InternalError(err, w, r)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
group, err := common.Groups.Get(user.Group)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Group #%d doesn't exist despite being used by common.User #%d", user.Group, user.ID)
|
|
|
|
return common.LocalError("Something weird happened", w, r, user)
|
|
|
|
}
|
|
|
|
canSee = group.CanSee
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fid := range canSee {
|
|
|
|
// Avoid data races by copying the struct into something we can freely mold without worrying about breaking something somewhere else
|
|
|
|
var forum = common.Forums.DirtyGet(fid).Copy()
|
|
|
|
if forum.ParentID == 0 && forum.Name != "" && forum.Active {
|
|
|
|
if forum.LastTopicID != 0 {
|
|
|
|
if forum.LastTopic.ID != 0 && forum.LastReplyer.ID != 0 {
|
|
|
|
forum.LastTopicTime = common.RelativeTime(forum.LastTopic.LastReplyAt)
|
|
|
|
} else {
|
|
|
|
forum.LastTopicTime = ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
forum.LastTopicTime = ""
|
|
|
|
}
|
|
|
|
common.RunHook("forums_frow_assign", &forum)
|
|
|
|
forumList = append(forumList, forum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 05:02:29 +00:00
|
|
|
pi := common.ForumsPage{header, forumList}
|
2018-03-17 08:16:43 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_forum_list", w, r, &user, &pi) {
|
|
|
|
return nil
|
|
|
|
}
|
2018-04-22 12:33:56 +00:00
|
|
|
err = common.RunThemeTemplate(header.Theme.Name, "forums", pi, w)
|
2018-03-17 08:16:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return common.InternalError(err, w, r)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|