Should be able to use this. Then to call your macro you can just type {% ForumContext.FormatPostText(PostTest, ForumID) |(identity)GlobalAdministrator%}
using System;
using CMS;
using CMS.Forums;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.SiteProvider;
[assembly: RegisterExtension(typeof(ForumCustomMacroMethds), typeof(ForumContext))]
public class ForumCustomMacroMethds : MacroMethodContainer
{
[MacroMethod(typeof(string), "Formats for forum Post Info", 1)]
[MacroMethodParam(0, "PostText", typeof(string), "PostText")]
[MacroMethodParam(1, "ForumID", typeof(int), "ForumID")]
public static object FormatPostText(EvaluationContext context, params object[] parameters)
{
// Branches according to the number of the method's parameters
switch (parameters.Length)
{
case 3:
// Overload with two parameters
return FormatPostText(ValidationHelper.GetString(parameters[1], ""),
ValidationHelper.GetInteger(parameters[2], 0));
default:
// No other overloads are supported
throw new NotSupportedException();
}
}
private static object FormatPostText(string postText,int forumId)
{
var forumInfo = ForumInfoProvider.GetForumInfo(forumId);
if (forumInfo != null)
{
string @string = ValidationHelper.GetString(postText, "", (System.Globalization.CultureInfo) null);
DiscussionMacroResolver discussionMacroResolver = new DiscussionMacroResolver();
discussionMacroResolver.EnableBold = forumInfo.ForumEnableFontBold;
discussionMacroResolver.EnableItalics = forumInfo.ForumEnableFontItalics;
discussionMacroResolver.EnableStrikeThrough = forumInfo.ForumEnableFontStrike;
discussionMacroResolver.EnableUnderline = forumInfo.ForumEnableFontUnderline;
discussionMacroResolver.EnableCode = forumInfo.ForumEnableCodeSnippet;
discussionMacroResolver.EnableColor = forumInfo.ForumEnableFontColor;
discussionMacroResolver.EnableImage = forumInfo.ForumEnableImage || forumInfo.ForumEnableAdvancedImage;
discussionMacroResolver.EnableQuote = forumInfo.ForumEnableQuote;
discussionMacroResolver.EnableURL = forumInfo.ForumEnableURL || forumInfo.ForumEnableAdvancedURL;
discussionMacroResolver.MaxImageSideSize = forumInfo.ForumImageMaxSideSize;
discussionMacroResolver.QuotePostText = ResHelper.GetString("DiscussionMacroResolver.QuotePostText",
(string) null, true);
discussionMacroResolver.UseNoFollowForLinks =
HTMLHelper.UseNoFollowForUsersLinks(SiteContext.CurrentSiteName);
if (forumInfo.ForumHTMLEditor)
{
discussionMacroResolver.EncodeText = false;
discussionMacroResolver.ConvertLineBreaksToHTML = false;
}
else
{
discussionMacroResolver.EncodeText = true;
discussionMacroResolver.ConvertLineBreaksToHTML = true;
}
return discussionMacroResolver.ResolveMacros(@string);
}
return postText;
}
}