コード例 #1
0
        /// <summary>
        /// converts bbcode to HTML
        /// </summary>
        public static string FormatMessageHTML(string input)
        {
            if (input.Length == 0)
            {
                return(string.Empty);
            }

            string msg = input;

            //youtube (to prevent standard bbencoding)
            Regex regexYouTube = new Regex(@"(\s|^)(http://www\.youtube\.com/watch\?v=([^\s^&]+)[^\s]*)", RegexOptions.IgnoreCase);

            msg = regexYouTube.Replace(msg, "$1[youtube]$3[/youtube]");

            msg = StringUtils.BBCode2HTML(msg, Resources.various.Wrote);

            //youtube AGAIN
            regexYouTube = new Regex(@"\[youtube\]([^\]]+)\[/youtube\]", RegexOptions.IgnoreCase);
            msg          = regexYouTube.Replace(msg, "<object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/$1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/$1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>");

            //remove external links (if disabled)
            if (Settings.DisableExternalLinks == true)
            {
                string localHost = new Uri(Various.ForumURL).Host;
                foreach (Match m in _rxExternalLink.Matches(msg))
                {
                    Uri linkUri;
                    try { linkUri = new Uri(m.Groups[1].Value); }
                    catch { continue; }

                    if (linkUri.Host != localHost)                     //link is external (host is different)
                    {
                        msg = msg.Replace(m.Value, m.Groups[2].Value);
                    }
                }
            }

            //smilies
            if (Settings.AllowSmilies)
            {
                msg = FormatSmilies(msg);
            }

            return(msg);
        }