using System; using System.Collections; using System.Text; using System.Collections.Generic; using Zhaizj.Framework.Web.Handler; using Zhaizj.Framework.Web.Mvc; namespace Zhaizj.Framework.Config { /// /// 注册类型 /// public class RegisterType { /// /// 开放注册 /// public static readonly int Open = 0; /// /// 关闭注册 /// public static readonly int Close = 1; /// /// 关闭注册,但受邀请的除外 /// public static readonly int CloseUnlessInvite = 2; } public class LoginType { /// /// 注册之后自动登录 /// public static readonly int Open = 0; /// /// 注册之后并不自动登录;必须激活才能登录 /// public static readonly int ActivationEmail = 1; } /// /// (网站页面顶部的)用户导航栏的显示状态 /// public class TopNavDisplay { /// /// 显示 /// public static readonly int Show = 0; /// /// 隐藏 /// public static readonly int Hide = 1; /// /// 在关闭注册之后隐藏 /// public static readonly int NoRegHide = 2; } /// /// 显示名称:Name 用户名,RealName 真实姓名,默认为RealName /// public class UserDisplayNameType { public static readonly int RealName = 1; public static readonly int Name = 2; } /// /// 网站配置 /// public class SiteSetting { //-------------------------------base--------------------------------- /// /// 网站名称 /// public String SiteName { get; set; } /// /// 网站的网址 /// public String SiteUrl { get; set; } /// /// logo的图片网址 /// public String SiteLogo { get; set; } /// /// 站长名字 /// public String Webmaster { get; set; } /// /// 网站的email /// public String Email { get; set; } /// /// 网页默认关键词 /// public String Keywords { get; set; } /// /// 网页默认的描述 /// public String Description { get; set; } /// /// 网页默认的标题 /// public String PageDefaultTitle { get; set; } /// /// 网站是否需要登录才能访问,默认不需要登录 /// public Boolean NeedLogin { get; set; } /// /// 用户注册之后必须经过人工审核 /// public Boolean UserNeedApprove { get; set; } /// /// 对尚未激活的用户,是否提醒他激活 /// public Boolean AlertActivation { get; set; } /// /// 用户自己重发激活邮件的间隔 /// public int UserSendConfirmEmailInterval { get; set; } /// /// 对尚未上传头像的用户,是否提醒他上传头像 /// public Boolean AlertUserPic { get; set; } /// /// 注册的三种类型 (1)开放注册 (2)关闭注册 (3)只有受邀请用户才可以注册 /// public int RegisterType { get; set; } /// /// 登录限制(1)注册之后自动登录 (2)必须激活才能登录) /// public int LoginType { get; set; } /// /// 顶部用户栏状态(1)显示 (2)隐藏 (3)在关闭注册之后隐藏 /// public int TopNavDisplay { get; set; } private String _initApp; /// /// 用户注册之后默认安装的app。 /// public String UserInitApp { get { //if (strUtil.IsNullOrEmpty( _initApp )) return "home, blog, photo"; if (strUtil.IsNullOrEmpty( _initApp )) return ""; return _initApp; } set { _initApp = value; } } private int _ValidationType; /// /// 验证码类型 /// public int ValidationType { get { if (_ValidationType == 0) return ValidationDefault.Type; return _ValidationType; } set { _ValidationType = value; } } private int _ValidationLength; /// /// 英文或数字的验证没长度 /// public int ValidationLength { get { if (_ValidationLength == 0) return ValidationDefault.Length; return _ValidationLength; } set { _ValidationLength = value; } } private int _ValidationChineseLength; /// /// 中文验证码长度 /// public int ValidationChineseLength { get { if (_ValidationChineseLength == 0) return ValidationDefault.ChineseLength; return _ValidationChineseLength; } set { _ValidationChineseLength = value; } } public Boolean IsInstall { get; set; } /// /// 网站是否关闭 /// public Boolean IsClose { get; set; } /// /// 如果关闭,关闭的原因 /// public String CloseReason { get; set; } /// /// 是否开启统计,需要结合StatsJs /// public Boolean StatsEnabled { get; set; } /// /// 统计js /// public String StatsJs { get; set; } /// /// 版权信息 /// public String Copyright { get; set; } /// /// logo宽度 /// public int LogoWidth { get { return 250; } } /// /// logo高度 /// public int LogoHeight { get { return 80; } } /// /// 网站当前皮肤的ID /// public int SkinId { get; set; } /// /// 用户密码是否采用16位的md5加密方式(默认为否,用于兼容旧的系统) /// public Boolean Md5Is16 { get; set; } /// /// 评论内容的长度 /// public int CommentLength { get { return 500; } } private int _TagLength; /// /// tag的长度 /// public int TagLength { get { if (_TagLength == 0) return 20; return _TagLength; } set { _TagLength = value; } } /// /// 网站logo图片的完整网址 /// public String SiteLogoFull { get { return strUtil.Join( sys.Path.Photo, this.SiteLogo ); } } /// /// 获取统计的js内容 /// /// public String GetStatsJs() { if (this.StatsEnabled == false) return ""; return this.StatsJs; } /// /// 如果设置了logo图片,返回img;否则返回siteName /// /// public String GetLogoHtml() { String logo; if (strUtil.HasText( this.SiteLogo )) { logo = ""; } else { logo = "
" + this.SiteName + "
"; } return logo; } /// /// 获取邮件发送服务器的域名,比如根据 abc@gmail.com,得到 gmail.com /// /// public String GetSmtpUserDomain() { return GetSmtpUserDomain( this.SmtpUser ); } public String GetSmtpUserDomain( string smtpUser ) { if (strUtil.IsNullOrEmpty( smtpUser )) return string.Concat( 'w', 'o', 'j', 'i', 'l', 'u', '.', 'c', 'o', 'm' ); if (smtpUser.IndexOf( '@' ) <= 0) return string.Concat( 'w', 'o', 'j', 'i', 'l', 'u', '.', 'c', 'o', 'm' ); String[] arr = smtpUser.Split( '@' ); return arr[1].Trim(); } //----------------------------- user ----------------------------------- public Boolean ShowSexyInfoInProfile { get; set; } /// /// 注册用户名允许的长度 /// public int UserNameLengthMax { get; set; } /// /// 注册用户名至少要达到的长度 /// public int UserNameLengthMin { get; set; } /// /// 登录是否启用验证码 /// public Boolean LoginNeedImgValidation { get; set; } /// /// 注册是否启用验证码 /// public Boolean RegisterNeedImgValidateion { get; set; } /// /// 给新注册用户发送的欢迎信息的标题 /// public String SystemMsgTitle { get; set; } /// /// 给新注册用户发送的欢迎信息的内容(支持html) /// public String SystemMsgContent { get; set; } /// /// 保留用户名(不可以注册的用户名) /// public String[] ReservedUserName { get; set; } /// /// 保留的用户个性网址 /// public String[] ReservedUserUrl { get; set; } /// /// 保留的关键词(不可以在用户名和个性网址中使用) /// public String[] ReservedKey { get; set; } public Boolean IsReservedKeyContains( String inputName ) { string[] arr = this.ReservedKey; foreach (String key in arr) { if (strUtil.EqualsIgnoreCase( inputName, key ) || strUtil.EqualsIgnoreCase( inputName, key + "s" )) { return true; } } return false; } /// /// 使用MS的Membership数据库验证登录,需要配合AuthenticationModule的自动注册功能一起使用,默认为否 /// public Boolean ValidateUserByMembership { get; set; } /// /// 显示名称:Name 用户名,RealName 真实姓名,默认为RealName /// public int UserDisplayName { get; set; } /// /// 是否禁止修改真实性名与空间名称,默认不禁止 /// public Boolean DenyEditUserRealName { get; set; } /// /// 是否禁止修改空间名称,默认不禁止 /// public Boolean DenyEditUserTitle { get; set; } //------------------------------filter---------------------------------- /// /// 禁用的关键词 /// public String[] BadWords { get; set; } /// /// 禁用词汇的替换词 /// public String BadWordsReplacement { get; set; } /// /// 所有被禁的ip地址 /// public String[] BannedIp { get; set; } private String _bannedIpInfo; /// /// 给被屏蔽访客的警告信息 /// public String BannedIpInfo { get { if (_bannedIpInfo == null) return "对不起,你的 ip 地址已被屏蔽"; return _bannedIpInfo; } set { _bannedIpInfo = value; } } //public Boolean IsWatermark { get; set; } private int _microblogContentMax; /// /// 微博内容字数最高限制 /// public int MicroblogContentMax { get { if (_microblogContentMax <= 0) return 140; return _microblogContentMax; } set { _microblogContentMax = value; } } private int _microblogPageSize; /// /// 微博内容字数最高限制 /// public int MicroblogPageSize { get { if (_microblogPageSize <= 0) return 20; return _microblogPageSize; } set { _microblogPageSize = value; } } //---------------------------------------------------------------- public Boolean EnableEmail { get; set; } // 是否开启邮件服务,比如:邮件激活等 public String SmtpUrl { get; set; } public String SmtpUser { get; set; } public String SmtpPwd { get; set; } public Boolean SmtpEnableSsl { get; set; } public Boolean CloseComment { get; set; } //-------------------------------other--------------------------------- public int MaxOnline { get; set; } public DateTime MaxOnlineTime { get; set; } public int UserTemplateId { get; set; } public int NoRefreshSecond { get; set; } public int FeedKeepDay { get; set; } public DateTime LastFeedClearTime { get; set; } public String[] Spider { get; set; } private static string getArrayString( String[] arr ) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.Length; i++) { sb.Append( arr[i] ); if (i < arr.Length - 1) sb.Append( "/" ); } return sb.ToString(); } //---------------------------------------------------------------- public int PhotoThumbHeight { get; set; } public int PhotoThumbWidth { get; set; } public int PhotoThumbHeightMedium { get; set; } public int PhotoThumbWidthMedium { get; set; } public int PhotoThumbHeightBig { get; set; } public int PhotoThumbWidthBig { get; set; } public int AvatarThumbHeight { get; set; } public int AvatarThumbWidth { get; set; } public int AvatarThumbHeightMedium { get; set; } public int AvatarThumbWidthMedium { get; set; } public int AvatarThumbHeightBig { get; set; } public int AvatarThumbWidthBig { get; set; } public Boolean IsSaveAvatarMedium { get; set; } public Boolean IsSaveAvatarBig { get; set; } public String[] UploadFileTypes { get; set; } public String[] UploadPicTypes { get; set; } private int _uploadPicMaxMB; private int _uploadFileMaxMB; /// /// 图片最大上传的大小,单位MB /// public int UploadPicMaxMB { get { if (_uploadPicMaxMB == 0) return 5; return _uploadPicMaxMB; } set { _uploadPicMaxMB = value; } } /// /// 图片最大上传的大小,单位MB /// public int UploadFileMaxMB { get { if (_uploadFileMaxMB == 0) return 20; return _uploadFileMaxMB; } set { _uploadFileMaxMB = value; } } // 扩展的值 //------------------------------------------------------------------------------------- public int GetValueInt( String key ) { return cvt.ToInt( GetValue( key ) ); } public Boolean GetValueBool( String key ) { return cvt.ToBool( GetValue( key ) ); } public decimal GetValueDecimal( String key ) { return cvt.ToDecimal( GetValue( key ) ); } public DateTime GetValueTime( String key ) { return cvt.ToTime( GetValue( key ) ); } public String GetValue( String key ) { if (strUtil.IsNullOrEmpty( key )) return null; if (_valueAll == null) return null; if (_valueAll.ContainsKey( key ) == false) return null; return _valueAll[key]; } //------------------------- public String[] GetArrayValue( String key ) { return getArrayValue( _valueAll, key ); } internal String[] getArrayValue( Dictionary dic, String key ) { if (dic == null) return new String[] { }; if (dic.ContainsKey( key ) && strUtil.HasText( dic[key] )) { return GetArrayValueByString( dic[key] ); } return new String[] { }; } public static String[] GetArrayValueByString( String valOne ) { if (strUtil.IsNullOrEmpty( valOne )) return new String[] { }; String[] arrValue = valOne.Split( new char[] { ',', '/', '|', ',', '、' } ); // 剔除掉无效的字符串 ArrayList results = new ArrayList(); foreach (String val in arrValue) { if (strUtil.HasText( val )) results.Add( val.Trim() ); } return (String[])results.ToArray( typeof( String ) ); } private Dictionary _valueAll; internal void setValueAll( Dictionary valueAll ) { _valueAll = valueAll; } //---------------------------------------------------------------- /// /// 将更新保存到磁盘 /// /// /// public void Update( String item, Object val ) { String itemValue = ""; if (val != null) itemValue = val.ToString(); itemValue = strUtil.Text2Html( itemValue ); saveConfig( item, itemValue ); } public void UpdateHtml( String item, Object val ) { String itemValue = ""; if (val != null) itemValue = val.ToString(); itemValue = itemValue.Replace( "\n", "" ).Replace( "\r", "" ); saveConfig( item, itemValue ); } private void saveConfig( String item, String itemValue ) { String[] configString = file.ReadAllLines( config.siteconfigAbsPath ); List results = new List(); checkSingleLine( item, itemValue, configString, results ); StringBuilder sb = new StringBuilder(); foreach (String line in results) { sb.Append( line ); sb.Append( Environment.NewLine ); } lock (objLock) { file.Write( config.siteconfigAbsPath, sb.ToString() ); } } private void checkSingleLine( String item, String itemValue, String[] configString, List results ) { Boolean hasItem = false; foreach (String line in configString) { if (startsWith( line, item )) { hasItem = true; results.Add( item + " : " + itemValue ); _valueAll[item] = itemValue; } else { results.Add( line ); } } if (hasItem == false) { results.Add( item + " : " + itemValue ); _valueAll[item] = itemValue; } } private static Boolean startsWith( String line, String item ) { if (line.StartsWith( item )) { String noPrefixLine = strUtil.TrimStart( line, item ).Trim(); if (noPrefixLine.StartsWith( ":" )) { return true; } } return false; } private static Object objLock = new object(); } }