PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/n3c/N3C.Site/Handler/TrackBackHandler.ashx.cs

http://3rgbcom.googlecode.com/
C# | 163 lines | 135 code | 14 blank | 14 comment | 11 complexity | 54af12bf7e2e501c0499fe6b182de678 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.Services;
  5. using System.Xml;
  6. using N3C.DAO;
  7. using N3C.POCO;
  8. using N3C.Utils;
  9. namespace N3C.Site.Handler
  10. {
  11. /// <summary>
  12. /// $codebehindclassname$ ?????
  13. /// </summary>
  14. [WebService(Namespace = "http://tempuri.org/")]
  15. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  16. public class TrackBackHandler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
  17. {
  18. public void ProcessRequest(HttpContext ctx)
  19. {
  20. ctx.Response.ContentType = "text/xml";
  21. XmlDocument xmlDoc;
  22. XmlNode root;
  23. XmlElement node;
  24. EntryCmt objEntryCmt;
  25. EntryCmtDAO daoEntryCmt;
  26. //ctx.Response.Write("Hello World");
  27. //???????
  28. Dictionary<string, string> customConfig = N3Cconst.LoadCustomConfig();
  29. xmlDoc = new XmlDocument();
  30. xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null));
  31. //????Root???
  32. xmlDoc.AppendChild(xmlDoc.CreateElement(null, "response", null));
  33. root = xmlDoc.SelectSingleNode("response");
  34. if (customConfig[N3Cconst.OpenTrackBack] == "true")
  35. {
  36. if (ctx.Request.RequestType == "POST")
  37. {
  38. //initialize spam session,for a session life,
  39. //not more than 2 trackback can be posted here
  40. //otherwise,deneied.
  41. int entryId = 0;
  42. Int32.TryParse(ctx.Request["id"], out entryId);
  43. if (entryId > 0 && null != new viewEntryDAO().Find(entryId))
  44. {
  45. if (null == ctx.Session["TBUser"]) ctx.Session["TBUser"] = 0;
  46. if (Convert.ToInt32(ctx.Session["TBUser"]) > 1)
  47. {
  48. node = xmlDoc.CreateElement("error");
  49. node.InnerText = "1";
  50. root.AppendChild(node);
  51. node = xmlDoc.CreateElement("message");
  52. node.InnerText = "??????,????SPAM";
  53. root.AppendChild(node);
  54. }
  55. else
  56. {
  57. string tbTitle = ctx.Request.Form["title"];
  58. string tbUrl = ctx.Request.Form["url"];
  59. string tbContent = ctx.Request.Form["excerpt"];
  60. string tbBlogName = ctx.Request.Form["blog_name"];
  61. daoEntryCmt = new EntryCmtDAO();
  62. if (!daoEntryCmt.IsExistTrackback(entryId, tbUrl))
  63. {
  64. //create a comment of entry as trackback
  65. objEntryCmt = new EntryCmt();
  66. objEntryCmt.AddTime = DateTime.Now;
  67. objEntryCmt.Author = tbBlogName;
  68. objEntryCmt.EntryId = entryId;
  69. objEntryCmt.IsPublic = 1;
  70. objEntryCmt.UserEmail = customConfig[N3Cconst.PublicEmail];
  71. objEntryCmt.IP = ctx.Request.UserHostAddress;
  72. objEntryCmt.UserSite = tbUrl;
  73. objEntryCmt.TrackBackUrl = tbUrl;
  74. objEntryCmt.Content = "<h3>" + tbTitle + "</h3>" + tbContent;
  75. try
  76. {
  77. daoEntryCmt.Create(objEntryCmt);
  78. //????????
  79. UtilModel.ClearCache(N3Cconst.CacheRecentCmt);
  80. //??????
  81. node = xmlDoc.CreateElement("error");
  82. node.InnerText = "0";
  83. root.AppendChild(node);
  84. //????TRACK URL?????,??2?
  85. ctx.Session["TBUser"] = 1 + Convert.ToInt32(ctx.Session["TBUser"]);
  86. }
  87. catch (Exception)
  88. {
  89. node = xmlDoc.CreateElement("error");
  90. node.InnerText = "1";
  91. root.AppendChild(node);
  92. node = xmlDoc.CreateElement("message");
  93. node.InnerText = "??TrackBack??";
  94. root.AppendChild(node);
  95. }
  96. }
  97. else
  98. {
  99. node = xmlDoc.CreateElement("error");
  100. node.InnerText = "1";
  101. root.AppendChild(node);
  102. node = xmlDoc.CreateElement("message");
  103. node.InnerText = "?URL?????TrackBack,??????";
  104. root.AppendChild(node);
  105. }
  106. }
  107. }
  108. else
  109. {
  110. node = xmlDoc.CreateElement("error");
  111. node.InnerText = "1";
  112. root.AppendChild(node);
  113. node = xmlDoc.CreateElement("message");
  114. node.InnerText = "?????ID";
  115. root.AppendChild(node);
  116. }
  117. }
  118. else
  119. {
  120. node = xmlDoc.CreateElement("error");
  121. node.InnerText = "1";
  122. root.AppendChild(node);
  123. node = xmlDoc.CreateElement("message");
  124. node.InnerText = "???????";
  125. root.AppendChild(node);
  126. }
  127. }
  128. else
  129. {
  130. node = xmlDoc.CreateElement("error");
  131. node.InnerText = "1";
  132. root.AppendChild(node);
  133. node = xmlDoc.CreateElement("message");
  134. node.InnerText = "?????TrackBack??";
  135. root.AppendChild(node);
  136. }
  137. //response XML
  138. xmlDoc.Save(ctx.Response.OutputStream);
  139. ctx.Response.End();
  140. }
  141. public bool IsReusable
  142. {
  143. get
  144. {
  145. return false;
  146. }
  147. }
  148. }
  149. }