protected override void PerformRedirect(string url)
        {
            if (Context.Site == null || Context.Database == null || Context.Database.Name == "core")
            {
                _logManager.LogError(string.Format("Attempting to redirect url {0}, but no Context Site or DB defined (or core db redirect attempted)", url), GetType());
                return;
            }

            // need to retrieve not found item to account for sites utilizing virtualFolder attribute
            var notFoundItem = Context.Database.GetItem(Context.Site.StartPath + Sitecore.Configuration.Settings.ItemNotFoundUrl);

            if (notFoundItem == null)
            {
                _logManager.LogError(string.Format("No 404 item found on site: {0}", Context.Site.Name), GetType());
                return;
            }

            var notFoundUrl = _baseLinkManager.GetItemUrl(notFoundItem);

            if (string.IsNullOrWhiteSpace(notFoundUrl))
            {
                _logManager.LogError(string.Format("Found 404 item for site, but no URL returned: {0}", Context.Site.Name), GetType());
                return;
            }

            _logManager.LogDebug(string.Format("Redirecting to {0}", notFoundUrl), GetType());

            if (Sitecore.Configuration.Settings.RequestErrors.UseServerSideRedirect)
            {
                HttpContext.Current.Server.TransferRequest(notFoundUrl);
                return;
            }

            WebUtil.Redirect(notFoundUrl, false);
        }
        public override object ResolveContents(Rendering rendering, IRenderingConfiguration renderingConfig)
        {
            var productsRoot = GetContextItem(rendering, renderingConfig);
            var products     = ProductRepository.GetProducts(productsRoot);

            return(new
            {
                // Use the inherited method to get the JSON serialized item, then reduce the returned fields
                Products = products.Select(item => new
                {
                    Item = item,
                    Serialized = base.ProcessItem(item, rendering, renderingConfig)
                })
                           .Select(product => new
                {
                    // Create object shape expected by ItemLinkField
                    Url = LinkManager.GetItemUrl(product.Item),
                    Id = product.Item.ID,
                    Fields = new
                    {
                        Title = product.Serialized[product.Item.Fields[Templates.Product.Fields.Title].Name],
                        ShortDescription = product.Serialized[product.Item.Fields[Templates.Product.Fields.ShortDescription].Name],
                        Image = product.Serialized[product.Item.Fields[Templates.Product.Fields.Image].Name]
                    }
                })
            });
        }
        /// <summary>
        /// Redirect On ItemNotFound
        /// </summary>
        /// <param name="url"></param>
        protected override void RedirectOnItemNotFound(string url)
        {
            var context = System.Web.HttpContext.Current;

            var settingSite = sites.Where(site => site.Equals(Sitecore.Context.GetSiteName(), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

            if (settingSite != null && Sitecore.Context.Database != null)
            {
                Item rootPage = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
                if (rootPage != null && rootPage.Versions.Count > 0)
                {
                    try
                    {
                        if (EnableLog)
                        {
                            Log(url);
                        }
                    }
                    catch (Exception ex)
                    {
                        Sitecore.Diagnostics.Log.Debug(string.Format("ItemNotfoundHandler Logger Error,Message:{0}", ex.Message));
                    }
                    Sitecore.Web.WebUtil.Redirect(_baseLinkManager.GetItemUrl(rootPage));
                }
                else
                {
                    base.RedirectOnItemNotFound(url);
                }
            }
            else
            {
                base.RedirectOnItemNotFound(url);
            }
        }
        public string GetItemUrl(Item item, bool enableLanguageEmbedding = false)
        {
            if (item == null)
            {
                return(null);
            }

            EnterspeedSitecoreConfiguration configuration = _enterspeedConfigurationService.GetConfiguration();
            EnterspeedSiteInfo siteInfo = configuration.GetSite(item);

            var urlBuilderOptions = new ItemUrlBuilderOptions
            {
                SiteResolving          = true,
                AlwaysIncludeServerUrl = true,
                LowercaseUrls          = true,
                LanguageEmbedding      = enableLanguageEmbedding ? LanguageEmbedding.Always : LanguageEmbedding.Never
            };

            if (siteInfo != null)
            {
                SiteContext siteContext = _siteContextFactory.GetSiteContext(siteInfo.Name);

                urlBuilderOptions.Site = siteContext;
            }

            return(_linkManager.GetItemUrl(item, urlBuilderOptions));
        }
Exemplo n.º 5
0
        protected override void PerformRedirect(string url)
        {
            if (Context.Site == null || Context.Database == null || Context.Database.Name == "core")
            {
                _404Logger.Log.Info($"Attempting to redirect url {url}, but no Context Site or DB defined (or core db redirect attempted)");
                return;
            }

            // need to retrieve not found item to account for sites utilizing virtualFolder attribute
            var notFoundItem = Context.Database.GetItem(Context.Site.StartPath + Settings.ItemNotFoundUrl);

            if (notFoundItem == null)
            {
                _404Logger.Log.Info($"No 404 item found on site: {Context.Site.Name}");
                return;
            }

            var notFoundUrl = _baseLinkManager.GetItemUrl(notFoundItem);

            if (string.IsNullOrWhiteSpace(notFoundUrl))
            {
                _404Logger.Log.Info($"Found 404 item for site, but no URL returned: {Context.Site.Name}");
                return;
            }

            _404Logger.Log.Info($"Redirecting to {notFoundUrl}");
            if (Settings.RequestErrors.UseServerSideRedirect)
            {
                HttpContext.Current.Server.TransferRequest(notFoundUrl);
            }
            else
            {
                WebUtil.Redirect(notFoundUrl, false);
            }
        }
        public LanguageSelectorViewModel GetViewModel(Language currentLanguage, Item currentItem, Database currentDatabase)
        {
            Throw.IfNull(currentLanguage, nameof(currentLanguage));
            Throw.IfNull(currentItem, nameof(currentItem));
            Throw.IfNull(currentDatabase, nameof(currentDatabase));

            var dataSource = _mvcContext.GetDataSourceItem <ILanguageSelectorSettings>();

            Throw.IfCondition(dataSource is null, nameof(dataSource),
                              Translate.Text(DictionaryKeys.ErrorMessages.DataSourceNotExist));

            var languages  = _languageManager.GetLanguages(currentDatabase);
            var viewModels = languages
                             .Select(x =>
            {
                var url = _linkManager.GetItemUrl(currentItem, new ItemUrlBuilderOptions
                {
                    Language          = x,
                    LanguageEmbedding = LanguageEmbedding.Always
                });

                return(new LanguageViewModel
                {
                    DisplayName = GetLanguageDisplayName(x.GetDisplayName()),
                    Link = url
                });
            });

            return(new LanguageSelectorViewModel
            {
                CurrentLanguageName = GetLanguageDisplayName(currentLanguage.GetDisplayName()),
                Languages = viewModels,
                LanguageSelectorSettings = dataSource
            });
        }
Exemplo n.º 7
0
 public IList <Link> GetNavigationLinks(Item navigationRootItem)
 {
     return(navigationRootItem.Children.Where(x => x.DescendsFrom(Templates.Navigation.TemplateId) && MainUtil.GetBool(x[Templates.Navigation.Fields.IncludeInMenu], false))
            .Select(x => new Link {
         Title = x[Templates.Navigation.Fields.MenuTitle], Url = _linkManager.GetItemUrl(x)
     })
            .ToList());
 }
Exemplo n.º 8
0
        public Header GetHeader(Item contextItem)
        {
            Debug.Assert(contextItem != null);
            var navigationRoot = RootResolver.GetNavigationRoot(contextItem);

            if (navigationRoot == null)
            {
                return(new Header());
            }

            return(new Header
            {
                HomeItem = navigationRoot,
                HomeUrl = LinkManager.GetItemUrl(navigationRoot),
                NavigationItems = GetNavigationItems(navigationRoot, contextItem)
            });
        }
Exemplo n.º 9
0
        public IList <Link> GetNavigationLinks(Item contextItem, Rendering rendering)
        {
            var homeItem = GetHomePage(contextItem);

            return(homeItem.Children.Where(x => x.DescendsFrom(Constants.Templates.NavigationItem) && x[Constants.FieldNames.IncludeInMenu] == Constants.FieldValues.CheckboxTrue)
                   .Select(x => new Link {
                Title = x[Constants.FieldNames.MenuTitle], Url = linkManager.GetItemUrl(x)
            })
                   .ToList());
        }
        public static string GetAbsoluteItemUrl(this BaseLinkManager linkManager, Item item)
        {
#if FEATURE_URL_BUILDERS
            var options = new ItemUrlBuilderOptions
#else
            var options = new UrlOptions
#endif
            {
                AlwaysIncludeServerUrl = true
            };

            return(linkManager.GetItemUrl(item, options));
        }
Exemplo n.º 11
0
 protected virtual void AddFeedToOutput(HtmlTextWriter output)
 {
     foreach (RssFeedItem feed in SyndicationLink.Feeds)
     {
         foreach (var a in SyndicationLink.Attributes)
         {
             output.AddAttribute(a.Key, a.Value);
         }
         output.AddAttribute(HtmlTextWriterAttribute.Title, feed.Title.Raw);
         output.AddAttribute(HtmlTextWriterAttribute.Href, LinkManager.GetItemUrl(feed));
         output.RenderBeginTag(HtmlTextWriterTag.Link);
         output.RenderEndTag();
     }
 }
Exemplo n.º 12
0
        private string GetItemUrl(Item item)
        {
            var url = _linkManager.GetItemUrl(item);

            return(url);
        }
Exemplo n.º 13
0
        public EnterspeedSitecoreConfiguration GetConfiguration()
        {
            Item enterspeedConfigurationItem = _itemManager.GetItem(EnterspeedIDs.Items.EnterspeedConfigurationID, Language.Parse("en"), Version.Latest, _factory.GetDatabase("web"));

            if (enterspeedConfigurationItem == null || enterspeedConfigurationItem.Versions.Count == 0)
            {
                return(new EnterspeedSitecoreConfiguration());
            }

            string enabled = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedEnabledFieldID] ?? string.Empty;

            if (enabled != "1")
            {
                return(new EnterspeedSitecoreConfiguration());
            }

            if (!IsConfigurationUpdated(enterspeedConfigurationItem, out Guid currentRevisionId))
            {
                return(_configuration);
            }

            var config = new EnterspeedSitecoreConfiguration
            {
                IsEnabled = true
            };

            string configApiBaseUrl = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedApiBaseUrlFieldID];

            config.BaseUrl = (configApiBaseUrl ?? string.Empty).Trim();

            string configApiKey = enterspeedConfigurationItem[EnterspeedIDs.Fields.EnterspeedApiKeyFieldID];

            config.ApiKey = (configApiKey ?? string.Empty).Trim();

            config.ItemNotFoundUrl = GetItemNotFoundUrl(_settings);

            MultilistField enabledSitesField = enterspeedConfigurationItem.Fields[EnterspeedIDs.Fields.EnterspeedEnabledSitesFieldID];

            var enabledSites = enabledSitesField?.GetItems()?.ToList() ?? new List <Item>();

            if (enabledSites.Any())
            {
                List <SiteInfo> allSiteInfos = _siteContextFactory.GetSites();

                foreach (Item enabledSite in enabledSites)
                {
                    SiteInfo matchingSite = allSiteInfos.FirstOrDefault(x => x.RootPath.Equals(enabledSite.Paths.FullPath, StringComparison.OrdinalIgnoreCase));
                    if (matchingSite == null)
                    {
                        continue;
                    }

                    SiteContext siteContext = _siteContextFactory.GetSiteContext(matchingSite.Name);

                    Language siteLanguage = _languageManager.GetLanguage(siteContext.Language);

                    Item homeItem = _itemManager.GetItem(siteContext.StartPath, siteLanguage, Version.Latest, siteContext.Database);
                    if (homeItem == null || homeItem.Versions.Count == 0)
                    {
                        // TODO - KEK: throw exception here?
                        continue;
                    }

                    string name         = siteContext.SiteInfo.Name;
                    string startPathUrl = _linkManager.GetItemUrl(homeItem, new ItemUrlBuilderOptions
                    {
                        SiteResolving          = true,
                        Site                   = siteContext,
                        AlwaysIncludeServerUrl = true,
                        LowercaseUrls          = true,
                        LanguageEmbedding      = LanguageEmbedding.Never
                    });

                    var enterspeedSiteInfo = new EnterspeedSiteInfo
                    {
                        Name         = name,
                        BaseUrl      = startPathUrl,
                        HomeItemPath = siteContext.StartPath,
                        SiteItemPath = siteContext.RootPath
                    };

                    if (siteContext.Properties["scheme"] != null &&
                        siteContext.Properties["scheme"].Equals("https", StringComparison.OrdinalIgnoreCase))
                    {
                        enterspeedSiteInfo.IsHttpsEnabled = true;
                    }

                    config.SiteInfos.Add(enterspeedSiteInfo);
                }
            }

            // Settings caching values
            _configuration           = config;
            _configurationRevisionId = currentRevisionId;

            return(_configuration);
        }