index.aspx.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Web;
  15. using System.Web.UI;
  16. using System.Web.UI.WebControls;
  17. using System.Text.RegularExpressions;
  18. using iNethinkCMS.Web.UI;
  19. using iNethinkCMS.Helper;
  20. using iNethinkCMS.Command;
  21. namespace iNethinkCMS.Web.plugs.guestbook
  22. {
  23. public partial class index : BasePage
  24. {
  25. private string vXmlPath = @"/plugs/guestbook/setting.xml";
  26. private string vState;
  27. private string vTemplatepath;
  28. private string vTimeinterval;
  29. private string vContentlength;
  30. private string vContentclearhtml;
  31. private string vSecuritycode;
  32. protected void Page_Load(object sender, EventArgs e)
  33. {
  34. vState = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"state\"]", "value").Value.Trim();
  35. vTemplatepath = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"templatepath\"]", "value").Value.Trim();
  36. vTimeinterval = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"timeinterval\"]", "value").Value.Trim();
  37. vContentlength = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"contentlength\"]", "value").Value.Trim();
  38. vContentclearhtml = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"contentclearhtml\"]", "value").Value.Trim();
  39. vSecuritycode = XMLHelper.GetXmlAttribute(Server.MapPath(vXmlPath), "//plugs//config//key[@name=\"securitycode\"]", "value").Value.Trim();
  40. //判断是否开启
  41. if (vState == "0")
  42. {
  43. Response.Write("<H3>留言板功能尚未开启!</H3>");
  44. Response.End();
  45. }
  46. string vAct = "";
  47. vAct = Request.QueryString["Act"] != null ? Request.QueryString["Act"] : "";
  48. switch (vAct)
  49. {
  50. case "guestbooksubmit":
  51. #region 提交留言信息
  52. //防止外部提交
  53. if (Command_Function.Fun_CheckPost())
  54. {
  55. Response.Write("<H3>请勿外部提交!</H3>");
  56. Response.End();
  57. }
  58. //判断时间限制
  59. if (int.Parse(vTimeinterval) > 0)
  60. {
  61. string vLastPostTimeStr = Command_Session.Get("GuestBook_PostTime_Last");
  62. if (Command_Validate.IsDateTime(vLastPostTimeStr))
  63. {
  64. DateTime vLastPostTime = DateTime.Parse(vLastPostTimeStr);
  65. TimeSpan Ts = new System.TimeSpan(DateTime.Now.Ticks - vLastPostTime.Ticks);
  66. if (Ts.TotalSeconds <= int.Parse(vTimeinterval))
  67. {
  68. Response.Write("E000");
  69. Response.End();
  70. }
  71. }
  72. }
  73. //取值
  74. string vGuestbookUserName = Request.Form["sGuestbookUserName"];
  75. string vGuestbookUserIP = Command.Command_Function.GetUserIp();
  76. string vGuestbookTel = Request.Form["sGuestbookTel"];
  77. string vGuestbookCompany = Request.Form["sGuestbookCompany"];
  78. string vGuestbookAddress = Request.Form["sGuestbookAddress"];
  79. string vGuestbookEmail = Request.Form["sGuestbookEmail"];
  80. string vGuestbookQQ = Request.Form["sGuestbookQQ"];
  81. string vGuestbookContent = Request.Form["sGuestbookContent"];
  82. string vGuestbookSecuritycode = Request.Form["sGuestbookSecuritycode"];
  83. DateTime vGuestbookTime = DateTime.Now;
  84. string vReplyUserName = "";
  85. string vReplyContent = "";
  86. //DateTime vReplyTime;
  87. int vDisplay = 0;
  88. int vOrderNum = 0;
  89. vGuestbookUserName = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookUserName)), 20);
  90. vGuestbookCompany = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookCompany)), 100);
  91. vGuestbookAddress = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookAddress)), 100);
  92. vGuestbookTel = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookTel)), 100);
  93. vGuestbookEmail = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookEmail)), 100);
  94. vGuestbookQQ = Command.Command_StringPlus.Left(Command.Command_Validate.SqlTextClear(Command.Command_StringPlus.LostHTML(vGuestbookQQ)), 100);
  95. if (vContentclearhtml == "1")
  96. {
  97. vGuestbookContent = Command.Command_StringPlus.LostHTML(vGuestbookContent);
  98. }
  99. vGuestbookContent = vGuestbookContent.Replace("{", "").Replace("}", "").Replace("'", "").Replace("\"", "").Replace("%", "");
  100. vGuestbookContent = Command.Command_StringPlus.Left(vGuestbookContent, int.Parse(vContentlength));
  101. vGuestbookSecuritycode = Command.Command_Validate.SqlTextClear(vGuestbookSecuritycode);
  102. //验证
  103. if (String.IsNullOrEmpty(vGuestbookUserName))
  104. {
  105. Response.Write("E001");
  106. Response.End();
  107. }
  108. if (String.IsNullOrEmpty(vGuestbookContent))
  109. {
  110. Response.Write("E002");
  111. Response.End();
  112. }
  113. //判断验证码情况
  114. if (vSecuritycode == "1")
  115. {
  116. if (String.IsNullOrEmpty(vGuestbookSecuritycode))
  117. {
  118. Response.Write("E003");
  119. Response.End();
  120. }
  121. if (vGuestbookSecuritycode.ToUpper() != Command.Command_Session.Get("verificationcode").ToUpper())
  122. {
  123. Response.Write("E004");
  124. Response.End();
  125. }
  126. }
  127. //入库
  128. Model.Model_iNethinkCMS_Plugs_Guestbook model = new iNethinkCMS.Model.Model_iNethinkCMS_Plugs_Guestbook();
  129. BLL.BLL_iNethinkCMS_Plugs_Guestbook bll = new iNethinkCMS.BLL.BLL_iNethinkCMS_Plugs_Guestbook();
  130. model.GuestbookUserName = vGuestbookUserName;
  131. model.GuestbookUserIP = vGuestbookUserIP;
  132. model.GuestbookCompany = vGuestbookCompany;
  133. model.GuestbookAddress = vGuestbookAddress;
  134. model.GuestbookTel = vGuestbookTel;
  135. model.GuestbookEmail = vGuestbookEmail;
  136. model.GuestbookQQ = vGuestbookQQ;
  137. model.GuestbookContent = vGuestbookContent;
  138. model.GuestbookTime = vGuestbookTime;
  139. model.ReplyUserName = vReplyUserName;
  140. model.ReplyContent = vReplyContent;
  141. //model.ReplyTime = vReplyTime;
  142. model.Display = vDisplay;
  143. model.OrderNum = vOrderNum;
  144. bll.Add(model);
  145. //写入提交时间Session信息
  146. iNethinkCMS.Command.Command_Session.Add("GuestBook_PostTime_Last", DateTime.Now.ToString());
  147. Response.Write("E100");
  148. #endregion
  149. break;
  150. default:
  151. #region 留言页面显示
  152. string rPage;
  153. rPage = Request.QueryString["page"];
  154. int vPage = 1;
  155. if (rPage != string.Empty && rPage != null && Command.Command_Validate.IsNumber(rPage))
  156. {
  157. vPage = Convert.ToInt32(rPage);
  158. }
  159. string vHtml = "";
  160. bool vWebPageCache = Command.Command_Configuration.GetConfigBool("WebPageCache"); //判断是否启用了页面缓存
  161. if (vWebPageCache == false)
  162. {
  163. vHtml = Fun_GetGuestBookContent(vPage);
  164. }
  165. else
  166. {
  167. int vCacheTime = Command.Command_Configuration.GetConfigInt("CacheTime");
  168. string guestbookCacheKey = Command.Command_Configuration.GetConfigString("CacheKey") + "_GuestBookCache_" + vPage;
  169. object guestbookCacheInfo = Command.Command_DataCache.GetCache(guestbookCacheKey);
  170. //判断缓存是否存在
  171. if (guestbookCacheInfo == null)
  172. {
  173. vHtml = Fun_GetGuestBookContent(vPage);
  174. Command.Command_DataCache.SetCache(guestbookCacheKey, (object)vHtml, DateTime.Now.AddSeconds(vCacheTime), TimeSpan.Zero);
  175. }
  176. else
  177. {
  178. vHtml = guestbookCacheInfo.ToString();
  179. }
  180. }
  181. vHtml = WebUI_Function.Fun_UrlRewriter(vHtml);
  182. Response.Write(vHtml);
  183. #endregion
  184. break;
  185. }
  186. }
  187. private string Fun_GetGuestBookContent(int byPage)
  188. {
  189. string vTemplateUrl = vTemplatepath;
  190. //是否调用移动端模板
  191. if (base.Request.QueryString["m"] != null && base.Request.QueryString["m"].ToString() == "1")
  192. {
  193. vTemplateUrl = Global.MobilePath + vTemplateUrl;
  194. }
  195. vTemplateUrl = isMobile() ? "Mobile/" + vTemplateUrl : vTemplateUrl;
  196. WebUI_Template wt = new WebUI_Template();
  197. wt.Load_Template(vTemplateUrl);
  198. wt.vPage = byPage;
  199. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:title}"), siteConfig.WebName, RegexOptions.IgnoreCase);
  200. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:seotitle}"), seoConfig.SeoTitle, RegexOptions.IgnoreCase);
  201. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:keywords}"), seoConfig.IndexKeywords, RegexOptions.IgnoreCase);
  202. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:description}"), seoConfig.IndexDescription, RegexOptions.IgnoreCase);
  203. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:sitepath}"), WebUI_Function.Fun_GetSitePath(69), RegexOptions.IgnoreCase);
  204. wt.Parser_MyTag();
  205. wt.Parser_List();
  206. wt.Parser_Page();
  207. wt.Parser_IF();
  208. return wt.vContent;
  209. }
  210. }
  211. }