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>
|
<Project>{D9A7B330-CD22-4DA1-A95A-8DE1982AD8EB}</Project>
|
||||||
<Name>Orchard.Media</Name>
|
<Name>Orchard.Media</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
|
||||||
|
<Project>{6f759635-13d7-4e94-bcc9-80445d63f117}</Project>
|
||||||
|
<Name>Orchard.Tokens</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdminMenu.cs" />
|
<Compile Include="AdminMenu.cs" />
|
||||||
|
@@ -8,6 +8,7 @@ using Orchard.Forms.Services;
|
|||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.MediaProcessing.Descriptors.Filter;
|
using Orchard.MediaProcessing.Descriptors.Filter;
|
||||||
using Orchard.MediaProcessing.Services;
|
using Orchard.MediaProcessing.Services;
|
||||||
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.MediaProcessing.Providers.Filters {
|
namespace Orchard.MediaProcessing.Providers.Filters {
|
||||||
public class ResizeFilter : IImageFilterProvider {
|
public class ResizeFilter : IImageFilterProvider {
|
||||||
@@ -65,7 +66,6 @@ namespace Orchard.MediaProcessing.Providers.Filters {
|
|||||||
else {
|
else {
|
||||||
settings.PaddingColor = Color.FromName(padcolor);
|
settings.PaddingColor = Color.FromName(padcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new MemoryStream();
|
var result = new MemoryStream();
|
||||||
@@ -77,7 +77,15 @@ namespace Orchard.MediaProcessing.Providers.Filters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LocalizedString DisplayFilter(FilterContext context) {
|
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;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.FileSystems.Media;
|
using Orchard.FileSystems.Media;
|
||||||
@@ -11,6 +13,7 @@ using Orchard.Logging;
|
|||||||
using Orchard.MediaProcessing.Descriptors.Filter;
|
using Orchard.MediaProcessing.Descriptors.Filter;
|
||||||
using Orchard.MediaProcessing.Media;
|
using Orchard.MediaProcessing.Media;
|
||||||
using Orchard.MediaProcessing.Services;
|
using Orchard.MediaProcessing.Services;
|
||||||
|
using Orchard.Tokens;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.MediaProcessing.Shapes {
|
namespace Orchard.MediaProcessing.Shapes {
|
||||||
@@ -20,20 +23,28 @@ namespace Orchard.MediaProcessing.Shapes {
|
|||||||
private readonly Work<IImageProfileService> _profileService;
|
private readonly Work<IImageProfileService> _profileService;
|
||||||
private readonly Work<IImageProcessingManager> _processingManager;
|
private readonly Work<IImageProcessingManager> _processingManager;
|
||||||
private readonly Work<IOrchardServices> _services;
|
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;
|
_storageProvider = storageProvider;
|
||||||
_fileNameProvider = fileNameProvider;
|
_fileNameProvider = fileNameProvider;
|
||||||
_profileService = profileService;
|
_profileService = profileService;
|
||||||
_processingManager = processingManager;
|
_processingManager = processingManager;
|
||||||
_services = services;
|
_services = services;
|
||||||
|
_tokenizer = tokenizer;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
[Shape]
|
[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);
|
var filePath = _fileNameProvider.Value.GetFileName(Profile, Path);
|
||||||
// todo: regenerate the file if the profile is newer, by getting IStorageFile.
|
// todo: regenerate the file if the profile is newer, by getting IStorageFile.
|
||||||
if (string.IsNullOrEmpty(filePath) || !_storageProvider.Value.FileExists(filePath)) {
|
if (string.IsNullOrEmpty(filePath) || !_storageProvider.Value.FileExists(filePath)) {
|
||||||
@@ -44,11 +55,20 @@ namespace Orchard.MediaProcessing.Shapes {
|
|||||||
|
|
||||||
var image = GetImage(Path);
|
var image = GetImage(Path);
|
||||||
var filterContext = new FilterContext {Media = image, Format = new FileInfo(Path).Extension, FilePath = _storageProvider.Value.Combine(Profile, CreateDefaultFileName(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)) {
|
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);
|
var descriptor = _processingManager.Value.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == filter.Category && x.Type == filter.Type);
|
||||||
if (descriptor == null)
|
if (descriptor == null)
|
||||||
continue;
|
continue;
|
||||||
filterContext.State = FormParametersHelper.ToDynamic(filter.State);
|
|
||||||
|
var tokenized = _tokenizer.Value.Replace(filter.State, tokens);
|
||||||
|
filterContext.State = FormParametersHelper.ToDynamic(tokenized);
|
||||||
descriptor.Filter(filterContext);
|
descriptor.Filter(filterContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,4 +2,5 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
@Html.LabelFor(m => m.Name, T("Name"))
|
@Html.LabelFor(m => m.Name, T("Name"))
|
||||||
@Html.TextBoxFor(m => m.Name, new {@class = "text"})
|
@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>
|
</fieldset>
|
Reference in New Issue
Block a user