Esempio n. 1
0
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
	}
}
Esempio n. 2
0
func (self *CategoryHandler) Get() {
	//fmt.Println("im CategoryHandler")
	self.TplNames = "category.html"

	ipage, _ := self.GetInt(":page")
	page := int(ipage)
	cid, _ := self.GetInt(":cid")
	tab := self.GetString(":tab")
	catname := self.GetString(":name")
	if cid > 0 {

		if c, e := model.GetCategory(cid); e == nil && c != nil {
			catname = c.Title
		}
	}
	self.Data["category"] = catname
	self.Data["catpage"] = catname

	url := "/category/"
	if tab == "lastest" {
		if catname != "" {
			url = "/category/lastest/" + catname + "/"
		} else {
			url = "/category/lastest/"
		}
		tab = "id"
		self.Data["tab"] = "lastest"
	} else if tab == "hotness" {

		if catname != "" {
			url = "/category/hotness/" + catname + "/"
		} else {
			url = "/category/hotness/"
		}
		tab = "hotness"
		self.Data["tab"] = "hotness"
	} else {
		if catname != "" {
			url = "/category/hotness/" + catname + "/"
		} else {
			url = "/category/hotness/"
		}

		tab = "hotness"
		self.Data["tab"] = "hotness"
	}

	pagesize := 30
	results_count, err := model.GetTopicsByCategoryCount(catname, 0, pagesize, tab)
	if err != nil {
		return
	}
	pages, page, beginnum, endnum, offset := helper.Pages(int(results_count), page, pagesize)

	if tps := model.GetTopicsByCategory(catname, offset, pagesize, 0, tab); len(*tps) > 0 {
		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
			self.Data["pagesbar"] = helper.Pagesbar(url, "", results_count, pages, page, beginnum, endnum, 0)
		}

	}

	//侧栏九宫格推荐榜单
	//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
	if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
		if len(*nd) > 0 {
			for _, v := range *nd {

				i := 0
				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

					if 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 {
		fmt.Println("节点数据查询出错", err)
	}
}
Esempio n. 3
0
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
		}
	}
}