Beispiel #1
0
        public static string MakeHtml( yaf.pages.ForumPage basePage, string bbcode, bool DoFormatting )
        {
            System.Collections.ArrayList codes = new System.Collections.ArrayList();
            const string codeFormat = ".code@{0}.";

            string localQuoteStr = basePage.GetText( "COMMON", "BBCODE_QUOTE" );
            string localCodeStr = basePage.GetText( "COMMON", "BBCODE_CODE" );
            string localQuoteWroteStr = basePage.GetText( "COMMON", "BBCODE_QUOTEWROTE" );

            Match m = r_code2.Match( bbcode );
            int nCodes = 0;

            while ( m.Success )
            {
                string before_replace = m.Groups [0].Value;
                string after_replace = m.Groups ["inner"].Value;

                try
                {
                    HighLighter hl = new HighLighter();
                    hl.ReplaceEnter = true;
                    after_replace = hl.colorText( after_replace, System.Web.HttpContext.Current.Server.MapPath( Data.ForumRoot + "defs/" ), m.Groups ["language"].Value );
                }
                catch ( Exception x )
                {
                    if ( basePage.IsAdmin )
                        basePage.AddLoadMessage( x.Message );
                    after_replace = FixCode( after_replace );
                }

                bbcode = bbcode.Replace( before_replace, string.Format( codeFormat, nCodes++ ) );
                codes.Add( string.Format( @"<div class=""code""><b>{1}</b><div class=""innercode"">{0}</div></div>", after_replace, localCodeStr ) );
                m = r_code2.Match( bbcode );

            }

            m = r_code1.Match( bbcode );
            while ( m.Success )
            {
                string before_replace = m.Groups [0].Value;
                string after_replace = FixCode( m.Groups ["inner"].Value );
                bbcode = bbcode.Replace( before_replace, string.Format( codeFormat, nCodes++ ) );
                codes.Add( string.Format( @"<div class=""code""><b>{1}</b><div class=""innercode"">{0}</div></div>", after_replace, localCodeStr ) );
                m = r_code1.Match( bbcode );
            }

            m = r_size.Match( bbcode );

            while ( m.Success )
            {
                ///Console.WriteLine("{0}",m.Groups["size"]);
                int i = GetNumber( m.Groups ["size"].Value );
                string tmp;
                if ( i < 1 )
                    tmp = m.Groups ["inner"].Value;
                else if ( i > 9 )
                    tmp = string.Format( "<span style=\"font-size:{1}\">{0}</span>", m.Groups ["inner"].Value, GetFontSize( 9 ) );
                else
                    tmp = string.Format( "<span style=\"font-size:{1}\">{0}</span>", m.Groups ["inner"].Value, GetFontSize( i ) );
                bbcode = bbcode.Substring( 0, m.Groups [0].Index ) + tmp + bbcode.Substring( m.Groups [0].Index + m.Groups [0].Length );
                m = r_size.Match( bbcode );
            }

            if ( DoFormatting )
            {
                NestedReplace( ref bbcode, r_bold, "<b>${inner}</b>" );
                NestedReplace( ref bbcode, r_strike, "<s>${inner}</s>" );
                NestedReplace( ref bbcode, r_italic, "<i>${inner}</i>" );
                NestedReplace( ref bbcode, r_underline, "<u>${inner}</u>" );
                // e-mails
                NestedReplace( ref bbcode, r_email2, "<a href=\"mailto:${email}\">${inner}</a>", new string [] { "email" } );
                NestedReplace( ref bbcode, r_email1, "<a href=\"mailto:${inner}\">${inner}</a>" );
                // urls
                if ( basePage.BoardSettings.BlankLinks )
                {
                    NestedReplace( ref bbcode, r_url2, "<a target=\"_blank\" rel=\"nofollow\" href=\"${http}${url}\">${inner}</a>", new string [] { "url", "http" }, new string [] { "", "http://" } );
                    NestedReplace( ref bbcode, r_url1, "<a target=\"_blank\" rel=\"nofollow\" href=\"${http}${inner}\">${http}${inner}</a>", new string [] { "http" }, new string [] { "http://" } );
                }
                else
                {
                    NestedReplace( ref bbcode, r_url2, "<a rel=\"nofollow\" href=\"${http}${url}\">${inner}</a>", new string [] { "url", "http" }, new string [] { "", "http://" } );
                    NestedReplace( ref bbcode, r_url1, "<a rel=\"nofollow\" href=\"${http}${inner}\">${http}${inner}</a>", new string [] { "http" }, new string [] { "http://" } );
                }
                // font
                NestedReplace( ref bbcode, r_font, "<span style=\"font-family:${font}\">${inner}</span>", new string [] { "font" } );
                NestedReplace( ref bbcode, r_color, "<span style=\"color:${color}\">${inner}</span>", new string [] { "color" } );
                // bullets
                bbcode = r_bullet.Replace( bbcode, "<li>" );
                NestedReplace( ref bbcode, r_list4, "<ol type=\"i\">${inner}</ol>" );
                NestedReplace( ref bbcode, r_list3, "<ol type=\"a\">${inner}</ol>" );
                NestedReplace( ref bbcode, r_list2, "<ol>${inner}</ol>" );
                NestedReplace( ref bbcode, r_list2, "<ul>${inner}</ul>" );
                // alignment
                NestedReplace( ref bbcode, r_center, "<div align=\"center\">${inner}</div>" );
                NestedReplace( ref bbcode, r_left, "<div align=\"left\">${inner}</div>" );
                NestedReplace( ref bbcode, r_right, "<div align=\"right\">${inner}</div>" );
                // image
                NestedReplace( ref bbcode, r_img, "<img src=\"${http}${inner}\"/>", new string [] { "http" }, new string [] { "http://" } );
                // youtube
                NestedReplace( ref bbcode, r_youtube, @"<!-- BEGIN youtube --><object width=""425"" height=""350""><param name=""movie"" value=""http://www.youtube.com/v/${id}""></param><embed src=""http://www.youtube.com/v/${id}"" type=""application/x-shockwave-flash"" width=""425"" height=""350""></embed></object><br /><a href=""http://youtube.com/watch?v=${id}"" target=""_blank"">${inner}</a><br /><!-- END youtube -->", new string [] { "id" } );

                bbcode = r_hr.Replace( bbcode, "<hr noshade/>" );
                bbcode = r_br.Replace( bbcode, "<br/>" );
            }

                bbcode = FormatMsg.iAddSmiles(basePage, bbcode);

            string tmpReplaceStr;

            tmpReplaceStr = string.Format( @"<div class=""quote""><b>{0}</b><div class=""innerquote"">{1}</div></div>", localQuoteWroteStr.Replace( "{0}", "${quote}" ), "${inner}" );

            while ( r_quote2.IsMatch( bbcode ) )
                bbcode = r_quote2.Replace( bbcode, tmpReplaceStr );

            tmpReplaceStr = string.Format( @"<div class=""quote""><b>{0}</b><div class=""innerquote"">{1}</div></div>", localQuoteStr, "${inner}" );

            while ( r_quote1.IsMatch( bbcode ) )
                bbcode = r_quote1.Replace( bbcode, tmpReplaceStr );

            m = r_post.Match( bbcode );
            while ( m.Success )
            {
                string link = Forum.GetLink( Pages.posts, "m={0}#{0}", m.Groups ["post"] );
                if ( basePage.BoardSettings.BlankLinks )
                    bbcode = bbcode.Replace( m.Groups [0].ToString(), string.Format( "<a target=\"_blank\" href=\"{0}\">{1}</a>", link, m.Groups ["inner"] ) );
                else
                    bbcode = bbcode.Replace( m.Groups [0].ToString(), string.Format( "<a href=\"{0}\">{1}</a>", link, m.Groups ["inner"] ) );
                m = r_post.Match( bbcode );
            }

            m = r_topic.Match( bbcode );
            while ( m.Success )
            {
                string link = Forum.GetLink( Pages.posts, "t={0}", m.Groups ["topic"] );
                if ( basePage.BoardSettings.BlankLinks )
                    bbcode = bbcode.Replace( m.Groups [0].ToString(), string.Format( "<a target=\"_blank\" href=\"{0}\">{1}</a>", link, m.Groups ["inner"] ) );
                else
                    bbcode = bbcode.Replace( m.Groups [0].ToString(), string.Format( "<a href=\"{0}\">{1}</a>", link, m.Groups ["inner"] ) );
                m = r_topic.Match( bbcode );
            }

            while ( nCodes > 0 )
            {
                bbcode = bbcode.Replace( string.Format( codeFormat, --nCodes ), codes [nCodes].ToString() );
            }

            return bbcode;
        }
