Merge remote-tracking branch 'origin/netcore/dev' into netcore/feature/AB4919-untable-umbraco-context
This commit is contained in:
64
src/Umbraco.Web/Models/ImageProcessorImageUrlGenerator.cs
Normal file
64
src/Umbraco.Web/Models/ImageProcessorImageUrlGenerator.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
{
|
||||
internal class ImageProcessorImageUrlGenerator : IImageUrlGenerator
|
||||
{
|
||||
public string GetImageUrl(ImageUrlGenerationOptions options)
|
||||
{
|
||||
if (options == null) return null;
|
||||
|
||||
var imageProcessorUrl = new StringBuilder(options.ImageUrl ?? string.Empty);
|
||||
|
||||
if (options.FocalPoint != null) AppendFocalPoint(imageProcessorUrl, options);
|
||||
else if (options.Crop != null) AppendCrop(imageProcessorUrl, options);
|
||||
else if (options.DefaultCrop) imageProcessorUrl.Append("?anchor=center&mode=crop");
|
||||
else
|
||||
{
|
||||
imageProcessorUrl.Append("?mode=").Append((options.ImageCropMode ?? "crop").ToLower());
|
||||
|
||||
if (options.ImageCropAnchor != null) imageProcessorUrl.Append("&anchor=").Append(options.ImageCropAnchor.ToLower());
|
||||
}
|
||||
|
||||
var hasFormat = options.FurtherOptions != null && options.FurtherOptions.InvariantContains("&format=");
|
||||
|
||||
//Only put quality here, if we don't have a format specified.
|
||||
//Otherwise we need to put quality at the end to avoid it being overridden by the format.
|
||||
if (options.Quality != null && hasFormat == false) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (options.HeightRatio != null) imageProcessorUrl.Append("&heightratio=").Append(options.HeightRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.WidthRatio != null) imageProcessorUrl.Append("&widthratio=").Append(options.WidthRatio.Value.ToString(CultureInfo.InvariantCulture));
|
||||
if (options.Width != null) imageProcessorUrl.Append("&width=").Append(options.Width);
|
||||
if (options.Height != null) imageProcessorUrl.Append("&height=").Append(options.Height);
|
||||
if (options.UpScale == false) imageProcessorUrl.Append("&upscale=false");
|
||||
if (options.AnimationProcessMode != null) imageProcessorUrl.Append("&animationprocessmode=").Append(options.AnimationProcessMode);
|
||||
if (options.FurtherOptions != null) imageProcessorUrl.Append(options.FurtherOptions);
|
||||
|
||||
//If furtherOptions contains a format, we need to put the quality after the format.
|
||||
if (options.Quality != null && hasFormat) imageProcessorUrl.Append("&quality=").Append(options.Quality);
|
||||
if (options.CacheBusterValue != null) imageProcessorUrl.Append("&rnd=").Append(options.CacheBusterValue);
|
||||
|
||||
return imageProcessorUrl.ToString();
|
||||
}
|
||||
|
||||
private void AppendFocalPoint(StringBuilder imageProcessorUrl, ImageUrlGenerationOptions options)
|
||||
{
|
||||
imageProcessorUrl.Append("?center=");
|
||||
imageProcessorUrl.Append(options.FocalPoint.Top.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
imageProcessorUrl.Append(options.FocalPoint.Left.ToString(CultureInfo.InvariantCulture));
|
||||
imageProcessorUrl.Append("&mode=crop");
|
||||
}
|
||||
|
||||
private void AppendCrop(StringBuilder imageProcessorUrl, ImageUrlGenerationOptions options)
|
||||
{
|
||||
imageProcessorUrl.Append("?crop=");
|
||||
imageProcessorUrl.Append(options.Crop.X1.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
imageProcessorUrl.Append(options.Crop.Y1.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
imageProcessorUrl.Append(options.Crop.X2.ToString(CultureInfo.InvariantCulture)).Append(",");
|
||||
imageProcessorUrl.Append(options.Crop.Y2.ToString(CultureInfo.InvariantCulture));
|
||||
imageProcessorUrl.Append("&cropmode=percentage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,11 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly IImageUrlGenerator _imageUrlGenerator;
|
||||
|
||||
public UserMapDefinition(ILocalizedTextService textService, IUserService userService, IEntityService entityService, ISectionService sectionService,
|
||||
AppCaches appCaches, ActionCollection actions, IGlobalSettings globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper)
|
||||
AppCaches appCaches, ActionCollection actions, IGlobalSettings globalSettings, IMediaFileSystem mediaFileSystem, IShortStringHelper shortStringHelper,
|
||||
IImageUrlGenerator imageUrlGenerator)
|
||||
{
|
||||
_sectionService = sectionService;
|
||||
_entityService = entityService;
|
||||
@@ -44,6 +46,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
_globalSettings = globalSettings;
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_imageUrlGenerator = imageUrlGenerator;
|
||||
}
|
||||
|
||||
public void DefineMaps(UmbracoMapper mapper)
|
||||
@@ -279,7 +282,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private void Map(IUser source, UserDisplay target, MapperContext context)
|
||||
{
|
||||
target.AvailableCultures = _textService.GetSupportedCultures().ToDictionary(x => x.Name, x => x.DisplayName);
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem);
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem, _imageUrlGenerator);
|
||||
target.CalculatedStartContentIds = GetStartNodes(source.CalculateContentStartNodeIds(_entityService), UmbracoObjectTypes.Document, "content/contentRoot", context);
|
||||
target.CalculatedStartMediaIds = GetStartNodes(source.CalculateMediaStartNodeIds(_entityService), UmbracoObjectTypes.Media, "media/mediaRoot", context);
|
||||
target.CreateDate = source.CreateDate;
|
||||
@@ -310,7 +313,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
//Loading in the user avatar's requires an external request if they don't have a local file avatar, this means that initial load of paging may incur a cost
|
||||
//Alternatively, if this is annoying the back office UI would need to be updated to request the avatars for the list of users separately so it doesn't look
|
||||
//like the load time is waiting.
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem);
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem, _imageUrlGenerator);
|
||||
target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString();
|
||||
target.Email = source.Email;
|
||||
target.EmailHash = source.Email.ToLowerInvariant().Trim().GenerateHash();
|
||||
@@ -329,7 +332,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private void Map(IUser source, UserDetail target, MapperContext context)
|
||||
{
|
||||
target.AllowedSections = source.AllowedSections;
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem);
|
||||
target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileSystem, _imageUrlGenerator);
|
||||
target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString();
|
||||
target.Email = source.Email;
|
||||
target.EmailHash = source.Email.ToLowerInvariant().Trim().GenerateHash();
|
||||
|
||||
Reference in New Issue
Block a user