protected override void Render(HtmlTextWriter writer) { uploadfield.DataTypeUploadField uft = new uploadfield.DataTypeUploadField(); cms.businesslogic.Content c = cms.businesslogic.media.Media.GetContentFromVersion(_data.Version); //store children array here because iterating over an Array property object is very inneficient. var children = c.Children; foreach (BusinessLogic.console.IconI cc in children) { cms.businesslogic.media.Media m = new cms.businesslogic.media.Media(cc.UniqueId); var props = m.getProperties; foreach (cms.businesslogic.property.Property p in props) { if (p.PropertyType.DataTypeDefinition.DataType.Id == uft.Id && p.Value.ToString() != "") { // Check for thumbnail! string fileNameOrg = p.Value.ToString(); string ext = fileNameOrg.Substring(fileNameOrg.LastIndexOf(".") + 1, fileNameOrg.Length - fileNameOrg.LastIndexOf(".") - 1); string fileNameThumb = fileNameOrg.Replace("." + ext, "_thumb.jpg"); if (File.Exists(IOHelper.MapPath(IOHelper.FindFile(fileNameThumb)))) { writer.WriteLine("<a href=\"?id=" + m.Id.ToString() + "\"><img src=\"" + IOHelper.ResolveUrl(fileNameThumb) + "\" alt=\"" + m.Text + "\" style=\"border: none\"/></a> "); } } } } base.Render(writer); }
private void HandleDocumentMoveOrCopy() { if (helper.Request("copyTo") != "" && helper.Request("id") != "") { // Check if the current node is allowed at new position bool nodeAllowed = false; cms.businesslogic.Content currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id"))); int oldParent = -1; if (currentNode.Level > 1) { oldParent = currentNode.Parent.Id; } cms.businesslogic.Content newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo"))); // Check on contenttypes if (int.Parse(helper.Request("copyTo")) == -1) { nodeAllowed = true; } else { foreach (int i in newNode.ContentType.AllowedChildContentTypeIDs.ToList()) { if (i == currentNode.ContentType.Id) { nodeAllowed = true; break; } } if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if (((string)("," + newNode.Path + ",")).IndexOf("," + currentNode.Id + ",") > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; string newNodeCaption = newNode.Id == -1 ? ui.Text(helper.Request("app")) : newNode.Text; string[] nodes = { currentNode.Text, newNodeCaption }; if (UmbracoContext.Current.Request["mode"] == "cut") { if (UmbracoContext.Current.Request["app"] == "content") { //PPH changed this to document instead of cmsNode to handle republishing. cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Move(int.Parse(helper.Request("copyTo"))); if (d.Published) { d.Publish(new umbraco.BusinessLogic.User(0)); //using library.publish to support load balancing. //umbraco.library.PublishSingleNode(d.Id); umbraco.library.UpdateDocumentCache(d.Id); //PPH added handling of load balanced moving of multiple nodes... if (d.HasChildren) { handleChildNodes(d); } //Using the general Refresh content method instead as it supports load balancing. //we only need to do this if the node is actually published. library.RefreshContent(); } d.Save(); //stub to save stuff to the db. } else { Media m = new Media(int.Parse(UmbracoContext.Current.Request["id"])); m.Move(int.Parse(UmbracoContext.Current.Request["copyTo"])); m.XmlGenerate(new XmlDocument()); library.ClearLibraryCacheForMedia(m.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path); } else { cms.businesslogic.web.Document d = new cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); } } } }
public void Save() { // Clear data if (helper.Request(this.ClientID + "clear") == "1") { // delete file deleteFile(_text); // set filename in db to nothing _text = ""; _data.Value = _text; //also clear umbracoWidth, umbracoHeight, umbracoExtension, umbracoBytes cms.businesslogic.Content content = cms.businesslogic.Content.GetContentFromVersion(this._data.Version); foreach (string prop in "umbracoExtension,umbracoBytes,umbracoWidth,umbracoHeight".Split(',')) { try { content.getProperty(prop).Value = string.Empty; noEdit bytesControl = uploadField.FindControlRecursive <noEdit>(this.Page, "prop_" + prop); if (bytesControl != null) { bytesControl.RefreshLabel(string.Empty); } } catch { //if first one fails we can assume that props don't exist break; } } } if (this.PostedFile != null) { if (this.PostedFile.FileName != "") { //if (_text.Length > 0 && helper.Request(this.ClientID + "clear") != "1") //{ // //delete old file // deleteFile(_text); //} // Find filename (removed the safe url here as it removes fullpath characters (such as c:\ becomes c:) - the safe url should only be used when saving the // local filename _text = this.PostedFile.FileName; string filename; string _fullFilePath; cms.businesslogic.Content content = cms.businesslogic.Content.GetContentFromVersion(this._data.Version); if (umbraco.UmbracoSettings.UploadAllowDirectories) { // moved the safeUrl call to here as it's the local file name to be stored filename = SafeUrl(_text.Substring(_text.LastIndexOf(IOHelper.DirSepChar) + 1, _text.Length - _text.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); // Create a new folder in the /media folder with the name /media/propertyid System.IO.Directory.CreateDirectory(IOHelper.MapPath(SystemDirectories.Media + "/" + _data.PropertyId.ToString())); _fullFilePath = IOHelper.MapPath(SystemDirectories.Media + "/" + _data.PropertyId.ToString() + "/" + filename); this.PostedFile.SaveAs(_fullFilePath); //if we are not in a virtual dir, just save without the ~ string _relFilePath = SystemDirectories.Media + "/" + _data.PropertyId + "/" + filename; if (SystemDirectories.Root == string.Empty) { _relFilePath = _relFilePath.TrimStart('~'); } _data.Value = _relFilePath; } else { //filename = this. filename = System.IO.Path.GetFileName(SafeUrl(this.PostedFile.FileName)); filename = _data.PropertyId + "-" + filename; _fullFilePath = IOHelper.MapPath(SystemDirectories.Media + "/" + filename); this.PostedFile.SaveAs(_fullFilePath); //if we are not in a virtual dir, just save without the ~ string _relFilePath = SystemDirectories.Media + "/" + filename; if (SystemDirectories.Root == string.Empty) { _relFilePath = _relFilePath.TrimStart('~'); } _data.Value = _relFilePath; } // hack to find master page prefix client id string masterpagePrefix = this.ClientID.Substring(0, this.ClientID.LastIndexOf("_") + 1); // Save extension string orgExt = ((string)_text.Substring(_text.LastIndexOf(".") + 1, _text.Length - _text.LastIndexOf(".") - 1)); orgExt = orgExt.ToLower(); string ext = orgExt.ToLower(); try { //cms.businesslogic.Content.GetContentFromVersion(_data.Version).getProperty("umbracoExtension").Value = ext; content.getProperty("umbracoExtension").Value = ext; noEdit extensionControl = uploadField.FindControlRecursive <noEdit>(this.Page, "prop_umbracoExtension"); if (extensionControl != null) { extensionControl.RefreshLabel(content.getProperty("umbracoExtension").Value.ToString()); } } catch { } // Save file size try { System.IO.FileInfo fi = new FileInfo(_fullFilePath); //cms.businesslogic.Content.GetContentFromVersion(_data.Version).getProperty("umbracoBytes").Value = fi.Length.ToString(); content.getProperty("umbracoBytes").Value = fi.Length.ToString(); noEdit bytesControl = uploadField.FindControlRecursive <noEdit>(this.Page, "prop_umbracoBytes"); if (bytesControl != null) { bytesControl.RefreshLabel(content.getProperty("umbracoBytes").Value.ToString()); } } catch { } // Check if image and then get sizes, make thumb and update database if (",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + ext + ",") > -1) { int fileWidth; int fileHeight; FileStream fs = new FileStream(_fullFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); System.Drawing.Image image = System.Drawing.Image.FromStream(fs); fileWidth = image.Width; fileHeight = image.Height; fs.Close(); try { //cms.businesslogic.Content.GetContentFromVersion(_data.Version).getProperty("umbracoWidth").Value = fileWidth.ToString(); //cms.businesslogic.Content.GetContentFromVersion(_data.Version).getProperty("umbracoHeight").Value = fileHeight.ToString(); content.getProperty("umbracoWidth").Value = fileWidth.ToString(); noEdit widthControl = uploadField.FindControlRecursive <noEdit>(this.Page, "prop_umbracoWidth"); if (widthControl != null) { widthControl.RefreshLabel(content.getProperty("umbracoWidth").Value.ToString()); } content.getProperty("umbracoHeight").Value = fileHeight.ToString(); noEdit heightControl = uploadField.FindControlRecursive <noEdit>(this.Page, "prop_umbracoHeight"); if (heightControl != null) { heightControl.RefreshLabel(content.getProperty("umbracoHeight").Value.ToString()); } } catch { } // Generate thumbnails string fileNameThumb = _fullFilePath.Replace("." + orgExt, "_thumb"); generateThumbnail(image, 100, fileWidth, fileHeight, _fullFilePath, ext, fileNameThumb + _thumbnailext); if (_thumbnails != "") { char sep = ';'; if (!_thumbnails.Contains(sep.ToString()) && _thumbnails.Contains(",")) { sep = ','; } string[] thumbnailSizes = _thumbnails.Split(sep); foreach (string thumb in thumbnailSizes) { int _thum = 0; if (thumb != "" && int.TryParse(thumb, out _thum)) { generateThumbnail(image, _thum, fileWidth, fileHeight, _fullFilePath, ext, fileNameThumb + "_" + thumb + _thumbnailext); } } } image.Dispose(); } } this.Text = _data.Value.ToString(); } }
private void HandleDocumentMoveOrCopy() { if (helper.Request("copyTo") != "" && helper.Request("id") != "") { // Check if the current node is allowed at new position var nodeAllowed = false; var currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id"))); var newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo"))); // Check on contenttypes if (int.Parse(helper.Request("copyTo")) == -1) { nodeAllowed = true; } else { if (newNode.ContentType.AllowedChildContentTypeIDs.Where(c => c == currentNode.ContentType.Id).Any()) { nodeAllowed = true; } if (nodeAllowed == false) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if ((string.Format(",{0},", newNode.Path)).IndexOf(string.Format(",{0},", currentNode.Id)) > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; var newNodeCaption = newNode.Id == -1 ? ui.Text(CurrentApp) : newNode.Text; string[] nodes = { currentNode.Text, newNodeCaption }; if (Request["mode"] == "cut") { if (CurrentApp == "content") { //PPH changed this to document instead of cmsNode to handle republishing. var documentId = int.Parse(helper.Request("id")); var document = new Document(documentId); document.Move(int.Parse(helper.Request("copyTo"))); library.RefreshContent(); } else { var media = new Media(int.Parse(UmbracoContext.Current.Request["id"])); media.Move(int.Parse(UmbracoContext.Current.Request["copyTo"])); media = new Media(int.Parse(UmbracoContext.Current.Request["id"])); media.XmlGenerate(new XmlDocument()); library.ClearLibraryCacheForMedia(media.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path); } else { var document = new Document(int.Parse(helper.Request("id"))); document.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); } } } }
private void HandleDocumentMoveOrCopy() { if (helper.Request("copyTo") != "" && helper.Request("id") != "") { // Check if the current node is allowed at new position bool nodeAllowed = false; cms.businesslogic.Content currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id"))); int oldParent = -1; if (currentNode.Level > 1) oldParent = currentNode.Parent.Id; cms.businesslogic.Content newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo"))); // Check on contenttypes if (int.Parse(helper.Request("copyTo")) == -1) nodeAllowed = true; else { foreach (int i in newNode.ContentType.AllowedChildContentTypeIDs.ToList()) if (i == currentNode.ContentType.Id) { nodeAllowed = true; break; } if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if (((string)("," + newNode.Path + ",")).IndexOf("," + currentNode.Id + ",") > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; string newNodeCaption = newNode.Id == -1 ? ui.Text(helper.Request("app")) : newNode.Text; string[] nodes = {currentNode.Text, newNodeCaption }; if (UmbracoContext.Current.Request["mode"] == "cut") { if (UmbracoContext.Current.Request["app"] == "content") { //PPH changed this to document instead of cmsNode to handle republishing. cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Move(int.Parse(helper.Request("copyTo"))); if (d.Published) { d.Publish(new umbraco.BusinessLogic.User(0)); //using library.publish to support load balancing. //umbraco.library.PublishSingleNode(d.Id); umbraco.library.UpdateDocumentCache(d.Id); //PPH added handling of load balanced moving of multiple nodes... if (d.HasChildren) { handleChildNodes(d); } //Using the general Refresh content method instead as it supports load balancing. //we only need to do this if the node is actually published. library.RefreshContent(); } d.Save(); //stub to save stuff to the db. } else { Media m = new Media(int.Parse(UmbracoContext.Current.Request["id"])); m.Move(int.Parse(UmbracoContext.Current.Request["copyTo"])); m.XmlGenerate(new XmlDocument()); library.ClearLibraryCacheForMedia(m.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path); } else { cms.businesslogic.web.Document d = new cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); } } } }