示例#1
0
文件: notice.go 项目: netxfly/wetalk
func (this *NoticeRouter) Get() {
	this.Data["IsNotificationPage"] = true
	this.TplNames = "post/notice.html"

	if this.CheckLoginRedirect() {
		return
	}

	var notifications []models.Notification
	qs := models.Notifications(this.User.Id)

	pers := 10
	count, _ := models.CountObjects(qs)
	pager := this.SetPaginator(pers, count)

	qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

	models.ListObjects(qs, &notifications)
	this.Data["Notifications"] = notifications

	var cats []models.Category
	var topics []models.Topic
	post.ListCategories(&cats)
	this.Data["Categories"] = cats
	post.ListTopics(&topics)
	this.Data["Topics"] = topics
}
示例#2
0
文件: post.go 项目: wildex/wetalk
// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Category() {
	this.TplName = "post/category.html"

	slug := this.GetString(":slug")
	cat := models.Category{Slug: slug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}

	pers := 25

	qs := models.Posts().Filter("Category", &cat)
	qs = this.postsFilter(qs)

	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(pers, cnt)

	qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Posts"] = posts
	this.Data["Category"] = &cat
	this.Data["CategorySlug"] = cat.Slug
	this.Data["IsCategory"] = true

	var cats []models.Category
	this.setCategories(&cats)

	var topics []models.Topic
	this.setTopicsOfCat(&topics, &cat)
}
示例#3
0
文件: post.go 项目: netxfly/wetalk
//Get sidebar bulletin information
func (this *PostListRouter) setSidebarBuilletinInfo() {
	var bulletins []models.Bulletin
	qs := models.Bulletins().OrderBy("Created")
	models.ListObjects(qs, &bulletins)

	var friendLinks []models.Bulletin
	var newComers []models.Bulletin
	var mobileApps []models.Bulletin
	var openSources []models.Bulletin

	for _, bulletin := range bulletins {
		switch bulletin.Type {
		case setting.BULLETIN_FRIEND_LINK:
			friendLinks = append(friendLinks, bulletin)
		case setting.BULLETIN_NEW_COMER:
			newComers = append(newComers, bulletin)
		case setting.BULLETIN_MOBILE_APP:
			mobileApps = append(mobileApps, bulletin)
		case setting.BULLETIN_OPEN_SOURCE:
			openSources = append(openSources, bulletin)
		}
	}
	this.Data["FriendLinks"] = friendLinks
	this.Data["NewComers"] = newComers
	this.Data["MobileApps"] = mobileApps
	this.Data["OpenSources"] = openSources
}
示例#4
0
文件: post.go 项目: netxfly/wetalk
//Get the posts by category
func (this *PostListRouter) Category() {
	this.TplNames = "post/home.html"

	//check category slug
	slug := this.GetString(":slug")
	cat := models.Category{Slug: slug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	//get posts by category slug, order by Created desc
	qs := models.Posts().Filter("Category", &cat)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	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()
}
示例#5
0
文件: post.go 项目: netxfly/wetalk
//Get the home page
func (this *PostListRouter) Home() {
	this.TplNames = "post/home.html"

	//get posts by Created datetime desc order
	var posts []models.Post
	qs := models.Posts()
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()

	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	this.Data["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()
}
示例#6
0
文件: user.go 项目: netxfly/wetalk
func (this *UserRouter) Home() {
	this.Data["IsUserHomePage"] = true
	this.TplNames = "user/home.html"

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

	//recent posts and comments
	limit := 5

	var posts []*models.Post
	var comments []*models.Comment

	user.RecentPosts().Limit(limit).RelatedSel().All(&posts)
	user.RecentComments().Limit(limit).RelatedSel().All(&comments)

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

	//follow topics
	var ftopics []*models.FollowTopic
	var topics []*models.Topic
	ftNums, _ := models.FollowTopics().Filter("User", &user.Id).Limit(8).OrderBy("-Created").RelatedSel("Topic").All(&ftopics, "Topic")
	if ftNums > 0 {
		topics = make([]*models.Topic, 0, ftNums)
		for _, ft := range ftopics {
			topics = append(topics, ft.Topic)
		}
	}
	this.Data["TheUserFollowTopics"] = topics
	this.Data["TheUserFollowTopicsMore"] = ftNums >= 8

	//favorite posts
	var favPostIds orm.ParamsList
	var favPosts []models.Post
	favNums, _ := user.FavoritePosts().Limit(8).OrderBy("-Created").ValuesFlat(&favPostIds, "Post")
	if favNums > 0 {
		qs := models.Posts().Filter("Id__in", favPostIds)
		qs = qs.OrderBy("-Created").RelatedSel()
		models.ListObjects(qs, &favPosts)
	}
	this.Data["TheUserFavoritePosts"] = favPosts
	this.Data["TheUserFavoritePostsMore"] = favNums >= 8

}
示例#7
0
文件: post.go 项目: netxfly/wetalk
func (this *PostListRouter) CatNavs() {
	this.TplNames = "post/home.html"
	//check category slug and sort slug
	catSlug := this.GetString(":catSlug")
	sortSlug := this.GetString(":sortSlug")
	cat := models.Category{Slug: catSlug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	qs := models.Posts().Filter("Category", &cat)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	switch sortSlug {
	case "recent":
		qs = qs.OrderBy("-Created")
	case "hot":
		qs = qs.OrderBy("-LastReplied")
	case "cold":
		qs = qs.Filter("Replys", 0).OrderBy("-Created")
	default:
		this.Abort("404")
		return
	}
	qs = qs.Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	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"] = sortSlug
	var newBestPosts []models.Post
	this.setNewBestPostsOfCategory(&newBestPosts, &cat)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfCategory(&mostReplysPosts, &cat)
	this.setSidebarBuilletinInfo()
}
示例#8
0
文件: post.go 项目: netxfly/wetalk
//Topic Home Page
func (this *PostListRouter) Topic() {
	this.TplNames = "post/topic.html"
	//check topic slug
	slug := this.GetString(":slug")
	topic := models.Topic{Slug: slug}
	if err := topic.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	//get topic category
	category := models.Category{Id: topic.Category.Id}
	if err := category.Read("Id"); err != nil {
		this.Abort("404")
		return
	}

	//get posts by topic
	qs := models.Posts().Filter("Topic", &topic)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Posts"] = posts
	this.Data["Topic"] = &topic
	this.Data["Category"] = &category

	//check whether added it into favorite list
	HasFavorite := false
	if this.IsLogin {
		HasFavorite = models.FollowTopics().Filter("User", &this.User).Filter("Topic", &topic).Exist()
	}
	this.Data["HasFavorite"] = HasFavorite

	//new best post
	var newBestPosts []models.Post
	this.setNewBestPostsOfTopic(&newBestPosts, &topic)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfTopic(&mostReplysPosts, &topic)
	this.setSidebarBuilletinInfo()
}
示例#9
0
文件: post.go 项目: wildex/wetalk
// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Home() {
	this.Data["IsHome"] = true
	this.TplName = "post/home.html"

	var cats []models.Category
	this.setCategories(&cats)

	var posts []models.Post
	qs := models.Posts().OrderBy("-Created").Limit(25).RelatedSel()
	qs = this.postsFilter(qs)

	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	this.Data["CategorySlug"] = "hot"

	var topics []models.Topic
	post.ListTopics(&topics)
	this.Data["Topics"] = topics
}
示例#10
0
文件: user.go 项目: netxfly/wetalk
func (this *UserRouter) FavoritePosts() {
	this.TplNames = "user/favorite-posts.html"

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

	var postIds orm.ParamsList
	var posts []models.Post
	nums, _ := user.FavoritePosts().OrderBy("-Created").ValuesFlat(&postIds, "Post")
	if nums > 0 {
		qs := models.Posts().Filter("Id__in", postIds)
		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(setting.PostCountPerPage, cnt)
		qs = qs.OrderBy("-Created").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
		models.ListObjects(qs, &posts)
	}

	this.Data["TheUserFavoritePosts"] = posts
}
示例#11
0
文件: post.go 项目: wildex/wetalk
// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Topic() {
	slug := this.GetString(":slug")

	switch slug {
	default: // View topic.
		this.TplName = "post/topic.html"
		topic := models.Topic{Slug: slug}
		if err := topic.Read("Slug"); err != nil {
			this.Abort("404")
			return
		}

		pers := 25

		qs := models.Posts().Filter("Topic", &topic)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		var posts []models.Post
		models.ListObjects(qs, &posts)

		this.Data["Posts"] = posts
		this.Data["Topic"] = &topic
		this.Data["IsTopic"] = true

		HasFavorite := false
		if this.IsLogin {
			HasFavorite = models.FollowTopics().Filter("User", &this.User).Filter("Topic", &topic).Exist()
		}
		this.Data["HasFavorite"] = HasFavorite
	}
}
示例#12
0
文件: post.go 项目: netxfly/wetalk
func (this *PostListRouter) Navs() {
	this.TplNames = "post/home.html"

	sortSlug := this.GetString(":sortSlug")
	var posts []models.Post
	qs := models.Posts()
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	switch sortSlug {
	case "recent":
		qs = qs.OrderBy("-Created")
	case "hot":
		qs = qs.OrderBy("-LastReplied")
	case "cold":
		qs = qs.Filter("Replys", 0).OrderBy("-Created")
	default:
		this.Abort("404")
		return
	}
	qs = qs.Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	models.ListObjects(qs, &posts)
	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()
}
示例#13
0
文件: post.go 项目: netxfly/wetalk
//Get most replys post of topic
func (this *PostListRouter) setMostReplysPostsOfTopic(posts *[]models.Post, topic *models.Topic) {
	qs := models.Posts()
	qs = qs.Filter("Topic__id", topic.Id).Filter("Replys__gt", 0).OrderBy("-Created", "-Replys").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["MostReplysPosts"] = posts
}
示例#14
0
文件: post.go 项目: wildex/wetalk
// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Navs() {
	slug := this.GetString(":slug")

	switch slug {
	case "favs", "follow":
		if this.CheckLoginRedirect() {
			return
		}
	}

	this.Data["CategorySlug"] = slug
	this.TplName = fmt.Sprintf("post/navs/%s.html", slug)

	pers := 25

	var posts []models.Post

	switch slug {
	case "recent":
		qs := models.Posts()
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Updated").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "best":
		qs := models.Posts().Filter("IsBest", true)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "cold":
		qs := models.Posts().Filter("Replys", 0)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "favs":
		var topicIds orm.ParamsList
		nums, _ := models.FollowTopics().Filter("User", &this.User.Id).OrderBy("-Created").ValuesFlat(&topicIds, "Topic")
		if nums > 0 {
			qs := models.Posts().Filter("Topic__in", topicIds)
			qs = this.postsFilter(qs)

			cnt, _ := models.CountObjects(qs)
			pager := this.SetPaginator(pers, cnt)

			qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

			models.ListObjects(qs, &posts)

			var topics []models.Topic
			nums, _ = models.Topics().Filter("Id__in", topicIds).Limit(8).All(&topics)
			this.Data["Topics"] = topics
			this.Data["TopicsMore"] = nums >= 8
		}

	case "follow":
		var userIds orm.ParamsList
		nums, _ := this.User.FollowingUsers().OrderBy("-Created").ValuesFlat(&userIds, "FollowUser")
		if nums > 0 {
			qs := models.Posts().Filter("User__in", userIds)
			qs = this.postsFilter(qs)

			cnt, _ := models.CountObjects(qs)
			pager := this.SetPaginator(pers, cnt)

			qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

			models.ListObjects(qs, &posts)
		}
	}

	this.Data["Posts"] = posts
}
示例#15
0
文件: post.go 项目: netxfly/wetalk
//Get new best posts
func (this *PostListRouter) setNewBestPosts(posts *[]models.Post) {
	qs := models.Posts()
	qs = qs.Filter("IsBest", true).OrderBy("-Created").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["NewBestPosts"] = posts
}
示例#16
0
文件: post.go 项目: netxfly/wetalk
//Get most replys posts of category
func (this *PostListRouter) setMostReplysPostsOfCategory(posts *[]models.Post, cat *models.Category) {
	qs := models.Posts()
	qs = qs.Filter("Category__id", cat.Id).Filter("Replys__gt", 0).OrderBy("-Created", "-Replys").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["MostReplysPosts"] = posts
}
示例#17
0
文件: post.go 项目: netxfly/wetalk
//Get new best posts by topic
func (this *PostListRouter) setNewBestPostsOfTopic(posts *[]models.Post, topic *models.Topic) {
	qs := models.Posts()
	qs = qs.Filter("IsBest", true).Filter("Topic__id", topic.Id).OrderBy("-Created").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["NewBestPosts"] = posts
}
示例#18
0
文件: post.go 项目: netxfly/wetalk
//Get new best posts by category
func (this *PostListRouter) setNewBestPostsOfCategory(posts *[]models.Post, cat *models.Category) {
	qs := models.Posts()
	qs = qs.Filter("IsBest", true).Filter("Category__id", cat.Id).OrderBy("-Created").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["NewBestPosts"] = posts
}