public static Sitecore.Data.Items.Item GetHomeItem( this Sitecore.Sites.SiteContext me, Sitecore.Data.Database database) { Sitecore.Diagnostics.Assert.ArgumentNotNull(database, "database"); return(database.GetItem(me.StartPath)); }
public static List <object[]> GetSiteProperties(Sitecore.Sites.SiteContext site) { var results = new List <object[]>() { new object[] { "Site Property", "Value" }, new object[] { "Name", site.Name }, new object[] { "HostName", site.HostName }, new object[] { "TargetHostName", site.TargetHostName }, new object[] { "Language", site.Language }, new object[] { "Database", site.Properties["database"] }, new object[] { "Device", site.Device }, new object[] { "RootPath", site.RootPath }, new object[] { "StartItem", site.StartItem }, new object[] { "StartPath", site.StartPath }, new object[] { "PhysicalFolder", site.PhysicalFolder }, new object[] { "VirtualFolder", site.VirtualFolder }, new object[] { "LoginPage", site.LoginPage }, new object[] { "RequireLogin", site.RequireLogin }, new object[] { "AllowDebug", site.AllowDebug }, new object[] { "EnableAnalytics", site.EnableAnalytics }, new object[] { "EnableDebugger", site.EnableDebugger }, new object[] { "EnablePreview", site.EnablePreview }, new object[] { "EnableWorkflow", site.EnableWorkflow }, new object[] { "EnableWebEdit", site.EnableWebEdit }, new object[] { "FilterItems", site.FilterItems }, new object[] { "CacheHtml", site.CacheHtml }, new object[] { "CacheMedia", site.CacheMedia }, new object[] { "MediaCachePath", site.MediaCachePath }, new object[] { "XmlControlPage", site.XmlControlPage } }; return(results); }
public object[] GetBreadcrumb(Item current, Sitecore.Sites.SiteContext site) { var breadcrumbs = new List <object>(); while (current != null) { if (current.Paths.FullPath.TrimEnd('/').Equals(site.RootPath.TrimEnd('/'), System.StringComparison.InvariantCultureIgnoreCase)) { break; } if (!ExcludeTemplates.Contains(current.TemplateID.ToString())) { var label = ID.TryParse(LabelField, out ID labelFieldId) && current.Fields.Contains(labelFieldId) && !string.IsNullOrWhiteSpace(current[labelFieldId]) ? current[labelFieldId] : current.DisplayName; dynamic breadcrumb = new ExpandoObject(); breadcrumb.label = label; breadcrumb.url = GetItemUrl(current); breadcrumbs.Add(breadcrumb); } current = current.Parent; } breadcrumbs.Reverse(); return(breadcrumbs.ToArray()); }
/// <summary> /// Retrieve the hostname, potentially including a protocol, to use in media URLs. /// </summary> /// <param name="me">The site referencing the media.</param> /// <returns>The hostname to use in media URLs, or an empty string.</returns> public static string GetMediaHost( this Sitecore.Sites.SiteContext me) { Sitecore.Diagnostics.Assert.IsNotNull(me, "me"); if (Sitecore.Context.Database == null || String.IsNullOrEmpty(me.Properties[MediaHostAttribute])) { return(null); } return(me.Properties[MediaHostAttribute]); }
public void ClearCaches(object sender, EventArgs args) { Sitecore.Diagnostics.Assert.ArgumentNotNull(sender, "sender"); Sitecore.Diagnostics.Assert.ArgumentNotNull(args, "args"); string[] siteNames; if (this.Sites.Count > 0) { siteNames = (string[])this.Sites.ToArray(); } else { siteNames = Sitecore.Configuration.Factory.GetSiteNames(); } Sitecore.Diagnostics.Log.Info( this + " clearing HTML caches; " + siteNames.Length + " possible sites.", this); foreach (string siteName in siteNames) { Sitecore.Diagnostics.Assert.IsNotNullOrEmpty(siteName, "siteName"); Sitecore.Sites.SiteContext site = Sitecore.Configuration.Factory.GetSite(siteName); Sitecore.Diagnostics.Assert.IsNotNull(site, "siteName: " + siteName); if (!site.CacheHtml) { continue; } Sitecore.Caching.HtmlCache htmlCache = Sitecore.Caching.CacheManager.GetHtmlCache( site); Sitecore.Diagnostics.Assert.IsNotNull(htmlCache, "htmlCache for " + siteName); if (htmlCache.InnerCache.Count < 1) { Sitecore.Diagnostics.Log.Info( this + " no entries in output cache for " + siteName, this); continue; } Sitecore.Diagnostics.Log.Info( this + " clearing output cache for " + siteName, this); htmlCache.Clear(); } Sitecore.Diagnostics.Log.Info(this + " done.", this); }
/// <summary> /// Retrieve the item to handle 404 conditions based on the notFound attribute of /// the site definition, or Null. /// </summary> /// <param name="me">This Sitecore.Context.SiteContext.</param> /// <returns>The not found item for the site, or Null.</returns> public static Sitecore.Data.Items.Item GetNotFoundItem( this Sitecore.Sites.SiteContext me) { Sitecore.Diagnostics.Assert.IsNotNull(me, "me"); if (Sitecore.Context.Database == null || String.IsNullOrEmpty(me.Properties[NotFoundAttribute])) { return(null); } string path = me.StartPath + me.Properties[NotFoundAttribute]; Sitecore.Data.Items.Item notFound = Sitecore.Context.Database.GetItem(path); Sitecore.Diagnostics.Assert.IsNotNull(notFound, path); return(notFound); }
private bool IsFallbackSupported(Field field) { if (FieldFallback.Data.FallbackDisabler.CurrentValue == FallbackStates.Disabled) { //Logger.Debug("@ Fallback Disabled by Disabler [{0}:{1}]", field.Item.Name, field.Name); return(false); } Assert.ArgumentNotNull(field, "field"); if (IsIgnoredField(field)) { //Logger.Debug("@ Field {0} is ignored", field.Name); return(false); } // Check the cache to see if this field is supported if (_supportCache.GetFallbackSupport(field).HasValue) { //Logger.Debug("@ IsFallbackSupported (cache hit - {0}) ", SupportCache.GetFallbackSupport(field).Value); return(_supportCache.GetFallbackSupport(field).Value); } Item item = field.Item; Assert.ArgumentNotNull(item, "item"); // see if we know this item should be skipped if (SkipItemCache.IsItemSkipped(item)) { //Logger.Debug("@ IsFallbackSupported (SkipItemCache cache hit) "); return(false); } bool isSupported = true; // Sitecore 7 Parallel Indexing may not supply us with a SiteContext... // Manually set it in this instnce // https://github.com/HedgehogDevelopment/sitecore-field-fallback/issues/3 if (Sitecore.Context.Site == null && Sitecore.Configuration.Settings.GetBoolSetting("ContentSearch.ParallelIndexing.Enabled", false)) { Logger.Warn("Sitecore.Context.Site was null and ContentSearch.ParallelIndexing.Enabled was true. Manually setting to 'shell' site. For more info see here: https://github.com/HedgehogDevelopment/sitecore-field-fallback/issues/3", this); Sitecore.Sites.SiteContext site = Sitecore.Sites.SiteContextFactory.GetSiteContext("shell"); Sitecore.Context.Site = site; } Logger.Debug(">> IsFallbackSupported - s:{0} db:{1} i:{2} f:{3}", Sitecore.Context.GetSiteName(), item.Database.Name, item.ID, field.Name); Logger.PushIndent(); if (!_siteManager.IsFallbackEnabledForDisplayMode(Sitecore.Context.Site)) { Logger.Debug("Fallback is not enabled for current page mode"); isSupported = false; } else if (!_siteManager.IsFallbackEnabled(Sitecore.Context.Site.SiteInfo)) { Logger.Debug("Fallback is not enabled for site {0}", Sitecore.Context.Site.Name); isSupported = false; } else if (!IsItemInSupportedDatabase(item)) { Logger.Debug("Item database '{0}' not valid.", item.Database.Name); isSupported = false; // lets cache this item as skipped to prevent future checks on it SkipItemCache.SetSkippedItem(item); } else if (!IsItemInSupportedPath(item)) // it must be under /sitecore/content or /sitecore/media library { Logger.Debug("Item {0} is in an invalid path", item.Name); isSupported = false; // lets cache this item as skipped to prevent future checks on it SkipItemCache.SetSkippedItem(item); } _supportCache.SetFallbackSupport(field, isSupported); Logger.PopIndent(); Logger.Debug("<< IsFallbackSupported: {0}", isSupported); return(isSupported); }
public static Sitecore.Data.Items.Item GetHomeItem( this Sitecore.Sites.SiteContext me) { return(GetHomeItemExtension.GetHomeItem(me, Sitecore.Context.Database)); }
private void GenerateSiteMap() { try { SiteMapConfig siteMapConfig = new SiteMapConfig(); if (siteMapConfig.definedSites == null || !siteMapConfig.definedSites.Any()) { return; } if (siteMapConfig.targetDatabaseName == string.Empty) { return; } foreach (var site in siteMapConfig.definedSites) { if (site.Fields[SiteItemFields.SiteName] == null || string.IsNullOrEmpty(site.Fields[SiteItemFields.SiteName].Value)) { continue; } Sitecore.Sites.SiteContext _site = Factory.GetSite(site.Fields[SiteItemFields.SiteName].Value); if (_site == null) { continue; } Item _root = GetTargetDatabase().GetItem(_site.StartPath); if (_root == null) { continue; } string siteHostName; if (string.IsNullOrEmpty(_site.TargetHostName)) { var hostArray = _site.HostName.Split('|'); siteHostName = hostArray.FirstOrDefault(); } else { siteHostName = _site.TargetHostName; } bool useServerUrlOverride = site.Fields[SiteItemFields.ServerURL] != null && !string.IsNullOrEmpty(site.Fields[SiteItemFields.ServerURL].Value); StringBuilder sbSiteMap = new StringBuilder(); sbSiteMap.Append("<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'>"); List <Item> siteMapItems = _root.Axes.GetDescendants().Where(P => P.Fields["Show In XML SiteMap"].Value == "1").ToList(); if (siteMapItems != null && siteMapItems.Any()) { if (_root.Fields["Show In XML SiteMap"].Value == "1") { siteMapItems.Add(_root); } var options = global::Sitecore.Links.LinkManager.GetDefaultUrlOptions(); options.AlwaysIncludeServerUrl = true; options.LanguageEmbedding = LanguageEmbedding.Always; options.SiteResolving = true; // get langauges List <Language> _availbleLangauges = null; if (siteMapConfig.multilingualSiteMapXML) { Item _languagesRoot = GetTargetDatabase().GetItem(Guids.Items.LangaugesRootItem); _availbleLangauges = _languagesRoot.Axes.GetDescendants().Where(P => P.Fields["Iso"].Value != string.Empty).Select(P => Language.Parse(P.Fields["Iso"].Value)).ToList(); } else { _availbleLangauges = new List <Language>() { Language.Parse("en") }; } XmlDocument doc = new XmlDocument(); foreach (var langauge in _availbleLangauges) { options.Language = langauge; options.EmbedLanguage(langauge); foreach (var item in siteMapItems) { //to resolve issues with multisite link resolution here, set the rootPath="#" on the publisher site in web.config //and also add scheme="http" to the Site Definition for your site string url = LinkManager.GetItemUrl(item, options); if (useServerUrlOverride) { if (url.Contains("://" + siteHostName + "/")) { url = url.Replace(siteHostName, site.Fields[SiteItemFields.ServerURL].Value.Replace("http://", "").Replace("https://", "")); } else { url = site.Fields[SiteItemFields.ServerURL].Value + "//" + url; } } //handle where scheme="http" has not been added to Site Definitions if (url.StartsWith("://")) { url = url.Replace("://", ""); } if (!url.StartsWith("http://")) { url = "http://" + url; } string lastUpdated = DateUtil.IsoDateToDateTime(item.Fields[Sitecore.FieldIDs.Updated].Value).ToString("yyyy-MM-ddTHH:mm:sszzz"); string FrequencyChange = "yearly"; if (item.Fields[SiteMapFields.FrequencyChange] != null) { if (!string.IsNullOrEmpty(item.Fields[SiteMapFields.FrequencyChange].Value)) { Item _FrequencyChange = GetTargetDatabase().GetItem(item.Fields[SiteMapFields.FrequencyChange].Value); if (_FrequencyChange != null) { FrequencyChange = _FrequencyChange.Name; } } } string Priority = "0.0"; if (item.Fields[SiteMapFields.Priority] != null) { if (!string.IsNullOrEmpty(item.Fields[SiteMapFields.Priority].Value)) { Item _priority = GetTargetDatabase().GetItem(item.Fields[SiteMapFields.Priority].Value); if (_priority != null && _priority.Fields["Value"] != null && !string.IsNullOrEmpty(_priority.Fields["Value"].Value)) { Priority = _priority.Fields["Value"].Value; } } } sbSiteMap.Append("<url>"); sbSiteMap.Append("<loc>"); sbSiteMap.Append(url); sbSiteMap.Append("</loc>"); sbSiteMap.Append("<lastmod>"); sbSiteMap.Append(lastUpdated); sbSiteMap.Append("</lastmod>"); sbSiteMap.Append("<changefreq>"); sbSiteMap.Append(FrequencyChange); sbSiteMap.Append("</changefreq>"); sbSiteMap.Append("<priority>"); sbSiteMap.Append(Priority); sbSiteMap.Append("</priority>"); sbSiteMap.Append("</url>"); } } sbSiteMap.Append("</urlset>"); string fileName = "SiteMap.xml"; if (site.Fields[SiteItemFields.SitemMapXMLFilename] != null && !string.IsNullOrEmpty(site.Fields[SiteItemFields.SitemMapXMLFilename].Value)) { fileName = site.Fields[SiteItemFields.SitemMapXMLFilename].Value; } doc.LoadXml(sbSiteMap.ToString()); string xmlFilePath = MainUtil.MapPath("/" + fileName); doc.Save(xmlFilePath); if (site.Fields[SiteItemFields.AddToRobotFile] != null) { Sitecore.Data.Fields.CheckboxField _AddToRobotFile = site.Fields[SiteItemFields.AddToRobotFile]; if (_AddToRobotFile != null) { if (_AddToRobotFile.Checked) { AddSitemapToRobots(fileName); } } } Sitecore.Web.UI.Sheer.SheerResponse.Alert("SiteMap has been generated successfully"); } } } catch (Exception exception) { Log.Error(exception.Message, "SiteMapBuilder - GenerateSiteMap method"); } }
public static string GetDynamicStorageValue(this Sitecore.Sites.SiteContext context, string key) { return(GetFromDB(key)); }
public static DateTime GetDynamicStorageDateTimeValue(this Sitecore.Sites.SiteContext context, string key) { return(DateTime.Parse(GetFromDB(key))); }
public static long GetDynamicStorageLongValue(this Sitecore.Sites.SiteContext context, string key) { return(long.Parse(GetFromDB(key))); }
public static int GetDynamicStorageInt32Value(this Sitecore.Sites.SiteContext context, string key) { return(int.Parse(GetFromDB(key))); }
public static void SetDynamicStorageValue(this Sitecore.Sites.SiteContext context, string key, DateTime value) { SetToDB(key, value.ToString()); }
public static void SetDynamicStorageValue(this Sitecore.Sites.SiteContext context, string key, string value) { SetToDB(key, value); }