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); } }
public static string GetSitePath(int siteId, params string[] paths) { return(GetSitePath(SiteManager.GetSiteInfo(siteId), paths)); }
//public static VisualInfo GetInstance() //{ // var siteId = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["s"]); ; // var channelId = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["n"]); ; // var contentId = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["c"]); // var fileTemplateId = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["f"]); // var pageIndex = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["p"]); // var previewId = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["previewId"]);//编辑界面预览 // return GetInstance(siteId, channelId, contentId, fileTemplateId, pageIndex, previewId); //} public static VisualInfo GetInstance(int siteId, int channelId, int contentId, int fileTemplateId, int pageIndex, int previewId) { var visualInfo = new VisualInfo { SiteId = siteId, ChannelId = channelId, ContentId = contentId, FileTemplateId = fileTemplateId, PageIndex = pageIndex }; if (visualInfo.SiteId == 0) { visualInfo.SiteId = PathUtility.GetCurrentSiteId(); } if (previewId > 0) { visualInfo.IsPreview = true; visualInfo.ContentId = previewId; } if (visualInfo.ChannelId > 0) { visualInfo.TemplateType = TemplateType.ChannelTemplate; } if (visualInfo.ContentId > 0 || visualInfo.IsPreview) { visualInfo.TemplateType = TemplateType.ContentTemplate; } if (visualInfo.FileTemplateId > 0) { visualInfo.TemplateType = TemplateType.FileTemplate; } if (visualInfo.ChannelId == 0) { visualInfo.ChannelId = visualInfo.SiteId; } var siteInfo = SiteManager.GetSiteInfo(visualInfo.SiteId); if (visualInfo.TemplateType == TemplateType.IndexPageTemplate) { var templateInfo = TemplateManager.GetIndexPageTemplateInfo(visualInfo.SiteId); var isHeadquarters = siteInfo.IsRoot; visualInfo.FilePath = PathUtility.GetIndexPageFilePath(siteInfo, templateInfo.CreatedFileFullName, isHeadquarters, visualInfo.PageIndex); } else if (visualInfo.TemplateType == TemplateType.ChannelTemplate) { visualInfo.FilePath = PathUtility.GetChannelPageFilePath(siteInfo, visualInfo.ChannelId, visualInfo.PageIndex); } else if (visualInfo.TemplateType == TemplateType.ContentTemplate) { visualInfo.FilePath = PathUtility.GetContentPageFilePath(siteInfo, visualInfo.ChannelId, visualInfo.ContentId, visualInfo.PageIndex); } else if (visualInfo.TemplateType == TemplateType.FileTemplate) { var templateInfo = TemplateManager.GetFileTemplateInfo(visualInfo.SiteId, visualInfo.FileTemplateId); visualInfo.FilePath = PathUtility.MapPath(siteInfo, templateInfo.CreatedFileFullName); } return(visualInfo); }
/// <summary> /// 对GetContentUrlByID的优化 /// 通过传入参数contentInfoCurrent,避免对ContentInfo查询太多 /// </summary> private static string GetContentUrlById(SiteInfo siteInfo, IContentInfo contentInfoCurrent, bool isLocal) { if (contentInfoCurrent == null) { return(PageUtils.UnclickedUrl); } if (isLocal) { return(ApiRoutePreview.GetContentUrl(siteInfo.Id, contentInfoCurrent.ChannelId, contentInfoCurrent.Id)); } var sourceId = contentInfoCurrent.SourceId; var referenceId = contentInfoCurrent.ReferenceId; var linkUrl = contentInfoCurrent.GetString(ContentAttribute.LinkUrl); var channelId = contentInfoCurrent.ChannelId; 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, false)); } var siteInfoTmp = SiteManager.GetSiteInfo(contentInfo.SiteId); return(GetContentUrlById(siteInfoTmp, contentInfo, false)); } else { var tableName = ChannelManager.GetTableName(siteInfo, channelId); channelId = StlContentCache.GetChannelId(tableName, referenceId); linkUrl = StlContentCache.GetValue(tableName, referenceId, ContentAttribute.LinkUrl); if (ChannelManager.IsExists(siteInfo.Id, channelId)) { return(GetContentUrlById(siteInfo, channelId, referenceId, 0, 0, linkUrl, false)); } var targetSiteId = StlChannelCache.GetSiteId(channelId); var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); return(GetContentUrlById(targetSiteInfo, channelId, referenceId, 0, 0, linkUrl, false)); } } if (!string.IsNullOrEmpty(linkUrl)) { return(ParseNavigationUrl(siteInfo, linkUrl, false)); } var contentUrl = PathUtility.ContentFilePathRules.Parse(siteInfo, channelId, contentInfoCurrent); return(GetSiteUrl(siteInfo, contentUrl, false)); }
public static string ParseNavigationUrl(int publishmentSystemId, string url, bool isLocal) { var siteInfo = SiteManager.GetSiteInfo(publishmentSystemId); return(ParseNavigationUrl(siteInfo, url, isLocal)); }