示例#1
0
        private SearchDocument FromPage(IPage page, EntityToken entityToken, Dictionary <Tuple <Guid, Guid>, List <IData> > allMetaData)
        {
            string label = page.MenuTitle;

            if (string.IsNullOrWhiteSpace(label))
            {
                label = page.Title;
            }

            bool   isPublished = page.DataSourceId.PublicationScope == PublicationScope.Published;
            string documentId  = GetDocumentId(page);

            var docBuilder = new SearchDocumentBuilder(_docBuilderExtensions);

            docBuilder.SetDataType(typeof(IPage));

            docBuilder.CrawlData(page);

            using (new DataConnection(page.DataSourceId.PublicationScope, page.DataSourceId.LocaleScope))
            {
                if (isPublished)
                {
                    docBuilder.Url = PageUrls.BuildUrl(page, UrlKind.Internal);
                }

                var placeholders = PageManager.GetPlaceholderContent(page.Id, page.VersionId);
                placeholders.ForEach(pl => docBuilder.CrawlData(pl, true));

                List <IData> metaData;

                if (allMetaData != null)
                {
                    allMetaData.TryGetValue(new Tuple <Guid, Guid>(page.Id, page.VersionId), out metaData);
                }
                else
                {
                    metaData = GetMetaData(page.Id, page.VersionId, page.DataSourceId.PublicationScope, page.DataSourceId.LocaleScope);
                }

                try
                {
                    metaData?.ForEach(pageMetaData => docBuilder.CrawlData(pageMetaData));
                }
                catch (Exception ex)
                {
                    Log.LogWarning(LogTitle, ex);
                }
            }

            if (!string.IsNullOrEmpty(page.UrlTitle) &&
                !UrlFormattersPluginFacade.FormatUrl(page.Title, true).Equals(page.UrlTitle, StringComparison.OrdinalIgnoreCase) &&
                !UrlFormattersPluginFacade.FormatUrl(page.Title, false).Equals(page.UrlTitle, StringComparison.OrdinalIgnoreCase))
            {
                docBuilder.TextParts.Add(page.UrlTitle);
            }

            return(docBuilder.BuildDocument(Name, documentId, label, null, entityToken));
        }
示例#2
0
        public static string GetUrlFromTitle(string title)
        {
            const string autoRemoveChars = @",./\?#!""@+'`´*():;$%&=¦§";
            var          generated       = new StringBuilder();

            foreach (char c in title.Where(c => autoRemoveChars.IndexOf(c) == -1))
            {
                generated.Append(c);
            }

            string url = generated.ToString().Replace(' ', '-');

            return(UrlFormattersPluginFacade.FormatUrl(url, false));
        }
示例#3
0
 private static string StringToUrlPart(string partnerName)
 {
     return(UrlFormattersPluginFacade.FormatUrl(partnerName, true));
 }
示例#4
0
 private string GenerateUrlTitleFromTitle(string title)
 {
     return(UrlFormattersPluginFacade.FormatUrl(title.Trim(), false));
 }
