コード例 #1
0
ファイル: EditQuestionHandler.go プロジェクト: jango2015/sdc
func (self *EditQuestionHandler) Get() {
	self.TplNames = "sdc/edit-question.html"
	flash := beego.NewFlash()

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

	if qid_handler, err := model.GetQuestion(qid); err == nil && qid_handler != nil {
		uid, _ := self.GetSession("userid").(int64)
		role, _ := self.GetSession("userrole").(int64)
		allow := bool(false)

		if qid_handler.Uid == uid && qid_handler.Id == qid {
			allow = true
		} else if role < 0 {
			allow = true
		}

		if allow {

			self.Data["question"] = *qid_handler
			self.Data["inode"], _ = model.GetNode(qid_handler.Nid)
		} else {

			//没有权限执行该操作则直接跳转到登录页面
			self.Redirect("/user/signin/", 302)
		}

	} else {

		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
コード例 #2
0
ファイル: ViewQuestionHandler.go プロジェクト: abci/sdc
func (self *ViewQuestionHandler) Get() {
	name := self.GetString(":name")
	id, _ := self.GetInt(":id")

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

			if qs, err := model.GetQuestion(id); qs != nil && err == nil {
				qs.Views = qs.Views + 1
				//qs.Hotup = qs.Hotup + 1
				//qs.Hotscore = helper.Qhot_QScore(qs.Hotup, qs.Hotdown)
				//qs.Hotness = helper.Qhot(qs.Views, qs.ReplyCount, qs.Hotscore, qs.Hotscore, qs.Created, qs.ReplyTime)
				//qs.Hotvote = helper.Qhot_Vote(qs.Hotup, qs.Hotdown)
				if row, e := model.PutQuestion(id, qs); e != nil {
					fmt.Println("ViewQuestionHandler更新话题ID", id, "访问次数数据错误,row:", row, e)
					self.Abort("500")
				} else {
					self.Ctx.Output.Context.WriteString(strconv.Itoa(int(qs.Views)))
				}
			}
		} else {
			self.Abort("501")
		}

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

}
コード例 #3
0
ファイル: EditQuestionHandler.go プロジェクト: jango2015/sdc
func (self *EditQuestionHandler) Post() {
	self.TplNames = "sdc/edit-question.html"

	flash := beego.NewFlash()
	tags := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("tags"))))

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

	if qid_handler, err := model.GetQuestion(qid); err == nil {
		uid, _ := self.GetSession("userid").(int64)
		role, _ := self.GetSession("userrole").(int64)
		allow := bool(false)

		if qid_handler.Uid == uid && qid_handler.Id == qid {
			allow = true
		} else if role < 0 {
			allow = true
		}

		if allow {

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

			if tags == "" {

				flash.Error("尚未设置标签,请设定正确的标签!")
				flash.Store(&self.Controller)
				return
			} else {
				qid_title := template.HTMLEscapeString(strings.TrimSpace(self.GetString("title")))
				qid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

				if qid_title != "" && qid_content != "" {
					tags := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("tags"))))

					if qs, err := model.GetQuestion(qid); qs != nil && err == nil {

						qs.Title = qid_title

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

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

						if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := helper.GetThumbnails(qid_content); e == nil {
							qs.Thumbnails = thumbnails
							qs.ThumbnailsLarge = thumbnailslarge
							qs.ThumbnailsMedium = thumbnailsmedium
							qs.ThumbnailsSmall = thumbnailssmall
						}
						/*
							if cat, err := model.GetCategory(nd.Pid); err == nil {
								qs.Category = cat.Title
							}
						*/

						qs.Tags = tags
						qs.Updated = time.Now()

						if row, err := model.PutQuestion(qid, qs); row == 1 && err == nil {
							model.SetRecordforImageOnEdit(qid, qs.Uid)
							self.Redirect("/"+strconv.Itoa(int(qid))+"/", 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 {

			//没有权限执行该操作则直接跳转到登录页面
			self.Redirect("/user/signin/", 302)
		}
	} else {

		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}

}
コード例 #4
0
ファイル: QuestionHandler.go プロジェクト: jango2015/sdc
func (self *QuestionHandler) Get() {
	self.TplNames = "sdc/question.html"

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

	if qid > 0 {

		if qs, err := model.GetQuestion(qid); qs != nil && err == nil {
			avatar := ""
			if usr, err := model.GetUser(qs.Uid); err == nil && usr != nil {
				avatar = helper.Gravatar(usr.Email, 32)
			}
			self.Data["avatar"] = avatar
			self.Data["article"] = *qs
			self.Data["replys"] = *model.GetAnswersByPid(qid, 0, 0, 0, "hotness")

			/*
				if qss := model.GetTopicsByCidOnBetween(qs.Cid, qid-5, qid+5, 0, 11, 0, "asc"); qss != nil && qid != 0 && len(qss) > 0 {

					for i, v := range qss {

						if v.Id == qid {
							//两侧的翻页按钮参数 初始化 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 qss {
								//两侧的翻页按钮 s
								if prev == i {
									self.Data["previd"] = v.Id
									self.Data["prev"] = v.Title
								}
								if next == i {
									self.Data["nexqid"] = 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 == qid { // 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>")
						}
					}
					// (qss []*Topic)

				}
			*/

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

					if len(*qss) > 0 {
						i := 0
						ouqsut := `<ul class="widgets-similar clx">`
						for _, v := range *qss {

							i += 1
							if i == 3 {
								ouqsut = ouqsut + `<li class="similar similar-third">`
								i = 0
							} else {
								ouqsut = ouqsut + `<li class="similar">`
							}
							ouqsut = ouqsut + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
						}
						ouqsut = ouqsut + `</ul>`
						self.Data["topic_sidebar_hotness_6_module"] = template.HTML(ouqsut)
					}

				}
			*/

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

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

								if len(*qss) > 0 {
									i := 0
									ouqsut := `<ul class="widgets-popular widgets-similar clx">`
									for _, v := range *qss {

										i += 1
										if i == 3 {
											ouqsut = ouqsut + `<li class="similar similar-third">`
											i = 0
										} else {
											ouqsut = ouqsut + `<li class="similar">`
										}
										ouqsut = ouqsut + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
													<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />
												</a>
											</li>`
									}
									ouqsut = ouqsut + `</ul>`
									self.Data["topic_hotness_9_module"] = template.HTML(ouqsut)
								}
							} else {
								fmt.Println("推荐榜单(9)数据查询出错", err)
							}
						}
					}
				} else {
					fmt.Println("节点数据查询出错", err)
				}
			*/

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

						i += 1
						if i == 3 {
							ouqsut = ouqsut + `<li class="likesimilar likesimilar-3">`
							i = 0
						} else {
							ouqsut = ouqsut + `<li class="likesimilar">`
						}
						ouqsut = ouqsut + `<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>`
					}
					ouqsut = ouqsut + `</ul>`
					self.Data["topic_hotness_6_module"] = template.HTML(ouqsut)
				}
			*/
		} else {
			self.Redirect("/", 302)
		}
	} else {
		self.Redirect("/", 302)
	}

}
コード例 #5
0
ファイル: HateHandler.go プロジェクト: jango2015/sdc
func (self *HateHandler) Get() {

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

		if name == "question" {
			if model.IsQuestionMark(uid, id) {
				//self.Abort("304") <-白痴函数 妈的 难道这货不是用来设置状态号的?居然尼玛的直接panic!
				self.Ctx.Output.SetStatus(304)
				return

			} else {
				if qs, err := model.GetQuestion(id); err == nil {

					qs.Hotdown = qs.Hotdown + 1
					qs.Hotscore = helper.Qhot_QScore(qs.Hotup, qs.Hotdown)
					qs.Hotvote = helper.Qhot_Vote(qs.Hotup, qs.Hotdown)
					qs.Hotness = helper.Qhot(qs.Views, qs.ReplyCount, qs.Hotscore, model.GetAScoresByPid(id), qs.Created, qs.ReplyTime)

					if _, err := model.PutQuestion(id, qs); err != nil {
						fmt.Println("PutQuestion执行错误:", err)
					} else {
						model.SetQuestionMark(uid, id)
					}
					self.Ctx.WriteString(strconv.Itoa(int(qs.Hotscore)))
				} else {
					return
				}
			}
		} else if name == "answer" {
			if model.IsAnswerMark(uid, id) {
				self.Ctx.Output.SetStatus(304)
				return

			} else {
				if ans, err := model.GetAnswer(id); err == nil {

					ans.Hotdown = ans.Hotdown + 1
					ans.Views = ans.Views + 1
					ans.Hotscore = helper.Qhot_QScore(ans.Hotup, ans.Hotdown)
					ans.Hotvote = helper.Qhot_Vote(ans.Hotup, ans.Hotdown)
					ans.Hotness = helper.Qhot(ans.Views, ans.ReplyCount, ans.Hotscore, ans.Views, ans.Created, ans.ReplyTime)

					if _, err := model.PutAnswer(id, ans); err != nil {
						fmt.Println("PutAnswer执行错误:", err)
					} else {
						model.SetAnswerMark(uid, id)
					}
					self.Ctx.WriteString(strconv.Itoa(int(ans.Hotscore)))
				} else {
					return
				}
			}
		} else if name == "topic" {

			if tp, err := model.GetTopic(id); err == nil {

				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)
				//&spades; 没用 ({{.article.Hotdown}})
				self.Ctx.WriteString(strconv.Itoa(int(tp.Hotdown)))
			} else {
				return
			}
		} else if name == "node" {

			if nd, err := model.GetNode(id); err == nil {

				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 {
				return
			}
		} else {
			self.Ctx.Output.SetStatus(304)
		}

	} else {
		self.Ctx.Output.SetStatus(401)
	}

}