Example #1
0
func (this *Navs) Get() error {
	sortSlug := this.Params().Get(":sortSlug")

	cnt, err := models.CountByExample(&models.Post{})
	if err != nil {
		return err
	}

	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	posts, err := models.RecentPosts(sortSlug, setting.PostCountPerPage, pager.Offset())
	if err != nil {
		return err
	}

	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	this.Data["SortSlug"] = sortSlug
	this.Data["CategorySlug"] = "home"
	//new best posts
	var newBestPosts []models.Post
	this.setNewBestPosts(&newBestPosts)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPosts(&mostReplysPosts)
	this.setSidebarBuilletinInfo()
	return this.Render("post/home.html", this.Data)
}
Example #2
0
File: user.go Project: zeuson/wego
func (this *Home) Get() error {
	this.Data["IsUserHomePage"] = true

	var user models.User
	if this.getUser(&user) {
		return nil
	}

	//recent posts and comments
	limit := 5

	posts, _ := models.RecentPosts("recent", limit, 0)
	comments, _ := models.RecentCommentsByUserId(user.Id, limit)

	this.Data["TheUserPosts"] = posts
	this.Data["TheUserComments"] = comments

	//follow topics
	var topics []*models.Topic
	ftopics, _ := models.FindFollowTopic(user.Id, 8)
	if len(ftopics) > 0 {
		topics = make([]*models.Topic, 0, len(ftopics))
		for _, ft := range ftopics {
			topics = append(topics, ft.Topic())
		}
	}
	this.Data["TheUserFollowTopics"] = topics
	this.Data["TheUserFollowTopicsMore"] = len(ftopics) >= 8

	//favorite posts
	var favPostIds = make([]int64, 0)
	var favPosts []models.Post
	models.ORM().Limit(8).Desc("created").Iterate(new(models.FavoritePost), func(idx int, bean interface{}) error {
		favPostIds = append(favPostIds, bean.(*models.FavoritePost).PostId)
		return nil
	})
	if len(favPostIds) > 0 {
		models.ORM().In("id", favPostIds).Desc("created").Find(&favPosts)
	}
	this.Data["TheUserFavoritePosts"] = favPosts
	this.Data["TheUserFavoritePostsMore"] = len(favPostIds) >= 8

	return this.Render("user/home.html", this.Data)
}
Example #3
0
//Get the posts by category
func (this *Category) Get() error {
	//check category slug
	slug := this.Params().Get(":slug")
	cat, err := models.GetCategoryBySlug(slug)
	if err != nil {
		return err
	}

	//get posts by category slug, order by Created desc
	cnt, err := models.CountByExample(&models.Post{CategoryId: cat.Id})
	if err != nil {
		return err
	}

	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	posts, err := models.RecentPosts("hot", setting.PostCountPerPage, pager.Offset())
	if err != nil {
		return err
	}

	this.Data["Category"] = cat
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	var topics []models.Topic
	this.setTopicsOfCategory(&topics, cat)
	this.Data["CategorySlug"] = cat.Slug
	this.Data["SortSlug"] = ""
	var newBestPosts []models.Post
	this.setNewBestPostsOfCategory(&newBestPosts, cat)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfCategory(&mostReplysPosts, cat)
	this.setSidebarBuilletinInfo()

	return this.Render("post/home.html", this.Data)
}