示例#5
0
        public PageUrlSet BuildUrlSet(IPage page, Guid parentPageId)
        {
            Verify.ArgumentNotNull(page, "page");
            Verify.ArgumentCondition(page.DataSourceId.PublicationScope == _publicationScope, "page", "Page belongs to a wrong publication scope");
            Verify.ArgumentCondition(page.DataSourceId.LocaleScope.Name == _localizationScope.Name, "page", "Page belongs to a wrong localization scope");

            DataScopeIdentifier dataScopeIdentifier = page.DataSourceId.DataScopeIdentifier;
            CultureInfo         cultureInfo         = page.DataSourceId.LocaleScope;

            string parentPath;

            IHostnameBinding appliedHostnameBinding = null;

            // Checking if it is a root-level page
            if (parentPageId == Guid.Empty)
            {
                parentPath = GetRootPageBaseUrl(page.Id, cultureInfo, out appliedHostnameBinding);
            }
            else
            {
                Verify.That(_folderPaths.ContainsKey(parentPageId), "Method BuildUrlInternal() should be called for parent page before running for childildren, so 'urlBuildingCache' parameter will contains parent pages data.");
                parentPath = _folderPaths[parentPageId];
            }

            // Building folderPath & lookup url
            string lookupUrl, folderPath;

            if (page.UrlTitle == string.Empty ||
                (appliedHostnameBinding != null &&
                 !appliedHostnameBinding.IncludeHomePageInUrl &&
                 appliedHostnameBinding.HomePageId == page.Id))
            {
                // Extensionless root url
                lookupUrl = folderPath = (parentPath == "" ? "/" : parentPath);
            }
            else
            {
                string parentPathWithSlash = parentPath + (parentPath.EndsWith("/") ? "" : "/");

                string urlTitle = page.UrlTitle;

#if URLDEBUG
                urlTitle = UrlFormattersPluginFacade.FormatUrl(urlTitle, true);
#endif

                folderPath = parentPathWithSlash + urlTitle;
                lookupUrl  = folderPath + UrlSuffix;
            }


            _folderPaths.Add(page.Id, folderPath);

            string lookupUrlLowerCased = lookupUrl.ToLowerInvariant();

            if (UrlToIdLookupLowerCased.ContainsKey(lookupUrlLowerCased))
            {
                if (!_knownNotUniqueUrls.Contains(lookupUrlLowerCased))
                {
                    lock (_knownNotUniqueUrls)
                    {
                        _knownNotUniqueUrls.Add(lookupUrlLowerCased);
                    }
                    Log.LogError(LogTitle, "Multiple pages share the same path '{0}'. Page ID: '{1}'. Duplicates are ignored.".FormatWith(lookupUrlLowerCased, page.Id));
                }
                return(null);
            }

            UrlToIdLookupLowerCased.Add(lookupUrlLowerCased, page.Id);
            UrlToIdLookup.Add(lookupUrl, page.Id);
            IdToUrlLookup.Add(page.Id, lookupUrl);


            // Building redirect folder path & url

            string redirectParentPath = (parentPageId == Guid.Empty)
                                            ? GetRedirectBaseUrl(cultureInfo)
                                            : _redirectFolderPaths[parentPageId];

            if (redirectParentPath != null)
            {
                string redirectLookupUrl;
                string redirectFolderPath;



                if (!page.UrlTitle.IsNullOrEmpty())
                {
                    string parentPathWithTrailingSlash = redirectParentPath + (redirectParentPath.EndsWith("/") ? "" : "/");
                    redirectFolderPath = parentPathWithTrailingSlash + page.UrlTitle;
                    redirectLookupUrl  = redirectFolderPath + UrlSuffix;
                }
                else
                {
                    redirectLookupUrl = redirectFolderPath = redirectParentPath;
                }

                if (redirectLookupUrl != lookupUrl || UrlSuffix == string.Empty)
                {
                    _redirectFolderPaths.Add(page.Id, redirectFolderPath);

                    string redirectLookupUrlLowerCased = redirectLookupUrl.ToLowerInvariant();

                    if (redirectLookupUrlLowerCased != lookupUrlLowerCased)
                    {
                        if (!RedirectUrlToIdLookupLowerCased.ContainsKey(redirectLookupUrlLowerCased))
                        {
                            RedirectUrlToIdLookupLowerCased.Add(redirectLookupUrlLowerCased, page.Id);
                        }
                    }

                    if (UrlSuffix == string.Empty)
                    {
                        string aspxExtensionRedirectUrl = redirectLookupUrlLowerCased + ".aspx";

                        if (!RedirectUrlToIdLookupLowerCased.ContainsKey(aspxExtensionRedirectUrl))
                        {
                            RedirectUrlToIdLookupLowerCased.Add(aspxExtensionRedirectUrl, page.Id);
                        }
                    }
                }
            }


            string url = lookupUrl;

            if (_forceRelativeUrls)
            {
                url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_RelativeUrl);
            }

            if (dataScopeIdentifier.Name == DataScopeIdentifier.AdministratedName)
            {
                url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_Unpublished);
            }

            var pageUrls = new PageUrlSet {
                PublicUrl = url
            };

            if (!string.IsNullOrEmpty(page.FriendlyUrl))
            {
                string friendlyUrl           = _friendlyUrlPrefix + MakeRelativeUrl(page.FriendlyUrl);
                string lowerCasedFriendlyUrl = friendlyUrl.ToLowerInvariant();

                if (!FriendlyUrlToIdLookup.ContainsKey(lowerCasedFriendlyUrl))
                {
                    pageUrls.FriendlyUrl = friendlyUrl;
                    FriendlyUrlToIdLookup.Add(lowerCasedFriendlyUrl, page.Id);
                }

                if (_friendlyUrlPrefixWithLanguageCode != null)
                {
                    string alternativeFriendlyUrl = (_friendlyUrlPrefixWithLanguageCode + MakeRelativeUrl(page.FriendlyUrl)).ToLowerInvariant();
                    if (!FriendlyUrlToIdLookup.ContainsKey(alternativeFriendlyUrl))
                    {
                        FriendlyUrlToIdLookup.Add(alternativeFriendlyUrl, page.Id);
                    }
                }
            }

            return(pageUrls);
        }
