smilies.cs
来自「个人博客系统」· CS 代码 · 共 60 行
CS
60 行
#region using
using System;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
#endregion
/// <summary>
/// Converts ASCII smilies into real smilies in the comments
/// </summary>
/// <remarks>
/// Based on the extension by John Knipper - http://www.happytocode.com
/// </remarks>
[Extension("Converts ASCII smilies into real smilies in the comments", "1.0.0.0", "BlogEngine.NET")]
public class Smilies
{
public Smilies()
{
Comment.Serving += new EventHandler<ServingEventArgs>(Post_CommentServing);
}
private static readonly string _Link = "<img src=\"{0}admin/tiny_mce/plugins/emotions/images/smiley-{1}.gif\" class=\"flag\" alt=\"{2}\" />";
/// <summary>
/// The event handler that is triggered every time a comment is served to a client.
/// </summary>
private void Post_CommentServing(object sender, ServingEventArgs e)
{
if (!string.IsNullOrEmpty(e.Body))
{
e.Body = e.Body.Replace("(H)", Convert("cool", "Cool"));
e.Body = e.Body.Replace(":'(", Convert("cry", "Cry"));
e.Body = e.Body.Replace(":$", Convert("embarassed", "Embarassed"));
e.Body = e.Body.Replace(":|", Convert("foot-in-mouth", "Foot"));
e.Body = e.Body.Replace(":(", Convert("frown", "Frown"));
e.Body = e.Body.Replace("(A)", Convert("innocent", "Innocent"));
e.Body = e.Body.Replace("(K)", Convert("kiss", "Kiss"));
e.Body = e.Body.Replace(":D", Convert("laughing", "Laughing"));
e.Body = e.Body.Replace("($)", Convert("money-mouth", "Money"));
e.Body = e.Body.Replace(":-#", Convert("sealed", "Sealed"));
e.Body = e.Body.Replace(":)", Convert("smile", "Smile"));
e.Body = e.Body.Replace(":-)", Convert("smile", "Smile"));
e.Body = e.Body.Replace(":-O", Convert("surprised", "Surprised"));
e.Body = e.Body.Replace(":P", Convert("tongue-out", "Tong"));
e.Body = e.Body.Replace("*-)", Convert("undecided", "Undecided"));
e.Body = e.Body.Replace(";)", Convert("wink", "Wink"));
e.Body = e.Body.Replace("8o|", Convert("yell", "Yell"));
}
}
/// <summary>
/// Formats the anchor and inserts the right smiley image.
/// </summary>
private static string Convert(string name, string alt)
{
return string.Format(_Link, Utils.RelativeWebRoot, name, alt);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?