public virtual IEnumerable <IMenuEntryViewModel> MapStickyMainMenuItems(List <StickyHeader> mainMenuItems) { return(mainMenuItems.OrderBy(el => el.Order).Select(li => new HomeStickyLinkViewModel() { DisplayName = li.DisplayName, Url = _analyticsNavigationUrlHelper.BuildUrl(li, GoogleAnalyticsNavigationUrlProvider.MenuOrigin.Sticky), UrlTarget = C1Helper.GetUrlTargetValue(li.Target) }).ToList()); }
public virtual IEnumerable <IMenuEntryViewModel> MapFooterOptionalLinksItems(List <FooterOptionalLink> optionalLinksItems) { return(optionalLinksItems.OrderBy(el => el.Order).Select(li => new OptionalLinkEntryViewModel() { DisplayName = li.DisplayName, Url = _analyticsNavigationUrlHelper.BuildUrl(li, GoogleAnalyticsNavigationUrlProvider.MenuOrigin.Footer), UrlTarget = C1Helper.GetUrlTargetValue(li.Target), CssClass = C1Helper.GetCssStyleValue(li.CssStyle) }).ToList()); }
public virtual IEnumerable <IFooterEntryViewModel> MapFooterItems(List <Footer> footer, Guid?parentId = null) { return(footer.Where(x => x.ParentId == parentId && C1Helper.IsUrlPagePublished(x.Url)).OrderBy(el => el.Order).Select(li => new FooterEntryViewModel() { DisplayName = li.DisplayName, Url = _analyticsNavigationUrlHelper.BuildUrl(li, footer, GoogleAnalyticsNavigationUrlProvider.MenuOrigin.Footer), CssClass = C1Helper.GetCssStyleValue(li.CssStyle), UrlTarget = C1Helper.GetUrlTargetValue(li.Target), Children = MapFooterItems(footer, li.Id) }).ToList()); }
public virtual HomeNavigationImageViewModel MapNavigationImage(NavigationImage navigationImage) { if (navigationImage == null) { return(new HomeNavigationImageViewModel()); } return(new HomeNavigationImageViewModel() { ImageLabel = navigationImage.ImageLabel, ImageSource = C1Helper.GetMediaUrl(navigationImage.ImageSource), ImageUrl = navigationImage.ImageUrl, ImageUrlTarget = C1Helper.GetUrlTargetValue(navigationImage.Target) }); }
public virtual IEnumerable <IMenuEntryViewModel> MapMainMenuItems(List <MainMenu> mainMenuItems, Guid?parentId = null) { return(mainMenuItems .Where(x => x.ParentId == parentId && C1Helper.IsUrlPagePublished(x.Url)) .OrderBy(el => el.Order) .Select(li => new HomeMainMenuEntryViewModel() { DisplayName = li.DisplayName, Url = _analyticsNavigationUrlHelper.BuildUrl(li, mainMenuItems, GoogleAnalyticsNavigationUrlProvider.MenuOrigin.Dropdown), Image = MapNavigationImage(GetNavigationImage(li.Id, new CultureInfo(li.SourceCultureName))), CssClass = C1Helper.GetCssStyleValue(li.CssStyle), UrlTarget = C1Helper.GetUrlTargetValue(li.Target), Children = MapMainMenuItems(mainMenuItems, li.Id), MenuType = MenuTypeEnum.Principal }).ToList()); }
public virtual string Get404PageUrl(string requestedPath) { if (requestedPath == null) { throw new ArgumentNullException(nameof(requestedPath)); } var pageUrlData = C1Helper.GetPageUrlDataFromUrl(requestedPath); var websiteId = C1Helper.GetWebsiteIdFromPageUrlData(pageUrlData); if (pageUrlData == null || websiteId == Guid.Empty) { return(null); } var pagesConfiguration = SiteConfiguration.GetPagesConfiguration(pageUrlData.LocalizationScope, websiteId); if (pagesConfiguration.PageNotFoundPageId != Guid.Empty) { var pageUrl = PageService.GetPageUrl(pagesConfiguration.PageNotFoundPageId, pageUrlData.LocalizationScope); if (pageUrl == null) { Log.LogWarning("PageNotFoundUrlProvider", $"404 Page is not configured for website id {pageUrlData.PageId} and culture {pageUrlData.LocalizationScope}. " + $"Requested path: {requestedPath}"); return(PageService.GetPageUrl(pagesConfiguration.HomePageId, pageUrlData.LocalizationScope)); } var urlBuilder = new UrlBuilder(pageUrl) { [ErrorPathQuerystringName] = HttpUtility.UrlEncode(requestedPath) }; return(urlBuilder.ToString()); } else { return(null); } }
private void OnBeginRequest(object sender, EventArgs args) { var context = ((HttpApplication)sender).Context; var url = context.Request.Url; var siteConfiguration = ServiceLocator.GetService <ISiteConfiguration>(); var urlPathSegments = url.Segments.Skip(1).Select(s => s.TrimEnd('/')).ToList(); //always skip the first segment, since it's always the first dash var newUrl = string.Empty; try { /** * Logic below identifies the type of page that is being accessed, based on the path segments that are identified, and then applies a redirect * to the URL which is mapped to a page controller. * For instance, a product page is identified because one of the path segments starts with "p-" and has at least 1 subsequent path (for the product id), * and is then redirected to the product page with the product/variant id sent as query strings. * A store page is identified with one of the segments starting with "s-" and has 1 subsequent path (for the store number). * * Note that this method of redirection creates a hard dependency the cutlure being explicitly passed in the URL. To account for this, we ASSUME * that the culture is always passed as the first parameters in URL. * This assumption is based on the ProductUrlProvider and StoreUrlProvider classes, which are responsbile for building these URLs. * */ int pathPatternIndex = -1; if ((pathPatternIndex = GetUrlPathIndexForSpecificPagePattern(urlPathSegments, ProductUrlPathIndicatorRegex)) > -1) { var pageUrlData = C1Helper.GetPageUrlDataFromUrl(url.ToString()); var websiteId = siteConfiguration.GetWebsiteByPageId(pageUrlData.PageId); var pagesConfiguration = siteConfiguration.GetPagesConfiguration(pageUrlData.LocalizationScope, websiteId); var productPageUrl = _pageService.GetPageUrl(pagesConfiguration.ProductPageId, pageUrlData.LocalizationScope); string productId = urlPathSegments.ElementAtOrDefault(pathPatternIndex + 1); //product Id is always in the path after the product path indicator string variantId = urlPathSegments.ElementAtOrDefault(pathPatternIndex + 2); //variant Id is always in the path after the product id newUrl = UrlFormatter.AppendQueryString(productPageUrl, new NameValueCollection(context.Request.QueryString) { { "id", productId }, { "variantId", variantId } }); } else if ((pathPatternIndex = GetUrlPathIndexForSpecificPagePattern(urlPathSegments, StoreUrlPathIndicatorRegex)) > -1) { var pageUrlData = C1Helper.GetPageUrlDataFromUrl(url.ToString()); var websiteId = siteConfiguration.GetWebsiteByPageId(pageUrlData.PageId); var pagesConfiguration = siteConfiguration.GetPagesConfiguration(pageUrlData.LocalizationScope, websiteId); var storePageUrl = _pageService.GetPageUrl(pagesConfiguration.StorePageId, pageUrlData.LocalizationScope); string storeNumber = urlPathSegments.ElementAtOrDefault(pathPatternIndex + 1); newUrl = UrlFormatter.AppendQueryString(storePageUrl, new NameValueCollection { { "storeNumber", storeNumber } }); } else { return; } } catch (Exception ex) { LoggingService.LogError("Composer Url Rewrite Module", ex); throw new HttpException(404, "Could not redirect page"); } if (!string.IsNullOrEmpty(newUrl)) { context.RewritePath(newUrl); } }