mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding tokens integration
--HG-- branch : 1.x extra : rebase_source : 4d57ad107c43236647d4d2967a161f2723631a00
This commit is contained in:
@@ -94,6 +94,10 @@
|
||||
<Project>{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}</Project>
|
||||
<Name>Orchard.Media</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
|
||||
<Project>{6f759635-13d7-4e94-bcc9-80445d63f117}</Project>
|
||||
<Name>Orchard.Tokens</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
|
@@ -8,6 +8,7 @@ using Orchard.Forms.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.MediaProcessing.Descriptors.Filter;
|
||||
using Orchard.MediaProcessing.Services;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.MediaProcessing.Providers.Filters {
|
||||
public class ResizeFilter : IImageFilterProvider {
|
||||
@@ -65,7 +66,6 @@ namespace Orchard.MediaProcessing.Providers.Filters {
|
||||
else {
|
||||
settings.PaddingColor = Color.FromName(padcolor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var result = new MemoryStream();
|
||||
@@ -77,7 +77,15 @@ namespace Orchard.MediaProcessing.Providers.Filters {
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(FilterContext context) {
|
||||
return T((string)context.State.Mode + " to {0}px high x {1}px wide", context.State.Height, context.State.Width);
|
||||
string mode = context.State.Mode;
|
||||
|
||||
switch (mode) {
|
||||
case "pad": return T("Pad to {0}x{1}", context.State.Height, context.State.Width);
|
||||
case "crop": return T("Crop to {0}x{1}", context.State.Height, context.State.Width);
|
||||
case "stretch": return T("Stretch to {0}x{1}", context.State.Height, context.State.Width);
|
||||
default: return T("Resize to {0}x{1}", context.State.Height, context.State.Width);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Environment;
|
||||
using Orchard.FileSystems.Media;
|
||||
@@ -11,6 +13,7 @@ using Orchard.Logging;
|
||||
using Orchard.MediaProcessing.Descriptors.Filter;
|
||||
using Orchard.MediaProcessing.Media;
|
||||
using Orchard.MediaProcessing.Services;
|
||||
using Orchard.Tokens;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.MediaProcessing.Shapes {
|
||||
@@ -20,20 +23,28 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
private readonly Work<IImageProfileService> _profileService;
|
||||
private readonly Work<IImageProcessingManager> _processingManager;
|
||||
private readonly Work<IOrchardServices> _services;
|
||||
private readonly Work<ITokenizer> _tokenizer;
|
||||
|
||||
public MediaShapes(Work<IStorageProvider> storageProvider, Work<IImageProcessingFileNameProvider> fileNameProvider, Work<IImageProfileService> profileService, Work<IImageProcessingManager> processingManager, Work<IOrchardServices> services) {
|
||||
public MediaShapes(
|
||||
Work<IStorageProvider> storageProvider,
|
||||
Work<IImageProcessingFileNameProvider> fileNameProvider,
|
||||
Work<IImageProfileService> profileService,
|
||||
Work<IImageProcessingManager> processingManager,
|
||||
Work<IOrchardServices> services,
|
||||
Work<ITokenizer> tokenizer) {
|
||||
_storageProvider = storageProvider;
|
||||
_fileNameProvider = fileNameProvider;
|
||||
_profileService = profileService;
|
||||
_processingManager = processingManager;
|
||||
_services = services;
|
||||
_tokenizer = tokenizer;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
[Shape]
|
||||
public void ImageUrl(dynamic Display, TextWriter Output, string Profile, string Path) {
|
||||
public void ImageUrl(dynamic Display, TextWriter Output, string Profile, string Path, ContentItem ContentItem) {
|
||||
var filePath = _fileNameProvider.Value.GetFileName(Profile, Path);
|
||||
// todo: regenerate the file if the profile is newer, by getting IStorageFile.
|
||||
if (string.IsNullOrEmpty(filePath) || !_storageProvider.Value.FileExists(filePath)) {
|
||||
@@ -44,11 +55,20 @@ namespace Orchard.MediaProcessing.Shapes {
|
||||
|
||||
var image = GetImage(Path);
|
||||
var filterContext = new FilterContext {Media = image, Format = new FileInfo(Path).Extension, FilePath = _storageProvider.Value.Combine(Profile, CreateDefaultFileName(Path))};
|
||||
|
||||
var tokens = new Dictionary<string, object>();
|
||||
// if a content item is provided, use it while tokenizing
|
||||
if (ContentItem != null) {
|
||||
tokens.Add("Content", ContentItem);
|
||||
}
|
||||
|
||||
foreach (var filter in profilePart.Filters.OrderBy(f => f.Position)) {
|
||||
var descriptor = _processingManager.Value.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == filter.Category && x.Type == filter.Type);
|
||||
if (descriptor == null)
|
||||
continue;
|
||||
filterContext.State = FormParametersHelper.ToDynamic(filter.State);
|
||||
|
||||
var tokenized = _tokenizer.Value.Replace(filter.State, tokens);
|
||||
filterContext.State = FormParametersHelper.ToDynamic(tokenized);
|
||||
descriptor.Filter(filterContext);
|
||||
}
|
||||
|
||||
|
@@ -2,4 +2,5 @@
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Name, T("Name"))
|
||||
@Html.TextBoxFor(m => m.Name, new {@class = "text"})
|
||||
<span class="hint">@T("The technical name of the profile. Must be letters and numbers only (e.g. Thumbnail).")</span>
|
||||
</fieldset>
|
Reference in New Issue
Block a user