Ejemplo n.º 1
0
func (self *LikeHandler) Get() {

	if helper.IsSpider(self.Ctx.Request.UserAgent()) != true {
		name := self.GetString(":name")
		id, _ := self.GetInt(":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)
			//♥ 有用 ({{.article.Hotup}})
			self.Ctx.WriteString(strconv.Itoa(int(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)

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

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

}
Ejemplo n.º 2
0
func (self *NodeEditHandler) Get() {
	nid, _ := self.GetInt(":nid")
	nid_handler := models.GetNode(nid)
	self.Data["inode"] = nid_handler
	self.Data["icategory"] = models.GetCategory(nid_handler.Pid)

	self.Layout = "layout.html"
	self.TplNames = "node_edit.html"
	self.Render()
}
Ejemplo n.º 3
0
func (self *TopicEditHandler) Get() {
	tid, _ := self.GetInt(":tid")
	tid_handler := models.GetTopic(tid)
	self.Data["topic"] = tid_handler
	self.Data["inode"] = models.GetNode(tid_handler.Nid)

	self.Layout = "layout.html"
	self.TplNames = "topic_edit.html"
	self.Render()
}
Ejemplo n.º 4
0
func (self *NewTopicHandler) Post() {
	nid, _ := self.GetInt("nodeid")
	cid := models.GetNode(nid).Pid
	uid, _ := self.GetSession("userid").(int64)
	tid_title := self.GetString("title")
	tid_content := self.GetString("content")
	if tid_title != "" && tid_content != "" {
		models.AddTopic(self.GetString("title"), self.GetString("content"), cid, nid, uid)
		self.Ctx.Redirect(302, "/node/"+self.GetString("nodeid"))
	} else {
		self.Ctx.Redirect(302, "/")
	}
}
Ejemplo n.º 5
0
func (self *TopicEditHandler) Post() {
	tid, _ := self.GetInt(":tid")
	nid, _ := self.GetInt("nodeid")
	cid := models.GetNode(nid).Pid
	uid, _ := self.GetSession("userid").(int64)
	tid_title := self.GetString("title")
	tid_content := self.GetString("content")

	if tid_title != "" && tid_content != "" {
		models.EditTopic(tid, nid, cid, uid, tid_title, tid_content)
		self.Redirect("/view/"+self.GetString(":tid"), 302)
	} else {
		self.Redirect("/", 302)
	}
}
Ejemplo n.º 6
0
func (self *NewTopicHandler) Post() {
	nid, _ := self.GetInt("nodeid")
	cid := models.GetNode(nid).Pid
	uid, _ := self.GetSession("userid").(int64)
	author, _ := self.GetSession("username").(string)

	fmt.Println("=============================")
	fmt.Println(self.GetSession("userid"))
	fmt.Println(uid)

	tid_title := self.GetString("title")
	tid_content := self.GetString("content")

	if tid_title != "" && tid_content != "" {
		models.AddTopic(tid_title, tid_content, cid, nid, uid, author)
		self.Ctx.Redirect(302, "/node/"+self.GetString("nodeid"))
	} else {
		self.Ctx.Redirect(302, "/")
	}
}
Ejemplo n.º 7
0
func (self *NodeHandler) Get() {
	page, _ := self.GetInt("page")
	nid, _ := self.GetInt(":nid")

	nid_handler := models.GetNode(nid)
	nid_handler.Views = nid_handler.Views + 1
	models.UpdateNode(nid, nid_handler)

	limit := 25
	rcs := len(models.GetAllTopicByNid(nid, 0, 0, 0, "hotness"))
	pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit)
	self.Data["pagesbar"] = helper.Pagesbar("", rcs, pages, pageout, beginnum, endnum, 1)
	self.Data["nodeid"] = nid
	self.Data["topics_hotness"] = models.GetAllTopicByNid(nid, offset, limit, 0, "hotness")
	self.Data["topics_latest"] = models.GetAllTopicByNid(nid, offset, limit, 0, "id")

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

	if nid != 0 {
		self.Render()
		/*
			if sess_userrole, _ := self.GetSession("userrole").(int64); sess_userrole == -1000 {
				self.Render()
			} else {
				nid_path := strconv.Itoa(int(nid_handler.Pid)) + "/" + strconv.Itoa(int(nid_handler.Id)) + "/"
				nid_name := "index.html"
				rs, _ := self.RenderString()
				helper.Writefile("./archives/"+nid_path, nid_name, rs)
				self.Redirect("/archives/"+nid_path+nid_name, 301)
			}*/
	} else {
		self.Redirect("/", 302)
	}

}
Ejemplo n.º 8
0
func (self *RApi) Get() {

	switch {
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-gallery-edit/([0-9]+)$"):
		//# Gallery编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.WriteString(outtimesz)
		} else {

			editmid, _ := self.GetInt(":editmid")
			img := models.GetFile(editmid)
			self.Data["img"] = img
			self.TplNames = "root/gallery_editurl.html"
			self.Render()
		}

	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-gallery-del/([0-9]+)$"):
		//# Gallery删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":delmid"); mid != 0 {
				if e := models.DelFile(mid); e != nil {
					self.Data["MsgErr"] = "删除图片文件失败!"
				} else {
					self.Data["MsgErr"] = "成功删除图片文件!"
				}

			} else {
				self.Data["MsgErr"] = "错误对象!"
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Ctx.Redirect(302, "/root-gallery")
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-node-del/([0-9]+)$"):
		//#ABOUT 节点删除 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":nid"); mid != 0 {
				if e := models.DelNode(mid); e != nil {
					self.Data["MsgErr"] = "删除节点失败!"
				} else {
					self.Data["MsgErr"] = "成功删除节点!"
				}

			} else {
				self.Data["MsgErr"] = "错误节点!"
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect("/root-about-node-list", 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-node-del/([0-9]+)$"):
		//#contact 节点删除 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":nid"); mid != 0 {
				if e := models.DelNode(mid); e != nil {
					self.Data["MsgErr"] = "删除节点失败!"
				} else {
					self.Data["MsgErr"] = "成功删除节点!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-contact-node-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-topic-del/([0-9]+)$"):
		//#ABOUT 内容删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":tid"); mid != 0 {
				if e := models.DelTopic(mid); e != nil {
					self.Data["MsgErr"] = "删除内容失败!"
				} else {
					self.Data["MsgErr"] = "成功删除内容!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-about-topic-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-topic-del/([0-9]+)$"):
		// crafts 内容删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			if mid, _ := self.GetInt(":tid"); mid != 0 {
				if e := models.DelTopic(mid); e != nil {
					self.Data["MsgErr"] = "删除内容失败!"
				} else {
					self.Data["MsgErr"] = "成功删除内容!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-crafts-topic-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-topic-del/([0-9]+)$"):
		// services 内容删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			if mid, _ := self.GetInt(":tid"); mid != 0 {
				if e := models.DelTopic(mid); e != nil {
					self.Data["MsgErr"] = "删除内容失败!"
				} else {
					self.Data["MsgErr"] = "成功删除内容!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-services-topic-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-topic-edit/([0-9]+)$"):
		//ABOUT 内容编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")
			tid, _ := self.GetInt(":tid")
			tid_handler := models.GetTopic(tid)
			self.Data["catpage"] = "about"
			self.Data["asidepage"] = "root_about_topic_edit"
			self.Data["topic"] = tid_handler

			self.TplNames = "root/about.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-topic-edit/([0-9]+)$"):
		// services 内容编辑 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			var cid int64 = 3
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			tid, _ := self.GetInt(":tid")
			tid_handler := models.GetTopic(tid)
			self.Data["catpage"] = "services"
			self.Data["asidepage"] = "root-services-topic-edit"
			self.Data["topic"] = tid_handler
			self.Data["inode"] = models.GetNode(tid_handler.Nid)
			self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id")
			self.TplNames = "root/published.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-topic-edit/([0-9]+)$"):
		//CONTACT 内容编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			var cid int64 = 6
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")
			tid, _ := self.GetInt(":tid")
			tid_handler := models.GetTopic(tid)
			self.Data["asidepage"] = "root-contact-topic-edit"
			self.Data["topic"] = tid_handler
			self.Data["inode"] = models.GetNode(tid_handler.Nid)
			self.Data["catpage"] = "contact"
			self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id")
			self.TplNames = "root/contact.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-topic-edit/([0-9]+)$"):
		//crafts 内容编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Redirect("/root-login", 302)
		} else {
			var cid int64 = 4
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			tid, _ := self.GetInt(":tid")
			tid_handler := models.GetTopic(tid)
			self.Data["catpage"] = "crafts"
			self.Data["asidepage"] = "root-crafts-topic-edit"
			self.Data["topic"] = tid_handler
			self.Data["inode"] = models.GetNode(tid_handler.Nid)
			self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id")
			self.TplNames = "root/published.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-topic-del/([0-9]+)$"):
		//information 内容删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":tid"); mid != 0 {
				if e := models.DelTopic(mid); e != nil {
					self.Data["MsgErr"] = "删除内容失败!"
				} else {
					self.Data["MsgErr"] = "成功删除内容!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-information-topic-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-topic-del/([0-9]+)$"):
		//contact 内容删除GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":tid"); mid != 0 {
				if e := models.DelTopic(mid); e != nil {
					self.Data["MsgErr"] = "删除内容失败!"
				} else {
					self.Data["MsgErr"] = "成功删除内容!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-contact-topic-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-node-edit/([0-9]+)$"):
		// about 节点编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			nid, _ := self.GetInt(":nid")
			//var cid int64 = 6
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			self.Data["catpage"] = "about"
			self.Data["asidepage"] = "root_about_node_edit"
			self.Data["node"] = models.GetNode(nid)
			self.TplNames = "root/published_node.html"
			self.Render()
		}

	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-node-edit/([0-9]+)$"):
		//contact 节点编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			nid, _ := self.GetInt(":nid")
			//var cid int64 = 6
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			self.Data["catpage"] = "contact"
			self.Data["asidepage"] = "root_contact_node_edit"
			self.Data["node"] = models.GetNode(nid)
			self.TplNames = "root/published_node.html"
			self.Render()
		}

	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-node-edit/([0-9]+)$"):
		//services 节点编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			nid, _ := self.GetInt(":nid")
			//var cid int64 = 6
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			self.Data["catpage"] = "services"
			self.Data["asidepage"] = "root_services_node_edit"
			self.Data["node"] = models.GetNode(nid)
			self.TplNames = "root/published_node.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-node-edit/([0-9]+)$"):
		//information 节点编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			nid, _ := self.GetInt(":nid")
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			self.Data["catpage"] = "information"
			self.Data["asidepage"] = "root-information-node-edit"
			self.Data["node"] = models.GetNode(nid)
			self.TplNames = "root/published_node.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-node-edit/([0-9]+)$"):
		//crafts节点编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			nid, _ := self.GetInt(":nid")
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			self.Data["catpage"] = "crafts"
			self.Data["asidepage"] = "root-crafts-node-edit"
			self.Data["node"] = models.GetNode(nid)
			self.TplNames = "root/published_node.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-topic-edit/([0-9]+)$"):
		//information 内容编辑GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 5
			self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
			self.DelSession("MsgErr")

			tid, _ := self.GetInt(":tid")
			tid_handler := models.GetTopic(tid)
			self.Data["catpage"] = "information"
			self.Data["asidepage"] = "root-information-topic-edit"
			self.Data["topic"] = tid_handler
			self.Data["inode"] = models.GetNode(tid_handler.Nid)
			self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id")
			self.TplNames = "root/published.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-node-del/([0-9]+)$"):
		//services 节点删除 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":nid"); mid != 0 {
				if e := models.DelNode(mid); e != nil {
					self.Data["MsgErr"] = "删除节点失败!"
				} else {
					self.Data["MsgErr"] = "成功删除节点!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-services-node-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-node-del/([0-9]+)$"):
		//#INFORMATION 节点删除 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":nid"); mid != 0 {
				if e := models.DelNode(mid); e != nil {
					self.Data["MsgErr"] = "删除节点失败!"
				} else {
					self.Data["MsgErr"] = "成功删除节点!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-information-node-list", 302)

			}
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-node-del/([0-9]+)$"):
		//#crafts 删除节点 GET状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			if mid, _ := self.GetInt(":nid"); mid != 0 {
				if e := models.DelNode(mid); e != nil {
					self.Data["MsgErr"] = "删除节点失败!"
				} else {
					self.Data["MsgErr"] = "成功删除节点!"
				}
				self.SetSession("MsgErr", self.Data["MsgErr"])
				self.Redirect("/root-crafts-node-list", 302)

			}
		}
	}

}