Beispiel #1
0
        private static string GetSharedItemUrl(Item item, SiteContext site, Item parentItem, string urlFormat)
        {
            var itemUrl    = HtmlEncode(GetItemUrl(item, site));
            var parentUrl  = HtmlEncode(GetItemUrl(parentItem, site));
            var siteConfig = new SitemapManagerConfiguration(site.Name);

            parentUrl = parentUrl.EndsWith("/") ? parentUrl : parentUrl + "/";
            if (!string.IsNullOrWhiteSpace(urlFormat))
            {
                return(HtmlEncode(parentUrl + FormatItemUrl(item, urlFormat).TrimStart('/')));
            }
            else if (siteConfig.CleanupBucketPath)
            {
                var pos          = itemUrl.LastIndexOf("/", StringComparison.Ordinal) + 1;
                var itemNamePath = itemUrl.Substring(pos, itemUrl.Length - pos);
                return(HtmlEncode(parentUrl + itemNamePath));
            }
            else
            {
                var contentParentItem = SitemapManager.GetContentLocation(item);
                if (contentParentItem == null)
                {
                    return(null);
                }
                var contentParentItemUrl = HtmlEncode(GetItemUrl(contentParentItem, site));
                if (string.IsNullOrWhiteSpace(contentParentItemUrl))
                {
                    return(string.Empty);
                }
                itemUrl = itemUrl.Replace(contentParentItemUrl, string.Empty);
                return(string.IsNullOrWhiteSpace(itemUrl) ? string.Empty : HtmlEncode(parentUrl + itemUrl.Trim('/')));
            }
        }
        protected void RefreshButtonClick()
        {
            var sh = new SitemapHandler();
            sh.RefreshSitemap(this, new EventArgs());

            StringBuilder sb = new StringBuilder();
            var siteNames = SitemapManagerConfiguration.GetSiteNames();
            var message = string.Empty;
            if (siteNames == null || !siteNames.Any())
            {
                Message.Text = "No sitemap configurations found under /sitecore/system/Modules/Sitemap XML. Please create one or more configuration nodes and try refreshing again.";
                RefreshPanel("MainPanel");
                return;
            }
            foreach (var siteName in siteNames)
            {
                var config = new SitemapManagerConfiguration(siteName);
                if (string.IsNullOrWhiteSpace(config.FileName)) continue;
                if (sb.Length > 0)
                    sb.Append(", ");
                sb.Append(config.FileName);
            }

            message = !string.IsNullOrWhiteSpace(sb.ToString())
                ? string.Format(" - The sitemap file <b>\"{0}\"</b> has been refreshed<br /> - <b>\"{0}\"</b> has been registered to \"robots.txt\"", sb.ToString())
                :"File name has not been specified for one or more sitemap configurations under /sitecore/system/Modules/Sitemap XML.";

            Message.Text = message;

            RefreshPanel("MainPanel");
        }
 public SitemapManager(SitemapManagerConfiguration config)
 {
     Assert.IsNotNull(config, "config");
     _config = config;
     if (!string.IsNullOrWhiteSpace(_config.FileName))
     {
         BuildSiteMap();
     }
 }
 public SitemapManager(SitemapManagerConfiguration config)
 {
     Assert.IsNotNull(config, "config");
     _config = config;
     if (!string.IsNullOrWhiteSpace(_config.FileName))
     {
         BuildSiteMap();
     }
 }
        public static string GetSharedItemUrl(Item item, SiteContext site, SitemapManagerConfiguration config)
        {
            var parentItem = SitemapManager.GetSharedLocationParent(item);
            var itemUrl    = HtmlEncode(GetItemUrl(item, site, config));
            var parentUrl  = HtmlEncode(GetItemUrl(parentItem, site, config));

            parentUrl = parentUrl.EndsWith("/") ? parentUrl : parentUrl + "/";
            var pos          = itemUrl.LastIndexOf("/") + 1;
            var itemNamePath = itemUrl.Substring(pos, itemUrl.Length - pos);

            return(HtmlEncode(parentUrl + itemNamePath));
        }
        public override void Process(HttpRequestArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (Context.Site == null || string.IsNullOrEmpty(Context.Site.RootPath.Trim())) return;
            if (Context.Page.FilePath.Length > 0) return;
            var sitemapHandler = string.IsNullOrWhiteSpace(Context.Site.Properties["sitemapHandler"])
                ? "sitemap.xml"
                : Context.Site.Properties["sitemapHandler"];
            if (!args.Url.FilePath.Contains(sitemapHandler)) return;

            // Important to return qualified XML (text/xml) for sitemaps
            args.Context.Response.ClearHeaders();
            args.Context.Response.ClearContent();
            args.Context.Response.ContentType = "text/xml";

            // Checking the HTML cache first
            var site = Context.Site;
            #if !DEBUG
            var cacheKey = "UltimateSitemapXML_" + site.Name;
            var cache = CacheManager.GetHtmlCache(site).GetHtml(cacheKey);
            if (!string.IsNullOrWhiteSpace(cache))
            {
                args.Context.Response.Write(cache);
                args.Context.Response.End();
                return;
            }
            #endif

            var content = string.Empty;
            try
            {
                var config = new SitemapManagerConfiguration(site.Name);
                var sitemapManager = new SitemapManager(config);

                content = sitemapManager.BuildSiteMapForHandler();
                args.Context.Response.Write(content);
            }
            finally
            {
            #if !DEBUG
                CacheManager.GetHtmlCache(site).SetHtml(cacheKey, content);
            #endif
                args.Context.Response.Flush();
                args.Context.Response.End();
            }
        }
