using System;
using System.Web.UI.WebControls;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Blogs;
using CommunityServer.Blogs.Components;
using CommunityServer.CMS;
namespace CommunityServer.CMS {
/// <summary>
/// Represents an in memory aggregate list of blog posts for a specific weblog.
/// </summary>
public class BlogPosts : TemplatedWebControl {
#region " Constructor "
/// <summary>
/// BlogPosts constructor.
/// </summary>
public BlogPosts() : base() {
//
// TODO: Add constructor logic here
//
}
#endregion
#region " Properties "
private AggregateListBlogPosts blogPostsList = null;
private Weblog thisWeblog = null;
#region " Control Properties "
private bool _showBody = false;
/// <summary>
/// Gets or sets a value indicating whether to show the body of a post.
/// </summary>
public bool ShowBody {
set {
this._showBody = value;
}
get {
return this._showBody;
}
}
private bool _showIcons = false;
/// <summary>
/// Gets or sets a value indicating if icon of the blog post/article is visible.
/// </summary>
public bool ShowIcons {
set {
this._showIcons = value;
}
get {
return this._showIcons;
}
}
private bool _collapsed;
/// <summary>
/// Gets or sets a value indicating if the panel is collapsed.
/// </summary>
public bool Collapsed{
get {
return _collapsed;
}
set {
_collapsed = value;
}
}
#endregion
#region " Query Properties "
private string _blogID;
/// <summary>
/// Gets or sets an value that represents the blog key.
/// </summary>
public string BlogID {
set {
_blogID = value;
}
get {
return _blogID;
}
}
private int _timeFrame = 60;
/// <summary>
/// Gets or sets a value that represents the timeframe in days the query for the recent post will use.
/// </summary>
public int TimeFrame {
set {
this._timeFrame = value;
}
get {
return this._timeFrame;
}
}
private SortOrder _SortingOrder = SortOrder.Descending;
/// <summary>
/// Gets or sets an enum that represents the sorting of post threads.
/// </summary>
public SortOrder SortingOrder {
set {
this._SortingOrder = (SortOrder) value;
}
get {
return this._SortingOrder;
}
}
#endregion
#region " Pager Properties "
private bool _enablePager = false;
/// <summary>
/// Gets or sets a value indicating if the pager would be visible.
/// </summary>
public bool EnablePager {
get {
return _enablePager;
}
set {
_enablePager = value;
}
}
private int _pageSize = 10;
/// <summary>
/// Gets or sets a value that represents the pagesize of the post listed.
/// </summary>
public int PageSize {
get {
return _pageSize;
}
set {
_pageSize = value;
}
}
#endregion
#endregion
#region " Overrides "
/// <summary>
/// Overridden. See TemplatedWebControl.ExternalSkinFileName
/// </summary>
protected override string ExternalSkinFileName {
get {
return CreateExternalSkinFileName("CMS");
}
}
/// <summary>
/// Overridden. See TemplatedWebControl.AttachChildControls
/// </summary>
protected override void AttachChildControls() {
blogPostsList = FindControl("PostsList") as AggregateListBlogPosts;
blogPostsList.ShowBody = this.ShowBody;
blogPostsList.ShowIcons = this.ShowIcons;
blogPostsList.Collapsed = this.Collapsed;
thisWeblog = Weblogs.GetWeblog(this.BlogID);
if (thisWeblog != null){
blogPostsList.Title = thisWeblog.Name;
}
blogPostsList.View = CMS.AggregateListBlogPosts.ViewType.IsRecent;
blogPostsList.EnablePager = this.EnablePager;
blogPostsList.PageSize = this.PageSize;
blogPostsList.RSSLink = BlogUrls.Instance().Rss(thisWeblog.ApplicationKey);
blogPostsList.PagerIndexChanged +=new EventHandler(blogPosts_PagerIndexChanged);
this.DataBind();
}
/// <summary>
/// Overridden. See TemplatedWebControl.DataBind
/// </summary>
public override void DataBind() {
base.DataBind ();
blogPostsList.PageSize = this.PageSize;
BlogThreadQuery query = new BlogThreadQuery();
query.BlogID = thisWeblog.SectionID;
query.DateFilter=DateTime.Now.AddDays(this.TimeFrame * -1);
query.BlogPostType = BlogPostType.Post;
query.BlogThreadType = BlogThreadType.Recent;
query.IncludeCategories = false;
query.IsPublished = true;
query.PageIndex = blogPostsList.PageIndex;
query.PageSize = blogPostsList.PageSize;
query.IgnorePaging = false;
query.SortBy = BlogThreadSortBy.MostRecent;
query.SortOrder = this.SortingOrder;
query.PostConfig = BlogPostConfig.IsCommunityAggregated | BlogPostConfig.IsAggregated;
query.FilterByList = Sections.FilterByAccessControl(Weblogs.GetWeblogs(false, true, false), Permission.View);
ThreadSet ts = WeblogPosts.GetBlogThreads(query, true, true);
if (ts.TotalRecords == 0) {
this.Visible = false;
}
blogPostsList.DataSource = ts.Threads;
blogPostsList.DataBind();
blogPostsList.TotalRecords = ts.TotalRecords;
}
/// <summary>
/// RenderBeginTag implementation
/// </summary>
/// <param name="writer"></param>
public override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer) {
// No beginning tag
}
/// <summary>
/// RenderEndTag implementation
/// </summary>
/// <param name="writer"></param>
public override void RenderEndTag(System.Web.UI.HtmlTextWriter writer) {
// No ending tag
}
#endregion
#region " Private "
/// <summary>
/// Event Handler for blogPostsList.PagerIndexChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void blogPosts_PagerIndexChanged(object sender, EventArgs e) {
this.DataBind();
}
#endregion
}
}