Exemple #1
0
func LikeHandler(self *vodka.Context) error {

	if helper.IsSpider(self.Request().UserAgent()) != true {
		name := self.FormEscape(":name")
		id, _ := self.ParamInt64(":id")

		if name == "topic" {

			tp := models.GetTopic(id)
			tp.Hotup = tp.Hotup + 1
			tp.Hotscore = helper.Hotness_Score(tp.Hotup, tp.Hotdown)
			tp.Hotness = helper.Hotness(tp.Hotup, tp.Hotdown, time.Now())

			models.PutTopic(id, tp)
			return self.String(http.StatusOK, "%v", tp.Hotup)
		} else if name == "node" {

			nd := models.GetNode(id)
			nd.Hotup = nd.Hotup + 1
			nd.Hotscore = helper.Hotness_Score(nd.Hotup, nd.Hotdown)
			nd.Hotness = helper.Hotness(nd.Hotup, nd.Hotdown, time.Now())

			models.PutNode(id, nd)

			return self.Status(200)
		}

	}
	return self.Status(401)
}
Exemple #2
0
func NodeEditGetHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	nid, _ := self.ParamInt64(":nid")
	nid_handler := models.GetNode(nid)
	data["inode"] = nid_handler
	data["icategory"] = models.GetCategory(nid_handler.Pid)

	return self.Render(http.StatusOK, "node_edit.html", data)
}
Exemple #3
0
func TopicEditGetHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	tid, _ := self.ParamInt64(":tid")
	tid_handler := models.GetTopic(tid)
	data["topic"] = tid_handler
	data["inode"] = models.GetNode(tid_handler.Nid)

	return self.Render(http.StatusOK, "topic_edit.html", data)
}
Exemple #4
0
func ModifyCatPostHandler(self *vodka.Context) error {

	cid, _ := self.ParamInt64("categoryid")

	cat_title := self.ParamEscape("title")
	cat_content := self.ParamEscape("content")
	if cid != 0 && cat_title != "" && cat_content != "" {
		var cat models.Category
		cat.Id = int64(cid)
		cat.Title = cat_title
		cat.Content = cat_content
		cat.Created = time.Now()
		models.UpdateCategory(cat.Id, cat)
		return self.Redirect(302, fmt.Sprintf("/category/%v/", cid))
	} else {
		return self.Redirect(302, "/")
	}
}
Exemple #5
0
func ViewHandler(self *vodka.Context) error {

	data := make(map[string]interface{})
	tid, _ := self.ParamInt64(":tid")
	tid_handler := models.GetTopic(tid)

	if tid_handler.Id > 0 {

		tid_handler.Views = tid_handler.Views + 1
		models.UpdateTopic(tid, tid_handler)

		data["article"] = tid_handler
		data["replys"] = models.GetReplyByPid(tid, 0, 0, "id")

		tps := models.GetAllTopicByCid(tid_handler.Cid, 0, 0, 0, "asc")

		if tps != nil && tid != 0 {

			for i, v := range tps {

				if v.Id == tid {
					prev := i - 1
					next := i + 1

					for i, v := range tps {
						if prev == i {
							data["previd"] = v.Id
							data["prev"] = v.Title
						}
						if next == i {
							data["nextid"] = v.Id
							data["next"] = v.Title
						}
					}
				}
			}
		}

		return self.Render(http.StatusOK, "view.html", data)
	}

	return self.Redirect(302, "/")

}
Exemple #6
0
func ModifyNodePostHandler(self *vodka.Context) error {

	cid, _ := self.ParamInt64("categoryid")
	nid, _ := self.ParamInt64("nodeid")

	nd_title := self.FormEscape("title")
	nd_content := self.FormEscape("content")
	if cid != 0 && nid != 0 && nd_title != "" && nd_content != "" {
		nd := new(models.Node)
		nd.Id = int64(nid)
		nd.Pid = int64(cid)
		nd.Title = nd_title
		nd.Content = nd_content
		nd.Created = time.Now()
		models.UpdateNode(nd.Id, nd)
		return self.Redirect(302, fmt.Sprintf("/node/%v/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
Exemple #7
0
func NodeEditPostHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64(":nid")
	cid, _ := self.ParamInt64("categoryid")

	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id

	nid_title := self.FormEscape("title")
	nid_content := self.FormEscape("content")
	if nid_title != "" && nid_content != "" {
		models.EditNode(nid, cid, uid, nid_title, nid_content)
		return self.Redirect(302, fmt.Sprintf("/node/%v/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
Exemple #8
0
func TopicEditPostHandler(self *vodka.Context) error {
	tid, _ := self.ParamInt64(":tid")
	nid, _ := self.ParamInt64("nodeid")
	cid := models.GetNode(nid).Pid

	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id
	tid_title := self.FormEscape("title")
	tid_content := self.FormEscape("content")

	if tid_title != "" && tid_content != "" {
		models.EditTopic(tid, nid, cid, uid, tid_title, tid_content)
		return self.Redirect(302, fmt.Sprintf("/view/%v/", tid))
	} else {
		return self.Redirect(302, "/")
	}
}
Exemple #9
0
func NewTopicPostHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64("nodeid")
	cid := models.GetNode(nid).Pid
	session := sessions.Default(self)
	var user models.User
	val := session.Get("user")
	if val != nil {
		user = val.(models.User)
	}
	uid := user.Id
	author := user.Nickname

	tid_title := self.FormEscape("title")
	tid_content := self.FormEscape("content")

	if tid_title != "" && tid_content != "" {
		models.AddTopic(tid_title, tid_content, cid, nid, uid, author)
		return self.Redirect(302, fmt.Sprintf("/node/", nid))
	} else {
		return self.Redirect(302, "/")
	}
}
Exemple #10
0
func NodeHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	page, _ := self.ParamInt64("page")
	nid, _ := self.ParamInt64(":nid")

	nid_handler := models.GetNode(nid)
	nid_handler.Views = nid_handler.Views + 1
	models.UpdateNode(nid, nid_handler)

	limit := 25
	rcs := len(models.GetAllTopicByNid(nid, 0, 0, 0, "hotness"))
	pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)
	data["pagesbar"] = helper.Pagesbar("", rcs, pages, pageout, beginnum, endnum, 1)
	data["nodeid"] = nid
	data["topics_hotness"] = models.GetAllTopicByNid(nid, offset, limit, 0, "hotness")
	data["topics_latest"] = models.GetAllTopicByNid(nid, offset, limit, 0, "id")

	if nid != 0 {
		return self.Render(http.StatusOK, "node.html", data)
	} else {
		return self.Redirect(302, "/")
	}

}
Exemple #11
0
func NodeDeleteHandler(self *vodka.Context) error {
	nid, _ := self.ParamInt64(":nid")
	models.DelNode(nid)
	return self.Redirect(302, "/")
}
Exemple #12
0
func TopicDeleteHandler(self *vodka.Context) error {
	tid, _ := self.ParamInt64(":tid")
	models.DelTopic(tid)
	return self.Redirect(302, "/")
}
Exemple #13
0
func DeleteReplyHandler(self *vodka.Context) error {
	rid, _ := self.ParamInt64(":rid")
	models.DelReply(rid)
	return self.Redirect(302, "/")
}
Exemple #14
0
func MainHandler(self *vodka.Context) error {
	data := make(map[string]interface{})
	///
	data["nodes"] = models.GetAllNode()
	data["nodes_hotness_topbar"] = models.GetAllNodeByCid(0, 0, 16, 0, "hotness")
	data["topics_5s"] = models.GetAllTopic(0, 5, "id")
	data["topics_10s"] = models.GetAllTopic(0, 10, "id")
	data["nodes_10s"] = models.GetAllNodeByCid(0, 0, 10, 0, "id")
	data["replys_5s"] = models.GetReplyByPid(0, 0, 5, "id")
	data["replys_10s"] = models.GetReplyByPid(0, 0, 10, "id")

	data["author"] = models.GetKV("author")
	data["title"] = models.GetKV("title")
	data["title_en"] = models.GetKV("title_en")
	data["keywords"] = models.GetKV("keywords")
	data["description"] = models.GetKV("description")

	data["company"] = models.GetKV("company")
	data["copyright"] = models.GetKV("copyright")
	data["site_email"] = models.GetKV("site_email")

	data["tweibo"] = models.GetKV("tweibo")
	data["sweibo"] = models.GetKV("sweibo")
	data["timenow"] = time.Now()
	data["statistics"] = models.GetKV("statistics")
	data["remoteproto"] = self.Request().Proto
	data["remotehost"] = self.Request().Host
	data["remoteos"] = runtime.GOOS
	data["remotearch"] = runtime.GOARCH
	data["remotecpus"] = runtime.NumCPU()
	data["golangver"] = runtime.Version()
	///
	page, _ := self.ParamInt64("page")
	curtab, _ := self.ParamInt64("tab")
	cid, _ := self.ParamInt64(":cid")
	limit := 25
	home := "false"
	if cid == 0 {
		home = "true"
	}

	data["home"] = home
	data["curcate"] = cid
	data["curtab"] = curtab

	topics_rcs := len(models.GetAllTopicByCid(cid, 0, 0, 0, "hotness"))
	topics_pages, topics_pageout, topics_beginnum, topics_endnum, offset := helper.Pages(topics_rcs, int(page), limit)

	data["topics_latest"] = models.GetAllTopicByCid(cid, offset, limit, 0, "id")
	data["topics_hotness"] = models.GetAllTopicByCid(cid, offset, limit, 0, "hotness")
	data["topics_views"] = models.GetAllTopicByCid(cid, offset, limit, 0, "views")
	data["topics_reply_count"] = models.GetAllTopicByCid(cid, offset, limit, 0, "reply_count")

	data["topics_pagesbar_tab1"] = helper.Pagesbar("tab=1&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
	data["topics_pagesbar_tab2"] = helper.Pagesbar("tab=2&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
	data["topics_pagesbar_tab3"] = helper.Pagesbar("tab=3&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)
	data["topics_pagesbar_tab4"] = helper.Pagesbar("tab=4&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1)

	nodes_rcs := len(models.GetAllNodeByCid(cid, 0, 0, 0, "hotness"))
	nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, offset := helper.Pages(nodes_rcs, int(page), limit)

	data["nodes_latest"] = models.GetAllNodeByCid(cid, offset, limit, 0, "id")
	data["nodes_hotness"] = models.GetAllNodeByCid(cid, offset, limit, 0, "hotness")

	data["nodes_pagesbar_tab5"] = helper.Pagesbar("tab=5&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1)
	data["nodes_pagesbar_tab6"] = helper.Pagesbar("tab=6&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1)

	return self.Render(http.StatusOK, "index.html", nil)

}