⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblog.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;

using CommunityServer.Components;

namespace CommunityServer.Blogs.Components
{
    /// <summary>
    /// Summary description for BlogConfiguration.
    /// </summary>
    public class Weblog : Section
    {
        public Weblog()
        {

        }

        #region Public 

        public string Email
        {
            get{return GetExtendedAttribute("email");}
            set{SetExtendedAttribute("email", value);}
        }

        public string RssLanguage
        {
            get{return GetExtendedAttribute("rssLanguage");}
            set{SetExtendedAttribute("rssLanguage", value);}
        }
		
        public string News
        {
            get{return GetExtendedAttribute("news");}
            set{SetExtendedAttribute("news", value);}
        }

        public bool EnableComments
        {
            get {  return GetBool("EnableComments",true); }
            set{ SetExtendedAttribute("EnableComments",value.ToString()); }
        }

		public bool EnableAggBugs
		{
			get {  return GetBool("EnableAggBugs",true); }
			set{ SetExtendedAttribute("EnableAggBugs",value.ToString()); }
		}

        public bool EnableTrackbacks
        {
            get
            {
                return GetBool("EnableTrackbacks", true);
            }
            set{ SetExtendedAttribute("EnableTrackbacks",value.ToString()); }
        }

		public bool EnableRatings
		{
			get
			{
				return GetBool("EnableRatings", true);
			}
			set{ SetExtendedAttribute("EnableRatings",value.ToString()); }
		}

        public bool EnableContact
        {
            get
            {
                return GetBool("EnableContact", true);
            }
            set{ SetExtendedAttribute("EnableContact",value.ToString()); }
        }

		

        public bool EnablePings
        {
            get
            {
                return GetBool("EnablePings",true);
            }
            set{ SetExtendedAttribute("EnablePings",value.ToString()); }
        }

        public string[] PingUrls
        {
            get
            {
                string[] pings = null;
                if(EnablePings)
                {
                    string p  = GetExtendedAttribute("PingUrls");
                    if(p != null)
                        pings = p.Split(',');
                    else
                        pings = new string[]{"http://rpc.weblogs.com/rpc2","http://ping.blo.gs","http://rpc.technorati.com/rpc/ping"};
                }

                return pings;
            }
            set
            {
                if(value != null)
                    SetExtendedAttribute("PingUrls",string.Join(",",value));
                else
                    SetExtendedAttribute("PingUrls",null);
            }
        }

        public bool ShowContact
        {
            get
            {
                return EnableContact && !Globals.IsNullorEmpty(this.Email);
            }
        }

        public int CommentExpirationDays
        {
            get
            {
                string i = GetExtendedAttribute("ced");
                if(i == null || i.Trim().Length == 0)
                    return 999999;

                return Int32.Parse(i);
            }
            set{ SetExtendedAttribute("ced",value.ToString()); }
        }

		public string Langugage
		{
			get{return GetString("Language","en-US");}
			set{SetExtendedAttribute("Language",value);}
		}

		public CommentModerationType ModerationType
		{
			//We need to support previous .Text configuration options. 
			//If IsModerated = true, we will return CommentModerationType.All since this was the same .Text behavior
			//If a user updates this property, we will set IsModerated to false, which will be an indication that we will 
			//no longer need to honor the .Text concept. 

			get
			{
				if(IsModerated)
					return CommentModerationType.All;

				return (CommentModerationType)Enum.Parse(typeof(CommentModerationType),GetString("CommentModerationType","None"),false);
				
			}
			set
			{
				this.IsModerated = false;
				SetExtendedAttribute("CommentModerationType",value.ToString());
			}
		
		}

        #endregion

        #region Permissions
        /// <summary>
        /// Returns a new instance of BlogPermission
        /// </summary>
        public override PermissionBase DefaultRolePermission
        {
            get
            {
                return new WeblogPermission();
            }
        }

        private AccessCheckDelegate _acd = null;

        /// <summary>
        /// Returns the delegate/method signature used to check the current users access
        /// to the requested blog
        /// </summary>
        public override AccessCheckDelegate AccessCheck
        {
            get
            {
                if(_acd == null)
                    _acd =  new AccessCheckDelegate(WeblogPermission.AccessCheck);

                return _acd;
            }
        }

        private ValidatePermissionsDelegate _vpd = null;
        /// <summary>
        /// Returns the delegate/method signature used to validate the current users
        /// permissions for a blog.
        /// </summary>
        public override ValidatePermissionsDelegate ValidatePermissions
        {
            get
            {
                if(_vpd == null)
                    _vpd = new ValidatePermissionsDelegate(WeblogPermission.Validate);

                return _vpd;
            }
        }

        WeblogPermission ownerPermission = null;
        public override PermissionBase OwnerPermission
        {
            get
            {
                if(ownerPermission == null)
                {
                    ownerPermission = new WeblogPermission();
                    ownerPermission.SetBit(Permission.Post,AccessControlEntry.Allow);
                    ownerPermission.SetBit(Permission.Reply,AccessControlEntry.Allow);
                    ownerPermission.SetBit(Permission.View,AccessControlEntry.Allow);
                }

                return ownerPermission;
            }
        }

