예제 #1
0
        /// <summary>
        /// 重新加载并初始化自定义标签正则对象数组
        /// </summary>
        /// <param name="smiliesList">自定义标签对象数组</param>
        public static void ResetRegexCustomTag(CustomEditorButtonInfo[] tagList)
        {
            int tagCount = tagList.Length;

            // 如果数目不同则重新创建数组, 以免发生数组越界
            if (regexCustomTag == null || tagCount != regexCustomTag.Length)
                regexCustomTag = new Regex[tagCount];

            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < tagCount; i++)
            {
                if (builder.Length > 0)
                    builder.Remove(0, builder.Length);

                builder.Append(@"(\[");
                builder.Append(tagList[i].Tag);
                if (tagList[i].Params > 1)
                {
                    builder.Append("=");
                    for (int j = 2; j <= tagList[i].Params; j++)
                    {
                        builder.Append(@"(.*?)");
                        if (j < tagList[i].Params)
                            builder.Append(","); 
                    }
                }

                builder.Append(@"\])([\s\S]+?)\[\/");
                builder.Append(tagList[i].Tag);
                builder.Append(@"\]");

                regexCustomTag[i] = new Regex(builder.ToString(), RegexOptions.IgnoreCase);
            }
        }
예제 #2
0
        /// <summary>
        /// 以CustomEditorButtonInfo数组
        /// </summary>
        /// <returns></returns>
        public static CustomEditorButtonInfo[] GetCustomEditButtonListWithInfo()
        {
            IDataReader iDataReader = DatabaseProvider.GetInstance().GetCustomEditButtonList();
            List<CustomEditorButtonInfo> buttonList = new List<CustomEditorButtonInfo>();
            while(iDataReader.Read())
            {         
                CustomEditorButtonInfo buttonInfo = new CustomEditorButtonInfo();
                buttonInfo.Id = TypeConverter.ObjectToInt(iDataReader["id"]);
                buttonInfo.Tag = iDataReader["Tag"].ToString();
                buttonInfo.Icon = iDataReader["Icon"].ToString();
                buttonInfo.Available = TypeConverter.ObjectToInt(iDataReader["Available"]);
                buttonInfo.Example = iDataReader["Example"].ToString();
                buttonInfo.Explanation = iDataReader["Explanation"].ToString();
                buttonInfo.Params = TypeConverter.ObjectToInt(iDataReader["Params"]);
                buttonInfo.Nest = TypeConverter.ObjectToInt(iDataReader["Nest"]);
                buttonInfo.Paramsdefvalue = iDataReader["Paramsdefvalue"].ToString();
                buttonInfo.Paramsdescript = iDataReader["Paramsdescript"].ToString();
                buttonInfo.Replacement = iDataReader["Replacement"].ToString();
                buttonList.Add(buttonInfo);
            }
            iDataReader.Close();

            return buttonList.ToArray();
        }
예제 #3
0
파일: Editors.cs 프로젝트: ichari/ichari
        /// <summary>
        /// 以CustomEditorButtonInfo数组形式返回自定义按钮
        /// </summary>
        /// <returns></returns>
        public static CustomEditorButtonInfo[] GetCustomEditButtonListWithInfo()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            CustomEditorButtonInfo[] buttonArray = cache.RetrieveObject("/UI/CustomEditButtonInfo") as CustomEditorButtonInfo[];
            if (buttonArray == null)
            {
                DataTable dt = GetCustomEditButtonListWithTable();
                if (dt == null)
                {
                    return null;
                }

                if (dt.Rows.Count <= 0)
                {
                    return null;
                }

                buttonArray = new CustomEditorButtonInfo[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    buttonArray[i] = new CustomEditorButtonInfo();
                    buttonArray[i].Id = Utils.StrToInt(dt.Rows[i]["id"], 0);
                    buttonArray[i].Tag = dt.Rows[i]["Tag"].ToString();
                    buttonArray[i].Icon = dt.Rows[i]["Icon"].ToString();
                    buttonArray[i].Available = Utils.StrToInt(dt.Rows[i]["Available"], 0);
                    buttonArray[i].Example = dt.Rows[i]["Example"].ToString();
                    buttonArray[i].Explanation = dt.Rows[i]["Explanation"].ToString();
                    buttonArray[i].Params = Utils.StrToInt(dt.Rows[i]["Params"], 0);
                    buttonArray[i].Nest = Utils.StrToInt(dt.Rows[i]["Nest"], 0);
                    buttonArray[i].Paramsdefvalue = dt.Rows[i]["Paramsdefvalue"].ToString();
                    buttonArray[i].Paramsdescript = dt.Rows[i]["Paramsdescript"].ToString();
                    buttonArray[i].Replacement = dt.Rows[i]["Replacement"].ToString();
                }
                dt.Dispose();
                cache.AddObject("/UI/CustomEditButtonInfo", buttonArray);

                // 表情缓存重新加载时重新初始化表情正则对象数组
                ResetRegexCustomTag(buttonArray);
            }
            return buttonArray;
        }
예제 #4
0
        /// <summary>
        /// 转换自定义标签
        /// </summary>
        /// <param name="sDetail">帖子内容</param>
        /// <param name="__customeditorbuttoninfo">自定义标签数组</param>
        /// <returns>帖子内容</returns>
        private static string ReplaceCustomTag(string sDetail, CustomEditorButtonInfo[] customeditorbuttoninfo)
        {
            if (customeditorbuttoninfo == null)
                return sDetail;

            string replacement = "";
            int b_params = 0;
            string tempReplacement;

            Match m;

            for (int i = 0; i < Editors.regexCustomTag.Length; i++)
            {
                replacement = customeditorbuttoninfo[i].Replacement;
                b_params = customeditorbuttoninfo[i].Params;

                for (int k = 0; k < customeditorbuttoninfo[i].Nest; k++)
                {
                    for (m = Editors.regexCustomTag[i].Match(sDetail); m.Success; m = m.NextMatch())
                    {
                        tempReplacement = replacement.Replace(@"{1}", m.Groups[m.Groups.Count - 1].ToString());
                        if (b_params > 1)
                        {
                            for (int j = 2; j <= b_params; j++)
                            {
                                if (m.Groups.Count > j)
                                    tempReplacement = tempReplacement.Replace("{" + j + "}", m.Groups[j].ToString());
                            }
                        }
                        sDetail = sDetail.Replace(m.Groups[0].ToString(), tempReplacement);
                        sDetail = sDetail.Replace("{RANDOM}", Guid.NewGuid().ToString());
                    }
                }
            }
            return sDetail;
        }
예제 #5
0
파일: DNTCache.cs 프로젝트: ichari/ichari
 /// <summary>
 /// 添加CustomEditorButtonInfo类型数据缓存
 /// </summary>
 /// <param name="xpath">分级对象的路径</param>
 /// <param name="cuebiArray">缓存的数据</param>
 public virtual void AddObject(string xpath, CustomEditorButtonInfo[] cuebiArray)
 {
     lock (lockHelper)
     {
         if (cuebiArray.Length > 0)
         {
             AddObject(xpath + "flag", CacheFlag.CacheHaveData);
         }
         else
         {
             AddObject(xpath + "flag", CacheFlag.CacheNoData);
         }
         AddObject(xpath, (object)cuebiArray);
     }
 }