WebUI_Template.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /*******************************************************************************@version 1.3.6.0 (2013-08-14)
  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.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Data;
  17. namespace iNethinkCMS.Web.UI
  18. {
  19. public class WebUI_Template
  20. {
  21. iNethinkCMS.Model.Model_Config siteConfig = new iNethinkCMS.BLL.BLL_Config().GetModel_SysConfig();
  22. private static string _UserCenterPath = "UserCenter/";
  23. /// <summary>
  24. /// 用户中心模板路径
  25. /// </summary>
  26. public static string UserCenterPath
  27. {
  28. get { return WebUI_Template._UserCenterPath; }
  29. set { WebUI_Template._UserCenterPath = value; }
  30. }
  31. public string vContent = "";
  32. public string vTemplate = ""; //模板路径
  33. public int vCID = 0; //当前栏目ID
  34. public int vSID = 0; //专题ID
  35. public int vPage; //当前页码
  36. //载入模板
  37. public void Load_Template(string byTemplate)
  38. {
  39. vTemplate = System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + byTemplate);
  40. string vTemplateBak=System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + _UserCenterPath+byTemplate);
  41. if (!System.IO.File.Exists(vTemplate) && System.IO.File.Exists(vTemplateBak))
  42. {
  43. vTemplate = vTemplateBak;
  44. }
  45. bool vTemplateCache = Command.Command_Configuration.GetConfigBool("TemplateCache"); //判断是否启用了模板缓存
  46. if (vTemplateCache == false)
  47. {
  48. Load_Template_File(); //读取模板信息
  49. }
  50. else
  51. {
  52. //模板缓存
  53. string templateCacheKey = Command.Command_Configuration.GetConfigString("CacheKey") + "_TemplateCache_" + byTemplate;
  54. object templateCacheInfo = Command.Command_DataCache.GetCache(templateCacheKey);
  55. if (templateCacheInfo == null)
  56. {
  57. Load_Template_File(); //读取模板信息
  58. Command.Command_DataCache.SetCache(templateCacheKey, (object)vContent);
  59. }
  60. else
  61. {
  62. vContent = templateCacheInfo.ToString();
  63. }
  64. }
  65. }
  66. //读取模板文件
  67. public void Load_Template_File()
  68. {
  69. string SysLoginUserTrueName = "匿名";
  70. try
  71. {
  72. bool isOk = true;
  73. if (vTemplate.ToLower().Contains(System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + _UserCenterPath).ToLower()))
  74. {
  75. string SysLoginUserName = iNethinkCMS.Command.Command_Session.Get("admin_username");
  76. SysLoginUserTrueName = iNethinkCMS.Command.Command_Session.Get("admin_usertruename");
  77. if (String.IsNullOrEmpty(SysLoginUserName))
  78. {
  79. isOk = false;
  80. }
  81. }
  82. if (isOk)
  83. {
  84. System.IO.StreamReader sr = new System.IO.StreamReader(vTemplate, System.Text.Encoding.UTF8);
  85. vContent = sr.ReadToEnd();
  86. sr.Close();
  87. }
  88. else {
  89. vContent = "<font color='#ff0000'>对不起,当前内容需要登录后才能查看。</font>";
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. vContent = "<font color='#ff0000'>" + ex.Message + "</font>";
  95. }
  96. //分析内容中是否含有嵌套模板
  97. Regex regex = new Regex(@"\{template:(.+?)\}", RegexOptions.IgnoreCase);
  98. MatchCollection matchCollection = regex.Matches(vContent);
  99. foreach (Match m in matchCollection)
  100. {
  101. string vNestTemplate = m.Groups[1].Value;
  102. vNestTemplate = System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + vNestTemplate);
  103. vContent = vContent.Replace(m.Value, Load_Template_NestFile(vNestTemplate));
  104. }
  105. int SysLoginUserID = 0;
  106. string vSecuritycode="0";
  107. string vXmlPath = System.Web.HttpContext.Current.Server.MapPath("/plugs/comment/setting.xml");
  108. try
  109. {
  110. if (iNethinkCMS.Command.Command_Session.Get("admin_loginuserid") != null)
  111. {
  112. SysLoginUserID = Convert.ToInt32(iNethinkCMS.Command.Command_Session.Get("admin_loginuserid"));
  113. }
  114. if (System.IO.File.Exists(vXmlPath))
  115. {
  116. vSecuritycode = iNethinkCMS.Helper.XMLHelper.GetXmlAttribute(vXmlPath, "//plugs//config//key[@name=\"securitycode\"]", "value").Value.Trim();
  117. }
  118. }
  119. catch { }
  120. if (SysLoginUserTrueName == null) {
  121. SysLoginUserTrueName = "匿名";
  122. }
  123. vContent = Regex.Replace(vContent, Regex.Escape("{sys:loginuserid}"), SysLoginUserID.ToString(), RegexOptions.IgnoreCase);
  124. vContent = Regex.Replace(vContent, Regex.Escape("{sys:loginusername}"), SysLoginUserTrueName, RegexOptions.IgnoreCase);
  125. vContent = Regex.Replace(vContent, Regex.Escape("{sys:securitycode}"), vSecuritycode, RegexOptions.IgnoreCase);
  126. }
  127. public static List<string> GetHtmlAttr(string html, string tag, string attr)
  128. {
  129. Regex re = new Regex("(<" + tag + "[\\w\\W].+?>)");
  130. MatchCollection imgreg = re.Matches(html);
  131. List<string> m_Attributes = new List<string>();
  132. try
  133. {
  134. Regex attrReg = new Regex("([a-zA-Z1-9_-]+)\\s*=\\s*(\\x27|\\x22)([^\\x27\\x22]*)(\\x27|\\x22)", RegexOptions.IgnoreCase);
  135. for (int i = 0; i < imgreg.Count; i++)
  136. {
  137. MatchCollection matchs = attrReg.Matches(imgreg[i].ToString());
  138. for (int j = 0; j < matchs.Count; j++)
  139. {
  140. GroupCollection groups = matchs[j].Groups;
  141. if (attr.ToUpper() == groups[1].Value.ToUpper())
  142. {
  143. m_Attributes.Add(groups[3].Value);
  144. break;
  145. }
  146. }
  147. }
  148. }
  149. catch { }
  150. return m_Attributes;
  151. }
  152. public void GetHtmlTag_List()
  153. {
  154. Regex regex = new Regex("<!--(.+?):\\{(.+?)\\}-->([\\s\\S]*?)<!--\\1-->", RegexOptions.IgnoreCase);
  155. MatchCollection matchCollection = regex.Matches(this.vContent);
  156. foreach (Match i in matchCollection)
  157. {
  158. string vBackValue = "";
  159. string vTagLabs = i.Groups[1].Value;
  160. string vTagsstr = i.Groups[2].Value;
  161. string vLoopstr = i.Groups[3].Value;
  162. if (vTagLabs.ToLower() != "page" && vTagsstr.ToLower().IndexOf("$HtmlTag=".ToLower()) >= 0)
  163. {
  164. string vTag_HtmlTag = this.Fun_GetAttr(vTagsstr, "htmltag").Trim();
  165. try
  166. {
  167. DataTable dt = this.Fun_GetHtmlTagAttrTable(vTag_HtmlTag);
  168. for (int j = 0; j < dt.Rows.Count; j++)
  169. {
  170. vBackValue += this.Parser_Tags(j + 1, "\\[" + vTagLabs + ":(.+?)\\]", vLoopstr, dt.Rows[j]);
  171. }
  172. this.vContent = this.vContent.Replace(i.Value, vBackValue);
  173. if (this.Fun_RegExists("<!--(.+?):\\{(.+?)\\}-->([\\s\\S]*?)<!--\\1-->", this.vContent))
  174. {
  175. this.GetHtmlTag_List();
  176. }
  177. }
  178. catch
  179. {
  180. this.vContent = this.vContent.Replace(i.Value, "读取HtmlTag列表信息时,数据读取错误!" + vTag_HtmlTag);
  181. }
  182. }
  183. }
  184. }
  185. private DataTable Fun_GetHtmlTagAttrTable(string HtmlTagStr)
  186. {
  187. string _MyTag = HtmlTagStr.Split(new char[]
  188. {
  189. '&'
  190. })[0];
  191. string[] HtmlTagAttrList = HtmlTagStr.Split(new char[]
  192. {
  193. '&'
  194. })[1].Split(new char[]
  195. {
  196. ','
  197. });
  198. string Parser_MyTag_Content = this.Parser_MyTag(_MyTag);
  199. DataTable dt = new DataTable();
  200. DataColumn column = new DataColumn();
  201. column.DataType = Type.GetType("System.Int32");
  202. column.ColumnName = "id";
  203. column.AutoIncrement = true;
  204. column.AutoIncrementSeed = 1L;
  205. column.AutoIncrementStep = 1L;
  206. dt.Columns.Add(column);
  207. for (int i = 0; i < HtmlTagAttrList.Length; i++)
  208. {
  209. dt.Columns.Add(HtmlTagAttrList[i], typeof(string));
  210. }
  211. List<List<string>> HtmlTagColumns = new List<List<string>>();
  212. for (int i = 0; i < HtmlTagAttrList.Length; i++)
  213. {
  214. List<string> TagAttrList = GetHtmlAttr(Parser_MyTag_Content, HtmlTagAttrList[i].Split(new char[]
  215. {
  216. '_'
  217. })[0], HtmlTagAttrList[i].Split(new char[]
  218. {
  219. '_'
  220. })[1]);
  221. if (TagAttrList.Count > 0)
  222. {
  223. HtmlTagColumns.Add(TagAttrList);
  224. }
  225. }
  226. for (int i = 0; i < HtmlTagColumns[0].Count; i++)
  227. {
  228. DataRow row = dt.NewRow();
  229. for (int j = 0; j < HtmlTagColumns.Count; j++)
  230. {
  231. row[HtmlTagAttrList[j]] = HtmlTagColumns[j][i];
  232. }
  233. dt.Rows.Add(row);
  234. }
  235. return dt;
  236. }
  237. public string Parser_MyTag(string _MyTag)
  238. {
  239. BLL.BLL_iNethinkCMS_Custom_Tags bll_tags = new BLL.BLL_iNethinkCMS_Custom_Tags();
  240. DataTable dt = bll_tags.GetAllList().Tables[0];
  241. string tempStr = "";
  242. string vValueKey = _MyTag.Split(new char[]
  243. {
  244. ':'
  245. })[1];
  246. for (int i = 0; i < dt.Rows.Count; i++)
  247. {
  248. if (dt.Rows[i]["Name"].ToString().ToLower() == vValueKey.ToLower())
  249. {
  250. tempStr = dt.Rows[i]["Code"].ToString();
  251. break;
  252. }
  253. }
  254. return tempStr;
  255. }
  256. //读取模板内容并返回
  257. public string Load_Template_NestFile(string byNestTemplate)
  258. {
  259. string vNestFile = "";
  260. try
  261. {
  262. System.IO.StreamReader sr = new System.IO.StreamReader(byNestTemplate, System.Text.Encoding.UTF8);
  263. vNestFile = sr.ReadToEnd();
  264. sr.Close();
  265. }
  266. catch (Exception ex)
  267. {
  268. vNestFile = "<font color='#ff0000'>" + ex.Message + "</font>";
  269. }
  270. return vNestFile;
  271. }
  272. //读取自定义标签
  273. public void Parser_MyTag()
  274. {
  275. //读出所有标签的信息
  276. BLL.BLL_iNethinkCMS_Custom_Tags bll_tags = new BLL.BLL_iNethinkCMS_Custom_Tags();
  277. DataTable dt = bll_tags.GetAllList().Tables[0];
  278. Regex regex = new Regex(@"{MyTag:([\s\S]*?)}", RegexOptions.IgnoreCase);
  279. MatchCollection matchCollection = regex.Matches(vContent);
  280. foreach (Match m in matchCollection)
  281. {
  282. string vValueKey = m.Groups[1].Value;
  283. // vContent = vContent.Replace(m.Value, vValueKey);
  284. for (int i = 0; i < dt.Rows.Count; i++)
  285. {
  286. if (dt.Rows[i]["Name"].ToString().ToLower() == vValueKey.ToLower())
  287. {
  288. vContent = vContent.Replace(m.Value, dt.Rows[i]["Code"].ToString());
  289. }
  290. }
  291. }
  292. this.GetHtmlTag_List();
  293. }
  294. //读取列表信息
  295. public void Parser_List()
  296. {
  297. Regex regex = new Regex(@"<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->", RegexOptions.IgnoreCase);
  298. MatchCollection matchCollection = regex.Matches(vContent);
  299. foreach (Match m in matchCollection)
  300. {
  301. string vBackValue = "";
  302. string vTagLabs = m.Groups[1].Value; //标签名称
  303. string vTagsstr = m.Groups[2].Value; //属性信息
  304. string vLoopstr = m.Groups[3].Value; //innerText
  305. if (vTagLabs.ToLower() != "page")
  306. {
  307. //int vTag_Row = Convert.ToInt32(GetAttr(vTagsstr, "row")); //列数量
  308. string vTag_SQL = Fun_GetAttr(vTagsstr, "sql").Trim(); //单独SQL查询
  309. //vContent = vContent.Replace(m.Value, vTag_SQL);
  310. //读取DataList
  311. DataSet ds = Helper.SQLHelper.Query(vTag_SQL);
  312. DataTable dt = ds.Tables[0];
  313. for (int i = 0; i < dt.Rows.Count; i++)
  314. {
  315. vBackValue = vBackValue + Parser_Tags(i + 1, @"\[" + vTagLabs + @":(.+?)\]", vLoopstr, dt.Rows[i]);
  316. }
  317. vContent = vContent.Replace(m.Value, vBackValue);
  318. //循环调用
  319. if (Fun_RegExists(@"<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->", vContent) == true)
  320. {
  321. Parser_List();
  322. }
  323. }
  324. }
  325. }
  326. //读取分页信息
  327. public void Parser_Page()
  328. {
  329. Regex regex = new Regex(@"<!--Page:\{(.+?)\}-->([\s\S]*?)<!--Page-->", RegexOptions.IgnoreCase);
  330. MatchCollection matchCollection = regex.Matches(vContent);
  331. foreach (Match m in matchCollection)
  332. {
  333. string vBackValue = "";
  334. string vTagsstr = m.Groups[1].Value; //属性信息
  335. string vLoopstr = m.Groups[2].Value; //innerText
  336. string vTag_Table = Fun_GetAttr(vTagsstr, "sqltable").Trim();
  337. string vTag_Select = Fun_GetAttr(vTagsstr, "sqlselect").Trim();
  338. string vTag_Where = Fun_GetAttr(vTagsstr, "sqlwhere").Trim();
  339. string vTag_Orderby = Fun_GetAttr(vTagsstr, "sqlorderby").Trim();
  340. int vTag_PageSize = 10;
  341. string vTag_PageSize_Tmp = Fun_GetAttr(vTagsstr, "pagesize").Trim();
  342. if (vTag_PageSize_Tmp != string.Empty && vTag_PageSize_Tmp != null && Command.Command_Validate.IsNumber(vTag_PageSize_Tmp))
  343. {
  344. vTag_PageSize = Convert.ToInt32(vTag_PageSize_Tmp);
  345. }
  346. int vStartIndex = ((vPage - 1) * vTag_PageSize) + 1;
  347. int vEndIndex = vPage * vTag_PageSize;
  348. DataSet ds = GetListByPage(vTag_Table, vTag_Select, vTag_Where, vTag_Orderby, vStartIndex, vEndIndex);
  349. DataTable dt = ds.Tables[0];
  350. for (int i = 0; i < dt.Rows.Count; i++)
  351. {
  352. vBackValue = vBackValue + Parser_Tags(vStartIndex + i, @"\[Page:(.+?)\]", vLoopstr, dt.Rows[i]);
  353. }
  354. vContent = vContent.Replace(m.Value, vBackValue);
  355. //分页显示
  356. int vPageCount; //总页数
  357. int vRecordCount; //总记录
  358. string vSql = "select Count([ID]) From " + vTag_Table + " Where 1 = 1 And " + vTag_Where;
  359. vRecordCount = Convert.ToInt32(Helper.SQLHelper.GetSingle(vSql));
  360. if (vRecordCount == 0)
  361. {
  362. vPageCount = 1;
  363. }
  364. else
  365. {
  366. vPageCount = (int)Math.Ceiling((double)vRecordCount / (double)vTag_PageSize);
  367. }
  368. string vPagingInfo = "";
  369. if (dt.Rows.Count > 0)
  370. {
  371. vPagingInfo = WebUI_PageList.GetPagingInfo_Web(vPageCount, vRecordCount, vPage, vTag_PageSize, vCID);
  372. }
  373. vContent = vContent.Replace("{tag:paging}", vPagingInfo);
  374. }
  375. }
  376. //If Else End If
  377. public void Parser_IF()
  378. {
  379. Regex regex = new Regex(@"{If:(.+?)}([\s\S]*?){End If}", RegexOptions.IgnoreCase);
  380. MatchCollection matchCollection = regex.Matches(vContent);
  381. foreach (Match m in matchCollection)
  382. {
  383. string rInfo = m.Value;
  384. string vTestInfo = m.Groups[2].Value;
  385. string vTestBase = Fun_GetAttr(m.Groups[1].Value, "testbase").Trim();
  386. string vTestValue = Fun_GetAttr(m.Groups[1].Value, "testvalue").Trim();
  387. string vTestMode = Fun_GetAttr(m.Groups[1].Value, "testmode").Trim();
  388. if (vTestBase == string.Empty || vTestValue == string.Empty || vTestMode == string.Empty)
  389. {
  390. rInfo = "<font color=red>判断语句相应条件错误,请参见模板手册进行修改!</font>";
  391. }
  392. else
  393. {
  394. #region
  395. //去掉取值的左右两侧引号
  396. if (Command.Command_StringPlus.Left(vTestBase, 1) == "\"")
  397. {
  398. vTestBase = Command.Command_StringPlus.Mid(vTestBase, 1, vTestBase.Length);
  399. }
  400. if (Command.Command_StringPlus.Right(vTestBase, 1) == "\"")
  401. {
  402. vTestBase = Command.Command_StringPlus.Mid(vTestBase, 0, vTestBase.Length - 1);
  403. }
  404. if (Command.Command_StringPlus.Left(vTestValue, 1) == "\"")
  405. {
  406. vTestValue = Command.Command_StringPlus.Mid(vTestValue, 1, vTestValue.Length);
  407. }
  408. if (Command.Command_StringPlus.Right(vTestValue, 1) == "\"")
  409. {
  410. vTestValue = Command.Command_StringPlus.Mid(vTestValue, 0, vTestValue.Length - 1);
  411. }
  412. string vTestTrue = "";
  413. string vTestFalse = "";
  414. if (vTestInfo.ToLower().IndexOf("{else}") > -1)
  415. {
  416. string[] sArray = Regex.Split(vTestInfo, "{else}", RegexOptions.IgnoreCase);
  417. vTestTrue = sArray[0];
  418. vTestFalse = sArray[1];
  419. //vTestTrue = vTestInfo.Split(new char[6] { '{', 'e', 'l', 's', 'e', '}' }, StringSplitOptions.RemoveEmptyEntries)[0];
  420. //vTestFalse = vTestInfo.Split(new char[6] { '{', 'e', 'l', 's', 'e', '}' }, StringSplitOptions.RemoveEmptyEntries)[1];
  421. }
  422. else
  423. {
  424. vTestTrue = vTestInfo;
  425. vTestFalse = "";
  426. }
  427. bool vTestBool = false;
  428. switch (vTestMode.ToLower())
  429. {
  430. case "empty": //值为空
  431. if (vTestBase == string.Empty)
  432. {
  433. vTestBool = true;
  434. }
  435. break;
  436. case "notempty": //值不为空
  437. if (vTestBase != string.Empty)
  438. {
  439. vTestBool = true;
  440. }
  441. break;
  442. case "equals": //值等于
  443. if (vTestBase == vTestValue)
  444. {
  445. vTestBool = true;
  446. }
  447. break;
  448. case "notequals": //值不等于
  449. if (vTestBase != vTestValue)
  450. {
  451. vTestBool = true;
  452. }
  453. break;
  454. case "in": //值属于
  455. vTestBase = "," + vTestBase + ",";
  456. if (vTestBase.IndexOf(vTestValue) >= 0)
  457. {
  458. vTestBool = true;
  459. }
  460. break;
  461. case "notin": //值不属于
  462. vTestBase = "," + vTestBase + ",";
  463. if (vTestBase.IndexOf(vTestValue) < 0)
  464. {
  465. vTestBool = true;
  466. }
  467. break;
  468. case "greatthan": //值大于(限整数符串)
  469. if (Command.Command_Validate.IsNumber(vTestBase) == false || Command.Command_Validate.IsNumber(vTestValue) == false)
  470. {
  471. vTestFalse = "<font color=red>基本值和测试值 必须是整数字符串!</font>";
  472. }
  473. else
  474. {
  475. if (Convert.ToInt32(vTestBase) > Convert.ToInt32(vTestValue))
  476. {
  477. vTestBool = true;
  478. }
  479. }
  480. break;
  481. case "lessthan": //值小于(限整数符串)
  482. if (Command.Command_Validate.IsNumber(vTestBase) == false || Command.Command_Validate.IsNumber(vTestValue) == false)
  483. {
  484. vTestFalse = "<font color=red>基本值和测试值 必须是整数字符串!</font>";
  485. }
  486. else
  487. {
  488. if (Convert.ToInt32(vTestBase) < Convert.ToInt32(vTestValue))
  489. {
  490. vTestBool = true;
  491. }
  492. }
  493. break;
  494. case "datediff": //日期比较
  495. if (Command.Command_Validate.IsDateTime(vTestBase) == false)
  496. {
  497. vTestFalse = "<font color=red>基本值 必须为日期!</font>";
  498. }
  499. else if (Command.Command_Validate.IsNumber(vTestValue) == false)
  500. {
  501. vTestFalse = "<font color=red>测试值 必须是整数字符串!</font>";
  502. }
  503. else
  504. {
  505. TimeSpan ts = Command.Command_StringPlus.DateDiff(Convert.ToDateTime(vTestBase), DateTime.Now);
  506. if (ts.Days < Convert.ToInt32(vTestValue))
  507. {
  508. vTestBool = true;
  509. }
  510. }
  511. break;
  512. }
  513. if (vTestBool == true)
  514. {
  515. rInfo = vTestTrue;
  516. }
  517. else
  518. {
  519. rInfo = vTestFalse;
  520. }
  521. #endregion
  522. }
  523. vContent = vContent.Replace(m.Value, rInfo);
  524. }
  525. }
  526. //替换列表中的字段信息
  527. public string Parser_Tags(int byI, string byPattern, string byLoopstr, DataRow byDR)
  528. {
  529. Regex regex = new Regex(byPattern, RegexOptions.IgnoreCase);
  530. MatchCollection matchCollection = regex.Matches(byLoopstr);
  531. foreach (Match m in matchCollection)
  532. {
  533. string vTagsstr = m.Groups[1].Value;
  534. //缩略图相关S
  535. string vTag_ThumbnailsMode = Fun_GetAttr(vTagsstr, "thumbmode").Trim();
  536. string vTag_ThumbnailsQuality = Fun_GetAttr(vTagsstr, "thumbquality").Trim();
  537. if (Command.Command_Validate.IsNumber(vTag_ThumbnailsQuality) == false)
  538. {
  539. vTag_ThumbnailsQuality = "100";
  540. }
  541. string vTag_ThumbnailsW = Fun_GetAttr(vTagsstr, "thumbw").Trim();
  542. string vTag_ThumbnailsH = Fun_GetAttr(vTagsstr, "thumbh").Trim();
  543. //缩略图相关E
  544. string vTag_Len = Fun_GetAttr(vTagsstr, "len").Trim();
  545. string vTag_Format = Fun_GetAttr(vTagsstr, "formatdate").Trim();
  546. string vTag_Replace = Fun_GetAttr(vTagsstr, "replace").Trim();
  547. string vTag_Function = Fun_GetAttr(vTagsstr, "function").Trim();
  548. string vTagsval = vTagsstr.Split(new Char[] { ' ' })[0];
  549. bool vTagTitle = false;
  550. switch (vTagsval.ToLower())
  551. {
  552. case "i": //i
  553. vTagsval = byI.ToString();
  554. break;
  555. case "titlex": //含有颜色属性的标题
  556. vTagsval = byDR["Title"].ToString();
  557. vTagTitle = true;
  558. break;
  559. case "creatorid_name":
  560. if (byDR["CreatorID"] != null && byDR["CreatorID"].ToString().Trim().Length > 0)
  561. {
  562. vTagsval = byDR["CreatorID"].ToString();
  563. vTagsval = iNethinkCMS.BLL.BLL_iNethinkCMS_User.GetIDToUserTrueName(Convert.ToInt32(vTagsval));
  564. }
  565. else {
  566. vTagsval = "系统管理员";
  567. }
  568. break;
  569. case "cname": //栏目名称
  570. iNethinkCMS.BLL.BLL_iNethinkCMS_Channel bll_column = new iNethinkCMS.BLL.BLL_iNethinkCMS_Channel();
  571. iNethinkCMS.Model.Model_iNethinkCMS_Channel model_column = new iNethinkCMS.Model.Model_iNethinkCMS_Channel();
  572. model_column = bll_column.GetModel(Convert.ToInt32(byDR["CID"]));
  573. if (model_column != null)
  574. {
  575. vTagsval = model_column.Name;
  576. }
  577. else
  578. {
  579. vTagsval = "-";
  580. }
  581. break;
  582. case "sname": //专题名称
  583. iNethinkCMS.BLL.BLL_iNethinkCMS_Special bll_special = new BLL.BLL_iNethinkCMS_Special();
  584. iNethinkCMS.Model.Model_iNethinkCMS_Special model_special = new iNethinkCMS.Model.Model_iNethinkCMS_Special();
  585. model_special = bll_special.GetModel(Convert.ToInt32(byDR["SID"]));
  586. if (model_special != null)
  587. {
  588. vTagsval = model_special.SpecialName;
  589. }
  590. else
  591. {
  592. vTagsval = "-";
  593. }
  594. break;
  595. default:
  596. if (Command.Command_StringPlus.Left(vTagsval, 9).ToLower() == "myfields_")
  597. {
  598. vTagsval = UI.WebUI_Function.Fun_GetFieldsInfo(vTagsval, byDR["FieldsInfo"].ToString());
  599. }
  600. else
  601. {
  602. try
  603. {
  604. vTagsval = byDR[vTagsval].ToString();
  605. }
  606. catch
  607. {
  608. vTagsval = m.Value;
  609. }
  610. }
  611. break;
  612. }
  613. //vTagsval = Command.Command_Validate.Decode(vTagsval);
  614. //replace
  615. if (vTag_Replace.Length > 0)
  616. {
  617. string[] sp = vTag_Replace.Split(new string[1] { "###" }, StringSplitOptions.None); //vTag_Replace.Split(new Char[3] { '#', '#', '#' });
  618. if (sp.Length == 2)
  619. {
  620. vTagsval = vTagsval.Replace(sp[0], sp[1]);
  621. }
  622. }
  623. //格式化日期
  624. if (vTag_Format.Length > 0)
  625. {
  626. if (Command.Command_Validate.IsDateTime(vTagsval))
  627. {
  628. DateTime vTagsval_DateTime = Convert.ToDateTime(vTagsval);
  629. vTagsval = vTagsval_DateTime.ToString(vTag_Format);
  630. }
  631. }
  632. //字符串截取
  633. if (vTag_Len.Length > 0)
  634. {
  635. vTagsval = Command.Command_StringPlus.Left(vTagsval, Convert.ToInt32(vTag_Len));
  636. }
  637. //函数操作
  638. if (vTag_Function.Length > 0)
  639. {
  640. string[] sp = vTag_Function.Split(new Char[] { ',' });
  641. for (int i = 0; i < sp.Length; i++)
  642. {
  643. switch (sp[i].ToLower())
  644. {
  645. case "urlencode":
  646. vTagsval = System.Web.HttpUtility.UrlEncode(vTagsval, Encoding.UTF8);
  647. break;
  648. case "urldecode":
  649. vTagsval = System.Web.HttpUtility.UrlDecode(vTagsval, Encoding.UTF8);
  650. break;
  651. case "htmlencode":
  652. vTagsval = System.Web.HttpUtility.HtmlEncode(vTagsval);
  653. break;
  654. case "htmldecode":
  655. vTagsval = System.Web.HttpUtility.HtmlDecode(vTagsval);
  656. break;
  657. case "trim":
  658. vTagsval = vTagsval.Trim();
  659. break;
  660. case "lower":
  661. vTagsval = vTagsval.ToLower();
  662. break;
  663. case "upper":
  664. vTagsval = vTagsval.ToUpper();
  665. break;
  666. case "clearhtml":
  667. vTagsval = Command.Command_StringPlus.LostHTML(vTagsval);
  668. break;
  669. }
  670. }
  671. }
  672. //缩略图操作
  673. if (vTag_ThumbnailsMode.Length > 0 && Command.Command_Validate.IsNumber(vTag_ThumbnailsW) && Command.Command_Validate.IsNumber(vTag_ThumbnailsH))
  674. {
  675. //如果原图存在
  676. if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(vTagsval)))
  677. {
  678. vTagsval = WebUI_Function.Fun_GetThumbnail(vTagsval, vTag_ThumbnailsW, vTag_ThumbnailsH, vTag_ThumbnailsMode, vTag_ThumbnailsQuality);
  679. }
  680. }
  681. //标题样式处理
  682. if (vTagTitle == true)
  683. {
  684. string vTitle_Color = byDR["Title_Color"].ToString();
  685. string vTitle_Style = byDR["Title_Style"].ToString();
  686. string vStlye = "";
  687. if (vTitle_Color.Length > 0)
  688. {
  689. vStlye = vTitle_Color;
  690. }
  691. if (vTitle_Style.Length > 0)
  692. {
  693. vStlye = vStlye + vTitle_Style;
  694. }
  695. if (vTitle_Color.Length > 0 || vTitle_Style.Length > 0)
  696. {
  697. vTagsval = "<font style='" + vStlye + "'>" + vTagsval + "</font>";
  698. }
  699. }
  700. byLoopstr = byLoopstr.Replace(m.Value, vTagsval);
  701. }
  702. return byLoopstr;
  703. }
  704. //获取指定标签属性的值
  705. public string Fun_GetAttr(string byTagsstr, string byAttrName)
  706. {
  707. string vBackGetAttr = "";
  708. //判断是否为空
  709. if (byTagsstr.ToLower().IndexOf("$" + byAttrName + "=") >= 0)
  710. {
  711. Regex regex = new Regex(@"\$" + byAttrName + @"=(.+?) \$", RegexOptions.IgnoreCase);
  712. MatchCollection matchCollection = regex.Matches(byTagsstr + " $");
  713. foreach (Match m in matchCollection)
  714. {
  715. vBackGetAttr = m.Groups[1].Value;
  716. }
  717. }
  718. return vBackGetAttr;
  719. }
  720. //是否存在此类标签
  721. public bool Fun_RegExists(string byPattern, string byContent)
  722. {
  723. return Regex.IsMatch(byContent, byPattern, RegexOptions.IgnoreCase);
  724. }
  725. /// <summary>
  726. /// 分页获取数据列表
  727. /// </summary>
  728. public DataSet GetListByPage(string strTable, string strSelect, string strWhere, string strOrderby, int startIndex, int endIndex)
  729. {
  730. if (string.IsNullOrEmpty(strSelect.Trim()))
  731. {
  732. strSelect = "*";
  733. }
  734. if (!string.IsNullOrEmpty(strWhere.Trim()))
  735. {
  736. strWhere = " Where " + strWhere;
  737. }
  738. if (!string.IsNullOrEmpty(strOrderby.Trim()))
  739. {
  740. strOrderby = " Order By " + strOrderby;
  741. }
  742. startIndex = startIndex - 1;
  743. StringBuilder strSql = new StringBuilder();
  744. strSql.Append("SELECT " + strSelect + " FROM " + strTable + " Where ID Not IN ");
  745. strSql.Append("(Select Top " + startIndex + " ID From " + strTable + strWhere + strOrderby + ")");
  746. strSql.Append(" And ID In ");
  747. strSql.Append("(Select Top " + endIndex + " ID From " + strTable + strWhere + strOrderby + ")");
  748. strSql.Append(strOrderby);
  749. return Helper.SQLHelper.Query(strSql.ToString());
  750. }
  751. }
  752. }