CS Nuggets

This blog is for addons, bugs, fixes, and issues pertaining to Community Server.

CS2007: BUG & FIX: BBCodes and Emoticons

This bug is a carry over from CS 2.x which improperly handles BBCodes and Emoticons.  You can see this on the communityserver.org site.  Every so often you will see a post with smilies that seem out of place, or you may be trying to use BBCodes and they don't quite work properly.  This is mostly due to the order in which things are being processed.

This fix requires making changes to the SDK, will correct these issues, and add 3 new BBCodes (

, [notes], and [ which is a BBCode escape for code lists).  The [code] BBCode is a standard code, but it was left out of the CS library.  To make these changes, do the following:

File: CommunityServerComponents20/Components/Transforms.cs:

Around line 53:

Move the following lines:

if (allowCustomTransforms ) {
    // must do emoteicons first because they are restricted from finding any inside [code]
blocks. We have to do
    // this before the later steps remove the
blocks.
    if( CSContext.Current.SiteSettings.EnableEmoticons ) {
        formattedPost = EmoticonTransforms(formattedPost);
    }
}

to line 76, after the following lines:

// Do BBCode transform, if any
//
formattedPost = BBcodeToHtml(formattedPost);

Around Line 240: 

After the following lines:

// Left, Right, Center
encodedString = Regex.Replace(encodedString, @"\[left(?:\s*)\]((.|\n)*?)\[/left(?:\s*)]", "<div style=\"text-align:left\">$1</div>", options);
encodedString = Regex.Replace(encodedString, @"\[center(?:\s*)\]((.|\n)*?)\[/center(?:\s*)]", "<div style=\"text-align:center\">$1</div>", options);
encodedString = Regex.Replace(encodedString, @"\[right(?:\s*)\]((.|\n)*?)\[/right(?:\s*)]", "<div style=\"text-align:right\">$1</div>", options);

insert:

// Note
//
encodedString = Regex.Replace(encodedString, @"\[note(?:\s*)header=(?:""|&quot;|&#34;)(.*?)(?:""|&quot;|&#34;)\]", "<blockquote><div><strong>$1:</strong></div><br /><div>", options);
encodedString = Regex.Replace(encodedString, @"\[note(\s*)\]", "<blockquote><div>", options);
encodedString = Regex.Replace(encodedString, @"\[/note(\s*)\]", "</div></blockquote>", options);

// Code
//
encodedString = Regex.Replace(encodedString, @"\[code(?:\s*)file=(?:""|&quot;|&#34;)(.*?)(?:""|&quot;|&#34;)\]", "<blockquote style=\"overflow-x: scroll;\"><div><strong>$1:</strong></div><br /><pre style=\"margin: 0px;\">", options);
encodedString = Regex.Replace(encodedString, @"\[code(?:\s*)\]", "<blockquote style=\"overflow-x: scroll;\"><pre style=\"margin: 0px;\">", options);
encodedString = Regex.Replace(encodedString, @"\[/code(?:\s*)\]", "</pre></blockquote>", options);

Around line 295:

Before the following line:

return encodedString;

insert:

// New code for developers
encodedString = Regex.Replace(encodedString, @"\[\]", "[", options);

File: communityserver.config:

In the <CSModules> section around line 1020:

Find the following section:

<add name = "AutoApproveForumModule" type="CommunityServer.Discussions.Components.AutoApproveForumModule, CommunityServer.Discussions" />
<add name = "BBcodeToHtml" type = "CommunityServer.Discussions.Components.BBcodeToHtmlModule, CommunityServer.Discussions" />
<add name = "IrcCommands" type = "CommunityServer.Discussions.Components.IrcCommandsModule, CommunityServer.Discussions" />
<add name = "ForumCensorship" type = "CommunityServer.Discussions.Components.CensorshipModule, CommunityServer.Discussions" />
<add name = "ForumEmoticon" type = "CommunityServer.Discussions.Components.EmoticonModule, CommunityServer.Discussions" />
<add name = "ForumSourceCode" type = "CommunityServer.Discussions.Components.SourceCodeModule, CommunityServer.Discussions" />
<add name = "ForumPlainText" type = "CommunityServer.Discussions.Components.PlainTextModule, CommunityServer.Discussions" />
<add name = "ForumHtmlScrubbing" type = "CommunityServer.Discussions.Components.HtmlScrubbingModule, CommunityServer.Discussions" />
<add name = "ForumCollapse" type = "CommunityServer.Discussions.Components.CollapseModule, CommunityServer.Discussions" />
<add name="ForumQuoteModule" type="CommunityServer.Discussions.Components.QuoteModule, CommunityServer.Discussions" />

and change the order of the lines to:

<add name = "AutoApproveForumModule" type="CommunityServer.Discussions.Components.AutoApproveForumModule, CommunityServer.Discussions" />
<add name = "IrcCommands" type = "CommunityServer.Discussions.Components.IrcCommandsModule, CommunityServer.Discussions" />
<add name = "ForumCensorship" type = "CommunityServer.Discussions.Components.CensorshipModule, CommunityServer.Discussions" />
<add name = "ForumSourceCode" type = "CommunityServer.Discussions.Components.SourceCodeModule, CommunityServer.Discussions" />
<add name = "ForumPlainText" type = "CommunityServer.Discussions.Components.PlainTextModule, CommunityServer.Discussions" />
<add name = "ForumHtmlScrubbing" type = "CommunityServer.Discussions.Components.HtmlScrubbingModule, CommunityServer.Discussions" />
<add name = "BBcodeToHtml" type = "CommunityServer.Discussions.Components.BBcodeToHtmlModule, CommunityServer.Discussions" />
<add name = "ForumEmoticon" type = "CommunityServer.Discussions.Components.EmoticonModule, CommunityServer.Discussions" />

<add name = "ForumCollapse" type = "CommunityServer.Discussions.Components.CollapseModule, CommunityServer.Discussions" />
<add name="ForumQuoteModule" type="CommunityServer.Discussions.Components.QuoteModule, CommunityServer.Discussions" />

The new [code] BBCode has an optional file="<text>" attribute that you can use for filenames or whatever else you would like.  The new [note] BBCode has an optional header="<text>" attribute that works in the same way as the file attribute of [code].  To use the new code for developers, you just type a ] (right bracket) immediately after an [ (left bracket).  For example, entering:

[b]This is how you bold text[/b]

in your post, will display:

This is how you bold text

And if you entered the above line directly into a post it would display as:

This is how you bold text

If you have any questions or comments, please post them here.  Also, if you haven't already read my post CS2007: Add BBCode support to Blogs, you may to read it as well.

Posted: Sun, Apr 29 2007 11:43 PM by Bill Bosacker | with no comments
Filed under: ,
Leave a Comment

(required) 

(required) 

(optional)

(required)