示例#1
0
        static public string RepairHtml(yaf.pages.ForumPage basePage, string html, bool bAllowHtml)
        {
            if (!bAllowHtml)
            {
                html = BBCode.EncodeHTML(html);
            }
            else
            {
                // get allowable html tags
                string   tStr        = basePage.BoardSettings.AcceptedHTML;
                string[] AllowedTags = tStr.Split(',');

                RegexOptions options = RegexOptions.IgnoreCase;

                MatchCollection m = Regex.Matches(html, "<.*?>", options);

                for (int i = m.Count - 1; i >= 0; i--)
                {
                    string tag = html.Substring(m[i].Index + 1, m[i].Length - 1).Trim().ToLower();

                    if (!IsValidTag(tag, AllowedTags))
                    {
                        html = html.Remove(m[i].Index, m[i].Length);
                        // just don't show this tag for now

                        //string tmp = System.Web.HttpContext.Current.Server.HtmlEncode(html.Substring(m[i].Index,m[i].Length));
                        //html = html.Insert(m[i].Index,tmp);
                    }
                }
            }
            return(html);
        }