9f273a99f5
Reduced the amount of boilerplate in routes with renderTemplate() Reduced the amount of boilerplate in routes with ParseSEOURL() Removed some dated commented bits of code. Used StashConfig in a few more places in the benchmarks to reduce the amount of boilerplate. Renamed the pre_render_forum_list hook to pre_render_forums. Renamed the pre_render_topic_list hook to pre_render_topics. Renamed a few benchmark variables to simplify the code.
85 lines
2.8 KiB
Go
85 lines
2.8 KiB
Go
package routes
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/Azareal/Gosora/common"
|
|
"github.com/Azareal/Gosora/common/phrases"
|
|
)
|
|
|
|
func TopicList(w http.ResponseWriter, r *http.Request, user common.User, header *common.Header) common.RouteError {
|
|
header.Title = phrases.GetTitlePhrase("topics")
|
|
header.Zone = "topics"
|
|
header.Path = "/topics/"
|
|
header.MetaDesc = header.Settings["meta_desc"].(string)
|
|
|
|
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)
|
|
}
|
|
|
|
// Get the current page
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
|
|
|
// TODO: Pass a struct back rather than passing back so many variables
|
|
var topicList []*common.TopicsRow
|
|
var forumList []common.Forum
|
|
var paginator common.Paginator
|
|
if user.IsSuperAdmin {
|
|
topicList, forumList, paginator, err = common.TopicList.GetList(page, "")
|
|
} else {
|
|
topicList, forumList, paginator, err = common.TopicList.GetListByGroup(group, page, "")
|
|
}
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
|
|
// ! Need an inline error not a page level error
|
|
if len(topicList) == 0 {
|
|
return common.NotFound(w, r, header)
|
|
}
|
|
|
|
pi := common.TopicListPage{header, topicList, forumList, common.Config.DefaultForum, common.TopicListSort{"lastupdated", false}, paginator}
|
|
return renderTemplate("topics", w, r, header, pi)
|
|
}
|
|
|
|
func TopicListMostViewed(w http.ResponseWriter, r *http.Request, user common.User, header *common.Header) common.RouteError {
|
|
header.Title = phrases.GetTitlePhrase("topics")
|
|
header.Zone = "topics"
|
|
header.Path = "/topics/"
|
|
header.MetaDesc = header.Settings["meta_desc"].(string)
|
|
|
|
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)
|
|
}
|
|
|
|
// Get the current page
|
|
page, _ := strconv.Atoi(r.FormValue("page"))
|
|
|
|
// TODO: Pass a struct back rather than passing back so many variables
|
|
var topicList []*common.TopicsRow
|
|
var forumList []common.Forum
|
|
var paginator common.Paginator
|
|
if user.IsSuperAdmin {
|
|
topicList, forumList, paginator, err = common.TopicList.GetList(page, "most-viewed")
|
|
} else {
|
|
topicList, forumList, paginator, err = common.TopicList.GetListByGroup(group, page, "most-viewed")
|
|
}
|
|
if err != nil {
|
|
return common.InternalError(err, w, r)
|
|
}
|
|
|
|
// ! Need an inline error not a page level error
|
|
if len(topicList) == 0 {
|
|
return common.NotFound(w, r, header)
|
|
}
|
|
|
|
pi := common.TopicListPage{header, topicList, forumList, common.Config.DefaultForum, common.TopicListSort{"mostviewed", false}, paginator}
|
|
return renderTemplate("topics", w, r, header, pi)
|
|
}
|