Example #1
0
func (self *EditNodeHandler) Post() {

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

	nd_title := self.GetString("title")
	nd_content := self.GetString("content")

	if cid != 0 && nid != 0 && nd_title != "" && nd_content != "" {

		nd := new(model.Node)
		nd.Id = int64(nid)
		nd.Pid = int64(cid)
		nd.Title = nd_title
		nd.Content = nd_content
		nd.Created = time.Now()

		if _, err := model.PutNode(nd.Id, nd); err == nil {

			self.Redirect("/node/"+strconv.Itoa(int(nid))+"/", 302)
		} else {
			self.Redirect("/", 302)
		}

	} else {
		self.Ctx.Redirect(302, "/")
	}
}
Example #2
0
func (self *NewNodeHandler) Post() {
	self.TplNames = "new-node.html"
	flash := beego.NewFlash()

	cid, _ := self.GetInt("category")
	uid, _ := self.GetSession("userid").(int64)
	nid_title := self.GetString("title")
	nid_content := self.GetString("content")

	if nid_title != "" && nid_content != "" && cid != 0 {

		if nid, err := model.AddNode(nid_title, nid_content, cid, uid); err != nil {
			flash.Error(fmt.Sprint(err))
			flash.Store(&self.Controller)
			return
		} else {

			if nd, err := model.GetNode(nid); err != nil {
				flash.Error(fmt.Sprint(err))
				flash.Store(&self.Controller)
				return
			} else {

				catmap := &map[string]interface{}{
					"node_time":         time.Now(),
					"node_count":        model.GetNodeCountByPid(cid),
					"node_last_user_id": uid}

				if e := model.UpdateCategory(cid, catmap); e != nil {
					fmt.Println("NewNode model.UpdateCategory errors:", e)
				}

				nd.Order = nd.Id * 10
				if row, err := model.PutNode(nid, nd); row != 0 && err != nil {
					flash.Error(fmt.Sprint(err))
					flash.Store(&self.Controller)
					return
				} else {
					self.Redirect("/", 302)
				}
			}
		}
	} else {
		flash.Error("分类不存在或节点标题、节点内容为空,请纠正错误!")
		flash.Store(&self.Controller)
		return
	}
}
Example #3
0
func (self *HateHandler) Get() {

	if helper.IsSpider(self.Ctx.Request.UserAgent()) != true {
		name := self.GetString(":name")
		id, _ := self.GetInt(":id")

		if name == "topic" {

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

			model.PutTopic(id, tp)
			self.Ctx.WriteString(strconv.Itoa(int(tp.Hotscore)))

		} else if name == "timeline" {

			tl, _ := model.GetTimeline(id)
			tl.Hotdown = tl.Hotdown + 1
			tl.Hotscore = helper.Hotness_Score(tl.Hotup, tl.Hotdown)
			tl.Hotness = helper.Hotness(tl.Hotup, tl.Hotdown, time.Now())

			model.PutTimeline(id, tl)
			self.Ctx.WriteString(strconv.Itoa(int(tl.Hotscore)))

		} else if name == "node" {

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

			model.PutNode(id, nd)

			self.Ctx.WriteString("node hated")
		} else {
			self.Abort("401")
		}

	} else {
		self.Abort("401")
	}

}
Example #4
0
func (self *NodeHandler) Get() {
	//fmt.Println("im NodeHandler")

	self.TplNames = "node.html"

	tab := self.GetString(":tab")
	ipage, _ := self.GetInt(":page")
	page := int(ipage)
	nid, _ := self.GetInt(":nid")
	ndname := self.GetString(":name")
	if nid > 0 {

		if n, e := model.GetNode(nid); e == nil && n != nil {
			ndname = n.Title
		}
	}

	url := "/node/"
	if tab == "lastest" {
		url = "/node/lastest/" + ndname + "/"
		tab = "id"
		self.Data["tab"] = "lastest"
	} else if tab == "hotness" {
		url = "/node/hotness/" + ndname + "/"
		tab = "hotness"
		self.Data["tab"] = "hotness"
	} else {
		url = "/node/hotness/" + ndname + "/"
		tab = "hotness"
		self.Data["tab"] = "hotness"
	}

	pagesize := 30

	if ndname != "" {
		//检验节点是否存在
		if nd, err := model.GetNodeByTitle(ndname); err == nil && nd != nil {
			//更新节点统计信息
			nd.Views = nd.Views + 1
			self.Data["innode"] = *nd
			self.Data["catpage"] = nd.Title
			model.PutNode(nd.Id, nd)

			limit := 25
			rcs := len(*model.GetTopicsByNid(nd.Id, 0, 0, 0, "hotness"))
			pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)

			//通过节点的名字获取下级话题
			if tps, err := model.GetTopicsByNode(ndname, offset, pagesize, tab); err == nil {
				results_count := len(*tps)
				if results_count > 0 {
					i := 1
					output := ""
					for _, v := range *tps {

						i += i
						if i == 3 {
							output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin pin3">`
							i = 0
						} else {

							output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin">`
						}
						output = output + `<div class="pin-coat">
									<a href="/` + strconv.Itoa(int(v.Id)) + `/" class='imageLink image loading' target='_blank'>
										<img src='/static/mzr/img/dot.png' original='` + v.ThumbnailsLarge + `' width='200' height='150' alt='` + v.Title + ` ` + v.Created.String() + ` ` + v.Node + ` ` + v.Category + `' oriheight='300' />
										<span class='bg'>` + v.Title + `</span>
									</a>
									<div class="pin-data clx">
										<span class="timer">
											<em></em>
											<span>` + helper.TimeSince(v.Created) + `</span>
										</span>
										<a href="/` + strconv.Itoa(int(v.Id)) + `/" class="viewsButton" title="阅读` + v.Title + `" target="_blank">
											<em></em>
											<span>` + strconv.Itoa(int(v.Views)) + ` views</span>
										</a>
									</div>
								</div>
							</div>`
					}
					self.Data["topics"] = output

				}

			} else {
				fmt.Println("节点推荐榜单 数据查询出错", err)
			}

			self.Data["pagesbar"] = helper.Pagesbar(url, "", rcs, pages, pageout, beginnum, endnum, 0)

			//侧栏九宫格推荐榜单
			output_start := `<ul class="widgets-popular widgets-similar clx">`
			output := ""
			i := 0
			//根据节点的上级PID 获取同分类下的最热话题
			if tps := model.GetTopicsByCid(nd.Pid, 0, 9, 0, "hotness"); len(*tps) > 0 {

				for _, v := range *tps {

					i += 1
					if i == 3 {
						output = output + `<li class="similar similar-third">`
						i = 0
					} else {
						output = output + `<li class="similar">`
					}
					output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
				}
			}
			output_end := "</ul>"

			if len(output) > 0 {
				output = output_start + output + output_end
				self.Data["topic_hotness_9_module"] = template.HTML(output)
			} else {
				self.Data["topic_hotness_9_module"] = nil
			}
		} else {
			self.Redirect("/", 302)
		}

	} else {
		self.Redirect("/", 302)
	}

}