예제 #1
0
func (self *ViewHandler) Get() {
	tid, _ := self.GetInt(":tid")
	tid_handler := models.GetTopic(tid)

	_, filename, fileline, _ := runtime.Caller(2)
	fmt.Println(filename)
	fmt.Println(fileline)

	fmt.Println("Author")
	fmt.Println(tid_handler.Uid)

	self.TplNames = "view.html"
	self.Layout = "layout.html"

	if tid_handler.Id > 0 {

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

		self.Data["article"] = tid_handler
		self.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 {
							self.Data["previd"] = v.Id
							self.Data["prev"] = v.Title
						}
						if next == i {
							self.Data["nextid"] = v.Id
							self.Data["next"] = v.Title
						}
					}
				}
			}
		}

		if sess_userrole, _ := self.GetSession("userrole").(int64); sess_userrole == -1000 {
			self.Render()
		} else {
			tid_path := strconv.Itoa(int(tid_handler.Cid)) + "/" + strconv.Itoa(int(tid_handler.Nid)) + "/"
			tid_name := strconv.Itoa(int(tid_handler.Id)) + ".html"
			rs, _ := self.RenderString()
			helper.WriteFile("./archives/"+tid_path, tid_name, rs)
			self.Redirect("/archives/"+tid_path+tid_name, 301)
		}
	} else {
		self.Redirect("/", 302)
	}

}
예제 #2
0
//用户等级划分:正数是普通用户,负数是管理员各种等级划分,为0则尚未注册
func (self *BaseHandler) Prepare() {
	sess_username, _ = self.GetSession("username").(string)
	sess_uid, _ = self.GetSession("userid").(int64)
	sess_role, _ = self.GetSession("userrole").(int64)
	sess_email, _ = self.GetSession("useremail").(string)

	if sess_role == 0 {
		self.Data["Userid"] = 0
		self.Data["Username"] = ""
		self.Data["Userrole"] = 0
		self.Data["Useremail"] = ""
	} else {
		self.Data["Userid"] = sess_uid
		self.Data["Username"] = sess_username
		self.Data["Userrole"] = sess_role
		self.Data["Useremail"] = sess_email
	}
	self.Data["categorys"] = models.GetAllCategory()
	self.Data["nodes"] = models.GetAllNode()
	self.Data["nodes_hotness_topbar"] = models.GetAllNodeByCid(0, 0, 16, 0, "hotness")
	self.Data["topics_5s"] = models.GetAllTopic(0, 5, "id")
	self.Data["topics_10s"] = models.GetAllTopic(0, 10, "id")
	self.Data["nodes_10s"] = models.GetAllNodeByCid(0, 0, 10, 0, "id")
	self.Data["replys_5s"] = models.GetReplyByPid(0, 0, 5, "id")
	self.Data["replys_10s"] = models.GetReplyByPid(0, 0, 10, "id")

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

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

	self.Data["tweibo"] = models.GetKV("tweibo")
	self.Data["sweibo"] = models.GetKV("sweibo")
	self.Data["timenow"] = time.Now()
	self.Data["statistics"] = models.GetKV("statistics")

}