Exemplo n.º 1
0
func (self *ViewHandler) Get() {
	name := self.GetString(":name")
	id, _ := self.GetInt(":id")

	if name != "" && id > 0 {
		if name == "topic" {

			if tp, err := model.GetTopic(id); tp != nil && err == nil {
				tp.Views = tp.Views + 1
				tp.Hotup = tp.Hotup + 1
				tp.Hotscore = helper.Hotness_Score(tp.Hotup, tp.Hotdown)
				tp.Hotness = helper.Hotness(tp.Hotup, tp.Hotdown, time.Now())

				if row, e := model.PutTopic(id, tp); e != nil {
					fmt.Println("ViewHandler更新话题ID", id, "访问次数数据错误,row:", row, e)
					self.Abort("500")
				} else {
					self.Ctx.Output.Context.WriteString(strconv.Itoa(int(tp.Views)))
				}
			}
		} else {
			self.Abort("501")
		}

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

}
Exemplo n.º 2
0
func (self *EditTopicHandler) Post() {
	self.TplNames = "edit-topic.html"
	flash := beego.NewFlash()

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

	if nd, err := model.GetNode(nid); nd != nil && err == nil {

		uid, _ := self.GetSession("userid").(int64)
		tid_title := self.GetString("title")
		tid_content := self.GetString("content")

		if tid_title != "" && tid_content != "" {

			if tp, err := model.GetTopic(tid); tp != nil && err == nil {

				tp.Title = tid_title
				tp.Uid = uid

				//删去用户没再使用的图片
				helper.DelLostImages(tp.Content, tid_content)
				tp.Content = tid_content

				if s, e := helper.GetBannerThumbnail(tid_content); e == nil {
					tp.Attachment = s
				}

				if cat, err := model.GetCategory(nd.Pid); err == nil {
					tp.Category = cat.Title
				}

				if row, err := model.PutTopic(tid, tp); row == 1 && err == nil {
					model.SetRecordforImageOnEdit(tid, uid)
					self.Redirect("/"+strconv.Itoa(int(tid))+"/", 302)
				} else {

					flash.Error("更新话题出现错误:", fmt.Sprint(err))
					flash.Store(&self.Controller)
					return
				}
			} else {

				flash.Error("无法获取根本不存在的话题!")
				flash.Store(&self.Controller)
				return
			}
		} else {

			flash.Error("话题标题或内容为空!")
			flash.Store(&self.Controller)
			return
		}
	} else {
		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
Exemplo n.º 3
0
//获取帖子
func (self *TopicHandler) Get() {
	tid, _ := self.GetInt(":objectId") //beego api模式下,提交的参数名总是唤作objectId

	if tid > 0 {
		tp, _ := model.GetTopic(tid)

		self.Data["json"] = *tp

	} else {
		tps, _ := model.GetTopics(0, 0, "id")
		self.Data["json"] = *tps
	}
	self.ServeJson()
}
Exemplo n.º 4
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")
	}

}
Exemplo n.º 5
0
func (self *EditTopicHandler) Get() {
	self.TplNames = "edit-topic.html"
	flash := beego.NewFlash()

	tid, _ := self.GetInt(":tid")

	if tid_handler, err := model.GetTopic(tid); err == nil {

		self.Data["topic"] = *tid_handler
		self.Data["inode"], _ = model.GetNode(tid_handler.Nid)

	} else {

		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
Exemplo n.º 6
0
func (self *TopicHandler) Get() {
	//fmt.Println("im TopicHandler")
	self.TplNames = "topic.html"

	tid, _ := self.GetInt(":tid")

	if tid > 0 {

		if tp, err := model.GetTopic(tid); tp != nil && err == nil {

			self.Data["article"] = *tp
			self.Data["replys"] = *model.GetReplysByPid(tid, 0, 0, 0, "id")

			//性能瓶颈 亟待优化!!!
			/*
				if tps := model.GetTopicsByCid(tp.Cid, 0, 0, 0, "asc"); *tps != nil && tid != 0 {
					if len(*tps) > 0 {
						self.Data["topics_cat"] = *tps
						//self.Data["topics_cat"] = model.GetTopicsByHotnessCategory(3, 3)

					}

					for i, v := range *tps {

						if v.Id == tid {
							//两侧的翻页按钮参数 初始化 s
							prev := i - 1
							next := i + 1
							//两侧的翻页按钮参数 初始化 e

							//话题内容部位 页码  初始化 s
							ipagesbar := `<div class="link_pages">`
							h := 5
							ipagesbar_start := i - h
							ipagesbar_end := i + h
							j := 0
							//话题内容部位 页码  初始化 e
							for i, v := range *tps {
								//两侧的翻页按钮 s
								if prev == i {
									self.Data["previd"] = v.Id
									self.Data["prev"] = v.Title
								}
								if next == i {
									self.Data["nextid"] = v.Id
									self.Data["next"] = v.Title
								}
								//两侧的翻页按钮 e

								//话题内容部位 页码 s
								if ipagesbar_start == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span><</span></a>`
								}
								if i > ipagesbar_start && i < ipagesbar_end {
									j += 1
									if v.Id == tid { // current

										ipagesbar = ipagesbar + `<span>` + strconv.Itoa(int(v.Id)) + `</span>`

									} else { //loop

										ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>` + strconv.Itoa(int(v.Id)) + `</span></a>`

									}
									if j > (2 * h) {
										break
									}
								}
								if ipagesbar_end == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>></span></a>`
								}
								//话题内容部位 页码 e
							}
							self.Data["ipagesbar"] = template.HTML(ipagesbar + "</div>")
						}
					}
				}
			*/

			if tps := model.GetTopicsByCidOnBetween(tp.Cid, tid-5, tid+5, 0, 11, 0, "asc"); tps != nil && tid != 0 && len(tps) > 0 {

				for i, v := range tps {

					if v.Id == tid {
						//两侧的翻页按钮参数 初始化 s
						prev := i - 1
						next := i + 1
						//两侧的翻页按钮参数 初始化 e

						//话题内容部位 页码  初始化 s
						ipagesbar := `<div class="link_pages">`
						h := 5
						ipagesbar_start := i - h
						ipagesbar_end := i + h
						j := 0
						//话题内容部位 页码  初始化 e
						for i, v := range tps {
							//两侧的翻页按钮 s
							if prev == i {
								self.Data["previd"] = v.Id
								self.Data["prev"] = v.Title
							}
							if next == i {
								self.Data["nextid"] = v.Id
								self.Data["next"] = v.Title
							}
							//两侧的翻页按钮 e

							//话题内容部位 页码 s
							if ipagesbar_start == i {
								ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span><</span></a>`
							}
							if i > ipagesbar_start && i < ipagesbar_end {
								j += 1
								if v.Id == tid { // current

									ipagesbar = ipagesbar + `<span>` + strconv.Itoa(int(v.Id)) + `</span>`

								} else { //loop

									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>` + strconv.Itoa(int(v.Id)) + `</span></a>`

								}
								if j > (2 * h) {
									break
								}
							}
							if ipagesbar_end == i {
								ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>></span></a>`
							}
							//话题内容部位 页码 e
						}
						self.Data["ipagesbar"] = template.HTML(ipagesbar + "</div>")
					}
				}
				// (tps []*Topic)

			}
			//侧栏你可能喜欢 推荐同节点下的最热话题
			if tps := model.GetTopicsByNid(tp.Nid, 0, 6, 0, "hotness"); *tps != nil {

				if len(*tps) > 0 {
					i := 0
					output := `<ul class="widgets-similar clx">`
					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 = output + `</ul>`
					self.Data["topic_sidebar_hotness_6_module"] = template.HTML(output)
				}

			}

			//侧栏九宫格推荐榜单
			//先行取出最热门的一个节点 然后根据节点获取该节点下最热门的话题
			if nd, err := model.GetNodes(0, 1, "hotness"); err == nil {
				if len(*nd) == 1 {
					for _, v := range *nd {

						if tps := model.GetTopicsByNid(v.Id, 0, 9, 0, "hotness"); err == nil {

							if len(*tps) > 0 {
								i := 0
								output := `<ul class="widgets-popular widgets-similar clx">`
								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 = output + `</ul>`
								self.Data["topic_hotness_9_module"] = template.HTML(output)
							}
						} else {
							fmt.Println("推荐榜单(9)数据查询出错", err)
						}
					}
				}
			} else {
				fmt.Println("节点数据查询出错", err)
			}

			//底部六格推荐
			//推荐同一作者的最热话题
			if tps := model.GetTopicsByUid(tp.Uid, 0, 6, 0, "hotness"); len(*tps) > 0 {
				i := 0
				output := `<ul class="widgets-similar clx">`
				for _, v := range *tps {

					i += 1
					if i == 3 {
						output = output + `<li class="likesimilar likesimilar-3">`
						i = 0
					} else {
						output = output + `<li class="likesimilar">`
					}
					output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `" alt="` + v.Title + `" class="likeimglink">
												<img src="` + v.ThumbnailsMedium + `" wdith="150" height="150" />
												<span class="bg">` + v.Title + `</span>			
											</a>
										</li>`
				}
				output = output + `</ul>`
				self.Data["topic_hotness_6_module"] = template.HTML(output)
			} else {
				fmt.Println("六格推荐查询出错:", err)
			}

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

}
Exemplo n.º 7
0
func (self *NewReplyHandler) Post() {
	tid, _ := self.GetInt(":tid")
	sess_userid, _ := self.GetSession("userid").(int64)

	author := self.GetString("author")
	email := self.GetString("email")
	website := self.GetString("website")
	rc := self.GetString("comment")

	//不等于0,即是注册用户或管理层 此时把ctype设置为1 主要是为了区分游客
	if sess_userid != 0 {
		if tid > 0 && rc != "" {

			if usr, err := model.GetUser(sess_userid); err == nil {
				//为安全计,先行保存回应,顺手获得rid,在后面顺手再更新替换@通知的链接
				if rid, err := model.AddReply(tid, sess_userid, 1, rc, usr.Username, usr.Content, usr.Email, usr.Website); err != nil {
					fmt.Println("#", rid, ":", err)
				} else {

					//如果回应内容中有@通知 则处理以下事件
					if users := helper.AtUsers(rc); len(users) > 0 {
						if tp, err := model.GetTopic(tid); err == nil {
							todo := []string{}
							for _, v := range users {
								//判断被通知之用户名是否真实存在
								if u, e := model.GetUserByUsername(v); e == nil && u != nil {
									//存在的则加入待操作列
									todo = append(todo, v)
									//替换被通知用户的用户名带上用户主页链接
									rc = strings.Replace(rc, "@"+v,
										"<a href='/user/"+u.Username+"/' title='"+u.Nickname+"' target='_blank'><span>@</span><span>"+u.Username+"</span></a>", -1)

									//发送通知内容到用户的 时间线
									model.AddTimeline(usr.Username+"在「"+tp.Title+"」的回应里提到了你~",
										rc+"[<a href='/topic/"+self.GetString(":tid")+"/#reply-"+strconv.Itoa(int(rid))+"'>"+tp.Title+"</a>]",
										tp.Cid, tp.Nid, u.Id, usr.Username, usr.Content)

								}

							}
							if len(todo) > 0 {
								model.SetReplyContentByRid(rid, rc)
							}

						}
					}

					self.Redirect("/topic/"+self.GetString(":tid")+"/#reply-"+strconv.Itoa(int(rid)), 302)
					return
				}
			}
			self.Redirect("/topic/"+self.GetString(":tid")+"/", 302)
		} else if tid > 0 {
			self.Redirect("/topic/"+self.GetString(":tid")+"/", 302)
		} else {
			self.Redirect("/", 302)
		}
	} else { //游客回应 此时把ctype设置为-1   游客不开放@通知功能
		if author != "" && email != "" && tid > 0 && rc != "" {
			if rid, err := model.AddReply(tid, sess_userid, -1, rc, author, "", email, website); err != nil {
				fmt.Println("#", rid, ":", err)
				self.Redirect("/topic/"+self.GetString(":tid")+"/", 302)
			} else {
				self.Redirect("/topic/"+self.GetString(":tid")+"/#reply-"+strconv.Itoa(int(rid)), 302)
			}
		} else if tid > 0 {
			self.Redirect("/topic/"+self.GetString(":tid")+"/", 302)
		} else {
			self.Redirect("/", 302)
		}

	}

}