Example #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")
	}

}
Example #2
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)
	}

}
Example #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()
}
func (self *RAdvantagesHandler) Get() {
	var cid int64 = 2 //優勢属于第二个分类
	self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
	self.DelSession("MsgErr")
	self.Data["catpage"] = "advantages"

	switch {

	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-advantages-del/([0-9]+)$"):
		//删除GET状态 删除內容
		tid, _ := self.GetInt(":tid")

		if e := models.DelTopic(tid); e != nil {
			self.Data["MsgErr"] = "删除內容失败!"
		} else {

			self.Data["MsgErr"] = "删除內容成功!"
		}

		self.SetSession("MsgErr", self.Data["MsgErr"])
		self.Redirect("/root-advantages-list", 302)

	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-advantages-edit/([0-9]+)$"):
		//编辑GET状态
		self.Data["asidepage"] = "root_advantages_edit"
		tid, _ := self.GetInt(":tid")
		self.Data["topic"] = models.GetTopic(tid)
		self.TplNames = "root/advantages.html"
		self.Render()

	case self.Ctx.Request.RequestURI == "/root-advantages-list":
		//優勢列表
		self.Data["asidepage"] = "root-advantages-list"
		self.Data["topics"] = models.GetAllTopicByCid(cid, 0, 0, 0, "asc")
		self.TplNames = "root/advantages_list.html"
		self.Render()

	default:
		//设置優勢
		self.Data["asidepage"] = "root_advantages"
		self.TplNames = "root/advantages.html"
		self.Render()
	}
}
Example #5
0
func (self *RSetvideoHandler) Get() {
	self.Data["catpage"] = "about"

	var tid int64 = 0
	for _, v := range models.GetAllTopicByCid(1, 0, 1, 30, "id") {
		if v.Id > 0 {
			tid = v.Id
		}
	}

	self.Data["topic"] = models.GetTopic(tid)

	//self.Data["nodes"] = models.GetAllNodeByCid(1, 0, 0, "id")
	self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
	self.DelSession("MsgErr")

	//簡介設置
	self.Data["asidepage"] = "root-about-setvideo"
	self.TplNames = "root/about_setvideo.html"

	self.Render()
}
Example #6
0
func (self *RAboutHandler) Get() {
	self.Data["catpage"] = "about"
	tid, _ := self.GetInt(":tid")
	self.Data["topic"] = models.GetTopic(tid)
	self.Data["topics"] = models.GetAllTopicByCid(1, 0, 0, 1, "id")
	self.Data["nodes"] = models.GetAllNodeByCid(1, 0, 0, 0, "id")
	self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string)
	self.DelSession("MsgErr")

	switch {
	case self.Ctx.Request.RequestURI == "/root-about":
		//发布内容
		self.Data["asidepage"] = "root_about"
		self.TplNames = "root/about.html"

		self.Render()
	case self.Ctx.Request.RequestURI == "/root-about-topic-list":
		//内容列表
		self.Data["asidepage"] = "root-about-topic-list"
		self.TplNames = "root/about_topic_list.html"

		self.Render()
	case self.Ctx.Request.RequestURI == "/root-about-new-node":
		//创建分类
		self.Data["asidepage"] = "root_about_new_node"
		self.TplNames = "root/about_new_node.html"

		self.Render()
	case self.Ctx.Request.RequestURI == "/root-about-node-list":
		//分类列表
		self.Data["asidepage"] = "root_about_node"
		self.TplNames = "root/about_node.html"

		self.Render()
	}
}
Example #7
0
func (self *RSetvideoHandler) Post() {

	ftitle := self.GetString("ftitle")
	content := self.GetString("content")
	var nodeid int64 = 1
	var cid int64 = 1
	uid, _ := self.GetSession("userid").(int64)

	msg := ""
	if ftitle == "" {
		msg = msg + "标题不能为空!"
	}

	if content == "" {
		msg = msg + "視頻鏈接不能为空!"
	}

	self.Data["MsgErr"] = msg

	if msg == "" {

		//新增内容POST状态
		file, handler, e := self.GetFile("image")
		path := ""

		if handler == nil {
			var tid int64 = 0
			for _, v := range models.GetAllTopicByCid(1, 0, 1, 30, "id") {
				if v.Id > 0 {
					tid = v.Id
				}
			}

			if m := models.GetTopic(tid); m.Attachment != "" {
				path = m.Attachment
			} else {

				self.Data["MsgErr"] = "你还没有选择封面!"
			}
		}

		if handler != nil {
			if e != nil {
				self.Data["MsgErr"] = "传输过程文件产生错误!"

			} else {

				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path = "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"

				} else {
					//拷貝成功之後執行刪除舊文件
					if _, err := io.Copy(f, file); err == nil {
						var tid int64 = 0
						for _, v := range models.GetAllTopicByCid(1, 0, 1, 30, "id") {
							if v.Id > 0 {
								tid = v.Id
							}
						}

						if m := models.GetTopic(tid); m.Attachment != "" {
							if err := os.Remove("." + m.Attachment); err != nil {
								fmt.Println("Remove Old Image", err)
							}
						}

					}
				}
			}

		}

		if self.Data["MsgErr"] == "" && path != "" && ftitle != "" && content != "" {
			//开始添加内容
			input_file := "." + path
			output_file := "." + path
			output_size := "196x117"
			output_align := "center"
			watermark_file := "./static/themes/ibeatuys/img/vicon.png"
			if e := helper.Thumbnail(input_file, output_file, output_size, output_align, "white"); e != nil {
				fmt.Println("Thumbnail", e)
			}

			if e := helper.Watermark(watermark_file, input_file, output_file, output_align); e != nil {
				fmt.Println("Watermark", e)
			}
			if e := models.SetTopic(2, cid, nodeid, uid, 30, ftitle, content, "root", path); e != nil {
				self.Data["MsgErr"] = "添加“" + ftitle + "”失败,无法写入数据库!"
			} else {
				self.Data["MsgErr"] = "添加“" + ftitle + "”成功,你可以继续添加其他内容!"
			}

		}
	}

	self.SetSession("MsgErr", self.Data["MsgErr"])
	self.Redirect(self.Ctx.Request.RequestURI, 302)

}
Example #8
0
func (self *RServicesHandler) Post() {
	title := self.GetString("title")
	content := self.GetString("content")
	nodeid, _ := self.GetInt("nodeid")
	var cid int64 = 3
	uid, _ := self.GetSession("userid").(int64)
	sess_username, _ := self.GetSession("username").(string)

	msg := ""
	if title == "" {
		msg = msg + "內容标题不能为空!"
	}
	if nodeid == 0 {
		msg = msg + "必须选择一个上级分类!"
	}
	if content == "" {
		msg = msg + "內容内容不能为空!"
	}

	self.Data["MsgErr"] = msg

	if msg == "" {
		switch {
		case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-edit/([0-9]+)$"):
			//编辑POST状态
			tid, _ := self.GetInt(":tid")
			file, handler, e := self.GetFile("image")
			defer file.Close()
			if handler == nil {

				if tid != 0 {
					item := models.GetTopic(tid)
					if item.Attachment != "" {
						self.Data["file_location"] = item.Attachment
					} else {
						self.Data["MsgErr"] = "你还没有选择內容封面!"
						self.Data["file_location"] = ""
					}
				} else {
					self.Data["MsgErr"] = "你编辑的內容不存在!"
				}
			}

			if nodeid != 0 && title != "" && content != "" && tid != 0 {
				if handler != nil {
					if e != nil {
						self.Data["MsgErr"] = "传输图片文件过程中产生错误!"
					}

					ext := "." + strings.Split(handler.Filename, ".")[1]
					filename := helper.MD5(time.Now().String()) + ext

					path := "/archives/upload/" + time.Now().Format("2006/01/02/")

					os.MkdirAll("."+path, 0644)
					path = path + filename
					f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
					defer f.Close()
					if err != nil {
						self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
					} else {
						io.Copy(f, file)
						input_file := "." + path
						output_file := "." + path
						output_size := "211x134"
						output_align := "center"
						helper.Thumbnail(input_file, output_file, output_size, output_align, "white")

						//若文件存在则删除,不存在就当忽略处理
						if self.Data["file_location"] != nil {
							if helper.Exist("." + self.Data["file_location"].(string)) {
								if err := os.Remove("." + self.Data["file_location"].(string)); err != nil {
									self.Data["MsgErr"] = "删除旧形象图片错误!"
								}
							}
						}
						self.Data["file_location"] = path

					}
				}
				if self.Data["file_location"] != "" {
					//保存编辑
					if e := models.SetTopic(tid, cid, nodeid, uid, 1, title, content, sess_username, self.Data["file_location"].(string)); e != nil {
						self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"
					} else {
						self.Data["MsgErr"] = "你提交的修改已保存成功!"
					}

				} else {
					self.Data["MsgErr"] = "你提交的內容缺少封面!"
				}
			}
		case self.Ctx.Request.RequestURI == "/root-services":
			//新增內容POST状态
			file, handler, e := self.GetFile("image")
			switch {
			case handler == nil:
				self.Data["MsgErr"] = "你还没有选择內容封面!"
			case handler != nil && nodeid != 0 && title != "" && content != "":
				//开始添加內容
				if e != nil {
					self.Data["MsgErr"] = "传输过程文件产生错误!"
				}

				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					input_file := "." + path
					output_file := "." + path
					output_size := "211x134"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "white")
					if e := models.SetTopic(0, cid, nodeid, uid, 1, title, content, sess_username, path); e != nil {
						self.Data["MsgErr"] = "添加內容“" + title + "”失败,无法写入数据库!"
					} else {
						self.Data["MsgErr"] = "添加內容“" + title + "”成功,你可以继续添加其他內容!"
					}

				}
			}
		}
	} else {

		switch {
		case self.Ctx.Request.RequestURI == "/root-services-new-node":
			//新建內容分类
			title := self.GetString("title")
			content := self.GetString("content")
			if title != "" {
				models.AddNode(title, content, 3, -1000)
				self.Data["MsgErr"] = "內容分类“" + title + "”创建成功!"
			} else {
				self.Data["MsgErr"] = "內容分类标题不能为空!"
			}
		}

	}

	self.SetSession("MsgErr", self.Data["MsgErr"])
	self.Redirect(self.Ctx.Request.RequestURI, 302)

}
Example #9
0
func (self *RContactHandler) Post() {
	var cid int64 = 5
	title := self.GetString("title")
	content := self.GetString("content")
	nodeid, _ := self.GetInt("nodeid")
	uid, _ := self.GetSession("userid").(int64)
	sess_username, _ := self.GetSession("username").(string)

	msg := ""
	if title == "" {
		msg = msg + "内容标题不能为空!"
	}
	if nodeid == 0 {
		msg = msg + "必须选择一个上级分类!"
	}
	if content == "" {
		msg = msg + "内容内容不能为空!"
	}

	self.Data["MsgErr"] = msg
	if self.Ctx.Request.RequestURI == "/root-contact-new-node" {

		//新建内容分类
		if title != "" {
			if e := models.AddNode(title, content, cid, 1); e != nil {

				self.Data["MsgErr"] = "内容分类无法保存到数据库!"
			} else {

				self.Data["MsgErr"] = "内容分类成功保存到数据库!"
			}

			if content == "" {
				self.Data["MsgErr"] = ""
			}
			self.Data["MsgErr"] = "内容分类“" + title + "”创建成功!"
		} else {
			self.Data["MsgErr"] = "内容分类标题不能为空!"
		}
	} else {

		if msg == "" {
			switch {
			case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-edit/([0-9]+)$"):
				//编辑POST状态
				tid, _ := self.GetInt(":tid")
				file, handler, e := self.GetFile("image")
				defer file.Close()
				if handler == nil {

					if tid != 0 {
						icase := models.GetTopic(tid)
						if icase.Attachment != "" {
							self.Data["file_location"] = icase.Attachment
						} else {
							self.Data["MsgErr"] = "你还没有选择内容封面!"
							self.Data["file_location"] = ""
						}
					} else {
						self.Data["MsgErr"] = "你编辑的内容不存在!"
					}
				}
				if nodeid != 0 && title != "" && content != "" && tid != 0 {
					if handler != nil {
						if e != nil {
							self.Data["MsgErr"] = "传输图片文件过程中产生错误!"
						}

						ext := "." + strings.Split(handler.Filename, ".")[1]
						filename := helper.MD5(time.Now().String()) + ext

						path := "/archives/upload/" + time.Now().Format("2006/01/02/")

						os.MkdirAll("."+path, 0644)
						path = path + filename
						f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
						defer f.Close()
						if err != nil {
							self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
						} else {
							io.Copy(f, file)
							input_file := "." + path
							output_file := "." + path
							output_size := "214x335"
							output_align := "center"
							helper.Thumbnail(input_file, output_file, output_size, output_align, "black")

							//若文件存在则删除,不存在就当忽略处理
							if self.Data["file_location"] != nil {
								if helper.Exist("." + self.Data["file_location"].(string)) {
									if err := os.Remove("." + self.Data["file_location"].(string)); err != nil {
										self.Data["MsgErr"] = "删除旧文件错误!"
									}
								}
							}
							self.Data["file_location"] = path

						}
					}
					if self.Data["file_location"] != "" {
						//保存编辑
						if e := models.SetTopic(tid, cid, nodeid, uid, 0, title, content, sess_username, self.Data["file_location"].(string)); e != nil {
							self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"
						} else {
							self.Data["MsgErr"] = "你提交的修改已保存成功!"
						}

					} else {
						self.Data["MsgErr"] = "你提交的内容缺少封面!"
					}
				}
			case self.Ctx.Request.RequestURI == "/root-contact":
				//新增内容POST状态
				file, handler, e := self.GetFile("image")
				switch { /*
					case handler == nil:
						self.Data["MsgErr"] = "你还没有选择封面!"*/
				case /* handler != nil &&*/ nodeid != 0 && title != "" && content != "":
					//开始添加内容
					if e != nil {
						self.Data["MsgErr"] = "传输过程文件产生错误!"
					}
					if handler != nil {

						ext := "." + strings.Split(handler.Filename, ".")[1]
						filename := helper.MD5(time.Now().String()) + ext

						path := "/archives/upload/" + time.Now().Format("2006/01/02/")

						os.MkdirAll("."+path, 0644)
						path = path + filename
						self.Data["file_localtion"] = path

					}

					uid, _ := self.GetSession("userid").(int64)
					username, _ := self.GetSession("username").(string)
					path := ""
					if self.Data["file_localtion"] != nil {
						path := self.Data["file_localtion"].(string)
						f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
						defer f.Close()

						if err != nil {
							self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
						} else {

							io.Copy(f, file)
							input_file := "." + path
							output_file := "." + path
							output_size := "288x180"
							output_align := "center"
							helper.Thumbnail(input_file, output_file, output_size, output_align, "black")
						}
					}
					if e := models.SetTopic(0, cid, nodeid, uid, 0, title, content, username, path); e != nil {
						self.Data["MsgErr"] = "添加“" + title + "”失败,无法写入数据库!"
					} else {
						self.Data["MsgErr"] = "添加“" + title + "”成功,你可以继续添加其他内容!"
					}

				}
			}
		}
	}
	self.SetSession("MsgErr", self.Data["MsgErr"])
	self.Redirect(self.Ctx.Request.RequestURI, 302)

}
Example #10
0
func (self *RApi) Post() {
	switch {
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-gallery-edit/([0-9]+)$"):
		//# Gallery 圖片编辑 POST状态 ,主要是爲了設置url
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.WriteString(outtimesz)
		} else {
			inputs := self.Input()
			url := inputs.Get("url")
			//圖片ID
			editmid, _ := self.GetInt(":editmid")
			img := models.GetFile(editmid)

			if e := models.SetFile(editmid, img.Pid, img.Ctype, img.Filename, img.Content, img.Hash, img.Location, url, img.Size); e != nil {
				self.Data["MsgErr"] = "设置图片链接失败!"
			} else {
				self.Data["MsgErr"] = "设置图片链接成功!"
			}

			self.TplNames = "root/gallery_editurl.html"
			self.Render()
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-topic-edit/([0-9]+)$"):
		//ABOUT内容编辑 POST状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid, nid int64 = 1, 1
			file_location := ""
			ftitle := self.GetString("ftitle")
			stitle := self.GetString("stitle")
			content := self.GetString("content")
			uid, _ := self.GetSession("userid").(int64)
			tid, _ := self.GetInt(":tid")

			file, handler, e := self.GetFile("image")

			if handler != nil && e == nil {

				if tid != 0 {
					tp := models.GetTopic(tid)
					if tp.Attachment != "" {
						file_location = tp.Attachment
					}
				} else {
					self.Data["MsgErr"] = "你编辑的内容不存在!"
				}
				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					defer file.Close()
					input_file := "." + path
					output_file := "." + path
					output_size := "232x135"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "white")

					//若文件存在则删除,不存在就当忽略处理
					if file_location != "" {
						if helper.Exist("." + file_location) {
							if err := os.Remove("." + file_location); err != nil {
								self.Data["MsgErr"] = "删除旧文件错误!"
							}
						}
					}
					file_location = path

				}
			}

			if ftitle != "" && nid != 0 && content != "" {
				//保存编辑
				if e := models.SetTopic(tid, cid, nid, uid, 1, ftitle, content, stitle, file_location); e != nil {
					self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"

				} else {
					self.Data["MsgErr"] = "你提交的修改已保存成功!"
				}
			} else {
				//下面三个为基本诉求
				msg := ""
				if ftitle == "" {
					msg = msg + "标题不能为空!"
				}
				if nid == 0 {
					msg = msg + "分类不正确!"
				}
				if content == "" {
					msg = msg + "内容不能为空!"
				}
				self.Data["MsgErr"] = msg
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-about-node-edit/([0-9]+)$"):
		/// about 节点编辑 POST状态

		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 1
			title := self.GetString("title")
			content := self.GetString("content")
			nid, _ := self.GetInt(":nid")
			//编辑NODE
			if title != "" && nid != 0 {
				if e := models.SetNode(nid, title, content, cid, 1); e != nil {

					self.Data["MsgErr"] = "内容分类无法保存到数据库!"
				} else {

					self.Data["MsgErr"] = "内容分类成功保存到数据库!"
				}

				if content == "" {
					self.Data["MsgErr"] = ""
				}
				self.Data["MsgErr"] = "内容分类“" + title + "”保存成功!"
			} else {
				self.Data["MsgErr"] = "内容分类标题不能为空!"
			}

			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-node-edit/([0-9]+)$"):
		/// services 节点编辑 POST状态

		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 3
			title := self.GetString("title")
			content := self.GetString("content")
			nid, _ := self.GetInt(":nid")
			//编辑NODE
			if title != "" && nid != 0 {
				if e := models.SetNode(nid, title, content, cid, 1); e != nil {

					self.Data["MsgErr"] = "内容分类无法保存到数据库!"
				} else {

					self.Data["MsgErr"] = "内容分类成功保存到数据库!"
				}

				if content == "" {
					self.Data["MsgErr"] = ""
				}
				self.Data["MsgErr"] = "内容分类“" + title + "”保存成功!"
			} else {
				self.Data["MsgErr"] = "内容分类标题不能为空!"
			}

			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-topic-edit/([0-9]+)$"):
		// services 内容编辑 POST状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 3
			file_location := ""
			ftitle := self.GetString("ftitle")
			stitle := self.GetString("stitle")
			content := self.GetString("content")
			uid, _ := self.GetSession("userid").(int64)
			tid, _ := self.GetInt(":tid")
			nid, _ := self.GetInt("nodeid")
			file, handler, e := self.GetFile("image")

			if handler != nil && e == nil {

				if tid != 0 {
					tp := models.GetTopic(tid)
					if tp.Attachment != "" {
						file_location = tp.Attachment
					}
				} else {
					self.Data["MsgErr"] = "你编辑的内容不存在!"
				}
				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					defer file.Close()
					input_file := "." + path
					output_file := "." + path
					output_size := "211x134"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "white")

					//若文件存在则删除,不存在就当忽略处理
					if file_location != "" {
						if helper.Exist("." + file_location) {
							if err := os.Remove("." + file_location); err != nil {
								self.Data["MsgErr"] = "删除旧文件错误!"
							}
						}
					}
					file_location = path

				}
			}

			if ftitle != "" && nid != 0 && content != "" {
				//保存编辑
				if e := models.SetTopic(tid, cid, nid, uid, 1, ftitle, content, stitle, file_location); e != nil {
					self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"

				} else {
					self.Data["MsgErr"] = "你提交的修改已保存成功!"
				}
			} else {
				//下面三个为基本诉求
				msg := ""
				if ftitle == "" {
					msg = msg + "标题不能为空!"
				}
				if nid == 0 {
					msg = msg + "分类不正确!"
				}
				if content == "" {
					msg = msg + "内容不能为空!"
				}
				self.Data["MsgErr"] = msg
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-node-edit/([0-9]+)$"):
		/// crafts 节点编辑 POST状态

		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 4
			title := self.GetString("title")
			content := self.GetString("content")
			nid, _ := self.GetInt(":nid")
			//编辑NODE
			if title != "" && nid != 0 {
				if e := models.SetNode(nid, title, content, cid, 1); e != nil {

					self.Data["MsgErr"] = "内容分类无法保存到数据库!"
				} else {

					self.Data["MsgErr"] = "内容分类成功保存到数据库!"
				}

				if content == "" {
					self.Data["MsgErr"] = ""
				}
				self.Data["MsgErr"] = "内容分类“" + title + "”保存成功!"
			} else {
				self.Data["MsgErr"] = "内容分类标题不能为空!"
			}

			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-crafts-topic-edit/([0-9]+)$"):
		// crafts 内容编辑 POST状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 4
			file_location := ""
			ftitle := self.GetString("ftitle")
			stitle := self.GetString("stitle")
			content := self.GetString("content")
			uid, _ := self.GetSession("userid").(int64)
			tid, _ := self.GetInt(":tid")
			nid, _ := self.GetInt("nodeid")
			file, handler, e := self.GetFile("image")

			if handler != nil && e == nil {

				if tid != 0 {
					tp := models.GetTopic(tid)
					if tp.Attachment != "" {
						file_location = tp.Attachment
					}
				} else {
					self.Data["MsgErr"] = "你编辑的内容不存在!"
				}
				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					defer file.Close()
					input_file := "." + path
					output_file := "." + path
					output_size := "534"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "black")

					//若文件存在则删除,不存在就当忽略处理
					if file_location != "" {
						if helper.Exist("." + file_location) {
							if err := os.Remove("." + file_location); err != nil {
								self.Data["MsgErr"] = "删除旧文件错误!"
							}
						}
					}
					file_location = path

				}
			}

			if ftitle != "" && nid != 0 && content != "" {
				//保存编辑
				if e := models.SetTopic(tid, cid, nid, uid, 0, ftitle, content, stitle, file_location); e != nil {
					self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"

				} else {
					self.Data["MsgErr"] = "你提交的修改已保存成功!"
				}
			} else {
				//下面三个为基本诉求
				msg := ""
				if ftitle == "" {
					msg = msg + "标题不能为空!"
				}
				if nid == 0 {
					msg = msg + "分类不正确!"
				}
				if content == "" {
					msg = msg + "内容不能为空!"
				}
				self.Data["MsgErr"] = msg
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-topic-edit/([0-9]+)$"):
		// information 内容编辑 POST状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 5
			file_location := ""
			ftitle := self.GetString("ftitle")
			stitle := self.GetString("stitle")
			content := self.GetString("content")
			uid, _ := self.GetSession("userid").(int64)
			tid, _ := self.GetInt(":tid")
			nid, _ := self.GetInt("nodeid")
			file, handler, e := self.GetFile("image")

			if handler != nil && e == nil {

				if tid != 0 {
					tp := models.GetTopic(tid)
					if tp.Attachment != "" {
						file_location = tp.Attachment
					}
				} else {
					self.Data["MsgErr"] = "你编辑的内容不存在!"
				}
				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					defer file.Close()
					input_file := "." + path
					output_file := "." + path
					output_size := "534"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "black")

					//若文件存在则删除,不存在就当忽略处理
					if file_location != "" {
						if helper.Exist("." + file_location) {
							if err := os.Remove("." + file_location); err != nil {
								self.Data["MsgErr"] = "删除旧文件错误!"
							}
						}
					}
					file_location = path

				}
			}

			if ftitle != "" && nid != 0 && content != "" {
				//保存编辑
				if e := models.SetTopic(tid, cid, nid, uid, 0, ftitle, content, stitle, file_location); e != nil {
					self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"

				} else {
					self.Data["MsgErr"] = "你提交的修改已保存成功!"
				}
			} else {
				//下面三个为基本诉求
				msg := ""
				if ftitle == "" {
					msg = msg + "标题不能为空!"
				}
				if nid == 0 {
					msg = msg + "分类不正确!"
				}
				if content == "" {
					msg = msg + "内容不能为空!"
				}
				self.Data["MsgErr"] = msg
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-information-node-edit/([0-9]+)$"):
		// information 节点编辑 POST状态

		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 5
			title := self.GetString("title")
			content := self.GetString("content")
			nid, _ := self.GetInt(":nid")
			//编辑NODE
			if title != "" && nid != 0 {
				if e := models.SetNode(nid, title, content, cid, 1); e != nil {

					self.Data["MsgErr"] = "内容分类无法保存到数据库!"
				} else {

					self.Data["MsgErr"] = "内容分类成功保存到数据库!"
				}

				if content == "" {
					self.Data["MsgErr"] = ""
				}
				self.Data["MsgErr"] = "内容分类“" + title + "”保存成功!"
			} else {
				self.Data["MsgErr"] = "内容分类标题不能为空!"
			}

			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-node-edit/([0-9]+)$"):
		//contact 节点编辑 POST状态

		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 6
			title := self.GetString("title")
			content := self.GetString("content")
			nid, _ := self.GetInt(":nid")
			//编辑NODE
			if title != "" && nid != 0 {
				if e := models.SetNode(nid, title, content, cid, 1); e != nil {

					self.Data["MsgErr"] = "内容分类无法保存到数据库!"
				} else {

					self.Data["MsgErr"] = "内容分类成功保存到数据库!"
				}

				if content == "" {
					self.Data["MsgErr"] = ""
				}
				self.Data["MsgErr"] = "内容分类“" + title + "”保存成功!"
			} else {
				self.Data["MsgErr"] = "内容分类标题不能为空!"
			}

			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	case helper.Rex(self.Ctx.Request.RequestURI, "^/root-contact-topic-edit/([0-9]+)$"):
		//CONTACT内容编辑 POST状态
		if sess_role, _ := self.GetSession("userrole").(int64); sess_role != -1000 {
			self.Ctx.Redirect(302, "/root-login")
		} else {
			var cid int64 = 6
			file_location := ""
			ftitle := self.GetString("title")
			content := self.GetString("content")
			uid, _ := self.GetSession("userid").(int64)
			tid, _ := self.GetInt(":tid")
			nid, _ := self.GetInt("nodeid")

			if ftitle != "" && nid != 0 && content != "" {
				//保存编辑
				if e := models.SetTopic(tid, cid, nid, uid, 0, ftitle, content, "", file_location); e != nil {
					self.Data["MsgErr"] = "你提交的修改保存失败,无法写入数据库!"

				} else {
					self.Data["MsgErr"] = "你提交的修改已保存成功!"
				}
			} else {
				//下面三个为基本诉求
				msg := ""
				if ftitle == "" {
					msg = msg + "标题不能为空!"
				}
				if nid == 0 {
					msg = msg + "分类不正确!"
				}
				if content == "" {
					msg = msg + "内容不能为空!"
				}
				self.Data["MsgErr"] = msg
			}
			self.SetSession("MsgErr", self.Data["MsgErr"])
			self.Redirect(self.Ctx.Request.RequestURI, 302)
		}
	}
}
Example #11
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)

			}
		}
	}

}
func (self *RAdvantagesHandler) Post() {
	var cid int64 = 2

	title := self.GetString("title")
	content := self.GetString("content")
	nodeid, _ := self.GetInt("nodeid")
	uid, _ := self.GetSession("userid").(int64)
	uname, _ := self.GetSession("username").(string)

	tid, _ := self.GetInt(":tid")
	file, handler, e := self.GetFile("image")

	msg := ""
	if title == "" {
		msg = msg + "標題不能为空!"
	}

	if content == "" {
		msg = msg + "内容不能为空!"
	}

	self.Data["MsgErr"] = msg
	if msg == "" {
		switch {
		case helper.Rex(self.Ctx.Request.RequestURI, "^/root-advantages-edit/([0-9]+)$"):
			//编辑POST状态
			if handler == nil {

				if tid != 0 {
					advantages := models.GetTopic(tid)
					if advantages.Attachment != "" {
						self.Data["file_location"] = advantages.Attachment
					} else {
						self.Data["MsgErr"] = "你还没有选择內容封面圖片!"
						self.Data["file_location"] = ""
					}
				} else {
					self.Data["MsgErr"] = "你编辑的內容不存在!"
				}
			}
			if title != "" && content != "" && tid != 0 {
				if handler != nil {
					if e != nil {
						self.Data["MsgErr"] = "传输图片文件过程中产生错误!"
					}

					ext := "." + strings.Split(handler.Filename, ".")[1]
					filename := helper.MD5(time.Now().String()) + ext

					path := "/archives/upload/" + time.Now().Format("2006/01/02/")

					os.MkdirAll("."+path, 0644)
					path = path + filename
					f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
					defer f.Close()
					if err != nil {
						self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
					} else {
						io.Copy(f, file)
						input_file := "." + path
						output_file := "." + path
						output_size := "248x171"
						output_align := "center"
						helper.Thumbnail(input_file, output_file, output_size, output_align, "white")

						//若文件存在则删除,不存在就当忽略处理
						if self.Data["file_location"] != nil {
							if helper.Exist("." + self.Data["file_location"].(string)) {
								if err := os.Remove("." + self.Data["file_location"].(string)); err != nil {
									self.Data["MsgErr"] = "删除旧形象图片错误!"
								}
							}
						}
						self.Data["file_location"] = path

					}
				}
				if self.Data["file_location"] != "" {
					//保存编辑
					if e := models.SetTopic(tid, cid, nodeid, uid, 0, title, content, uname, self.Data["file_location"].(string)); e != nil {
						self.Data["MsgErr"] = "修改“" + title + "”失败,无法写入数据库!"
					} else {
						self.Data["MsgErr"] = "修改“" + title + "”成功,你可以继续修改其他内容!"
					}

				} else {
					self.Data["MsgErr"] = "你提交的內容缺少封面圖片!"
				}
			}
		case self.Ctx.Request.RequestURI == "/root-advantages":
			//新增內容POST状态
			if handler == nil {
				self.Data["MsgErr"] = "你还没有选择內容封面圖片!"
			}

			if handler != nil && title != "" && content != "" {
				//开始添加內容
				if e != nil {
					self.Data["MsgErr"] = "传输过程文件产生错误!"
				}

				ext := "." + strings.Split(handler.Filename, ".")[1]
				filename := helper.MD5(time.Now().String()) + ext

				path := "/archives/upload/" + time.Now().Format("2006/01/02/")

				os.MkdirAll("."+path, 0644)
				path = path + filename
				f, err := os.OpenFile("."+path, os.O_WRONLY|os.O_CREATE, 0644)
				defer f.Close()
				if err != nil {
					self.Data["MsgErr"] = "无法打开服务端文件存储路径!"
				} else {
					io.Copy(f, file)
					input_file := "." + path
					output_file := "." + path
					output_size := "248x171"
					output_align := "center"
					helper.Thumbnail(input_file, output_file, output_size, output_align, "white")
					if e := models.SetTopic(0, cid, nodeid, uid, 0, title, content, uname, path); e != nil {
						self.Data["MsgErr"] = "添加“" + title + "”失败,无法写入数据库!"
					} else {
						self.Data["MsgErr"] = "添加“" + title + "”成功,你可以继续添加其他案例!"
					}

				}
			}
		}
	}

	self.SetSession("MsgErr", self.Data["MsgErr"])
	self.Redirect(self.Ctx.Request.RequestURI, 302)

}