internal static string Parse(string stlEntity, IParseManager parseManager) { var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; if (contextInfo.ItemContainer?.SqlItem == null) { return(string.Empty); } try { var attributeName = stlEntity.Substring(5, stlEntity.Length - 6); if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.SqlItem.Key, attributeName, contextInfo).ToString(); } else { if (contextInfo.ItemContainer.SqlItem.Value.TryGetValue(attributeName, out var value)) { parsedContent = Convert.ToString(value); } } } catch { // ignored } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ItemContainer == null || contextInfo.ItemContainer.SqlItem == null) { return(string.Empty); } try { var attributeName = stlEntity.Substring(5, stlEntity.Length - 6); if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.SqlItem.ItemIndex, attributeName, contextInfo).ToString(); } else { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.SqlItem.DataItem, attributeName, "{0}"); } } catch { } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ItemContainer == null || contextInfo.ItemContainer.CommentItem == null) { return(string.Empty); } try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var type = entityName.Substring(9, entityName.Length - 10); var commentId = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "ID"); var goodCount = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "GoodCount"); var userName = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "UserName"); var addDate = SqlUtils.EvalDateTime(contextInfo.ItemContainer.CommentItem, "AddDate"); var content = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "Content"); if (StringUtils.EqualsIgnoreCase(type, Id)) { parsedContent = commentId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, AddDate)) { parsedContent = DateUtils.Format(addDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(type, UserName)) { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : userName; } else if (StringUtils.EqualsIgnoreCase(type, DisplayName)) { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : BaiRongDataProvider.UserDao.GetDisplayName(userName); } else if (StringUtils.EqualsIgnoreCase(type, GoodCount)) { parsedContent = goodCount.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, Content)) { parsedContent = content; } else if (StringUtils.StartsWithIgnoreCase(type, ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.CommentItem.ItemIndex, type, contextInfo).ToString(); } } catch { // ignored } return(parsedContent); }
private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string connectionString, string queryString, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; if (!string.IsNullOrEmpty(type) && contextInfo.ItemContainer?.SqlItem != null) { if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } else { formatString = "{0}"; } if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.SqlItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.SqlItem.DataItem, type, formatString); } } else if (!string.IsNullOrEmpty(queryString)) { if (string.IsNullOrEmpty(connectionString)) { connectionString = WebConfigUtils.ConnectionString; } //parsedContent = DataProvider.DatabaseDao.GetString(connectionString, queryString); parsedContent = Database.GetString(connectionString, queryString); } if (!string.IsNullOrEmpty(parsedContent)) { 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(XmlNode node, PageInfo pageInfo, ContextInfo contextInfo, StringDictionary attributes, string leftText, string rightText, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; if (InputContentAttribute.Id.ToLower().Equals(type)) { parsedContent = SqlUtils.EvalString(contextInfo.ItemContainer.InputItem.DataItem, InputContentAttribute.Id); } else if (InputContentAttribute.AddDate.ToLower().Equals(type)) { var addDate = SqlUtils.EvalDateTime(contextInfo.ItemContainer.InputItem.DataItem, InputContentAttribute.AddDate); parsedContent = DateUtils.Format(addDate, formatString); } else if (InputContentAttribute.UserName.ToLower().Equals(type)) { parsedContent = SqlUtils.EvalString(contextInfo.ItemContainer.InputItem.DataItem, InputContentAttribute.UserName); } else if (InputContentAttribute.Reply.ToLower().Equals(type)) { var content = SqlUtils.EvalString(contextInfo.ItemContainer.InputItem.DataItem, InputContentAttribute.Reply); parsedContent = content; parsedContent = StringUtils.ParseString(EInputType.TextEditor, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.InputItem.ItemIndex, type, contextInfo).ToString(); } else { var id = SqlUtils.EvalInt(contextInfo.ItemContainer.InputItem.DataItem, InputContentAttribute.Id); var inputContentInfo = DataProvider.InputContentDao.GetContentInfo(id); if (inputContentInfo != null) { parsedContent = inputContentInfo.GetExtendedAttribute(type); if (!string.IsNullOrEmpty(parsedContent)) { if (!InputContentAttribute.HiddenAttributes.Contains(type.ToLower())) { var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, type, RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent, pageInfo.PublishmentSystemId, inputContentInfo.InputId)); parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, separator, pageInfo.PublishmentSystemInfo, ETableStyle.InputContent, 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 (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ItemContainer == null || contextInfo.ItemContainer.CommentItem == null) { return(string.Empty); } try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var type = entityName.Substring(9, entityName.Length - 10).ToLower(); var commentID = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "ID"); var nodeID = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "NodeID"); var contentID = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "ContentID"); var goodCount = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "GoodCount"); var userName = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "UserName"); var isChecked = TranslateUtils.ToBool(SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "IsChecked")); var addDate = SqlUtils.EvalDateTime(contextInfo.ItemContainer.CommentItem, "AddDate"); var content = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "Content"); if (type == "id") { parsedContent = commentID.ToString(); } else if (type == "adddate") { parsedContent = DateUtils.Format(addDate, string.Empty); } else if (type == "username") { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : userName; } else if (type == "goodcount") { parsedContent = goodCount.ToString(); } else if (type == "content") { parsedContent = content; } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.CommentItem.ItemIndex, type, contextInfo).ToString(); } } catch { } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ItemContainer == null || contextInfo.ItemContainer.PhotoItem == null) { return(string.Empty); } try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var type = entityName.Substring(7, entityName.Length - 8).ToLower(); var photoInfo = new PhotoInfo(contextInfo.ItemContainer.PhotoItem.DataItem); if (StringUtils.EqualsIgnoreCase(type, PhotoID)) { parsedContent = photoInfo.ID.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, SmallUrl)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, photoInfo.SmallUrl); } else if (StringUtils.EqualsIgnoreCase(type, MiddleUrl)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, photoInfo.MiddleUrl); } else if (StringUtils.EqualsIgnoreCase(type, LargeUrl)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, photoInfo.LargeUrl); } else if (StringUtils.EqualsIgnoreCase(type, Description)) { parsedContent = photoInfo.Description; } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.PhotoItem.ItemIndex, type, contextInfo).ToString(); } } catch { // ignored } return(parsedContent); }
private static string ParseImpl(ContextInfo contextInfo, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; var commentId = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "Id"); var goodCount = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "GoodCount"); var userName = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "UserName"); var addDate = SqlUtils.EvalDateTime(contextInfo.ItemContainer.CommentItem, "AddDate"); var content = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "Content"); if (StringUtils.EqualsIgnoreCase(type, TypeId)) { parsedContent = commentId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, TypeAddDate)) { parsedContent = DateUtils.Format(addDate, formatString); } else if (StringUtils.EqualsIgnoreCase(type, TypeUserName)) { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : userName; } else if (StringUtils.EqualsIgnoreCase(type, TypeDisplayName)) { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : BaiRongDataProvider.UserDao.GetDisplayName(userName); } else if (StringUtils.EqualsIgnoreCase(type, TypeGoodCount)) { parsedContent = $"<span id='commentsDigg_{commentId}_{true}'>{goodCount}</span>"; } else if (StringUtils.EqualsIgnoreCase(type, TypeContent)) { parsedContent = StringUtils.ParseString(content, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.CommentItem.ItemIndex, type, contextInfo).ToString(); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } return(parsedContent); }
private static string ParseImpl(ContextInfo contextInfo, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; var commentId = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "ID"); //var nodeId = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, CommentAttribute.NodeId); //var contentId = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, CommentAttribute.ContentId); var goodCount = SqlUtils.EvalInt(contextInfo.ItemContainer.CommentItem, "GoodCount"); var userName = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "UserName"); //var isChecked = TranslateUtils.ToBool(SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, CommentAttribute.IsChecked)); var addDate = SqlUtils.EvalDateTime(contextInfo.ItemContainer.CommentItem, "AddDate"); var content = SqlUtils.EvalString(contextInfo.ItemContainer.CommentItem, "Content"); if (type == "id") { parsedContent = commentId.ToString(); } else if (type == "adddate") { parsedContent = DateUtils.Format(addDate, formatString); } else if (type == "username") { parsedContent = string.IsNullOrEmpty(userName) ? "匿名" : userName; } else if (type == "goodcount") { parsedContent = $"<span id='commentsDigg_{commentId}_{true}'>{goodCount}</span>"; } else if (type == "content") { parsedContent = StringUtils.ParseString(content, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.CommentItem.ItemIndex, type, contextInfo).ToString(); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } return(parsedContent); }
private static string ParseImpl(ContextInfo contextInfo, string connectionString, string queryString, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; if (!string.IsNullOrEmpty(type) && contextInfo.ItemContainer?.SqlItem != null) { if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.SqlItem.ItemIndex, type, contextInfo); parsedContent = itemIndex.ToString(); } else { var obj = DataBinder.Eval(contextInfo.ItemContainer.SqlItem.DataItem, type); parsedContent = obj != null?obj.ToString() : string.Empty; } } else if (!string.IsNullOrEmpty(queryString)) { if (string.IsNullOrEmpty(connectionString)) { connectionString = WebConfigUtils.ConnectionString; } //parsedContent = DataProvider.DatabaseDao.GetString(connectionString, queryString); parsedContent = StlDatabaseCache.GetString(connectionString, queryString); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = InputTypeUtils.ParseString(InputType.Text, 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 channelIndex, string channelName, int upLevel, int topLevel, string type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper) { var parsedContent = string.Empty; var channelId = StlDataUtility.GetChannelIdByLevel(pageInfo.SiteId, contextInfo.ChannelId, upLevel, topLevel); channelId = StlDataUtility.GetChannelIdByChannelIdOrChannelIndexOrChannelName(pageInfo.SiteId, channelId, channelIndex, channelName); var channel = ChannelManager.GetChannelInfo(pageInfo.SiteId, channelId); if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } if (!string.IsNullOrEmpty(type)) { if (type.ToLower().Equals(ChannelAttribute.Title.ToLower())) { parsedContent = channel.ChannelName; if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(ChannelAttribute.ChannelIndex.ToLower())) { parsedContent = channel.IndexName; if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(ChannelAttribute.Content.ToLower())) { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(ChannelAttribute.PageContent.ToLower())) { if (contextInfo.IsInnerElement || pageInfo.TemplateInfo.TemplateType != TemplateType.ChannelTemplate) { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else { return(contextInfo.StlElement); } } else if (type.ToLower().Equals(ChannelAttribute.AddDate.ToLower())) { parsedContent = DateUtils.Format(channel.AddDate, formatString); } else if (type.ToLower().Equals(ChannelAttribute.ImageUrl.ToLower())) { parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, channel.ImageUrl, contextInfo.Attributes, contextInfo.IsCurlyBrace); // contextInfo.IsCurlyBrace = true 表示实体标签 } else if (type.ToLower().Equals(ChannelAttribute.Id.ToLower())) { parsedContent = channelId.ToString(); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (type.ToLower().Equals(ChannelAttribute.CountOfChannels.ToLower())) { parsedContent = channel.ChildrenCount.ToString(); } else if (type.ToLower().Equals(ChannelAttribute.CountOfContents.ToLower())) { parsedContent = channel.ContentNum.ToString(); } else if (type.ToLower().Equals(ChannelAttribute.CountOfImageContents.ToLower())) { var count = Content.GetCountCheckedImage(pageInfo.SiteId, channel.Id); parsedContent = count.ToString(); } else if (type.ToLower().Equals(ChannelAttribute.Keywords.ToLower())) { parsedContent = channel.Keywords; } else if (type.ToLower().Equals(ChannelAttribute.Description.ToLower())) { parsedContent = channel.Description; } else { var attributeName = type; var formCollection = channel.Additional.ToNameValueCollection(); if (formCollection != null && formCollection.Count > 0) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.ChannelDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, channel.Id)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, formCollection, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, 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 (!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); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ContentId != 0) { try { if (contextInfo.ContentInfo != null && contextInfo.ContentInfo.ReferenceId > 0 && contextInfo.ContentInfo.SourceId > 0 && contextInfo.ContentInfo.GetExtendedAttribute(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) { var targetNodeId = contextInfo.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, contextInfo.ContentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.NodeId > 0) { //标题可以使用自己的 targetContentInfo.Title = contextInfo.ContentInfo.Title; contextInfo.ContentInfo = targetContentInfo; } } var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); if (StringUtils.EqualsIgnoreCase(ContentAttribute.Id, attributeName))//内容ID { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.ReferenceId > 0 ? contextInfo.ContentInfo.ReferenceId.ToString() : contextInfo.ContentInfo.Id.ToString(); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Id); } } else if (StringUtils.EqualsIgnoreCase(Title, attributeName))//内容标题 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Title; } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); } } else if (StringUtils.EqualsIgnoreCase(FullTitle, attributeName))//内容标题全称 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Title; } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); } } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//内容链接地址 { if (contextInfo.ContentInfo != null) { parsedContent = PageUtility.GetContentUrl(pageInfo.PublishmentSystemInfo, contextInfo.ContentInfo); } else { var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId); parsedContent = PageUtility.GetContentUrl(pageInfo.PublishmentSystemInfo, nodeInfo, contextInfo.ContentId, false); } } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//内容图片地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(BackgroundContentAttribute.ImageUrl); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.ImageUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(VideoUrl, attributeName))//内容视频地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(BackgroundContentAttribute.VideoUrl); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.VideoUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(FileUrl, attributeName))//内容附件地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(DownloadUrl, attributeName))//内容附件地址(可统计下载量) { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(BackgroundContentAttribute.FileUrl); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = ActionsDownload.GetUrl(pageInfo.PublishmentSystemInfo.Additional.ApiUrl, pageInfo.PublishmentSystemId, contextInfo.ChannelId, contextInfo.ContentId, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//内容添加日期 { if (contextInfo.ContentInfo != null) { parsedContent = DateUtils.Format(contextInfo.ContentInfo.AddDate, string.Empty); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, contextInfo.ChannelId); parsedContent = DateUtils.Format(BaiRongDataProvider.ContentDao.GetAddDate(tableName, contextInfo.ContentId), string.Empty); } } else if (StringUtils.EqualsIgnoreCase(LastEditDate, attributeName))//替换最后修改日期 { if (contextInfo.ContentInfo != null) { parsedContent = DateUtils.Format(contextInfo.ContentInfo.LastEditDate, string.Empty); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, contextInfo.ChannelId); parsedContent = DateUtils.Format(BaiRongDataProvider.ContentDao.GetLastEditDate(tableName, contextInfo.ContentId), string.Empty); } } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//内容正文 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(BackgroundContentAttribute.Content); } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.Content); } parsedContent = StringUtility.TextEditorContentDecode(parsedContent, pageInfo.PublishmentSystemInfo); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//内容组别 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.ContentGroupNameCollection; } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.ContentGroupNameCollection); } } else if (StringUtils.EqualsIgnoreCase(Tags, attributeName))//标签 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Tags; } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Tags); } } else if (StringUtils.EqualsIgnoreCase(AddUserName, attributeName)) { string addUserName; if (contextInfo.ContentInfo != null) { addUserName = contextInfo.ContentInfo.AddUserName; } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contextInfo.ChannelId)); addUserName = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.AddUserName); } if (!string.IsNullOrEmpty(addUserName)) { var displayName = BaiRongDataProvider.AdministratorDao.GetDisplayName(addUserName); parsedContent = string.IsNullOrEmpty(displayName) ? addUserName : displayName; } } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.ItemIndex, attributeName, contextInfo).ToString(); } else { int contentNodeId; if (contextInfo.ContentInfo != null) { contentNodeId = contextInfo.ContentInfo.NodeId; if (contextInfo.ContentInfo.ContainsKey(attributeName)) { parsedContent = contextInfo.ContentInfo.GetExtendedAttribute(attributeName); } } else { var tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, contextInfo.ChannelId); contentNodeId = BaiRongDataProvider.ContentDao.GetNodeId(tableName, contextInfo.ContentId); tableName = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, contentNodeId)); parsedContent = BaiRongDataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, attributeName); } if (!string.IsNullOrEmpty(parsedContent)) { var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(pageInfo.PublishmentSystemId, contentNodeId); var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.BackgroundContent, pageInfo.PublishmentSystemInfo.AuxiliaryTableForContent, attributeName, relatedIdentities); parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.PublishmentSystemInfo, ETableStyle.BackgroundContent, styleInfo, string.Empty, null, string.Empty, true); } } } catch { // ignored } } 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); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var channelIndex = StlParserUtility.GetValueFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); var upLevel = 0; var topLevel = -1; var channelId = contextInfo.ChannelId; if (!string.IsNullOrEmpty(channelIndex)) { //channelId = DataProvider.ChannelDao.GetIdByIndexName(pageInfo.SiteId, channelIndex); channelId = Node.GetIdByIndexName(pageInfo.SiteId, channelIndex); if (channelId == 0) { channelId = contextInfo.ChannelId; } } if (attributeName.ToLower().StartsWith("up") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (attributeName.ToLower().StartsWith("up.")) { upLevel = 1; } else { var upLevelStr = attributeName.Substring(2, attributeName.IndexOf(".", StringComparison.Ordinal) - 2); upLevel = TranslateUtils.ToInt(upLevelStr); } topLevel = -1; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } else if (attributeName.ToLower().StartsWith("top") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (attributeName.ToLower().StartsWith("top.")) { topLevel = 1; } else { var topLevelStr = attributeName.Substring(3, attributeName.IndexOf(".", StringComparison.Ordinal) - 3); topLevel = TranslateUtils.ToInt(topLevelStr); } upLevel = 0; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, StlDataUtility.GetChannelIdByLevel(pageInfo.SiteId, channelId, upLevel, topLevel)); if (StringUtils.EqualsIgnoreCase(ChannelId, attributeName))//栏目ID { parsedContent = nodeInfo.Id.ToString(); } else if (StringUtils.EqualsIgnoreCase(Title, attributeName) || StringUtils.EqualsIgnoreCase(ChannelName, attributeName))//栏目名称 { parsedContent = nodeInfo.ChannelName; } else if (StringUtils.EqualsIgnoreCase(ChannelIndex, attributeName))//栏目索引 { parsedContent = nodeInfo.IndexName; } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//栏目正文 { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, nodeInfo.Content, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//栏目链接地址 { parsedContent = PageUtility.GetChannelUrl(pageInfo.SiteInfo, nodeInfo, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//栏目图片地址 { parsedContent = nodeInfo.ImageUrl; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//栏目添加日期 { parsedContent = DateUtils.Format(nodeInfo.AddDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(DirectoryName, attributeName))//生成文件夹名称 { parsedContent = PathUtils.GetDirectoryName(nodeInfo.FilePath, true); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//栏目组别 { parsedContent = nodeInfo.GroupNameCollection; } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, attributeName, contextInfo).ToString(); } else if (StringUtils.EqualsIgnoreCase(ChannelAttribute.Keywords, attributeName))//栏目组别 { parsedContent = nodeInfo.Keywords; } else if (StringUtils.EqualsIgnoreCase(ChannelAttribute.Description, attributeName))//栏目组别 { parsedContent = nodeInfo.Description; } else { //var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, DataProvider.ChannelDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, nodeInfo.ChannelId)); //parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.SiteInfo, ETableStyle.Channel, styleInfo, string.Empty, null, string.Empty, true); var formCollection = nodeInfo.Additional.ToNameValueCollection(); if (formCollection != null && formCollection.Count > 0) { var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.ChannelDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, nodeInfo.Id)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, formCollection, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { if (InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } else { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, null, pageInfo.SiteInfo, styleInfo, string.Empty, null, string.Empty, true); } } } } } } catch { // ignored } return(parsedContent); }
internal static async Task <string> ParseAsync(string stlEntity, IParseManager parseManager) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; if (parseManager.ContextInfo.ContentId != 0) { try { var contentInfo = await parseManager.GetContentAsync(); if (contentInfo != null && contentInfo.ReferenceId > 0 && contentInfo.SourceId > 0 && TranslateType.ReferenceContent.GetValue() == contentInfo.Get <string>(ColumnsManager.TranslateContentType)) { var targetChannelId = contentInfo.SourceId; var targetSiteId = await databaseManager.ChannelRepository.GetSiteIdAsync(targetChannelId); var targetSite = await databaseManager.SiteRepository.GetAsync(targetSiteId); var targetNodeInfo = await databaseManager.ChannelRepository.GetAsync(targetChannelId); var targetContentInfo = await databaseManager.ContentRepository.GetAsync(targetSite, targetNodeInfo, contentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { //标题可以使用自己的 targetContentInfo.Title = contentInfo.Title; contentInfo = targetContentInfo; } } var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); if (StringUtils.EqualsIgnoreCase(nameof(Models.Content.Id), attributeName))//内容ID { if (contentInfo != null) { parsedContent = contentInfo.ReferenceId > 0 ? contentInfo.ReferenceId.ToString() : contentInfo.Id.ToString(); } } else if (StringUtils.EqualsIgnoreCase(Title, attributeName))//内容标题 { if (contentInfo != null) { parsedContent = contentInfo.Title; } } else if (StringUtils.EqualsIgnoreCase(FullTitle, attributeName))//内容标题全称 { if (contentInfo != null) { parsedContent = contentInfo.Title; } } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//内容链接地址 { if (contentInfo != null) { parsedContent = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, contentInfo, pageInfo.IsLocal); } else { var nodeInfo = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); parsedContent = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, nodeInfo, contextInfo.ContentId, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//内容图片地址 { if (contentInfo != null) { parsedContent = contentInfo.ImageUrl; } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(VideoUrl, attributeName))//内容视频地址 { if (contentInfo != null) { parsedContent = contentInfo.VideoUrl; } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(FileUrl, attributeName))//内容附件地址 { if (contentInfo != null) { parsedContent = contentInfo.FileUrl; } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(DownloadUrl, attributeName))//内容附件地址(可统计下载量) { if (contentInfo != null) { parsedContent = contentInfo.FileUrl; } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = parseManager.PathManager.GetDownloadApiUrl(pageInfo.SiteId, contextInfo.ChannelId, contextInfo.ContentId, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//内容添加日期 { if (contentInfo != null) { parsedContent = DateUtils.Format(contentInfo.AddDate, string.Empty); } } else if (StringUtils.EqualsIgnoreCase(LastModifiedDate, attributeName))//替换最后修改日期 { if (contentInfo != null) { parsedContent = DateUtils.Format(contentInfo.LastModifiedDate, string.Empty); } } else if (StringUtils.EqualsIgnoreCase(Body, attributeName) || StringUtils.EqualsIgnoreCase("Content", attributeName))//内容正文 { if (contentInfo != null) { parsedContent = contentInfo.Body; } parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//内容组别 { if (contentInfo != null) { parsedContent = ListUtils.ToString(contentInfo.GroupNames); } } else if (StringUtils.EqualsIgnoreCase(Tags, attributeName))//标签 { if (contentInfo != null) { parsedContent = ListUtils.ToString(contentInfo.TagNames); } } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.Key, attributeName, contextInfo).ToString(); } else { var contentChannelId = 0; if (contentInfo == null) { contentInfo = await databaseManager.ContentRepository.GetAsync(pageInfo.Site, contextInfo.ChannelId, contextInfo.ContentId); } if (contentInfo != null) { contentChannelId = contentInfo.ChannelId; if (contentInfo.ContainsKey(attributeName)) { parsedContent = contentInfo.Get <string>(attributeName); } } if (!string.IsNullOrEmpty(parsedContent)) { var channel = await databaseManager.ChannelRepository.GetAsync(contentChannelId); var tableName = databaseManager.ChannelRepository.GetTableName(pageInfo.Site, channel); var relatedIdentities = databaseManager.TableStyleRepository.GetRelatedIdentities(channel); var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(tableName, attributeName, relatedIdentities); //styleInfo.IsVisible = false 表示此字段不需要显示 styleInfo.TableStyleId = 0 不能排除,因为有可能是直接辅助表字段没有添加显示样式 var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(parsedContent, ",", pageInfo.Site, styleInfo, string.Empty, null, string.Empty, true); } } } catch { // ignored } } return(parsedContent?.Replace(Constants.PagePlaceHolder, string.Empty)); }
private static string ParseImpl(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfo, StringDictionary attributes, string leftText, string rightText, string channelIndex, string channelName, int upLevel, int topLevel, string type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper) { var parsedContent = string.Empty; var channelId = StlDataUtility.GetNodeIdByLevel(pageInfo.PublishmentSystemId, contextInfo.ChannelID, upLevel, topLevel); channelId = StlCacheManager.NodeId.GetNodeIdByChannelIdOrChannelIndexOrChannelName(pageInfo.PublishmentSystemId, channelId, channelIndex, channelName); var channel = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, channelId); if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } if (!string.IsNullOrEmpty(type)) { if (type.ToLower().Equals(NodeAttribute.Title.ToLower())) { parsedContent = channel.NodeName; if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (wordNum == 0 && contextInfo.TitleWordNum > 0) { wordNum = contextInfo.TitleWordNum; } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(NodeAttribute.ChannelIndex.ToLower())) { parsedContent = channel.NodeIndexName; if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(NodeAttribute.Content.ToLower())) { parsedContent = StringUtility.TextEditorContentDecode(channel.Content, pageInfo.PublishmentSystemInfo); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.ToLower().Equals(NodeAttribute.PageContent.ToLower())) { if (contextInfo.IsInnerElement || pageInfo.TemplateInfo.TemplateType != ETemplateType.ChannelTemplate) { parsedContent = StringUtility.TextEditorContentDecode(channel.Content, pageInfo.PublishmentSystemInfo); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else { return(stlElement); } } else if (type.ToLower().Equals(NodeAttribute.AddDate.ToLower())) { parsedContent = DateUtils.Format(channel.AddDate, formatString); } else if (type.ToLower().Equals(NodeAttribute.ImageUrl.ToLower())) { parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, channel.ImageUrl, attributes, false); } else if (type.ToLower().Equals(NodeAttribute.Id.ToLower())) { parsedContent = channelId.ToString(); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (type.ToLower().Equals(NodeAttribute.CountOfChannels.ToLower())) { parsedContent = channel.ChildrenCount.ToString(); } else if (type.ToLower().Equals(NodeAttribute.CountOfContents.ToLower())) { parsedContent = channel.ContentNum.ToString(); } else if (type.ToLower().Equals(NodeAttribute.CountOfImageContents.ToLower())) { var count = DataProvider.BackgroundContentDao.GetCountCheckedImage(pageInfo.PublishmentSystemId, channel.NodeId); parsedContent = count.ToString(); } else if (type.ToLower().Equals(NodeAttribute.Keywords.ToLower())) { parsedContent = channel.Keywords; } else if (type.ToLower().Equals(NodeAttribute.Description.ToLower())) { parsedContent = channel.Description; } else { var attributeName = type; var formCollection = channel.Additional.Attributes; if (formCollection != null && formCollection.Count > 0) { var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, DataProvider.NodeDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.PublishmentSystemId, channel.NodeId)); parsedContent = GetValue(attributeName, formCollection, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, separator, pageInfo.PublishmentSystemInfo, ETableStyle.Channel, 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 (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } } return(parsedContent); }
private static string ParseImpl(IParseManager parseManager, string connectionString, string queryString, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type) { var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; if (!string.IsNullOrEmpty(type) && contextInfo.ItemContainer?.SqlItem != null) { if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } else { formatString = "{0}"; } if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.SqlItem.Key, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else { if (contextInfo.ItemContainer.SqlItem.Value.TryGetValue(type, out var value)) { parsedContent = string.Format(formatString, value); } } } else if (!string.IsNullOrEmpty(queryString)) { if (string.IsNullOrEmpty(connectionString)) { connectionString = parseManager.SettingsManager.Database.ConnectionString; } //parsedContent = GlobalSettings.DatabaseRepository.GetString(connectionString, queryString); parsedContent = parseManager.DatabaseManager.GetString(connectionString, queryString); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = InputTypeUtils.ParseString(InputType.Text, 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 type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, ChannelInfo channel, int channelId) { if (string.IsNullOrEmpty(type)) { type = ChannelAttribute.Title; } type = type.ToLower(); var parsedContent = string.Empty; if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } var inputType = InputType.Text; if (type.Equals(ChannelAttribute.Id.ToLower())) { parsedContent = channelId.ToString(); } else if (type.Equals(ChannelAttribute.SiteId.ToLower())) { parsedContent = channel.SiteId.ToString(); } else if (type.Equals(ChannelAttribute.ContentModelPluginId.ToLower())) { parsedContent = channel.ContentModelPluginId; } else if (type.Equals(ChannelAttribute.ContentRelatedPluginIds.ToLower())) { parsedContent = channel.ContentRelatedPluginIds; } else if (type.Equals(ChannelAttribute.ParentId.ToLower())) { parsedContent = channel.ParentId.ToString(); } else if (type.Equals(ChannelAttribute.ParentsPath.ToLower())) { parsedContent = channel.ParentsPath; } else if (type.Equals(ChannelAttribute.ParentsCount.ToLower())) { parsedContent = channel.ParentsCount.ToString(); } else if (type.Equals(ChannelAttribute.ChildrenCount.ToLower())) { parsedContent = channel.ChildrenCount.ToString(); } else if (type.Equals(ChannelAttribute.IsLastNode.ToLower())) { parsedContent = channel.IsLastNode.ToString(); } else if (type.Equals(ChannelAttribute.ChannelIndex.ToLower()) || type.Equals(ChannelAttribute.IndexName.ToLower())) { parsedContent = channel.IndexName; if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.Equals(ChannelAttribute.GroupNameCollection.ToLower())) { parsedContent = channel.GroupNameCollection; } else if (type.Equals(ChannelAttribute.Taxis.ToLower())) { parsedContent = channel.Taxis.ToString(); } else if (type.Equals(ChannelAttribute.AddDate.ToLower())) { inputType = InputType.DateTime; parsedContent = DateUtils.Format(channel.AddDate, formatString); } else if (type.Equals(ChannelAttribute.ImageUrl.ToLower())) { inputType = InputType.Image; parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.SiteInfo, channel.ImageUrl, contextInfo.Attributes, contextInfo.IsStlEntity); // contextInfo.IsStlEntity = true 表示实体标签 } else if (type.Equals(ChannelAttribute.Content.ToLower())) { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.Equals(ChannelAttribute.FilePath.ToLower())) { parsedContent = channel.FilePath; } else if (type.Equals(ChannelAttribute.ChannelFilePathRule.ToLower())) { parsedContent = channel.ChannelFilePathRule; } else if (type.Equals(ChannelAttribute.ContentFilePathRule.ToLower())) { parsedContent = channel.ContentFilePathRule; } else if (type.Equals(ChannelAttribute.LinkUrl.ToLower())) { parsedContent = channel.LinkUrl; } else if (type.Equals(ChannelAttribute.LinkType.ToLower())) { parsedContent = channel.LinkType; } else if (type.Equals(ChannelAttribute.ChannelTemplateId.ToLower())) { parsedContent = channel.ChannelTemplateId.ToString(); } else if (type.Equals(ChannelAttribute.ContentTemplateId.ToLower())) { parsedContent = channel.ContentTemplateId.ToString(); } else if (type.Equals(ChannelAttribute.Keywords.ToLower())) { parsedContent = channel.Keywords; } else if (type.Equals(ChannelAttribute.Description.ToLower())) { parsedContent = channel.Description; } else if (type.Equals(ChannelAttribute.ExtendValues.ToLower())) { parsedContent = channel.Additional.ToString(); } else if (type.Equals(ChannelAttribute.Title.ToLower()) || type.Equals(ChannelAttribute.ChannelName.ToLower())) { parsedContent = channel.ChannelName; if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (type.Equals(ChannelAttribute.PageContent.ToLower())) { if (contextInfo.IsInnerElement || pageInfo.TemplateInfo.TemplateType != TemplateType.ChannelTemplate) { parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(replace, parsedContent, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else { return(contextInfo.OuterHtml); } } else if (StringUtils.StartsWithIgnoreCase(type, ChannelAttribute.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (type.Equals(ChannelAttribute.CountOfChannels.ToLower())) { parsedContent = channel.ChildrenCount.ToString(); } else if (type.Equals(ChannelAttribute.CountOfContents.ToLower())) { var count = ContentManager.GetCount(pageInfo.SiteInfo, channel, true); parsedContent = count.ToString(); } else if (type.Equals(ChannelAttribute.CountOfImageContents.ToLower())) { var count = StlContentCache.GetCountCheckedImage(pageInfo.SiteId, channel.Id); parsedContent = count.ToString(); } else { var attributeName = type; var styleInfo = TableStyleManager.GetTableStyleInfo(DataProvider.ChannelDao.TableName, attributeName, TableStyleManager.GetRelatedIdentities(channel)); // 如果 styleInfo.TableStyleId <= 0,表示此字段已经被删除了,不需要再显示值了 ekun008 if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, channel.Additional, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, separator, pageInfo.SiteInfo, styleInfo, formatString, contextInfo.Attributes, contextInfo.InnerHtml, false); inputType = styleInfo.InputType; } } } if (string.IsNullOrEmpty(parsedContent)) { return(string.Empty); } parsedContent = InputTypeUtils.ParseString(inputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); return(leftText + parsedContent + rightText); }
private static async Task <string> ParseImplAsync(IParseManager parseManager, 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, Content content, int contentId) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var databaseManager = parseManager.DatabaseManager; if (content == null) { return(string.Empty); } var parsedContent = string.Empty; if (string.IsNullOrEmpty(type)) { type = nameof(Content.Title); } var isReturnToBr = false; if (string.IsNullOrEmpty(isReturnToBrStr)) { if (StringUtils.EqualsIgnoreCase(type, nameof(Content.Summary))) { isReturnToBr = true; } } else { isReturnToBr = TranslateUtils.ToBool(isReturnToBrStr, true); } if (isOriginal) { if (content.ReferenceId > 0 && content.SourceId > 0 && TranslateType.Reference.GetValue() == content.Get <string>(ColumnsManager.TranslateContentType)) { var targetChannelId = content.SourceId; //var targetSiteId = databaseManager.ChannelRepository.GetSiteId(targetChannelId); var targetSiteId = await databaseManager.ChannelRepository.GetSiteIdAsync(targetChannelId); var targetSite = await databaseManager.SiteRepository.GetAsync(targetSiteId); var targetNodeInfo = await databaseManager.ChannelRepository.GetAsync(targetChannelId); //var targetContentInfo = databaseManager.ContentRepository.GetContentInfo(tableStyle, tableName, content.ReferenceId); var targetContentInfo = await databaseManager.ContentRepository.GetAsync(targetSite, targetNodeInfo, content.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { //标题可以使用自己的 targetContentInfo.Title = content.Title; content = targetContentInfo; } } } if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } if (contentId != 0) { if (StringUtils.EqualsIgnoreCase(type, nameof(Content.Title))) { var channel = await databaseManager.ChannelRepository.GetAsync(content.ChannelId); var relatedIdentities = databaseManager.TableStyleRepository.GetRelatedIdentities(channel); var tableName = databaseManager.ChannelRepository.GetTableName(pageInfo.Site, channel); var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(tableName, type, relatedIdentities); var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(content.Title, separator, pageInfo.Site, styleInfo, formatString, contextInfo.Attributes, contextInfo.InnerHtml, false); parsedContent = InputTypeUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (!isClearTags && !string.IsNullOrEmpty(content.Get <string>(ColumnsManager.GetFormatStringAttributeName(nameof(Content.Title))))) { parsedContent = ContentUtility.FormatTitle(content.Get <string>(ColumnsManager.GetFormatStringAttributeName(nameof(Content.Title))), parsedContent); } if (pageInfo.Site.IsContentTitleBreakLine) { parsedContent = parsedContent.Replace(" ", !contextInfo.IsInnerElement ? "<br />" : string.Empty); } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.SubTitle))) { parsedContent = InputTypeUtils.ParseString(InputType.Text, content.SubTitle, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); if (pageInfo.Site.IsContentSubTitleBreakLine) { parsedContent = parsedContent.Replace(" ", !contextInfo.IsInnerElement ? "<br />" : string.Empty); } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.Summary))) { parsedContent = InputTypeUtils.ParseString(InputType.TextArea, content.Summary, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.Body)) || StringUtils.EqualsIgnoreCase(type, nameof(Content))) { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, content.Body, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } parsedContent = await EditorUtility.ParseAsync(pageInfo, parsedContent); } else if (StringUtils.EqualsIgnoreCase(type, nameof(ColumnsManager.PageContent))) { //if (contextInfo.IsInnerElement) // { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, content.Body, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (wordNum > 0 && !string.IsNullOrEmpty(parsedContent)) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, parsedContent); } parsedContent = await EditorUtility.ParseAsync(pageInfo, parsedContent); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.AddDate))) { parsedContent = DateUtils.Format(content.AddDate, formatString); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.LastModifiedDate))) { parsedContent = DateUtils.Format(content.LastModifiedDate, formatString); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.LastHitsDate))) { parsedContent = DateUtils.Format(content.LastHitsDate, formatString); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.ImageUrl))) { var inputParser = new InputParserManager(parseManager.PathManager); if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, content.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, content.ImageUrl, contextInfo.Attributes, false)); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.ImageUrl)); var count = content.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.ImageUrl), i); var extend = content.Get <string>(extendName); sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, contextInfo.Attributes, false)); } //var extendAttributeName = ColumnsManager.GetExtendAttributeName(nameof(Content.ImageUrl)); //var extendValues = content.Get<string>(extendAttributeName); //if (!string.IsNullOrEmpty(extendValues)) //{ // foreach (var extendValue in ListUtils.GetStringList(extendValues)) // { // var newExtendValue = extendValue; // sbParsedContent.Append(contextInfo.IsStlEntity // ? await parseManager.PathManager.ParseNavigationUrlAsync(pageInfo.Site, newExtendValue, pageInfo.IsLocal) // : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, newExtendValue, contextInfo.Attributes, false)); // } //} parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no); if (num <= 1) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, content.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, content.ImageUrl, contextInfo.Attributes, false); } else { var extendName = ColumnsManager.GetExtendName(nameof(Content.ImageUrl), num - 1); var extend = content.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, contextInfo.Attributes, false); } //var extendAttributeName = ColumnsManager.GetExtendAttributeName(nameof(Content.ImageUrl)); //var extendValues = content.Get<string>(extendAttributeName); //if (!string.IsNullOrEmpty(extendValues)) //{ // var index = 2; // foreach (var extendValue in ListUtils.GetStringList(extendValues)) // { // var newExtendValue = extendValue; // if (index == num) // { // parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseNavigationUrlAsync(pageInfo.Site, newExtendValue, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, newExtendValue, contextInfo.Attributes, false); // break; // } // index++; // } //} } } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.VideoUrl))) { var inputParser = new InputParserManager(parseManager.PathManager); if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(await inputParser.GetVideoHtmlAsync(pageInfo.Site, content.VideoUrl, contextInfo.Attributes, contextInfo.IsStlEntity)); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.VideoUrl)); var count = content.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.VideoUrl), i); var extend = content.Get <string>(extendName); sbParsedContent.Append(await inputParser.GetVideoHtmlAsync(pageInfo.Site, extend, contextInfo.Attributes, contextInfo.IsStlEntity)); } //var extendAttributeName = ColumnsManager.GetExtendAttributeName(nameof(Content.VideoUrl)); //var extendValues = content.Get<string>(extendAttributeName); //if (!string.IsNullOrEmpty(extendValues)) //{ // foreach (string extendValue in ListUtils.GetStringList(extendValues)) // { // sbParsedContent.Append(await inputParser.GetVideoHtmlAsync(pageInfo.Config, pageInfo.Site, extendValue, contextInfo.Attributes, contextInfo.IsStlEntity)); // } //} parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no); if (num <= 1) { parsedContent = await inputParser.GetVideoHtmlAsync(pageInfo.Site, content.VideoUrl, contextInfo.Attributes, contextInfo.IsStlEntity); } else { var extendName = ColumnsManager.GetExtendName(nameof(Content.VideoUrl), num - 1); var extend = content.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = await inputParser.GetVideoHtmlAsync(pageInfo.Site, extend, contextInfo.Attributes, contextInfo.IsStlEntity); } } } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.FileUrl))) { if (no == "all") { var sbParsedContent = new StringBuilder(); if (contextInfo.IsStlEntity) { //第一条 sbParsedContent.Append(content.FileUrl); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.FileUrl)); var count = content.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.FileUrl), i); var extend = content.Get <string>(extendName); sbParsedContent.Append(extend); } } else { var inputParser = new InputParserManager(parseManager.PathManager); //第一条 sbParsedContent.Append(inputParser.GetFileHtmlWithCount(pageInfo.Site, content.ChannelId, content.Id, content.FileUrl, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper)); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.FileUrl)); var count = content.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.FileUrl), i); var extend = content.Get <string>(extendName); sbParsedContent.Append(inputParser.GetFileHtmlWithCount(pageInfo.Site, content.ChannelId, content.Id, extend, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper)); } } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no); if (contextInfo.IsStlEntity) { if (num <= 1) { parsedContent = content.FileUrl; } else { var extendName = ColumnsManager.GetExtendName(nameof(Content.FileUrl), num - 1); var extend = content.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = extend; } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else { var inputParser = new InputParserManager(parseManager.PathManager); if (num <= 1) { parsedContent = inputParser.GetFileHtmlWithCount(pageInfo.Site, content.ChannelId, content.Id, content.FileUrl, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper); } else { var extendName = ColumnsManager.GetExtendName(nameof(Content.FileUrl), num - 1); var extend = content.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = inputParser.GetFileHtmlWithCount(pageInfo.Site, content.ChannelId, content.Id, extend, contextInfo.Attributes, contextInfo.InnerHtml, false, isLower, isUpper); } } } } } else if (StringUtils.EqualsIgnoreCase(type, nameof(ColumnsManager.NavigationUrl))) { if (contextInfo.Content != null) { parsedContent = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, contextInfo.Content, pageInfo.IsLocal); } else { var channelInfo = await databaseManager.ChannelRepository.GetAsync(contextInfo.ChannelId); parsedContent = await parseManager.PathManager.GetContentUrlAsync(pageInfo.Site, channelInfo, contextInfo.ContentId, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Content.TagNames))) { parsedContent = ListUtils.ToString(content.TagNames); } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.Key, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else { var channel = await databaseManager.ChannelRepository.GetAsync(content.ChannelId); if (content.ContainsKey(type)) { if (!ListUtils.ContainsIgnoreCase(ColumnsManager.MetadataAttributes.Value, type)) { var relatedIdentities = databaseManager.TableStyleRepository.GetRelatedIdentities(channel); var tableName = databaseManager.ChannelRepository.GetTableName(pageInfo.Site, channel); var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(tableName, type, relatedIdentities); //styleInfo.IsVisible = false 表示此字段不需要显示 styleInfo.TableStyleId = 0 不能排除,因为有可能是直接辅助表字段没有添加显示样式 var num = TranslateUtils.ToInt(no); var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(content, separator, pageInfo.Site, styleInfo, formatString, num, contextInfo.Attributes, contextInfo.InnerHtml, false); parsedContent = InputTypeUtils.ParseString(styleInfo.InputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } else { parsedContent = content.Get <string>(type); parsedContent = InputTypeUtils.ParseString(InputType.Text, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); } } } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = leftText + parsedContent + rightText; } } return(parsedContent); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var channelIndex = StlParserUtility.GetValueFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); var upLevel = 0; var topLevel = -1; var channelID = contextInfo.ChannelID; if (!string.IsNullOrEmpty(channelIndex)) { channelID = DataProvider.NodeDao.GetNodeIdByNodeIndexName(pageInfo.PublishmentSystemId, channelIndex); if (channelID == 0) { channelID = contextInfo.ChannelID; } } if (attributeName.ToLower().StartsWith("up") && attributeName.IndexOf(".") != -1) { if (attributeName.ToLower().StartsWith("up.")) { upLevel = 1; } else { var upLevelStr = attributeName.Substring(2, attributeName.IndexOf(".") - 2); upLevel = TranslateUtils.ToInt(upLevelStr); } topLevel = -1; attributeName = attributeName.Substring(attributeName.IndexOf(".") + 1); } else if (attributeName.ToLower().StartsWith("top") && attributeName.IndexOf(".") != -1) { if (attributeName.ToLower().StartsWith("top.")) { topLevel = 1; } else { var topLevelStr = attributeName.Substring(3, attributeName.IndexOf(".") - 3); topLevel = TranslateUtils.ToInt(topLevelStr); } upLevel = 0; attributeName = attributeName.Substring(attributeName.IndexOf(".") + 1); } var nodeInfo = NodeManager.GetNodeInfo(pageInfo.PublishmentSystemId, StlDataUtility.GetNodeIdByLevel(pageInfo.PublishmentSystemId, channelID, upLevel, topLevel)); if (StringUtils.EqualsIgnoreCase(ChannelID, attributeName))//栏目ID { parsedContent = nodeInfo.NodeId.ToString(); } else if (StringUtils.EqualsIgnoreCase(Title, attributeName) || StringUtils.EqualsIgnoreCase(ChannelName, attributeName))//栏目名称 { parsedContent = nodeInfo.NodeName; } else if (StringUtils.EqualsIgnoreCase(ChannelIndex, attributeName))//栏目索引 { parsedContent = nodeInfo.NodeIndexName; } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//栏目正文 { parsedContent = StringUtility.TextEditorContentDecode(nodeInfo.Content, pageInfo.PublishmentSystemInfo); } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//栏目链接地址 { parsedContent = PageUtility.GetChannelUrl(pageInfo.PublishmentSystemInfo, nodeInfo); } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//栏目图片地址 { parsedContent = nodeInfo.ImageUrl; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.PublishmentSystemInfo, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//栏目添加日期 { parsedContent = DateUtils.Format(nodeInfo.AddDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(DirectoryName, attributeName))//生成文件夹名称 { parsedContent = PathUtils.GetDirectoryName(nodeInfo.FilePath); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//栏目组别 { parsedContent = nodeInfo.NodeGroupNameCollection; } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer != null && contextInfo.ItemContainer.ChannelItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.ItemIndex, attributeName, contextInfo).ToString(); } else if (StringUtils.EqualsIgnoreCase(NodeAttribute.Keywords, attributeName))//栏目组别 { parsedContent = nodeInfo.Keywords; } else if (StringUtils.EqualsIgnoreCase(NodeAttribute.Description, attributeName))//栏目组别 { parsedContent = nodeInfo.Description; } else { var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, DataProvider.NodeDao.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.PublishmentSystemId, nodeInfo.NodeId)); parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.PublishmentSystemInfo, ETableStyle.Channel, styleInfo, string.Empty, null, string.Empty, true); } } catch { } return(parsedContent); }
private static async Task <string> ParseImplAsync(IParseManager parseManager, string leftText, string rightText, string type, string formatString, string no, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, Channel channel, int channelId, NameValueCollection attributes) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; if (string.IsNullOrEmpty(type)) { type = nameof(StlParserUtility.Title); } //type = StringUtils.ToLower(type); var parsedContent = string.Empty; if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString += "}"; } } var inputType = InputType.Text; if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.Id))) { parsedContent = channelId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.SiteId))) { parsedContent = channel.SiteId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ContentModelPluginId))) { parsedContent = channel.ContentModelPluginId; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ParentId))) { parsedContent = channel.ParentId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ParentsPath))) { parsedContent = ListUtils.ToString(channel.ParentsPath); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ParentsCount))) { parsedContent = channel.ParentsCount.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ChildrenCount))) { parsedContent = channel.ChildrenCount.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(ColumnsManager.NavigationUrl)))//栏目链接地址 { parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, channel, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.IndexName)) || StringUtils.EqualsIgnoreCase(type, "ChannelIndex")) { parsedContent = channel.IndexName; if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.GroupNames))) { parsedContent = ListUtils.ToString(channel.GroupNames); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.Taxis))) { parsedContent = channel.Taxis.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.AddDate))) { inputType = InputType.DateTime; parsedContent = DateUtils.Format(channel.AddDate, formatString); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ImageUrl))) { //inputType = InputType.Image; //var inputParser = new InputParserManager(parseManager.PathManager); //parsedContent = await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, channel.ImageUrl, attributes, contextInfo.IsStlEntity); var inputParser = new InputParserManager(parseManager.PathManager); if (no == "all") { var sbParsedContent = new StringBuilder(); //第一条 sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, channel.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, channel.ImageUrl, attributes, false)); //第n条 var countName = ColumnsManager.GetCountName(nameof(Content.ImageUrl)); var count = channel.Get <int>(countName); for (var i = 1; i <= count; i++) { var extendName = ColumnsManager.GetExtendName(nameof(Content.ImageUrl), i); var extend = channel.Get <string>(extendName); sbParsedContent.Append(contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, attributes, false)); } parsedContent = sbParsedContent.ToString(); } else { var num = TranslateUtils.ToInt(no); if (num <= 1) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, channel.ImageUrl, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, channel.ImageUrl, attributes, false); } else { var extendName = ColumnsManager.GetExtendName(nameof(Site.ImageUrl), num - 1); var extend = channel.Get <string>(extendName); if (!string.IsNullOrEmpty(extend)) { parsedContent = contextInfo.IsStlEntity ? await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, extend, pageInfo.IsLocal) : await inputParser.GetImageOrFlashHtmlAsync(pageInfo.Site, extend, attributes, false); } } } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.Content))) { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.FilePath))) { parsedContent = channel.FilePath; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ChannelFilePathRule))) { parsedContent = channel.ChannelFilePathRule; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ContentFilePathRule))) { parsedContent = channel.ContentFilePathRule; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.LinkUrl))) { parsedContent = channel.LinkUrl; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.LinkType))) { parsedContent = channel.LinkType.GetValue(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ChannelTemplateId))) { parsedContent = channel.ChannelTemplateId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.ContentTemplateId))) { parsedContent = channel.ContentTemplateId.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.Keywords))) { parsedContent = channel.Keywords; } else if (StringUtils.EqualsIgnoreCase(type, nameof(Channel.Description))) { parsedContent = channel.Description; } else if (StringUtils.EqualsIgnoreCase(type, StlParserUtility.Title) || StringUtils.EqualsIgnoreCase(type, nameof(Channel.ChannelName))) { parsedContent = channel.ChannelName; if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else if (StringUtils.EqualsIgnoreCase(type, StlParserUtility.PageContent)) { if (contextInfo.IsInnerElement || pageInfo.Template.TemplateType != TemplateType.ChannelTemplate) { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, channel.Content, pageInfo.IsLocal); if (isClearTags) { parsedContent = StringUtils.StripTags(parsedContent); } if (!string.IsNullOrEmpty(replace)) { parsedContent = StringUtils.Replace(parsedContent, replace, to); } if (!string.IsNullOrEmpty(parsedContent) && wordNum > 0) { parsedContent = StringUtils.MaxLengthText(parsedContent, wordNum, ellipsis); } } else { return(contextInfo.OuterHtml); } } else if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.Key, type, contextInfo); parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, StlParserUtility.CountOfChannels)) { parsedContent = channel.ChildrenCount.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, StlParserUtility.CountOfContents)) { var count = await databaseManager.ContentRepository.GetCountAsync(pageInfo.Site, channel); parsedContent = count.ToString(); } else if (StringUtils.EqualsIgnoreCase(type, StlParserUtility.CountOfImageContents)) { var count = await databaseManager.ContentRepository.GetCountCheckedImageAsync(pageInfo.Site, channel); parsedContent = count.ToString(); } else { var attributeName = type; var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.ChannelRepository.TableName, attributeName, databaseManager.TableStyleRepository.GetRelatedIdentities(channel)); if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, channel, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(parsedContent, separator, pageInfo.Site, styleInfo, formatString, attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity); inputType = styleInfo.InputType; } } } if (string.IsNullOrEmpty(parsedContent)) { return(string.Empty); } parsedContent = InputTypeUtils.ParseString(inputType, parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString); return(leftText + parsedContent + rightText); }
private static string ParseImpl(XmlNode node, PageInfo pageInfo, ContextInfo contextInfo, StringDictionary attributes, string leftText, string rightText, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBR, bool isLower, bool isUpper, string type) { var parsedContent = string.Empty; if (!string.IsNullOrEmpty(type) && contextInfo.ItemContainer != null && contextInfo.ItemContainer.PhotoItem != null) { if (!string.IsNullOrEmpty(formatString)) { formatString = formatString.Trim(); if (!formatString.StartsWith("{0")) { formatString = "{0:" + formatString; } if (!formatString.EndsWith("}")) { formatString = formatString + "}"; } } else { formatString = "{0}"; } if (string.IsNullOrEmpty(type) || StringUtils.EqualsIgnoreCase(type, "imageUrl")) { type = Type_LargeUrl; } if (StringUtils.StartsWithIgnoreCase(type, StlParserUtility.ItemIndex)) { var itemIndex = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.PhotoItem.ItemIndex, type, contextInfo); if (!string.IsNullOrEmpty(formatString)) { parsedContent = string.Format(formatString, itemIndex); } else { parsedContent = itemIndex.ToString(); } } else if (StringUtils.StartsWithIgnoreCase(type, Type_SmallUrl) || StringUtils.StartsWithIgnoreCase(type, Type_MiddleUrl) || StringUtils.StartsWithIgnoreCase(type, Type_LargeUrl)) { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.PhotoItem.DataItem, type, formatString); parsedContent = InputParserUtility.GetImageOrFlashHtml(pageInfo.PublishmentSystemInfo, parsedContent, attributes, false); } else if (StringUtils.StartsWithIgnoreCase(type, "description") || StringUtils.StartsWithIgnoreCase(type, "content")) { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.PhotoItem.DataItem, "description", formatString); parsedContent = StringUtils.ReplaceNewlineToBr(parsedContent); } else { parsedContent = DataBinder.Eval(contextInfo.ItemContainer.PhotoItem.DataItem, type, formatString); } } if (!string.IsNullOrEmpty(parsedContent)) { 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); }
internal static string Parse(string stlEntity, PageInfo pageInfo, ContextInfo contextInfo) { var parsedContent = string.Empty; if (contextInfo.ContentId != 0) { try { if (contextInfo.ContentInfo != null && contextInfo.ContentInfo.ReferenceId > 0 && contextInfo.ContentInfo.SourceId > 0 && contextInfo.ContentInfo.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) { var targetChannelId = contextInfo.ContentInfo.SourceId; var targetSiteId = StlChannelCache.GetSiteId(targetChannelId); var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); var targetNodeInfo = ChannelManager.GetChannelInfo(targetSiteId, targetChannelId); var targetContentInfo = ContentManager.GetContentInfo(targetSiteInfo, targetNodeInfo, contextInfo.ContentInfo.ReferenceId); if (targetContentInfo != null && targetContentInfo.ChannelId > 0) { //标题可以使用自己的 targetContentInfo.Title = contextInfo.ContentInfo.Title; contextInfo.ContentInfo = targetContentInfo; } } var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); if (StringUtils.EqualsIgnoreCase(ContentAttribute.Id, attributeName))//内容ID { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.ReferenceId > 0 ? contextInfo.ContentInfo.ReferenceId.ToString() : contextInfo.ContentInfo.Id.ToString(); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Id); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Id); } } else if (StringUtils.EqualsIgnoreCase(Title, attributeName))//内容标题 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Title; } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); } } else if (StringUtils.EqualsIgnoreCase(FullTitle, attributeName))//内容标题全称 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Title; } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Title); } } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//内容链接地址 { if (contextInfo.ContentInfo != null) { parsedContent = PageUtility.GetContentUrl(pageInfo.SiteInfo, contextInfo.ContentInfo, pageInfo.IsLocal); } else { var nodeInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId); parsedContent = PageUtility.GetContentUrl(pageInfo.SiteInfo, nodeInfo, contextInfo.ContentId, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//内容图片地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetString(BackgroundContentAttribute.ImageUrl); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.ImageUrl); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.ImageUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(VideoUrl, attributeName))//内容视频地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetString(BackgroundContentAttribute.VideoUrl); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.VideoUrl); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.VideoUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(FileUrl, attributeName))//内容附件地址 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetString(BackgroundContentAttribute.FileUrl); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = PageUtility.ParseNavigationUrl(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(DownloadUrl, attributeName))//内容附件地址(可统计下载量) { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetString(BackgroundContentAttribute.FileUrl); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.FileUrl); } if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = ApiRouteActionsDownload.GetUrl(pageInfo.ApiUrl, pageInfo.SiteId, contextInfo.ChannelId, contextInfo.ContentId, parsedContent); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//内容添加日期 { if (contextInfo.ContentInfo != null) { parsedContent = DateUtils.Format(contextInfo.ContentInfo.AddDate, string.Empty); } } else if (StringUtils.EqualsIgnoreCase(LastEditDate, attributeName))//替换最后修改日期 { if (contextInfo.ContentInfo != null) { parsedContent = DateUtils.Format(contextInfo.ContentInfo.LastEditDate, string.Empty); } } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//内容正文 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GetString(BackgroundContentAttribute.Content); } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.Content); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, BackgroundContentAttribute.Content); } parsedContent = ContentUtility.TextEditorContentDecode(pageInfo.SiteInfo, parsedContent, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//内容组别 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.GroupNameCollection; } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.ContentGroupNameCollection); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.GroupNameCollection); } } else if (StringUtils.EqualsIgnoreCase(Tags, attributeName))//标签 { if (contextInfo.ContentInfo != null) { parsedContent = contextInfo.ContentInfo.Tags; } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Tags); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.Tags); } } else if (StringUtils.EqualsIgnoreCase(AddUserName, attributeName)) { string addUserName; if (contextInfo.ContentInfo != null) { addUserName = contextInfo.ContentInfo.AddUserName; } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contextInfo.ChannelId)); //addUserName = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, ContentAttribute.AddUserName); addUserName = StlContentCache.GetValue(tableName, contextInfo.ContentId, ContentAttribute.AddUserName); } if (!string.IsNullOrEmpty(addUserName)) { parsedContent = addUserName; } } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ContentItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ContentItem.ItemIndex, attributeName, contextInfo).ToString(); } else { int contentChannelId; if (contextInfo.ContentInfo != null) { contentChannelId = contextInfo.ContentInfo.ChannelId; if (contextInfo.ContentInfo.ContainsKey(attributeName)) { parsedContent = contextInfo.ContentInfo.GetString(attributeName); } } else { var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, contextInfo.ChannelId); //contentChannelId = DataProvider.ContentDao.GetChannelId(tableName, contextInfo.ContentId); contentChannelId = StlContentCache.GetChannelId(tableName, contextInfo.ContentId); tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, ChannelManager.GetChannelInfo(pageInfo.SiteId, contentChannelId)); //parsedContent = DataProvider.ContentDao.GetValue(tableName, contextInfo.ContentId, attributeName); parsedContent = StlContentCache.GetValue(tableName, contextInfo.ContentId, attributeName); } if (!string.IsNullOrEmpty(parsedContent)) { var channelInfo = ChannelManager.GetChannelInfo(pageInfo.SiteId, contentChannelId); var tableName = ChannelManager.GetTableName(pageInfo.SiteInfo, channelInfo); var relatedIdentities = TableStyleManager.GetRelatedIdentities(channelInfo); var styleInfo = TableStyleManager.GetTableStyleInfo(tableName, attributeName, relatedIdentities); //styleInfo.IsVisible = false 表示此字段不需要显示 styleInfo.TableStyleId = 0 不能排除,因为有可能是直接辅助表字段没有添加显示样式 parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.SiteInfo, styleInfo, string.Empty, null, string.Empty, true); } } } catch { // ignored } } parsedContent = parsedContent.Replace(ContentUtility.PagePlaceHolder, string.Empty); return(parsedContent); }
internal static async Task <string> ParseAsync(string stlEntity, IParseManager parseManager) { var databaseManager = parseManager.DatabaseManager; var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; var parsedContent = string.Empty; try { var entityName = StlParserUtility.GetNameFromEntity(stlEntity); var channelIndex = StlParserUtility.GetValueFromEntity(stlEntity); var attributeName = entityName.Substring(9, entityName.Length - 10); var upLevel = 0; var topLevel = -1; var channelId = contextInfo.ChannelId; if (!string.IsNullOrEmpty(channelIndex)) { //channelId = databaseManager.ChannelRepository.GetIdByIndexName(pageInfo.SiteId, channelIndex); channelId = await databaseManager.ChannelRepository.GetChannelIdByIndexNameAsync(pageInfo.SiteId, channelIndex); if (channelId == 0) { channelId = contextInfo.ChannelId; } } if (StringUtils.StartsWithIgnoreCase(attributeName, "up") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (StringUtils.StartsWithIgnoreCase(attributeName, "up.")) { upLevel = 1; } else { var upLevelStr = attributeName.Substring(2, attributeName.IndexOf(".", StringComparison.Ordinal) - 2); upLevel = TranslateUtils.ToInt(upLevelStr); } topLevel = -1; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } else if (StringUtils.StartsWithIgnoreCase(attributeName, "top") && attributeName.IndexOf(".", StringComparison.Ordinal) != -1) { if (StringUtils.StartsWithIgnoreCase(attributeName, "top.")) { topLevel = 1; } else { var topLevelStr = attributeName.Substring(3, attributeName.IndexOf(".", StringComparison.Ordinal) - 3); topLevel = TranslateUtils.ToInt(topLevelStr); } upLevel = 0; attributeName = attributeName.Substring(attributeName.IndexOf(".", StringComparison.Ordinal) + 1); } var dataManager = new StlDataManager(parseManager.DatabaseManager); var nodeInfo = await databaseManager.ChannelRepository.GetAsync(await dataManager.GetChannelIdByLevelAsync(pageInfo.SiteId, channelId, upLevel, topLevel)); if (StringUtils.EqualsIgnoreCase(ChannelId, attributeName))//栏目ID { parsedContent = nodeInfo.Id.ToString(); } else if (StringUtils.EqualsIgnoreCase(Title, attributeName) || StringUtils.EqualsIgnoreCase(ChannelName, attributeName))//栏目名称 { parsedContent = nodeInfo.ChannelName; } else if (StringUtils.EqualsIgnoreCase(ChannelIndex, attributeName))//栏目索引 { parsedContent = nodeInfo.IndexName; } else if (StringUtils.EqualsIgnoreCase(Content, attributeName))//栏目正文 { parsedContent = await parseManager.PathManager.DecodeTextEditorAsync(pageInfo.Site, nodeInfo.Content, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(NavigationUrl, attributeName))//栏目链接地址 { parsedContent = await parseManager.PathManager.GetChannelUrlAsync(pageInfo.Site, nodeInfo, pageInfo.IsLocal); } else if (StringUtils.EqualsIgnoreCase(ImageUrl, attributeName))//栏目图片地址 { parsedContent = nodeInfo.ImageUrl; if (!string.IsNullOrEmpty(parsedContent)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } } else if (StringUtils.EqualsIgnoreCase(AddDate, attributeName))//栏目添加日期 { parsedContent = DateUtils.Format(nodeInfo.AddDate, string.Empty); } else if (StringUtils.EqualsIgnoreCase(DirectoryName, attributeName))//生成文件夹名称 { parsedContent = PathUtils.GetDirectoryName(nodeInfo.FilePath, true); } else if (StringUtils.EqualsIgnoreCase(Group, attributeName))//栏目组别 { parsedContent = ListUtils.ToString(nodeInfo.GroupNames); } else if (StringUtils.StartsWithIgnoreCase(attributeName, StlParserUtility.ItemIndex) && contextInfo.ItemContainer?.ChannelItem != null) { parsedContent = StlParserUtility.ParseItemIndex(contextInfo.ItemContainer.ChannelItem.Key, attributeName, contextInfo).ToString(); } else if (StringUtils.EqualsIgnoreCase(nameof(Channel.Keywords), attributeName))//栏目组别 { parsedContent = nodeInfo.Keywords; } else if (StringUtils.EqualsIgnoreCase(nameof(Channel.Description), attributeName))//栏目组别 { parsedContent = nodeInfo.Description; } else { //var styleInfo = TableStyleManager.GetTableStyleInfo(ETableStyle.Channel, databaseManager.ChannelRepository.TableName, attributeName, RelatedIdentities.GetChannelRelatedIdentities(pageInfo.SiteId, node.ChannelId)); //parsedContent = InputParserUtility.GetContentByTableStyle(parsedContent, ",", pageInfo.Site, ETableStyle.Channel, styleInfo, string.Empty, null, string.Empty, true); var styleInfo = await databaseManager.TableStyleRepository.GetTableStyleAsync(databaseManager.ChannelRepository.TableName, attributeName, databaseManager.TableStyleRepository.GetRelatedIdentities(nodeInfo)); if (styleInfo.Id > 0) { parsedContent = GetValue(attributeName, nodeInfo, false, styleInfo.DefaultValue); if (!string.IsNullOrEmpty(parsedContent)) { if (InputTypeUtils.EqualsAny(styleInfo.InputType, InputType.Image, InputType.File)) { parsedContent = await parseManager.PathManager.ParseSiteUrlAsync(pageInfo.Site, parsedContent, pageInfo.IsLocal); } else { var inputParser = new InputParserManager(parseManager.PathManager); parsedContent = await inputParser.GetContentByTableStyleAsync(parsedContent, null, pageInfo.Site, styleInfo, string.Empty, null, string.Empty, true); } } } } } catch { // ignored } return(parsedContent); }