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); } } }