Beispiel #7
0
        public void RefreshSitemap(object sender, EventArgs args)
        {
            var sites = SitemapManagerConfiguration.GetSiteNames();

            foreach (var site in sites)
            {
                var config         = new SitemapManagerConfiguration(site);
                var sitemapManager = new SitemapManager(config);
                sitemapManager.SubmitSitemapToSearchenginesByHttp();

                if (!config.GenerateRobotsFile)
                {
                    continue;
                }
                sitemapManager.RegisterSitemapToRobotsFile();
            }
        }
        public SitemapItem(Item item, SiteContext site, Item parentItem, SitemapManagerConfiguration config,
                           Language currentLanguage = null, List <Language> allLanguages = null)
        {
            var itemId   = item.ID;
            var database = Sitecore.Configuration.Factory.GetDatabase(SitemapManagerConfiguration.WorkingDatabase);

            Id = itemId.Guid;

            allLanguages = allLanguages ?? item.Languages.Where(l =>
                                                                config.EnabledLanguageList == null ||
                                                                config.EnabledLanguageList.Contains(l.Origin.ItemId.ToString())).ToList();

            var currentLanguageName = !string.IsNullOrWhiteSpace(site.Language)
                ? site.Language
                : allLanguages.FirstOrDefault().Name;

            currentLanguageName = currentLanguage != null ? currentLanguage.Name : currentLanguageName;

            HrefLangs = new List <SitemapItemHrefLang>();

            foreach (var language in allLanguages)
            {
                item = database.GetItem(itemId, language);

                var itemUrl = HtmlEncode(GetItemUrl(item, site, config, language));
                if (parentItem != null)
                {
                    itemUrl = GetSharedItemUrl(item, site, parentItem, config);
                }

                if (currentLanguage != null && language.Name == currentLanguage.Name)
                {
                    Priority        = item[Constants.SeoSettings.Priority];
                    ChangeFrequency = item[Constants.SeoSettings.ChangeFrequency].ToLower();
                    LastModified    = HtmlEncode(item.Statistics.Updated.ToLocalTime()
                                                 .ToString(Constants.XmlSettings.LastmodDateFormat));
                    Location = language.Name == currentLanguageName ? itemUrl : Location;
                }

                HrefLangs.Add(new SitemapItemHrefLang()
                {
                    Href     = itemUrl,
                    HrefLang = language.Name
                });
            }
        }