示例#6
0
 private static string LabelToUrlPart(string label, bool allowDataLoss)
 {
     return(allowDataLoss
         ? UrlFormattersPluginFacade.FormatUrl(label, true)
         : UrlUtils.EncodeUrlInvalidCharacters(label));
 }
示例#7
0
        private void ValidateSave(object sender, ConditionalEventArgs e)
        {
            var selectedPage = GetBinding <IPage>("SelectedPage");

            selectedPage.MenuTitle   = selectedPage.MenuTitle ?? string.Empty;
            selectedPage.FriendlyUrl = selectedPage.FriendlyUrl ?? string.Empty;

            TrimFieldValues(selectedPage);

            if (!FieldHasValidLength(selectedPage.Title, "Title", 255) ||
                !FieldHasValidLength(selectedPage.MenuTitle, "MenuTitle", 64) ||
                !FieldHasValidLength(selectedPage.UrlTitle, "UrlTitle", 64) ||
                !FieldHasValidLength(selectedPage.FriendlyUrl, "FriendlyUrl", 64))
            {
                e.Result = false;
                return;
            }

            e.Result = true;

            var processedUrlTitle = UrlFormattersPluginFacade.FormatUrl(selectedPage.UrlTitle, true);

            if (selectedPage.UrlTitle != processedUrlTitle)
            {
                RerenderView();
                selectedPage.UrlTitle = processedUrlTitle;
                ShowMessage(DialogType.Message,
                            GetText("EditPage.UrlTitleFormattedTitle"),
                            (GetText("EditPage.UrlTitleFormattedMessage") ?? string.Empty).FormatWith(processedUrlTitle));
            }

            var siblingPageUrlTitles =
                (from page in PageServices.GetChildren(selectedPage.GetParentId())
                 where page.Id != selectedPage.Id
                 select page.UrlTitle).ToList();

            foreach (var siblingUrlTitle in siblingPageUrlTitles)
            {
                if (siblingUrlTitle.Equals(selectedPage.UrlTitle, StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowFieldMessage("SelectedPage.UrlTitle", "${Composite.Plugins.PageElementProvider, UrlTitleNotUniqueError}");
                    e.Result = false;
                    break;
                }
            }

            if (string.IsNullOrEmpty(selectedPage.FriendlyUrl) == false)
            {
                var usedFriendlyUrls = DataFacade.GetData <IPage>(f => f.FriendlyUrl != null && f.FriendlyUrl != string.Empty && f.Id != selectedPage.Id).Select(f => f.FriendlyUrl).ToList();

                if (usedFriendlyUrls.Any(f => f.Equals(selectedPage.FriendlyUrl, StringComparison.InvariantCultureIgnoreCase)))
                {
                    ShowFieldMessage("SelectedPage.FriendlyUrl", "${Composite.Plugins.PageElementProvider, FriendlyUrlNotUniqueError}");
                    e.Result = false;
                }
            }

            if (string.IsNullOrEmpty(selectedPage.Title))
            {
                ShowFieldMessage("SelectedPage.Title", "${Composite.Plugins.PageElementProvider, TitleMissingError}");
                e.Result = false;
            }

            var validationResults = ValidationFacade.Validate(selectedPage);

            if (!validationResults.IsValid)
            {
                if (validationResults.Any(f => f.Key == "UrlTitle"))
                {
                    ShowFieldMessage("SelectedPage.UrlTitle", "${Composite.Plugins.PageElementProvider, UrlTitleNotValidError}");
                    e.Result = false;
                }

                foreach (var validationResult in validationResults.Where(f => f.Key != "UrlTitle"))
                {
                    ShowFieldMessage("SelectedPage." + validationResult.Key, validationResult.Message);
                }
            }

            if (!ValidateBindings())
            {
                e.Result = false;
            }
        }