/// <summary> /// GEs the t_ DATE. /// </summary> /// <param name="Con">The con.</param> /// <returns></returns> public string ArticlsHtml(HttpContext Con) { //初始化一些参数 this.Context = Con; this.type = Context.Request["type"]; this.bh = Context.Request["id"]; this.templet = Context.Request["templet"]; this.pageNum = Context.Request["page_Num"]; //分页 page 参数 this.classs = Context.Request["class"]; //list页的分类编号参数 this.pageHost = Context.Request["host"]; //模板URL string templet_url = "~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/" + type + templet + ".html"; //读取 模板 StringBuilder HTM = new StringBuilder(); if (DataCache.GetCache(templet_url) == null) { try { if (SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language) == null) { //目录不存在创建 if (!Directory.Exists(Con.Server.MapPath("~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/"))) { Directory.CreateDirectory(Con.Server.MapPath("~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/")); } if (this.templet != null) { ROYcms.Sys.Model.ROYcms_template model = _BLL.GetModel(Convert.ToInt32(this.templet)); HTM.Append(model.htmlcontent); SystemCms.CreateFile(Con.Server.MapPath(templet_url), model.htmlcontent, config.templet_language); } else { HTM.Append("模板不存在!"); SystemCms.CreateFile(Con.Server.MapPath(templet_url), "ROYcms!NT 空模板,请编辑", config.templet_language); } } else { HTM.Append(SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language)); } DataCache.SetCache(templet_url, (object)SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language)); } catch { HTM.Append("读取模板异常!确定是否有创建文件的权限"); } } else { HTM.Append(DataCache.GetCache(templet_url).ToString()); } if (config.HTML_zip == "true") { return(SystemCms.ZipHtml(LoopClass(loopPage(ShowTag(LoopTag(PublicTag(HTM.ToString()))))))); } else { return(LoopClass(loopPage(ShowTag(LoopTag(PublicTag(HTM.ToString())))))); } }
///// <summary> ///// loop标签的匹配替换 ///// </summary> ///// <param name="template">模板内容</param> public string LoopClass(string template) { string Attributes = ""; string Text = ""; string AllText = ""; Regex r = new Regex(@"(\[SG:class\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:class\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (Match m in r.Matches(template)) { Attributes = m.Groups["attributes"].ToString(); //循环属性集 Text = m.Groups["text"].ToString(); //循环的内容不包含SG:Loop AllText = m.Groups[0].Value.ToString(); //整个匹配的内容包含SG:Loop #region 取得相关属性 string Count = null; //调用数量 string classID = null; string Templet = null; // 模板ID Templet = TagVal(Attributes, "Templet"); Count = TagVal(Attributes, "Count"); classID = TagVal(Attributes, "classID"); #endregion #region 对循环的内容进行替换 string content = ""; ROYcms.Sys.BLL.ROYcms_class bll = new ROYcms.Sys.BLL.ROYcms_class(); DataSet dt = bll.GetClassList(0); if (classID != null) { dt = bll.GetSubClassList(bll.GetClassId(Convert.ToInt32(classID))); } if (dt.Tables[0].Rows.Count > 0) { int rowsCount = dt.Tables[0].Rows.Count; if (Count != null && rowsCount > Convert.ToInt32(Count)) { rowsCount = Convert.ToInt32(Count); } for (int n = 0; n < rowsCount; n++) { string str = Text; str = Replace(str, @"\[SG:ClassName\]", dt.Tables[0].Rows[n]["ClassName"].ToString()); str = Replace(str, @"\[SG:Link\]", config.web_host + TemplateZone.Zpath(this.pageHost) + "list" + Templet + "-" + dt.Tables[0].Rows[n]["Id"].ToString() + config.web_forge); str = Replace(str, @"\[SG:_Link\]", "list-" + dt.Tables[0].Rows[n]["Id"].ToString() + config.web_forge); content += str; } } else { content = ""; } #endregion template = template.Replace(AllText, content); } return(template); }
/// <summary> /// show页面标签 替换 /// </summary> /// <param name="template">模板内容</param> /// <returns></returns> public string ShowTag(string template) { if (this.bh != null) { ROYcms.Sys.BLL.ROYcms_news bll = new ROYcms.Sys.BLL.ROYcms_news(); DataSet dt = bll.GetList("bh = '" + this.bh + "'"); DataSet pg_Dn = bll.GetList("bh > '" + this.bh + "'"); DataSet pg_Up = bll.GetList("bh < '" + this.bh + "' order by bh DESC"); if (pg_Dn.Tables[0].Rows.Count > 0) { template = Replace(template, @"\[SG:pg_Dn\]", pg_Dn.Tables[0].Rows[0]["title"].ToString()); template = Replace(template, @"\[SG:pg_Dn_Link\]", pg_Dn.Tables[0].Rows[0]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + this.templet + "-" + pg_Dn.Tables[0].Rows[0]["bh"].ToString() + "-" + Convert.ToDateTime(pg_Dn.Tables[0].Rows[0]["time"]).ToString("yyyyMM") + config.web_forge) : pg_Dn.Tables[0].Rows[0]["jumpurl"].ToString()); } else { template = Replace(template, @"\[SG:pg_Dn\]", "无数据"); template = Replace(template, @"\[SG:pg_Dn_Link\]", "#"); } if (pg_Up.Tables[0].Rows.Count > 0) { template = Replace(template, @"\[SG:pg_Up\]", pg_Up.Tables[0].Rows[0]["title"].ToString()); template = Replace(template, @"\[SG:pg_Up_Link\]", pg_Up.Tables[0].Rows[0]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + this.templet + "-" + pg_Up.Tables[0].Rows[0]["bh"].ToString() + "-" + Convert.ToDateTime(pg_Up.Tables[0].Rows[0]["time"]).ToString("yyyyMM") + config.web_forge) : pg_Up.Tables[0].Rows[0]["jumpurl"].ToString()); } else { template = Replace(template, @"\[SG:pg_Up\]", "无数据"); template = Replace(template, @"\[SG:pg_Up_Link\]", "#"); } template = Replace(template, @"\[SG:UrlPath\]", config.web_host); Regex r = new Regex(@"(\[SG:Field\s+name=" + "\"" + @"(?<name>[^" + "\"" + "]*)" + "\"" + @"\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (dt.Tables[0].Rows.Count > 0) { foreach (Match m in r.Matches(template)) { string name = m.Groups["name"].ToString().ToLowerInvariant(); if (name == "year") { template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Year.ToString()); } else if (name == "month") { template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Month.ToString()); } else if (name == "day") { template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Day.ToString()); } else { try { template = template.Replace(m.Groups[0].Value.ToString(), dt.Tables[0].Rows[0][name].ToString()); } catch { return("标签定义出错"); } } } } } else { return(template); } return(template); }
/// <summary> /// 公共标签替换 /// </summary> /// <param name="template">模板内容</param> /// <returns></returns> /// <summary> private string PublicTag(string template) { //引入外部文件标签 Regex r = new Regex(@"(\[SG:File\s+Path=" + "\"" + @"(?<Path>[^" + "\"" + "]*)" + "\"" + @"\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (Match m in r.Matches(template)) { string Path = m.Groups["Path"].ToString(); template = template.Replace(m.Groups[0].Value.ToString(), SystemCms.Read_File(Context.Server.MapPath(config.templet_root + TemplateZone.TemplateZpath(this.pageHost) + "/" + Path), config.templet_language)); } //WEB.config 文件信息替换 template = Replace(template, @"\[SG:WebPath\]", config.web_host); template = Replace(template, @"\[SG:WebName\]", config.web_name); template = Replace(template, @"\[SG:TemplatePath\]", config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost)); //用户自定义标签替换 #region 对循环的内容进行替换 ROYcms.Sys.BLL.ROYcms_CustomTag bll = new ROYcms.Sys.BLL.ROYcms_CustomTag(); DataSet dt = bll.GetAllList(); if (dt.Tables[0].Rows.Count > 0) { int rowsCount = dt.Tables[0].Rows.Count; for (int n = 0; n < rowsCount; n++) { string str = template; str = str.Replace(@"[SG:" + dt.Tables[0].Rows[n]["TAG"].ToString().Trim() + "]", dt.Tables[0].Rows[n]["TAG_content"].ToString().Trim()); template = str; } } #endregion return(template); }
///// <summary> ///// loopPage分页标签的匹配替换 ///// </summary> ///// <param name="template">模板内容</param> public string loopPage(string template) { string Attributes = ""; string Text = ""; string AllText = ""; Regex r = new Regex(@"(\[SG:loopPage\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:loopPage\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (Match m in r.Matches(template)) { Attributes = m.Groups["attributes"].ToString(); //循环属性集 Text = m.Groups["text"].ToString(); //循环的内容不包含SG:Loop AllText = m.Groups[0].Value.ToString(); //整个匹配的内容包含SG:Loop #region 取得相关属性 string NewsCount = null; //调用数量 string TitleNum = null; //新闻标题的显示字符数量 string ding = null; string tuijian = null; string NewsType = null; //调用新闻的类型 string Templet = null; // 模板ID string Pagesize = null; // string SQL = null; NewsCount = TagVal(Attributes, "NewsCount"); if (NewsCount == null) { NewsCount = "1000"; } TitleNum = TagVal(Attributes, "TitleNum"); if (TitleNum == null) { TitleNum = "100"; } ding = TagVal(Attributes, "ding"); if (ding == null) { ding = "false"; } tuijian = TagVal(Attributes, "tuijian"); if (tuijian == null) { tuijian = "false"; } NewsType = TagVal(Attributes, "NewsType"); if (NewsType == null) { NewsType = "0"; } if (this.classs != null) { NewsType = this.classs; } Templet = TagVal(Attributes, "Templet"); Pagesize = TagVal(Attributes, "Pagesize"); if (Pagesize == null) { Pagesize = "30"; } SQL = TagVal(Attributes, "SQL"); #endregion #region 构造 查询SQL语句 //SQL语句拼接 string strWher = ""; StringBuilder strSql = new StringBuilder(); if (SQL == null) { strWher = "classname='" + NewsType + "'"; strSql.Append("select top "); strSql.Append(NewsCount); strSql.Append(" * from [" + config.date_prefix + "news] where "); strSql.Append(strWher); strSql.Append(" AND switchs='0'"); if (ding == "true") { strSql.Append(" AND ding='0'"); } if (tuijian == "true") { strSql.Append(" AND tuijian='0'"); } strSql.Append(" order by switchs,bh DESC"); } else { strSql.Append(SQL); } #endregion #region 对循环的内容进行替换 string content = ""; DataSet Pa = Bll.GetDataSet(strSql.ToString()); int PageContent = Pa.Tables[0].Rows.Count;//数据总数 分页用 int PS = Convert.ToInt32(Pagesize); int p = Convert.ToInt32(pageNum == null ? "1" : pageNum) - 1; DataTable dt = new DataTable(); dt = Pa.Tables[0]; if (dt.Rows.Count > 0) { int rowsCount = p * PS + PS; if ((p * PS + PS) - dt.Rows.Count > 0) { rowsCount = dt.Rows.Count; } for (int n = p * PS; n < rowsCount; n++) { string str = Text; str = Replace(str, @"\[SG:Title\]", ROYcms.Common.input.GetSubString(dt.Rows[n]["title"].ToString(), Convert.ToInt32(TitleNum))); str = Replace(str, @"\[SG:Id\]", dt.Rows[n]["bh"].ToString()); str = Replace(str, @"\[SG:Url\]", dt.Rows[n]["url"].ToString()); str = Replace(str, @"\[SG:Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + Templet + "-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString()); str = Replace(str, @"\[SG:_Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? ("show-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString()); str = Replace(str, @"\[SG:Pic\]", dt.Rows[n]["pic"].ToString()); str = Replace(str, @"\[SG:Zhaiyao\]", dt.Rows[n]["zhaiyao"].ToString()); str = Replace(str, @"\[SG:Keyword\]", dt.Rows[n]["keyword"].ToString()); str = Replace(str, @"\[SG:classname\]", dt.Rows[n]["classname"].ToString()); str = Replace(str, @"\[SG:Content\]", dt.Rows[n]["contents"].ToString()); str = Replace(str, @"\[SG:Infor\]", dt.Rows[n]["infor"].ToString()); str = Replace(str, @"\[SG:Author\]", dt.Rows[n]["author"].ToString()); str = Replace(str, @"\[SG:Tag\]", dt.Rows[n]["tag"].ToString()); str = Replace(str, @"\[SG:Dig\]", dt.Rows[n]["dig"].ToString()); str = Replace(str, @"\[SG:Hits\]", dt.Rows[n]["hits"].ToString()); str = Replace(str, @"\[SG:Time\]", dt.Rows[n]["time"].ToString()); str = Replace(str, @"\[SG:Year\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Year.ToString()); str = Replace(str, @"\[SG:Month\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Month.ToString()); str = Replace(str, @"\[SG:Day\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Day.ToString()); content += str; } } else { content = ""; } #endregion template = template.Replace(AllText, content); template = template.Replace(@"[SG:Page]", PageContent.ToString()); if (this.classs != null) { ROYcms.Sys.BLL.ROYcms_class ROYcms_classBLL = new ROYcms.Sys.BLL.ROYcms_class(); template = template.Replace(@"[SG:ClassTitle]", ROYcms_classBLL.GetClassTitle(Convert.ToInt32(this.classs))); } } return(template); }