Merge remote-tracking branch 'origin/6.2.2' into 7.1.5

Conflicts:
	src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
	src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs
	src/Umbraco.Web/Umbraco.Web.csproj
This commit is contained in:
Shannon
2014-07-24 09:42:44 -07:00
3 changed files with 71 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Text;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Macros;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors.ValueConverters
{
/// <summary>
/// Ensures macro syntax is parsed for the macro container which will work when getting the field
/// values in any way (i.e. dynamically, using Field(), or IPublishedContent)
/// </summary>
[PropertyValueType(typeof (IHtmlString))]
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Request)]
public class MacroContainerValueConverter : PropertyValueConverterBase
{
public override bool IsConverter(PublishedPropertyType propertyType)
{
return Guid.Parse(Constants.PropertyEditors.MacroContainer).Equals(propertyType.PropertyEditorGuid);
}
// NOT thread-safe over a request because it modifies the
// global UmbracoContext.Current.InPreviewMode status. So it
// should never execute in // over the same UmbracoContext with
// different preview modes.
static string RenderMacros(string source, bool preview)
{
// save and set for macro rendering
var inPreviewMode = UmbracoContext.Current.InPreviewMode;
UmbracoContext.Current.InPreviewMode = preview;
var sb = new StringBuilder();
try
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
MacroTagParser.ParseMacros(
source,
//callback for when text block is found
textBlock => sb.Append(textBlock),
//callback for when macro syntax is found
(macroAlias, macroAttributes) => sb.Append(umbracoHelper.RenderMacro(
macroAlias,
//needs to be explicitly casted to Dictionary<string, object>
macroAttributes.ConvertTo(x => (string)x, x => x)).ToString()));
}
finally
{
// restore
UmbracoContext.Current.InPreviewMode = inPreviewMode;
}
return sb.ToString();
}
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null) return null;
var sourceString = source.ToString();
// ensure string is parsed for macros and macros are executed correctly
sourceString = RenderMacros(sourceString, preview);
return sourceString;
}
}
}

View File

@@ -11,7 +11,7 @@ using Umbraco.Web.Templates;
namespace Umbraco.Web.PropertyEditors.ValueConverters
{
/// <summary>
/// <summary>
/// A value converter for TinyMCE that will ensure any macro content is rendered properly even when
/// used dynamically.
/// </summary>

View File

@@ -355,6 +355,7 @@
<Compile Include="Mvc\PreRenderViewActionFilterAttribute.cs" />
<Compile Include="Mvc\RedirectToUmbracoUrlResult.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeByIdRouteHandler.cs" />
<Compile Include="PropertyEditors\ValueConverters\MacroContainerValueConverter.cs" />
<Compile Include="PropertyEditors\TagsDataController.cs" />
<Compile Include="PublishedCache\MemberPublishedContent.cs" />
<Compile Include="PublishedCache\RawValueProperty.cs" />