func (self *EditTopicHandler) Post() { self.TplNames = "edit-topic.html" flash := beego.NewFlash() tid, _ := self.GetInt(":tid") nid, _ := self.GetInt("nodeid") if nd, err := model.GetNode(nid); nd != nil && err == nil { uid, _ := self.GetSession("userid").(int64) tid_title := self.GetString("title") tid_content := self.GetString("content") if tid_title != "" && tid_content != "" { if tp, err := model.GetTopic(tid); tp != nil && err == nil { tp.Title = tid_title tp.Uid = uid //删去用户没再使用的图片 helper.DelLostImages(tp.Content, tid_content) tp.Content = tid_content if s, e := helper.GetBannerThumbnail(tid_content); e == nil { tp.Attachment = s } if cat, err := model.GetCategory(nd.Pid); err == nil { tp.Category = cat.Title } if row, err := model.PutTopic(tid, tp); row == 1 && err == nil { model.SetRecordforImageOnEdit(tid, uid) self.Redirect("/"+strconv.Itoa(int(tid))+"/", 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 { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } }
func (self *NewNodeHandler) Post() { self.TplNames = "new-node.html" flash := beego.NewFlash() cid, _ := self.GetInt("category") uid, _ := self.GetSession("userid").(int64) nid_title := self.GetString("title") nid_content := self.GetString("content") if nid_title != "" && nid_content != "" && cid != 0 { if nid, err := model.AddNode(nid_title, nid_content, cid, uid); err != nil { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } else { if nd, err := model.GetNode(nid); err != nil { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } else { catmap := &map[string]interface{}{ "node_time": time.Now(), "node_count": model.GetNodeCountByPid(cid), "node_last_user_id": uid} if e := model.UpdateCategory(cid, catmap); e != nil { fmt.Println("NewNode model.UpdateCategory errors:", e) } nd.Order = nd.Id * 10 if row, err := model.PutNode(nid, nd); row != 0 && err != nil { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } else { self.Redirect("/", 302) } } } } else { flash.Error("分类不存在或节点标题、节点内容为空,请纠正错误!") flash.Store(&self.Controller) return } }
func (self *HateHandler) Get() { if helper.IsSpider(self.Ctx.Request.UserAgent()) != true { name := self.GetString(":name") id, _ := self.GetInt(":id") if name == "topic" { tp, _ := model.GetTopic(id) 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) self.Ctx.WriteString(strconv.Itoa(int(tp.Hotscore))) } else if name == "timeline" { tl, _ := model.GetTimeline(id) tl.Hotdown = tl.Hotdown + 1 tl.Hotscore = helper.Hotness_Score(tl.Hotup, tl.Hotdown) tl.Hotness = helper.Hotness(tl.Hotup, tl.Hotdown, time.Now()) model.PutTimeline(id, tl) self.Ctx.WriteString(strconv.Itoa(int(tl.Hotscore))) } else if name == "node" { nd, _ := model.GetNode(id) 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 { self.Abort("401") } } else { self.Abort("401") } }
func (self *EditTopicHandler) Get() { self.TplNames = "edit-topic.html" flash := beego.NewFlash() tid, _ := self.GetInt(":tid") if tid_handler, err := model.GetTopic(tid); err == nil { self.Data["topic"] = *tid_handler self.Data["inode"], _ = model.GetNode(tid_handler.Nid) } else { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } }
func (self *NewTopicHandler) Post() { self.TplNames = "new-topic.html" flash := beego.NewFlash() nid, _ := self.GetInt("nodeid") nd, err := model.GetNode(nid) if err != nil || nid == 0 { flash.Error("节点不存在,请创建或指定正确的节点!") flash.Store(&self.Controller) return } else { cid := nd.Pid uid, _ := self.GetSession("userid").(int64) sess_username, _ := self.GetSession("username").(string) tid_title := self.GetString("title") tid_content := self.GetString("content") if tid_title != "" && tid_content != "" { tp := new(model.Topic) tp.Title = tid_title tp.Content = tid_content tp.Cid = cid tp.Nid = nid tp.Uid = uid tp.Node = nd.Title tp.Author = sess_username tp.Created = time.Now() if s, e := helper.GetBannerThumbnail(tid_content); e == nil { tp.Attachment = s } if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := helper.GetThumbnails(tid_content); e == nil { tp.Thumbnails = thumbnails tp.ThumbnailsLarge = thumbnailslarge tp.ThumbnailsMedium = thumbnailsmedium tp.ThumbnailsSmall = thumbnailssmall } if cat, err := model.GetCategory(cid); err == nil { tp.Category = cat.Title } nodezmap := &map[string]interface{}{ "topic_time": time.Now(), "topic_count": model.GetTopicCountByNid(nid), "topic_last_user_id": uid} if e := model.UpdateNode(nid, nodezmap); e != nil { fmt.Println("NewTopic model.UpdateNode errors:", e) } if tid, err := model.PostTopic(tp); err == nil { model.SetRecordforImageOnPost(tid, uid) self.Redirect("/"+strconv.Itoa(int(tid))+"/", 302) } else { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } } else { flash.Error("话题标题或内容为空!") flash.Store(&self.Controller) return } } }
func (self *NodeHandler) Get() { //fmt.Println("im NodeHandler") self.TplNames = "node.html" tab := self.GetString(":tab") ipage, _ := self.GetInt(":page") page := int(ipage) nid, _ := self.GetInt(":nid") ndname := self.GetString(":name") if nid > 0 { if n, e := model.GetNode(nid); e == nil && n != nil { ndname = n.Title } } url := "/node/" if tab == "lastest" { url = "/node/lastest/" + ndname + "/" tab = "id" self.Data["tab"] = "lastest" } else if tab == "hotness" { url = "/node/hotness/" + ndname + "/" tab = "hotness" self.Data["tab"] = "hotness" } else { url = "/node/hotness/" + ndname + "/" tab = "hotness" self.Data["tab"] = "hotness" } pagesize := 30 if ndname != "" { //检验节点是否存在 if nd, err := model.GetNodeByTitle(ndname); err == nil && nd != nil { //更新节点统计信息 nd.Views = nd.Views + 1 self.Data["innode"] = *nd self.Data["catpage"] = nd.Title model.PutNode(nd.Id, nd) limit := 25 rcs := len(*model.GetTopicsByNid(nd.Id, 0, 0, 0, "hotness")) pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, int(page), limit) //通过节点的名字获取下级话题 if tps, err := model.GetTopicsByNode(ndname, offset, pagesize, tab); err == nil { results_count := len(*tps) if results_count > 0 { i := 1 output := "" for _, v := range *tps { i += i if i == 3 { output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin pin3">` i = 0 } else { output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin">` } output = output + `<div class="pin-coat"> <a href="/` + strconv.Itoa(int(v.Id)) + `/" class='imageLink image loading' target='_blank'> <img src='/static/mzr/img/dot.png' original='` + v.ThumbnailsLarge + `' width='200' height='150' alt='` + v.Title + ` ` + v.Created.String() + ` ` + v.Node + ` ` + v.Category + `' oriheight='300' /> <span class='bg'>` + v.Title + `</span> </a> <div class="pin-data clx"> <span class="timer"> <em></em> <span>` + helper.TimeSince(v.Created) + `</span> </span> <a href="/` + strconv.Itoa(int(v.Id)) + `/" class="viewsButton" title="阅读` + v.Title + `" target="_blank"> <em></em> <span>` + strconv.Itoa(int(v.Views)) + ` views</span> </a> </div> </div> </div>` } self.Data["topics"] = output } } else { fmt.Println("节点推荐榜单 数据查询出错", err) } self.Data["pagesbar"] = helper.Pagesbar(url, "", rcs, pages, pageout, beginnum, endnum, 0) //侧栏九宫格推荐榜单 output_start := `<ul class="widgets-popular widgets-similar clx">` output := "" i := 0 //根据节点的上级PID 获取同分类下的最热话题 if tps := model.GetTopicsByCid(nd.Pid, 0, 9, 0, "hotness"); len(*tps) > 0 { for _, v := range *tps { i += 1 if i == 3 { output = output + `<li class="similar similar-third">` i = 0 } else { output = output + `<li class="similar">` } output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"> <img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" /> </a> </li>` } } output_end := "</ul>" if len(output) > 0 { output = output_start + output + output_end self.Data["topic_hotness_9_module"] = template.HTML(output) } else { self.Data["topic_hotness_9_module"] = nil } } else { self.Redirect("/", 302) } } else { self.Redirect("/", 302) } }