示例#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);
        }
示例#2
0
        static public string FormatMessage(yaf.pages.ForumPage basePage, string Message, MessageFlags mFlags)
        {
            // do html damage control
            Message = RepairHtml(basePage, Message, mFlags.IsHTML);

            // convert spaces if bbcode (causes too many problems)

            /*if (mFlags.IsBBCode)
             * {
             *      Message = Message.Replace(" ","&nbsp;");
             * }*/

            // do BBCode and Smilies...
            Message = BBCode.MakeHtml(basePage, Message, mFlags.IsBBCode);

            RegexOptions options = RegexOptions.IgnoreCase /*| RegexOptions.Singleline | RegexOptions.Multiline*/;

            //Email -- RegEx VS.NET
            Message = Regex.Replace(Message, @"(?<before>^|[ ]|<br/>)(?<email>\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)", "${before}<a href=\"mailto:${email}\">${email}</a>", options);

            //URL (http://) -- RegEx http://www.dotnet247.com/247reference/msgs/2/10022.aspx
            Message = Regex.Replace(Message, "(?<before>^|[ ]|<br/>)(?<!href=\")(?<!src=\")(?<url>(http://|https://|ftp://)(?:[\\w-]+\\.)+[\\w-]+(?:/[\\w-./?%&=;,]*)?)", "${before}<a href=\"${url}\">${url}</a>", options);

            //URL (www) -- RegEx http://www.dotnet247.com/247reference/msgs/2/10022.aspx
            Message = Regex.Replace(Message, @"(?<before>^|[ ]|<br/>)(?<!http://)(?<url>www\.(?:[\w-]+\.)+[\w-]+(?:/[\w-./?%&=;,]*)?)", "${before}<a href=\"http://${url}\">${url}</a>", options);

            // jaben : moved word replace to reusable function in class utils
            Message = Utils.BadWordReplace(Message);

            return(Message);
        }