123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- /*******************************************************************************@version 1.3.6.0 (2013-08-14)
- * iNethinkCMS - 网站内容管理系统
- * Copyright (C) 2012-2013 inethink.com
- *
- * @author jackyang <69991000@qq.com>
- * @website http://cms.inethink.com
- * @version 1.3.6.0 (2013-08-14)
- *
- * This is licensed under the GNU LGPL, version 3.0 or later.
- * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Data;
- namespace iNethinkCMS.Web.UI
- {
- public class WebUI_Template
- {
- iNethinkCMS.Model.Model_Config siteConfig = new iNethinkCMS.BLL.BLL_Config().GetModel_SysConfig();
- private static string _UserCenterPath = "UserCenter/";
- /// <summary>
- /// 用户中心模板路径
- /// </summary>
- public static string UserCenterPath
- {
- get { return WebUI_Template._UserCenterPath; }
- set { WebUI_Template._UserCenterPath = value; }
- }
- public string vContent = "";
- public string vTemplate = ""; //模板路径
- public int vCID = 0; //当前栏目ID
- public int vSID = 0; //专题ID
- public int vPage; //当前页码
- //载入模板
- public void Load_Template(string byTemplate)
- {
- vTemplate = System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + byTemplate);
- string vTemplateBak=System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + _UserCenterPath+byTemplate);
- if (!System.IO.File.Exists(vTemplate) && System.IO.File.Exists(vTemplateBak))
- {
- vTemplate = vTemplateBak;
- }
- bool vTemplateCache = Command.Command_Configuration.GetConfigBool("TemplateCache"); //判断是否启用了模板缓存
- if (vTemplateCache == false)
- {
- Load_Template_File(); //读取模板信息
- }
- else
- {
- //模板缓存
- string templateCacheKey = Command.Command_Configuration.GetConfigString("CacheKey") + "_TemplateCache_" + byTemplate;
- object templateCacheInfo = Command.Command_DataCache.GetCache(templateCacheKey);
- if (templateCacheInfo == null)
- {
- Load_Template_File(); //读取模板信息
- Command.Command_DataCache.SetCache(templateCacheKey, (object)vContent);
- }
- else
- {
- vContent = templateCacheInfo.ToString();
- }
- }
- }
- //读取模板文件
- public void Load_Template_File()
- {
- string SysLoginUserTrueName = "匿名";
- try
- {
- bool isOk = true;
- if (vTemplate.ToLower().Contains(System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + _UserCenterPath).ToLower()))
- {
- string SysLoginUserName = iNethinkCMS.Command.Command_Session.Get("admin_username");
- SysLoginUserTrueName = iNethinkCMS.Command.Command_Session.Get("admin_usertruename");
- if (String.IsNullOrEmpty(SysLoginUserName))
- {
- isOk = false;
- }
-
- }
-
- if (isOk)
- {
- System.IO.StreamReader sr = new System.IO.StreamReader(vTemplate, System.Text.Encoding.UTF8);
- vContent = sr.ReadToEnd();
- sr.Close();
- }
- else {
- vContent = "<font color='#ff0000'>对不起,当前内容需要登录后才能查看。</font>";
- }
- }
- catch (Exception ex)
- {
- vContent = "<font color='#ff0000'>" + ex.Message + "</font>";
- }
- //分析内容中是否含有嵌套模板
- Regex regex = new Regex(@"\{template:(.+?)\}", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(vContent);
- foreach (Match m in matchCollection)
- {
- string vNestTemplate = m.Groups[1].Value;
- vNestTemplate = System.Web.HttpContext.Current.Server.MapPath(siteConfig.TemplateDir + vNestTemplate);
- vContent = vContent.Replace(m.Value, Load_Template_NestFile(vNestTemplate));
- }
- int SysLoginUserID = 0;
- string vSecuritycode="0";
- string vXmlPath = System.Web.HttpContext.Current.Server.MapPath("/plugs/comment/setting.xml");
- try
- {
-
- if (iNethinkCMS.Command.Command_Session.Get("admin_loginuserid") != null)
- {
- SysLoginUserID = Convert.ToInt32(iNethinkCMS.Command.Command_Session.Get("admin_loginuserid"));
- }
- if (System.IO.File.Exists(vXmlPath))
- {
- vSecuritycode = iNethinkCMS.Helper.XMLHelper.GetXmlAttribute(vXmlPath, "//plugs//config//key[@name=\"securitycode\"]", "value").Value.Trim();
- }
- }
- catch { }
- if (SysLoginUserTrueName == null) {
- SysLoginUserTrueName = "匿名";
- }
- vContent = Regex.Replace(vContent, Regex.Escape("{sys:loginuserid}"), SysLoginUserID.ToString(), RegexOptions.IgnoreCase);
- vContent = Regex.Replace(vContent, Regex.Escape("{sys:loginusername}"), SysLoginUserTrueName, RegexOptions.IgnoreCase);
- vContent = Regex.Replace(vContent, Regex.Escape("{sys:securitycode}"), vSecuritycode, RegexOptions.IgnoreCase);
- }
- public static List<string> GetHtmlAttr(string html, string tag, string attr)
- {
- Regex re = new Regex("(<" + tag + "[\\w\\W].+?>)");
- MatchCollection imgreg = re.Matches(html);
- List<string> m_Attributes = new List<string>();
- try
- {
- Regex attrReg = new Regex("([a-zA-Z1-9_-]+)\\s*=\\s*(\\x27|\\x22)([^\\x27\\x22]*)(\\x27|\\x22)", RegexOptions.IgnoreCase);
- for (int i = 0; i < imgreg.Count; i++)
- {
- MatchCollection matchs = attrReg.Matches(imgreg[i].ToString());
- for (int j = 0; j < matchs.Count; j++)
- {
- GroupCollection groups = matchs[j].Groups;
- if (attr.ToUpper() == groups[1].Value.ToUpper())
- {
- m_Attributes.Add(groups[3].Value);
- break;
- }
- }
- }
- }
- catch { }
- return m_Attributes;
- }
- public void GetHtmlTag_List()
- {
- Regex regex = new Regex("<!--(.+?):\\{(.+?)\\}-->([\\s\\S]*?)<!--\\1-->", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(this.vContent);
- foreach (Match i in matchCollection)
- {
- string vBackValue = "";
- string vTagLabs = i.Groups[1].Value;
- string vTagsstr = i.Groups[2].Value;
- string vLoopstr = i.Groups[3].Value;
- if (vTagLabs.ToLower() != "page" && vTagsstr.ToLower().IndexOf("$HtmlTag=".ToLower()) >= 0)
- {
- string vTag_HtmlTag = this.Fun_GetAttr(vTagsstr, "htmltag").Trim();
- try
- {
- DataTable dt = this.Fun_GetHtmlTagAttrTable(vTag_HtmlTag);
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- vBackValue += this.Parser_Tags(j + 1, "\\[" + vTagLabs + ":(.+?)\\]", vLoopstr, dt.Rows[j]);
- }
- this.vContent = this.vContent.Replace(i.Value, vBackValue);
- if (this.Fun_RegExists("<!--(.+?):\\{(.+?)\\}-->([\\s\\S]*?)<!--\\1-->", this.vContent))
- {
- this.GetHtmlTag_List();
- }
- }
- catch
- {
- this.vContent = this.vContent.Replace(i.Value, "读取HtmlTag列表信息时,数据读取错误!" + vTag_HtmlTag);
- }
- }
- }
- }
- private DataTable Fun_GetHtmlTagAttrTable(string HtmlTagStr)
- {
- string _MyTag = HtmlTagStr.Split(new char[]
- {
- '&'
- })[0];
- string[] HtmlTagAttrList = HtmlTagStr.Split(new char[]
- {
- '&'
- })[1].Split(new char[]
- {
- ','
- });
- string Parser_MyTag_Content = this.Parser_MyTag(_MyTag);
- DataTable dt = new DataTable();
- DataColumn column = new DataColumn();
- column.DataType = Type.GetType("System.Int32");
- column.ColumnName = "id";
- column.AutoIncrement = true;
- column.AutoIncrementSeed = 1L;
- column.AutoIncrementStep = 1L;
- dt.Columns.Add(column);
- for (int i = 0; i < HtmlTagAttrList.Length; i++)
- {
- dt.Columns.Add(HtmlTagAttrList[i], typeof(string));
- }
- List<List<string>> HtmlTagColumns = new List<List<string>>();
- for (int i = 0; i < HtmlTagAttrList.Length; i++)
- {
- List<string> TagAttrList = GetHtmlAttr(Parser_MyTag_Content, HtmlTagAttrList[i].Split(new char[]
- {
- '_'
- })[0], HtmlTagAttrList[i].Split(new char[]
- {
- '_'
- })[1]);
- if (TagAttrList.Count > 0)
- {
- HtmlTagColumns.Add(TagAttrList);
- }
- }
- for (int i = 0; i < HtmlTagColumns[0].Count; i++)
- {
- DataRow row = dt.NewRow();
- for (int j = 0; j < HtmlTagColumns.Count; j++)
- {
- row[HtmlTagAttrList[j]] = HtmlTagColumns[j][i];
- }
- dt.Rows.Add(row);
- }
- return dt;
- }
- public string Parser_MyTag(string _MyTag)
- {
- BLL.BLL_iNethinkCMS_Custom_Tags bll_tags = new BLL.BLL_iNethinkCMS_Custom_Tags();
- DataTable dt = bll_tags.GetAllList().Tables[0];
- string tempStr = "";
- string vValueKey = _MyTag.Split(new char[]
- {
- ':'
- })[1];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["Name"].ToString().ToLower() == vValueKey.ToLower())
- {
- tempStr = dt.Rows[i]["Code"].ToString();
- break;
- }
- }
- return tempStr;
- }
- //读取模板内容并返回
- public string Load_Template_NestFile(string byNestTemplate)
- {
- string vNestFile = "";
- try
- {
- System.IO.StreamReader sr = new System.IO.StreamReader(byNestTemplate, System.Text.Encoding.UTF8);
- vNestFile = sr.ReadToEnd();
- sr.Close();
- }
- catch (Exception ex)
- {
- vNestFile = "<font color='#ff0000'>" + ex.Message + "</font>";
- }
- return vNestFile;
- }
- //读取自定义标签
- public void Parser_MyTag()
- {
- //读出所有标签的信息
- BLL.BLL_iNethinkCMS_Custom_Tags bll_tags = new BLL.BLL_iNethinkCMS_Custom_Tags();
- DataTable dt = bll_tags.GetAllList().Tables[0];
- Regex regex = new Regex(@"{MyTag:([\s\S]*?)}", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(vContent);
- foreach (Match m in matchCollection)
- {
- string vValueKey = m.Groups[1].Value;
- // vContent = vContent.Replace(m.Value, vValueKey);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["Name"].ToString().ToLower() == vValueKey.ToLower())
- {
- vContent = vContent.Replace(m.Value, dt.Rows[i]["Code"].ToString());
- }
- }
- }
- this.GetHtmlTag_List();
- }
- //读取列表信息
- public void Parser_List()
- {
- Regex regex = new Regex(@"<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(vContent);
- foreach (Match m in matchCollection)
- {
- string vBackValue = "";
- string vTagLabs = m.Groups[1].Value; //标签名称
- string vTagsstr = m.Groups[2].Value; //属性信息
- string vLoopstr = m.Groups[3].Value; //innerText
- if (vTagLabs.ToLower() != "page")
- {
- //int vTag_Row = Convert.ToInt32(GetAttr(vTagsstr, "row")); //列数量
- string vTag_SQL = Fun_GetAttr(vTagsstr, "sql").Trim(); //单独SQL查询
- //vContent = vContent.Replace(m.Value, vTag_SQL);
- //读取DataList
- DataSet ds = Helper.SQLHelper.Query(vTag_SQL);
- DataTable dt = ds.Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- vBackValue = vBackValue + Parser_Tags(i + 1, @"\[" + vTagLabs + @":(.+?)\]", vLoopstr, dt.Rows[i]);
- }
- vContent = vContent.Replace(m.Value, vBackValue);
- //循环调用
- if (Fun_RegExists(@"<!--(.+?):\{(.+?)\}-->([\s\S]*?)<!--\1-->", vContent) == true)
- {
- Parser_List();
- }
- }
- }
- }
- //读取分页信息
- public void Parser_Page()
- {
- Regex regex = new Regex(@"<!--Page:\{(.+?)\}-->([\s\S]*?)<!--Page-->", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(vContent);
- foreach (Match m in matchCollection)
- {
- string vBackValue = "";
- string vTagsstr = m.Groups[1].Value; //属性信息
- string vLoopstr = m.Groups[2].Value; //innerText
- string vTag_Table = Fun_GetAttr(vTagsstr, "sqltable").Trim();
- string vTag_Select = Fun_GetAttr(vTagsstr, "sqlselect").Trim();
- string vTag_Where = Fun_GetAttr(vTagsstr, "sqlwhere").Trim();
- string vTag_Orderby = Fun_GetAttr(vTagsstr, "sqlorderby").Trim();
- int vTag_PageSize = 10;
- string vTag_PageSize_Tmp = Fun_GetAttr(vTagsstr, "pagesize").Trim();
- if (vTag_PageSize_Tmp != string.Empty && vTag_PageSize_Tmp != null && Command.Command_Validate.IsNumber(vTag_PageSize_Tmp))
- {
- vTag_PageSize = Convert.ToInt32(vTag_PageSize_Tmp);
- }
- int vStartIndex = ((vPage - 1) * vTag_PageSize) + 1;
- int vEndIndex = vPage * vTag_PageSize;
- DataSet ds = GetListByPage(vTag_Table, vTag_Select, vTag_Where, vTag_Orderby, vStartIndex, vEndIndex);
- DataTable dt = ds.Tables[0];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- vBackValue = vBackValue + Parser_Tags(vStartIndex + i, @"\[Page:(.+?)\]", vLoopstr, dt.Rows[i]);
- }
- vContent = vContent.Replace(m.Value, vBackValue);
- //分页显示
- int vPageCount; //总页数
- int vRecordCount; //总记录
- string vSql = "select Count([ID]) From " + vTag_Table + " Where 1 = 1 And " + vTag_Where;
- vRecordCount = Convert.ToInt32(Helper.SQLHelper.GetSingle(vSql));
- if (vRecordCount == 0)
- {
- vPageCount = 1;
- }
- else
- {
- vPageCount = (int)Math.Ceiling((double)vRecordCount / (double)vTag_PageSize);
- }
- string vPagingInfo = "";
- if (dt.Rows.Count > 0)
- {
- vPagingInfo = WebUI_PageList.GetPagingInfo_Web(vPageCount, vRecordCount, vPage, vTag_PageSize, vCID);
- }
- vContent = vContent.Replace("{tag:paging}", vPagingInfo);
- }
- }
- //If Else End If
- public void Parser_IF()
- {
- Regex regex = new Regex(@"{If:(.+?)}([\s\S]*?){End If}", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(vContent);
- foreach (Match m in matchCollection)
- {
- string rInfo = m.Value;
- string vTestInfo = m.Groups[2].Value;
- string vTestBase = Fun_GetAttr(m.Groups[1].Value, "testbase").Trim();
- string vTestValue = Fun_GetAttr(m.Groups[1].Value, "testvalue").Trim();
- string vTestMode = Fun_GetAttr(m.Groups[1].Value, "testmode").Trim();
- if (vTestBase == string.Empty || vTestValue == string.Empty || vTestMode == string.Empty)
- {
- rInfo = "<font color=red>判断语句相应条件错误,请参见模板手册进行修改!</font>";
- }
- else
- {
- #region
- //去掉取值的左右两侧引号
- if (Command.Command_StringPlus.Left(vTestBase, 1) == "\"")
- {
- vTestBase = Command.Command_StringPlus.Mid(vTestBase, 1, vTestBase.Length);
- }
- if (Command.Command_StringPlus.Right(vTestBase, 1) == "\"")
- {
- vTestBase = Command.Command_StringPlus.Mid(vTestBase, 0, vTestBase.Length - 1);
- }
- if (Command.Command_StringPlus.Left(vTestValue, 1) == "\"")
- {
- vTestValue = Command.Command_StringPlus.Mid(vTestValue, 1, vTestValue.Length);
- }
- if (Command.Command_StringPlus.Right(vTestValue, 1) == "\"")
- {
- vTestValue = Command.Command_StringPlus.Mid(vTestValue, 0, vTestValue.Length - 1);
- }
- string vTestTrue = "";
- string vTestFalse = "";
- if (vTestInfo.ToLower().IndexOf("{else}") > -1)
- {
- string[] sArray = Regex.Split(vTestInfo, "{else}", RegexOptions.IgnoreCase);
- vTestTrue = sArray[0];
- vTestFalse = sArray[1];
- //vTestTrue = vTestInfo.Split(new char[6] { '{', 'e', 'l', 's', 'e', '}' }, StringSplitOptions.RemoveEmptyEntries)[0];
- //vTestFalse = vTestInfo.Split(new char[6] { '{', 'e', 'l', 's', 'e', '}' }, StringSplitOptions.RemoveEmptyEntries)[1];
- }
- else
- {
- vTestTrue = vTestInfo;
- vTestFalse = "";
- }
- bool vTestBool = false;
- switch (vTestMode.ToLower())
- {
- case "empty": //值为空
- if (vTestBase == string.Empty)
- {
- vTestBool = true;
- }
- break;
- case "notempty": //值不为空
- if (vTestBase != string.Empty)
- {
- vTestBool = true;
- }
- break;
- case "equals": //值等于
- if (vTestBase == vTestValue)
- {
- vTestBool = true;
- }
- break;
- case "notequals": //值不等于
- if (vTestBase != vTestValue)
- {
- vTestBool = true;
- }
- break;
- case "in": //值属于
- vTestBase = "," + vTestBase + ",";
- if (vTestBase.IndexOf(vTestValue) >= 0)
- {
- vTestBool = true;
- }
- break;
- case "notin": //值不属于
- vTestBase = "," + vTestBase + ",";
- if (vTestBase.IndexOf(vTestValue) < 0)
- {
- vTestBool = true;
- }
- break;
- case "greatthan": //值大于(限整数符串)
- if (Command.Command_Validate.IsNumber(vTestBase) == false || Command.Command_Validate.IsNumber(vTestValue) == false)
- {
- vTestFalse = "<font color=red>基本值和测试值 必须是整数字符串!</font>";
- }
- else
- {
- if (Convert.ToInt32(vTestBase) > Convert.ToInt32(vTestValue))
- {
- vTestBool = true;
- }
- }
- break;
- case "lessthan": //值小于(限整数符串)
- if (Command.Command_Validate.IsNumber(vTestBase) == false || Command.Command_Validate.IsNumber(vTestValue) == false)
- {
- vTestFalse = "<font color=red>基本值和测试值 必须是整数字符串!</font>";
- }
- else
- {
- if (Convert.ToInt32(vTestBase) < Convert.ToInt32(vTestValue))
- {
- vTestBool = true;
- }
- }
- break;
- case "datediff": //日期比较
- if (Command.Command_Validate.IsDateTime(vTestBase) == false)
- {
- vTestFalse = "<font color=red>基本值 必须为日期!</font>";
- }
- else if (Command.Command_Validate.IsNumber(vTestValue) == false)
- {
- vTestFalse = "<font color=red>测试值 必须是整数字符串!</font>";
- }
- else
- {
- TimeSpan ts = Command.Command_StringPlus.DateDiff(Convert.ToDateTime(vTestBase), DateTime.Now);
- if (ts.Days < Convert.ToInt32(vTestValue))
- {
- vTestBool = true;
- }
- }
- break;
- }
- if (vTestBool == true)
- {
- rInfo = vTestTrue;
- }
- else
- {
- rInfo = vTestFalse;
- }
- #endregion
- }
- vContent = vContent.Replace(m.Value, rInfo);
- }
- }
- //替换列表中的字段信息
- public string Parser_Tags(int byI, string byPattern, string byLoopstr, DataRow byDR)
- {
- Regex regex = new Regex(byPattern, RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(byLoopstr);
- foreach (Match m in matchCollection)
- {
- string vTagsstr = m.Groups[1].Value;
- //缩略图相关S
- string vTag_ThumbnailsMode = Fun_GetAttr(vTagsstr, "thumbmode").Trim();
- string vTag_ThumbnailsQuality = Fun_GetAttr(vTagsstr, "thumbquality").Trim();
- if (Command.Command_Validate.IsNumber(vTag_ThumbnailsQuality) == false)
- {
- vTag_ThumbnailsQuality = "100";
- }
- string vTag_ThumbnailsW = Fun_GetAttr(vTagsstr, "thumbw").Trim();
- string vTag_ThumbnailsH = Fun_GetAttr(vTagsstr, "thumbh").Trim();
- //缩略图相关E
- string vTag_Len = Fun_GetAttr(vTagsstr, "len").Trim();
- string vTag_Format = Fun_GetAttr(vTagsstr, "formatdate").Trim();
- string vTag_Replace = Fun_GetAttr(vTagsstr, "replace").Trim();
- string vTag_Function = Fun_GetAttr(vTagsstr, "function").Trim();
- string vTagsval = vTagsstr.Split(new Char[] { ' ' })[0];
- bool vTagTitle = false;
- switch (vTagsval.ToLower())
- {
- case "i": //i
- vTagsval = byI.ToString();
- break;
- case "titlex": //含有颜色属性的标题
- vTagsval = byDR["Title"].ToString();
- vTagTitle = true;
- break;
- case "creatorid_name":
- if (byDR["CreatorID"] != null && byDR["CreatorID"].ToString().Trim().Length > 0)
- {
- vTagsval = byDR["CreatorID"].ToString();
- vTagsval = iNethinkCMS.BLL.BLL_iNethinkCMS_User.GetIDToUserTrueName(Convert.ToInt32(vTagsval));
- }
- else {
- vTagsval = "系统管理员";
- }
- break;
- case "cname": //栏目名称
- iNethinkCMS.BLL.BLL_iNethinkCMS_Channel bll_column = new iNethinkCMS.BLL.BLL_iNethinkCMS_Channel();
- iNethinkCMS.Model.Model_iNethinkCMS_Channel model_column = new iNethinkCMS.Model.Model_iNethinkCMS_Channel();
- model_column = bll_column.GetModel(Convert.ToInt32(byDR["CID"]));
- if (model_column != null)
- {
- vTagsval = model_column.Name;
- }
- else
- {
- vTagsval = "-";
- }
- break;
- case "sname": //专题名称
- iNethinkCMS.BLL.BLL_iNethinkCMS_Special bll_special = new BLL.BLL_iNethinkCMS_Special();
- iNethinkCMS.Model.Model_iNethinkCMS_Special model_special = new iNethinkCMS.Model.Model_iNethinkCMS_Special();
- model_special = bll_special.GetModel(Convert.ToInt32(byDR["SID"]));
- if (model_special != null)
- {
- vTagsval = model_special.SpecialName;
- }
- else
- {
- vTagsval = "-";
- }
- break;
- default:
- if (Command.Command_StringPlus.Left(vTagsval, 9).ToLower() == "myfields_")
- {
- vTagsval = UI.WebUI_Function.Fun_GetFieldsInfo(vTagsval, byDR["FieldsInfo"].ToString());
- }
- else
- {
- try
- {
- vTagsval = byDR[vTagsval].ToString();
- }
- catch
- {
- vTagsval = m.Value;
- }
- }
- break;
- }
- //vTagsval = Command.Command_Validate.Decode(vTagsval);
- //replace
- if (vTag_Replace.Length > 0)
- {
- string[] sp = vTag_Replace.Split(new string[1] { "###" }, StringSplitOptions.None); //vTag_Replace.Split(new Char[3] { '#', '#', '#' });
- if (sp.Length == 2)
- {
- vTagsval = vTagsval.Replace(sp[0], sp[1]);
- }
- }
- //格式化日期
- if (vTag_Format.Length > 0)
- {
- if (Command.Command_Validate.IsDateTime(vTagsval))
- {
- DateTime vTagsval_DateTime = Convert.ToDateTime(vTagsval);
- vTagsval = vTagsval_DateTime.ToString(vTag_Format);
- }
- }
- //字符串截取
- if (vTag_Len.Length > 0)
- {
- vTagsval = Command.Command_StringPlus.Left(vTagsval, Convert.ToInt32(vTag_Len));
- }
- //函数操作
- if (vTag_Function.Length > 0)
- {
- string[] sp = vTag_Function.Split(new Char[] { ',' });
- for (int i = 0; i < sp.Length; i++)
- {
- switch (sp[i].ToLower())
- {
- case "urlencode":
- vTagsval = System.Web.HttpUtility.UrlEncode(vTagsval, Encoding.UTF8);
- break;
- case "urldecode":
- vTagsval = System.Web.HttpUtility.UrlDecode(vTagsval, Encoding.UTF8);
- break;
- case "htmlencode":
- vTagsval = System.Web.HttpUtility.HtmlEncode(vTagsval);
- break;
- case "htmldecode":
- vTagsval = System.Web.HttpUtility.HtmlDecode(vTagsval);
- break;
- case "trim":
- vTagsval = vTagsval.Trim();
- break;
- case "lower":
- vTagsval = vTagsval.ToLower();
- break;
- case "upper":
- vTagsval = vTagsval.ToUpper();
- break;
- case "clearhtml":
- vTagsval = Command.Command_StringPlus.LostHTML(vTagsval);
- break;
- }
- }
- }
- //缩略图操作
- if (vTag_ThumbnailsMode.Length > 0 && Command.Command_Validate.IsNumber(vTag_ThumbnailsW) && Command.Command_Validate.IsNumber(vTag_ThumbnailsH))
- {
- //如果原图存在
- if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(vTagsval)))
- {
- vTagsval = WebUI_Function.Fun_GetThumbnail(vTagsval, vTag_ThumbnailsW, vTag_ThumbnailsH, vTag_ThumbnailsMode, vTag_ThumbnailsQuality);
- }
- }
- //标题样式处理
- if (vTagTitle == true)
- {
- string vTitle_Color = byDR["Title_Color"].ToString();
- string vTitle_Style = byDR["Title_Style"].ToString();
- string vStlye = "";
- if (vTitle_Color.Length > 0)
- {
- vStlye = vTitle_Color;
- }
- if (vTitle_Style.Length > 0)
- {
- vStlye = vStlye + vTitle_Style;
- }
- if (vTitle_Color.Length > 0 || vTitle_Style.Length > 0)
- {
- vTagsval = "<font style='" + vStlye + "'>" + vTagsval + "</font>";
- }
- }
- byLoopstr = byLoopstr.Replace(m.Value, vTagsval);
- }
- return byLoopstr;
- }
- //获取指定标签属性的值
- public string Fun_GetAttr(string byTagsstr, string byAttrName)
- {
- string vBackGetAttr = "";
- //判断是否为空
- if (byTagsstr.ToLower().IndexOf("$" + byAttrName + "=") >= 0)
- {
- Regex regex = new Regex(@"\$" + byAttrName + @"=(.+?) \$", RegexOptions.IgnoreCase);
- MatchCollection matchCollection = regex.Matches(byTagsstr + " $");
- foreach (Match m in matchCollection)
- {
- vBackGetAttr = m.Groups[1].Value;
- }
- }
- return vBackGetAttr;
- }
- //是否存在此类标签
- public bool Fun_RegExists(string byPattern, string byContent)
- {
- return Regex.IsMatch(byContent, byPattern, RegexOptions.IgnoreCase);
- }
- /// <summary>
- /// 分页获取数据列表
- /// </summary>
- public DataSet GetListByPage(string strTable, string strSelect, string strWhere, string strOrderby, int startIndex, int endIndex)
- {
- if (string.IsNullOrEmpty(strSelect.Trim()))
- {
- strSelect = "*";
- }
- if (!string.IsNullOrEmpty(strWhere.Trim()))
- {
- strWhere = " Where " + strWhere;
- }
- if (!string.IsNullOrEmpty(strOrderby.Trim()))
- {
- strOrderby = " Order By " + strOrderby;
- }
- startIndex = startIndex - 1;
- StringBuilder strSql = new StringBuilder();
- strSql.Append("SELECT " + strSelect + " FROM " + strTable + " Where ID Not IN ");
- strSql.Append("(Select Top " + startIndex + " ID From " + strTable + strWhere + strOrderby + ")");
- strSql.Append(" And ID In ");
- strSql.Append("(Select Top " + endIndex + " ID From " + strTable + strWhere + strOrderby + ")");
- strSql.Append(strOrderby);
- return Helper.SQLHelper.Query(strSql.ToString());
- }
- }
- }
|