/// <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> /// 公共标签替换Publics the tag. /// </summary> /// <param name="template">The template.</param> /// <returns></returns> public string PublicTag(string template) { if (template != null) { //引入外部文件标签 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(HttpContext.Current.Server.MapPath(ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("templet_root") + ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("templet_file") + "/" + Path), ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("templet_language"))); } //WEB.config 文件信息替换 template = Replace(template, @"\[SG:WebPath\]", ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("web_host")); template = Replace(template, @"\[SG:WebName\]", ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("web_name")); template = Replace(template, @"\[SG:WebDescription\]", ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("Description")); template = Replace(template, @"\[SG:TemplatePath\]", ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("templet_root") + ROYcms.Config.ROYcmsConfig.GetCmsConfigValue("templet_file")); //用户自定义标签替换 #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 } else { template = "<!--公共标签值为空!-->"; } return(template); }