diff --git a/src/Umbraco.Web/ImageCropperBaseExtensions.cs b/src/Umbraco.Web/ImageCropperBaseExtensions.cs index f589deabee..6041802fe6 100644 --- a/src/Umbraco.Web/ImageCropperBaseExtensions.cs +++ b/src/Umbraco.Web/ImageCropperBaseExtensions.cs @@ -52,115 +52,45 @@ namespace Umbraco.Web internal static bool HasPropertyAndValue(this IPublishedContent publishedContent, string propertyAlias) - { - try + { + if (propertyAlias != null && publishedContent.HasProperty(propertyAlias) + && publishedContent.HasValue(propertyAlias)) { - - if (propertyAlias != null && publishedContent.HasProperty(propertyAlias) - && publishedContent.HasValue(propertyAlias)) + var propertyAliasValue = publishedContent.GetPropertyValue(propertyAlias); + if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) { - var propertyAliasValue = publishedContent.GetPropertyValue(propertyAlias); - if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) - { - return false; - } - return true; + return false; } - } - catch (Exception ex) - { - LogHelper.Warn("The cache unicorn is not happy with node id: " + publishedContent.Id + " - http://issues.umbraco.org/issue/U4-4146"); - - var cropsProperty = publishedContent.Properties.FirstOrDefault(x => x.PropertyTypeAlias == propertyAlias); - - if (cropsProperty != null && !string.IsNullOrEmpty(cropsProperty.Value.ToString())) - { - var propertyAliasValue = cropsProperty.Value.ToString(); - if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) - { - return false; - } - return true; - } - } + return true; + } return false; } internal static bool HasPropertyAndValueAndCrop(this IPublishedContent publishedContent, string propertyAlias, string cropAlias) { - try + if (propertyAlias != null && publishedContent.HasProperty(propertyAlias) + && publishedContent.HasValue(propertyAlias)) { - if (propertyAlias != null && publishedContent.HasProperty(propertyAlias) - && publishedContent.HasValue(propertyAlias)) + var propertyAliasValue = publishedContent.GetPropertyValue(propertyAlias); + if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) { - var propertyAliasValue = publishedContent.GetPropertyValue(propertyAlias); - if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) - { - return false; - } - var allTheCrops = propertyAliasValue.SerializeToCropDataSet(); - if (allTheCrops != null && allTheCrops.Crops.Any()) - { - var crop = cropAlias != null - ? allTheCrops.Crops.First(x => x.Alias ==cropAlias) - : allTheCrops.Crops.First(); - if (crop != null) - { - return true; - } - } return false; } - } - catch (Exception ex) - { - LogHelper.Warn("The cache unicorn is not happy with node id: " + publishedContent.Id + " - http://issues.umbraco.org/issue/U4-4146"); - var cropsProperty = publishedContent.Properties.FirstOrDefault(x => x.PropertyTypeAlias == propertyAlias); - - if (cropsProperty != null && !string.IsNullOrEmpty(cropsProperty.Value.ToString())) + var allTheCrops = propertyAliasValue.SerializeToCropDataSet(); + if (allTheCrops != null && allTheCrops.Crops.Any()) { - var propertyAliasValue = cropsProperty.Value.ToString(); - if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2) + var crop = cropAlias != null + ? allTheCrops.Crops.First(x => x.Alias ==cropAlias) + : allTheCrops.Crops.First(); + if (crop != null) { - return false; + return true; } - var allTheCrops = propertyAliasValue.SerializeToCropDataSet(); - if (allTheCrops != null && allTheCrops.Crops.Any()) - { - var crop = cropAlias != null - ? allTheCrops.Crops.First(x => x.Alias ==cropAlias) - : allTheCrops.Crops.First(); - if (crop != null) - { - return true; - } - } - return false; } - } + return false; + } return false; } - internal static string GetPropertyValueHack(this IPublishedContent publishedContent, string propertyAlias) - { - string propertyValue = null; - try - { - if (propertyAlias != null && publishedContent.HasProperty(propertyAlias) - && publishedContent.HasValue(propertyAlias)) - { - propertyValue = publishedContent.GetPropertyValue(propertyAlias); - } - } - catch (Exception ex) - { - var cropsProperty = publishedContent.Properties.FirstOrDefault(x => x.PropertyTypeAlias == propertyAlias); - if (cropsProperty != null) - { - propertyValue = cropsProperty.Value.ToString(); - } - } - return propertyValue; - } } } diff --git a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs index 783e25f4ae..fbc1c3dba2 100644 --- a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs +++ b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs @@ -32,7 +32,6 @@ namespace Umbraco.Web } } - public static string GetCropUrl( this IPublishedContent mediaItem, int? width = null, @@ -40,19 +39,19 @@ namespace Umbraco.Web int? quality = null, Mode? mode = null, Anchor? anchor = null, - string imageCropperAlias = null, - string imageCropperCropId = null, + string propertyAlias = null, + string cropAlias = null, string furtherOptions = null, bool slimmage = false) { string imageCropperValue = null; - if (mediaItem.HasPropertyAndValueAndCrop(imageCropperAlias, imageCropperCropId)) + if (mediaItem.HasPropertyAndValueAndCrop(propertyAlias, cropAlias)) { - imageCropperValue = mediaItem.GetPropertyValueHack(imageCropperAlias); + imageCropperValue = mediaItem.GetPropertyValue(propertyAlias); } - return mediaItem != null ? GetCropUrl(mediaItem.Url, width, height, quality, mode, anchor, imageCropperValue, imageCropperCropId, furtherOptions, slimmage) : string.Empty; + return mediaItem != null ? GetCropUrl(mediaItem.Url, width, height, quality, mode, anchor, imageCropperValue, cropAlias, furtherOptions, slimmage) : string.Empty; } @@ -71,17 +70,12 @@ namespace Umbraco.Web if (!string.IsNullOrEmpty(imageUrl)) { var imageResizerUrl = new StringBuilder(); - imageResizerUrl.Append(imageUrl); + //imageResizerUrl.Append(imageUrl); if (!string.IsNullOrEmpty(imageCropperValue) && imageCropperValue.DetectIsJson()) { - var allTheCrops = imageCropperValue.SerializeToCropDataSet(); - if (allTheCrops != null && allTheCrops.Crops.Any()) - { - - if(allTheCrops.HasCrop(cropAlias)) - imageResizerUrl.Append(allTheCrops.GetCropUrl(cropAlias)); - } + var cropDataSet = imageCropperValue.SerializeToCropDataSet(); + imageResizerUrl.Append(cropDataSet.Src + cropDataSet.GetCropUrl(cropAlias)); } else {