From 33b497e5f4c24fbf8b3f8e01edb8e86c8553acd4 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 20 Dec 2012 13:42:30 -0100 Subject: [PATCH 1/9] Additional fix for U4-1341 - nodes should appear dimmed when unpublished, but they appeared as changed (and not dimmed, therefore looked published) --- src/Umbraco.Web/umbraco.presentation/umbraco/Trees/XmlTree.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/XmlTree.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/XmlTree.cs index ccef7f03bd..314a5363ed 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/XmlTree.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/XmlTree.cs @@ -342,8 +342,8 @@ namespace umbraco.cms.presentation.Trees set { m_notPublished = value; - if (m_notPublished.HasValue && m_notPublished.Value) - this.Style.HighlightNode(); + if (m_notPublished.HasValue && m_notPublished.Value) + this.Style.DimNode(); } } From e6975a71d581c7431fb2ad226a2705dcf060c97c Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 20 Dec 2012 14:05:28 -0100 Subject: [PATCH 2/9] Additional fix for U4-1312 Cant publish child node, because parent not published When you unpublish a node which it's descendants also get unpublished, but as soon as you publish the parent node again, they don't end up in the XML cache any more, leading to this error again. Now putting all previously published documents back into the XML cache when the parent gets published --- .../umbraco.presentation/umbraco/editContent.aspx.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index 6ccd3e0ee3..e1bdb5f673 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -323,6 +323,9 @@ namespace umbraco.cms.presentation UnPublish.Visible = true; _documentHasPublishedVersion = _document.HasPublishedVersion(); + + foreach (var descendant in _document.GetDescendants().Cast().Where(descendant => descendant.HasPublishedVersion())) + library.UpdateDocumentCache(descendant.Id); } else { From 6589d5d5d3e3eca0b8148937438ab6ecb568739c Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 21 Dec 2012 15:58:02 +0000 Subject: [PATCH 3/9] MNTP: Fixed an long-time CSS bug. Aligned the header with the right-panel. --- .../MultiNodeTreePicker/MultiNodePickerStyles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/umbraco.editorControls/MultiNodeTreePicker/MultiNodePickerStyles.css b/src/umbraco.editorControls/MultiNodeTreePicker/MultiNodePickerStyles.css index ebb6293a87..3b54b79e9f 100644 --- a/src/umbraco.editorControls/MultiNodeTreePicker/MultiNodePickerStyles.css +++ b/src/umbraco.editorControls/MultiNodeTreePicker/MultiNodePickerStyles.css @@ -176,7 +176,7 @@ } .multiNodePicker .header { - width: 622px; + width: 618px; } .uc-treenode-noclick > a > div From dc111768e326c40a17e3df0ea8359ebffdfbf5a4 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sun, 23 Dec 2012 11:46:04 -0100 Subject: [PATCH 4/9] Slight MediaFactory refactors, mostly to fix issue U4-1344 where files wouldn't upload if the "magic" umbraco props don't exist (witdth, height, bytes) --- .../umbraco/webservices/MediaUploader.ashx.cs | 44 ++++++++----------- .../media/UmbracoImageMediaFactory.cs | 40 ++++++++++------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/MediaUploader.ashx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/MediaUploader.ashx.cs index 51ac1743b2..ba0b19e998 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/MediaUploader.ashx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/MediaUploader.ashx.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Configuration; -using System.IO; using System.Linq; -using System.Text; using System.Web; using System.Web.Configuration; using System.Web.Script.Serialization; @@ -11,6 +9,7 @@ using System.Web.Security; using System.Web.UI; using System.Xml; using System.Xml.Serialization; +using Umbraco.Core.Logging; using umbraco.BasePages; using umbraco.BusinessLogic; using umbraco.businesslogic.Exceptions; @@ -137,19 +136,15 @@ namespace umbraco.presentation.umbraco.webservices { var pathParts = context.Request["path"].Trim('/').Split('/'); - foreach (var pathPart in pathParts) - { - if (!string.IsNullOrEmpty(pathPart)) - { + foreach (var pathPart in pathParts.Where(part => string.IsNullOrWhiteSpace(part) == false)) parentNode = GetOrCreateFolder(parentNode, pathPart); - } - } + parentNodeId = parentNode.Id; } // Check whether to replace existing - var parsed = false; - bool replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed)); + bool parsed; + var replaceExisting = (context.Request["replaceExisting"] == "1" || (bool.TryParse(context.Request["replaceExisting"], out parsed) && parsed)); // loop through uploaded files for (var j = 0; j < context.Request.Files.Count; j++) @@ -190,22 +185,20 @@ namespace umbraco.presentation.umbraco.webservices scripts.SyncTree(parentNode.Path, true); // log succes - Log.Add(LogTypes.New, parentNodeId, "Succes"); + LogHelper.Info(string.Format("Successful upload to parent ID: {0}", parentNodeId)); } catch (Exception e) { // log error - Log.Add(LogTypes.Error, parentNodeId, e.ToString()); + LogHelper.Error(string.Format("Error uploading to parent ID {0}", parentNodeId), e); } } else { // log error - Log.Add(LogTypes.Error, -1, "Parent node id is in incorrect format"); + LogHelper.Warn(string.Format("Parent node id is in incorrect format: {0}", parentNodeId)); } - - return new UploadResponse(); } @@ -217,16 +210,16 @@ namespace umbraco.presentation.umbraco.webservices if (GlobalSettings.UseSSL && !context.Request.IsSecureConnection) throw new UserAuthorizationException("This installation requires a secure connection (via SSL). Please update the URL to include https://"); - string username = context.Request["username"]; - string password = context.Request["password"]; - string ticket = context.Request["ticket"]; + var username = context.Request["username"]; + var password = context.Request["password"]; + var ticket = context.Request["ticket"]; - bool isValid = false; + var isValid = false; if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { var mp = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider]; - if (mp.ValidateUser(username, password)) + if (mp != null && mp.ValidateUser(username, password)) { var user = new User(username); isValid = user.Applications.Any(app => app.alias == "media"); @@ -239,6 +232,8 @@ namespace umbraco.presentation.umbraco.webservices { var t = FormsAuthentication.Decrypt(ticket); var user = new User(username); + + if (t != null) isValid = user.LoginName.ToLower() == t.Name.ToLower() && user.Applications.Any(app => app.alias == "media"); if (isValid) @@ -278,14 +273,13 @@ namespace umbraco.presentation.umbraco.webservices if (appSetting > 0) return appSetting; - var configXml = new XmlDocument(); - configXml.PreserveWhitespace = true; + var configXml = new XmlDocument { PreserveWhitespace = true }; configXml.Load(HttpContext.Current.Server.MapPath("/web.config")); var requestLimitsNode = configXml.SelectSingleNode("//configuration/system.webServer/security/requestFiltering/requestLimits"); if (requestLimitsNode != null) { - if (requestLimitsNode.Attributes["maxAllowedContentLength"] != null) + if (requestLimitsNode.Attributes != null && requestLimitsNode.Attributes["maxAllowedContentLength"] != null) { var maxAllowedContentLength = Convert.ToInt32(requestLimitsNode.Attributes["maxAllowedContentLength"].Value); if (maxAllowedContentLength > 0) @@ -294,10 +288,8 @@ namespace umbraco.presentation.umbraco.webservices } var httpRuntime = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection; - if (httpRuntime != null) - return httpRuntime.MaxRequestLength; - return 4096; + return httpRuntime == null ? 4096 : httpRuntime.MaxRequestLength; } private Media GetOrCreateFolder(Media parent, string name) diff --git a/src/umbraco.cms/businesslogic/media/UmbracoImageMediaFactory.cs b/src/umbraco.cms/businesslogic/media/UmbracoImageMediaFactory.cs index 4c5c25d6ff..152de97676 100644 --- a/src/umbraco.cms/businesslogic/media/UmbracoImageMediaFactory.cs +++ b/src/umbraco.cms/businesslogic/media/UmbracoImageMediaFactory.cs @@ -5,12 +5,10 @@ using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; using System.Linq; -using System.Web; +using Umbraco.Core.Logging; using umbraco.BasePages; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.datatype; -using Encoder = System.Text.Encoder; -using Umbraco.Core.IO; namespace umbraco.cms.businesslogic.media { @@ -26,10 +24,10 @@ namespace umbraco.cms.businesslogic.media get { return new List { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }; } } - public override void DoHandleMedia(Media media, PostedMediaFile postedFile, BusinessLogic.User user) + public override void DoHandleMedia(Media media, PostedMediaFile postedFile, User user) { // Get Image object, width and height - var image = System.Drawing.Image.FromStream(postedFile.InputStream); + var image = Image.FromStream(postedFile.InputStream); var fileWidth = image.Width; var fileHeight = image.Height; @@ -42,9 +40,15 @@ namespace umbraco.cms.businesslogic.media // Set media properties media.getProperty("umbracoFile").Value = FileSystem.GetUrl(destFilePath); - media.getProperty("umbracoWidth").Value = fileWidth; - media.getProperty("umbracoHeight").Value = fileHeight; - media.getProperty("umbracoBytes").Value = postedFile.ContentLength; + + if (media.getProperty("umbracoWidth") != null) + media.getProperty("umbracoWidth").Value = fileWidth; + + if (media.getProperty("umbracoHeight") != null) + media.getProperty("umbracoHeight").Value = fileHeight; + + if (media.getProperty("umbracoBytes") != null) + media.getProperty("umbracoBytes").Value = postedFile.ContentLength; if (media.getProperty("umbracoExtension") != null) media.getProperty("umbracoExtension").Value = ext; @@ -78,7 +82,10 @@ namespace umbraco.cms.businesslogic.media // Get DataTypeDefinition of upload field dataTypeDef = DataTypeDefinition.GetByDataTypeId(uploadFieldDataTypeId); } - catch { } + catch (Exception e) + { + LogHelper.Error("Could get Upload Field datatype definition", e); + } if (dataTypeDef != null) { @@ -94,8 +101,7 @@ namespace umbraco.cms.businesslogic.media var thumbnailSizes = thumbnails.Split(";".ToCharArray()); foreach (var thumb in thumbnailSizes.Where(thumb => thumb != "")) { - GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, ext, - destFilePath + "_" + thumb + ".jpg"); + GenerateThumbnail(image, int.Parse(thumb), fileWidth, fileHeight, ext, destFilePath + "_" + thumb + ".jpg"); } } } @@ -115,6 +121,7 @@ namespace umbraco.cms.businesslogic.media // fixes for empty width or height if (widthTh == 0) widthTh = 1; + if (heightTh == 0) heightTh = 1; @@ -131,15 +138,14 @@ namespace umbraco.cms.businesslogic.media // Copy metadata var codecs = ImageCodecInfo.GetImageEncoders(); - ImageCodecInfo codec = null; - if (ext.ToLower() == "png" || ext.ToLower() == "gif") - codec = codecs.Single(t => t.MimeType.Equals("image/png")); - else - codec = codecs.Single(t => t.MimeType.Equals("image/jpeg")); + + var codec = ext.ToLower() == "png" || ext.ToLower() == "gif" + ? codecs.Single(t => t.MimeType.Equals("image/png")) + : codecs.Single(t => t.MimeType.Equals("image/jpeg")); // Set compresion ratio to 90% var ep = new EncoderParameters(); - ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); + ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L); // Save the new image if (codec != null) From 37b1fcbaf039f01ae6c9657671396665f93a626e Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 26 Dec 2012 05:49:03 -0100 Subject: [PATCH 5/9] Fix image uploader in RTE, when used in VDir it returns the right path now no need for relative path hacks --- .../umbraco/controls/Images/UploadMediaImage.ascx.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs index 1bbc5d0ea8..7fc5c398cc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs @@ -98,7 +98,7 @@ namespace umbraco.controls.Images feedback.type = uicontrols.Feedback.feedbacktype.success; if (mainImage.StartsWith("~")) mainImage = mainImage.Substring(1); if (thumbnail.StartsWith("~")) thumbnail = thumbnail.Substring(1); - feedback.Text += "


