Exemplo n.º 1
0
        private bool ValidatePageUrlSettings(PageSettings pageSettings, TabInfo tab, ref string invalidField, ref string errorMessage)
        {
            var portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var urlPath        = !string.IsNullOrEmpty(pageSettings.Url) ? pageSettings.Url.TrimStart('/') : string.Empty;

            if (string.IsNullOrEmpty(urlPath))
            {
                return(true);
            }

            bool modified;
            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                errorMessage = Localization.GetString("UrlPathCleaned");
                invalidField = "url";
                return(false);
            }

            //Validate for uniqueness
            FriendlyUrlController.ValidateUrl(urlPath, tab?.TabID ?? Null.NullInteger, portalSettings, out modified);
            if (modified)
            {
                errorMessage = Localization.GetString("UrlPathNotUnique");
                invalidField = "url";
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public string CleanTabUrl(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(url);
            }

            var  urlPath = url.TrimStart('/');
            bool modified;

            var portalSettings      = PortalController.Instance.GetCurrentPortalSettings();
            var friendlyUrlSettings = new FriendlyUrlSettings(portalSettings.PortalId);

            urlPath = UrlRewriterUtils.CleanExtension(urlPath, friendlyUrlSettings, string.Empty);

            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(friendlyUrlSettings));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);

            return('/' + urlPath);
        }
        public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto)
        {
            var  urlPath = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId)));

            //now clean the path
            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error", Localization.GlobalResourceFile),
                    SuggestedUrlPath = "/" + urlPath
                }));
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified);
            if (modified)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile),
                    SuggestedUrlPath = "/" + urlPath
                }));
            }

            var tab         = PortalSettings.ActiveTab;
            var cultureCode = LocaleController.Instance.GetLocales(PortalId)
                              .Where(l => l.Value.KeyID == dto.LocaleKey)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault();

            if (dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture) == "200")
            {
                //We need to check if we are updating a current url or creating a new 200
                var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id &&
                                                         t.HttpStatus == "200");
                if (tabUrl == null)
                {
                    //Just create Url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                        IsSystem    = dto.IsSystem              // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
                }
                else
                {
                    //Change the original 200 url to a redirect
                    tabUrl.HttpStatus = "301";
                    tabUrl.SeqNum     = dto.Id;
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);

                    //Add new custom url
                    tabUrl.Url        = dto.Path.ValueOrEmpty();
                    tabUrl.HttpStatus = "200";
                    tabUrl.SeqNum     = tab.TabUrls.Max(t => t.SeqNum) + 1;
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
                }
            }
            else
            {
                //Just update the url
                var tabUrl = new TabUrlInfo
                {
                    TabId            = tab.TabID,
                    SeqNum           = dto.Id,
                    PortalAliasId    = dto.SiteAliasKey,
                    PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                    QueryString      = dto.QueryString.ValueOrEmpty(),
                    Url         = dto.Path.ValueOrEmpty(),
                    CultureCode = cultureCode,
                    HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                    IsSystem    = dto.IsSystem                  // false
                };
                TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
            }


            var response = new
            {
                Success = true,
            };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
 public FriendlyUrlOptions GetExtendOptionsForURLs(int portalId)
 {
     return(UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalId))));
 }
Exemplo n.º 5
0
        public PageUrlResult CreateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var  portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var  urlPath        = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == dto.Path.ValueOrEmpty().ToLowerInvariant() &&
                                (u.PortalAliasId == dto.SiteAliasKey || u.PortalAliasId == -1)))
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("DuplicateUrl.Error")
                });
            }

            var seqNum        = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1;
            var portalLocales = LocaleController.Instance.GetLocales(portalSettings.PortalId);
            var cultureCode   = portalLocales.Where(l => l.Value.KeyID == dto.LocaleKey)
                                .Select(l => l.Value.Code)
                                .SingleOrDefault();

            var portalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;

            if (portalAliasUsage == PortalAliasUsageType.Default)
            {
                var alias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId)
                            .SingleOrDefault(a => a.PortalAliasID == dto.SiteAliasKey);

                if (string.IsNullOrEmpty(cultureCode) || alias == null)
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error")
                    });
                }
            }
            else
            {
                var cultureAlias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId)
                                   .FirstOrDefault(a => a.CultureCode == cultureCode);

                if (portalLocales.Count > 1 && !portalSettings.ContentLocalizationEnabled && (string.IsNullOrEmpty(cultureCode) || cultureAlias == null))
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error")
                    });
                }
            }

            var tabUrl = new TabUrlInfo
            {
                TabId            = tab.TabID,
                SeqNum           = seqNum,
                PortalAliasId    = dto.SiteAliasKey,
                PortalAliasUsage = portalAliasUsage,
                QueryString      = dto.QueryString.ValueOrEmpty(),
                Url         = dto.Path.ValueOrEmpty(),
                CultureCode = cultureCode,
                HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                IsSystem    = false
            };

            TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

            return(new PageUrlResult
            {
                Success = true,
                Id = seqNum // returns Id of the created Url
            });
        }
