mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Incremental work on update media
This commit is contained in:
parent
61b614a0bb
commit
5e93dfa190
@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
@ -40,14 +41,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
public ActionResult Index(string folderPath = "", bool dialog = false) {
|
public ActionResult Index(string folderPath = "", bool dialog = false) {
|
||||||
var mediaTypes = new List<string>();
|
|
||||||
|
|
||||||
foreach(var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions()) {
|
|
||||||
string stereotype;
|
|
||||||
if (contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype) && stereotype == "Media")
|
|
||||||
mediaTypes.Add(contentTypeDefinition.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// let other modules enhance the ui by providing custom navigation and actions
|
// let other modules enhance the ui by providing custom navigation and actions
|
||||||
var explorer = Services.ContentManager.New("MediaLibraryExplorer");
|
var explorer = Services.ContentManager.New("MediaLibraryExplorer");
|
||||||
explorer.Weld(new MediaLibraryExplorerPart());
|
explorer.Weld(new MediaLibraryExplorerPart());
|
||||||
@ -58,7 +52,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
DialogMode = dialog,
|
DialogMode = dialog,
|
||||||
Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy),
|
Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy),
|
||||||
FolderPath = folderPath,
|
FolderPath = folderPath,
|
||||||
MediaTypes = mediaTypes.ToArray(),
|
MediaTypes = _mediaLibraryService.GetMediaTypes(),
|
||||||
CustomActionsShapes = explorerShape.Actions,
|
CustomActionsShapes = explorerShape.Actions,
|
||||||
CustomNavigationShapes = explorerShape.Navigation,
|
CustomNavigationShapes = explorerShape.Navigation,
|
||||||
};
|
};
|
||||||
@ -75,13 +69,15 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Import(string folderPath) {
|
public ActionResult Import(string folderPath) {
|
||||||
|
|
||||||
var mediaProviderMenu = _navigationManager.BuildMenu("mediaproviders");
|
var mediaProviderMenu = _navigationManager.BuildMenu("mediaproviders");
|
||||||
var imageSets = _navigationManager.BuildImageSets("mediaproviders");
|
var imageSets = _navigationManager.BuildImageSets("mediaproviders");
|
||||||
|
|
||||||
var viewModel = new MediaManagerImportViewModel {
|
var viewModel = new MediaManagerImportViewModel {
|
||||||
Menu = mediaProviderMenu,
|
Menu = mediaProviderMenu,
|
||||||
ImageSets = imageSets,
|
ImageSets = imageSets,
|
||||||
FolderPath = folderPath
|
FolderPath = folderPath,
|
||||||
|
MediaTypes = _mediaLibraryService.GetMediaTypes()
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
@ -94,7 +90,7 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
|
|
||||||
var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
|
var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
|
||||||
MediaPart = x,
|
MediaPart = x,
|
||||||
Shape = Services.ContentManager.BuildDisplay(x, "Thumbnail")
|
Shape = Services.ContentManager.BuildDisplay(x.ContentItem, "Thumbnail")
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
var viewModel = new MediaManagerMediaItemsViewModel {
|
var viewModel = new MediaManagerMediaItemsViewModel {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using Orchard.MediaLibrary.Services;
|
using Orchard.MediaLibrary.Services;
|
||||||
|
using Orchard.MediaLibrary.ViewModels;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
|
|
||||||
@ -9,18 +12,25 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
[Admin, Themed(false)]
|
[Admin, Themed(false)]
|
||||||
public class ClientStorageController : Controller {
|
public class ClientStorageController : Controller {
|
||||||
private readonly IMediaLibraryService _mediaLibraryService;
|
private readonly IMediaLibraryService _mediaLibraryService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public ClientStorageController(IMediaLibraryService mediaManagerService) {
|
public ClientStorageController(IMediaLibraryService mediaManagerService, IContentManager contentManager) {
|
||||||
_mediaLibraryService = mediaManagerService;
|
_mediaLibraryService = mediaManagerService;
|
||||||
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index(string folderPath) {
|
public ActionResult Index(string folderPath, string type) {
|
||||||
|
|
||||||
return View((object)folderPath);
|
var viewModel = new ImportMediaViewModel {
|
||||||
|
FolderPath = folderPath,
|
||||||
|
Type = type
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Upload(string folderPath) {
|
public ActionResult Upload(string folderPath, string type) {
|
||||||
var statuses = new List<object>();
|
var statuses = new List<object>();
|
||||||
|
|
||||||
// Loop through each file in the request
|
// Loop through each file in the request
|
||||||
@ -34,7 +44,8 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
filename = "clipboard.png";
|
filename = "clipboard.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename);
|
var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type);
|
||||||
|
_contentManager.Create(mediaPart);
|
||||||
|
|
||||||
statuses.Add(new {
|
statuses.Add(new {
|
||||||
id = mediaPart.Id,
|
id = mediaPart.Id,
|
||||||
|
@ -5,7 +5,6 @@ using System.Text.RegularExpressions;
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
using Orchard.MediaLibrary.Services;
|
|
||||||
using Orchard.MediaLibrary.ViewModels;
|
using Orchard.MediaLibrary.ViewModels;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
@ -14,30 +13,28 @@ using Orchard.ContentManagement;
|
|||||||
namespace Orchard.MediaLibrary.Controllers {
|
namespace Orchard.MediaLibrary.Controllers {
|
||||||
[Admin, Themed(false)]
|
[Admin, Themed(false)]
|
||||||
public class OEmbedController : Controller {
|
public class OEmbedController : Controller {
|
||||||
private readonly IMediaLibraryService _mediaLibraryService;
|
public OEmbedController(IOrchardServices services) {
|
||||||
|
|
||||||
public OEmbedController(
|
|
||||||
IMediaLibraryService mediaManagerService,
|
|
||||||
IOrchardServices services) {
|
|
||||||
_mediaLibraryService = mediaManagerService;
|
|
||||||
Services = services;
|
Services = services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
|
|
||||||
public ActionResult Index(string folderPath) {
|
public ActionResult Index(string folderPath, string type) {
|
||||||
var viewModel = new OEmbedViewModel {
|
var viewModel = new OEmbedViewModel {
|
||||||
FolderPath = folderPath
|
FolderPath = folderPath,
|
||||||
|
Type = type
|
||||||
};
|
};
|
||||||
|
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Index(string folderPath, string url) {
|
[ActionName("Index")]
|
||||||
|
public ActionResult IndexPOST(string folderPath, string url, string type) {
|
||||||
var viewModel = new OEmbedViewModel {
|
var viewModel = new OEmbedViewModel {
|
||||||
Url = url,
|
Url = url,
|
||||||
FolderPath = folderPath
|
FolderPath = folderPath,
|
||||||
|
Type = type
|
||||||
};
|
};
|
||||||
|
|
||||||
var webClient = new WebClient {Encoding = Encoding.UTF8};
|
var webClient = new WebClient {Encoding = Encoding.UTF8};
|
||||||
@ -76,14 +73,20 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ValidateInput(false)]
|
[HttpPost, ValidateInput(false)]
|
||||||
public ActionResult MediaPost(string folderPath, string url, string document) {
|
public ActionResult MediaPost(string folderPath, string url, string document, string type) {
|
||||||
var content = XDocument.Parse(document);
|
var content = XDocument.Parse(document);
|
||||||
var oembed = content.Root;
|
var oembed = content.Root;
|
||||||
|
|
||||||
var part = Services.ContentManager.New<MediaPart>("OEmbed");
|
if (String.IsNullOrEmpty(type)) {
|
||||||
|
type = "OEmbed";
|
||||||
|
}
|
||||||
|
|
||||||
|
var part = Services.ContentManager.New<MediaPart>(type);
|
||||||
|
|
||||||
part.MimeType = "text/html";
|
part.MimeType = "text/html";
|
||||||
part.FolderPath = folderPath;
|
part.FolderPath = folderPath;
|
||||||
|
part.LogicalType = "OEmbed";
|
||||||
|
|
||||||
if (oembed.Element("title") != null) {
|
if (oembed.Element("title") != null) {
|
||||||
part.Title = oembed.Element("title").Value;
|
part.Title = oembed.Element("title").Value;
|
||||||
}
|
}
|
||||||
@ -93,18 +96,23 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
if (oembed.Element("description") != null) {
|
if (oembed.Element("description") != null) {
|
||||||
part.Caption = oembed.Element("description").Value;
|
part.Caption = oembed.Element("description").Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var oembedPart = part.As<OEmbedPart>();
|
var oembedPart = part.As<OEmbedPart>();
|
||||||
|
|
||||||
oembedPart.Source = url;
|
if (oembedPart != null) {
|
||||||
|
|
||||||
foreach (var element in oembed.Elements()) {
|
oembedPart.Source = url;
|
||||||
oembedPart[element.Name.LocalName] = element.Value;
|
|
||||||
|
foreach (var element in oembed.Elements()) {
|
||||||
|
oembedPart[element.Name.LocalName] = element.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Services.ContentManager.Create(oembedPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.ContentManager.Create(oembedPart);
|
|
||||||
|
|
||||||
var viewModel = new OEmbedViewModel {
|
var viewModel = new OEmbedViewModel {
|
||||||
FolderPath = folderPath
|
FolderPath = folderPath,
|
||||||
|
Type = type
|
||||||
};
|
};
|
||||||
|
|
||||||
return View("Index", viewModel);
|
return View("Index", viewModel);
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using Orchard.MediaLibrary.Services;
|
using Orchard.MediaLibrary.Services;
|
||||||
|
using Orchard.MediaLibrary.ViewModels;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
|
|
||||||
@ -10,24 +12,32 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
[Admin, Themed(false)]
|
[Admin, Themed(false)]
|
||||||
public class WebSearchController : Controller {
|
public class WebSearchController : Controller {
|
||||||
private readonly IMediaLibraryService _mediaLibraryService;
|
private readonly IMediaLibraryService _mediaLibraryService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
public WebSearchController(IMediaLibraryService mediaManagerService) {
|
public WebSearchController(IMediaLibraryService mediaManagerService, IContentManager contentManager) {
|
||||||
_mediaLibraryService = mediaManagerService;
|
_mediaLibraryService = mediaManagerService;
|
||||||
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Index(string folderPath) {
|
public ActionResult Index(string folderPath, string type) {
|
||||||
|
var viewModel = new ImportMediaViewModel {
|
||||||
|
FolderPath = folderPath,
|
||||||
|
Type = type
|
||||||
|
};
|
||||||
|
|
||||||
return View((object)folderPath);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public JsonResult ImagePost(string folderPath, string url) {
|
public JsonResult ImagePost(string folderPath, string type, string url) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var buffer = new WebClient().DownloadData(url);
|
var buffer = new WebClient().DownloadData(url);
|
||||||
var stream = new MemoryStream(buffer);
|
var stream = new MemoryStream(buffer);
|
||||||
var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url));
|
|
||||||
|
var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url), type);
|
||||||
|
_contentManager.Create(mediaPart);
|
||||||
|
|
||||||
return new JsonResult {
|
return new JsonResult {
|
||||||
Data = new {folderPath, MediaPath = mediaPart.FileName}
|
Data = new {folderPath, MediaPath = mediaPart.FileName}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Drivers {
|
namespace Orchard.MediaLibrary.Drivers {
|
||||||
|
@ -1,21 +1,33 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
|
|
||||||
public class AudioFactorySelector : IMediaFactorySelector {
|
public class AudioFactorySelector : IMediaFactorySelector {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public AudioFactorySelector(IContentManager contentManager) {
|
public AudioFactorySelector(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) {
|
||||||
if (!mimeType.StartsWith("audio/")) {
|
if (!mimeType.StartsWith("audio/")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(contentType)) {
|
||||||
|
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof(AudioPart).Name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new MediaFactorySelectorResult {
|
return new MediaFactorySelectorResult {
|
||||||
Priority = -5,
|
Priority = -5,
|
||||||
MediaFactory = new AudioFactory(_contentManager)
|
MediaFactory = new AudioFactory(_contentManager)
|
||||||
@ -33,13 +45,23 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
|
||||||
var part = _contentManager.New<MediaPart>("Audio");
|
if (String.IsNullOrEmpty(contentType)) {
|
||||||
|
contentType = "Audio";
|
||||||
|
}
|
||||||
|
|
||||||
|
var part = _contentManager.New<MediaPart>(contentType);
|
||||||
|
|
||||||
|
part.LogicalType = "Audio";
|
||||||
part.MimeType = mimeType;
|
part.MimeType = mimeType;
|
||||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
var audioPart = part.As<AudioPart>();
|
var audioPart = part.As<AudioPart>();
|
||||||
|
|
||||||
|
if (audioPart == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
audioPart.Length = 0;
|
audioPart.Length = 0;
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
@ -10,12 +13,21 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DocumentFactorySelector : IMediaFactorySelector {
|
public class DocumentFactorySelector : IMediaFactorySelector {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public DocumentFactorySelector(IContentManager contentManager) {
|
public DocumentFactorySelector(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) {
|
||||||
|
if (!String.IsNullOrEmpty(contentType)) {
|
||||||
|
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof(DocumentPart).Name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new MediaFactorySelectorResult {
|
return new MediaFactorySelectorResult {
|
||||||
Priority = -10,
|
Priority = -10,
|
||||||
MediaFactory = new DocumentFactory(_contentManager)
|
MediaFactory = new DocumentFactory(_contentManager)
|
||||||
@ -30,14 +42,24 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
|
||||||
|
|
||||||
var part = _contentManager.New<MediaPart>("Document");
|
if (String.IsNullOrEmpty(contentType)) {
|
||||||
|
contentType = "Document";
|
||||||
|
}
|
||||||
|
|
||||||
|
var part = _contentManager.New<MediaPart>(contentType);
|
||||||
|
|
||||||
|
part.LogicalType = "Document";
|
||||||
part.MimeType = mimeType;
|
part.MimeType = mimeType;
|
||||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
var documentPart = part.As<DocumentPart>();
|
var documentPart = part.As<DocumentPart>();
|
||||||
|
|
||||||
|
if (documentPart == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
documentPart.Length = stream.Length;
|
documentPart.Length = stream.Length;
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
|
@ -4,7 +4,7 @@ using Orchard.MediaLibrary.Models;
|
|||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
|
|
||||||
public interface IMediaFactory {
|
public interface IMediaFactory {
|
||||||
MediaPart CreateMedia(Stream stream, string path, string mimeType);
|
MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NullMediaFactory : IMediaFactory {
|
public class NullMediaFactory : IMediaFactory {
|
||||||
@ -12,7 +12,7 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
get { return new NullMediaFactory(); }
|
get { return new NullMediaFactory(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
public interface IMediaFactorySelector : IDependency {
|
public interface IMediaFactorySelector : IDependency {
|
||||||
MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType);
|
MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,35 @@
|
|||||||
using System.Drawing;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
using Image = System.Drawing.Image;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
|
|
||||||
public class ImageFactorySelector : IMediaFactorySelector {
|
public class ImageFactorySelector : IMediaFactorySelector {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public ImageFactorySelector(IContentManager contentManager) {
|
public ImageFactorySelector(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
|
||||||
|
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) {
|
||||||
if (!mimeType.StartsWith("image/")) {
|
if (!mimeType.StartsWith("image/")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(contentType)) {
|
||||||
|
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof (ImagePart).Name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new MediaFactorySelectorResult {
|
return new MediaFactorySelectorResult {
|
||||||
Priority = -5,
|
Priority = -5,
|
||||||
MediaFactory = new ImageFactory(_contentManager)
|
MediaFactory = new ImageFactory(_contentManager)
|
||||||
@ -32,14 +45,22 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
|
||||||
|
if (String.IsNullOrEmpty(contentType)) {
|
||||||
|
contentType = "Image";
|
||||||
|
}
|
||||||
|
|
||||||
var part = _contentManager.New<MediaPart>("Image");
|
var part = _contentManager.New<MediaPart>(contentType);
|
||||||
|
|
||||||
|
part.LogicalType = "Image";
|
||||||
part.MimeType = mimeType;
|
part.MimeType = mimeType;
|
||||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
var imagePart = part.As<ImagePart>();
|
var imagePart = part.As<ImagePart>();
|
||||||
|
if (imagePart == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
using (var image = Image.FromStream(stream)) {
|
using (var image = Image.FromStream(stream)) {
|
||||||
imagePart.Width = image.Width;
|
imagePart.Width = image.Width;
|
||||||
imagePart.Height = image.Height;
|
imagePart.Height = image.Height;
|
||||||
|
@ -1,21 +1,33 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Factories {
|
namespace Orchard.MediaLibrary.Factories {
|
||||||
|
|
||||||
public class VideoFactorySelector : IMediaFactorySelector {
|
public class VideoFactorySelector : IMediaFactorySelector {
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
|
||||||
public VideoFactorySelector(IContentManager contentManager) {
|
public VideoFactorySelector(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) {
|
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) {
|
||||||
if (!mimeType.StartsWith("video/")) {
|
if (!mimeType.StartsWith("video/")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(contentType)) {
|
||||||
|
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
|
if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof(VideoPart).Name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new MediaFactorySelectorResult {
|
return new MediaFactorySelectorResult {
|
||||||
Priority = -5,
|
Priority = -5,
|
||||||
MediaFactory = new VideoFactory(_contentManager)
|
MediaFactory = new VideoFactory(_contentManager)
|
||||||
@ -31,13 +43,23 @@ namespace Orchard.MediaLibrary.Factories {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart CreateMedia(Stream stream, string path, string mimeType) {
|
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
|
||||||
var part = _contentManager.New<MediaPart>("Video");
|
if (String.IsNullOrEmpty(contentType)) {
|
||||||
|
contentType = "Video";
|
||||||
|
}
|
||||||
|
|
||||||
|
var part = _contentManager.New<MediaPart>(contentType);
|
||||||
|
|
||||||
|
part.LogicalType = "Video";
|
||||||
part.MimeType = mimeType;
|
part.MimeType = mimeType;
|
||||||
part.Title = Path.GetFileNameWithoutExtension(path);
|
part.Title = Path.GetFileNameWithoutExtension(path);
|
||||||
|
|
||||||
var videoPart = part.As<VideoPart>();
|
var videoPart = part.As<VideoPart>();
|
||||||
|
|
||||||
|
if (videoPart == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
videoPart.Length = 0;
|
videoPart.Length = 0;
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.Core.Contents.Extensions;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary {
|
namespace Orchard.MediaLibrary {
|
||||||
@ -86,5 +87,39 @@ namespace Orchard.MediaLibrary {
|
|||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom3() {
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("MediaPart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Turns a content type into a Media. Note: you need to set the stereotype to \"Media\" as well.")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("ImagePart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Provides common metadata for an Image Media.")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("VideoPart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Provides common metadata for a Video Media.")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("AudioPart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Provides common metadata for an Audio Media.")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("DocumentPart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Provides common metadata for a Document Media.")
|
||||||
|
);
|
||||||
|
|
||||||
|
ContentDefinitionManager.AlterPartDefinition("OEmbedPart", part => part
|
||||||
|
.Attachable()
|
||||||
|
.WithDescription("Provides common metadata for an OEmbed Media.")
|
||||||
|
);
|
||||||
|
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
using Orchard.ContentManagement;
|
using System;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||||
using Orchard.ContentManagement.Utilities;
|
using Orchard.ContentManagement.Utilities;
|
||||||
using Orchard.Core.Title.Models;
|
using Orchard.Core.Title.Models;
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ namespace Orchard.MediaLibrary.Models {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or set the name of the media when <see cref="IMediaService"/> is used
|
/// Gets or sets the name of the media when <see cref="IMediaService"/> is used
|
||||||
/// to store the physical media. If <value>null</value> then the media is not associated
|
/// to store the physical media. If <value>null</value> then the media is not associated
|
||||||
/// with a local file.
|
/// with a local file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,5 +65,16 @@ namespace Orchard.MediaLibrary.Models {
|
|||||||
public string MediaUrl {
|
public string MediaUrl {
|
||||||
get { return _publicUrl.Value; }
|
get { return _publicUrl.Value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get or sets the logical type of the media. For instance a custom type could be rendered as an Image
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The logical type is used to drive the thumbnails generation in the admin.
|
||||||
|
/// </remarks>
|
||||||
|
public string LogicalType {
|
||||||
|
get { return Convert.ToString(this.As<InfosetPart>().Get<MediaPart>("LogicalType")); }
|
||||||
|
set { this.As<InfosetPart>().Set<MediaPart>("LogicalType", value); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -167,6 +167,7 @@
|
|||||||
<Compile Include="Settings\MediaLibraryPickerFieldEditorEvents.cs" />
|
<Compile Include="Settings\MediaLibraryPickerFieldEditorEvents.cs" />
|
||||||
<Compile Include="Settings\MediaLibraryPickerFieldSettings.cs" />
|
<Compile Include="Settings\MediaLibraryPickerFieldSettings.cs" />
|
||||||
<Compile Include="Tokens\FieldTokens.cs" />
|
<Compile Include="Tokens\FieldTokens.cs" />
|
||||||
|
<Compile Include="ViewModels\ImportMediaViewModel.cs" />
|
||||||
<Compile Include="ViewModels\MediaLibraryPickerFieldViewModel.cs" />
|
<Compile Include="ViewModels\MediaLibraryPickerFieldViewModel.cs" />
|
||||||
<Compile Include="ViewModels\MediaManagerMediaItemsViewModel.cs" />
|
<Compile Include="ViewModels\MediaManagerMediaItemsViewModel.cs" />
|
||||||
<Compile Include="ViewModels\MediaManagerFolderCreateViewModel.cs" />
|
<Compile Include="ViewModels\MediaManagerFolderCreateViewModel.cs" />
|
||||||
@ -336,6 +337,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Parts\MediaLibrary.Navigation.cshtml" />
|
<Content Include="Views\Parts\MediaLibrary.Navigation.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\EditorTemplates\Parts.Image.Edit.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
Parts_OEmbed="Content"
|
Parts_OEmbed="Content"
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
<!-- MediaPart -->
|
<!-- MediaPart -->
|
||||||
<Match DisplayType="SummaryAdmin">
|
<Match DisplayType="SummaryAdmin">
|
||||||
<Place Parts_Media_SummaryAdmin="Meta:5"
|
<Place Parts_Media_SummaryAdmin="Meta:5"
|
||||||
|
@ -2,20 +2,23 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.MediaLibrary.Factories;
|
using Orchard.MediaLibrary.Factories;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Services {
|
namespace Orchard.MediaLibrary.Services {
|
||||||
public interface IMediaLibraryService : IDependency {
|
public interface IMediaLibraryService : IDependency {
|
||||||
IEnumerable<string> GetMediaTypes();
|
IEnumerable<ContentTypeDefinition> GetMediaTypes();
|
||||||
IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems();
|
IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems();
|
||||||
IEnumerable<MediaPart> GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType);
|
IEnumerable<MediaPart> GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType);
|
||||||
IEnumerable<MediaPart> GetMediaContentItems(int skip, int count, string order, string mediaType);
|
IEnumerable<MediaPart> GetMediaContentItems(int skip, int count, string order, string mediaType);
|
||||||
int GetMediaContentItemsCount(string folderPath, string mediaType);
|
int GetMediaContentItemsCount(string folderPath, string mediaType);
|
||||||
int GetMediaContentItemsCount(string mediaType);
|
int GetMediaContentItemsCount(string mediaType);
|
||||||
MediaPart ImportMedia(string relativePath, string filename);
|
MediaPart ImportMedia(string relativePath, string filename);
|
||||||
|
MediaPart ImportMedia(string relativePath, string filename, string contentType);
|
||||||
MediaPart ImportMedia(Stream stream, string relativePath, string filename);
|
MediaPart ImportMedia(Stream stream, string relativePath, string filename);
|
||||||
IMediaFactory GetMediaFactory(Stream stream, string mimeType);
|
MediaPart ImportMedia(Stream stream, string relativePath, string filename, string contentType);
|
||||||
|
IMediaFactory GetMediaFactory(Stream stream, string mimeType, string contentType);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a unique filename to prevent filename collisions.
|
/// Creates a unique filename to prevent filename collisions.
|
||||||
|
@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.FileSystems.Media;
|
using Orchard.FileSystems.Media;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@ -34,10 +35,13 @@ namespace Orchard.MediaLibrary.Services {
|
|||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public IEnumerable<string> GetMediaTypes() {
|
public IEnumerable<ContentTypeDefinition> GetMediaTypes() {
|
||||||
return _orchardServices.ContentManager.GetContentTypeDefinitions()
|
return _orchardServices
|
||||||
|
.ContentManager
|
||||||
|
.GetContentTypeDefinitions()
|
||||||
.Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "Media")
|
.Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "Media")
|
||||||
.Select(contentTypeDefinition => contentTypeDefinition.Name);
|
.OrderBy(x => x.DisplayName)
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems() {
|
public IContentQuery<MediaPart, MediaPartRecord> GetMediaContentItems() {
|
||||||
@ -105,10 +109,14 @@ namespace Orchard.MediaLibrary.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart ImportMedia(Stream stream, string relativePath, string filename) {
|
public MediaPart ImportMedia(Stream stream, string relativePath, string filename) {
|
||||||
|
return ImportMedia(stream, relativePath, filename, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaPart ImportMedia(Stream stream, string relativePath, string filename, string contentType) {
|
||||||
var uniqueFilename = GetUniqueFilename(relativePath, filename);
|
var uniqueFilename = GetUniqueFilename(relativePath, filename);
|
||||||
|
|
||||||
UploadMediaFile(relativePath, uniqueFilename, stream);
|
UploadMediaFile(relativePath, uniqueFilename, stream);
|
||||||
return ImportMedia(relativePath, uniqueFilename);
|
return ImportMedia(relativePath, uniqueFilename, contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetUniqueFilename(string folderPath, string filename) {
|
public string GetUniqueFilename(string folderPath, string filename) {
|
||||||
@ -123,6 +131,10 @@ namespace Orchard.MediaLibrary.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MediaPart ImportMedia(string relativePath, string filename) {
|
public MediaPart ImportMedia(string relativePath, string filename) {
|
||||||
|
return ImportMedia(relativePath, filename, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaPart ImportMedia(string relativePath, string filename, string contentType) {
|
||||||
|
|
||||||
var mimeType = _mimeTypeProvider.GetMimeType(filename);
|
var mimeType = _mimeTypeProvider.GetMimeType(filename);
|
||||||
|
|
||||||
@ -134,21 +146,20 @@ namespace Orchard.MediaLibrary.Services {
|
|||||||
var mediaFile = BuildMediaFile(relativePath, storageFile);
|
var mediaFile = BuildMediaFile(relativePath, storageFile);
|
||||||
|
|
||||||
using (var stream = storageFile.OpenRead()) {
|
using (var stream = storageFile.OpenRead()) {
|
||||||
var mediaFactory = GetMediaFactory(stream, mimeType);
|
var mediaFactory = GetMediaFactory(stream, mimeType, contentType);
|
||||||
var mediaPart = mediaFactory.CreateMedia(stream, mediaFile.Name, mimeType);
|
var mediaPart = mediaFactory.CreateMedia(stream, mediaFile.Name, mimeType, contentType);
|
||||||
if (mediaPart != null) {
|
if (mediaPart != null) {
|
||||||
mediaPart.FolderPath = relativePath;
|
mediaPart.FolderPath = relativePath;
|
||||||
mediaPart.FileName = filename;
|
mediaPart.FileName = filename;
|
||||||
_orchardServices.ContentManager.Create(mediaPart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mediaPart;
|
return mediaPart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMediaFactory GetMediaFactory(Stream stream, string mimeType) {
|
public IMediaFactory GetMediaFactory(Stream stream, string mimeType, string contentType) {
|
||||||
var requestMediaFactoryResults = _mediaFactorySelectors
|
var requestMediaFactoryResults = _mediaFactorySelectors
|
||||||
.Select(x => x.GetMediaFactory(stream, mimeType))
|
.Select(x => x.GetMediaFactory(stream, mimeType, contentType))
|
||||||
.Where(x => x != null)
|
.Where(x => x != null)
|
||||||
.OrderByDescending(x => x.Priority);
|
.OrderByDescending(x => x.Priority);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using Orchard.ContentManagement;
|
using System;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
using Orchard.DisplayManagement.Descriptors;
|
using Orchard.DisplayManagement.Descriptors;
|
||||||
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.Services {
|
namespace Orchard.MediaLibrary.Services {
|
||||||
public class Shapes : IShapeTableProvider {
|
public class Shapes : IShapeTableProvider {
|
||||||
@ -12,16 +14,30 @@ namespace Orchard.MediaLibrary.Services {
|
|||||||
// Display type > content type > specific content > display type for a content type > display type for specific content
|
// Display type > content type > specific content > display type for a content type > display type for specific content
|
||||||
// BasicShapeTemplateHarvester.Adjust will then adjust the template name
|
// BasicShapeTemplateHarvester.Adjust will then adjust the template name
|
||||||
|
|
||||||
|
var mediaPart = contentItem.As<MediaPart>();
|
||||||
|
|
||||||
// Media__[DisplayType] e.g. Media-Summary
|
// Media__[DisplayType] e.g. Media-Summary
|
||||||
displaying.ShapeMetadata.Alternates.Add("Media_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType));
|
displaying.ShapeMetadata.Alternates.Add("Media_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType));
|
||||||
|
|
||||||
// Media__[ContentType] e.g. Media-BlogPost,
|
if (!String.IsNullOrEmpty(mediaPart.LogicalType)) {
|
||||||
|
|
||||||
|
// Media__[LogicalType] e.g. Media-Image,
|
||||||
|
displaying.ShapeMetadata.Alternates.Add("Media__" + EncodeAlternateElement(mediaPart.LogicalType));
|
||||||
|
|
||||||
|
// Media__[Id] e.g. Media-42,
|
||||||
|
displaying.ShapeMetadata.Alternates.Add("Media__" + contentItem.Id);
|
||||||
|
|
||||||
|
// Media_[DisplayType]__[LogicalType] e.g. Media-Image.Summary
|
||||||
|
displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(mediaPart.LogicalType));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Media__[ContentType] e.g. Media-ProductImage,
|
||||||
displaying.ShapeMetadata.Alternates.Add("Media__" + EncodeAlternateElement(contentItem.ContentType));
|
displaying.ShapeMetadata.Alternates.Add("Media__" + EncodeAlternateElement(contentItem.ContentType));
|
||||||
|
|
||||||
// Media__[Id] e.g. Media-42,
|
// Media__[Id] e.g. Media-42,
|
||||||
displaying.ShapeMetadata.Alternates.Add("Media__" + contentItem.Id);
|
displaying.ShapeMetadata.Alternates.Add("Media__" + contentItem.Id);
|
||||||
|
|
||||||
// Media_[DisplayType]__[ContentType] e.g. Media-Image.Summary
|
// Media_[DisplayType]__[ContentType] e.g. Media-ProductImage.Summary
|
||||||
displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));
|
displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));
|
||||||
|
|
||||||
// Media_[DisplayType]__[Id] e.g. Media-42.Summary
|
// Media_[DisplayType]__[Id] e.g. Media-42.Summary
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace Orchard.MediaLibrary.ViewModels {
|
||||||
|
public class ImportMediaViewModel {
|
||||||
|
public string FolderPath { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.UI.Navigation;
|
using Orchard.UI.Navigation;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.ViewModels {
|
namespace Orchard.MediaLibrary.ViewModels {
|
||||||
@ -6,5 +7,6 @@ namespace Orchard.MediaLibrary.ViewModels {
|
|||||||
public IEnumerable<MenuItem> Menu { get; set; }
|
public IEnumerable<MenuItem> Menu { get; set; }
|
||||||
public IEnumerable<string> ImageSets { get; set; }
|
public IEnumerable<string> ImageSets { get; set; }
|
||||||
public string FolderPath { get; set; }
|
public string FolderPath { get; set; }
|
||||||
|
public IEnumerable<ContentTypeDefinition> MediaTypes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.MediaLibrary.Models;
|
using Orchard.MediaLibrary.Models;
|
||||||
|
|
||||||
namespace Orchard.MediaLibrary.ViewModels {
|
namespace Orchard.MediaLibrary.ViewModels {
|
||||||
@ -6,7 +7,7 @@ namespace Orchard.MediaLibrary.ViewModels {
|
|||||||
public IEnumerable<FolderHierarchy> Folders { get; set; }
|
public IEnumerable<FolderHierarchy> Folders { get; set; }
|
||||||
public string FolderPath { get; set; }
|
public string FolderPath { get; set; }
|
||||||
public bool DialogMode { get; set; }
|
public bool DialogMode { get; set; }
|
||||||
public string[] MediaTypes { get; set; }
|
public IEnumerable<ContentTypeDefinition> MediaTypes { get; set; }
|
||||||
public dynamic CustomActionsShapes { get; set; }
|
public dynamic CustomActionsShapes { get; set; }
|
||||||
public dynamic CustomNavigationShapes { get; set; }
|
public dynamic CustomNavigationShapes { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@ namespace Orchard.MediaLibrary.ViewModels {
|
|||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public XDocument Content { get; set; }
|
public XDocument Content { get; set; }
|
||||||
public bool Success { get; set; }
|
public bool Success { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,10 +19,20 @@
|
|||||||
<div id="media-library-toolbar">
|
<div id="media-library-toolbar">
|
||||||
|
|
||||||
<div id="media-library-toolbar-actions">
|
<div id="media-library-toolbar-actions">
|
||||||
|
|
||||||
|
<label for="filterMediaType">@T("Create")</label>
|
||||||
|
<select id="filterMediaType" name="FilteredMediaType">
|
||||||
|
@Html.SelectOption("", true, T("Any").ToString())
|
||||||
|
@foreach (var mediaType in Model.MediaTypes) {
|
||||||
|
@Html.SelectOption(mediaType.Name, false, mediaType.DisplayName)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
|
||||||
<a href="@Url.Action("Index", "Admin", new { folderPath = Model.FolderPath})" class="button">@T("Close")</a>
|
<a href="@Url.Action("Index", "Admin", new { folderPath = Model.FolderPath})" class="button">@T("Close")</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@T("Media Folders") @foreach (var folder in Model.FolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries)) {<text> > </text>@folder}
|
@T("Media Folders") @foreach (var folder in Model.FolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries)) {<text> > </text>@folder}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -44,19 +54,43 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@using (Script.Foot()) {
|
@using (Script.Foot()) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
$(function () {
|
$(function() {
|
||||||
$("#media-library-main-navigation a").click(function () {
|
$("#media-library-main-navigation a").click(function() {
|
||||||
var self = $(this);
|
var self = $(this);
|
||||||
$("#media-library-main-list-frame").attr("src", self.attr("href"));
|
var href = replaceQueryString(self.attr("href"), "type", getMediaType());
|
||||||
|
$("#media-library-main-list-frame").attr("src", href);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
})
|
|
||||||
|
$("#filterMediaType").change(function() {
|
||||||
|
var href = $("#media-library-main-list-frame").attr("src");
|
||||||
|
href = replaceQueryString(href, 'type', getMediaType());
|
||||||
|
$("#media-library-main-list-frame").attr("src", href);
|
||||||
|
});
|
||||||
|
|
||||||
|
// loads the first available link
|
||||||
|
$("#media-library-main-navigation a").first().click();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// returns the currently selected preferred media type
|
||||||
|
function getMediaType() {
|
||||||
|
return $('#filterMediaType').find("option:selected").attr('value');
|
||||||
|
}
|
||||||
|
|
||||||
|
// replaces a specific query parameter in the given url
|
||||||
|
function replaceQueryString(url, param, value) {
|
||||||
|
value = encodeURIComponent(value);
|
||||||
|
var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
|
||||||
|
if (url.match(re))
|
||||||
|
return url.replace(re, '$1' + param + "=" + value + '$2');
|
||||||
|
else
|
||||||
|
return url + '&' + param + "=" + value;
|
||||||
|
}
|
||||||
|
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
@using System.Text
|
@model Orchard.MediaLibrary.ViewModels.ImportMediaViewModel
|
||||||
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
@ -87,7 +87,8 @@
|
|||||||
url: '@Url.Action("Upload", "ClientStorage")',
|
url: '@Url.Action("Upload", "ClientStorage")',
|
||||||
autoUpload: true,
|
autoUpload: true,
|
||||||
formData: {
|
formData: {
|
||||||
folderPath: '@HttpUtility.JavaScriptStringEncode(Model)',
|
folderPath: '@HttpUtility.JavaScriptStringEncode(Model.FolderPath)',
|
||||||
|
type: '@HttpUtility.JavaScriptStringEncode(Model.Type)',
|
||||||
__RequestVerificationToken: '@Html.AntiForgeryTokenValueOrchard()'
|
__RequestVerificationToken: '@Html.AntiForgeryTokenValueOrchard()'
|
||||||
},
|
},
|
||||||
done: function (e, data) {
|
done: function (e, data) {
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
using (Html.BeginFormAntiForgeryPost(Url.Action("MediaPost"))) {
|
using (Html.BeginFormAntiForgeryPost(Url.Action("MediaPost"))) {
|
||||||
@Html.Hidden("url", Model.Url)
|
@Html.Hidden("url", Model.Url)
|
||||||
@Html.Hidden("folderPath", Model.FolderPath)
|
@Html.Hidden("folderPath", Model.FolderPath)
|
||||||
|
@Html.Hidden("type", Model.Type)
|
||||||
@Html.Hidden("document", Model.Content.ToString())
|
@Html.Hidden("document", Model.Content.ToString())
|
||||||
|
|
||||||
<button type="submit">@("Import")</button>
|
<button type="submit">@("Import")</button>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<select id="filterMediaType" name="FilteredMediaType" data-bind="selectedOptions: mediaType">
|
<select id="filterMediaType" name="FilteredMediaType" data-bind="selectedOptions: mediaType">
|
||||||
@Html.SelectOption("", true, T("Any (show all)").ToString())
|
@Html.SelectOption("", true, T("Any (show all)").ToString())
|
||||||
@foreach (var mediaType in viewModel.MediaTypes) {
|
@foreach (var mediaType in viewModel.MediaTypes) {
|
||||||
@Html.SelectOption(mediaType, false, mediaType)
|
@Html.SelectOption(mediaType.Name, false, mediaType.DisplayName)
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
@using System.Text
|
@model Orchard.MediaLibrary.ViewModels.ImportMediaViewModel
|
||||||
|
|
||||||
|
@using System.Text
|
||||||
@using Orchard.ContentManagement
|
@using Orchard.ContentManagement
|
||||||
@using Orchard.MediaLibrary.Models
|
@using Orchard.MediaLibrary.Models
|
||||||
|
|
||||||
@ -83,7 +85,8 @@
|
|||||||
|
|
||||||
@Html.Hidden("antiforgerytoken", Html.AntiForgeryTokenValueOrchard())
|
@Html.Hidden("antiforgerytoken", Html.AntiForgeryTokenValueOrchard())
|
||||||
@Html.Hidden("action", Url.Action("ImagePost"))
|
@Html.Hidden("action", Url.Action("ImagePost"))
|
||||||
@Html.Hidden("folderPath", (string)Model)
|
@Html.Hidden("folderPath", Model.FolderPath)
|
||||||
|
@Html.Hidden("type", Model.Type)
|
||||||
|
|
||||||
@using(Script.Foot()) {
|
@using(Script.Foot()) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -209,6 +212,7 @@
|
|||||||
$("#button-import").on("click", function (e) {
|
$("#button-import").on("click", function (e) {
|
||||||
var antiForgeryToken = $('[name=antiforgerytoken]').val();
|
var antiForgeryToken = $('[name=antiforgerytoken]').val();
|
||||||
var folderPath = $('[name=folderPath]').val();
|
var folderPath = $('[name=folderPath]').val();
|
||||||
|
var type = $('[name=type]').val();
|
||||||
var action = $('[name=action]').val();
|
var action = $('[name=action]').val();
|
||||||
|
|
||||||
viewModel.selection().forEach(function (item) {
|
viewModel.selection().forEach(function (item) {
|
||||||
@ -216,6 +220,7 @@
|
|||||||
item.status('uploading');
|
item.status('uploading');
|
||||||
$.post(action, {
|
$.post(action, {
|
||||||
folderPath: folderPath,
|
folderPath: folderPath,
|
||||||
|
type: type,
|
||||||
url: url,
|
url: url,
|
||||||
__RequestVerificationToken: antiForgeryToken,
|
__RequestVerificationToken: antiForgeryToken,
|
||||||
})
|
})
|
||||||
|
@ -157,7 +157,9 @@ namespace Upgrade.Controllers {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
//_orchardServices.Notifier.Information(T("Importing {0}.", mediaFile.MediaPath));
|
//_orchardServices.Notifier.Information(T("Importing {0}.", mediaFile.MediaPath));
|
||||||
return _mediaLibraryService.ImportMedia(folderName, fileName);
|
var media = _mediaLibraryService.ImportMedia(folderName, fileName);
|
||||||
|
_orchardServices.ContentManager.Create(media);
|
||||||
|
return media;
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
_orchardServices.Notifier.Error(T("Error while importing {0}. Please check the logs", folderName + "/" + fileName));
|
_orchardServices.Notifier.Error(T("Error while importing {0}. Please check the logs", folderName + "/" + fileName));
|
||||||
|
Loading…
Reference in New Issue
Block a user