Beispiel #9
0
 public void RefreshSitemap(object sender, EventArgs args)
 {
     try
     {
         var sites = SitemapManagerConfiguration.GetSiteNames();
         foreach (var site in sites)
         {
             var config         = new SitemapManagerConfiguration(site);
             var sitemapManager = new SitemapManager(config);
             sitemapManager.SubmitSitemapToSearchenginesByHttp();
             //removed because now the robots is generated when it is invoked the url with robots.txt at the end
             //if (!config.GenerateRobotsFile) continue;
             //sitemapManager.RegisterSitemapToRobotsFile();
         }
     }
     catch (Exception e)
     {
         Log.Error("Error Sitemap", e, this);
     }
 }
        protected void RefreshButtonClick()
        {
            var sh = new SitemapHandler();

            sh.RefreshSitemap(this, new EventArgs());

            StringBuilder sb        = new StringBuilder();
            var           siteNames = SitemapManagerConfiguration.GetSiteNames();
            var           message   = string.Empty;

            if (siteNames == null || !siteNames.Any())
            {
                Message.Text = "No sitemap configurations found under /sitecore/system/Modules/Sitemap XML. Please create one or more configuration nodes and try refreshing again.";
                RefreshPanel("MainPanel");
                return;
            }
            foreach (var siteName in siteNames)
            {
                var config = new SitemapManagerConfiguration(siteName);
                if (string.IsNullOrWhiteSpace(config.FileName))
                {
                    continue;
                }
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(config.FileName);
            }

            message = !string.IsNullOrWhiteSpace(sb.ToString())
                ? string.Format(" - The sitemap file <b>\"{0}\"</b> has been refreshed<br /> - <b>\"{0}\"</b> has been registered to \"robots.txt\"", sb.ToString())
                :"File name has not been specified for one or more sitemap configurations under /sitecore/system/Modules/Sitemap XML.";

            Message.Text = message;

            RefreshPanel("MainPanel");
        }
 public static bool IsEnabledTemplate(Item item)
 {
     var config = new SitemapManagerConfiguration(Context.GetSiteName());
     return config.EnabledTemplates.ToLower().Contains(item.TemplateID.ToGuid().ToString());
 }
        public static bool IsEnabledTemplate(Item item)
        {
            var config = new SitemapManagerConfiguration(Context.GetSiteName());

            return(config.EnabledTemplates.ToLower().Contains(item.TemplateID.ToGuid().ToString()));
        }
        public static string GetItemUrl(Item item, SiteContext site, SitemapManagerConfiguration config, Language language = null)
        {
            var options = UrlOptions.DefaultOptions;

            options.SiteResolving          = Sitecore.Configuration.Settings.Rendering.SiteResolving;
            options.Site                   = SiteContext.GetSite(site.Name);
            options.AlwaysIncludeServerUrl = false;
            options.UseDisplayName         = config.UseDisplayName;
            if (language != null)
            {
                options.LanguageEmbedding = config.EnableLanguageEmbedding? LanguageEmbedding.Always: LanguageEmbedding.Never;
                options.Language          = language;
            }

            var url = LinkManager.GetItemUrl(item, options);

            //Sitecore OOTB does not use display name for the home page URLs even if configured.
            //That needs to be corrected
            if (item.Paths.FullPath.Equals(site.StartPath) && !url.EndsWith(item.DisplayName) && config.UseDisplayName)
            {
                url = string.Concat(url, url.EndsWith("/")? "": "/", item.DisplayName);
            }

            var serverUrl = config.ServerUrl;

            var isHttps = false;

            if (serverUrl.Contains("http://"))
            {
                serverUrl = serverUrl.Substring("http://".Length);
            }
            else if (serverUrl.Contains("https://"))
            {
                serverUrl = serverUrl.Substring("https://".Length);
                isHttps   = true;
            }

            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrl))
            {
                if (url.Contains("://") && !url.Contains("http"))
                {
                    sb.Append(isHttps ? "https://" : "http://");
                    sb.Append(serverUrl);
                    if (url.IndexOf("/", 3) > 0)
                    {
                        sb.Append(url.Substring(url.IndexOf("/", 3)));
                    }
                }
                else
                {
                    sb.Append(isHttps ? "https://" : "http://");
                    sb.Append(serverUrl);
                    sb.Append(url);
                }
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                sb.Append(isHttps ? "https://" : "http://");
                sb.Append(site.Properties["hostname"]);
                sb.Append(url);
            }
            else
            {
                if (url.Contains("://") && !url.Contains("http"))
                {
                    sb.Append(isHttps ? "https://" : "http://");
                    sb.Append(url);
                }
                else
                {
                    sb.Append(Sitecore.Web.WebUtil.GetFullUrl(url));
                }
            }
            return(sb.ToString());
        }
        public static List <SitemapItem> GetLanguageSitemapItems(Item item, SiteContext site, Item parentItem, SitemapManagerConfiguration config)
        {
            //If list of languages are not specified take all languages or else take only the languages in the list.
            var languages = item.Languages.Where(l =>
                                                 config.EnabledLanguageList == null ||
                                                 config.EnabledLanguageList.Contains(l.Origin.ItemId.ToString()))
                            .ToList();

            return(languages.Select(language => new SitemapItem(item, site, parentItem, config, language, languages)).ToList());
        }
Beispiel #15
0
        public static bool IsExcludedItem(Item item)
        {
            var config = new SitemapManagerConfiguration(Context.GetSiteName());

            return(config.ExcludedItems.ToLower().Contains(item.ID.Guid.ToString()));
        }
 private static string GetSharedItemUrl(Item item, SiteContext site, Item parentItem)
 {
     var itemUrl = HtmlEncode(GetItemUrl(item, site));
     var parentUrl = HtmlEncode(GetItemUrl(parentItem, site));
     var siteConfig = new SitemapManagerConfiguration(site.Name);
     parentUrl = parentUrl.EndsWith("/") ? parentUrl : parentUrl + "/";
     if (siteConfig.CleanupBucketPath)
     {
         var pos = itemUrl.LastIndexOf("/", StringComparison.Ordinal) + 1;
         var itemNamePath = itemUrl.Substring(pos, itemUrl.Length - pos);
         return HtmlEncode(parentUrl + itemNamePath);
     }
     else
     {
         var contentParentItem = SitemapManager.GetContentLocation(item);
         if (contentParentItem == null) return null;
         var contentParentItemUrl = HtmlEncode(GetItemUrl(contentParentItem, site));
         if (string.IsNullOrWhiteSpace(contentParentItemUrl)) return string.Empty;
         itemUrl = itemUrl.Replace(contentParentItemUrl, string.Empty);
         return string.IsNullOrWhiteSpace(itemUrl) ? string.Empty : HtmlEncode(parentUrl + itemUrl.Trim('/'));
     }
 }