protected static string GetFieldSource(ClientPipelineArgs args) { var fieldIdValue = args.Parameters["fieldid"]; if (string.IsNullOrWhiteSpace(fieldIdValue)) { return(string.Empty); } var fieldId = new Sitecore.Data.ID(fieldIdValue); var fieldItem = Context.ContentDatabase.GetItem(fieldId); if (fieldItem == null) { return(string.Empty); } var fieldSource = fieldItem.Fields["Source"]; if (fieldSource == null) { return(string.Empty); } return(fieldSource.Value); }
/// <summary> /// Responds to Sitecore item moving /// </summary> /// <param name="sender"></param> /// <param name="args"> /// Param index 0 contains the Item being moved, /// Param index 1 contains the ID of the old parent, /// Param index 2 contains the ID of the new parent /// </param> protected void OnItemMoving(object sender, EventArgs args) { Assert.IsTrue(args != null, "args != null"); if (args != null && _auditItemMoving) { using (new SecurityDisabler()) { Item item = Event.ExtractParameter(args, 0) as Item; Assert.IsTrue(item != null, "item != null"); if (ShouldAudit(item)) { Sitecore.Data.ID oldParentID = Event.ExtractParameter(args, 1) as Sitecore.Data.ID; Sitecore.Data.ID newParentID = Event.ExtractParameter(args, 2) as Sitecore.Data.ID; Item oldParent = item.Database.Items[oldParentID]; Item newParent = item.Database.Items[newParentID]; if (item != null && oldParent != null && newParent != null && oldParent.ID != newParent.ID) { Log(string.Format("MOVE: [{0}] from: {1}:{2} to: {3}:{4}", item.Name, oldParent.Database.Name, oldParent.Paths.Path, newParent.Database.Name, newParent.Paths.Path)); } } } } }
/// <summary> /// Responds to Sitecore item copying /// </summary> /// <param name="sender"></param> /// <param name="args"> /// Param index 0 contains the Item being copied, /// Param index 1 contains the Item Copy destination, /// Param index 2 contains the Result item name, /// Param index 3 contains the Result item ID, /// Param index 4 contains the boolean indication whether it is a recursive copy (including children) or not /// </param> protected void OnItemCopying(object sender, EventArgs args) { Assert.IsTrue(args != null, "args != null"); if (args != null && _auditItemCopying) { using (new SecurityDisabler()) { Item item = Event.ExtractParameter(args, 0) as Item; Assert.IsTrue(item != null, "item != null"); if (item != null && ShouldAudit(item)) { Item destination = Event.ExtractParameter(args, 1) as Item; string itemName = Event.ExtractParameter(args, 2) as string; Sitecore.Data.ID itemID = Event.ExtractParameter(args, 3) as Sitecore.Data.ID; bool recursive = (bool)Event.ExtractParameter(args, 4); if (item.Parent.Paths.Path == destination.Paths.Path && item.Name != itemName) { Log(string.Format("DUPLICATE: {0}:{1}, destination: {2}/{3}, id: {4}{5}", item.Database.Name, item.Paths.Path, destination.Paths.Path, itemName, itemID.ToString(), item.Children.Count == 0 ? string.Empty : string.Format(" recursive: {0}", recursive.ToString()))); } else { Log(string.Format("COPY: {0}:{1}, destination: {2}/{3}, id: {4}{5}", item.Database.Name, item.Paths.Path, destination.Paths.Path, itemName, itemID.ToString(), item.Children.Count == 0 ? string.Empty : string.Format(" recursive: {0}", recursive.ToString()))); } } } } }
/// <summary> /// /// </summary> /// <param name="output"></param> protected override void DoRender(HtmlTextWriter output) { LanguageCollection languageCollection = LanguageManager.GetLanguages(Sitecore.Context.Database); output.BeginRender(); if (languageCollection.Any()) { output.AddAttribute(HtmlTextWriterAttribute.Class, "pickLanguage"); output.RenderBeginTag(HtmlTextWriterTag.P); foreach (Language language in languageCollection) { Sitecore.Data.ID contextLanguageId = LanguageManager.GetLanguageItemId(language, Sitecore.Context.Database); Item contextLanguage = Sitecore.Context.Database.GetItem(contextLanguageId); string iso = contextLanguage.Fields["Regional Iso Code"].Value; if (string.IsNullOrEmpty(iso)) { iso = contextLanguage["Iso"]; } output.AddAttribute(HtmlTextWriterAttribute.Href, String.Format("?sc_lang={0}", iso)); output.RenderBeginTag(HtmlTextWriterTag.A); output.WriteLine(FieldRenderer.Render(contextLanguage, "Display Image", "mw=20")); output.RenderEndTag(); } output.RenderEndTag(); } output.EndRender(); }
public void HowToMockMediaItemProvider() { const string MyImageUrl = "~/media/myimage.ashx"; Sitecore.Data.ID mediaItemId = Sitecore.Data.ID.NewID; // create some media item. Location, fields and template are not important using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db { new Sitecore.FakeDb.DbItem("my-image", mediaItemId) }) { Sitecore.Data.Items.Item mediaItem = db.GetItem(mediaItemId); // create media provider mock and configure behaviour Sitecore.Resources.Media.MediaProvider mediaProvider = NSubstitute.Substitute.For <Sitecore.Resources.Media.MediaProvider>(); mediaProvider .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == mediaItemId)) .Returns(MyImageUrl); // substitute the original provider with the mocked one using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider)) { string mediaUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem); Xunit.Assert.Equal(MyImageUrl, mediaUrl); } } }
public void Initialize(Sitecore.Mvc.Presentation.Rendering rendering) { Parameter = rendering.Parameters; Locations = Parameter["Location"]; if (!String.IsNullOrEmpty(Locations)) { Sitecore.Data.ID Id = Sitecore.Data.ID.Parse(Locations); Item = Sitecore.Context.Database.GetItem(Id); AddressLine2 = Parameter["Address Line 2"]; Phone = Parameter["Phone"]; URL = Parameter["URL"]; Image = Parameter["Image"]; if (Locations != "{3CF19799-D782-4708-B5F3-09EFFC0C30B5}") { Name = FieldRenderer.Render(Item, "Name"); Address = FieldRenderer.Render(Item, "Address"); MapURL = FieldRenderer.Render(Item, "MapURL"); LocationID = FieldRenderer.Render(Item, "LocationID"); City = FieldRenderer.Render(Item, "City"); State = FieldRenderer.Render(Item, "State"); Zip = FieldRenderer.Render(Item, "Zip"); DefaultImage = FieldRenderer.Render(Item, "DefaultImage", "bc=lightgray&as=1"); } } }
public SiteMetaDataSettings(Guid id) { var db = Sitecore.Context.Database ?? Sitecore.Data.Database.GetDatabase("master"); var dataId = new Sitecore.Data.ID(id); var item = db.GetItem(dataId); Load(item); }
public string AddItem(AddItemDetails details) { if (string.IsNullOrEmpty(details.name) || string.IsNullOrEmpty(details.templateId) || string.IsNullOrEmpty(details.parentId) ) { throwError(HttpStatusCode.BadRequest, "Missing Name, TemplateId or ParentId", "Missing Parameters"); } var templateID = new Sitecore.Data.ID(details.templateId); var parentID = new Sitecore.Data.ID(details.parentId); var db = Sitecore.Context.Database; var parent = db.GetItem(parentID); if (parent == null) { throwError(HttpStatusCode.BadRequest, "ParentId is invalid", "Could not find Parent"); } var template = db.GetItem(templateID); if (template == null) { throwError(HttpStatusCode.BadRequest, "TemplateId is invalid", "Could not find template"); } try { var childItem = parent.Add(details.name, new Sitecore.Data.TemplateID(templateID)); //change sort order to be first if (childItem.Access.CanWrite() && !childItem.Appearance.ReadOnly) { childItem.Editing.BeginEdit(); childItem[FieldIDs.Sortorder] = "1"; childItem.Editing.EndEdit(); } int counter = 1; foreach (Item child in parent.Children) { int sortorder = counter * 100; SetSortorder(child, sortorder); counter++; } return("OK"); } catch (Exception ex) { Sitecore.Diagnostics.Log.Error("Error in Add Item", ex, this); throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError); } }
private string SetTitles(string value) { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(value); HtmlAgilityPack.HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//img[@src]"); if (nodes == null || nodes.Count == 0) { return(value); } string id = null; // non-null indicates need to update field value after looping foreach (HtmlAgilityPack.HtmlNode node in nodes) { string src = node.GetAttributeValue("src", String.Empty); if (src == null) { continue; } Match match = this.regex.Match(src); if (match.Success) { id = match.Groups[1].Value; Sitecore.Data.ID guid = Sitecore.Data.ID.Parse(id); Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(guid); if (item == null) { continue; } string title = String.Format( "{0} [{1}, {2}]", item.Name, item["extension"].ToUpper(), this.FormatBytes(Int32.Parse(item["size"]))); node.SetAttributeValue("title", title); } } if (id == null) { return(value); } StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); doc.Save(sw); sw.Flush(); return(sb.ToString()); }
protected static string formatDateField(Item item, Sitecore.Data.ID fieldID) { DateField field = item.Fields[fieldID]; if (field != null && !String.IsNullOrEmpty(field.Value)) { return(field.DateTime.ToString("dd/MM/yyyy HH:mm")); } return(string.Empty); }
public RedirectSiteSettings(Guid id) { Sitecore.Diagnostics.Log.Info("RedirectSiteSettings: Guid:" + id, this); var db = Sitecore.Context.Database ?? Sitecore.Data.Database.GetDatabase("master"); Sitecore.Diagnostics.Log.Info("Current DB Context:" + db.Name, this); var dataId = new Sitecore.Data.ID(id); var item = db.GetItem(dataId); Load(item); }
public override SC.Data.Items.Item GetItem(SC.Data.ID itemId) { SC.Data.Items.Item item = this.InnerLocator.GetItem(itemId); string message = String.Format( "{0} : GetItem(itemId[{1}]) : {2}", this, itemId, item != null ? item.Paths.FullPath : "null"); SC.Diagnostics.Log.Info(message, this); SC.Diagnostics.Log.Info(Environment.StackTrace, this); return(item); }
public void HowToWorkWithLinkDatabase() { // arrange your database and items Sitecore.Data.ID sourceId = Sitecore.Data.ID.NewID; Sitecore.Data.ID aliasId = Sitecore.Data.ID.NewID; Sitecore.Data.ID linkedItemId = Sitecore.Data.ID.NewID; using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db { new Sitecore.FakeDb.DbItem("source", sourceId), new Sitecore.FakeDb.DbItem("clone"), new Sitecore.FakeDb.DbItem("alias", aliasId, Sitecore.TemplateIDs.Alias) { new Sitecore.FakeDb.DbField("Linked item", linkedItemId) } }) { // arrange desired LinkDatabase behavior var behavior = Substitute.For <Sitecore.Links.LinkDatabase>(); Sitecore.Data.Items.Item source = db.GetItem("/sitecore/content/source"); Sitecore.Data.Items.Item alias = db.GetItem("/sitecore/content/alias"); Sitecore.Data.Items.Item clone = db.GetItem("/sitecore/content/clone"); string sourcePath = source.Paths.FullPath; behavior.GetReferrers(source).Returns(new[] { new Sitecore.Links.ItemLink(alias, linkedItemId, source, sourcePath), new Sitecore.Links.ItemLink(clone, Sitecore.FieldIDs.Source, source, sourcePath) }); // link database is clean Xunit.Assert.Empty(Sitecore.Globals.LinkDatabase.GetReferrers(source)); using (new Sitecore.FakeDb.Links.LinkDatabaseSwitcher(behavior)) { Sitecore.Links.ItemLink[] referrers = Sitecore.Globals.LinkDatabase.GetReferrers(source); const int expected = 2; Xunit.Assert.Equal(referrers.Count(), expected); Xunit.Assert.Single(referrers.Where(r => r.SourceItemID == clone.ID && r.TargetItemID == source.ID)); Xunit.Assert.Single(referrers.Where(r => r.SourceItemID == alias.ID && r.TargetItemID == source.ID)); } // link database is clean again Xunit.Assert.Empty(Sitecore.Globals.LinkDatabase.GetReferrers(source)); } }
public void ProcessRequest(HttpContext context) { var gid = context.Request.QueryString["gid"]; var triggerCampaign = context.Request.QueryString["triggerCampaign"]; bool isTriggerCampaign = false; bool.TryParse(triggerCampaign.ToString(), out isTriggerCampaign); if (!string.IsNullOrEmpty(gid.ToString()) && isTriggerCampaign) { if (!Tracker.IsActive) { Tracker.StartTracking(); } if (Tracker.IsActive) { if (Tracker.Current.CurrentPage != null) { var id = new Sitecore.Data.ID(gid.ToString()); Item campaignItem = Context.Database.GetItem(id); CampaignItem campaignToTrigger = new CampaignItem(campaignItem); if (campaignToTrigger != null) { Tracker.Current.CurrentPage.TriggerCampaign(campaignToTrigger); Console.WriteLine("Campaign is successfully triggered."); } else { Log.Error("Campaign with ID " + gid + " does not exist", this); } } else { Log.Error("Tracker.Current.CurrentPage is null", this); } } else { Log.Warn("The tracker is not active. Unable to register the campaign.", this); } } else { Log.Warn("There is no campaign selected.", this); } }
private Sitecore.Data.ItemUri parseItemUri(string Message) { Match match = Regex.Match(Message, @"(?<db>\w+):(?<path>[^,]+), language: (?<language>[^,]+), version: (?<version>[^,]+), id: (?<id>\{.{36}\}).*"); if (!match.Success) { return(null); } Sitecore.Data.Version version = new Sitecore.Data.Version(match.Groups["version"].Value); Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse(match.Groups["language"].Value); Sitecore.Data.ID id = Sitecore.Data.ID.Parse(match.Groups["id"].Value); Sitecore.Data.Database db = Sitecore.Data.Database.GetDatabase(match.Groups["db"].Value); return(new Sitecore.Data.ItemUri(id, language, version, db)); }
public void HowToCreateItemWithSpecificTemplate() { Sitecore.Data.ID templateId = Sitecore.Data.ID.NewID; using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db { new Sitecore.FakeDb.DbTemplate("products", templateId) { "Name" }, new Sitecore.FakeDb.DbItem("Apple") { TemplateID = templateId } }) { Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/apple"); Xunit.Assert.Equal(templateId, item.TemplateID); Xunit.Assert.NotNull(item.Fields["Name"]); } }
public override void Process(PublishItemContext context) { Sitecore.Data.ID itmID = context.ItemId; Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item item = masterDB.GetItem(itmID); if (item == null) { return; } //string spName = "dbo.AddToPublishLog"; //String ConnectionString = Sitecore.Configuration.Settings.GetConnectionString("custom"); //if (!String.IsNullOrWhiteSpace(ConnectionString)) //{ // using (SqlConnection connection = new SqlConnection(ConnectionString)) // { // using (SqlCommand command = new SqlCommand(spName, connection)) // { // command.CommandType = CommandType.StoredProcedure; // command.Parameters.Add(new SqlParameter("@Site", Sitecore.Context.Site.Name.ToString())); // command.Parameters.Add(new SqlParameter("@ItemID", item.ID.ToString())); // Item produdctGp = GetProductGroup(item); // command.Parameters.Add(new SqlParameter("@ProductGroupItemID", produdctGp == null ? string.Empty : produdctGp.ID.ToString())); // Item productCat = GetProductCategory(item); // command.Parameters.Add(new SqlParameter("@ProductCategoryItemID", productCat == null ? string.Empty : productCat.ID.ToString())); // command.Parameters.Add(new SqlParameter("@Language", String.Empty)); // command.Parameters.Add(new SqlParameter("@Mode", String.Empty)); // command.Parameters.Add(new SqlParameter("@RepublishAll", String.Empty)); // command.Parameters.Add(new SqlParameter("@SourceDatabase", String.Empty)); // command.Parameters.Add(new SqlParameter("@TargetDatabase", String.Empty)); // command.Parameters.Add(new SqlParameter("@RequestedBy", String.Empty)); // connection.Open(); // command.ExecuteNonQuery(); // } // } //} }
private Sitecore.Data.ItemUri parseItemUri(string Message) { Match match = Regex.Match(Message, @"(?<db>\w+):(?<path>[^,]+), language: (?<language>[^,]+), version: (?<version>[^,]+), id: (?<id>\{.{36}\}).*"); if (!match.Success) { return(null); } var versionNumber = int.Parse(match.Groups["version"].Value); var item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(match.Groups["id"].Value)); var currentVersion = item.Versions.GetVersionNumbers().First(x => x.Number == versionNumber); Sitecore.Globalization.Language language = Sitecore.Globalization.Language.Parse(match.Groups["language"].Value); Sitecore.Data.ID id = Sitecore.Data.ID.Parse(match.Groups["id"].Value); Sitecore.Data.Database db = Sitecore.Data.Database.GetDatabase(match.Groups["db"].Value); return(new Sitecore.Data.ItemUri(id, language, currentVersion, db)); }
protected bool PublishingTargetApplies( Sitecore.Data.Items.Item item, Sitecore.Data.ID publishingTarget) { while (item != null) { string restricted = item[Sitecore.FieldIDs.PublishingTargets]; if (!(String.IsNullOrEmpty(restricted) || restricted.Contains(item.ID.ToString()))) { return(false); } item = item.Parent; } return(true); }
// retrieve the versions of the item to process in the relevant language(s) protected SC.Data.Items.Item[] GetVersionsToProcess( SC.Data.Database db, SC.Data.ID id) { // default version of the item in default language SC.Data.Items.Item item = db.GetItem(id); SC.Diagnostics.Assert.IsNotNull(item, "item"); // all versions of the item to process in all languages to process List <SC.Data.Items.Item> versions = new List <SC.Data.Items.Item>(); // languages to process List <SC.Globalization.Language> languages = new List <SC.Globalization.Language>(); if (this.AllLanguages) { languages.AddRange(item.Languages); } else { languages.Add(item.Language); } foreach (SC.Globalization.Language language in languages) { // default version of item in individual language SC.Data.Items.Item languageItem = db.GetItem(id, language); SC.Diagnostics.Assert.IsNotNull(languageItem, "languageItem"); if (this.AllVersions) { versions.AddRange(languageItem.Versions.GetVersions()); } else { versions.Add(languageItem); } } return(versions.ToArray()); }
public ActionResult Index(string email) { // 10.3 Add entered email to session Sitecore.Analytics.Tracker.Current.Session.Identify(email); string message = ""; var contact = Sitecore.Analytics.Tracker.Current.Contact; var emails = contact.GetFacet <IContactEmailAddresses>("Emails"); if (!emails.Entries.Contains("personal")) { var personalEmail = emails.Entries.Create("personal"); personalEmail.SmtpAddress = email; emails.Preferred = "personal"; message = "Email Added; "; } // 10.4 Add Outcome Subscribed Sitecore.Data.ID outcomeID = new Sitecore.Data.ID("{C41E28D0-66C4-423F-84D5-09DEABD6294A}"); Sitecore.Data.ID contactID = new Sitecore.Data.ID(contact.ContactId); var co = new Sitecore.Analytics.Outcome.Model.ContactOutcome(Sitecore.Data.ID.NewID, outcomeID, contactID); Sitecore.Analytics.Tracker.Current.RegisterContactOutcome(co); message += "Subscribed; "; // 10 optional Sitecore.Analytics.Data.PageEventData pageEvent = new Sitecore.Analytics.Data.PageEventData("Newsletter Signup"); var page = Sitecore.Analytics.Tracker.Current.CurrentPage; page.Register(pageEvent); message += "Registered; "; TempData["message"] = message; return(View("Confirmation")); }
public static SC.Data.Items.Item GetAncestorWithTemplateThatIsOrInheritsFrom( this SC.Data.Items.Item item, SC.Data.ID templateID) { string id = templateID.ToString(); while (item != null) { string[] templates = item.Template.GetSelfAndDerivedTemplates(); if (new List <string>(templates).Contains(id)) { return(item); } item = item.Parent; } return(null); }
public override void Expand(List<Sitecore.Data.Items.Item> masters, Sitecore.Data.Items.Item item) { Sitecore.Data.ID id = new Sitecore.Data.ID(TEMPLATE_ID); Sitecore.Collections.ChildList items = item.Children; foreach (Sitecore.Data.Items.Item child in items) { if (child.TemplateID.Equals(id)) { for (int i = 0; i < masters.Count; i++) { if (masters[i].ID.Equals(id)) { masters.RemoveAt(i); break; } } break; } } }
public override void Expand(List <Sitecore.Data.Items.Item> masters, Sitecore.Data.Items.Item item) { Sitecore.Data.ID id = new Sitecore.Data.ID(TEMPLATE_ID); Sitecore.Collections.ChildList items = item.Children; foreach (Sitecore.Data.Items.Item child in items) { if (child.TemplateID.Equals(id)) { for (int i = 0; i < masters.Count; i++) { if (masters[i].ID.Equals(id)) { masters.RemoveAt(i); break; } } break; } } }
protected void Page_Load(object sender, EventArgs e) { thisUrl = current.PageSummary.QualifiedUrl; if (!String.IsNullOrEmpty(WebUtil.GetQueryString("searchloc"))) { location = WebUtil.GetQueryString("searchloc", ""); } //display the club info. if (!String.IsNullOrEmpty(WebUtil.GetQueryString("cid"))) { try { Sitecore.Data.ID id = new Sitecore.Data.ID(WebUtil.GetQueryString("cid")); Item c = Sitecore.Context.Database.GetItem(id); if (c != null) { ClubInfoPh.Visible = true; club = new Club(c); txtClubCode.Value = club.ClubItm.ClubId.Raw; } } catch (Exception ex) { Log.Warn(String.Format("Could not fetch club for 12 for 10 offer from qs: {0} error: {1}", WebUtil.GetQueryString("cid"), ex.Message), this); mm.virginactive.common.EmailMessagingService.ErrorEmailNotification.SendMail(ex); } } Control scriptPh = this.Page.FindControl("ScriptPh"); if (scriptPh != null) { scriptPh.Controls.Add(new LiteralControl(@" <script src='/va_campaigns/js/ajax.js'></script> <script src='/virginactive/scripts/infobox_packed.js'></script> ")); if (!String.IsNullOrEmpty(WebUtil.GetQueryString("searchloc"))) { scriptPh.Controls.Add(new LiteralControl(String.Format(@"<script> GetSuggestions('{0}'); viewClubFinderResults(); </script>", WebUtil.GetQueryString("searchloc")))); ResultsPh.Visible = true; } } //add the item specific css stylesheet string classNames = article.Attributes["class"]; article.Attributes.Add("class", classNames.Length > 0 ? classNames + " membs-" + current.CampaignBase.Cssstyle.Raw : "membs-" + current.CampaignBase.Cssstyle.Raw); //Add dynamic content to header HtmlHead head = (HtmlHead)Page.Header; //Add Open Tag if (Session["sess_User"] != null) { User objUser = (User)Session["sess_User"]; if (objUser.Preferences != null) { if (objUser.Preferences.MarketingCookies && objUser.Preferences.MetricsCookies) { head.Controls.Add(new LiteralControl(OpenTagHelper.OpenTagVirginActiveUK)); } } } //Add Page Title HtmlTitle title = (HtmlTitle)Page.FindControl("title"); if (title != null) { title.Text = current.PageSummary.NavigationTitle.Raw + " | " + Translate.Text("Virgin Active"); } //Add Css Style Sheet HtmlGenericControl link = new HtmlGenericControl("LINK"); link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("type", "text/css"); link.Attributes.Add("href", "/va_campaigns/css/membership.css"); ////Add to the page header head.Controls.Add(link); }
/// <summary> /// Generates Sitecore FakeDb /// </summary> /// <returns></returns> private Sitecore.FakeDb.Db GenerateFakeDb() { Sitecore.Data.ID templateId = new Sitecore.Data.ID("{3AD0E3AB-0CC7-41F1-B9FD-5FD9DDEF50B4}"); Sitecore.Data.ID referencedItemId = new Sitecore.Data.ID(); return new Sitecore.FakeDb.Db("master") { new Sitecore.FakeDb.DbTemplate("TestTemplate", templateId) { FieldNames.TextField, FieldNames.EmptyField, new Sitecore.FakeDb.DbField(FieldNames.CheckboxField) { Type = "Checkbox" }, new Sitecore.FakeDb.DbField(FieldNames.CheckboxFieldUnchecked) { Type = "Checkbox" }, new Sitecore.FakeDb.DbField(FieldNames.DateFieldFrom) { Type = "DateTime" }, new Sitecore.FakeDb.DbField(FieldNames.DateFieldTo) { Type = "DateTime" }, new Sitecore.FakeDb.DbField(FieldNames.DateFieldEmpty) { Type = "DateTime" }, new Sitecore.FakeDb.DbField(FieldNames.DateFieldAnother) { Type = "DateTime" }, new Sitecore.FakeDb.DbField(FieldNames.DateFieldAnother2) { Type = "DateTime" }, FieldNames.LinkFieldExternal, new Sitecore.FakeDb.DbLinkField(FieldNames.LinkFieldInternal) { LinkType = "internal", Url = "/sitecore/content/TestItemReferenced" }, FieldNames.IntegerField, FieldNames.FieldWithDoubleValue, FieldNames.FieldWithAnotherDoubleValue }, new Sitecore.FakeDb.DbItem("TestItemReferenced", referencedItemId) { TemplateID = templateId, Fields = { { FieldNames.TextField, "Value 1" }, { FieldNames.CheckboxField, "1" }, { FieldNames.CheckboxFieldUnchecked, "" }, { FieldNames.DateFieldFrom, DateUtil.ToIsoDate(DateTime.Now.AddDays(-1)) }, { FieldNames.DateFieldTo, DateUtil.ToIsoDate(DateTime.Now.AddDays(1)) }, { FieldNames.DateFieldEmpty, "" }, { FieldNames.LinkFieldExternal, "<link linktype=\"external\" url=\"http://facebook.com\" />" } } }, new Sitecore.FakeDb.DbItem("TestItem") { TemplateID = templateId, Fields = { { FieldNames.TextField, "Value 1" }, { FieldNames.CheckboxField, "1" }, { FieldNames.CheckboxFieldUnchecked, "" }, { FieldNames.DateFieldFrom, DateUtil.ToIsoDate(DateTime.Now.AddDays(-1)) }, { FieldNames.DateFieldTo, DateUtil.ToIsoDate(DateTime.Now.AddDays(1)) }, { FieldNames.DateFieldAnother, "20150821T143143" }, { FieldNames.DateFieldAnother2, "20150821T135808Z" }, { FieldNames.DateFieldEmpty, "" }, { FieldNames.LinkFieldExternal, "<link linktype=\"external\" url=\"http://google.com\" />" }, new Sitecore.FakeDb.DbLinkField(FieldNames.LinkFieldInternal) { LinkType = "internal", Url = "/sitecore/content/TestItemReferenced", TargetID = referencedItemId }, { FieldNames.IntegerField, "123" }, { FieldNames.FieldWithDoubleValue, "3.14159265358979" }, { FieldNames.FieldWithAnotherDoubleValue, "100,000.001" } } //String.Format("<link linktype=\"internal\" id=\"{0}\" url=\"{1}\" />", referencedItemId.Guid.ToString(), "/sitecore/content/TestItemReferenced") } }; }
public static void ShowItemBrowser(string header, string text, string icon, string button, Sitecore.Data.ID root, Sitecore.Data.ID selected) { ShowItemBrowser( header, text, icon, button, root, selected, Sitecore.Context.ContentDatabase.Name); }
public static bool IsBasedOn(Item item, Sitecore.Data.ID templateID) { var template = Sitecore.Data.Managers.TemplateManager.GetTemplate(item.TemplateID, item.Database); return(template.DescendsFromOrEquals(templateID)); }
public string GetCategoryArticle(Sitecore.Data.ID idCategoryTemplate, Item item) { MultilistField ListValue = null; string CategoryValue = string.Empty; Item _items = Sitecore.Context.Database.GetItem(item.ID); if (_items.TemplateID == Sitecore.Feature.Library.Templates.ArticleItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.ArticleItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.PremiereWealthHighlightItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.PremiereWealthHighlightItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.SyariahArticleItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.ApplyTabs.Fields.IconName]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.ApplyTabs.Fields.IconName].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.NewsItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.NewsItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.MoreFromSyariahItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.MoreFromSyariahItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.PremiereWealtStoryForYouItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.PremiereWealtStoryForYouItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.DestinationReviewItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.DestinationReviewItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.TreatsPointItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.TreatsPointItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.LatestOfferCategory.Fields.IconName].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.CSREventItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.CSREventItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.LatestOfferCategory.Fields.IconName].Value).FirstOrDefault(); } } if (_items.TemplateID == Sitecore.Feature.Library.Templates.BusinessArticleItem.ID) { ListValue = _items.Fields[Sitecore.Feature.Library.Templates.BusinessArticleItem.Fields.Category]; if (ListValue != null) { Item[] items = ListValue.GetItems(); CategoryValue = items.Select(x => x.Fields[Sitecore.Feature.Library.Templates.GeneralValue.Fields.Title].Value).FirstOrDefault(); } } return(CategoryValue); }
/// <summary> /// Returns the id sanitized in the format "uid-{ShortID}" for use in html as a uid. /// </summary> /// <param name="id"></param> /// <returns></returns> public static string Sanitize(this Sitecore.Data.ID id) { return("uid-" + id.ToShortID()); }
public static void ShowItemBrowser(string header, string text, string icon, string button, Sitecore.Data.ID root, Sitecore.Data.ID selected, string database) { //string str = selected; //Item item = Client.ContentDatabase.Items[selected]; //if (item != null) //{ // selected = item.ID.ToString(); // if (item.Parent != null) // { // str = item.ParentID.ToString(); // } //} UrlString str2 = new UrlString("/sitecore/shell/Applications/Item browser.aspx"); str2.Append("db", database); str2.Append("id", selected.ToString()); str2.Append("fo", selected.ToString()); str2.Append("ro", root.ToString()); str2.Append("he", header); str2.Append("txt", text); str2.Append("ic", icon); str2.Append("btn", button); SheerResponse.ShowModalDialog(str2.ToString(), true); }
/// <summary> /// Formats a Sitecore ID or Guid for solr search. /// </summary> protected virtual string FormatIdForSearch(Sitecore.Data.ID id) { return(FormatIdForSearch(id.ToString())); }
public Sitecore.Data.Items.Item Get(Sitecore.Data.ID id) { return(Db.GetItem(id)); }