/// <summary> /// For a VisualList, the value contents /// should be a pipe delimited list of MediaItemIDs, but handle old /// Image XmlValue contents as well. (in the case that this field was originally an Image field) /// </summary> /// <param name="i"></param> /// <param name="bRandom"></param> /// <returns></returns> public List<MediaItem> MediaItems() { List<MediaItem> results = new List<MediaItem>(); foreach (string id in vlField.Items) { Item item = Sitecore.Context.Database.GetItem(id); if (item != null) { results.Add((MediaItem)item); } else { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Sitecore.Context.Database.GetItem(mediaID); if (item != null) results.Add((MediaItem)item); } } } return results; }
/// <summary> /// For a VisualList, the value contents /// should be a pipe delimited list of MediaItemIDs, but handle old /// Image XmlValue contents as well. (in the case that this field was originally an Image field) /// </summary> /// <param name="i"></param> /// <param name="bRandom"></param> /// <returns></returns> public List<MediaItem> MediaItems() { List<MediaItem> results = new List<MediaItem>(); foreach (string id in vlField.Items) { Item item = Sitecore.Context.Database.GetItem(id); if (item != null) { results.Add((MediaItem)item); } //if id is not a valid Sitecore id and has at least one closing angle bracket else if(!Sitecore.Data.ID.IsID(id) && id.IndexOf(">", System.StringComparison.Ordinal) > -1 ) { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Sitecore.Context.Database.GetItem(mediaID); if (item != null) results.Add((MediaItem)item); } } } return results; }
/// <summary> /// For a VisualList, the value contents /// should be a pipe delimited list of MediaItemIDs, but handle old /// Image XmlValue contents as well. (in the case that this field was originally an Image field) /// </summary> /// <param name="i"></param> /// <param name="bRandom"></param> /// <returns></returns> public List <MediaItem> MediaItems() { List <MediaItem> results = new List <MediaItem>(); foreach (string id in vlField.Items) { Item item = Sitecore.Context.Database.GetItem(id); if (item != null) { results.Add((MediaItem)item); } //if id is not a valid Sitecore id and has at least one closing angle bracket else if (!Sitecore.Data.ID.IsID(id) && id.IndexOf(">", System.StringComparison.Ordinal) > -1) { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Sitecore.Context.Database.GetItem(mediaID); if (item != null) { results.Add((MediaItem)item); } } } } return(results); }
IList <Item> GetItems() { var result = new List <Item>(); var values = new ListString(GetItem()[FieldID]); foreach (var id in values) { var item = Client.ContentDatabase.GetItem(id); if (item != null) { result.Add(item); } else { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Client.ContentDatabase.GetItem(mediaID); if (item != null) { result.Add(item); } } } } return(result); }
/// <summary> /// For a VisualList, the value contents /// should be a pipe delimited list of MediaItemIDs, but handle old /// Image XmlValue contents as well. (in the case that this field was originally an Image field) /// </summary> /// <param name="i"></param> /// <param name="bRandom"></param> /// <returns></returns> public List <MediaItem> MediaItems() { List <MediaItem> results = new List <MediaItem>(); foreach (string id in vlField.Items) { Item item = Sitecore.Context.Database.GetItem(id); if (item != null) { results.Add((MediaItem)item); } else { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Sitecore.Context.Database.GetItem(mediaID); if (item != null) { results.Add((MediaItem)item); } } } } return(results); }
private void Follow() { Sitecore.Shell.Applications.ContentEditor.XmlValue xmlValue = this.XmlValue; string attribute = xmlValue.GetAttribute("linktype"); if (attribute != null) { if ((attribute != "internal") && (attribute != "media")) { if ((attribute != "external") && (attribute != "mailto")) { if (attribute == "anchor") { SheerResponse.Alert(Translate.Text("You cannot follow an Anchor link."), new string[0]); return; } if (attribute == "javascript") { SheerResponse.Alert(Translate.Text("You cannot follow a Javascript link."), new string[0]); } return; } } else { string str2 = xmlValue.GetAttribute("id"); if (!string.IsNullOrEmpty(str2)) { Context.ClientPage.SendMessage(this, "item:load(id=" + str2 + ")"); } return; } string str3 = xmlValue.GetAttribute("url"); if (!string.IsNullOrEmpty(str3)) { SheerResponse.Eval("window.open('" + str3 + "', '_blank')"); } } }
private string GetLinkPath() { Sitecore.Shell.Applications.ContentEditor.XmlValue xmlValue = this.XmlValue; string attribute = xmlValue.GetAttribute("id"); string str2 = string.Empty; Item item = null; if (!string.IsNullOrEmpty(attribute) && ID.IsID(attribute)) { item = Client.ContentDatabase.GetItem(new ID(attribute)); } if (item != null) { if (this.Value.EndsWith("." + "aspx")) { if (item.Paths.Path.StartsWith("/sitecore/content", StringComparison.InvariantCulture)) { str2 = item.Paths.Path.Substring("/sitecore/content".Length); if (LinkManager.AddAspxExtension) { str2 = str2 + ("." + "aspx"); } return(str2); } if (item.Paths.Path.StartsWith("/sitecore/media library", StringComparison.InvariantCulture)) { str2 = item.Paths.Path + ("." + "aspx"); } return(str2); } if (item.Paths.Path.StartsWith("/sitecore/media library", StringComparison.InvariantCulture)) { str2 = item.Paths.Path.Substring("/sitecore/media library".Length); } return(str2); } return(xmlValue.GetAttribute("url")); }
IList<Item> GetItems() { var result = new List<Item>(); var values = new ListString(GetItem()[FieldID]); foreach (var id in values) { var item = Client.ContentDatabase.GetItem(id); if (item != null) { result.Add(item); } else { // If this field used to be an Image field then the value was stored // as an XmlValue instead of just an ItemID // So, we'll try to parse it out. Sitecore.Shell.Applications.ContentEditor.XmlValue xmlVal = new Sitecore.Shell.Applications.ContentEditor.XmlValue(id, "image"); string mediaID = xmlVal.GetAttribute("mediaid"); if (!String.IsNullOrEmpty(mediaID)) { item = Client.ContentDatabase.GetItem(mediaID); if (item != null) result.Add(item); } } } return result; }
protected override bool LoadPostData(string value) { Assert.ArgumentNotNull(value, "value"); bool flag = base.LoadPostData(value); if (flag) { if (string.IsNullOrEmpty(this.Value)) { this.ClearLink(); return(true); } Sitecore.Shell.Applications.ContentEditor.XmlValue xmlValue = this.XmlValue; if (this.GetLinkPath() == this.Value) { return(flag); } if (xmlValue.GetAttribute("linktype").Length == 0) { xmlValue.SetAttribute("linktype", (this.Value.IndexOf("://", StringComparison.InvariantCulture) >= 0) ? "external" : "internal"); } string str2 = string.Empty; if (xmlValue.GetAttribute("linktype") == "internal") { string path = string.Empty; if (this.Value.EndsWith("." + "aspx")) { if (this.Value.StartsWith("/sitecore/media library")) { path = this.Value.Remove(this.Value.Length - ("." + "aspx").Length); } else { path = "/sitecore/content" + this.Value.Remove(this.Value.Length - ("." + "aspx").Length); } } Item item = Client.ContentDatabase.GetItem(path); if (item != null) { str2 = item.ID.ToString(); } } else if (xmlValue.GetAttribute("linktype") == "media") { string str4 = "/sitecore/media library" + this.Value; Item item2 = Client.ContentDatabase.GetItem(str4); if (item2 != null) { str2 = item2.ID.ToString(); } } else { xmlValue.SetAttribute("url", this.Value); } if (!string.IsNullOrEmpty(str2)) { xmlValue.SetAttribute("id", str2); } this.XmlValue = xmlValue; } return(flag); }