Exemplo n.º 6
0
        public PageUrlResult UpdateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var  portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var  urlPath        = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options =
                UrlRewriterUtils.ExtendOptionsForCustomURLs(
                    UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            //now clean the path
            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, tab.TabID, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            var cultureCode = LocaleController.Instance.GetLocales(portalSettings.PortalId)
                              .Where(l => l.Value.KeyID == dto.LocaleKey)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault() ?? portalSettings.DefaultLanguage;

            var statusCodeKey = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture);
            var tabUrl        = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == statusCodeKey);

            if (statusCodeKey == "200")
            {
                //We need to check if we are updating a current url or creating a new 200
                if (tabUrl == null)
                {
                    //Just create Url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = "200",
                        IsSystem    = dto.IsSystem // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    if (!tabUrl.Url.Equals("/" + urlPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //Change the original 200 url to a redirect
                        tabUrl.HttpStatus = "301";
                        tabUrl.SeqNum     = dto.Id;
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

                        //Add new custom url
                        tabUrl.Url              = dto.Path.ValueOrEmpty();
                        tabUrl.HttpStatus       = "200";
                        tabUrl.SeqNum           = tab.TabUrls.Max(t => t.SeqNum) + 1;
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                    else
                    {
                        //Update the original 200 url
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                }
            }
            else
            {
                //Update the original non 200 url
                if (tabUrl == null)
                {
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = statusCodeKey,
                        IsSystem    = dto.IsSystem // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    tabUrl.CultureCode      = cultureCode;
                    tabUrl.PortalAliasId    = dto.SiteAliasKey;
                    tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                    tabUrl.Url         = dto.Path.ValueOrEmpty();
                    tabUrl.HttpStatus  = statusCodeKey;
                    tabUrl.QueryString = dto.QueryString.ValueOrEmpty();
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
            }


            return(new PageUrlResult
            {
                Success = true
            });
        }
        private Outcome UpdateTabUrl(TabInfo tab, int portalId, string fieldValue)
        {
            var portalSettings = new PortalSettings(portalId);

            var urlPath = fieldValue.ValueOrEmpty().TrimStart('/');

            bool modified;
            // Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new Outcome()
                {
                    Success = false,
                    ErrorMessage = Constants.ERROR_PAGE_URL_VALUE, //CustomUrlPathCleaned
                    Suggestion = string.Concat(Constants.SLASH, urlPath)
                });
            }

            // Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified);
            if (modified)
            {
                return(new Outcome()
                {
                    Success = false,
                    ErrorMessage = Constants.ERROR_PAGE_URL_NOT_UNIQUE, //UrlPathNotUnique
                    Suggestion = string.Concat(Constants.SLASH, urlPath)
                });
            }


            if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == urlPath.ValueOrEmpty().ToLowerInvariant() &&
                                (u.PortalAliasId == portalSettings.PrimaryAlias.PortalAliasID || u.PortalAliasId == -1)))
            {
                return(new Outcome
                {
                    Success = false,
                    ErrorMessage = Constants.ERROR_PAGE_URL_DUPLICATE, //DuplicateUrl
                    Suggestion = string.Concat(Constants.SLASH, urlPath)
                });
            }

            var seqNum = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1;

            var tabUrl = new TabUrlInfo
            {
                TabId            = tab.TabID,
                SeqNum           = seqNum,
                PortalAliasId    = portalSettings.PrimaryAlias.PortalAliasID,
                PortalAliasUsage = PortalAliasUsageType.Default,
                QueryString      = string.Empty,
                Url         = urlPath.ValueOrEmpty(),
                CultureCode = portalSettings.CultureCode,
                HttpStatus  = Constants.RESPONSE_STATUS_200,
                IsSystem    = false,
            };

            TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
            //tab.Url = fieldValue;
            return(new Outcome
            {
                Success = true,
                ErrorMessage = string.Empty,
                Suggestion = string.Empty
            });
        }