private void PutPageBody(XmlDocument xmlDoc) { string nodeInnerText = GetNodeInnerText(xmlDoc, "//labelname"); string str2 = GetNodeInnerText(xmlDoc, "//sourcename"); string input = GetNodeInnerText(xmlDoc, "//currentpage", "1"); string str4 = GetNodeInnerText(xmlDoc, "//total", "0"); string str5 = GetNodeInnerText(xmlDoc, "//pagesize", "1"); string unitname = GetNodeInnerText(xmlDoc, "//unitname"); if (string.IsNullOrEmpty(nodeInnerText)) { this.PutErrMessage("分页标签名不能为空!"); } else { PageInfo iPage = new PageInfo(); iPage.SpanName = str2; iPage.PageName = string.Empty; int num = DataConverter.CLng(str4) / DataConverter.CLng(str5); if ((DataConverter.CLng(str4) % DataConverter.CLng(str5)) > 0) { num++; } iPage.PageNum = num; iPage.PageSize = DataConverter.CLng(str5); iPage.CurrentPage = DataConverter.CLng(input); iPage.TotalPub = DataConverter.CLng(str4); iPage.IsDynamicPage = true; iPage.PageName = "ajaxpage"; this.XmlResponseWriter.WriteElementString("status", "ok"); this.XmlResponseWriter.WriteElementString("body", LabelTransform.GetListPage(nodeInnerText, iPage, unitname)); } }
private void PutSystemLabel(string labelname, XmlNodeList bnode) { string labelName = labelname; List <string> list = new List <string>(); list.Add("webmaster"); list.Add("webmasteremail"); list.Add("managedir"); list.Add("readfile"); if (list.Contains(labelname)) { this.PutErrMessage(labelname + "标签禁止AJAX访问!"); } else { foreach (XmlNode node in bnode) { if (node.FirstChild != null) { string str2 = labelName; labelName = str2 + " " + node.FirstChild.Name.Trim() + "=\"" + node.FirstChild.InnerText.Trim() + "\""; } } this.XmlResponseWriter.WriteElementString("status", "ok"); this.XmlResponseWriter.WriteElementString("body", LabelTransform.GetSiteConfigLabel(labelName).ToString()); } }
/// <summary> /// 内容分页标签解析 /// </summary> /// <param name="templateInfo"></param> private void FiltPageContent(TemplateInfo templateInfo) { string pattern = @"{PE\.ContentPage(.*)}(([\s\S](?!{PE\.ContentPage))*?){\/PE.ContentPage}"; foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase)) { XmlElement firstChild; XmlDocument document = new XmlDocument(); try { document.LoadXml("<root " + match.Groups[1].Value + " />"); firstChild = (XmlElement)document.FirstChild; } catch (XmlException exception) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.ToString(), "[err:内容分页标签参数" + match.Groups[1].Value + "错,原因:" + exception.Message + "]"); continue; } string attributesValue = XmlManage.GetAttributesValue(firstChild, "id"); bool flag = DataConverter.CBoolean(XmlManage.GetAttributesValue(firstChild, "urlpage")); if (!string.IsNullOrEmpty(attributesValue)) { attributesValue = attributesValue.ToLower().Trim(); ContentPageInfo contentPageInfo = new ContentPageInfo(); contentPageInfo.Parameter = "<root " + match.Groups[1].Value + " />"; contentPageInfo.Content = match.Groups[2].Value; contentPageInfo.PageName = templateInfo.PageName; if (flag) { contentPageInfo.CurrentPage = templateInfo.CurrentPage; } else { contentPageInfo.CurrentPage = 1; } contentPageInfo.IsDynamicPage = templateInfo.IsDynamicPage; LabelTransform.TransContentPageLabel(contentPageInfo); templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, contentPageInfo.Content); PageInfo item = new PageInfo(); item.PageName = templateInfo.PageName; item.SpanName = attributesValue; item.IsDynamicPage = templateInfo.IsDynamicPage; item.CurrentPage = contentPageInfo.CurrentPage; if (flag) { item.IsMainPage = true; } item.PageNum = contentPageInfo.PageNum; item.TotalPub = contentPageInfo.Content.Length; string str3 = @"\[PageSet\]([\s\S]*?)\[\/PageSet\]"; foreach (Match match2 in Regex.Matches(match.Groups[2].Value, str3, RegexOptions.IgnoreCase)) { item.PageOtherSet = match2.ToString().Replace("<", "<").Replace(">", ">").Replace("'", "'").Replace(""", "\""); templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match2.Value, string.Empty); } this.tempLabelPageList.Add(item); } } }
/// <summary> /// 分页标签解析 /// </summary> /// <param name="templateInfo"></param> private void FiltPage(TemplateInfo templateInfo) { XmlDocument document = new XmlDocument(); string pattern = @"{PE\.Page([\s\S](?!{PE))*?\/}"; foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase)) { try { document.LoadXml(FormatLabel(match.Value)); } catch (XmlException exception) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.ToString(), "[err:分页标签" + match.Value.Replace("{", string.Empty).Replace("/}", string.Empty) + "错,原因:" + exception.Message + "]"); continue; } XmlElement firstChild = (XmlElement)document.FirstChild; foreach (PageInfo info in this.tempLabelPageList) { string str2; if (string.Compare(info.SpanName, XmlManage.GetAttributesValue(firstChild, "datasource"), StringComparison.OrdinalIgnoreCase) != 0) { continue; } if (templateInfo.PageType == 1) { str2 = LabelTransform.GetListPage(XmlManage.GetAttributesValue(firstChild, "id"), info, XmlManage.GetAttributesValue(firstChild, "unitname")); } else { str2 = LabelTransform.GetPage(XmlManage.GetAttributesValue(firstChild, "id"), info, XmlManage.GetAttributesValue(firstChild, "unitname")); } string attributesValue = XmlManage.GetAttributesValue(firstChild, "span"); string str4 = XmlManage.GetAttributesValue(firstChild, "class"); if (string.IsNullOrEmpty(attributesValue)) { attributesValue = "span"; } if (string.IsNullOrEmpty(str4)) { str4 = "pagecss"; } string str5 = "<" + attributesValue + " id=\"pe100_page_" + info.SpanName + "\""; if (!string.IsNullOrEmpty(str4)) { str5 = str5 + " class=\"" + str4 + "\""; } str5 = str5 + ">"; str2 = str5 + str2 + "</" + attributesValue + ">"; templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, str2); if ((info.PageNum > 0) && info.IsMainPage) { templateInfo.PageNum = info.PageNum; templateInfo.TotalPub = info.TotalPub; } } templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, string.Empty); } }
/// <summary> /// 系统标签转换 /// </summary> /// <param name="templateInfo"></param> /// <param name="queryList"></param> private void SystemLabeTransform(TemplateInfo templateInfo, NameValueCollection queryList) { string pattern = "@Request(int|Bool|Date|Dec)?_"; foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase)) { for (int i = 0; i < queryList.Count; i++) { string str4 = match.Groups[1].Value.ToLower(); if (str4 == null) { goto Label_0185; } if (!(str4 == "int")) { if (str4 == "bool") { goto Label_00D4; } if (str4 == "date") { goto Label_0112; } if (str4 == "dec") { goto Label_014A; } goto Label_0185; } templateInfo.TemplateContent = Regex.Replace(templateInfo.TemplateContent, match.Value + queryList.GetKey(i), DataConverter.CLng(queryList.Get(i)).ToString(), RegexOptions.IgnoreCase); continue; Label_00D4: templateInfo.TemplateContent = Regex.Replace(templateInfo.TemplateContent, match.Value + queryList.GetKey(i), DataConverter.CBoolean(queryList.Get(i)).ToString(), RegexOptions.IgnoreCase); continue; Label_0112: templateInfo.TemplateContent = Regex.Replace(templateInfo.TemplateContent, match.Value + queryList.GetKey(i), this.SysCDate(queryList.Get(i)).ToString(), RegexOptions.IgnoreCase); continue; Label_014A: templateInfo.TemplateContent = Regex.Replace(templateInfo.TemplateContent, match.Value + queryList.GetKey(i), DataConverter.CDecimal(queryList.Get(i)).ToString(), RegexOptions.IgnoreCase); continue; Label_0185: templateInfo.TemplateContent = Regex.Replace(templateInfo.TemplateContent, match.Value + queryList.GetKey(i), DataSecurity.FilterBadChar(queryList.Get(i)), RegexOptions.IgnoreCase); } } pattern = @"{PE\.SiteConfig\.(([\s\S](?!{PE))*?)\/}"; foreach (Match match2 in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase)) { if (match2.Groups.Count > 1) { string siteConfigLabel = LabelTransform.GetSiteConfigLabel(match2.Groups[1].Value.Trim().ToLower()); templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match2.Value, siteConfigLabel); } else { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match2.Value, "[err:系统标签'" + match2.Value.Replace("{", string.Empty).Replace("}", string.Empty) + "'错误!]"); } } }
private string ContentLabelProc(string getlabel, string lrootpath, string lpagename, int lpage) { if (string.IsNullOrEmpty(getlabel)) { return(string.Empty); } getlabel = getlabel.Replace("{", "<").Replace("}", ">"); XmlDocument document = new XmlDocument(); LabelInfo labelInfo = new LabelInfo(); labelInfo.RootPath = lrootpath; labelInfo.PageName = lpagename; labelInfo.Page = lpage; try { document.LoadXml(getlabel); foreach (XmlAttribute attribute in document.FirstChild.Attributes) { labelInfo.OriginalData[attribute.Name] = attribute.Value; } } catch (XmlException exception) { return("[err:内容标签" + getlabel.Replace("<", string.Empty).Replace("/>", string.Empty) + "错,原因:" + exception.Message + "]"); } string key = "CK_Label_TransformCacheData_" + labelInfo.OriginalData["id"] + "_" + labelInfo.OriginalData["cacheid"]; int seconds = DataConverter.CLng(labelInfo.OriginalData["cachetime"]); if ((seconds > 0) && (SiteCache.Get(key) != null)) { labelInfo = (LabelInfo)SiteCache.Get(key); } else { labelInfo = LabelTransform.GetLabel(labelInfo); if (seconds > 0) { SiteCache.Insert(key, labelInfo, seconds); } } return(labelInfo.LabelContent.ToString()); }
private void PutLabelBody(XmlDocument xmldoc) { string nodeInnerText = GetNodeInnerText(xmldoc, "//labelname"); string lrootpath = GetNodeInnerText(xmldoc, "//rootpath"); string str3 = GetNodeInnerText(xmldoc, "//pagename"); string input = GetNodeInnerText(xmldoc, "//currentpage", "1"); XmlNodeList list = xmldoc.DocumentElement.SelectNodes("//attrib"); if (string.IsNullOrEmpty(nodeInnerText)) { this.PutErrMessage("标签名不能为空!"); } else if (!this.CheckLabel(nodeInnerText)) { this.PutErrMessage(nodeInnerText + "标签禁止AJAX访问!"); } else { LabelInfo labelInfo = new LabelInfo(); new XmlDocument(); labelInfo.RootPath = lrootpath; labelInfo.PageName = str3; labelInfo.Page = DataConverter.CLng(input); labelInfo.TotalPub = 0; labelInfo.OriginalData["id"] = nodeInnerText; foreach (XmlNode node in list) { if (node.FirstChild != null) { labelInfo.OriginalData[node.FirstChild.Name.Trim()] = DataSecurity.FilterSqlKeyword(DataSecurity.PELabelEncode(node.FirstChild.InnerText.Trim())); } } string key = "CK_Label_TransformCacheData_" + nodeInnerText + "_" + labelInfo.OriginalData["cacheid"]; int seconds = DataConverter.CLng(labelInfo.OriginalData["cachetime"]); if ((seconds > 0) && (SiteCache.Get(key) != null)) { labelInfo = (LabelInfo)SiteCache.Get(key); } else { labelInfo = LabelTransform.GetLabel(labelInfo); string pattern = @"{PE\.Label([\s\S](?!{PE))*?\/}"; bool flag = false; do { flag = false; foreach (Match match in Regex.Matches(labelInfo.LabelContent.ToString(), pattern, RegexOptions.IgnoreCase)) { labelInfo.LabelContent.Replace(match.Value, this.ContentLabelProc(match.Value, lrootpath, labelInfo.PageName, labelInfo.Page)); flag = true; } }while (flag); if (seconds > 0) { SiteCache.Insert(key, labelInfo, seconds); } } this.XmlResponseWriter.WriteElementString("status", "ok"); this.XmlResponseWriter.WriteElementString("body", DataSecurity.PELabelDecode(labelInfo.LabelContent.ToString())); this.XmlResponseWriter.WriteElementString("pagename", str3); this.XmlResponseWriter.WriteElementString("total", labelInfo.TotalPub.ToString()); this.XmlResponseWriter.WriteElementString("currentpage", labelInfo.Page.ToString()); this.XmlResponseWriter.WriteElementString("pagesize", labelInfo.PageSize.ToString()); } }
/// <summary> /// 内容标签转换 /// </summary> /// <param name="OrangeStr"></param> /// <param name="templateInfo"></param> private void ContentLabelProc(string OrangeStr, TemplateInfo templateInfo) { XmlDocument document = new XmlDocument(); LabelInfo labelInfo = new LabelInfo(); labelInfo.RootPath = templateInfo.RootPath; labelInfo.PageName = templateInfo.PageName; try { document.LoadXml(FormatLabel(OrangeStr)); foreach (XmlAttribute attribute in document.FirstChild.Attributes) { labelInfo.OriginalData[attribute.Name.ToLower()] = attribute.Value; } } catch (XmlException exception) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(OrangeStr, "[err:内容标签" + OrangeStr.Replace("{", string.Empty).Replace("/}", string.Empty) + "错,原因:" + exception.Message + "]"); return; } bool flag = DataConverter.CBoolean(labelInfo.OriginalData["urlpage"]); if (flag) { labelInfo.Page = templateInfo.CurrentPage; } string key = "CK_Label_TransformCacheData_" + labelInfo.OriginalData["id"] + "_" + labelInfo.OriginalData["cacheid"]; int seconds = DataConverter.CLng(labelInfo.OriginalData["cachetime"]); if ((seconds > 0) && (SiteCache.Get(key) != null)) { labelInfo = (LabelInfo)SiteCache.Get(key); } else { labelInfo = LabelTransform.GetLabel(labelInfo); if (seconds > 0) { SiteCache.Insert(key, labelInfo, seconds); } } string str2 = labelInfo.OriginalData["span"]; string str3 = labelInfo.OriginalData["id"].ToLower().Trim(); string str4 = labelInfo.OriginalData["class"]; if (!string.IsNullOrEmpty(str2)) { if (string.IsNullOrEmpty(str4)) { labelInfo.LabelContent.Insert(0, "<" + str2 + " id=\"pe100_" + str3 + "\">"); } else { labelInfo.LabelContent.Insert(0, "<" + str2 + " id=\"pe100_" + str3 + "\" class=\"" + str4 + "\">"); } labelInfo.LabelContent.Append("</" + str2 + ">"); } if (DataConverter.CBoolean(labelInfo.OriginalData["noprocinlabel"])) { this.tempstr.Add(this.loopmark.ToString(), labelInfo.LabelContent.ToString()); templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(OrangeStr, "###labelmark" + this.loopmark.ToString() + "###"); this.loopmark++; } else { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(OrangeStr, labelInfo.LabelContent.ToString()); } if (DataConverter.CBoolean(labelInfo.OriginalData["page"])) { PageInfo item = new PageInfo(); item.PageName = templateInfo.PageName; item.SpanName = str3; item.IsDynamicPage = templateInfo.IsDynamicPage; if ((labelInfo.PageSize > 0) && (labelInfo.TotalPub > 0)) { int num2 = labelInfo.TotalPub / labelInfo.PageSize; if ((labelInfo.TotalPub % labelInfo.PageSize) > 0) { num2++; } if (num2 < 1) { num2 = 1; } item.PageNum = num2; item.PageSize = labelInfo.PageSize; item.CurrentPage = templateInfo.CurrentPage; item.TotalPub = labelInfo.TotalPub; if (flag) { item.IsMainPage = true; } this.tempLabelPageList.Add(item); } } }
/// <summary> /// 数据源标签转换 /// </summary> /// <param name="getLabel"></param> /// <param name="templateInfo"></param> private void DatasourceLabelProc(string getLabel, TemplateInfo templateInfo) { XmlDocument document = new XmlDocument(); string xml = getLabel.Replace("{", "<").Replace("}", ">"); LabelInfo inLabel = new LabelInfo(); inLabel.RootPath = templateInfo.RootPath; inLabel.PageName = templateInfo.PageName; try { document.LoadXml(xml); foreach (XmlAttribute attribute in document.FirstChild.Attributes) { inLabel.OriginalData[attribute.Name.ToLower()] = attribute.Value; } } catch (XmlException exception) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "格式错,原因:" + exception.Message + "]"); return; } string str2 = inLabel.OriginalData["id"]; string str3 = inLabel.OriginalData["datasource"]; if (!string.IsNullOrEmpty(str2)) { str2 = str2.ToLower().Trim(); if (string.IsNullOrEmpty(str3)) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "错,原因:请指定DataSource]"); } else { str3 = str3.ToLower().Trim(); bool flag = DataConverter.CBoolean(inLabel.OriginalData["urlpage"]); if (flag) { inLabel.Page = templateInfo.CurrentPage; } string key = "CK_Label_TransformCacheXmlData_" + str2 + "_" + inLabel.OriginalData["cacheid"]; int seconds = DataConverter.CLng(inLabel.OriginalData["cachetime"]); if ((seconds > 0) && (SiteCache.Get(key) != null)) { inLabel = (LabelInfo)SiteCache.Get(key); } else { inLabel = LabelTransform.GetLabelDataTable(str3, templateInfo.CurrentPage, inLabel); if (seconds > 0) { SiteCache.Insert(key, inLabel, seconds); } } try { document.LoadXml(inLabel.LabelContent.ToString()); } catch (XmlException exception2) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "返回数据错,原因:" + exception2.Message + ",源码:" + inLabel.LabelContent.ToString() + "]"); return; } templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, string.Empty); string pattern = @"{PE\.Repeat(.*)}(([\s\S](?!{PE\.Repeat))*?)\{\/PE.Repeat}"; foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase)) { XmlNode firstChild; if (match.Groups.Count < 3) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, "[err:循环标签" + match.Value.Replace("{", string.Empty).Replace("}", string.Empty) + "格式错"); continue; } XmlDocument document2 = new XmlDocument(); xml = "<root " + match.Groups[1].Value + " />"; try { document2.LoadXml(xml); firstChild = document2.FirstChild; } catch (XmlException exception3) { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, "[err:循环标签{PE:Repeat " + match.Groups[1].Value + " /}错,原因:" + exception3.Message + "]"); continue; } if (string.Compare(XmlManage.GetAttributesValue(firstChild, "id"), str2, StringComparison.OrdinalIgnoreCase) == 0) { string input = match.Groups[2].Value; int num2 = 0; string str7 = string.Empty; string str8 = @"{PE\.RMod(.*)}(([\s\S](?!{PE\.RMod))*?)\{\/PE.RMod}"; foreach (Match match2 in Regex.Matches(input, str8, RegexOptions.IgnoreCase)) { if (match2.Groups.Count >= 3) { XmlDocument document3 = new XmlDocument(); xml = "<root " + match2.Groups[1].Value + " />"; bool flag2 = true; try { document3.LoadXml(xml); num2 = DataConverter.CLng(XmlManage.GetAttributesValue(document3.FirstChild, "mod")); } catch (XmlException) { flag2 = false; } if (flag2) { str7 = match2.Groups[2].Value; } input = input.Replace(match2.Value, string.Empty); } } int num3 = DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "loopbegin"), 0); int count = DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "loop"), 0); int num5 = DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "countbase"), 0); if ((num3 >= 0) && (count >= 0)) { if (num3 >= document.DocumentElement.ChildNodes.Count) { num3 = document.DocumentElement.ChildNodes.Count - 1; if (num3 < 0) { num3 = 0; } } if ((count == 0) || (count > document.DocumentElement.ChildNodes.Count)) { count = document.DocumentElement.ChildNodes.Count; if (count < 0) { count = 0; } } if (num3 > count) { num3 = count; } StringBuilder builder = new StringBuilder(); for (int i = num3; i < count; i++) { input = Regex.Replace(input, "{PE.Field.AutoId/}", (i + num5).ToString(), RegexOptions.IgnoreCase); str7 = Regex.Replace(str7, "{PE.Field.AutoId/}", (i + num5).ToString(), RegexOptions.IgnoreCase); builder.Append(this.FieldProc(input, str2, (XmlElement)document.DocumentElement.ChildNodes[i], 1, templateInfo)); if ((num2 > 0) && (((i + 1) % num2) == 0)) { builder.Append(str7); } } templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, builder.ToString()); continue; } templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, string.Empty); } } templateInfo.TemplateContent = this.FieldProc(templateInfo.TemplateContent, str2, document.DocumentElement, 0, templateInfo); if (DataConverter.CBoolean(inLabel.OriginalData["page"])) { PageInfo item = new PageInfo(); item.PageName = templateInfo.PageName; item.SpanName = str2; item.IsDynamicPage = templateInfo.IsDynamicPage; if ((inLabel.PageSize > 0) && (inLabel.TotalPub > 0)) { int num7 = inLabel.TotalPub / inLabel.PageSize; if ((inLabel.TotalPub % inLabel.PageSize) > 0) { num7++; } if (num7 < 1) { num7 = 1; } item.PageNum = num7; item.PageSize = inLabel.PageSize; item.CurrentPage = inLabel.Page; item.TotalPub = inLabel.TotalPub; if (flag) { item.IsMainPage = true; } this.tempLabelPageList.Add(item); } } } } else { templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "错,原因:请指定ID]"); } }