// 社区帖子列表页 // uri: /topics{view:(|/popular|/no_reply|/last)} func TopicsHandler(rw http.ResponseWriter, req *http.Request) { nodes := service.GenNodes() // 设置内容模板 page, _ := strconv.Atoi(req.FormValue("p")) if page == 0 { page = 1 } vars := mux.Vars(req) order := "" where := "" view := "" switch vars["view"] { case "/no_reply": view = "no_reply" where = "lastreplyuid=0" case "/last": view = "last" order = "ctime DESC" } topics, total := service.FindTopics(page, 0, where, order) pageHtml := service.GetPageHtml(page, total, req.URL.Path) req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list.html") // 设置模板数据 filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes, "view": view}) }
// 某节点下的帖子列表 // uri: /topics/node{nid:[0-9]+} func NodesHandler(rw http.ResponseWriter, req *http.Request) { page, _ := strconv.Atoi(req.FormValue("p")) if page == 0 { page = 1 } vars := mux.Vars(req) topics, total := service.FindTopics(page, 0, "nid="+vars["nid"]) pageHtml := service.GetPageHtml(page, total) // 当前节点信息 node := model.GetNode(util.MustInt(vars["nid"])) req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/node.html") // 设置模板数据 filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topics": topics, "page": template.HTML(pageHtml), "total": total, "node": node}) }
// 社区帖子列表页 // uri: /topics{view:(|/popular|/no_reply|/last)} func TopicsHandler(rw http.ResponseWriter, req *http.Request, ismobile bool) { logger.Traceln("User-Agent") logger.Traceln(req.Header["User-Agent"][0]) nodes := genNodes() // 设置内容模板 page, _ := strconv.Atoi(req.FormValue("p")) if page == 0 { page = 1 } vars := mux.Vars(req) order := "" where := "" switch vars["view"] { case "/popular": where = "like>0" case "/last": order = "ctime DESC" } var PAGE_NUM int if ismobile { PAGE_NUM = 30 } else { PAGE_NUM = 10 } topics, total := service.FindTopics(page, PAGE_NUM, where, order) logger.Traceln(total) logger.Traceln(len(topics)) logger.Traceln(PAGE_NUM) pageHtml := service.GetPageHtml(page, total, PAGE_NUM) if ismobile { req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list_mobile.html") } else { req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/list.html") } // 设置模板数据 switch vars["view"] { case "/popular": filter.SetData(req, map[string]interface{}{"popular": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) case "/last": filter.SetData(req, map[string]interface{}{"last": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) default: filter.SetData(req, map[string]interface{}{"active": 1, "topics": topics, "page": template.HTML(pageHtml), "nodes": nodes}) } }
// 某个分类的资源列表 // uri: /resources/cat/{catid:[0-9]+} func CatResourcesHandler(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) catid := vars["catid"] page, _ := strconv.Atoi(req.FormValue("p")) if page == 0 { page = 1 } resources, total := service.FindResourcesByCatid(catid, page) pageHtml := service.GetPageHtml(page, total, req.URL.Path) req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/index.html") filter.SetData(req, map[string]interface{}{"activeResources": "active", "resources": resources, "categories": service.AllCategory, "page": template.HTML(pageHtml), "curCatid": util.MustInt(catid)}) }