/* This is an adaptation of the original AggregateCompactPostList and * AggregateCompactArticleList created by Brendan Tompkins at * http://www.codebetter.com. See this post for the originals * http://codebetter.com/blogs/brendan.tompkins/archive/2005/06/15/64634.aspx * * The original controls required a rebuild of the CommunityServer source * files, and furthermore were not compatible with version 2.0 * To make life easier for those who don't want to mess around with the * source files (myself for example) I rewrote them as User Controls. * * I added an extra property to let users choose the Category of the posts or * articles that they would like to display. * * You are free to alter the source as long as this header stays in place. * Jacob Reimers * http://www.reimers.dk */ using System; using System.Web.UI.WebControls; using CommunityServer.Blogs.Components; using CommunityServer.Components; using CommunityServer.Controls; public partial class AggregateCompactList : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { DataBind(); } private object _dataSource; private bool showComments = true; private bool showBlog = true; private bool showExcerpt = true; private bool showDate = true; string sectionTitle = String.Empty; private string titleLink = String.Empty; private string titleRssLink = String.Empty; int maxPosts = 5; int groupId = -1; int catID = -1; BlogThreadSortBy sortBy = BlogThreadSortBy.MostRecent; BlogPostType postType = BlogPostType.Post; /// /// Property DataSource (object) /// public object DataSource { get { return this._dataSource; } set { this._dataSource = value; } } public bool ShowComments { get { return showComments; } set { showComments = value; } } public bool ShowExcerpt { get { return showExcerpt; } set { showExcerpt = value; } } public bool ShowBlog { get { return showBlog; } set { showBlog = value; } } public bool ShowDate { get { return showDate; } set { showDate = value; } } public BlogPostType PostType { get { return postType; } set { postType = value; } } public string Title { get { return sectionTitle; } set { sectionTitle = value; } } public string TitleLink { get { return titleLink; } set { titleLink = value; } } public string TitleRssLink { get { return titleRssLink; } set { titleRssLink = value; } } public int MaxPosts { get { return maxPosts; } set { maxPosts = value; } } public int GroupId { get { return groupId; } set { groupId = value; } } public int CategoryID { get { return catID; } set { catID = value; } } public BlogThreadSortBy SortBy { get { return sortBy; } set { sortBy = value; } } protected void posts_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { WeblogPost post = e.Item.DataItem as WeblogPost; if (post != null) { HyperLink titleLink = e.Item.FindControl("TitleLink") as HyperLink; titleLink.Text = post.Subject; titleLink.NavigateUrl = BlogUrls.Instance().Post(post); if (showBlog) { HyperLink Blog = e.Item.FindControl("Blog") as HyperLink; Blog.NavigateUrl = BlogUrls.Instance().HomePage(post.Section.ApplicationKey); Blog.Text = post.Section.Name; } if (showDate) { Literal Posted = e.Item.FindControl("Posted") as Literal; Posted.Text = post.PostDate.ToShortDateString() + " " + post.PostDate.ToShortTimeString(); } if (showExcerpt && post.Excerpt != null) { Literal Excerpt = e.Item.FindControl("Excerpt") as Literal; Excerpt.Text = post.Excerpt; ; } HyperLink link = e.Item.FindControl("CommentsLink") as HyperLink; if (link != null) { if (showComments && (post.Weblog.EnableCommentsDefault || post.Weblog.EnableCommentsOverride) && !post.IsLocked) { link.Text = string.Format(ResourceManager.GetString("Weblog_EntryList_Comments"), post.Replies); link.NavigateUrl = BlogUrls.Instance().Post(post, post.Weblog) + "#comments"; e.Item.FindControl("CommentDesc").Visible = true; } else { e.Item.FindControl("CommentDesc").Visible = false; link.Visible = false; } } HyperLink linkImage = e.Item.FindControl("linkImage") as HyperLink; if (linkImage != null) { linkImage.NavigateUrl = titleLink.NavigateUrl; linkImage.ToolTip = post.Subject; } } } } public override void DataBind() { base.DataBind(); BlogThreadQuery query = new BlogThreadQuery(); if (sectionTitle.Length > 0) { title.Text = sectionTitle; } else if (GroupId > -1) { title.Text = string.Format(ResourceManager.GetString("LatestPostsTo"), WeblogGroups.GetWeblogGroup(GroupId, true, false).Name); } else { title.Text = ResourceManager.GetString("LatestPosts"); } if (titleRssLink.Length > 0) { rssLink.NavigateUrl = titleRssLink; } else { rssLink.Visible = false; } if (titleLink.Length > 0) { title.NavigateUrl = titleLink; } //query.GroupID = GroupId; query.SectionID = GroupId; query.CategoryID = catID; query.BlogPostType = this.postType; query.BlogThreadType = BlogThreadType.Recent; query.IncludeCategories = false; query.PageSize = 25; query.SortBy = sortBy; query.SortOrder = SortOrder.Descending; query.PostConfig = BlogPostConfig.IsCommunityAggregated; query.FilterBySectionList = Sections.FilterByAccessControl(Weblogs.GetWeblogs(false, true, false), Permission.View); query.DateFilter = DateTime.Today; ThreadSet ts = WeblogPosts.GetBlogThreads(query, true, true); if (ts.Threads != null && ts.Threads.Count > this.maxPosts) { ts.Threads = ts.Threads.GetRange(0, this.maxPosts); } Posts.DataSource = ts.Threads; Posts.DataBind(); } }