func (self *RContactHandler) Get() { var cid int64 = 5 self.Data["catpage"] = "contact" self.Data["topics"] = models.GetAllTopicByCid(cid, 0, 0, 0, "id") self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id") self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string) self.DelSession("MsgErr") switch { case self.Ctx.Request.RequestURI == "/root-contact": self.Data["asidepage"] = "root_contact" self.TplNames = "root/contact.html" case self.Ctx.Request.RequestURI == "/root-contact-node-list": self.Data["asidepage"] = "root_contact_node" self.TplNames = "root/contact_node.html" case self.Ctx.Request.RequestURI == "/root-contact-new-node": self.Data["asidepage"] = "root_contact_new_node" self.TplNames = "root/contact_new_node.html" case self.Ctx.Request.RequestURI == "/root-contact-topic-list": self.Data["asidepage"] = "root_contact_topic_list" self.TplNames = "root/contact_topic_list.html" } self.Render() }
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) } }
func (self *MainHandler) Get() { page, _ := self.GetInt("page") curtab, _ := self.GetInt("tab") cid, _ := self.GetInt(":cid") limit := 25 home := "false" if cid == 0 { home = "true" } self.Data["home"] = home self.Data["curcate"] = cid self.Data["curtab"] = curtab topics_rcs := len(models.GetAllTopicByCid(cid, 0, 0, 0, "hotness")) topics_pages, topics_pageout, topics_beginnum, topics_endnum, offset := helper.Pages(topics_rcs, int(page), limit) self.Data["topics_latest"] = models.GetAllTopicByCid(cid, offset, limit, 0, "id") self.Data["topics_hotness"] = models.GetAllTopicByCid(cid, offset, limit, 0, "hotness") self.Data["topics_views"] = models.GetAllTopicByCid(cid, offset, limit, 0, "views") self.Data["topics_reply_count"] = models.GetAllTopicByCid(cid, offset, limit, 0, "reply_count") self.Data["topics_pagesbar_tab1"] = helper.Pagesbar("tab=1&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1) self.Data["topics_pagesbar_tab2"] = helper.Pagesbar("tab=2&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1) self.Data["topics_pagesbar_tab3"] = helper.Pagesbar("tab=3&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1) self.Data["topics_pagesbar_tab4"] = helper.Pagesbar("tab=4&", topics_rcs, topics_pages, topics_pageout, topics_beginnum, topics_endnum, 1) nodes_rcs := len(models.GetAllNodeByCid(cid, 0, 0, 0, "hotness")) nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, offset := helper.Pages(nodes_rcs, int(page), limit) self.Data["nodes_latest"] = models.GetAllNodeByCid(cid, offset, limit, 0, "id") self.Data["nodes_hotness"] = models.GetAllNodeByCid(cid, offset, limit, 0, "hotness") self.Data["nodes_pagesbar_tab5"] = helper.Pagesbar("tab=5&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1) self.Data["nodes_pagesbar_tab6"] = helper.Pagesbar("tab=6&", nodes_rcs, nodes_pages, nodes_pageout, nodes_beginnum, nodes_endnum, 1) self.Layout = "layout.html" self.TplNames = "index.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() } }
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() }
func (self *RServicesHandler) Get() { var cid int64 = 3 self.Data["catpage"] = "services" self.Data["nodes"] = models.GetAllNodeByCid(cid, 0, 0, 0, "id") self.Data["MsgErr"], _ = self.GetSession("MsgErr").(string) self.DelSession("MsgErr") self.Data["topics"] = models.GetAllTopicByCid(cid, 0, 0, 0, "id") switch { case helper.Rex(self.Ctx.Request.RequestURI, "^/root-services-del/([0-9]+)$"): self.Data["asidepage"] = "root_services_list" self.TplNames = "root/services_list.html" case self.Ctx.Request.RequestURI == "/root-services-new-node": //新建內容分类 self.Data["asidepage"] = "root_services_new_node" self.TplNames = "root/services_new_node.html" case self.Ctx.Request.RequestURI == "/root-services-node-list": //內容分类列表 self.Data["asidepage"] = "root_services_node" self.TplNames = "root/services_node.html" case self.Ctx.Request.RequestURI == "/root-services-topic-list": //內容列表 self.Data["asidepage"] = "root-services-topic-list" self.TplNames = "root/services_topic_list.html" case self.Ctx.Request.RequestURI == "/root-services": //设置內容 self.Data["asidepage"] = "root_services" self.TplNames = "root/services.html" } self.Render() }
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() } }
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) }