📄 weblogpost.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;using CommunityServer.Components;namespace CommunityServer.Blogs.Components
{
/// <summary>
/// Core Weblog content object. Extends Post
/// </summary>
[Serializable]
public class WeblogPost : Post
{
public WeblogPost()
{
//
// TODO: Add constructor logic here
//
}
public Weblog Weblog
{
get{ return Section as Weblog;}
}
#region Tracking
public override bool IsTracked
{
get
{
return GetIsTracked(CSContext.Current.User.UserID);
}
set
{
//base.IsTracked = value;
}
}
public bool GetIsTracked(int userID)
{
return ThreadTracking.IsTracked(this.ThreadID,userID);
}
#endregion
#region private
private string excerpt;
private string name;
private string titleUrl;
private BlogPostConfig postConfig = BlogPostConfig.Empty;
private BlogPostType blogPostType = BlogPostType.Post;
private string[] categories;
private DateTime _bloggerTime;
private int authorID;
private int aggViews;
private int ratingSum;
private int totalRatings;
#endregion
#region Public
/// <summary>
/// Short description of post
/// </summary>
public string Excerpt
{
get{return excerpt;}
set{excerpt = value;}
}
/// <summary>
/// Name of the post.
/// </summary>
public string Name
{
get{return name;}
set{name = value;}
}
/// <summary>
/// Url to use instead of default title link
/// </summary>
public string TitleUrl
{
get{return titleUrl;}
set{titleUrl = value;}
}
/// <summary>
/// Name of site making the trackback
/// </summary>
public string TrackBackName
{
get{return this.GetExtendedAttribute("trackbackName");}
set{this.SetExtendedAttribute("trackbackName",value);}
}
public string Custom
{
get{return GetString("Custom",null);}
set{this.SetExtendedAttribute("Custom",value);}
}
/// <summary>
/// Name submitted when the post was saved
/// </summary>
public string SubmittedUserName
{
get{return GetString("SubmittedUserName",null);}
set{this.SetExtendedAttribute("SubmittedUserName",value);}
}
/// <summary>
/// When the post was saved, did the user submit a different name
/// </summary>
public bool HasSubmittedUserName
{
get{ return !Globals.IsNullorEmpty(this.SubmittedUserName);}
}
/// <summary>
/// Timezone refactored date. Converts date of post to the local time of the blogger
/// </summary>
public DateTime BloggerTime
{
get { return this._bloggerTime; }
set { this._bloggerTime = value; }
}
/// <summary>
/// Is this post aggregated
/// </summary>
public bool IsAggregated
{
get{return GetPostConfig(BlogPostConfig.IsAggregated);}
set{SetPostConfig(BlogPostConfig.IsAggregated, value);}
}
/// <summary>
/// Is this post aggregated to the community root site
/// </summary>
public bool IsCommunityAggregated
{
get{return GetPostConfig(BlogPostConfig.IsCommunityAggregated);}
set{SetPostConfig(BlogPostConfig.IsCommunityAggregated, value);}
}
/// <summary>
/// Should this post syndicated the excerpt only?
/// </summary>
public bool SyndicateExcerpt
{
get{return GetPostConfig(BlogPostConfig.SyndicateExcerpt);}
set{SetPostConfig(BlogPostConfig.SyndicateExcerpt, value);}
}
/// <summary>
/// Displayon the individual blogs home page
/// </summary>
public bool DisplayOnHomePage
{
get{return GetPostConfig(BlogPostConfig.DisplayOnHomePage);}
set{SetPostConfig(BlogPostConfig.DisplayOnHomePage, value);}
}
/// <summary>
/// Should comments to this post be moderated
/// </summary>
[Obsolete("This method has been replaced by ModerationType")]
public bool IsModerated
{
get{return GetPostConfig(BlogPostConfig.ModerateFeedback);}
set{SetPostConfig(BlogPostConfig.ModerateFeedback, value);}
}
public CommentModerationType ModerationType
{
get
{
if(IsModerated)
return CommentModerationType.All;
return (CommentModerationType)Enum.Parse(typeof(CommentModerationType),GetString("CommentModerationType","None"),false);
}
set
{
this.IsModerated = false;
SetExtendedAttribute("CommentModerationType",value.ToString());
}
}
internal bool EverTracked
{
get{return GetBool("EverPublished",false);}
set{ SetExtendedAttribute("EverPublished",value.ToString());}
}
/// <summary>
/// returns true if the Post is approved and th PostDate is less than the current datetime
/// </summary>
public bool IsPostEnabled
{
get
{
return IsApproved && (this.PostDate <= DateTime.Now);
}
}
//Need a better pattern here!
/// <summary>
/// This value is not persisted! The first time a Weblog Post is saved and EverTracked is set to true, this value
/// will be true. CSModule subscribers can use this property to determine if one time notifications should be made.
///
/// </summary>
internal bool EnableExternalNotificatons;
public bool EnableRatings
{
get{return GetBool("EnableRatings",true);}
set{ SetExtendedAttribute("EnableRatings",value.ToString());}
}
public bool EnableTrackBacks
{
get{return GetBool("EnableTrackBacks",true);}
set{ SetExtendedAttribute("EnableTrackBacks",value.ToString());}
}
public bool EnableXmlRpcPings
{
get{return GetBool("EnableXmlRpcPings",true);}
set{ SetExtendedAttribute("EnableXmlRpcPings",value.ToString());}
}
/// <summary>
/// Summary of the blog feedback. Not used as an API
/// </summary>
public BlogPostConfig PostConfig
{
get{return postConfig;}
set{postConfig = value;}
}
/// <summary>
/// list of categories this post was made to
/// </summary>
public string[] Categories
{
get{return categories;}
set{categories = value;}
}
/// <summary>
/// Specific type of blog post (Post, Article, Comment, Trackback)
/// </summary>
public BlogPostType BlogPostType
{
get{return blogPostType;}
set{blogPostType = value;}
}
/// <summary>
/// The UserID of the person who wrote the post
/// </summary>
public int AuthorID
{
get { return authorID; }
set { authorID = value; }
}
/// <summary>
/// The number of aggregate views
/// </summary>
public int AggViews
{
get { return aggViews; }
set { aggViews = value; }
}
public int RatingSum
{
get
{
return ratingSum;
}
set
{
ratingSum = value;
}
}
public int TotalRatings
{
get
{
return totalRatings;
}
set
{
totalRatings = value;
}
}
public double Rating
{
get
{
if (TotalRatings == 0)
return 0;
return ( (double) RatingSum / (double) TotalRatings );
}
}
#endregion
#region Public Helpers
/// <summary>
/// Does this post have a title url
/// </summary>
public bool HasTitleUrl
{
get{return (TitleUrl != null && TitleUrl.Length > 0);}
}
/// <summary>
/// Does this post of have name
/// </summary>
public bool HasName
{
get{return (Name != null && Name.Length > 0);}
}
/// <summary>
/// Does this post have an excerpt
/// </summary>
public bool HasExcerpt
{
get{return (Excerpt != null && Excerpt.Length > 0);}
}
/// <summary>
/// Does this post have categories
/// </summary>
public bool HasCategories
{
get{return (Categories != null && Categories.Length > 0);}
}
#endregion
#region Private Helpers
/// <summary>
/// Helper to set the PostConfig value
/// </summary>
/// <param name="bpc"></param>
/// <param name="isSelected"></param>
protected void SetPostConfig(BlogPostConfig bpc, bool isSelected)
{
if(isSelected)
{
PostConfig = PostConfig | bpc;
}
else
{
PostConfig = PostConfig & ~bpc;
}
}
/// <summary>
/// Helper to get the current post config value
/// </summary>
/// <param name="bpc"></param>
/// <returns></returns>
protected bool GetPostConfig(BlogPostConfig bpc)
{
return IsPostConfigSelected(PostConfig,bpc);// (PostConfig & bpc) == bpc;
}
/// <summary>
/// Helper to check if a specific property is set via the PostConfig
/// </summary>
public static bool IsPostConfigSelected(BlogPostConfig current, BlogPostConfig item)
{
return (current & item) == item;
}
#endregion
#region Section
private Section section = null;
/// <summary>
/// Override Section. Returns the partent "Weblog/Section" for this post
/// </summary>
public override Section Section
{
get
{
if(section == null)
{
section = Weblogs.GetWeblog(this.SectionID,true);
}
return section;
}
set
{
section = value;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -