Example #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)
}
Example #2
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)
}
Example #3
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, "/")

}