Пример #1
0
        public static void TransContentInfo(SiteInfo siteInfo, ChannelInfo channelInfo, int contentId, SiteInfo targetSiteInfo, int targetChannelId)
        {
            var targetTableName = ChannelManager.GetTableName(targetSiteInfo, targetChannelId);

            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);

            FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo);
            contentInfo.SiteId       = targetSiteInfo.Id;
            contentInfo.SourceId     = channelInfo.Id;
            contentInfo.ChannelId    = targetChannelId;
            contentInfo.IsChecked    = targetSiteInfo.Additional.IsCrossSiteTransChecked;
            contentInfo.CheckedLevel = 0;

            //复制
            if (Equals(channelInfo.Additional.TransDoneType, ETranslateContentType.Copy))
            {
                contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString());
            }
            //引用地址
            else if (Equals(channelInfo.Additional.TransDoneType, ETranslateContentType.Reference))
            {
                contentInfo.SiteId      = targetSiteInfo.Id;
                contentInfo.SourceId    = channelInfo.Id;
                contentInfo.ChannelId   = targetChannelId;
                contentInfo.ReferenceId = contentId;
                contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString());
            }
            //引用内容
            else if (Equals(channelInfo.Additional.TransDoneType, ETranslateContentType.ReferenceContent))
            {
                contentInfo.SiteId      = targetSiteInfo.Id;
                contentInfo.SourceId    = channelInfo.Id;
                contentInfo.ChannelId   = targetChannelId;
                contentInfo.ReferenceId = contentId;
                contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.ReferenceContent.ToString());
            }

            if (!string.IsNullOrEmpty(targetTableName))
            {
                DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, channelInfo, contentInfo);

                #region  制资源
                //资源:图片,文件,视频
                if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.ImageUrl)))
                {
                    //修改图片
                    var sourceImageUrl = PathUtility.MapPath(siteInfo, contentInfo.GetString(BackgroundContentAttribute.ImageUrl));
                    CopyReferenceFiles(targetSiteInfo, sourceImageUrl, siteInfo);
                }
                else if (!string.IsNullOrEmpty(contentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl))))
                {
                    var sourceImageUrls = TranslateUtils.StringCollectionToStringList(contentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl)));

                    foreach (string imageUrl in sourceImageUrls)
                    {
                        var sourceImageUrl = PathUtility.MapPath(siteInfo, imageUrl);
                        CopyReferenceFiles(targetSiteInfo, sourceImageUrl, siteInfo);
                    }
                }
                if (!string.IsNullOrEmpty(contentInfo.GetString(BackgroundContentAttribute.FileUrl)))
                {
                    //修改附件
                    var sourceFileUrl = PathUtility.MapPath(siteInfo, contentInfo.GetString(BackgroundContentAttribute.FileUrl));
                    CopyReferenceFiles(targetSiteInfo, sourceFileUrl, siteInfo);
                }
                else if (!string.IsNullOrEmpty(contentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl))))
                {
                    var sourceFileUrls = TranslateUtils.StringCollectionToStringList(contentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl)));

                    foreach (string fileUrl in sourceFileUrls)
                    {
                        var sourceFileUrl = PathUtility.MapPath(siteInfo, fileUrl);
                        CopyReferenceFiles(targetSiteInfo, sourceFileUrl, siteInfo);
                    }
                }
                #endregion
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
            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   = DateTime.MinValue;
                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 = Content.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 (addDate == DateTime.MinValue)
                        {
                            var tableName = ChannelManager.GetTableName(siteInfo, channelId);
                            addDate = Content.GetAddDate(tableName, contentId);
                        }

                        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);
            }