"; + feedback.Text += "
"; if (!string.IsNullOrEmpty(OnClientUpload)) From 6c8c37256b57af9290712331678039f136b80cf1 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 26 Dec 2012 05:50:48 -0100 Subject: [PATCH 6/9] Cleanup media uploader in RTE a little --- .../controls/Images/UploadMediaImage.ascx.cs | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs index 7fc5c398cc..87ee1b4ae6 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/Images/UploadMediaImage.ascx.cs @@ -1,19 +1,12 @@ using System; -using System.Collections; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Web; -using System.Web.SessionState; using System.Web.UI; -using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Linq; using System.Xml; using umbraco.BasePages; -using umbraco.uicontrols; +using umbraco.cms.businesslogic.datatype; using umbraco.interfaces; -using umbraco.cms.businesslogic.media; +using Media = umbraco.cms.businesslogic.media.Media; namespace umbraco.controls.Images { @@ -23,7 +16,7 @@ namespace umbraco.controls.Images /// Includes ability to select where in the media you would like it to upload and also supports client /// callback methods once complete. /// - public partial class UploadMediaImage : System.Web.UI.UserControl + public partial class UploadMediaImage : UserControl { public UploadMediaImage() @@ -42,7 +35,7 @@ namespace umbraco.controls.Images /// public string OnClientUpload { get; set; } - protected IDataType UploadField = new cms.businesslogic.datatype.controls.Factory().GetNewObject(new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); + protected IDataType UploadField = DataTypeDefinition.GetByDataTypeId(new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")).DataType; protected override void OnInit(EventArgs e) { @@ -66,33 +59,29 @@ namespace umbraco.controls.Images protected void SubmitButton_Click(object sender, EventArgs e) { - int parent = int.Parse(MediaPickerControl.Value); - if (BusinessLogic.User.GetCurrent().StartMediaId != -1 && parent == -1) - parent = BusinessLogic.User.GetCurrent().StartNodeId; + var media = Media.MakeNew(TextBoxTitle.Text, cms.businesslogic.media.MediaType.GetByAlias("image"), BasePage.Current.getUser(), int.Parse(MediaPickerControl.Value)); - Media m = Media.MakeNew(TextBoxTitle.Text, cms.businesslogic.media.MediaType.GetByAlias("image"), BasePage.Current.getUser(), int.Parse(MediaPickerControl.Value)); - var props = m.getProperties; - foreach (cms.businesslogic.property.Property p in props) + foreach (var property in media.GenericProperties) { - if (p.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id) + if (property.PropertyType.DataTypeDefinition.DataType.Id == UploadField.Id) { - UploadField.DataTypeDefinitionId = p.PropertyType.DataTypeDefinition.Id; - UploadField.Data.PropertyId = p.Id; + UploadField.DataTypeDefinitionId = property.PropertyType.DataTypeDefinition.Id; + UploadField.Data.PropertyId = property.Id; } } UploadField.DataEditor.Save(); // Generate xml on image - m.XmlGenerate(new XmlDocument()); + 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 = m.getProperty("umbracoFile").Value.ToString(); + string mainImage = media.getProperty("umbracoFile").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 = m.getProperty("umbracoWidth").Value.ToString(); - string height = m.getProperty("umbracoHeight").Value.ToString(); - int id = m.Id; + string width = media.getProperty("umbracoWidth").Value.ToString(); + string height = media.getProperty("umbracoHeight").Value.ToString(); + int id = media.Id; feedback.Style.Add("margin-top", "8px"); feedback.type = uicontrols.Feedback.feedbacktype.success; @@ -106,7 +95,7 @@ namespace umbraco.controls.Images feedback.Text += @" "; } From 3bd487d09258b061c89b9fcfc8ac16d73ac0915a Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 26 Dec 2012 05:54:34 -0100 Subject: [PATCH 7/9] Fixed #U4-1323 Stripping umbraco path out of source is not needed any more --- .../tinymce/tinyMCEImageHelper.cs | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs b/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs index aaf9579e8d..bb578f43f4 100644 --- a/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs +++ b/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs @@ -72,8 +72,6 @@ namespace umbraco.editorControls.tinymce } else { - cleanTag = StripSrc(cleanTag, ht); - if (helper.FindAttribute(ht, "width") != "") { cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\""; @@ -84,10 +82,6 @@ namespace umbraco.editorControls.tinymce } else { - // Add src, width and height properties - cleanTag = StripSrc(cleanTag, ht); - - if (helper.FindAttribute(ht, "width") != "") { cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\""; @@ -118,22 +112,6 @@ namespace umbraco.editorControls.tinymce return html; } - private static string StripSrc(string cleanTag, Hashtable ht) - { - string src = helper.FindAttribute(ht, "src"); - //get the media folder, minus the starting '~' - string mediaRoot = global::Umbraco.Core.IO.SystemDirectories.Media.Replace("~", string.Empty); - - // update orgSrc to remove umbraco reference - int mediaRootIndex = src.IndexOf(mediaRoot); - if (mediaRootIndex > -1) - - src = src.Substring(mediaRootIndex, src.Length - mediaRootIndex); - - cleanTag += " src=\"" + src + "\""; - return cleanTag; - } - private static string doResize(Hashtable attributes, out int finalWidth, out int finalHeight) { var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); From 48d620cdb0a85b7012ae00b4d155bdf8ee067338 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 26 Dec 2012 06:27:30 -0100 Subject: [PATCH 8/9] Cleanup RTE ImageHelper a little bit, still bad code but more readable now --- .../tinymce/tinyMCEImageHelper.cs | 138 +++++------------- 1 file changed, 33 insertions(+), 105 deletions(-) diff --git a/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs b/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs index bb578f43f4..66a3994ad4 100644 --- a/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs +++ b/src/umbraco.editorControls/tinymce/tinyMCEImageHelper.cs @@ -1,14 +1,10 @@ using System; using System.Collections; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; using System.Text.RegularExpressions; using System.Web; using Umbraco.Core.IO; -using umbraco.BusinessLogic; +using Umbraco.Core.Logging; using umbraco.cms.businesslogic.Files; -using umbraco.IO; namespace umbraco.editorControls.tinymce { @@ -16,47 +12,36 @@ namespace umbraco.editorControls.tinymce { public static string cleanImages(string html) { - string[] allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(','); - string pattern = @"]*>"; - MatchCollection tags = - Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); + var allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(','); + const string pattern = @"]*>"; + var tags = Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); foreach (Match tag in tags) { - if (tag.Value.ToLower().IndexOf("umbraco_macro") == -1) + if (tag.Value.ToLower().IndexOf("umbraco_macro", StringComparison.Ordinal) == -1) { - string cleanTag = "", " >"), - "(?\\S*)=\"(?[^\"]*)\"|(?\\S*)=(?[^\"|\\s]*)\\s", - RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); - foreach (Match attributeSet in m) + var ht = new Hashtable(); + var matches = Regex.Matches(tag.Value.Replace(">", " >"), "(?\\S*)=\"(?[^\"]*)\"|(?\\S*)=(?[^\"|\\s]*)\\s", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); + foreach (Match attributeSet in matches) { - ht.Add(attributeSet.Groups["attributeName"].Value.ToString().ToLower(), - attributeSet.Groups["attributeValue"].Value.ToString()); - if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "width") - int.TryParse(attributeSet.Groups["attributeValue"].Value.ToString(), out orgWidth); - else if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "height") - int.TryParse(attributeSet.Groups["attributeValue"].Value.ToString(), out orgHeight); + ht.Add(attributeSet.Groups["attributeName"].Value.ToLower(), + attributeSet.Groups["attributeValue"].Value); } // If rel attribute exists and if it's different from current sizing we should resize the image! if (helper.FindAttribute(ht, "rel") != "") { - int newWidth = 0, newHeight = 0; - // if size has changed resize image serverside - string[] newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray()); - if (newDims.Length > 0 && - (newDims[0] != helper.FindAttribute(ht, "width") || - newDims[1] != helper.FindAttribute(ht, "height"))) + var newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray()); + if (newDims.Length > 0 && (newDims[0] != helper.FindAttribute(ht, "width") || newDims[1] != helper.FindAttribute(ht, "height"))) { try { - cleanTag += doResize(ht, out newWidth, out newHeight); + int newWidth; + int newHeight; + cleanTag += DoResize(ht, out newWidth, out newHeight); } catch (Exception err) { @@ -66,8 +51,8 @@ namespace umbraco.editorControls.tinymce cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\""; cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\""; } - Log.Add(LogTypes.Error, User.GetUser(0), -1, - "Error resizing image in editor: " + err.ToString()); + + LogHelper.Error("Error resizing image in editor", err); } } else @@ -87,23 +72,21 @@ namespace umbraco.editorControls.tinymce cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\""; cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\""; } - } - // Build image tag - foreach (string attr in allowedAttributes) + foreach (var attr in allowedAttributes) { if (helper.FindAttribute(ht, attr) != "") { - string attrValue = helper.FindAttribute(ht, attr); + var attrValue = helper.FindAttribute(ht, attr); cleanTag += " " + attr + "=\"" + attrValue + "\""; } } - if (bool.Parse(GlobalSettings.EditXhtmlMode)) cleanTag += "/"; + cleanTag += ">"; html = html.Replace(tag.Value, cleanTag); } @@ -112,97 +95,42 @@ namespace umbraco.editorControls.tinymce return html; } - private static string doResize(Hashtable attributes, out int finalWidth, out int finalHeight) + private static string DoResize(IDictionary attributes, out int finalWidth, out int finalHeight) { var fs = FileSystemProviderManager.Current.GetFileSystemProvider(); + var orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " ")); + var orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray()); + var orgWidth = float.Parse(orgDim[0]); + var orgHeight = float.Parse(orgDim[1]); + var newWidth = int.Parse(helper.FindAttribute(attributes, "width")); + var newHeight = int.Parse(helper.FindAttribute(attributes, "height")); - string resizeDim = helper.FindAttribute(attributes, "width") + "," + - helper.FindAttribute(attributes, "height"); - string[] resizeDimSplit = resizeDim.Split(','); - string orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " ")); - string[] orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray()); - float orgWidth = float.Parse(orgDim[0]); - float orgHeight = float.Parse(orgDim[1]); - string newSrc = ""; - int newWidth = int.Parse(resizeDimSplit[0]); - int newHeight = int.Parse(resizeDimSplit[1]); + var newSrc = ""; - if (orgHeight > 0 && orgWidth > 0 && resizeDim != "" && orgSrc != "") + if (orgHeight > 0 && orgWidth > 0 && orgSrc != "") { // Check dimensions if (Math.Abs(orgWidth / newWidth) > Math.Abs(orgHeight / newHeight)) { - newHeight = (int)Math.Round((float)newWidth * (orgHeight / orgWidth)); + newHeight = (int)Math.Round(newWidth * (orgHeight / orgWidth)); } else { - newWidth = (int)Math.Round((float)newHeight * (orgWidth / orgHeight)); + newWidth = (int)Math.Round(newHeight * (orgWidth / orgHeight)); } - // update orgSrc to remove umbraco reference - //string resolvedMedia = IOHelper.ResolveUrl(SystemDirectories.Media); - //if (IOHelper.ResolveUrl(orgSrc).IndexOf(resolvedMedia) > -1) - //{ - // orgSrc = SystemDirectories.Media + orgSrc.Substring(orgSrc.IndexOf(resolvedMedia) + resolvedMedia.Length); //, orgSrc.Length - orgSrc.IndexOf(String.Format("/media/", SystemDirectories.Media))); - - //} - - //string fullSrc = IOHelper.MapPath(orgSrc); - var orgPath = fs.GetRelativePath(orgSrc); if (fs.FileExists(orgPath)) { var uf = new UmbracoFile(orgPath); newSrc = uf.Resize(newWidth, newHeight); } - - /* - // Load original image - Image image = Image.FromFile(fullSrc); - - - // Create new image with best quality settings - Bitmap bp = new Bitmap(newWidth, newHeight); - Graphics g = Graphics.FromImage(bp); - g.SmoothingMode = SmoothingMode.HighQuality; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.PixelOffsetMode = PixelOffsetMode.HighQuality; - - // Copy the old image to the new and resized - Rectangle rect = new Rectangle(0, 0, newWidth, newHeight); - g.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); - - // Copy metadata - ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); - ImageCodecInfo codec = null; - for (int i = 0; i < codecs.Length; i++) - { - if (codecs[i].MimeType.Equals("image/jpeg")) - codec = codecs[i]; } - // Set compresion ratio to 90% - EncoderParameters ep = new EncoderParameters(); - ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L); - - // Save the new image - bp.Save(fullSrcNew, codec, ep); - * */ - } - - // return the new width and height finalWidth = newWidth; finalHeight = newHeight; - //GE: When the SystemDirectories.Media contains a ~, newSrc will also contain this and hasn't been resolved. - //This causes the editor to save content which contains a virtual url, and thus the image doesn't serve - //the admin editor successfully displays the image because the HTML is rewritten, but when you get the RTE content in the template - //it hasn't been replaced - //2011-08-12 added a IOHelper.ResolveUrl call around newSrc - //2012-08-20 IFileSystem now takes care of URL resolution, so should be safe to assume newSrc is a full/absolute URL - return - " src=\"" + newSrc + "\" width=\"" + newWidth.ToString() + "\" height=\"" + newHeight.ToString() + - "\""; + return " src=\"" + newSrc + "\" width=\"" + newWidth + "\" height=\"" + newHeight + "\""; } } } \ No newline at end of file From 30cf0e2040d942e7d2dc80c93b41164304aac50a Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 26 Dec 2012 06:49:54 -0100 Subject: [PATCH 9/9] Add some logging to PhysicalFileSystem --- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 36 +++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index a53b5b1784..0e2f97bd7f 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -1,14 +1,14 @@ using System; using System.Collections.Generic; -using System.IO; +using System.Globalization; +using System.IO; using System.Linq; -using System.Text; using System.Web; using Umbraco.Core.CodeAnnotations; +using Umbraco.Core.Logging; namespace Umbraco.Core.IO { - [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] internal class PhysicalFileSystem : IFileSystem { @@ -43,9 +43,13 @@ namespace Umbraco.Core.IO return Directory.EnumerateDirectories(path).Select(GetRelativePath); } catch (UnauthorizedAccessException ex) - { } + { + LogHelper.Error("Not authorized to get directories", ex); + } catch (DirectoryNotFoundException ex) - { } + { + LogHelper.Error("Directory not found", ex); + } return Enumerable.Empty(); } @@ -65,7 +69,9 @@ namespace Umbraco.Core.IO Directory.Delete(GetFullPath(path), recursive); } catch (DirectoryNotFoundException ex) - { } + { + LogHelper.Error("Directory not found", ex); + } } public bool DirectoryExists(string path) @@ -80,9 +86,7 @@ namespace Umbraco.Core.IO public void AddFile(string path, Stream stream, bool overrideIfExists) { - if (FileExists(path) && !overrideIfExists) - throw new InvalidOperationException(string.Format("A file at path '{0}' already exists", - path)); + if (FileExists(path) && !overrideIfExists) throw new InvalidOperationException(string.Format("A file at path '{0}' already exists", path)); EnsureDirectory(Path.GetDirectoryName(path)); @@ -108,9 +112,13 @@ namespace Umbraco.Core.IO return Directory.EnumerateFiles(path, filter).Select(GetRelativePath); } catch (UnauthorizedAccessException ex) - { } + { + LogHelper.Error("Not authorized to get directories", ex); + } catch (DirectoryNotFoundException ex) - { } + { + LogHelper.Error("Directory not found", ex); + } return Enumerable.Empty(); } @@ -130,7 +138,9 @@ namespace Umbraco.Core.IO File.Delete(GetFullPath(path)); } catch (FileNotFoundException ex) - { } + { + LogHelper.Error("File not found", ex); + } } public bool FileExists(string path) @@ -188,7 +198,7 @@ namespace Umbraco.Core.IO protected string EnsureTrailingSeparator(string path) { - if (!path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) + if (!path.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)) path = path + Path.DirectorySeparatorChar; return path;