//得到栏目经过计算后的连接地址 public static string GetChannelUrl(SiteInfo siteInfo, ChannelInfo channelInfo, bool isLocal) { if (channelInfo == null) { return(string.Empty); } var url = string.Empty; if (channelInfo.ParentId == 0) { url = GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else { var linkType = ELinkTypeUtils.GetEnumType(channelInfo.LinkType); if (linkType == ELinkType.None) { url = GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else if (linkType == ELinkType.NoLink) { url = PageUtils.UnclickedUrl; } else { if (linkType == ELinkType.NoLinkIfContentNotExists) { var count = ContentManager.GetCount(siteInfo, channelInfo, true); url = count == 0 ? PageUtils.UnclickedUrl : GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else if (linkType == ELinkType.LinkToOnlyOneContent) { var count = ContentManager.GetCount(siteInfo, channelInfo, true); if (count == 1) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentId = StlContentCache.GetContentId(tableName, channelInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType))); url = GetContentUrl(siteInfo, channelInfo, contentId, isLocal); } else { url = GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } } else if (linkType == ELinkType.NoLinkIfContentNotExistsAndLinkToOnlyOneContent) { var count = ContentManager.GetCount(siteInfo, channelInfo, true); if (count == 0) { url = PageUtils.UnclickedUrl; } else if (count == 1) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentId = StlContentCache.GetContentId(tableName, channelInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType))); url = GetContentUrl(siteInfo, channelInfo, contentId, isLocal); } else { url = GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } } else if (linkType == ELinkType.LinkToFirstContent) { var count = ContentManager.GetCount(siteInfo, channelInfo, true); if (count >= 1) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentId = StlContentCache.GetContentId(tableName, channelInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType))); //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo); url = GetContentUrl(siteInfo, channelInfo, contentId, isLocal); } else { url = GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } } else if (linkType == ELinkType.NoLinkIfContentNotExistsAndLinkToFirstContent) { var count = ContentManager.GetCount(siteInfo, channelInfo, true); if (count >= 1) { var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentId = StlContentCache.GetContentId(tableName, channelInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType))); //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo); url = GetContentUrl(siteInfo, channelInfo, contentId, isLocal); } else { url = PageUtils.UnclickedUrl; } } else if (linkType == ELinkType.NoLinkIfChannelNotExists) { url = channelInfo.ChildrenCount == 0 ? PageUtils.UnclickedUrl : GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else if (linkType == ELinkType.LinkToLastAddChannel) { var lastAddChannelInfo = StlChannelCache.GetChannelInfoByLastAddDate(channelInfo.Id); url = lastAddChannelInfo != null?GetChannelUrl(siteInfo, lastAddChannelInfo, isLocal) : GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else if (linkType == ELinkType.LinkToFirstChannel) { var firstChannelInfo = StlChannelCache.GetChannelInfoByTaxis(channelInfo.Id); url = firstChannelInfo != null?GetChannelUrl(siteInfo, firstChannelInfo, isLocal) : GetChannelUrlNotComputed(siteInfo, channelInfo.Id, isLocal); } else if (linkType == ELinkType.NoLinkIfChannelNotExistsAndLinkToLastAddChannel) { var lastAddChannelInfo = StlChannelCache.GetChannelInfoByLastAddDate(channelInfo.Id); url = lastAddChannelInfo != null?GetChannelUrl(siteInfo, lastAddChannelInfo, isLocal) : PageUtils.UnclickedUrl; } else if (linkType == ELinkType.NoLinkIfChannelNotExistsAndLinkToFirstChannel) { var firstChannelInfo = StlChannelCache.GetChannelInfoByTaxis(channelInfo.Id); url = firstChannelInfo != null?GetChannelUrl(siteInfo, firstChannelInfo, isLocal) : PageUtils.UnclickedUrl; } } } return(RemoveDefaultFileName(siteInfo, url)); }
private static string GetContentUrlById(SiteInfo siteInfo, int channelId, int contentId, int sourceId, int referenceId, string linkUrl, bool isLocal) { if (isLocal) { return(ApiRoutePreview.GetContentUrl(siteInfo.Id, channelId, contentId)); } var contentInfoCurrent = ContentManager.GetContentInfo(siteInfo, channelId, contentId); if (referenceId > 0 && contentInfoCurrent.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) { if (sourceId > 0 && (ChannelManager.IsExists(siteInfo.Id, sourceId) || ChannelManager.IsExists(sourceId))) { var targetChannelId = sourceId; var targetSiteId = StlChannelCache.GetSiteId(targetChannelId); var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); var targetChannelInfo = ChannelManager.GetChannelInfo(targetSiteId, targetChannelId); var contentInfo = ContentManager.GetContentInfo(targetSiteInfo, targetChannelInfo, referenceId); if (contentInfo == null || contentInfo.ChannelId <= 0) { return(PageUtils.UnclickedUrl); } if (contentInfo.SiteId == targetSiteInfo.Id) { return(GetContentUrlById(targetSiteInfo, contentInfo.ChannelId, contentInfo.Id, contentInfo.SourceId, contentInfo.ReferenceId, contentInfo.GetString(ContentAttribute.LinkUrl), false)); } var siteInfoTmp = SiteManager.GetSiteInfo(contentInfo.SiteId); return(GetContentUrlById(siteInfoTmp, contentInfo.ChannelId, contentInfo.Id, contentInfo.SourceId, contentInfo.ReferenceId, contentInfo.GetString(ContentAttribute.LinkUrl), false)); } else { var tableName = ChannelManager.GetTableName(siteInfo, channelId); channelId = StlContentCache.GetChannelId(tableName, referenceId); linkUrl = StlContentCache.GetValue(tableName, referenceId, ContentAttribute.LinkUrl); return(GetContentUrlById(siteInfo, channelId, referenceId, 0, 0, linkUrl, false)); } } if (!string.IsNullOrEmpty(linkUrl)) { return(ParseNavigationUrl(siteInfo, linkUrl, false)); } var contentUrl = PathUtility.ContentFilePathRules.Parse(siteInfo, channelId, contentId); return(GetSiteUrl(siteInfo, contentUrl, false)); }
private static string ParseContentPath(SiteInfo siteInfo, int channelId, IContentInfo contentInfo, string contentFilePathRule) { var filePath = contentFilePathRule.Trim(); var regex = "(?<element>{@[^}]+})"; var elements = RegexUtils.GetContents("element", regex, filePath); var addDate = contentInfo.AddDate; var contentId = contentInfo.Id; foreach (var element in elements) { var value = string.Empty; if (StringUtils.EqualsIgnoreCase(element, ChannelId)) { value = channelId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ContentId)) { value = contentId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Sequence)) { var tableName = ChannelManager.GetTableName(siteInfo, channelId); value = StlContentCache.GetSequence(tableName, channelId, contentId).ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ParentRule))//继承父级设置 20151113 sessionliang { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); var parentInfo = ChannelManager.GetChannelInfo(siteInfo.Id, nodeInfo.ParentId); if (parentInfo != null) { var parentRule = GetContentFilePathRule(siteInfo, parentInfo.Id); value = DirectoryUtils.GetDirectoryPath(ParseContentPath(siteInfo, parentInfo.Id, contentInfo, parentRule)).Replace("\\", "/"); } } else if (StringUtils.EqualsIgnoreCase(element, ChannelName)) { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); if (nodeInfo != null) { value = nodeInfo.ChannelName; } } else if (StringUtils.EqualsIgnoreCase(element, LowerChannelName)) { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); if (nodeInfo != null) { value = nodeInfo.ChannelName.ToLower(); } } else if (StringUtils.EqualsIgnoreCase(element, ChannelIndex)) { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); if (nodeInfo != null) { value = nodeInfo.IndexName; } } else if (StringUtils.EqualsIgnoreCase(element, LowerChannelIndex)) { var nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); if (nodeInfo != null) { value = nodeInfo.IndexName.ToLower(); } } else if (StringUtils.EqualsIgnoreCase(element, Year) || StringUtils.EqualsIgnoreCase(element, Month) || StringUtils.EqualsIgnoreCase(element, Day) || StringUtils.EqualsIgnoreCase(element, Hour) || StringUtils.EqualsIgnoreCase(element, Minute) || StringUtils.EqualsIgnoreCase(element, Second)) { if (StringUtils.EqualsIgnoreCase(element, Year)) { value = addDate.Year.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Month)) { value = addDate.Month.ToString("D2"); //value = addDate.ToString("MM"); } else if (StringUtils.EqualsIgnoreCase(element, Day)) { value = addDate.Day.ToString("D2"); //value = addDate.ToString("dd"); } else if (StringUtils.EqualsIgnoreCase(element, Hour)) { value = addDate.Hour.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Minute)) { value = addDate.Minute.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Second)) { value = addDate.Second.ToString(); } } else { var attributeName = element.Replace("{@", string.Empty).Replace("}", string.Empty); var isLower = false; if (StringUtils.StartsWithIgnoreCase(attributeName, "lower")) { isLower = true; attributeName = attributeName.Substring(5); } value = contentInfo.GetString(attributeName); if (isLower) { value = value.ToLower(); } } value = StringUtils.HtmlDecode(value); filePath = filePath.Replace(element, value); } if (filePath.Contains("//")) { filePath = Regex.Replace(filePath, @"(/)\1{2,}", "/"); filePath = filePath.Replace("//", "/"); } if (filePath.Contains("(")) { regex = @"(?<element>\([^\)]+\))"; elements = RegexUtils.GetContents("element", regex, filePath); foreach (var element in elements) { if (!element.Contains("|")) { continue; } var value = element.Replace("(", string.Empty).Replace(")", string.Empty); var value1 = value.Split('|')[0]; var value2 = value.Split('|')[1]; value = value1 + value2; if (!string.IsNullOrEmpty(value1) && !string.IsNullOrEmpty(value1)) { value = value1; } filePath = filePath.Replace(element, value); } } return(filePath); }
public static void Translate(SiteInfo siteInfo, int channelId, int contentId, int targetSiteId, int targetChannelId, ETranslateContentType translateType) { if (siteInfo == null || channelId <= 0 || contentId <= 0 || targetSiteId <= 0 || targetChannelId <= 0) { return; } var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); var targetTableName = ChannelManager.GetTableName(targetSiteInfo, targetChannelId); var channelInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentInfo = DataProvider.ContentDao.GetContentInfo(tableName, contentId); if (contentInfo == null) { return; } if (translateType == ETranslateContentType.Copy) { FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString()); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, theContentId)); } catch (Exception ex) { LogUtils.AddErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } } CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, theContentId); } else if (translateType == ETranslateContentType.Cut) { FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Cut.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Cut.ToString()); var newContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); DataProvider.ContentDao.DeleteContents(siteInfo.Id, tableName, TranslateUtils.ToIntList(contentId), channelId); DataProvider.ChannelDao.UpdateContentNum(siteInfo, channelId, true); DataProvider.ChannelDao.UpdateContentNum(targetSiteInfo, targetChannelId, true); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, newContentId)); } catch (Exception ex) { LogUtils.AddErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } try { service.OnContentDeleteCompleted(new ContentEventArgs(siteInfo.Id, channelInfo.Id, contentId)); } catch (Exception ex) { LogUtils.AddErrorLog(service.PluginId, ex, nameof(service.OnContentDeleteCompleted)); } } CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, newContentId); } else if (translateType == ETranslateContentType.Reference) { if (contentInfo.ReferenceId != 0) { return; } contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.ReferenceId = contentId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString()); DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); } else if (translateType == ETranslateContentType.ReferenceContent) { if (contentInfo.ReferenceId != 0) { return; } FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.ReferenceId = contentId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.ReferenceContent.ToString()); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, theContentId)); } catch (Exception ex) { LogUtils.AddErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } } CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, theContentId); } }
//递归处理 private static string ParseChannelPath(SiteInfo siteInfo, int channelId, string channelFilePathRule) { var filePath = channelFilePathRule.Trim(); const string regex = "(?<element>{@[^}]+})"; var elements = RegexUtils.GetContents("element", regex, filePath); ChannelInfo nodeInfo = null; foreach (var element in elements) { var value = string.Empty; if (StringUtils.EqualsIgnoreCase(element, ChannelId)) { value = channelId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Year)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Year.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Month)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Month.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Day)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Day.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Hour)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Hour.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Minute)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Minute.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Second)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.AddDate.Second.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Sequence)) { value = StlChannelCache.GetSequence(siteInfo.Id, channelId).ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ParentRule)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } var parentInfo = ChannelManager.GetChannelInfo(siteInfo.Id, nodeInfo.ParentId); if (parentInfo != null) { var parentRule = GetChannelFilePathRule(siteInfo, parentInfo.Id); value = DirectoryUtils.GetDirectoryPath(ParseChannelPath(siteInfo, parentInfo.Id, parentRule)).Replace("\\", "/"); } } else if (StringUtils.EqualsIgnoreCase(element, ChannelName)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.ChannelName; } else if (StringUtils.EqualsIgnoreCase(element, LowerChannelName)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.ChannelName.ToLower(); } else if (StringUtils.EqualsIgnoreCase(element, LowerChannelIndex)) { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } value = nodeInfo.IndexName.ToLower(); } else { if (nodeInfo == null) { nodeInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); } var attributeName = element.Replace("{@", string.Empty).Replace("}", string.Empty); var isLower = false; if (StringUtils.StartsWithIgnoreCase(attributeName, "lower")) { isLower = true; attributeName = attributeName.Substring(5); } value = nodeInfo.Additional.GetString(attributeName); if (isLower) { value = value.ToLower(); } } filePath = filePath.Replace(element, value); } if (!filePath.Contains("//")) { return(filePath); } filePath = Regex.Replace(filePath, @"(/)\1{2,}", "/"); filePath = Regex.Replace(filePath, @"//", "/"); return(filePath); }