public override Node GetParentNode(Node node) { var media = new umbraco.cms.businesslogic.media.Media(Convert.ToInt32(node.Id)); if (media.ParentId == -1) return null; return GetNode(media.ParentId.ToString()); }
private void ReindexMedia(Guid mediaGuid, ItemIdentifier itemId) { umbraco.cms.businesslogic.media.Media m = new umbraco.cms.businesslogic.media.Media(mediaGuid); if (m != null) { //first, clear the cache umbraco.library.ClearLibraryCacheForMedia(m.Id); XmlNode n = m.ToXml(new XmlDocument(), true); if (n != null) { XElement mediaXnode = XDocument.Parse(n.OuterXml).Root; //add to all indexes supporting unpublished content try { ExamineManager.Instance.ReIndexNode(mediaXnode, IndexTypes.Media, ExamineManager.Instance.IndexProviderCollection.OfType <BaseUmbracoIndexer>() .Where(x => x.EnableDefaultEventHandler)); } catch (Exception ex) { RevisionLog.Instance.AddItemEntry(itemId, this.GetType(), "UpdateLuceneIndexes", ex.ToString(), LogItemEntryType.Error); } } } }
protected void SubmitButton_Click(object sender, EventArgs e) { var media = Media.MakeNew(TextBoxTitle.Text, cms.businesslogic.media.MediaType.GetByAlias(Constants.Conventions.MediaTypes.Image), BasePage.Current.getUser(), int.Parse(MediaPickerControl.Value)); foreach (var property in media.GenericProperties) { if (property.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id) { UploadField.DataTypeDefinitionId = property.PropertyType.DataTypeDefinition.Id; UploadField.Data.PropertyId = property.Id; } } UploadField.DataEditor.Save(); //MCH NOTE: After having refactored the legacy api to use the new api under the hood, it is necessary to set the property value and save the media. var prop = media.GenericProperties.FirstOrDefault(x => x.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id); prop.Value = UploadField.Data.Value; media.Save(); // Generate xml on image media.XmlGenerate(new XmlDocument()); pane_upload.Visible = false; //this seems real ugly since we apparently already have the properties above (props)... but this data layer is insane and undecipherable:) string mainImage = media.getProperty(Constants.Conventions.Media.File).Value.ToString(); string extension = mainImage.Substring(mainImage.LastIndexOf(".") + 1, mainImage.Length - mainImage.LastIndexOf(".") - 1); var thumbnail = mainImage.Remove(mainImage.Length - extension.Length - 1, extension.Length + 1) + "_thumb.jpg"; string width = media.getProperty(Constants.Conventions.Media.Width).Value.ToString(); string height = media.getProperty(Constants.Conventions.Media.Height).Value.ToString(); int id = media.Id; feedback.Style.Add("margin-top", "8px"); feedback.type = uicontrols.Feedback.feedbacktype.success; if (mainImage.StartsWith("~")) { mainImage = mainImage.Substring(1); } if (thumbnail.StartsWith("~")) { thumbnail = thumbnail.Substring(1); } feedback.Text += "<div style=\"text-align: center\"> <a target=\"_blank\" href='" + mainImage + "'><img src='" + thumbnail + "' style='border: none;'/><br/><br/>"; feedback.Text += ui.Text("thumbnailimageclickfororiginal") + "</a><br/><br/></div>"; if (!string.IsNullOrEmpty(OnClientUpload)) { feedback.Text += @" <script type=""text/javascript""> jQuery(document).ready(function() { " + OnClientUpload + @".call(this, {imagePath: '" + mainImage + @"', thumbnailPath: '" + thumbnail + @"', width: " + width + @", height: " + height + @", id: " + id + @"}); }); </script>"; } }
public override void Render(ref XmlTree tree) { if (UseOptimizedRendering == false) { //We cannot run optimized mode since there are subscribers to events/methods that require document instances // so we'll render the original way by looking up the docs. var docs = new Media(m_id).Children; var args = new TreeEventArgs(tree); OnBeforeTreeRender(docs, args); foreach (var dd in docs) { var e = dd; var xNode = PerformNodeRender(e.Id, e.Text, e.HasChildren, e.ContentType.IconUrl, e.ContentType.Alias, () => GetLinkValue(e, e.Id.ToString(CultureInfo.InvariantCulture))); OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } OnAfterTreeRender(docs, args); } else { //We ARE running in optmized mode, this means we will NOT be raising the BeforeTreeRender or AfterTreeRender // events - we've already detected that there are not subscribers or implementations // to call so that is fine. var entities = Services.EntityService.GetChildren(m_id, UmbracoObjectTypes.Media).ToArray(); foreach (UmbracoEntity entity in entities) { var e = entity; var xNode = PerformNodeRender(e.Id, entity.Name, e.HasChildren, e.ContentTypeIcon, e.ContentTypeAlias, () => GetLinkValue(e)); OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } } }
public override void Render(ref XmlTree tree) { if (UseOptimizedRendering == false) { //We cannot run optimized mode since there are subscribers to events/methods that require document instances // so we'll render the original way by looking up the docs. var docs = new Media(m_id).Children; var args = new TreeEventArgs(tree); OnBeforeTreeRender(docs, args); foreach (var dd in docs) { var e = dd; var xNode = PerformNodeRender(e.Id, e.Text, e.HasChildren, e.ContentType.IconUrl, e.ContentType.Alias, () => GetLinkValue(e, e.Id.ToString(CultureInfo.InvariantCulture))); OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } OnAfterTreeRender(docs, args); } else { //We ARE running in optmized mode, this means we will NOT be raising the BeforeTreeRender or AfterTreeRender // events - we've already detected that there are not subscribers or implementations // to call so that is fine. var entities = Services.EntityService.GetChildren(m_id, UmbracoObjectTypes.Media).ToArray(); foreach (UmbracoEntity entity in entities) { var e = entity; var xNode = PerformNodeRender(e.Id, entity.Name, e.HasChildren, e.ContentTypeIcon, e.ContentTypeAlias, () => GetLinkValue(e)); OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } } }
/// <summary> /// Returns the value for a link in WYSIWYG mode, by default only media items that have a /// DataTypeUploadField are linkable, however, a custom tree can be created which overrides /// this method, or another GUID for a custom data type can be added to the LinkableMediaDataTypes /// list on application startup. /// </summary> /// <param name="dd"></param> /// <param name="nodeLink"></param> /// <returns></returns> public virtual string GetLinkValue(Media dd, string nodeLink) { var props = dd.GenericProperties; foreach (Property p in props) { Guid currId = p.PropertyType.DataTypeDefinition.DataType.Id; if (LinkableMediaDataTypes.Contains(currId) && string.IsNullOrEmpty(p.Value.ToString()) == false) { return(p.Value.ToString()); } } return(""); }
public static string GetPropertyAsMediaItem(this IPublishedContent content, string field) { if (string.IsNullOrEmpty(content.GetPropertyValue <string>(field)) == false) { var mItem = new umbraco.cms.businesslogic.media.Media(int.Parse(content.GetPropertyValue <string>(field))); var propertyValue = string.Empty; var property = mItem.getProperty("umbracoFile"); if (property != null) { propertyValue = property.Value.ToString(); } return(propertyValue); } return(string.Empty); }
public static void refreshMediaSection(int umbracoMediaId) { if (umbracoMediaId < 1000) { return; } var m = new umbraco.cms.businesslogic.media.Media(umbracoMediaId); if (m == null) { return; } // Voer wat Umbraco UI opties uit if (umbraco.BasePages.BasePage.Current != null) { // Ververs media tree string path, url; var p = m.getProperty(Constants.UmbracoPropertyAliasStatus); if (p != null && (p.Value as String) == "Original") { path = m.Parent.Path; url = "editMedia.aspx?id=" + m.ParentId.ToString(); } else { path = m.Path; url = "editMedia.aspx?id=" + m.Id.ToString(); } // Ververs de tree aan de linker kant (in de media section refreshMediaTree(path); // Open media node string script = String.Format(umbraco.BasePages.ClientTools.Scripts.ChangeContentFrameUrl(url)); System.Web.UI.ScriptManager.RegisterStartupScript(umbraco.BasePages.BasePage.Current, umbraco.BasePages.BasePage.Current.GetType(), "showMediaId", script, true); } }
/// <summary> /// Returns the value for a link in WYSIWYG mode, by default only media items that have a /// DataTypeUploadField are linkable, however, a custom tree can be created which overrides /// this method, or another GUID for a custom data type can be added to the LinkableMediaDataTypes /// list on application startup. /// </summary> /// <param name="dd"></param> /// <param name="nodeLink"></param> /// <returns></returns> public virtual string GetLinkValue(Media dd, string nodeLink) { var props = dd.GenericProperties; foreach (Property p in props) { Guid currId = p.PropertyType.DataTypeDefinition.DataType.Id; if (LinkableMediaDataTypes.Contains(currId) && string.IsNullOrEmpty(p.Value.ToString()) == false) { return p.Value.ToString(); } } return ""; }
private void ReindexMedia(Guid mediaGuid, ItemIdentifier itemId) { umbraco.cms.businesslogic.media.Media m = new umbraco.cms.businesslogic.media.Media(mediaGuid); if (m != null) { //first, clear the cache umbraco.library.ClearLibraryCacheForMedia(m.Id); XmlNode n = m.ToXml(new XmlDocument(), true); if (n != null) { XElement mediaXnode = XDocument.Parse(n.OuterXml).Root; //add to all indexes supporting unpublished content try { ExamineManager.Instance.ReIndexNode(mediaXnode, IndexTypes.Media, ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>() .Where(x => x.EnableDefaultEventHandler)); } catch (Exception ex) { RevisionLog.Instance.AddItemEntry(itemId, this.GetType(), "UpdateLuceneIndexes", ex.ToString(), LogItemEntryType.Error); } } } }
private void Move(CMSNode newParent) { MoveEventArgs e = new MoveEventArgs(); FireBeforeMove(e); if (!e.Cancel) { //first we need to establish if the node already exists under the newParent node //var isNewParentInPath = (Path.Contains("," + newParent.Id + ",")); //if it's the same newParent, we can save some SQL calls since we know these wont change. //level and path might change even if it's the same newParent because the newParent could be moving somewhere. if (ParentId != newParent.Id) { int maxSortOrder = SqlHelper.ExecuteScalar <int>("select coalesce(max(sortOrder),0) from umbracoNode where parentid = @parentId", SqlHelper.CreateParameter("@parentId", newParent.Id)); this.Parent = newParent; this.sortOrder = maxSortOrder + 1; } //detect if we have moved, then update the level and path // issue: http://issues.umbraco.org/issue/U4-1579 if (this.Path != newParent.Path + "," + this.Id.ToString()) { this.Level = newParent.Level + 1; this.Path = newParent.Path + "," + this.Id.ToString(); } //this code block should not be here but since the class structure is very poor and doesn't use //overrides (instead using shadows/new) for the Children property, when iterating over the children //and calling Move(), the super classes overridden OnMove or Move methods never get fired, so //we now need to hard code this here :( if (Path.Contains("," + ((int)RecycleBin.RecycleBinType.Content).ToString() + ",") || Path.Contains("," + ((int)RecycleBin.RecycleBinType.Media).ToString() + ",")) { //if we've moved this to the recyle bin, we need to update the trashed property if (!IsTrashed) { IsTrashed = true; //don't update if it's not necessary } } else { if (IsTrashed) { IsTrashed = false; //don't update if it's not necessary } } //make sure the node type is a document/media, if it is a recycle bin then this will not be equal if (!IsTrashed && newParent.nodeObjectType == Document._objectType) { // regenerate the xml of the current document var movedDocument = new Document(this.Id); movedDocument.XmlGenerate(new XmlDocument()); //regenerate the xml for the newParent node var parentDocument = new Document(newParent.Id); parentDocument.XmlGenerate(new XmlDocument()); } else if (!IsTrashed && newParent.nodeObjectType == Media._objectType) { //regenerate the xml for the newParent node var m = new Media(newParent.Id); m.XmlGenerate(new XmlDocument()); } var children = this.Children; foreach (CMSNode c in children) { c.Move(this); } //TODO: Properly refactor this, we're just clearing the cache so the changes will also be visible in the backoffice InMemoryCacheProvider.Current.Clear(); FireAfterMove(e); } }
private void HandleDocumentMoveOrCopy() { if (Request.GetItemAsString("copyTo") != "" && Request.GetItemAsString("id") != "") { // Check if the current node is allowed at new position var nodeAllowed = false; IContentBase currContent; IContentBase parentContent = null; IContentTypeBase parentContentType = null; if (CurrentApp == "content") { currContent = Services.ContentService.GetById(Request.GetItemAs<int>("id")); if (Request.GetItemAs<int>("copyTo") != -1) { parentContent = Services.ContentService.GetById(Request.GetItemAs<int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetContentType(parentContent.ContentTypeId); } } } else { currContent = Services.MediaService.GetById(Request.GetItemAs<int>("id")); if (Request.GetItemAs<int>("copyTo") != -1) { parentContent = Services.MediaService.GetById(Request.GetItemAs<int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetMediaType(parentContent.ContentTypeId); } } } // Check on contenttypes if (parentContentType == null) { //check if this is allowed at root IContentTypeBase currContentType; if (CurrentApp == "content") { currContentType = Services.ContentTypeService.GetContentType(currContent.ContentTypeId); } else { currContentType = Services.ContentTypeService.GetMediaType(currContent.ContentTypeId); } nodeAllowed = currContentType.AllowedAsRoot; if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedAtRoot", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } else { var allowedChildContentTypeIds = parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray(); if (allowedChildContentTypeIds.Any(x => x.Value == currContent.ContentTypeId)) { nodeAllowed = true; } if (nodeAllowed == false) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if ((string.Format(",{0},", parentContent.Path)).IndexOf(string.Format(",{0},", currContent.Id)) > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; var newNodeCaption = parentContent == null ? ui.Text(CurrentApp) : parentContent.Name; string[] nodes = { currContent.Name, newNodeCaption }; if (Request["mode"] == "cut") { if (CurrentApp == Constants.Applications.Content) { //Backwards comp. change, so old events are fired #U4-2731 var doc = new Document(currContent as IContent); doc.Move(Request.GetItemAs<int>("copyTo")); } else { //Backwards comp. change, so old events are fired #U4-2731 var media = new umbraco.cms.businesslogic.media.Media(currContent as IMedia); media.Move(Request.GetItemAs<int>("copyTo")); library.ClearLibraryCacheForMedia(currContent.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, UmbracoUser) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currContent.Id.ToString(), currContent.Path); } else { //NOTE: We ONLY support Copy on content not media for some reason. //Backwards comp. change, so old events are fired #U4-2731 var newContent = new Document(currContent as IContent); newContent.Copy(Request.GetItemAs<int>("copyTo"), getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.CopyNode(currContent.Id.ToString(), newContent.Path); } } } }
public override Node GetNode(string value) { var media = new umbraco.cms.businesslogic.media.Media(Convert.ToInt32(value)); return GetNode(media); }
public override IEnumerable<Node> GetChildNodes(Node node) { var media = new umbraco.cms.businesslogic.media.Media(Convert.ToInt32(node.Id)); return media.Children.Select(GetNode); }
private void HandleDocumentMoveOrCopy() { if (Request.GetItemAsString("copyTo") != "" && Request.GetItemAsString("id") != "") { // Check if the current node is allowed at new position var nodeAllowed = false; IContentBase currContent; IContentBase parentContent = null; IContentTypeBase parentContentType = null; if (CurrentApp == "content") { currContent = Services.ContentService.GetById(Request.GetItemAs <int>("id")); if (Request.GetItemAs <int>("copyTo") != -1) { parentContent = Services.ContentService.GetById(Request.GetItemAs <int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetContentType(parentContent.ContentTypeId); } } } else { currContent = Services.MediaService.GetById(Request.GetItemAs <int>("id")); if (Request.GetItemAs <int>("copyTo") != -1) { parentContent = Services.MediaService.GetById(Request.GetItemAs <int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetMediaType(parentContent.ContentTypeId); } } } // Check on contenttypes if (parentContentType == null) { //check if this is allowed at root IContentTypeBase currContentType; if (CurrentApp == "content") { currContentType = Services.ContentTypeService.GetContentType(currContent.ContentTypeId); } else { currContentType = Services.ContentTypeService.GetMediaType(currContent.ContentTypeId); } nodeAllowed = currContentType.AllowedAsRoot; if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedAtRoot", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } else { var allowedChildContentTypeIds = parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray(); if (allowedChildContentTypeIds.Any(x => x.Value == currContent.ContentTypeId)) { nodeAllowed = true; } if (nodeAllowed == false) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if ((string.Format(",{0},", parentContent.Path)).IndexOf(string.Format(",{0},", currContent.Id)) > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; var newNodeCaption = parentContent == null ? ui.Text(CurrentApp) : parentContent.Name; string[] nodes = { currContent.Name, newNodeCaption }; if (Request["mode"] == "cut") { if (CurrentApp == Constants.Applications.Content) { //Backwards comp. change, so old events are fired #U4-2731 var doc = new Document(currContent as IContent); doc.Move(Request.GetItemAs <int>("copyTo")); } else { //Backwards comp. change, so old events are fired #U4-2731 var media = new umbraco.cms.businesslogic.media.Media(currContent as IMedia); media.Move(Request.GetItemAs <int>("copyTo")); library.ClearLibraryCacheForMedia(currContent.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, UmbracoUser) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currContent.Id.ToString(), currContent.Path); } else { //NOTE: We ONLY support Copy on content not media for some reason. //Backwards comp. change, so old events are fired #U4-2731 var newContent = new Document(currContent as IContent); newContent.Copy(Request.GetItemAs <int>("copyTo"), getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.CopyNode(currContent.Id.ToString(), newContent.Path); } } } }
public static string GetPropertyAsMediaItem(this IPublishedContent content, string field) { if (string.IsNullOrEmpty(content.GetPropertyValue<string>(field)) == false) { var mItem = new umbraco.cms.businesslogic.media.Media(int.Parse(content.GetPropertyValue<string>(field))); var propertyValue = string.Empty; var property = mItem.getProperty("umbracoFile"); if (property != null) propertyValue = property.Value.ToString(); return propertyValue; } return string.Empty; }