        #endregion


        #region Recent Data
        private string _mostRecentPostName;
        /// <summary>
        /// Property MostRecentPostName (string)
        /// </summary>
        public string MostRecentPostName
        {
            get {  return this._mostRecentPostName; }
            set {  this._mostRecentPostName = value; }
        }


        private int _mostRecentArticleID;
        /// <summary>
        /// Property MostRecentArticleID (int)
        /// </summary>
        public int MostRecentArticleID
        {
            get {  return this._mostRecentArticleID; }
            set {  this._mostRecentArticleID = value; }
        }

        private DateTime _mostRecentArticleDate;
        /// <summary>
        /// Property MostRecentArticleDate (DateTime)
        /// </summary>
        public DateTime MostRecentArticleDate
        {
            get {  return this._mostRecentArticleDate; }
            set {  this._mostRecentArticleDate = value; }
        }

        private string _mostRecentArticleName;
        /// <summary>
        /// Property MostRecentArticleName (string)
        /// </summary>
        public string MostRecentArticleName
        {
            get {  return this._mostRecentArticleName; }
            set {  this._mostRecentArticleName = value; }
        }

        private int _mostRecentArticleAuthorID;
        /// <summary>
        /// Property MostRecentArticleAuthorID (int)
        /// </summary>
        public int MostRecentArticleAuthorID
        {
            get {  return this._mostRecentArticleAuthorID; }
            set {  this._mostRecentArticleAuthorID = value; }
        }

        private string _mostRecentArticleAuthorName;
        /// <summary>
        /// Property MostRecentArticleAuthorName (string)
        /// </summary>
        public string MostRecentArticleAuthor
        {
            get {  return this._mostRecentArticleAuthorName; }
            set {  this._mostRecentArticleAuthorName = value; }
        }

        #endregion

        #region Counts
        private int _postCount;
        /// <summary>
        /// Property PostCount (int)
        /// </summary>
        public int PostCount
        {
            get {  return this._postCount; }
            set {  this._postCount = value; }
        }

        private int _articleCount;
        /// <summary>
        /// Property ArticleCount (int)
        /// </summary>
        public int ArticleCount
        {
            get {  return this._articleCount; }
            set {  this._articleCount = value; }
        }

        private int _commentCount;
        /// <summary>
        /// Property CommentCount (int)
        /// </summary>
        public int CommentCount
        {
            get {  return this._commentCount; }
            set {  this._commentCount = value; }
        }

        private int _trackbackCount;
        /// <summary>
        /// Property TrackbackCount (int)
        /// </summary>
        public int TrackbackCount
        {
            get {  return this._trackbackCount; }
            set {  this._trackbackCount = value; }
        }
        #endregion

        #region Links
        public string HomePage
        {
            get {return BlogUrls.Instance().HomePage(this.ApplicationKey);}
        }

        public string ReferralFilter
        {
            get{ return HomePage.ToLower().Replace("/default.aspx",string.Empty);}
        }
        #endregion

        #region Themes

        private string theme = null;
        public string  Theme
        {
            get
            {
                //This property will be called numerous times per request. Let's save the lookup cost 
                //by using a local variable. In addition, this will give us a clean spot to set the default skin
                if(theme == null)
                {
                    theme =  GetString("Theme",null);
                    
                    
                    if(Globals.IsNullorEmpty(theme))
                        theme = WeblogConfiguration.Instance().DefaultTheme;
                }
                return theme;
            }

            //If the theme name == the default value, do we want to save it?
            set
            {

                //If updated value == Default Value, set to null. Otherwise, just update the inernal
                //store and set the local variable
                if(string.Compare(value,WeblogConfiguration.Instance().DefaultTheme) == 0)
                     SetExtendedAttribute("Theme", null);
                else
                     SetExtendedAttribute("Theme", value);

                theme = value;
            }
        }

        public string SecondaryCSS
        {
            get {  return GetString("SecondaryCSS",null); }
            set{ SetExtendedAttribute("SecondaryCSS",value); }            
        }

        public string CSSOverride
        {
            get {  return GetString("CSSOverride",null); }
            set{ SetExtendedAttribute("CSSOverride",value); }            
        }

        #endregion

        public bool EnableNewComments(WeblogPost post, User user)
        {
			if(!Permissions.ValidatePermissions(this,Permission.Reply,user))
				return false;

            if(!EnableComments)
                return false;

            if(post.IsLocked)
                return false;

            if(user.IsAnonymous && (!this.EnableAnonymousPosting || !CSContext.Current.SiteSettings.EnableAnonymousUserPosting))
                return false;

            return post.BloggerTime.AddDays(this.CommentExpirationDays) > DateTime.Now;
        }

		public bool IsPostModerated(WeblogPost post, User user)
		{
			switch(post.ModerationType)
			{
				case CommentModerationType.All:
					return true;
				case CommentModerationType.Anonymous:
					return user.IsAnonymous;
				case CommentModerationType.None:
					return false;
				default:
					return true;
			}
		}


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -