diff --git a/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs b/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs index 90674a0d4b..a2166e82c0 100644 --- a/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs +++ b/src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs @@ -11,10 +11,7 @@ namespace Umbraco.Web.umbraco.presentation { static class CompatibilityHelper { - // NOTE - this is all already in umbraco.MacroEngines - // which references Umbraco.Web - so we can't reference it without - // creating circular references - // fixme - there has to be a better way? + // NOTE - moved from umbraco.MacroEngines to avoid circ. references public static INode ConvertToNode(IPublishedContent doc) { @@ -22,9 +19,9 @@ namespace Umbraco.Web.umbraco.presentation return node; } - public static IProperty ConvertToNodeProperty(IPublishedProperty prop) + private static IProperty ConvertToNodeProperty(IPublishedProperty prop) { - return new ConvertedProperty(prop.PropertyTypeAlias, prop.Value.ToString()); + return new ConvertedProperty(prop); } private class ConvertedNode : INode @@ -96,20 +93,16 @@ namespace Umbraco.Web.umbraco.presentation { get { return _doc.Children.Select(ConvertToNode).ToList(); } } - public IProperty GetProperty(string Alias) + public IProperty GetProperty(string alias) { - return PropertiesAsList.Cast().FirstOrDefault(p => p.Alias == Alias); + return PropertiesAsList.Cast().FirstOrDefault(p => p.Alias == alias); } - public IProperty GetProperty(string Alias, out bool propertyExists) + public IProperty GetProperty(string alias, out bool propertyExists) { - foreach (var p in from global::umbraco.NodeFactory.Property p in PropertiesAsList where p.Alias == Alias select p) - { - propertyExists = true; - return p; - } - propertyExists = false; - return null; + var prop = _doc.GetProperty(alias); + propertyExists = prop != null; + return prop == null ? null : ConvertToNodeProperty(prop); } public DataTable ChildrenAsTable() @@ -125,23 +118,21 @@ namespace Umbraco.Web.umbraco.presentation private class ConvertedProperty : IProperty, IHtmlString { - private readonly string _alias; - private readonly string _value; + private readonly IPublishedProperty _prop; - public ConvertedProperty(string alias, string value) + public ConvertedProperty(IPublishedProperty prop) { - _alias = alias; - _value = value; + _prop = prop; } public string Alias { - get { return _alias; } + get { return _prop.PropertyTypeAlias; } } public string Value { - get { return _value; } + get { return _prop.DataValue == null ? null : _prop.DataValue.ToString(); } } public Guid Version @@ -156,7 +147,7 @@ namespace Umbraco.Web.umbraco.presentation public bool HasValue() { - return !string.IsNullOrWhiteSpace(Value); + return _prop.HasValue; } public int ContextId { get; set; } diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index f97cd789eb..93e90989fd 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -1463,7 +1463,7 @@ namespace umbraco IMacroEngine engine = null; engine = MacroEngineFactory.GetEngine(PartialViewMacroEngine.EngineName); - var ret = engine.Execute(macro, CompatibilityHelper.ConvertToNode(UmbracoContext.Current.PublishedContentRequest.PublishedContent)); + var ret = engine.Execute(macro, GetCurrentNode()); // if the macro engine supports success reporting and executing failed, then return an empty control so it's not cached if (engine is IMacroEngineResultStatus) @@ -1488,13 +1488,13 @@ namespace umbraco engine = MacroEngineFactory.GetByExtension(macro.ScriptLanguage); ret = engine.Execute( macro, - CompatibilityHelper.ConvertToNode(UmbracoContext.Current.PublishedContentRequest.PublishedContent)); + GetCurrentNode()); } else { string path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + macro.ScriptName); engine = MacroEngineFactory.GetByFilename(path); - ret = engine.Execute(macro, CompatibilityHelper.ConvertToNode(UmbracoContext.Current.PublishedContentRequest.PublishedContent)); + ret = engine.Execute(macro, GetCurrentNode()); } // if the macro engine supports success reporting and executing failed, then return an empty control so it's not cached @@ -1521,13 +1521,13 @@ namespace umbraco engine = MacroEngineFactory.GetByExtension(macro.ScriptLanguage); ret.Text = engine.Execute( macro, - CompatibilityHelper.ConvertToNode(UmbracoContext.Current.PublishedContentRequest.PublishedContent)); + GetCurrentNode()); } else { string path = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + macro.ScriptName); engine = MacroEngineFactory.GetByFilename(path); - ret.Text = engine.Execute(macro, CompatibilityHelper.ConvertToNode(UmbracoContext.Current.PublishedContentRequest.PublishedContent)); + ret.Text = engine.Execute(macro, GetCurrentNode()); } // if the macro engine supports success reporting and executing failed, then return an empty control so it's not cached @@ -2082,6 +2082,13 @@ namespace umbraco return false; } + private static INode GetCurrentNode() + { + var id = Node.getCurrentNodeId(); + var content = UmbracoContext.Current.ContentCache.GetById(id); + return CompatibilityHelper.ConvertToNode(content); + } + #region Events /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/Node.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/Node.cs index e25754b0a5..e0cf298d5d 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/Node.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/Node.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Web; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; @@ -542,10 +543,9 @@ namespace umbraco.NodeFactory public static int getCurrentNodeId() { - if (UmbracoContext.Current == null) throw new InvalidOperationException("Cannot get current node id without an UmbracoContext."); - if (UmbracoContext.Current.PublishedContentRequest == null) throw new InvalidOperationException("Cannot get current node id without a PublishedContentRequest."); - if (UmbracoContext.Current.PublishedContentRequest.HasPublishedContent == false) throw new InvalidOperationException("Cannot get current node id because the current PublishedContentRequest has no content."); - return UmbracoContext.Current.PublishedContentRequest.PublishedContent.Id; + if (HttpContext.Current.Items["pageID"] == null) + throw new InvalidOperationException("There is no current node."); + return (int)HttpContext.Current.Items["pageID"]; } } } \ No newline at end of file diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs index e2a7c6d56f..c748605264 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicBackingItem.cs @@ -32,7 +32,7 @@ namespace umbraco.MacroEngines } public DynamicBackingItem(int Id) { - var n = UmbracoContext.Current.ContentCache.GetById(Id).ConvertToNode(); + var n = CompatibilityHelper.ConvertToNode(UmbracoContext.Current.ContentCache.GetById(Id)); this.content = n; this.Type = DynamicBackingItemType.Content; @@ -57,7 +57,7 @@ namespace umbraco.MacroEngines } else { - this.content = UmbracoContext.Current.ContentCache.GetById(Id).ConvertToNode(); + this.content = CompatibilityHelper.ConvertToNode(UmbracoContext.Current.ContentCache.GetById(Id)); this.Type = Type; } } diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/PublishedContentExtensions.cs b/src/umbraco.MacroEngines/RazorDynamicNode/PublishedContentExtensions.cs deleted file mode 100644 index 59b32fa0ea..0000000000 --- a/src/umbraco.MacroEngines/RazorDynamicNode/PublishedContentExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using Umbraco.Core; -using Umbraco.Core.Dynamics; -using Umbraco.Core.Models; -using Umbraco.Web; -using umbraco.NodeFactory; -using umbraco.interfaces; -using Umbraco.Web.umbraco.presentation; -using Property = umbraco.NodeFactory.Property; - -namespace umbraco.MacroEngines.Library -{ - /// - /// Provides extension methods for IPublishedContent. - /// - /// These are dedicated to converting DynamicPublishedContent to INode. - internal static class PublishedContentExtensions - { - internal static INode ConvertToNode(this IPublishedContent doc) - { - return CompatibilityHelper.ConvertToNode(doc); - } - } -} \ No newline at end of file diff --git a/src/umbraco.MacroEngines/umbraco.MacroEngines.csproj b/src/umbraco.MacroEngines/umbraco.MacroEngines.csproj index 3b6be4351d..cfe7659b01 100644 --- a/src/umbraco.MacroEngines/umbraco.MacroEngines.csproj +++ b/src/umbraco.MacroEngines/umbraco.MacroEngines.csproj @@ -127,7 +127,6 @@ -