private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, int no, string src, bool isFilesize, bool isCount, string leftText, string rightText) { if (!string.IsNullOrEmpty(contextInfo.InnerXml)) { var innerBuilder = new StringBuilder(contextInfo.InnerXml); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); contextInfo.InnerXml = innerBuilder.ToString(); } var fileUrl = string.Empty; if (!string.IsNullOrEmpty(src)) { fileUrl = src; } else { if (contextInfo.ContextType == EContextType.Undefined) { contextInfo.ContextType = EContextType.Content; } if (contextInfo.ContextType == EContextType.Content) { if (contextInfo.ContentId != 0) { var contentInfo = contextInfo.ContentInfo; if (!string.IsNullOrEmpty(contentInfo?.GetString(type))) { if (no <= 1) { fileUrl = contentInfo.GetString(StringUtils.EqualsIgnoreCase(type, BackgroundContentAttribute.FileUrl) ? BackgroundContentAttribute.FileUrl : type); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(type); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (var extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == no) { fileUrl = extendValue; break; } index++; } } } } } } else if (contextInfo.ContextType == EContextType.Each) { fileUrl = contextInfo.ItemContainer.EachItem.DataItem as string; } } var parsedContent = InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, contextInfo.InnerXml, contextInfo.IsStlEntity); if (isFilesize) { var filePath = PathUtility.MapPath(pageInfo.SiteInfo, fileUrl); parsedContent += " (" + FileUtils.GetFileSizeByFilePath(filePath) + ")"; } else { if (isCount && contextInfo.ContentInfo != null) { parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contextInfo.ContentInfo.ChannelId, contextInfo.ContentInfo.Id, fileUrl, contextInfo.Attributes, contextInfo.InnerXml, contextInfo.IsStlEntity); } else { parsedContent = InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, contextInfo.InnerXml, contextInfo.IsStlEntity); } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } return(parsedContent); }
private static string ParseImpl(XmlNode node, PageInfo pageInfo, ContextInfo contextInfo, string leftText, string rightText, string formatString, string no, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, string isReturnToBrStr, bool isLower, bool isUpper, bool isOriginal, string type, StringDictionary attributes, string imageType) { var parsedContent = string.Empty; var isReturnToBr = false; if (string.IsNullOrEmpty(isReturnToBrStr)) { if (BackgroundContentAttribute.Summary.ToLower().Equals(type)) { isReturnToBr = true; } } else { isReturnToBr = TranslateUtils.ToBool(isReturnToBrStr, true); } var contentId = contextInfo.ContentID; var contentInfo = contextInfo.ContentInfo; if (contentInfo == null) { return(string.Empty); } if (isOriginal) { if (contentInfo.ReferenceId > 0 && contentInfo.SourceId > 0 && contentInfo.GetExtendedAttribute(ContentAttribute.TranslateContentType) == ETranslateContentType.Reference.ToString()) { var targetNodeId = contentInfo.SourceId; var targetPublishmentSystemId = DataProvider.NodeDao.GetPublishmentSystemId(targetNodeId); var targetPublishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(targetPublishmentSystemId); var targetNodeInfo = NodeManager.GetNodeInfo(targetPublishmentSystemId, targetNodeId); var tableStyle = NodeManager.GetTableStyle(targetPublishmentSystemInfo, targetNodeInfo); var tableName = NodeManager.GetTableName(targetPublishmentSystemInfo, targetNodeInfo); var targetContentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.NodeId > 0) { //标题可以使用自己的 targetContentInfo.Title = contentInfo.Title; contentInfo = targetContentInfo; } } } if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } if (contentId != 0) { if (ContentAttribute.Title.ToLower().Equals(type)) { var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(pageInfo.PublishmentSystemId, contentInfo.NodeId); var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contentInfo.NodeId); var tableStyle = NodeManager.GetTableStyle(pageInfo.PublishmentSystemInfo, nodeInfo); var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, nodeInfo); var styleInfo = TableStyleManager.GetTableStyleInfo(tableStyle, tableName, type, relatedIdentities); if (wordNum == 0) { wordNum = contextInfo.TitleWordNum; } parsedContent = InputParserUtility.GetContentByTableStyle(contentInfo.Title, separator, pageInfo.PublishmentSystemInfo, tableStyle, styleInfo, formatString, attributes, node.InnerXml, false); parsedContent = StringUtils.ParseString(EInputTypeUtils.GetEnumType(styleInfo.InputType), parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!isClearTags && !string.IsNullOrEmpty(contentInfo.Attributes[BackgroundContentAttribute.TitleFormatString])) { parsedContent = ContentUtility.FormatTitle(contentInfo.Attributes[BackgroundContentAttribute.TitleFormatString], parsedContent); } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } if (pageInfo.PublishmentSystemInfo.Additional.IsContentTitleBreakLine) { parsedContent = parsedContent.Replace(" ", !contextInfo.IsInnerElement ? "<br />" : string.Empty); } } else if (BackgroundContentAttribute.Summary.ToLower().Equals(type)) { parsedContent = StringUtils.ParseString(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.Summary), replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } else if (BackgroundContentAttribute.Content.ToLower().Equals(type)) { parsedContent = StringUtility.TextEditorContentDecode(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.Content), pageInfo.PublishmentSystemInfo); if (pageInfo.PublishmentSystemInfo.Additional.IsInnerLink) { var innerLinkInfoList = pageInfo.CacheOfInnerLinkInfoList; if (innerLinkInfoList != null && innerLinkInfoList.Count > 0) { InnerLinkInfo newInnerLinkInfo; for (var i = 0; i < innerLinkInfoList.Count - 1; i++) { for (var j = i + 1; j < innerLinkInfoList.Count; j++) { if (innerLinkInfoList[i].InnerLinkName.Length < innerLinkInfoList[j].InnerLinkName.Length) { newInnerLinkInfo = innerLinkInfoList[i]; innerLinkInfoList[i] = innerLinkInfoList[j]; innerLinkInfoList[j] = newInnerLinkInfo; } } } var arrayLinkName = new List <string>(); var arrayInnerLink = new List <string>(); for (var i = 0; i < innerLinkInfoList.Count; i++) { newInnerLinkInfo = innerLinkInfoList[i]; arrayLinkName.Add(newInnerLinkInfo.InnerLinkName); arrayInnerLink.Add(newInnerLinkInfo.InnerString); } for (var m = 0; m < arrayLinkName.Count; m++) { var innerLinkName = arrayLinkName[m]; arrayLinkName[m] = Guid.NewGuid().ToString(); parsedContent = RegexUtils.Replace( $"({innerLinkName.Replace(" ", "\\s")})(?!</a>)(?![^><]*>)", parsedContent, arrayLinkName[m], pageInfo.PublishmentSystemInfo.Additional.InnerLinkMaxNum); } for (var n = 0; n < arrayLinkName.Count; n++) { parsedContent = RegexUtils.Replace( $"({arrayLinkName[n].Replace(" ", "\\s")})(?!</a>)(?![^><]*>)", parsedContent, arrayInnerLink[n], pageInfo.PublishmentSystemInfo.Additional.InnerLinkMaxNum); } } } if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } else if (BackgroundContentAttribute.PageContent.ToLower().Equals(type)) { //if (contextInfo.IsInnerElement) // { parsedContent = StringUtility.TextEditorContentDecode(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.Content), pageInfo.PublishmentSystemInfo); if (pageInfo.PublishmentSystemInfo.Additional.IsInnerLink) { var innerLinkInfoList = pageInfo.CacheOfInnerLinkInfoList; if (innerLinkInfoList != null && innerLinkInfoList.Count > 0) { InnerLinkInfo newInnerLinkInfo; for (var i = 0; i < innerLinkInfoList.Count - 1; i++) { for (var j = i + 1; j < innerLinkInfoList.Count; j++) { if (innerLinkInfoList[i].InnerLinkName.Length < innerLinkInfoList[j].InnerLinkName.Length) { newInnerLinkInfo = innerLinkInfoList[i]; innerLinkInfoList[i] = innerLinkInfoList[j]; innerLinkInfoList[j] = newInnerLinkInfo; } } } for (var i = 0; i < innerLinkInfoList.Count; i++) { newInnerLinkInfo = innerLinkInfoList[i]; for (var j = i + 1; j < innerLinkInfoList.Count; j++) { var lastInnerLinkInfo = innerLinkInfoList[j]; if (newInnerLinkInfo.InnerLinkName.Contains(lastInnerLinkInfo.InnerLinkName)) { innerLinkInfoList.Remove(lastInnerLinkInfo); } } parsedContent = RegexUtils.Replace( $"({newInnerLinkInfo.InnerLinkName.Replace(" ", "\\s")})(?!</a>)(?![^><]*>)", parsedContent, newInnerLinkInfo.InnerString, pageInfo.PublishmentSystemInfo.Additional.InnerLinkMaxNum); } } } if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } } else if (ContentAttribute.AddDate.ToLower().Equals(type)) { parsedContent = DateUtils.Format(contentInfo.AddDate, formatString); } else if (ContentAttribute.LastEditDate.ToLower().Equals(type)) { parsedContent = DateUtils.Format(contentInfo.LastEditDate, formatString); } else if (BackgroundContentAttribute.ImageUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 if (contextInfo.IsCurlyBrace) { sbParsedContent.Append(PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, GetImageUrlByType(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl), imageType))); } else { sbParsedContent.Append(InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, GetImageUrlByType(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl), imageType), attributes, false)); } //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { var newExtendValue = GetImageUrlByType(extendValue, imageType); if (contextInfo.IsCurlyBrace) { sbParsedContent.Append(PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, newExtendValue)); } else { sbParsedContent.Append(InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, newExtendValue, attributes, false)); } } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (num <= 1) { if (contextInfo.IsCurlyBrace) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, GetImageUrlByType(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl), imageType)); } else { parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, GetImageUrlByType(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl), imageType), attributes, false); } } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { var newExtendValue = GetImageUrlByType(extendValue, imageType); if (index == num) { if (contextInfo.IsCurlyBrace) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, newExtendValue); } else { parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, newExtendValue, attributes, false); } break; } index++; } } } } } else if (BackgroundContentAttribute.VideoUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(InputParserUtility.GetVideoHtml(pageInfo.PublishmentSystemInfo, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.VideoUrl), attributes, false)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.VideoUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(InputParserUtility.GetVideoHtml(pageInfo.PublishmentSystemInfo, extendValue, attributes, false)); } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (num <= 1) { parsedContent = InputParserUtility.GetVideoHtml(pageInfo.PublishmentSystemInfo, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.VideoUrl), attributes, false); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.VideoUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = InputParserUtility.GetVideoHtml(pageInfo.PublishmentSystemInfo, extendValue, attributes, false); break; } index++; } } } } } else if (BackgroundContentAttribute.FileUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); if (contextInfo.IsCurlyBrace) { //第一条 sbParsedContent.Append(contentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(extendValue); } } } else { //第一条 sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.PublishmentSystemInfo, contentInfo.NodeId, contentInfo.Id, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl), attributes, node.InnerXml, false)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.PublishmentSystemInfo, contentInfo.NodeId, contentInfo.Id, extendValue, attributes, node.InnerXml, false)); } } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (contextInfo.IsCurlyBrace) { if (num <= 1) { parsedContent = contentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = extendValue; break; } index++; } } } } else { if (num <= 1) { parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.PublishmentSystemInfo, contentInfo.NodeId, contentInfo.Id, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl), attributes, node.InnerXml, false); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetExtendedAttribute(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.PublishmentSystemInfo, contentInfo.NodeId, contentInfo.Id, extendValue, attributes, node.InnerXml, false); break; } index++; } } } } } } else if (BackgroundContentAttribute.NavigationUrl.ToLower().Equals(type)) { parsedContent = PageUtility.GetContentUrl(pageInfo.PublishmentSystemInfo, contentInfo); } else if (ContentAttribute.Tags.ToLower().Equals(type)) { parsedContent = contentInfo.Tags; } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (ContentAttribute.AddUserName.ToLower().Equals(type)) { if (!string.IsNullOrEmpty(contentInfo.AddUserName)) { var displayName = BaiRongDataProvider.AdministratorDao.GetDisplayName(contentInfo.AddUserName); parsedContent = string.IsNullOrEmpty(displayName) ? contentInfo.AddUserName : displayName; } } else { var isSelected = false; var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contentInfo.NodeId); var tableStyle = NodeManager.GetTableStyle(pageInfo.PublishmentSystemInfo, nodeInfo); //WCM SPECIFIC if (tableStyle == ETableStyle.GovInteractContent) { isSelected = true; if (GovInteractContentAttribute.State.ToLower().Equals(type)) { parsedContent = EGovInteractStateUtils.GetText(EGovInteractStateUtils.GetEnumType(contentInfo.GetExtendedAttribute(GovInteractContentAttribute.State))); } else if (StringUtils.EqualsIgnoreCase(type, GovInteractContentAttribute.Reply)) { var replyInfo = DataProvider.GovInteractReplyDao.GetReplyInfoByContentId(pageInfo.PublishmentSystemId, contentInfo.Id); if (replyInfo != null) { parsedContent = replyInfo.Reply; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.ParseString(EInputType.TextEditor, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } } else if (StringUtils.EqualsIgnoreCase(type, GovInteractContentAttribute.ReplyDepartment)) { var replyInfo = DataProvider.GovInteractReplyDao.GetReplyInfoByContentId(pageInfo.PublishmentSystemId, contentInfo.Id); if (replyInfo != null) { parsedContent = DepartmentManager.GetDepartmentName(replyInfo.DepartmentID); } } else if (StringUtils.EqualsIgnoreCase(type, GovInteractContentAttribute.ReplyUserName)) { var replyInfo = DataProvider.GovInteractReplyDao.GetReplyInfoByContentId(pageInfo.PublishmentSystemId, contentInfo.Id); if (replyInfo != null) { parsedContent = replyInfo.UserName; } } else if (StringUtils.EqualsIgnoreCase(type, GovInteractContentAttribute.ReplyDate)) { var replyInfo = DataProvider.GovInteractReplyDao.GetReplyInfoByContentId(pageInfo.PublishmentSystemId, contentInfo.Id); if (replyInfo != null) { var addDate = replyInfo.AddDate; parsedContent = DateUtils.Format(addDate, formatString); } } else if (StringUtils.EqualsIgnoreCase(type, GovInteractContentAttribute.ReplyFileUrl)) { var replyInfo = DataProvider.GovInteractReplyDao.GetReplyInfoByContentId(pageInfo.PublishmentSystemId, contentInfo.Id); if (replyInfo != null) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, replyInfo.FileUrl); } } else { isSelected = false; } } //WCM SPECIFIC if (!isSelected && contentInfo.ContainsKey(type)) { if (!ContentAttribute.HiddenAttributes.Contains(type.ToLower())) { var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(pageInfo.PublishmentSystemId, contentInfo.NodeId); var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, nodeInfo); var styleInfo = TableStyleManager.GetTableStyleInfo(tableStyle, tableName, type, relatedIdentities); var num = TranslateUtils.ToInt(no); parsedContent = InputParserUtility.GetContentByTableStyle(contentInfo, separator, pageInfo.PublishmentSystemInfo, tableStyle, styleInfo, formatString, num, attributes, node.InnerXml, false); parsedContent = StringUtils.ParseString(EInputTypeUtils.GetEnumType(styleInfo.InputType), parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else { parsedContent = contentInfo.GetExtendedAttribute(type); parsedContent = StringUtils.ParseString(parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } } else { if (!string.IsNullOrEmpty(type) && contextInfo.ItemContainer != null && contextInfo.ItemContainer.ContentItem != null) { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.ContentItem.DataItem, type, "{0}"); parsedContent = StringUtils.ParseString(parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } } } return(parsedContent); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string leftText, string rightText, string formatString, string no, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, string isReturnToBrStr, bool isLower, bool isUpper, bool isOriginal, string type) { var parsedContent = string.Empty; var isReturnToBr = false; if (string.IsNullOrEmpty(isReturnToBrStr)) { if (BackgroundContentAttribute.Summary.ToLower().Equals(type)) { isReturnToBr = true; } } else { isReturnToBr = TranslateUtils.ToBool(isReturnToBrStr, true); } var contentId = contextInfo.ContentId; var contentInfo = contextInfo.ContentInfo; if (contentInfo == null) { return(string.Empty); } if (isOriginal) { if (contentInfo.ReferenceId > 0 && contentInfo.SourceId > 0 && contentInfo.GetString(ContentAttribute.TranslateContentType) == ETranslateContentType.Reference.ToString()) { var targetChannelId = contentInfo.SourceId; //var targetSiteId = DataProvider.ChannelDao.GetSiteId(targetChannelId); var targetSiteId = Node.GetSiteId(targetChannelId); var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); var targetNodeInfo = ChannelManager.GetChannelInfo(targetSiteId, targetChannelId); var tableName = ChannelManager.GetTableName(targetSiteInfo, targetNodeInfo); //var targetContentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentInfo.ReferenceId); var targetContentInfo = Content.GetContentInfo(tableName, contentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { //标题可以使用自己的 targetContentInfo.Title = contentInfo.Title; contentInfo = targetContentInfo; } } } if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } if (contentId != 0) { if (ContentAttribute.Title.ToLower().Equals(type)) { var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, contentInfo.ChannelId); var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contentInfo.ChannelId); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, nodeInfo); var styleInfo = TableStyleManager.GetTableStyleInfo(tableName, type, relatedIdentities); parsedContent = InputParserUtility.GetContentByTableStyle(contentInfo.Title, separator, pageInfo.SiteInfo, styleInfo, formatString, contextInfo.Attributes, contextInfo.InnerXml, false); parsedContent = StringUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!isClearTags && !string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.TitleFormatString))) { parsedContent = ContentUtility.FormatTitle(contentInfo.GetString(BackgroundContentAttribute.TitleFormatString), parsedContent); } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } if (pageInfo.SiteInfo.Additional.IsContentTitleBreakLine) { parsedContent = parsedContent.Replace(" ", !contextInfo.IsInnerElement ? "<br />" : string.Empty); } } else if (BackgroundContentAttribute.Summary.ToLower().Equals(type)) { parsedContent = StringUtils.ParseString(contentInfo.GetString(BackgroundContentAttribute.Summary), replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } else if (BackgroundContentAttribute.Content.ToLower().Equals(type)) { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.Content), pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } else if (BackgroundContentAttribute.PageContent.ToLower().Equals(type)) { //if (contextInfo.IsInnerElement) // { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.Content), pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } } else if (ContentAttribute.AddDate.ToLower().Equals(type)) { parsedContent = DateUtils.Format(contentInfo.AddDate, formatString); } else if (ContentAttribute.LastEditDate.ToLower().Equals(type)) { parsedContent = DateUtils.Format(contentInfo.LastEditDate, formatString); } else if (BackgroundContentAttribute.ImageUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(contextInfo.IsCurlyBrace ? PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), pageInfo.IsLocal) : InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), contextInfo.Attributes, false)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (var extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { var newExtendValue = extendValue; sbParsedContent.Append(contextInfo.IsCurlyBrace ? PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, newExtendValue, pageInfo.IsLocal) : InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, newExtendValue, contextInfo.Attributes, false)); } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (num <= 1) { parsedContent = contextInfo.IsCurlyBrace ? PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), pageInfo.IsLocal) : InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl), contextInfo.Attributes, false); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (var extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { var newExtendValue = extendValue; if (index == num) { parsedContent = contextInfo.IsCurlyBrace ? PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, newExtendValue, pageInfo.IsLocal) : InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, newExtendValue, contextInfo.Attributes, false); break; } index++; } } } } } else if (BackgroundContentAttribute.VideoUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(InputParserUtility.GetVideoHtml(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.VideoUrl), contextInfo.Attributes, contextInfo.IsCurlyBrace)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.VideoUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(InputParserUtility.GetVideoHtml(pageInfo.SiteInfo, extendValue, contextInfo.Attributes, contextInfo.IsCurlyBrace)); } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (num <= 1) { parsedContent = InputParserUtility.GetVideoHtml(pageInfo.SiteInfo, contentInfo.GetString(BackgroundContentAttribute.VideoUrl), contextInfo.Attributes, contextInfo.IsCurlyBrace); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.VideoUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = InputParserUtility.GetVideoHtml(pageInfo.SiteInfo, extendValue, contextInfo.Attributes, contextInfo.IsCurlyBrace); break; } index++; } } } } } else if (BackgroundContentAttribute.FileUrl.ToLower().Equals(type)) { if (no == "all") { var sbParsedContent = new StringBuilder(); if (contextInfo.IsCurlyBrace) { //第一条 sbParsedContent.Append(contentInfo.GetString(BackgroundContentAttribute.FileUrl)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(extendValue); } } } else { //第一条 sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerXml, false)); //第n条 var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { sbParsedContent.Append(InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerXml, false)); } } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no, 0); if (contextInfo.IsCurlyBrace) { if (num <= 1) { parsedContent = contentInfo.GetString(BackgroundContentAttribute.FileUrl); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = extendValue; break; } index++; } } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else { if (num <= 1) { parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.GetString(BackgroundContentAttribute.FileUrl), contextInfo.Attributes, contextInfo.InnerXml, false); } else { var extendAttributeName = ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl); var extendValues = contentInfo.GetString(extendAttributeName); if (!string.IsNullOrEmpty(extendValues)) { var index = 2; foreach (string extendValue in TranslateUtils.StringCollectionToStringList(extendValues)) { if (index == num) { parsedContent = InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contentInfo.ChannelId, contentInfo.Id, extendValue, contextInfo.Attributes, contextInfo.InnerXml, false); break; } index++; } } } } } } else if (BackgroundContentAttribute.NavigationUrl.ToLower().Equals(type)) { parsedContent = PageUtility.GetContentUrl(pageInfo.SiteInfo, contentInfo, pageInfo.IsLocal); } else if (ContentAttribute.Tags.ToLower().Equals(type)) { parsedContent = contentInfo.Tags; } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (ContentAttribute.AddUserName.ToLower().Equals(type)) { if (!string.IsNullOrEmpty(contentInfo.AddUserName)) { //var displayName = DataProvider.AdministratorDao.GetDisplayName(contentInfo.AddUserName); var displayName = Administrator.GetDisplayName(contentInfo.AddUserName); parsedContent = string.IsNullOrEmpty(displayName) ? contentInfo.AddUserName : displayName; } } else { var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contentInfo.ChannelId); if (contentInfo.ContainsKey(type)) { if (!ContentAttribute.AllAttributesLowercase.Contains(type.ToLower())) { var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, contentInfo.ChannelId); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, nodeInfo); var styleInfo = TableStyleManager.GetTableStyleInfo(tableName, type, relatedIdentities); //styleInfo.IsVisible = false 表示此字段不需要显示 styleInfo.TableStyleId = 0 不能排除,因为有可能是直接辅助表字段没有添加显示样式 var num = TranslateUtils.ToInt(no); parsedContent = InputParserUtility.GetContentByTableStyle(contentInfo, separator, pageInfo.SiteInfo, styleInfo, formatString, num, contextInfo.Attributes, contextInfo.InnerXml, false); parsedContent = StringUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else { parsedContent = contentInfo.GetString(type); parsedContent = StringUtils.ParseString(parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } if (!contextInfo.IsInnerElement) { parsedContent = parsedContent.Replace("&", "&"); } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } } return(parsedContent); }