private string GetItemUrl(Item item, Site site, Language language) { UrlOptions defaultOptions = UrlOptions.DefaultOptions; defaultOptions.SiteResolving = Settings.Rendering.SiteResolving; defaultOptions.Site = SiteContext.GetSite(site.Name); defaultOptions.AlwaysIncludeServerUrl = false; defaultOptions.LanguageEmbedding = LanguageEmbedding.Always; if (language != null) { defaultOptions.Language = language; } string itemUrl = LinkManager.GetItemUrl(item, defaultOptions); string serverUrlBySite = SitemapManagerConfiguration.GetServerUrlBySite(site.Name); if (serverUrlBySite.Contains("http://")) { serverUrlBySite = serverUrlBySite.Substring("http://".Length); } StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(serverUrlBySite)) { if (!(itemUrl.Contains("://") || itemUrl.Contains("http"))) { stringBuilder.Append("http://"); stringBuilder.Append(serverUrlBySite); stringBuilder.Append(itemUrl); } else { if (itemUrl.StartsWith("http")) { itemUrl = itemUrl.Remove(0, 4); } stringBuilder.Append("http://"); stringBuilder.Append(serverUrlBySite); if (itemUrl.IndexOf("/", 3) > 0) { stringBuilder.Append(itemUrl.Substring(itemUrl.IndexOf("/", 3))); } } } else if (!string.IsNullOrEmpty(site.Properties["hostname"])) { stringBuilder.Append("http://"); stringBuilder.Append(site.Properties["hostname"]); stringBuilder.Append(itemUrl); } else if (!itemUrl.Contains("://") || itemUrl.Contains("http")) { stringBuilder.Append(WebUtil.GetFullUrl(itemUrl)); } else { stringBuilder.Append("http://"); stringBuilder.Append(itemUrl); } return(stringBuilder.ToString()); }
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(); } }
protected void RefreshButtonClick() { (new SitemapHandler()).RefreshSitemap(this, new EventArgs()); StringDictionary sites = SitemapManagerConfiguration.GetSites(); StringBuilder stringBuilder = new StringBuilder(); foreach (string value in sites.Values) { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(String.Format("{0}.xml", value)); } string str = string.Format(" - The sitemap file <b>\"{0}\"</b> has been refreshed<br /> ", stringBuilder.ToString()); this.Message.Text = str; SitemapManagerForm.RefreshPanel("MainPanel"); }
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 site = Context.Site; if (!args.Url.FilePath.Contains(Constants.RobotsFileName)) { return; } args.HttpContext.Response.ClearHeaders(); args.HttpContext.Response.ClearContent(); args.HttpContext.Response.ContentType = "text/plain"; var content = string.Empty; try { var config = new SitemapManagerConfiguration(site.Name); var sitemapManager = new SitemapManager(config); content = sitemapManager.GetRobotSite(); args.HttpContext.Response.Write(content); } catch (Exception e) { Log.Error("Error Robots", e, this); } finally { args.HttpContext.Response.Flush(); args.HttpContext.Response.End(); } }