From 0cf44c1bd0c54ec568d597528f7014243c16bf80 Mon Sep 17 00:00:00 2001 From: Claus Date: Thu, 22 Oct 2015 13:42:38 +0200 Subject: [PATCH] Fixes: U4-7223 GetCropUrl outputs html entities in url when used in css Adding in HtmlHelper extensions for GetCropUrl. --- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 128 ++++++++++++++++-- 1 file changed, 120 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 7ae519a44b..813ac92142 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Text; using System.Web; @@ -11,10 +10,12 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Dynamics; using Umbraco.Core.IO; +using Umbraco.Core.Models; using Umbraco.Core.Profiling; +using Umbraco.Web.Models; using Umbraco.Web.Mvc; -using umbraco; -using umbraco.cms.businesslogic.member; +using Constants = Umbraco.Core.Constants; +using Member = umbraco.cms.businesslogic.member.Member; namespace Umbraco.Web { @@ -194,12 +195,123 @@ namespace Umbraco.Web return htmlHelper.Action(actionName, metaData.ControllerName, routeVals); } - #region BeginUmbracoForm + #region GetCropUrl - /// - /// Used for rendering out the Form for BeginUmbracoForm - /// - internal class UmbracoForm : MvcForm + /// + /// Gets the ImageProcessor Url of a media item by the crop alias (using default media item property alias of "umbracoFile") + /// + /// + /// + /// + /// + public static IHtmlString GetCropUrl(this HtmlHelper htmlHelper, IPublishedContent mediaItem, string cropAlias) + { + return new HtmlString(mediaItem.GetCropUrl(cropAlias: cropAlias, useCropDimensions: true)); + } + + /// + /// Gets the ImageProcessor Url of a media item by the property alias and crop alias. + /// + /// + /// + /// + /// + /// + public static IHtmlString GetCropUrl(this HtmlHelper htmlHelper, IPublishedContent mediaItem, string propertyAlias, string cropAlias) + { + return new HtmlString(mediaItem.GetCropUrl(propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true)); + } + + /// + /// Gets the ImageProcessor Url of a media item + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static IHtmlString GetCropUrl(this HtmlHelper htmlHelper, + IPublishedContent mediaItem, + int? width = null, + int? height = null, + string propertyAlias = Constants.Conventions.Media.File, + string cropAlias = null, + int? quality = null, + ImageCropMode? imageCropMode = null, + ImageCropAnchor? imageCropAnchor = null, + bool preferFocalPoint = false, + bool useCropDimensions = false, + bool cacheBuster = true, + string furtherOptions = null, + ImageCropRatioMode? ratioMode = null, + bool upScale = true) + { + return + new HtmlString(mediaItem.GetCropUrl(width, height, propertyAlias, cropAlias, quality, imageCropMode, + imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, + upScale)); + } + + /// + /// Gets the ImageProcessor Url from the media path + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static IHtmlString GetCropUrl(this HtmlHelper htmlHelper, + string imageUrl, + int? width = null, + int? height = null, + string imageCropperValue = null, + string cropAlias = null, + int? quality = null, + ImageCropMode? imageCropMode = null, + ImageCropAnchor? imageCropAnchor = null, + bool preferFocalPoint = false, + bool useCropDimensions = false, + string cacheBusterValue = null, + string furtherOptions = null, + ImageCropRatioMode? ratioMode = null, + bool upScale = true) + { + return + new HtmlString(imageUrl.GetCropUrl(width, height, imageCropperValue, cropAlias, quality, imageCropMode, + imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode, + upScale)); + } + + #endregion + + #region BeginUmbracoForm + + /// + /// Used for rendering out the Form for BeginUmbracoForm + /// + internal class UmbracoForm : MvcForm { /// /// Creates an UmbracoForm