diff --git a/src/Umbraco.Core/IO/FileSystemExtensions.cs b/src/Umbraco.Core/IO/FileSystemExtensions.cs index 49128db5b2..1549ff4f65 100644 --- a/src/Umbraco.Core/IO/FileSystemExtensions.cs +++ b/src/Umbraco.Core/IO/FileSystemExtensions.cs @@ -1,11 +1,12 @@ -using Umbraco.Core.CodeAnnotations; +using System.IO; +using Umbraco.Core.CodeAnnotations; namespace Umbraco.Core.IO { [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] public static class FileSystemExtensions { - [UmbracoExperimentalFeature("", "Will be declared public after 4.10")] + [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] internal static long GetSize(this IFileSystem fs, string path) { var s = fs.OpenFile(path); @@ -15,10 +16,16 @@ namespace Umbraco.Core.IO return size; } - [UmbracoExperimentalFeature("", "Will be declared public after 4.10")] + [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] internal static void CopyFile(this IFileSystem fs, string path, string newPath) { fs.AddFile(newPath, fs.OpenFile(path)); } + + [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] + internal static string GetExtension(this IFileSystem fs, string path) + { + return Path.GetExtension(fs.GetFullPath(path)); + } } } diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index 4f3262b560..0682e6d61f 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -13,12 +13,12 @@ namespace Umbraco.Core.IO [UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")] internal class PhysicalFileSystem : IFileSystem { - private readonly string _rootPath; + internal string RootPath { get; private set; } private readonly string _rootUrl; public PhysicalFileSystem(string virtualRoot) { - _rootPath = System.Web.Hosting.HostingEnvironment.MapPath(virtualRoot); + RootPath = System.Web.Hosting.HostingEnvironment.MapPath(virtualRoot); _rootUrl = VirtualPathUtility.ToAbsolute(virtualRoot); } @@ -30,7 +30,7 @@ namespace Umbraco.Core.IO if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentException("The argument 'rootUrl' cannot be null or empty."); - _rootPath = rootPath; + RootPath = rootPath; _rootUrl = rootUrl; } @@ -150,17 +150,12 @@ namespace Umbraco.Core.IO return File.Exists(GetFullPath(path)); } - public string GetExtension(string path) - { - return Path.GetExtension(GetFullPath(path)); - } - public string GetRelativePath(string fullPathOrUrl) { var relativePath = fullPathOrUrl .TrimStart(_rootUrl) .Replace('/', Path.DirectorySeparatorChar) - .TrimStart(_rootPath) + .TrimStart(RootPath) .TrimStart(Path.DirectorySeparatorChar); return relativePath; @@ -168,8 +163,8 @@ namespace Umbraco.Core.IO public string GetFullPath(string path) { - return !path.StartsWith(_rootPath) - ? Path.Combine(_rootPath, path) + return !path.StartsWith(RootPath) + ? Path.Combine(RootPath, path) : path; } diff --git a/src/Umbraco.Web/Strategies/DataTypes/LegacyUploadFieldWorkaround.cs b/src/Umbraco.Web/Strategies/DataTypes/LegacyUploadFieldWorkaround.cs index 10b3d63cb2..f737173795 100644 --- a/src/Umbraco.Web/Strategies/DataTypes/LegacyUploadFieldWorkaround.cs +++ b/src/Umbraco.Web/Strategies/DataTypes/LegacyUploadFieldWorkaround.cs @@ -12,112 +12,108 @@ using umbraco.interfaces; namespace Umbraco.Web.Strategies.DataTypes { - /// - /// Before Save Content/Media subscriber that checks for Upload fields and updates related fields accordingly. - /// - /// - /// This is an intermediate fix for the legacy DataTypeUploadField and the FileHandlerData, so that properties - /// are saved correctly when using the Upload field on a (legacy) Document or Media class. - /// - public class LegacyUploadFieldWorkaround : IApplicationStartupHandler - { - public LegacyUploadFieldWorkaround() - { - global::umbraco.cms.businesslogic.media.Media.BeforeSave += MediaBeforeSave; - global::umbraco.cms.businesslogic.web.Document.BeforeSave += DocumentBeforeSave; - } + ///// + ///// Before Save Content/Media subscriber that checks for Upload fields and updates related fields accordingly. + ///// + ///// + ///// This is an intermediate fix for the legacy DataTypeUploadField and the FileHandlerData, so that properties + ///// are saved correctly when using the Upload field on a (legacy) Document or Media class. + ///// + //public class LegacyUploadFieldWorkaround : IApplicationStartupHandler + //{ + // public LegacyUploadFieldWorkaround() + // { + // global::umbraco.cms.businesslogic.media.Media.BeforeSave += MediaBeforeSave; + // global::umbraco.cms.businesslogic.web.Document.BeforeSave += DocumentBeforeSave; + // } - void DocumentBeforeSave(global::umbraco.cms.businesslogic.web.Document sender, global::umbraco.cms.businesslogic.SaveEventArgs e) - { - if (UmbracoSettings.ImageAutoFillImageProperties != null) - { - var property = sender.GenericProperties.FirstOrDefault(x => x.PropertyType.DataTypeDefinition.DataType.Id == new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); - if (property == null) - return; + // void DocumentBeforeSave(global::umbraco.cms.businesslogic.web.Document sender, global::umbraco.cms.businesslogic.SaveEventArgs e) + // { + // if (UmbracoSettings.ImageAutoFillImageProperties != null) + // { + // var property = sender.GenericProperties.FirstOrDefault(x => x.PropertyType.DataTypeDefinition.DataType.Id == new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); + // if (property == null) + // return; - FillProperties(sender.Content, property); - } - } + // FillProperties(sender.Content, property); + // } + // } - void MediaBeforeSave(global::umbraco.cms.businesslogic.media.Media sender, global::umbraco.cms.businesslogic.SaveEventArgs e) - { - if (UmbracoSettings.ImageAutoFillImageProperties != null) - { - var property = sender.GenericProperties.FirstOrDefault(x => x.PropertyType.DataTypeDefinition.DataType.Id == new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); - if (property == null) - return; + // void MediaBeforeSave(global::umbraco.cms.businesslogic.media.Media sender, global::umbraco.cms.businesslogic.SaveEventArgs e) + // { + // if (UmbracoSettings.ImageAutoFillImageProperties != null) + // { + // var property = sender.GenericProperties.FirstOrDefault(x => x.PropertyType.DataTypeDefinition.DataType.Id == new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); + // if (property == null) + // return; - FillProperties(sender.MediaItem, property); - } - } + // FillProperties(sender.MediaItem, property); + // } + // } - private void FillProperties(IContentBase content, global::umbraco.cms.businesslogic.property.Property property) - { - XmlNode uploadFieldConfigNode = global::umbraco.UmbracoSettings.ImageAutoFillImageProperties.SelectSingleNode(string.Format("uploadField [@alias = \"{0}\"]", property.PropertyType.Alias)); + // private void FillProperties(IContentBase content, global::umbraco.cms.businesslogic.property.Property property) + // { + // XmlNode uploadFieldConfigNode = global::umbraco.UmbracoSettings.ImageAutoFillImageProperties.SelectSingleNode(string.Format("uploadField [@alias = \"{0}\"]", property.PropertyType.Alias)); - if (uploadFieldConfigNode != null) - { - var fileSystem = new PhysicalFileSystem("/"); + // if (uploadFieldConfigNode != null) + // { + // var fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider(); + // var path = fileSystem.GetRelativePath(property.Value.ToString()); - var path = string.IsNullOrEmpty(property.Value.ToString()) - ? string.Empty - : System.Web.Hosting.HostingEnvironment.MapPath(property.Value.ToString()); + // if (string.IsNullOrWhiteSpace(path) == false && fileSystem.FileExists(path)) + // { + // long size; + // using (var fileStream = fileSystem.OpenFile(path)) + // { + // size = fileStream.Length; + // } - if (string.IsNullOrWhiteSpace(path) == false && fileSystem.FileExists(path)) - { - long size; - using (var fileStream = fileSystem.OpenFile(path)) - { - size = fileStream.Length; - } + // var extension = fileSystem.GetExtension(path) != null + // ? fileSystem.GetExtension(path).Substring(1).ToLowerInvariant() + // : ""; - var extension = fileSystem.GetExtension(path) != null - ? fileSystem.GetExtension(path).Substring(1).ToLowerInvariant() - : ""; + // var supportsResizing = ("," + UmbracoSettings.ImageFileTypes + ",").Contains(string.Format(",{0},", extension)); + // var dimensions = supportsResizing ? GetDimensions(path, fileSystem) : null; - var supportsResizing = ("," + UmbracoSettings.ImageFileTypes + ",").Contains(string.Format(",{0},", extension)); - var dimensions = supportsResizing ? GetDimensions(path) : null; + // // only add dimensions to web images + // UpdateProperty(uploadFieldConfigNode, content, "widthFieldAlias", supportsResizing ? dimensions.Item1.ToString(CultureInfo.InvariantCulture) : string.Empty); + // UpdateProperty(uploadFieldConfigNode, content, "heightFieldAlias", supportsResizing ? dimensions.Item2.ToString(CultureInfo.InvariantCulture) : string.Empty); - // only add dimensions to web images - UpdateProperty(uploadFieldConfigNode, content, "widthFieldAlias", supportsResizing ? dimensions.Item1.ToString(CultureInfo.InvariantCulture) : string.Empty); - UpdateProperty(uploadFieldConfigNode, content, "heightFieldAlias", supportsResizing ? dimensions.Item2.ToString(CultureInfo.InvariantCulture) : string.Empty); + // UpdateProperty(uploadFieldConfigNode, content, "lengthFieldAlias", size == default(long) ? string.Empty : size.ToString(CultureInfo.InvariantCulture)); + // UpdateProperty(uploadFieldConfigNode, content, "extensionFieldAlias", string.IsNullOrEmpty(extension) ? string.Empty : extension); + // } + // } + // } - UpdateProperty(uploadFieldConfigNode, content, "lengthFieldAlias", size == default(long) ? string.Empty : size.ToString(CultureInfo.InvariantCulture)); - UpdateProperty(uploadFieldConfigNode, content, "extensionFieldAlias", string.IsNullOrEmpty(extension) ? string.Empty : extension); - } - } - } + // private void UpdateProperty(XmlNode uploadFieldConfigNode, IContentBase content, string propertyAlias, object propertyValue) + // { + // XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias); + // if (propertyNode != null && !String.IsNullOrEmpty(propertyNode.FirstChild.Value)) + // { + // if (content.Properties.Contains(propertyNode.FirstChild.Value) && content.Properties[propertyNode.FirstChild.Value] != null) + // { + // content.SetValue(propertyNode.FirstChild.Value, propertyValue); + // } + // } + // } - private void UpdateProperty(XmlNode uploadFieldConfigNode, IContentBase content, string propertyAlias, object propertyValue) - { - XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias); - if (propertyNode != null && !String.IsNullOrEmpty(propertyNode.FirstChild.Value)) - { - if (content.Properties.Contains(propertyNode.FirstChild.Value) && content.Properties[propertyNode.FirstChild.Value] != null) - { - content.SetValue(propertyNode.FirstChild.Value, propertyValue); - } - } - } - - private Tuple GetDimensions(string path) - { - var fileSystem = new PhysicalFileSystem("/"); + // private Tuple GetDimensions(string path, IFileSystem fs) + // { - int fileWidth; - int fileHeight; - using (var stream = fileSystem.OpenFile(path)) - { - using (var image = Image.FromStream(stream)) - { - fileWidth = image.Width; - fileHeight = image.Height; - } - } + // int fileWidth; + // int fileHeight; + // using (var stream = fs.OpenFile(path)) + // { + // using (var image = Image.FromStream(stream)) + // { + // fileWidth = image.Width; + // fileHeight = image.Height; + // } + // } - return new Tuple(fileWidth, fileHeight); - } - } + // return new Tuple(fileWidth, fileHeight); + // } + //} } \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/helper.cs b/src/Umbraco.Web/umbraco.presentation/helper.cs index 3caf4ec5c0..7a965d09ae 100644 --- a/src/Umbraco.Web/umbraco.presentation/helper.cs +++ b/src/Umbraco.Web/umbraco.presentation/helper.cs @@ -27,8 +27,10 @@ namespace umbraco [Obsolete("This method has been superceded. Use the extension method for HttpRequest or HttpRequestBase method: GetItemAsString instead.")] public static string Request(string text) - { - + { + if (HttpContext.Current == null) + return string.Empty; + if (HttpContext.Current.Request[text.ToLower()] != null) if (HttpContext.Current.Request[text] != string.Empty) return HttpContext.Current.Request[text]; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index a8a549383d..e4be986986 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core.IO; using umbraco.BasePages; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.media; @@ -15,7 +16,6 @@ using umbraco.cms.businesslogic.web; using umbraco.interfaces; using umbraco.uicontrols; using Content = umbraco.cms.businesslogic.Content; -using SystemDirectories = umbraco.IO.SystemDirectories; namespace umbraco.controls { @@ -26,19 +26,19 @@ namespace umbraco.controls /// public class ContentControl : TabView { - private Content _content; + private readonly Content _content; internal Dictionary DataTypes = new Dictionary(); - private UmbracoEnsuredPage prntpage; + private UmbracoEnsuredPage _prntpage; public event EventHandler SaveAndPublish; public event EventHandler SaveToPublish; public event EventHandler Save; - private publishModes CanPublish = publishModes.NoPublish; + private readonly publishModes _canPublish = publishModes.NoPublish; public TabPage tpProp; public bool DoesPublish = false; public TextBox NameTxt = new TextBox(); public PlaceHolder NameTxtHolder = new PlaceHolder(); public RequiredFieldValidator NameTxtValidator = new RequiredFieldValidator(); - private static string _UmbracoPath = SystemDirectories.Umbraco; + private static readonly string _UmbracoPath = SystemDirectories.Umbraco; public Pane PropertiesPane = new Pane(); public Content ContentObject @@ -59,7 +59,7 @@ namespace umbraco.controls } // zb-00036 #29889 : load it only once - List virtualTabs; + List _virtualTabs; /// /// Constructor to set default properties. @@ -76,7 +76,7 @@ namespace umbraco.controls public ContentControl(Content c, publishModes CanPublish, string Id) { ID = Id; - this.CanPublish = CanPublish; + this._canPublish = CanPublish; _content = c; Width = 350; @@ -84,16 +84,16 @@ namespace umbraco.controls SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + _prntpage = (UmbracoEnsuredPage)Page; // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + if (_virtualTabs == null) + _virtualTabs = _content.ContentType.getVirtualTabs.ToList(); - foreach (ContentType.TabI t in virtualTabs) + foreach (ContentType.TabI t in _virtualTabs) { TabPage tp = NewTabPage(t.Caption); - addSaveAndPublishButtons(ref tp); + AddSaveAndPublishButtons(ref tp); } } @@ -106,15 +106,15 @@ namespace umbraco.controls SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + _prntpage = (UmbracoEnsuredPage)Page; int i = 0; var inTab = new Hashtable(); // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + if (_virtualTabs == null) + _virtualTabs = _content.ContentType.getVirtualTabs.ToList(); - foreach (ContentType.TabI tab in virtualTabs) + foreach (ContentType.TabI tab in _virtualTabs) { var tabPage = this.Panels[i] as TabPage; if (tabPage == null) @@ -136,7 +136,7 @@ namespace umbraco.controls var property = _content.getProperty(propertyType); if (property != null && tabPage != null) { - addControlNew(property, tabPage, tab.Caption); + AddControlNew(property, tabPage, tab.Caption); // adding this check, as we occasionally get an already in dictionary error, though not sure why if (!inTab.ContainsKey(propertyType.Id.ToString())) @@ -153,7 +153,7 @@ namespace umbraco.controls // Add property pane tpProp = NewTabPage(ui.Text("general", "properties", null)); - addSaveAndPublishButtons(ref tpProp); + AddSaveAndPublishButtons(ref tpProp); tpProp.Controls.Add( new LiteralControl("
There were errors - data has not been saved!
")); @@ -163,7 +163,7 @@ namespace umbraco.controls foreach (Property p in props) { if (inTab[p.PropertyType.Id.ToString()] == null) - addControlNew(p, tpProp, ui.Text("general", "properties", null)); + AddControlNew(p, tpProp, ui.Text("general", "properties", null)); } } @@ -257,21 +257,21 @@ namespace umbraco.controls Save(this, new EventArgs()); } - private void savePublish(object Sender, ImageClickEventArgs e) + private void DoSaveAndPublish(object sender, ImageClickEventArgs e) { DoesPublish = true; - saveClick(Sender, e); + saveClick(sender, e); SaveAndPublish(this, new EventArgs()); } - private void saveToPublish(object Sender, ImageClickEventArgs e) + private void DoSaveToPublish(object sender, ImageClickEventArgs e) { - saveClick(Sender, e); + saveClick(sender, e); SaveToPublish(this, new EventArgs()); } - private void addSaveAndPublishButtons(ref TabPage tp) + private void AddSaveAndPublishButtons(ref TabPage tp) { MenuImageButton menuSave = tp.Menu.NewImageButton(); menuSave.ID = tp.ID + "_save"; @@ -279,28 +279,28 @@ namespace umbraco.controls menuSave.Click += new ImageClickEventHandler(saveClick); menuSave.OnClickCommand = "invokeSaveHandlers();"; menuSave.AltText = ui.Text("buttons", "save", null); - if (CanPublish == publishModes.Publish) + if (_canPublish == publishModes.Publish) { MenuImageButton menuPublish = tp.Menu.NewImageButton(); menuPublish.ID = tp.ID + "_publish"; menuPublish.ImageUrl = _UmbracoPath + "/images/editor/saveAndPublish.gif"; menuPublish.OnClickCommand = "invokeSaveHandlers();"; - menuPublish.Click += new ImageClickEventHandler(savePublish); + menuPublish.Click += new ImageClickEventHandler(DoSaveAndPublish); menuPublish.AltText = ui.Text("buttons", "saveAndPublish", null); } - else if (CanPublish == publishModes.SendToPublish) + else if (_canPublish == publishModes.SendToPublish) { MenuImageButton menuToPublish = tp.Menu.NewImageButton(); menuToPublish.ID = tp.ID + "_topublish"; menuToPublish.ImageUrl = _UmbracoPath + "/images/editor/saveToPublish.gif"; menuToPublish.OnClickCommand = "invokeSaveHandlers();"; - menuToPublish.Click += new ImageClickEventHandler(saveToPublish); + menuToPublish.Click += new ImageClickEventHandler(DoSaveToPublish); menuToPublish.AltText = ui.Text("buttons", "saveToPublish", null); } } - private void addControlNew(Property p, TabPage tp, string Caption) + private void AddControlNew(Property p, TabPage tp, string Caption) { IDataType dt = p.PropertyType.DataTypeDefinition.DataType; dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias); @@ -497,7 +497,7 @@ namespace umbraco.controls NoPublish } - private string dictinaryItem(string alias) + private string DictinaryItem(string alias) { if (alias.Substring(1, 0) == "#") { diff --git a/src/umbraco.cms/Properties/AssemblyInfo.cs b/src/umbraco.cms/Properties/AssemblyInfo.cs index 2e08a091b9..ca728d05e1 100644 --- a/src/umbraco.cms/Properties/AssemblyInfo.cs +++ b/src/umbraco.cms/Properties/AssemblyInfo.cs @@ -13,4 +13,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("umbraco", AllInternalsVisible=true)] [assembly: InternalsVisibleTo("Umbraco.LegacyTests")] -[assembly: InternalsVisibleTo("Umbraco.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("umbraco.editorControls")] \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index ece234542e..1d15edfcad 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -16,11 +16,13 @@ namespace umbraco.cms.businesslogic.datatype ///
public class DefaultData : IData, IDataWithPreview { - private int m_PropertyId; - private object m_Value; + private int _propertyId; + private object _value; protected BaseDataType _dataType; - private bool m_PreviewMode; - private bool m_ValueLoaded = false; + private bool _previewMode; + private bool _valueLoaded = false; + private Guid? _version = null; + private int? _nodeId = null; [Obsolete("Deprecated, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)] protected static ISqlHelper SqlHelper @@ -51,8 +53,8 @@ namespace umbraco.cms.businesslogic.datatype /// The init property id. public virtual void Initialize(object InitValue, int InitPropertyId) { - m_PropertyId = InitPropertyId; - m_Value = InitValue; + _propertyId = InitPropertyId; + _value = InitValue; } /// @@ -67,7 +69,7 @@ namespace umbraco.cms.businesslogic.datatype .On(x => x.Id, y => y.PropertyTypeId) .InnerJoin() .On(x => x.DataTypeId, y => y.DataTypeId) - .Where("cmsPropertyData.id = @Id", new {Id = m_PropertyId}); + .Where("cmsPropertyData.id = @Id", new {Id = _propertyId}); var dto = Database.Fetch(sql).FirstOrDefault(); if (dto != null) @@ -79,7 +81,7 @@ namespace umbraco.cms.businesslogic.datatype //get the column name in the cmsPropertyData table that stores the correct information for the data type var fieldName = BaseDataType.GetDataFieldName(dbType); //get the value for the data type, if null, set it to an empty string - m_Value = dto.GetValue; + _value = dto.GetValue; //now that we've set our value, we can update our BaseDataType object with the correct values from the db //instead of making it query for itself. This is a peformance optimization enhancement. _dataType.SetDataTypeProperties(fieldName, dbType); @@ -126,17 +128,17 @@ namespace umbraco.cms.businesslogic.datatype get { //Lazy load the value when it is required. - if (!m_ValueLoaded) + if (!_valueLoaded) { LoadValueFromDatabase(); - m_ValueLoaded = true; + _valueLoaded = true; } - return m_Value; + return _value; } set { - m_Value = value; - m_ValueLoaded = true; + _value = value; + _valueLoaded = true; } } @@ -168,23 +170,27 @@ namespace umbraco.cms.businesslogic.datatype { get { - return m_PropertyId; + return _propertyId; } set { - m_PropertyId = value; + _propertyId = value; //LoadValueFromDatabase(); } } - + // TODO: clean up Legacy - these are needed by the wysiwyeditor, in order to feed the richtextholder with version and nodeid // solution, create a new version of the richtextholder, which does not depend on these. public virtual Guid Version { get { - var dto = Database.FirstOrDefault("WHERE id = @Id", new {Id = PropertyId}); - return dto.VersionId.HasValue ? dto.VersionId.Value : Guid.Empty; + if (_version == null) + { + var dto = Database.FirstOrDefault("WHERE id = @Id", new { Id = PropertyId }); + _version = dto.VersionId.HasValue ? dto.VersionId.Value : Guid.Empty; + } + return _version.Value; } } @@ -196,7 +202,11 @@ namespace umbraco.cms.businesslogic.datatype { get { - return Database.ExecuteScalar("Select contentNodeid from cmsPropertyData where id = @Id", new {Id = PropertyId}); + if (_nodeId == null) + { + _nodeId = Database.ExecuteScalar("Select contentNodeid from cmsPropertyData where id = @Id", new { Id = PropertyId }); + } + return _nodeId.Value; } } @@ -215,16 +225,16 @@ namespace umbraco.cms.businesslogic.datatype { get { - return m_PreviewMode; + return _previewMode; } set { - if (m_PreviewMode != value) + if (_previewMode != value) { // if preview mode is switched off, reload the value from persistent storage if (!value) LoadValueFromDatabase(); - m_PreviewMode = value; + _previewMode = value; } } } diff --git a/src/umbraco.cms/businesslogic/datatype/FileHandlerData.cs b/src/umbraco.cms/businesslogic/datatype/FileHandlerData.cs index 6bdb826e39..eeb934cc9f 100644 --- a/src/umbraco.cms/businesslogic/datatype/FileHandlerData.cs +++ b/src/umbraco.cms/businesslogic/datatype/FileHandlerData.cs @@ -2,9 +2,9 @@ using System.IO; using System.Web; using System.Xml; +using Umbraco.Core.IO; using umbraco.cms.businesslogic.Files; using umbraco.cms.businesslogic.property; -using umbraco.IO; using IContent = Umbraco.Core.Models.IContent; using IMedia = Umbraco.Core.Models.IMedia; @@ -20,38 +20,37 @@ namespace umbraco.cms.businesslogic.datatype _thumbnailSizes = thumbnailSizes; } + /// + /// Gets/sets the loaded Conent object which we can resolve from other classes since this class sets it's properties + /// + internal Content LoadedContentItem { get; set; } + + /// + /// Called to ensure we have a valid LoadedContentItem. + /// + /// + private void EnsureLoadedContentItem(Guid version) + { + if (LoadedContentItem == null) + { + LoadedContentItem = Content.GetContentFromVersion(Version); + } + } + public override object Value { get { return base.Value; } set { - UmbracoFile um = null; - if (value is HttpPostedFile || value is HttpPostedFileBase || value is HttpPostedFileWrapper) + if (value is HttpPostedFile || value is HttpPostedFileBase) { - string name = string.Empty; - Stream fileStream = null; + Stream fileStream = null; - if (value is HttpPostedFile) - { - var file = value as HttpPostedFile; - name = Umbraco.Core.IO.IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); - fileStream = file.InputStream; - } - else if (value is HttpPostedFileBase) - { - var file = value as HttpPostedFileBase; - name = Umbraco.Core.IO.IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); - fileStream = file.InputStream; - } - else if (value is HttpPostedFileWrapper) - { - var file = value as HttpPostedFileWrapper; - name = file.FileName; - fileStream = file.InputStream; - } + var file = value as HttpPostedFile; + var name = IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); + fileStream = file.InputStream; - - // handle upload + // handle upload if (name != String.Empty) { @@ -60,7 +59,7 @@ namespace umbraco.cms.businesslogic.datatype : PropertyId + "-" + name; //fileName = Path.Combine(SystemDirectories.Media, fileName); - um = UmbracoFile.Save(fileStream, fileName); + UmbracoFile um = UmbracoFile.Save(fileStream, fileName); if (um.SupportsResizing) { @@ -94,11 +93,8 @@ namespace umbraco.cms.businesslogic.datatype if (uploadFieldConfigNode != null) { - var legacy = Content.GetContentFromVersion(Version); - if (legacy.ContentBase is IContent == false && legacy.ContentBase is IMedia == false) - { - FillProperties(uploadFieldConfigNode, legacy, um); - } + EnsureLoadedContentItem(Version); + FillProperties(uploadFieldConfigNode, LoadedContentItem, um); } } @@ -110,18 +106,18 @@ namespace umbraco.cms.businesslogic.datatype base.Value = String.Empty; // also reset values of related fields - clearRelatedValues(); + ClearRelatedValues(); } } else { base.Value = value; - clearRelatedValues(); + ClearRelatedValues(); } } } - private void clearRelatedValues() + private void ClearRelatedValues() { string propertyTypeAlias = new Property(PropertyId).PropertyType.Alias; if (UmbracoSettings.ImageAutoFillImageProperties != null) @@ -132,12 +128,13 @@ namespace umbraco.cms.businesslogic.datatype if (uploadFieldConfigNode != null) { // get the current document - Content legacy = Content.GetContentFromVersion(Version); + //Content legacy = Content.GetContentFromVersion(Version); + EnsureLoadedContentItem(Version); // only add dimensions to web images - updateContentProperty(uploadFieldConfigNode, legacy, "widthFieldAlias", String.Empty); - updateContentProperty(uploadFieldConfigNode, legacy, "heightFieldAlias", String.Empty); - updateContentProperty(uploadFieldConfigNode, legacy, "lengthFieldAlias", String.Empty); - updateContentProperty(uploadFieldConfigNode, legacy, "extensionFieldAlias", String.Empty); + UpdateContentProperty(uploadFieldConfigNode, LoadedContentItem, "widthFieldAlias", String.Empty); + UpdateContentProperty(uploadFieldConfigNode, LoadedContentItem, "heightFieldAlias", String.Empty); + UpdateContentProperty(uploadFieldConfigNode, LoadedContentItem, "lengthFieldAlias", String.Empty); + UpdateContentProperty(uploadFieldConfigNode, LoadedContentItem, "extensionFieldAlias", String.Empty); } } } @@ -145,14 +142,14 @@ namespace umbraco.cms.businesslogic.datatype private void FillProperties(XmlNode uploadFieldConfigNode, Content content, UmbracoFile um) { // only add dimensions to web images - updateContentProperty(uploadFieldConfigNode, content, "widthFieldAlias", um.SupportsResizing ? um.GetDimensions().Item1.ToString() : string.Empty); - updateContentProperty(uploadFieldConfigNode, content, "heightFieldAlias", um.SupportsResizing ? um.GetDimensions().Item2.ToString() : string.Empty); + UpdateContentProperty(uploadFieldConfigNode, content, "widthFieldAlias", um.SupportsResizing ? um.GetDimensions().Item1.ToString() : string.Empty); + UpdateContentProperty(uploadFieldConfigNode, content, "heightFieldAlias", um.SupportsResizing ? um.GetDimensions().Item2.ToString() : string.Empty); - updateContentProperty(uploadFieldConfigNode, content, "lengthFieldAlias", um.Length); - updateContentProperty(uploadFieldConfigNode, content, "extensionFieldAlias", um.Extension); + UpdateContentProperty(uploadFieldConfigNode, content, "lengthFieldAlias", um.Length); + UpdateContentProperty(uploadFieldConfigNode, content, "extensionFieldAlias", um.Extension); } - private void updateContentProperty(XmlNode uploadFieldConfigNode, Content content, string propertyAlias, + private static void UpdateContentProperty(XmlNode uploadFieldConfigNode, Content content, string propertyAlias, object propertyValue) { XmlNode propertyNode = uploadFieldConfigNode.SelectSingleNode(propertyAlias); diff --git a/src/umbraco.editorControls/uploadfield/DataTypeUploadField.cs b/src/umbraco.editorControls/uploadfield/DataTypeUploadField.cs index acdf95af82..8d5104094c 100644 --- a/src/umbraco.editorControls/uploadfield/DataTypeUploadField.cs +++ b/src/umbraco.editorControls/uploadfield/DataTypeUploadField.cs @@ -7,20 +7,26 @@ namespace umbraco.editorControls.uploadfield /// public class DataTypeUploadField : cms.businesslogic.datatype.BaseDataType,interfaces.IDataType { - private interfaces.IDataEditor _Editor; + private interfaces.IDataEditor _editor; private interfaces.IData _baseData; private interfaces.IDataPrevalue _prevalueeditor; + /// + /// Always returns an uploadField control + /// public override interfaces.IDataEditor DataEditor { get { - if (_Editor == null) - _Editor = new uploadField(Data, ((uploadFieldPreValue)PrevalueEditor).Configuration); - return _Editor; + if (_editor == null) + _editor = new uploadField(Data, ((uploadFieldPreValue)PrevalueEditor).Configuration); + return _editor; } } + /// + /// Always returns FileHandlerData + /// public override interfaces.IData Data { get diff --git a/src/umbraco.editorControls/uploadfield/uploadField.cs b/src/umbraco.editorControls/uploadfield/uploadField.cs index 933fffd8a1..3723f31c34 100644 --- a/src/umbraco.editorControls/uploadfield/uploadField.cs +++ b/src/umbraco.editorControls/uploadfield/uploadField.cs @@ -14,17 +14,16 @@ namespace umbraco.editorControls [ValidationProperty("IsValid")] public class uploadField : HtmlInputFile, IDataEditor { - private const String _thumbnailext = ".jpg"; - private readonly cms.businesslogic.datatype.DefaultData _data; + private const String Thumbnailext = ".jpg"; + private readonly cms.businesslogic.datatype.FileHandlerData _data; private readonly String _thumbnails; private String _text; - - private MediaFileSystem _fs; + private readonly MediaFileSystem _fs; public uploadField(IData Data, string ThumbnailSizes) { _fs = FileSystemProviderManager.Current.GetFileSystemProvider(); - _data = (cms.businesslogic.datatype.DefaultData) Data; + _data = (cms.businesslogic.datatype.FileHandlerData) Data; //this is always FileHandlerData _thumbnails = ThumbnailSizes; } @@ -79,7 +78,7 @@ namespace umbraco.editorControls if (helper.Request(ClientID + "clear") == "1") { // delete file - deleteFile(_text); + DeleteFile(_text); // set filename in db to nothing _text = ""; @@ -111,51 +110,14 @@ namespace umbraco.editorControls // we update additional properties post image upload if (_data.Value != DBNull.Value && !string.IsNullOrEmpty(_data.Value.ToString())) { - Content content = Content.GetContentFromVersion(_data.Version); - - // update extension in UI - try - { - var extensionControl = FindControlRecursive(Page, "prop_umbracoExtension"); - if (extensionControl != null) - { - extensionControl.RefreshLabel(content.getProperty("umbracoExtension").Value.ToString()); - } - } - catch - { - } - - + var content = _data.LoadedContentItem; + + // update extension in UI + UpdateLabelValue("umbracoExtension", "prop_umbracoExtension", Page, content); // update file size in UI - try - { - var bytesControl = FindControlRecursive(Page, "prop_umbracoBytes"); - if (bytesControl != null) - { - bytesControl.RefreshLabel(content.getProperty("umbracoBytes").Value.ToString()); - } - } - catch - { - } - - try - { - var widthControl = FindControlRecursive(Page, "prop_umbracoWidth"); - if (widthControl != null) - { - widthControl.RefreshLabel(content.getProperty("umbracoWidth").Value.ToString()); - } - var heightControl = FindControlRecursive(Page, "prop_umbracoHeight"); - if (heightControl != null) - { - heightControl.RefreshLabel(content.getProperty("umbracoHeight").Value.ToString()); - } - } - catch - { - } + UpdateLabelValue("umbracoBytes", "prop_umbracoBytes", Page, content); + UpdateLabelValue("umbracoWidth", "prop_umbracoWidth", Page, content); + UpdateLabelValue("umbracoHeight", "prop_umbracoHeight", Page, content); } Text = _data.Value.ToString(); } @@ -163,6 +125,18 @@ namespace umbraco.editorControls #endregion + private static void UpdateLabelValue(string propAlias, string controlId, Page controlPage, Content content) + { + var extensionControl = FindControlRecursive(controlPage, controlId); + if (extensionControl != null) + { + if (content.getProperty(propAlias) != null && content.getProperty(propAlias).Value != null) + { + extensionControl.RefreshLabel(content.getProperty(propAlias).Value.ToString()); + } + } + } + [Obsolete("This method is now obsolete due to a change in the way that files are handled. If you need to check if a URL for an uploaded file is safe you should implement your own as this method will be removed in a future version", false)] public string SafeUrl(string url) { @@ -179,7 +153,7 @@ namespace umbraco.editorControls Text = _data.Value.ToString(); } - private void deleteFile(string fileUrl) + private void DeleteFile(string fileUrl) { if (fileUrl.Length > 0) { @@ -200,8 +174,8 @@ namespace umbraco.editorControls try { - if (_fs.FileExists(relativeThumbFilePath + _thumbnailext)) - _fs.DeleteFile(relativeThumbFilePath + _thumbnailext); + if (_fs.FileExists(relativeThumbFilePath + Thumbnailext)) + _fs.DeleteFile(relativeThumbFilePath + Thumbnailext); } catch { @@ -214,7 +188,7 @@ namespace umbraco.editorControls { if (thumb != "") { - string relativeExtraThumbFilePath = relativeThumbFilePath + "_" + thumb + _thumbnailext; + string relativeExtraThumbFilePath = relativeThumbFilePath + "_" + thumb + Thumbnailext; try {