content.aspx.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.Data;
  14. using System.Data.SqlClient;
  15. using System.Collections.Generic;
  16. using System.Web;
  17. using System.Web.UI;
  18. using System.Web.UI.WebControls;
  19. using System.Text.RegularExpressions;
  20. using iNethinkCMS.Web.UI;
  21. using iNethinkCMS.Helper;
  22. namespace iNethinkCMS.Web
  23. {
  24. public partial class content : BasePage
  25. {
  26. protected void Page_Load(object sender, EventArgs e)
  27. {
  28. # region 页面传值分析
  29. string rID;
  30. int vID;
  31. rID = Request.QueryString["ID"];
  32. if (rID == null || rID.IndexOf(",", 0) > 0 || Command.Command_Validate.IsNumber(rID) == false)
  33. {
  34. Response.Write("<H3>内容ID错误!</H3>");
  35. Response.End();
  36. }
  37. vID = Convert.ToInt32(rID);
  38. string rPage;
  39. rPage = Request.QueryString["page"];
  40. int vPage = 1;
  41. if (rPage != string.Empty && rPage != null && Command.Command_Validate.IsNumber(rPage))
  42. {
  43. vPage = Convert.ToInt32(rPage);
  44. }
  45. #endregion
  46. #region 获取页面信息
  47. string vHtml = "";
  48. bool vWebPageCache = Command.Command_Configuration.GetConfigBool("WebPageCache"); //判断是否启用了页面缓存
  49. if (vWebPageCache == false)
  50. {
  51. vHtml = Fun_GetContent(vID, vPage);
  52. }
  53. else
  54. {
  55. int vCacheTime = Command.Command_Configuration.GetConfigInt("CacheTime");
  56. string contentCacheKey = Command.Command_Configuration.GetConfigString("CacheKey") + "_ContentCache_" + vID;
  57. object contentCacheInfo = Command.Command_DataCache.GetCache(contentCacheKey);
  58. //判断缓存是否存在
  59. if (contentCacheInfo == null)
  60. {
  61. vHtml = Fun_GetContent(vID, vPage);
  62. Command.Command_DataCache.SetCache(contentCacheKey, (object)vHtml, DateTime.Now.AddSeconds(vCacheTime), TimeSpan.Zero);
  63. }
  64. else
  65. {
  66. vHtml = contentCacheInfo.ToString();
  67. }
  68. }
  69. vHtml = WebUI_Function.Fun_UrlRewriter(vHtml);
  70. Response.Write(vHtml);
  71. #endregion
  72. }
  73. private string Fun_GetContent(int byID, int byPage)
  74. {
  75. //获取当前内容信息
  76. BLL.BLL_iNethinkCMS_Content bll = new BLL.BLL_iNethinkCMS_Content();
  77. Model.Model_iNethinkCMS_Content model = new Model.Model_iNethinkCMS_Content();
  78. //获取当前栏目信息
  79. BLL.BLL_iNethinkCMS_Channel bll_channel = new BLL.BLL_iNethinkCMS_Channel();
  80. Model.Model_iNethinkCMS_Channel model_channel = new Model.Model_iNethinkCMS_Channel();
  81. model = bll.GetModel(byID);
  82. if (model == null)
  83. {
  84. Response.Write("<H3>不存在该内容信息!</H3>");
  85. Response.End();
  86. }
  87. int vCID = Convert.ToInt32(model.Cid); //栏目ID
  88. int vSID = Convert.ToInt32(model.Sid); //专题ID
  89. model_channel = bll_channel.GetModel(vCID);
  90. if (model_channel == null)
  91. {
  92. Response.Write("<H3>不存在相应的栏目信息!</H3>");
  93. Response.End();
  94. }
  95. //当该页面启用了跳转时,则跳转!
  96. if (model.Jumpurl != null && model.Jumpurl.Length > 0)
  97. {
  98. //Response.Redirect(model.Jumpurl);
  99. Response.Clear();
  100. Response.Status = "301 Moved Permanently";
  101. Response.AddHeader("Location", model.Jumpurl);
  102. Response.End();
  103. }
  104. string vTemplateUrl = ""; //对应的模板
  105. vTemplateUrl = model_channel.Templateview;
  106. DataTable dt = bll.GetList("[ID] = " + byID).Tables[0];
  107. DataRow dr = dt.Rows[0];
  108. WebUI_Template wt = new WebUI_Template();
  109. wt.Load_Template(vTemplateUrl);
  110. wt.vPage = byPage;
  111. wt.vCID = vCID;
  112. wt.vSID = vSID;
  113. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:title}"), siteConfig.WebName, RegexOptions.IgnoreCase);
  114. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:seotitle}"), seoConfig.SeoTitle, RegexOptions.IgnoreCase);
  115. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:keywords}"), seoConfig.IndexKeywords, RegexOptions.IgnoreCase);
  116. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:description}"), seoConfig.IndexDescription, RegexOptions.IgnoreCase);
  117. string sitepath = $@"<ol class=""breadcrumb"">{WebUI_Function.Fun_GetSitePath(vCID,"",false)}<li>正文</li></ol>";
  118. wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:sitepath}"), sitepath, RegexOptions.IgnoreCase);
  119. //替换专用标签
  120. Regex regex = new Regex(@"{Tag:([\s\S]*?)}", RegexOptions.IgnoreCase);
  121. MatchCollection matchCollection = regex.Matches(wt.vContent);
  122. foreach (Match m in matchCollection)
  123. {
  124. string vContentTmp = "";
  125. string vValueKey = m.Groups[1].Value;
  126. switch (vValueKey.ToLower())
  127. {
  128. case "prev": //上一篇
  129. vContentTmp = Get_Page_PrevNext(byID, vCID, "prev");
  130. break;
  131. case "next": //下一篇
  132. vContentTmp = Get_Page_PrevNext(byID, vCID, "next");
  133. break;
  134. }
  135. wt.vContent = wt.vContent.Replace(m.Value, vContentTmp);
  136. }
  137. //wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{field:contents}"), dr["Contents"].ToString(), RegexOptions.IgnoreCase);
  138. wt.vContent = wt.Parser_Tags(0, @"\{field:(.+?)\}", wt.vContent, dr); //数据信息替换
  139. wt.Parser_MyTag();
  140. wt.Parser_List();
  141. wt.Parser_Page();
  142. wt.Parser_IF();
  143. return wt.vContent;
  144. }
  145. //获取新闻信息的上一篇,下一篇
  146. private string Get_Page_PrevNext(int byID, int byCID, string byFlag)
  147. {
  148. string vBaseUrl = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
  149. string vBackInfo = "";
  150. string vWhere = "";
  151. string vOrder = "";
  152. switch (byFlag)
  153. {
  154. case "prev": //上一篇
  155. vWhere = "[id] > " + byID + "";
  156. vOrder = "[id] Asc";
  157. break;
  158. case "next": //下一篇
  159. vWhere = "[id] < " + byID + "";
  160. vOrder = "[id] Desc";
  161. break;
  162. }
  163. BLL.BLL_iNethinkCMS_Content bll = new BLL.BLL_iNethinkCMS_Content();
  164. DataTable dt = bll.GetList(1, vWhere + " and Display=1 and IsComment=1 ", vOrder).Tables[0];
  165. for (int i = 0; i < dt.Rows.Count; i++)
  166. {
  167. vBaseUrl += "?id=" + dt.Rows[i]["ID"].ToString();
  168. vBackInfo = "<a href=" + vBaseUrl + ">" + dt.Rows[i]["Title"].ToString() + "</a>";
  169. }
  170. return vBackInfo;
  171. }
  172. }
  173. }