public string TryGetUrl(EntityToken entityToken) { var dataEntityToken = entityToken as DataEntityToken; if (dataEntityToken == null) { return(null); } var data = dataEntityToken.Data; if (data == null) { return(null); } PageUrlData pageUrlData; var page = data as IPage; if (page != null) { pageUrlData = new PageUrlData(page); } else { pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference()); } return(pageUrlData != null?GetPagePreviewUrl(pageUrlData) : null); }
private SitemapEntry CreateSitemapEntryFromRelatedData(string baseUrl, IPageRelatedData relatedData) { var baseUrlWithoutEndSlash = baseUrl.TrimEnd('/'); var dataRef = relatedData.ToDataReference(); var pageUrlData = DataUrls.TryGetPageUrlData(dataRef); if (pageUrlData == null) { return(null); } var url = PageUrls.BuildUrl(pageUrlData).TrimStart('/'); return(new SitemapEntry { Location = $"{baseUrlWithoutEndSlash}/{url}", }); }
public string ToPublicUrl(string internalDataUrl, UrlSpace urlSpace) { object keyValue = ExtractKeyValue(internalDataUrl); if (keyValue == null) { return(null); } var data = DataFacade.TryGetDataByUniqueKey(_type, keyValue); if (data == null) { return(null); } var pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference()); return(pageUrlData != null?PageUrls.BuildUrl(pageUrlData, UrlKind.Public, urlSpace) : null); }
public string ToPublicUrl(string internalDataUrl, UrlSpace urlSpace) { object keyValue = ExtractKeyValue(internalDataUrl); if (keyValue == null) { return(null); } var data = DataFacade.TryGetDataByUniqueKey(_type, keyValue); if (data == null) { return(null); } var pageUrlData = DataUrls.TryGetPageUrlData(data.ToDataReference()); if (internalDataUrl.IndexOf("?", StringComparison.Ordinal) > 0) { var parameters = new UrlBuilder(internalDataUrl).GetQueryParameters(); if (parameters.HasKeys()) { if (pageUrlData.QueryParameters == null) { pageUrlData.QueryParameters = parameters; } else { pageUrlData.QueryParameters.Add(parameters); } } } return(pageUrlData != null?PageUrls.BuildUrl(pageUrlData, UrlKind.Public, urlSpace) : null); }
private static IEnumerable <SearchResultEntry> SearchInType <T>(string[] keywords, bool currentWebsiteOnly) where T : class, IData { var stringFields = typeof(T).GetPropertiesRecursively() .Where(p => p.PropertyType == typeof(string) && p.ReflectedType != typeof(IPublishControlled) && p.ReflectedType != typeof(ILocalizedControlled) && p.ReflectedType != typeof(IPageMetaData) && !p.GetCustomAttributes <ForeignKeyAttribute>().Any()).ToList(); if (stringFields.Count == 0) { return(null); } Expression searchExpr = null; var parameter = Expression.Parameter(typeof(T), "p"); foreach (string keyword in keywords) { Expression keywordSearchExpr = null; foreach (var stringField in stringFields) { // Building the following expression: // p => (p.{stringField} != null && p.{stringField}.ToLower().Contains(keyword)) var propertyExpression = Expression.Property(parameter, stringField); var notNullExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, typeof(string))); var toLowerExpression = Expression.Call(propertyExpression, String_ToLower); var containsExpression = Expression.Call(toLowerExpression, String_Contains, new Expression[] { Expression.Constant(keyword) }); var andExpression = Expression.AndAlso(notNullExpression, containsExpression); keywordSearchExpr = keywordSearchExpr.OrElse(andExpression); } searchExpr = searchExpr.AndAlso(keywordSearchExpr); } if (searchExpr == null) { return(null); } var searchPredicate = Expression.Lambda <Func <T, bool> >(searchExpr, parameter); HashSet <Guid> pagesIdsOfCurrentSite = null; if (currentWebsiteOnly) { using (var c = new DataConnection()) { pagesIdsOfCurrentSite = new HashSet <Guid>(c.SitemapNavigator.CurrentPageNode .GetPageIds(SitemapScope.Level1AndDescendants)); } } var result = new List <SearchResultEntry>(); foreach (var data in DataFacade.GetData(searchPredicate)) { if (currentWebsiteOnly && data is IPageRelatedData && !pagesIdsOfCurrentSite.Contains((data as IPageRelatedData).PageId)) { continue; } var dataReference = data.ToDataReference(); string url; if (currentWebsiteOnly && !(data is IPageRelatedData)) { // Getting public url data to see if it is pointing to the website var pageUrlData = DataUrls.TryGetPageUrlData(dataReference); if (pageUrlData == null || !pagesIdsOfCurrentSite.Contains(pageUrlData.PageId)) { continue; } url = PageUrls.BuildUrl(pageUrlData); } else { url = InternalUrls.TryBuildInternalUrl(dataReference); } if (url == null) { continue; } string label = data.GetLabel(); // TODO: support for current website only for global data types result.Add(new SearchResultEntry { Url = url, Title = label }); } return(result); }