diff --git a/src/Orchard.Web/Core/Shapes/CoreShapes.cs b/src/Orchard.Web/Core/Shapes/CoreShapes.cs index be95189eb..c1260411e 100644 --- a/src/Orchard.Web/Core/Shapes/CoreShapes.cs +++ b/src/Orchard.Web/Core/Shapes/CoreShapes.cs @@ -301,9 +301,12 @@ namespace Orchard.Core.Shapes { var progress = 1; var flatPositionComparer = new FlatPositionComparer(); var ordering = unordered.Select(item => { - var position = (item == null || item.GetType().GetProperty("Metadata") == null || item.Metadata.GetType().GetProperty("Position") == null) - ? null - : item.Metadata.Position; + string position = null; + var itemPosition = item as IPositioned; + if (itemPosition != null) { + position = itemPosition.Position; + } + return new { item, position }; }).ToList(); diff --git a/src/Orchard/ContentManagement/ContentPart.cs b/src/Orchard/ContentManagement/ContentPart.cs index cdb4bbfbe..16ed02311 100644 --- a/src/Orchard/ContentManagement/ContentPart.cs +++ b/src/Orchard/ContentManagement/ContentPart.cs @@ -21,14 +21,6 @@ namespace Orchard.ContentManagement { public virtual ContentItem ContentItem { get; set; } - //interesting thought, should/could parts also have zones (would then have zones on the page, content item and parts...)? - private readonly IZoneCollection _zones = new ZoneCollection(); - public virtual IZoneCollection Zones { - get { - return _zones; - } - } - /// /// The ContentItem's identifier. /// diff --git a/src/Orchard/DisplayManagement/IPositioned.cs b/src/Orchard/DisplayManagement/IPositioned.cs new file mode 100644 index 000000000..898cdc76a --- /dev/null +++ b/src/Orchard/DisplayManagement/IPositioned.cs @@ -0,0 +1,5 @@ +namespace Orchard.DisplayManagement { + public interface IPositioned { + string Position { get; } + } +} \ No newline at end of file diff --git a/src/Orchard/DisplayManagement/IShape.cs b/src/Orchard/DisplayManagement/IShape.cs index 27ad21151..5ec1483cb 100644 --- a/src/Orchard/DisplayManagement/IShape.cs +++ b/src/Orchard/DisplayManagement/IShape.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using Orchard.DisplayManagement.Shapes; +using Orchard.DisplayManagement.Shapes; namespace Orchard.DisplayManagement { /// diff --git a/src/Orchard/DisplayManagement/PositionWrapper.cs b/src/Orchard/DisplayManagement/PositionWrapper.cs new file mode 100644 index 000000000..e684bfdb5 --- /dev/null +++ b/src/Orchard/DisplayManagement/PositionWrapper.cs @@ -0,0 +1,26 @@ +using System.Web; + +namespace Orchard.DisplayManagement { + public class PositionWrapper : IHtmlString, IPositioned { + + private IHtmlString _value; + public string Position { get; private set; } + + public PositionWrapper(IHtmlString value, string position) { + _value = value; + Position = position; + } + + public PositionWrapper(string value, string position) + : this(new HtmlString(HttpUtility.HtmlEncode(value)), position) { + } + + public string ToHtmlString() { + return _value.ToHtmlString(); + } + + public override string ToString() { + return _value.ToString(); + } + } +} diff --git a/src/Orchard/DisplayManagement/Shapes/Shape.cs b/src/Orchard/DisplayManagement/Shapes/Shape.cs index d009d1123..a3e30e6d8 100644 --- a/src/Orchard/DisplayManagement/Shapes/Shape.cs +++ b/src/Orchard/DisplayManagement/Shapes/Shape.cs @@ -4,11 +4,11 @@ using System.Dynamic; using System.Linq; using System.Collections; using System.Collections.Generic; -using System.Web.Mvc; +using System.Web; namespace Orchard.DisplayManagement.Shapes { [DebuggerTypeProxy(typeof(ShapeDebugView))] - public class Shape : Composite, IShape, IEnumerable { + public class Shape : Composite, IShape, IPositioned, IEnumerable { private const string DefaultPosition = "5"; private readonly IList _items = new List(); @@ -22,6 +22,12 @@ namespace Orchard.DisplayManagement.Shapes { public virtual IDictionary Attributes { get { return _attributes; } } public virtual IEnumerable Items { get { return _items; } } + public string Position { + get { + return Metadata.Position; + } + } + public Shape() { Metadata = new ShapeMetadata(); } @@ -33,13 +39,14 @@ namespace Orchard.DisplayManagement.Shapes { } try { - // todo: (sebros) this is a temporary implementation to prevent common known scenarios throwing exceptions. The final solution would need to filter based on the fact that it is a Shape instance - if (item is MvcHtmlString || - item is String) { - // need to implement positioned wrapper for non-shape objects + if (position != null && item is IHtmlString) { + item = new PositionWrapper((IHtmlString)item, position); + } + else if (position != null && item is string) { + item = new PositionWrapper((string)item, position); } else if (item is IShape) { - ((dynamic)item).Metadata.Position = position; + ((IShape)item).Metadata.Position = position; } } catch { diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 05643ba8a..bc54f1a22 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -150,6 +150,8 @@ + +