PageRenderTime 34ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Extensions/Smilies.cs

#
C# | 86 lines | 49 code | 14 blank | 23 comment | 2 complexity | 3e922b9f5fa21553add6c9e6fe139484 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. #region using
  2. using BlogEngine.Core;
  3. using BlogEngine.Core.Web.Controls;
  4. using BlogEngine.Core.Web.Extensions;
  5. #endregion
  6. /// <summary>
  7. /// Converts ASCII smilies into real smilies in the comments.
  8. /// </summary>
  9. /// <remarks>
  10. /// Based on the extension by John Knipper - http://www.happytocode.com
  11. /// </remarks>
  12. [Extension("Converts ASCII smilies into real smilies in the comments", "1.3", "BlogEngine.NET")]
  13. public class Smilies
  14. {
  15. #region Constants and Fields
  16. /// <summary>
  17. /// The link string.
  18. /// </summary>
  19. private const string Link =
  20. "<img src=\"{0}editors/tiny_mce_3_4_3_1/plugins/emotions/img/smiley-{1}.gif\" class=\"flag\" alt=\"{2}\" />";
  21. #endregion
  22. #region Constructors and Destructors
  23. /// <summary>
  24. /// Initializes static members of the <see cref="Smilies"/> class.
  25. /// </summary>
  26. static Smilies()
  27. {
  28. Comment.Serving += PostCommentServing;
  29. }
  30. #endregion
  31. #region Methods
  32. /// <summary>
  33. /// Formats the anchor and inserts the right smiley image.
  34. /// </summary>
  35. /// <param name="name">The name of the link.</param>
  36. /// <param name="alt">The alternate string.</param>
  37. /// <returns>The link image.</returns>
  38. private static string Convert(string name, string alt)
  39. {
  40. return string.Format(Link, Utils.RelativeWebRoot, name, alt);
  41. }
  42. /// <summary>
  43. /// Handles the CommentServing event of the Post control.
  44. /// </summary>
  45. /// <param name="sender">The source of the event.</param>
  46. /// <param name="e">The <see cref="BlogEngine.Core.ServingEventArgs"/> instance containing the event data.</param>
  47. private static void PostCommentServing(object sender, ServingEventArgs e)
  48. {
  49. if (!ExtensionManager.ExtensionEnabled("Smilies"))
  50. return;
  51. if (string.IsNullOrEmpty(e.Body))
  52. return;
  53. e.Body = e.Body.Replace("(H)", Convert("cool", "Cool"));
  54. e.Body = e.Body.Replace(":'(", Convert("cry", "Cry"));
  55. e.Body = e.Body.Replace(":$", Convert("embarassed", "Embarassed"));
  56. e.Body = e.Body.Replace(":|", Convert("foot-in-mouth", "Foot"));
  57. e.Body = e.Body.Replace(":(", Convert("frown", "Frown"));
  58. e.Body = e.Body.Replace("(A)", Convert("innocent", "Innocent"));
  59. e.Body = e.Body.Replace("(K)", Convert("kiss", "Kiss"));
  60. e.Body = e.Body.Replace(":D", Convert("laughing", "Laughing"));
  61. e.Body = e.Body.Replace("($)", Convert("money-mouth", "Money"));
  62. e.Body = e.Body.Replace(":-#", Convert("sealed", "Sealed"));
  63. e.Body = e.Body.Replace(":)", Convert("smile", "Smile"));
  64. e.Body = e.Body.Replace(":-)", Convert("smile", "Smile"));
  65. e.Body = e.Body.Replace(":-O", Convert("surprised", "Surprised"));
  66. e.Body = e.Body.Replace(":P", Convert("tongue-out", "Tong"));
  67. e.Body = e.Body.Replace("*-)", Convert("undecided", "Undecided"));
  68. e.Body = e.Body.Replace(";-)", Convert("wink", "Wink"));
  69. e.Body = e.Body.Replace("8o|", Convert("yell", "Yell"));
  70. }
  71. #endregion
  72. }