Beispiel #2
0
        public static string MakeHtml(yaf.pages.ForumPage basePage,string bbcode,bool DoFormatting)
        {
            System.Collections.ArrayList codes = new System.Collections.ArrayList();
            const string codeFormat = ".code@{0}.";

            Match m = r_code2.Match(bbcode);
            int nCodes = 0;
            while(m.Success)
            {
                string before_replace = m.Groups[0].Value;
                string after_replace = m.Groups["inner"].Value;

                try
                {
                    HighLighter hl = new HighLighter();
                    hl.ReplaceEnter = true;
                    after_replace = hl.colorText(after_replace,System.Web.HttpContext.Current.Server.MapPath(Data.ForumRoot + "defs/"),m.Groups["language"].Value);
                }
                catch(Exception x)
                {
                    if(basePage.IsAdmin)
                        basePage.AddLoadMessage(x.Message);
                    after_replace = FixCode(after_replace);
                }

                bbcode = bbcode.Replace(before_replace,string.Format(codeFormat,nCodes++));
                codes.Add(string.Format("<div class='code'><b>Code:</b><div class='innercode'>{0}</div></div>",after_replace));
                m = r_code2.Match(bbcode);
            }

            m = r_code1.Match(bbcode);
            while(m.Success)
            {
                string before_replace = m.Groups[0].Value;
                string after_replace = FixCode(m.Groups["inner"].Value);
                bbcode = bbcode.Replace(before_replace,string.Format(codeFormat,nCodes++));
                codes.Add(string.Format("<div class='code'><b>Code:</b><div class='innercode'>{0}</div></div>",after_replace));
                m = r_code1.Match(bbcode);
            }

            m = r_size.Match(bbcode);

            while(m.Success)
            {
                ///Console.WriteLine("{0}",m.Groups["size"]);
                int i = GetNumber(m.Groups["size"].Value);
                string tmp;
                if(i<1)
                    tmp = m.Groups["inner"].Value;
                else if(i>9)
                    tmp = string.Format("<span style=\"font-size:{1}\">{0}</span>",m.Groups["inner"].Value,GetFontSize(9));
                else
                    tmp = string.Format("<span style=\"font-size:{1}\">{0}</span>",m.Groups["inner"].Value,GetFontSize(i));
                bbcode = bbcode.Substring(0,m.Groups[0].Index) + tmp + bbcode.Substring(m.Groups[0].Index + m.Groups[0].Length);
                m = r_size.Match(bbcode);
            }

            bbcode = FormatMsg.iAddSmiles(basePage,bbcode);

            if (DoFormatting)
            {
                NestedReplace(ref bbcode,r_bold,"<b>${inner}</b>");
                NestedReplace(ref bbcode,r_strike,"<s>${inner}</s>");
                NestedReplace(ref bbcode,r_italic,"<i>${inner}</i>");
                NestedReplace(ref bbcode,r_underline,"<u>${inner}</u>");
                // e-mails
                NestedReplace(ref bbcode,r_email2,"<a href=\"mailto:${email}\">${inner}</a>",new string[]{"email"});
                NestedReplace(ref bbcode,r_email1,"<a href=\"mailto:${inner}\">${inner}</a>");
                // urls
                if(basePage.BoardSettings.BlankLinks)
                {
                    NestedReplace(ref bbcode,r_url2,"<a target=\"_blank\" href=\"${http}${url}\">${inner}</a>",new string[]{"url","http"},new string[]{"","http://"});
                    NestedReplace(ref bbcode,r_url1,"<a target=\"_blank\" href=\"${http}${inner}\">${http}${inner}</a>",new string[]{"http"},new string[]{"http://"});
                }
                else
                {
                    NestedReplace(ref bbcode,r_url2,"<a href=\"${http}${url}\">${inner}</a>",new string[]{"url","http"},new string[]{"","http://"});
                    NestedReplace(ref bbcode,r_url1,"<a href=\"${http}${inner}\">${http}${inner}</a>",new string[]{"http"},new string[]{"http://"});
                }
                // font
                NestedReplace(ref bbcode,r_font,"<span style=\"font-family:${font}\">${inner}</span>",new string[]{"font"});
                NestedReplace(ref bbcode,r_color,"<span style=\"color:${color}\">${inner}</span>",new string[]{"color"});
                // bullets
                bbcode = r_bullet.Replace(bbcode,"<li>");
                NestedReplace(ref bbcode,r_list4,"<ol type=\"i\">${inner}</ol>");
                NestedReplace(ref bbcode,r_list3,"<ol type=\"a\">${inner}</ol>");
                NestedReplace(ref bbcode,r_list2,"<ol>${inner}</ol>");
                NestedReplace(ref bbcode,r_list2,"<ul>${inner}</ul>");
                // alignment
                NestedReplace(ref bbcode,r_center,"<div align=\"center\">${inner}</div>");
                NestedReplace(ref bbcode,r_left,"<div align=\"left\">${inner}</div>");
                NestedReplace(ref bbcode,r_right,"<div align=\"right\">${inner}</div>");
                // image
                NestedReplace(ref bbcode,r_img,"<img src=\"${inner}\"/>");

                bbcode = r_hr.Replace(bbcode,"<hr noshade/>");
                bbcode = r_br.Replace(bbcode,"<br/>");
            }

            while(r_quote2.IsMatch(bbcode))
                bbcode = r_quote2.Replace(bbcode,"<div class='quote'><b>${quote} wrote:</b><div class='innerquote'>${inner}</div></div>");
            while(r_quote1.IsMatch(bbcode))
                bbcode = r_quote1.Replace(bbcode,"<div class='quote'><b>Quote:</b><div class='innerquote'>${inner}</div></div>");

            m = r_post.Match(bbcode);
            while(m.Success)
            {
                string link = Forum.GetLink(Pages.posts,"m={0}#{0}",m.Groups["post"]);
                if(basePage.BoardSettings.BlankLinks)
                    bbcode = bbcode.Replace(m.Groups[0].ToString(),string.Format("<a target=\"_blank\" href=\"{0}\">{1}</a>",link,m.Groups["inner"]));
                else
                    bbcode = bbcode.Replace(m.Groups[0].ToString(),string.Format("<a href=\"{0}\">{1}</a>",link,m.Groups["inner"]));
                m = r_post.Match(bbcode);
            }

            m = r_topic.Match(bbcode);
            while(m.Success)
            {
                string link = Forum.GetLink(Pages.posts,"t={0}",m.Groups["topic"]);
                if(basePage.BoardSettings.BlankLinks)
                    bbcode = bbcode.Replace(m.Groups[0].ToString(),string.Format("<a target=\"_blank\" href=\"{0}\">{1}</a>",link,m.Groups["inner"]));
                else
                    bbcode = bbcode.Replace(m.Groups[0].ToString(),string.Format("<a href=\"{0}\">{1}</a>",link,m.Groups["inner"]));
                m = r_topic.Match(bbcode);
            }

            while(nCodes>0)
            {
                bbcode = bbcode.Replace(string.Format(codeFormat,--nCodes),codes[nCodes].ToString());
            }

            return bbcode;
        }