📄 helper.cs
字号:
using System;
using System.Data;
using System.Web;
using System.Text.RegularExpressions;
namespace Wrox.WebModules.Forums.Business
{
/// <summary>
/// Summary description for Helper.
/// </summary>
public class Helper: Wrox.WebModules.Business.BizObject
{
public static string ProcessSpecialTags(string text)
{
Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings();
// encode the text if HTML code is not allowed. This must be done before
// translating the special tags to real HTML tags
if (!settings.HtmlEnabled)
text = HttpUtility.HtmlEncode(text);
// if the special tags are enabled, process them
if (settings.SpecialTagsEnabled)
{
string smiliesFolder = settings.SmiliesFolder;
if (!smiliesFolder.EndsWith("/")) smiliesFolder += "/";
// replace the bold special tags
text = Regex.Replace(text, "\\[B\\](?<boldText>.*)\\[/B\\]",
"<b>${boldText}</b>", RegexOptions.IgnoreCase);
// replace the underline special tags
text = Regex.Replace(text, "\\[U\\](?<underlineText>.*)\\[/U\\]",
"<u>${underlineText}</u>", RegexOptions.IgnoreCase);
// replace the italic special tags
text = Regex.Replace(text, "\\[I\\](?<italicText>.*)\\[/I\\]",
"<i>${italicText}</i>", RegexOptions.IgnoreCase);
// replace the smilies
text = text.Replace("[:)]", "<img src=\"" + smiliesFolder + "Smile.gif\" border=\"0\"/>");
text = text.Replace("[:D]", "<img src=\"" + smiliesFolder + "LargeSmile.gif\" border=\"0\"/>");
text = text.Replace("[8)]", "<img src=\"" + smiliesFolder + "Cool.gif\" border=\"0\"/>");
text = text.Replace("[:(]", "<img src=\"" + smiliesFolder + "Sad.gif\" border=\"0\"/>");
text = text.Replace("[:o]", "<img src=\"" + smiliesFolder + "Surprise.gif\" border=\"0\"/>");
text = text.Replace("[:x]", "<img src=\"" + smiliesFolder + "Angry.gif\" border=\"0\"/>");
// replace the URL tag
text = Regex.Replace(text, "\\[URL\\](?<url>.*)\\[/URL\\]",
"<a href=\"${url}\" target=\"_blank\">${url}</a>", RegexOptions.IgnoreCase);
// replace the EMAIL tag
text = Regex.Replace(text, "\\[EMAIL\\](?<email>.*)\\[/EMAIL\\]",
"<a href=\"mailto:${email}\">${email}</a>", RegexOptions.IgnoreCase);
}
// replace the quote tags. Quoting is enabled even if the special tags are not
text = Regex.Replace(text, "\\[QUOTE\\]",
"<font size=\"1\"><blockquote>quote:<hr height=\"1\" noshade>",
RegexOptions.IgnoreCase);
text = Regex.Replace(text, "\\[/QUOTE\\]",
"<hr height=\"1\" noshade></blockquote></font>",
RegexOptions.IgnoreCase);
// replace the new line and carriage return chars
text = text.Replace("\n", "<br>");
text = text.Replace("\r", "");
return text;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -