| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using Utils.IO;
- using Utils;
- namespace SiteCore.Framework
- {
- /// <summary>
- /// 注册类型
- /// </summary>
- public class RegisterType {
- /// <summary>
- /// 开放注册
- /// </summary>
- public static readonly int Open;
- /// <summary>
- /// 关闭注册
- /// </summary>
- public static readonly int Close = 1;
- /// <summary>
- /// 关闭注册,但受邀请的除外
- /// </summary>
- public static readonly int CloseUnlessInvite = 2;
- }
- /// <summary>
- /// 网站配置
- /// </summary>
- public class SiteSetting {
- /// <summary>
- /// 保留用户名(不可以注册的用户名)
- /// </summary>
- public String[] ReservedUserName { get; set; }
- /// <summary>
- /// 保留的用户个性网址
- /// </summary>
- public String[] ReservedUserUrl { get; set; }
- /// <summary>
- /// 保留的关键词(不可以在用户名和个性网址中使用)
- /// </summary>
- 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;
- }
- //------------------------------filter----------------------------------
- /// <summary>
- /// 禁用的关键词
- /// </summary>
- public String[] BadWords { get; set; }
- /// <summary>
- /// 禁用词汇的替换词
- /// </summary>
- public String BadWordsReplacement { get; set; }
- /// <summary>
- /// 所有被禁的ip地址
- /// </summary>
- public String[] BannedIp { get; set; }
- private String _bannedIpInfo;
- /// <summary>
- /// 给被屏蔽访客的警告信息
- /// </summary>
- public String BannedIpInfo {
- get {
- if (_bannedIpInfo == null) return "对不起,你的 ip 地址已被屏蔽";
- return _bannedIpInfo;
- }
- set { _bannedIpInfo = value; }
- }
- //邮箱
- public String SmtpUrl { get; set; }
- public String SmtpUser { get; set; }
- public String SmtpPwd { get; set; }
- //蜘蛛
- public String SpiderIp { get; set; }
-
- //天气Url
- public String WeatherUrl { get; set; }
- //短信
- public String SmsUid { get; set; }
- public String SmsPwd { get; set; }
- public String SmsUrl { get; set; }
- public String SmsLoginUrl { get; set; }
- public String SmsVerifyMobileInfo { get; set; }
- public String SmsGroupPayMobileInfo { get; set; }
- public String SmsGroupCodMobileInfo { get; set; }
- public String SmsGoodsCodMobileInfo { get; set; }
- public String SmsGoodsPayMobileInfo { get; set; }
- public String SmsTakeMoenyMobileInfo { get; set; }
- public String SmsExitQueueMobileInfo { get; set; }
- public String SmsConsumptionInfo { get; set; }
- //充值
- public String Partner_99 { get; set; }
- public String Key_99 { get; set; }
- public String Host_99 { get; set; }
- // 扩展的值
- //-------------------------------------------------------------------------------------
- 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<String, String> 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[] { ',', '/', '|', ',', '、' } );
- // 剔除掉无效的字符串
- 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<String, String> _valueAll;
- internal void setValueAll( Dictionary<String, String> valueAll ) {
- _valueAll = valueAll;
- }
- //----------------------------------------------------------------
- /// <summary>
- /// 将更新保存到磁盘
- /// </summary>
- /// <param name="item"></param>
- /// <param name="val"></param>
- 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<String> results = new List<string>();
- 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<String> 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;
- }
- }
- public void UpdateItems(string[] keys,string[] values)
- {
- String[] configString = File.ReadAllLines(config.siteconfigAbsPath);
- List<String> results = new List<string>();
- foreach (String line in configString)
- {
- Boolean hasItem = false;
- for (int i = 0; i < keys.Length; i++)
- {
- if (startsWith(line, keys[i]))
- {
- hasItem = true;
- results.Add(keys[i] + " : " + values[i]);
- _valueAll[keys[i]] = values[i];
- break;
- }
- }
- if (!hasItem) results.Add(line);
- }
- 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 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 readonly Object objLock = new object();
- }
- }
|