Пример #4
0
        //得到栏目经过计算后的连接地址
        public static string GetChannelUrl(SiteInfo siteInfo, ChannelInfo nodeInfo, bool isLocal)
        {
            if (isLocal)
            {
                return(ApiRoutePreview.GetChannelUrl(siteInfo.Id, nodeInfo.Id));
            }
            var url = string.Empty;

            if (nodeInfo != null)
            {
                if (nodeInfo.ParentId == 0)
                {
                    url = GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                }
                else
                {
                    var linkType = ELinkTypeUtils.GetEnumType(nodeInfo.LinkType);
                    if (linkType == ELinkType.None)
                    {
                        url = GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                    }
                    else if (linkType == ELinkType.NoLink)
                    {
                        url = PageUtils.UnclickedUrl;
                    }
                    else
                    {
                        if (linkType == ELinkType.NoLinkIfContentNotExists)
                        {
                            url = nodeInfo.ContentNum == 0 ? PageUtils.UnclickedUrl : GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                        }
                        else if (linkType == ELinkType.LinkToOnlyOneContent)
                        {
                            if (nodeInfo.ContentNum == 1)
                            {
                                var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
                                //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo);
                                var contentId = Content.GetContentId(tableName, nodeInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(nodeInfo.Additional.DefaultTaxisType)));
                                url = GetContentUrl(siteInfo, nodeInfo, contentId, false);
                            }
                            else
                            {
                                url = GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                            }
                        }
                        else if (linkType == ELinkType.NoLinkIfContentNotExistsAndLinkToOnlyOneContent)
                        {
                            if (nodeInfo.ContentNum == 0)
                            {
                                url = PageUtils.UnclickedUrl;
                            }
                            else if (nodeInfo.ContentNum == 1)
                            {
                                var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
                                var contentId = Content.GetContentId(tableName, nodeInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(nodeInfo.Additional.DefaultTaxisType)));
                                //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo);
                                url = GetContentUrl(siteInfo, nodeInfo, contentId, false);
                            }
                            else
                            {
                                url = GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                            }
                        }
                        else if (linkType == ELinkType.LinkToFirstContent)
                        {
                            if (nodeInfo.ContentNum >= 1)
                            {
                                var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
                                var contentId = Content.GetContentId(tableName, nodeInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(nodeInfo.Additional.DefaultTaxisType)));
                                //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo);
                                url = GetContentUrl(siteInfo, nodeInfo, contentId, false);
                            }
                            else
                            {
                                url = GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                            }
                        }
                        else if (linkType == ELinkType.NoLinkIfContentNotExistsAndLinkToFirstContent)
                        {
                            if (nodeInfo.ContentNum >= 1)
                            {
                                var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
                                var contentId = Content.GetContentId(tableName, nodeInfo.Id, ETaxisTypeUtils.GetContentOrderByString(ETaxisTypeUtils.GetEnumType(nodeInfo.Additional.DefaultTaxisType)));
                                //var contentId = StlCacheManager.FirstContentId.GetValue(siteInfo, nodeInfo);
                                url = GetContentUrl(siteInfo, nodeInfo, contentId, false);
                            }
                            else
                            {
                                url = PageUtils.UnclickedUrl;
                            }
                        }
                        else if (linkType == ELinkType.NoLinkIfChannelNotExists)
                        {
                            url = nodeInfo.ChildrenCount == 0 ? PageUtils.UnclickedUrl : GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                        }
                        else if (linkType == ELinkType.LinkToLastAddChannel)
                        {
                            var lastAddChannelInfo = Node.GetChannelInfoByLastAddDate(nodeInfo.Id);
                            url = lastAddChannelInfo != null?GetChannelUrl(siteInfo, lastAddChannelInfo, false) : GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                        }
                        else if (linkType == ELinkType.LinkToFirstChannel)
                        {
                            var firstChannelInfo = Node.GetChannelInfoByTaxis(nodeInfo.Id);
                            url = firstChannelInfo != null?GetChannelUrl(siteInfo, firstChannelInfo, false) : GetChannelUrlNotComputed(siteInfo, nodeInfo.Id, false);
                        }
                        else if (linkType == ELinkType.NoLinkIfChannelNotExistsAndLinkToLastAddChannel)
                        {
                            var lastAddChannelInfo = Node.GetChannelInfoByLastAddDate(nodeInfo.Id);
                            url = lastAddChannelInfo != null?GetChannelUrl(siteInfo, lastAddChannelInfo, false) : PageUtils.UnclickedUrl;
                        }
                        else if (linkType == ELinkType.NoLinkIfChannelNotExistsAndLinkToFirstChannel)
                        {
                            var firstChannelInfo = Node.GetChannelInfoByTaxis(nodeInfo.Id);
                            url = firstChannelInfo != null?GetChannelUrl(siteInfo, firstChannelInfo, false) : PageUtils.UnclickedUrl;
                        }
                    }
                }
            }
            return(url);
        }
Пример #5
0
        /// <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      = Node.GetSiteId(targetChannelId);
                    var targetSiteInfo    = SiteManager.GetSiteInfo(targetSiteId);
                    var targetChannelInfo = ChannelManager.GetChannelInfo(targetSiteId, targetChannelId);

                    var tableName   = ChannelManager.GetTableName(targetSiteInfo, targetChannelInfo);
                    var contentInfo = Content.GetContentInfo(tableName, 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 = Content.GetChannelId(tableName, referenceId);
                    linkUrl   = Content.GetValue(tableName, referenceId, ContentAttribute.LinkUrl);
                    if (ChannelManager.IsExists(siteInfo.Id, channelId))
                    {
                        return(GetContentUrlById(siteInfo, channelId, referenceId, 0, 0, linkUrl, false));
                    }
                    var targetSiteId   = Node.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));
        }
Пример #6
0
        //得到栏目经过计算后的连接地址
        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, true, 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, true, 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, true, 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, true, 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));
        }