From 2889d29498e9c7b3c053104294c44a12f381ebba Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 2 Jul 2013 18:10:43 -0700 Subject: [PATCH] Refactoring the Media Library - Removed dependency on Orchard.Taxonomies - Removed dependency on Orchard.Media You will need to remove the Orchard_MediaLibrary tables and also the Data Migration record corresponding to this module if you want to upgrade from 1.x. You can also apply the database changes by hand, remove all the records then use the Upgrade module to import all media. --HG-- branch : 1.x extra : rebase_source : 46100428d9546c3082bf65ce85d8d891543dc0a9 --- .../Media/AzureBlobStorageProvider.cs | 2 +- .../Media/Services/MediaServiceTests.cs | 4 + .../Controllers/AdminController.cs | 38 +- .../Views/Content-ImageEditor.cshtml | 4 +- .../Views/Parts/Image.Editor.cshtml | 2 +- .../Orchard.Media/Services/IMediaService.cs | 8 + .../Orchard.Media/Services/MediaService.cs | 14 + .../Modules/Orchard.MediaLibrary/AdminMenu.cs | 2 +- .../Controllers/AdminController.cs | 29 +- .../Controllers/ClientStorageController.cs | 15 +- .../Controllers/FolderController.cs | 46 ++- .../Controllers/OEmbedController.cs | 28 +- .../Controllers/WebSearchController.cs | 13 +- .../Factories/AudioFactory.cs | 24 +- .../Factories/DocumentFactory.cs | 25 +- .../Factories/IMediaFactory.cs | 1 - .../Factories/ImageFactory.cs | 25 +- .../Factories/VideoFactory.cs | 29 +- .../Handlers/MediaPartHandler.cs | 27 +- .../Orchard.MediaLibrary/Migrations.cs | 30 +- .../Models/FolderHierarchy.cs | 13 + .../Orchard.MediaLibrary/Models/MediaFile.cs | 13 + .../Models/MediaFolder.cs | 14 +- .../Orchard.MediaLibrary/Models/MediaPart.cs | 46 ++- .../Models/MediaPartRecord.cs | 5 +- .../Modules/Orchard.MediaLibrary/Module.txt | 2 +- .../Orchard.MediaLibrary.csproj | 14 +- .../Services/IMediaLibraryService.cs | 128 +++++-- .../Services/MediaLibraryService.cs | 357 ++++++++++++------ .../Styles/Images/menu.media.png | Bin 0 -> 360 bytes .../Styles/menu.media-library-admin.css | 6 + .../MediaManagerFolderCreateViewModel.cs | 2 +- .../MediaManagerFolderEditViewModel.cs | 2 +- .../ViewModels/MediaManagerImportViewModel.cs | 3 +- .../ViewModels/MediaManagerIndexViewModel.cs | 5 +- .../ViewModels/OEmbedViewModel.cs | 2 +- .../Views/Admin/Import.cshtml | 6 +- .../Views/Admin/Index.cshtml | 40 +- .../Views/Admin/MediaItems.cshtml | 2 +- .../Views/Admin/MediaManagerFolder.cshtml | 10 +- .../Views/ClientStorage/Index.cshtml | 2 +- .../Views/Folder/Create.cshtml | 15 +- .../Views/Media-Image.Thumbnail.cshtml | 2 +- .../Views/OEmbed/Index.cshtml | 5 +- .../Views/Parts/Audio.Summary.cshtml | 2 +- .../Views/Parts/Audio.SummaryAdmin.cshtml | 2 +- .../Views/Parts/Audio.cshtml | 2 +- .../Views/Parts/Document.Summary.cshtml | 2 +- .../Views/Parts/Document.SummaryAdmin.cshtml | 2 +- .../Views/Parts/Document.cshtml | 2 +- .../Views/Parts/Image.Summary.cshtml | 4 +- .../Views/Parts/Image.SummaryAdmin.cshtml | 2 +- .../Views/Parts/Image.cshtml | 2 +- .../Views/Parts/Media.SummaryAdmin.cshtml | 2 +- .../Views/Parts/OEmbed.Summary.cshtml | 2 +- .../Views/Parts/OEmbed.SummaryAdmin.cshtml | 2 +- .../Views/Parts/Video.Summary.cshtml | 2 +- .../Views/Parts/Video.SummaryAdmin.cshtml | 2 +- .../Views/Parts/Video.cshtml | 2 +- .../Views/WebSearch/Index.cshtml | 3 +- .../Orchard.MediaProcessing/Module.txt | 2 +- .../Orchard.MediaProcessing.csproj | 4 - .../Shapes/MediaShapes.cs | 91 ++--- .../Upgrade/Controllers/MediaController.cs | 73 +--- .../Modules/Upgrade/Upgrade.csproj | 4 - .../Media/FileSystemStorageProvider.cs | 32 +- .../FileSystems/Media/IStorageProvider.cs | 14 +- 67 files changed, 669 insertions(+), 646 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/FolderHierarchy.cs create mode 100644 src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFile.cs create mode 100644 src/Orchard.Web/Modules/Orchard.MediaLibrary/Styles/Images/menu.media.png create mode 100644 src/Orchard.Web/Modules/Orchard.MediaLibrary/Styles/menu.media-library-admin.css diff --git a/src/Orchard.Azure/FileSystems/Media/AzureBlobStorageProvider.cs b/src/Orchard.Azure/FileSystems/Media/AzureBlobStorageProvider.cs index 783ca8fb6..4a6162aaa 100644 --- a/src/Orchard.Azure/FileSystems/Media/AzureBlobStorageProvider.cs +++ b/src/Orchard.Azure/FileSystems/Media/AzureBlobStorageProvider.cs @@ -44,7 +44,7 @@ namespace Orchard.Azure.FileSystems.Media { /// /// The public url of the media. /// The local path. - public string GetLocalPath(string url) { + public string GetStoragePath(string url) { if (url.StartsWith(_absoluteRoot)) { return url.Substring(_absoluteRoot.Length); } diff --git a/src/Orchard.Tests.Modules/Media/Services/MediaServiceTests.cs b/src/Orchard.Tests.Modules/Media/Services/MediaServiceTests.cs index 51479fbbb..9cb0cf14a 100644 --- a/src/Orchard.Tests.Modules/Media/Services/MediaServiceTests.cs +++ b/src/Orchard.Tests.Modules/Media/Services/MediaServiceTests.cs @@ -218,6 +218,10 @@ namespace Orchard.Tests.Modules.Media.Services { return FileSystemStorageProvider.GetPublicUrl(path); } + public string GetStoragePath(string url) { + throw new NotImplementedException(); + } + public IStorageFile GetFile(string path) { throw new NotImplementedException(); } diff --git a/src/Orchard.Web/Modules/Orchard.ImageEditor/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ImageEditor/Controllers/AdminController.cs index 38d66ad5f..c66960bae 100644 --- a/src/Orchard.Web/Modules/Orchard.ImageEditor/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ImageEditor/Controllers/AdminController.cs @@ -3,9 +3,9 @@ using System.IO; using System.Linq; using System.Web.Mvc; using Orchard.ContentManagement; -using Orchard.FileSystems.Media; using Orchard.ImageEditor.Models; using Orchard.MediaLibrary.Models; +using Orchard.MediaLibrary.Services; using Orchard.Mvc; using Orchard.Themes; using Orchard.UI.Admin; @@ -13,10 +13,10 @@ using Orchard.UI.Admin; namespace Orchard.ImageEditor.Controllers { [Admin] public class AdminController : Controller { - private readonly IStorageProvider _storageProvider; + private readonly IMediaLibraryService _mediaLibraryService; - public AdminController(IOrchardServices orchardServices, IStorageProvider storageProvider) { - _storageProvider = storageProvider; + public AdminController(IOrchardServices orchardServices, IMediaLibraryService mediaLibraryService) { + _mediaLibraryService = mediaLibraryService; Services = orchardServices; } @@ -41,27 +41,8 @@ namespace Orchard.ImageEditor.Controllers { } [Themed(false)] - public ActionResult Touch(string src) { - var localPath = _storageProvider.GetLocalPath(src); - - if (_storageProvider.GetFile(localPath) == null) { - return HttpNotFound(); - } - - var media = Services.ContentManager.Query().Where(x => x.Resource == src).Slice(0, 1).FirstOrDefault(); - - return Json(media != null); - } - - [Themed(false)] - public ActionResult Edit(string src) { - var localPath = _storageProvider.GetLocalPath(src); - - if (_storageProvider.GetFile(localPath) == null) { - return HttpNotFound(); - } - - var media = Services.ContentManager.Query().Where(x => x.Resource == src).Slice(0, 1).FirstOrDefault(); + public ActionResult Edit(string folderPath, string filename) { + var media = Services.ContentManager.Query().Where(x => x.FolderPath == folderPath && x.FileName == filename).Slice(0, 1).FirstOrDefault(); if (media == null) { return HttpNotFound(); @@ -97,10 +78,11 @@ namespace Orchard.ImageEditor.Controllers { content = content.Substring(signature.Length); var buffer = Convert.FromBase64String(content); - var localPath = _storageProvider.GetLocalPath(media.Resource); - _storageProvider.DeleteFile(localPath); + + _mediaLibraryService.DeleteFile(media.FolderPath, media.FileName); + using (var stream = new MemoryStream(buffer)) { - _storageProvider.SaveStream(localPath, stream); + _mediaLibraryService.UploadMediaFile(media.FolderPath, media.FileName, stream); } image.Width = width; diff --git a/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Content-ImageEditor.cshtml b/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Content-ImageEditor.cshtml index 65dbb9a4a..94e371d13 100644 --- a/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Content-ImageEditor.cshtml +++ b/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Content-ImageEditor.cshtml @@ -19,7 +19,7 @@ } } - +
@@ -41,7 +41,7 @@
@**@ - +
diff --git a/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Parts/Image.Editor.cshtml b/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Parts/Image.Editor.cshtml index 4b0cf3cf6..f087eff9a 100644 --- a/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Parts/Image.Editor.cshtml +++ b/src/Orchard.Web/Modules/Orchard.ImageEditor/Views/Parts/Image.Editor.cshtml @@ -4,7 +4,7 @@ ImagePart imagePart = Model.ContentPart; // do not show the editor if the image is not local - if (!imagePart.As().Resource.StartsWith("~/")) { + if (String.IsNullOrEmpty(imagePart.As().MediaPath)) { return; } } diff --git a/src/Orchard.Web/Modules/Orchard.Media/Services/IMediaService.cs b/src/Orchard.Web/Modules/Orchard.Media/Services/IMediaService.cs index bfc6a5f50..d0e3624cf 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Services/IMediaService.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Services/IMediaService.cs @@ -73,6 +73,14 @@ namespace Orchard.Media.Services { /// The new file name. void RenameFile(string folderPath, string currentFileName, string newFileName); + /// + /// Moves a media file. + /// + /// The file name. + /// The path to the file's parent folder. + /// The path where the file will be moved to. + void MoveFile(string fileName, string currentPath, string newPath); + /// /// Uploads a media file based on a posted file. /// diff --git a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs index e85d61004..c4a0720eb 100644 --- a/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs +++ b/src/Orchard.Web/Modules/Orchard.Media/Services/MediaService.cs @@ -160,6 +160,20 @@ namespace Orchard.Media.Services { _storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName)); } + /// + /// Moves a media file. + /// + /// The file name. + /// The path to the file's parent folder. + /// The path where the file will be moved to. + public void MoveFile(string fileName, string currentPath, string newPath) { + Argument.ThrowIfNullOrEmpty(currentPath, "currentPath"); + Argument.ThrowIfNullOrEmpty(newPath, "newPath"); + Argument.ThrowIfNullOrEmpty(fileName, "fileName"); + + _storageProvider.RenameFile(_storageProvider.Combine(currentPath, fileName), _storageProvider.Combine(newPath, fileName)); + } + /// /// Uploads a media file based on a posted file. /// diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/AdminMenu.cs index 3e7f759a5..9125466f7 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/AdminMenu.cs @@ -12,7 +12,7 @@ namespace Orchard.MediaLibrary { public string MenuName { get { return "admin"; } } public void GetNavigation(NavigationBuilder builder) { - builder.AddImageSet("media") + builder.AddImageSet("media-library") .Add(T("Media"), "6", menu => menu.Add(T("Media"), "0", item => item.Action("Index", "Admin", new { area = "Orchard.MediaLibrary", id = (int?)null }) .Permission(Permissions.ManageMediaContent))); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/AdminController.cs index c1669bdea..2d7471f19 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/AdminController.cs @@ -10,9 +10,9 @@ using Orchard.MediaLibrary.ViewModels; using Orchard.Mvc; using Orchard.Themes; using Orchard.UI.Navigation; -using Orchard.Utility.Extensions; using Orchard.ContentManagement.MetaData; using System.Collections.Generic; +using Orchard.Validation; namespace Orchard.MediaLibrary.Controllers { [ValidateInput(false)] @@ -39,46 +39,42 @@ namespace Orchard.MediaLibrary.Controllers { public Localizer T { get; set; } public ILogger Logger { get; set; } - public ActionResult Index(int? id, bool dialog = false) { - string stereotype; + public ActionResult Index(string folderPath = "", bool dialog = false) { var mediaTypes = new List(); foreach(var contentTypeDefinition in _contentDefinitionManager.ListTypeDefinitions()) { + string stereotype; if (contentTypeDefinition.Settings.TryGetValue("Stereotype", out stereotype) && stereotype == "Media") mediaTypes.Add(contentTypeDefinition.Name); } var viewModel = new MediaManagerIndexViewModel { DialogMode = dialog, - Folders = _mediaLibraryService.GetMediaFolders(), - Folder = id, - Hierarchy = id.HasValue ? _mediaLibraryService.GetMediaFolderHierarchy(id.Value) : Enumerable.Empty(), + Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy), + FolderPath = folderPath, MediaTypes = mediaTypes.ToArray() }; return View(viewModel); } - public ActionResult Import(int id) { + public ActionResult Import(string folderPath) { var mediaProviderMenu = _navigationManager.BuildMenu("mediaproviders"); var imageSets = _navigationManager.BuildImageSets("mediaproviders"); - var hierarchy = _mediaLibraryService.GetMediaFolderHierarchy(id); - - var viewModel = new MediaManagerImportViewModel { Menu = mediaProviderMenu, - Hierarchy = hierarchy.ToReadOnlyCollection(), ImageSets = imageSets, + FolderPath = folderPath }; return View(viewModel); } [Themed(false)] - public ActionResult MediaItems(int id, int skip = 0, int count = 0, string order = "created", string mediaType = "") { - var mediaParts = _mediaLibraryService.GetMediaContentItems(id, skip, count, order, mediaType); - var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(id, mediaType); + public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "") { + var mediaParts = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType); + var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType); var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel { MediaPart = x, @@ -145,5 +141,10 @@ namespace Orchard.MediaLibrary.Controllers { return Json(false); } } + + private FolderHierarchy GetFolderHierarchy(MediaFolder root) { + Argument.ThrowIfNull(root, "root"); + return new FolderHierarchy(root) {Children = _mediaLibraryService.GetMediaFolders(root.MediaPath).Select(GetFolderHierarchy)}; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs index f764c6741..b2511f523 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Web.Mvc; using Orchard.MediaLibrary.Services; @@ -15,13 +14,13 @@ namespace Orchard.MediaLibrary.Controllers { _mediaLibraryService = mediaManagerService; } - public ActionResult Index(int id) { + public ActionResult Index(string folderPath) { - return View(id); + return View((object)folderPath); } [HttpPost] - public ActionResult Upload(int id) { + public ActionResult Upload(string folderPath) { var statuses = new List(); // Loop through each file in the request @@ -34,8 +33,8 @@ namespace Orchard.MediaLibrary.Controllers { if (filename == "blob") { filename = "clipboard.png"; } - - var mediaPart = _mediaLibraryService.ImportStream(id, file.InputStream, filename); + + var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename); statuses.Add(new { id = mediaPart.Id, @@ -43,7 +42,7 @@ namespace Orchard.MediaLibrary.Controllers { type = mediaPart.MimeType, size = file.ContentLength, progress = 1.0, - url= mediaPart.Resource, + url= mediaPart.FileName, }); } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/FolderController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/FolderController.cs index 57b819574..740dd0244 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/FolderController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/FolderController.cs @@ -15,7 +15,10 @@ namespace Orchard.MediaLibrary.Controllers { public class FolderController : Controller { private readonly IMediaLibraryService _mediaLibraryService; - public FolderController(IOrchardServices services, IMediaLibraryService mediaManagerService) { + public FolderController( + IOrchardServices services, + IMediaLibraryService mediaManagerService + ) { _mediaLibraryService = mediaManagerService; Services = services; @@ -27,13 +30,13 @@ namespace Orchard.MediaLibrary.Controllers { public ILogger Logger { get; set; } public Localizer T { get; set; } - public ActionResult Create(int? id) { + public ActionResult Create(string folderPath) { if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't create media folder"))) return new HttpUnauthorizedResult(); var viewModel = new MediaManagerFolderCreateViewModel { - Hierarchy = id.HasValue ? _mediaLibraryService.GetMediaFolderHierarchy(id.Value) : Enumerable.Empty(), - ParentFolderId = id + Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath), + FolderPath = folderPath }; return View(viewModel); @@ -48,7 +51,7 @@ namespace Orchard.MediaLibrary.Controllers { UpdateModel(viewModel); try { - _mediaLibraryService.CreateFolder(viewModel.ParentFolderId, viewModel.Name); + _mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name); Services.Notifier.Information(T("Media folder created")); } catch (ArgumentException argumentException) { @@ -61,16 +64,14 @@ namespace Orchard.MediaLibrary.Controllers { } - public ActionResult Edit(int id) { + public ActionResult Edit(string folderPath) { if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't edit media folder"))) return new HttpUnauthorizedResult(); - - var folder = _mediaLibraryService.GetMediaFolder(id); - + var viewModel = new MediaManagerFolderEditViewModel { - Hierarchy = _mediaLibraryService.GetMediaFolderHierarchy(id), - FolderId = id, - Name = folder.Name + Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath), + FolderPath = folderPath, + Name = folderPath.Split('/').LastOrDefault() }; return View(viewModel); @@ -86,7 +87,7 @@ namespace Orchard.MediaLibrary.Controllers { UpdateModel(viewModel); try { - _mediaLibraryService.RenameFolder(viewModel.FolderId, viewModel.Name); + _mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name); Services.Notifier.Information(T("Media folder renamed")); } catch (ArgumentException argumentException) { @@ -108,7 +109,7 @@ namespace Orchard.MediaLibrary.Controllers { UpdateModel(viewModel); try { - _mediaLibraryService.DeleteFolder(viewModel.FolderId); + _mediaLibraryService.DeleteFolder(viewModel.FolderPath); Services.Notifier.Information(T("Media folder deleted")); } catch (ArgumentException argumentException) { @@ -121,22 +122,17 @@ namespace Orchard.MediaLibrary.Controllers { } [HttpPost] - public ActionResult Move(int targetId, int[] mediaItemIds) { + public ActionResult Move(string folderPath, int[] mediaItemIds) { if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't move media items"))) return new HttpUnauthorizedResult(); - var targetFolder = _mediaLibraryService.GetMediaFolder(targetId); - - if (targetFolder == null) { - return Json(false); + foreach (var media in Services.ContentManager.Query().ForPart().ForContentItems(mediaItemIds).List()) { + var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName); + _mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename); + media.FolderPath = folderPath; + media.FileName = uniqueFilename; } - if (mediaItemIds == null || mediaItemIds.Length == 0) { - return Json(false); - } - - _mediaLibraryService.MoveMedia(targetId, mediaItemIds); - return Json(true); } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/OEmbedController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/OEmbedController.cs index c0d1ef3ab..6a6993409 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/OEmbedController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/OEmbedController.cs @@ -6,7 +6,6 @@ using System.Xml.Linq; using Orchard.MediaLibrary.Models; using Orchard.MediaLibrary.Services; using Orchard.MediaLibrary.ViewModels; -using Orchard.Taxonomies.Services; using Orchard.Themes; using Orchard.UI.Admin; using Orchard.ContentManagement; @@ -14,30 +13,30 @@ using Orchard.ContentManagement; namespace Orchard.MediaLibrary.Controllers { [Admin, Themed(false)] public class OEmbedController : Controller { - private readonly ITaxonomyService _taxonomyService; private readonly IMediaLibraryService _mediaLibraryService; public OEmbedController( - ITaxonomyService taxonomyService, IMediaLibraryService mediaManagerService, IOrchardServices services) { - _taxonomyService = taxonomyService; _mediaLibraryService = mediaManagerService; Services = services; } public IOrchardServices Services { get; set; } - public ActionResult Index(int id) { - var viewModel = new OEmbedViewModel(); + public ActionResult Index(string folderPath) { + var viewModel = new OEmbedViewModel { + FolderPath = folderPath + }; + return View(viewModel); } [HttpPost] - public ActionResult Index(int id, string url) { + public ActionResult Index(string folderPath, string url) { var viewModel = new OEmbedViewModel { Url = url, - Id = id + FolderPath = folderPath }; try { @@ -72,20 +71,13 @@ namespace Orchard.MediaLibrary.Controllers { } [HttpPost, ValidateInput(false)] - public ActionResult MediaPost(int id, string url, string document) { - var termPart = _taxonomyService.GetTerm(id); - - if (termPart == null) { - return HttpNotFound(); - } - + public ActionResult MediaPost(string folderPath, string url, string document) { var content = XDocument.Parse(document); var oembed = content.Root; var part = Services.ContentManager.New("OEmbed"); - part.TermPart = _taxonomyService.GetTerm(id); - part.Resource = url; + part.FileName = url; part.MimeType = "text/html"; part.Title = oembed.Element("title").Value; if (oembed.Element("description") != null) { @@ -101,7 +93,7 @@ namespace Orchard.MediaLibrary.Controllers { Services.ContentManager.Create(oembedPart); var viewModel = new OEmbedViewModel { - Id = id + FolderPath = folderPath }; return View("Index", viewModel); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/WebSearchController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/WebSearchController.cs index 1c171136e..87ac76ce4 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/WebSearchController.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/WebSearchController.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; -using System.Web; using System.Web.Mvc; using Orchard.MediaLibrary.Services; using Orchard.Themes; @@ -18,22 +15,22 @@ namespace Orchard.MediaLibrary.Controllers { _mediaLibraryService = mediaManagerService; } - public ActionResult Index(int id) { + public ActionResult Index(string folderPath) { - return View(id); + return View((object)folderPath); } [HttpPost] - public JsonResult ImagePost(int id, string url) { + public JsonResult ImagePost(string folderPath, string url) { try { var buffer = new WebClient().DownloadData(url); var stream = new MemoryStream(buffer); - var mediaPart = _mediaLibraryService.ImportStream(id, stream, Path.GetFileName(url)); + var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url)); return new JsonResult { - Data = new {id, mediaPart.Resource} + Data = new {folderPath, MediaPath = mediaPart.FileName} }; } catch(Exception e) { diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/AudioFactory.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/AudioFactory.cs index 5e9ca8c65..f300c4f80 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/AudioFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/AudioFactory.cs @@ -1,17 +1,14 @@ using System.IO; using Orchard.ContentManagement; -using Orchard.FileSystems.Media; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Factories { public class AudioFactorySelector : IMediaFactorySelector { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public AudioFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) { + public AudioFactorySelector(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) { @@ -21,7 +18,7 @@ namespace Orchard.MediaLibrary.Factories { return new MediaFactorySelectorResult { Priority = -5, - MediaFactory = new AudioFactory(_contentManager, _storageProvider) + MediaFactory = new AudioFactory(_contentManager) }; } @@ -29,31 +26,16 @@ namespace Orchard.MediaLibrary.Factories { public class AudioFactory : IMediaFactory { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; public const string BaseFolder = "Audio"; - public AudioFactory(IContentManager contentManager, IStorageProvider storageProvider) { + public AudioFactory(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaPart CreateMedia(Stream stream, string path, string mimeType) { - var uniquePath = path; - var index = 1; - while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) { - uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path); - } - - _storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream); - var part = _contentManager.New("Audio"); - if (!_storageProvider.FolderExists(BaseFolder)) { - _storageProvider.CreateFolder(BaseFolder); - } - - part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath)); part.MimeType = mimeType; part.Title = Path.GetFileNameWithoutExtension(path); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/DocumentFactory.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/DocumentFactory.cs index d6c634bd0..e291d5582 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/DocumentFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/DocumentFactory.cs @@ -1,6 +1,5 @@ using System.IO; using Orchard.ContentManagement; -using Orchard.FileSystems.Media; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Factories { @@ -11,48 +10,30 @@ namespace Orchard.MediaLibrary.Factories { /// public class DocumentFactorySelector : IMediaFactorySelector { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public DocumentFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) { + public DocumentFactorySelector(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) { return new MediaFactorySelectorResult { Priority = -10, - MediaFactory = new DocumentFactory(_contentManager, _storageProvider) + MediaFactory = new DocumentFactory(_contentManager) }; } } public class DocumentFactory : IMediaFactory { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public const string BaseFolder = "Documents"; - - public DocumentFactory(IContentManager contentManager, IStorageProvider storageProvider) { + public DocumentFactory(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaPart CreateMedia(Stream stream, string path, string mimeType) { - var uniquePath = path; - var index = 1; - while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) { - uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path); - } - - _storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream); var part = _contentManager.New("Document"); - if (!_storageProvider.FolderExists(BaseFolder)) { - _storageProvider.CreateFolder(BaseFolder); - } - - part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath)); part.MimeType = mimeType; part.Title = Path.GetFileNameWithoutExtension(path); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/IMediaFactory.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/IMediaFactory.cs index 962c74fdd..65c4fdc26 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/IMediaFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/IMediaFactory.cs @@ -1,5 +1,4 @@ using System.IO; -using Orchard.ContentManagement; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Factories { diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/ImageFactory.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/ImageFactory.cs index dfb1b2f1e..431913729 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/ImageFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/ImageFactory.cs @@ -1,18 +1,15 @@ using System.Drawing; using System.IO; using Orchard.ContentManagement; -using Orchard.FileSystems.Media; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Factories { public class ImageFactorySelector : IMediaFactorySelector { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public ImageFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) { + public ImageFactorySelector(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) { @@ -22,7 +19,7 @@ namespace Orchard.MediaLibrary.Factories { return new MediaFactorySelectorResult { Priority = -5, - MediaFactory = new ImageFactory(_contentManager, _storageProvider) + MediaFactory = new ImageFactory(_contentManager) }; } @@ -30,31 +27,15 @@ namespace Orchard.MediaLibrary.Factories { public class ImageFactory : IMediaFactory { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public const string BaseFolder = "Images"; - - public ImageFactory(IContentManager contentManager, IStorageProvider storageProvider) { + public ImageFactory(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaPart CreateMedia(Stream stream, string path, string mimeType) { - var uniquePath = path; - var index = 1; - while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) { - uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path); - } - - _storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream); var part = _contentManager.New("Image"); - if (!_storageProvider.FolderExists(BaseFolder)) { - _storageProvider.CreateFolder(BaseFolder); - } - - part.Resource = _storageProvider.GetRelativePath(_storageProvider.Combine(BaseFolder, uniquePath)); part.MimeType = mimeType; part.Title = Path.GetFileNameWithoutExtension(path); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/VideoFactory.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/VideoFactory.cs index 213329893..e8447c7ba 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/VideoFactory.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Factories/VideoFactory.cs @@ -1,18 +1,14 @@ -using System; -using System.IO; +using System.IO; using Orchard.ContentManagement; -using Orchard.FileSystems.Media; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Factories { public class VideoFactorySelector : IMediaFactorySelector { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public VideoFactorySelector(IContentManager contentManager, IStorageProvider storageProvider) { + public VideoFactorySelector(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType) { @@ -22,7 +18,7 @@ namespace Orchard.MediaLibrary.Factories { return new MediaFactorySelectorResult { Priority = -5, - MediaFactory = new VideoFactory(_contentManager, _storageProvider) + MediaFactory = new VideoFactory(_contentManager) }; } @@ -30,31 +26,14 @@ namespace Orchard.MediaLibrary.Factories { public class VideoFactory : IMediaFactory { private readonly IContentManager _contentManager; - private readonly IStorageProvider _storageProvider; - public const string BaseFolder = "Videos"; - - public VideoFactory(IContentManager contentManager, IStorageProvider storageProvider) { + public VideoFactory(IContentManager contentManager) { _contentManager = contentManager; - _storageProvider = storageProvider; } public MediaPart CreateMedia(Stream stream, string path, string mimeType) { - var uniquePath = path; - var index = 1; - while (_storageProvider.FileExists(_storageProvider.Combine(BaseFolder, uniquePath))) { - uniquePath = Path.GetFileNameWithoutExtension(path) + "-" + index++ + Path.GetExtension(path); - } - - _storageProvider.SaveStream(_storageProvider.Combine(BaseFolder, uniquePath), stream); - var part = _contentManager.New("Video"); - if (!_storageProvider.FolderExists(BaseFolder)) { - _storageProvider.CreateFolder(BaseFolder); - } - - part.Resource = _storageProvider.GetPublicUrl(_storageProvider.Combine(BaseFolder, uniquePath)); part.MimeType = mimeType; part.Title = Path.GetFileNameWithoutExtension(path); diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Handlers/MediaPartHandler.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Handlers/MediaPartHandler.cs index a4749edbd..926254ba8 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Handlers/MediaPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Handlers/MediaPartHandler.cs @@ -1,37 +1,34 @@ -using Orchard.ContentManagement; +using System; using Orchard.ContentManagement.Handlers; using Orchard.Data; using Orchard.FileSystems.Media; +using Orchard.MediaLibrary.Services; using Orchard.MediaLibrary.Models; -using Orchard.Taxonomies.Models; namespace Orchard.MediaLibrary.Handlers { public class MediaPartHandler : ContentHandler { - private readonly IContentManager _contentManager; + private readonly IMediaLibraryService _mediaLibraryService; private readonly IStorageProvider _storageProvider; public MediaPartHandler( - IContentManager contentManager, + IMediaLibraryService mediaLibraryService, IRepository repository, IStorageProvider storageProvider) { - - _contentManager = contentManager; + _mediaLibraryService = mediaLibraryService; _storageProvider = storageProvider; Filters.Add(StorageFilter.For(repository)); - OnLoading((context, part) => LazyLoadHandlers(part)); - OnVersioning((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart)); OnRemoving((context, part) => RemoveMedia(part)); - } - - protected void LazyLoadHandlers(MediaPart part) { - // add handlers that will load content for id's just-in-time - part.TermPartField.Loader(() => part.Record.TermPartRecord == null ? null : _contentManager.Get(part.Record.TermPartRecord.Id)); + OnLoading((context, part) => { + if (!String.IsNullOrEmpty(part.FileName)) { + part._publicUrl.Loader(x => _mediaLibraryService.GetMediaPublicUrl(part.FolderPath, part.FileName)); + } + }); } protected void RemoveMedia(MediaPart part) { - if (part.Resource.StartsWith("~/")) { - var path = _storageProvider.GetLocalPath(part.Resource); + if (!string.IsNullOrEmpty(part.FileName)) { + var path = _storageProvider.Combine(part.FolderPath, part.FileName); _storageProvider.DeleteFile(path); } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Migrations.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Migrations.cs index 45721e738..eda190d08 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Migrations.cs @@ -1,16 +1,8 @@ -using Orchard.ContentManagement; -using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData; using Orchard.Data.Migration; -using Orchard.MediaLibrary.Services; -using Orchard.Taxonomies.Models; namespace Orchard.MediaLibrary { public class MediaDataMigration : DataMigrationImpl { - private readonly IContentManager _contentManager; - - public MediaDataMigration(IContentManager contentManager) { - _contentManager = contentManager; - } public int Create() { @@ -19,26 +11,10 @@ namespace Orchard.MediaLibrary { .Column("MimeType") .Column("Caption", c => c.Unlimited()) .Column("AlternateText", c => c.Unlimited()) - .Column("TermPartRecord_id") - .Column("Resource", c => c.WithLength(2048)) + .Column("FolderPath", c => c.WithLength(2048)) + .Column("FileName", c => c.WithLength(2048)) ); - // create the "Media Location" taxonomy - var taxonomy = _contentManager.New("Taxonomy"); - taxonomy.IsInternal = true; - taxonomy.Name = MediaLibraryService.MediaLocation; - - _contentManager.Create(taxonomy); - - // create the "Media" term - var term = _contentManager.New(taxonomy.TermTypeName); - term.TaxonomyId = taxonomy.Id; - term.Container = taxonomy; - term.Name = "Media"; - term.Path = "/"; - - _contentManager.Create(term, VersionOptions.Published); - ContentDefinitionManager.AlterTypeDefinition("Image", td => td .DisplayedAs("Image") .WithSetting("Stereotype", "Media") diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/FolderHierarchy.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/FolderHierarchy.cs new file mode 100644 index 000000000..78912aa55 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/FolderHierarchy.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Orchard.MediaLibrary.Models { + public class FolderHierarchy { + public FolderHierarchy(MediaFolder root) { + Root = root; + Children = new List(); + } + + public MediaFolder Root { get; set; } + public IEnumerable Children { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFile.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFile.cs new file mode 100644 index 000000000..7328e10e5 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFile.cs @@ -0,0 +1,13 @@ +using System; + +namespace Orchard.MediaLibrary.Models { + public class MediaFile { + public string Name { get; set; } + public string User { get; set; } + public string Type { get; set; } + public long Size { get; set; } + public string FolderName { get; set; } + public DateTime LastUpdated { get; set; } + public string MediaPath { get; set; } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFolder.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFolder.cs index 2cc3368c7..6611f4f80 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFolder.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaFolder.cs @@ -1,17 +1,11 @@ -using System.Collections.Generic; -using System.Linq; +using System; namespace Orchard.MediaLibrary.Models { public class MediaFolder { - public MediaFolder() { - Folders = new List(); - } - public string Name { get; set; } public string MediaPath { get; set; } - public int TermId { get; set; } - public int? ParentTermId { get; set; } - - public IList Folders { get; set; } + public string User { get; set; } + public long Size { get; set; } + public DateTime LastUpdated { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPart.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPart.cs index bac761dd5..2e9605a46 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPart.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPart.cs @@ -1,43 +1,67 @@ using Orchard.ContentManagement; -using Orchard.Core.Common.Utilities; +using Orchard.ContentManagement.Utilities; using Orchard.Core.Title.Models; -using Orchard.Taxonomies.Models; namespace Orchard.MediaLibrary.Models { public class MediaPart : ContentPart { - private readonly LazyField _termPartField = new LazyField(); - - public LazyField TermPartField { get { return _termPartField; } } + internal LazyField _publicUrl = new LazyField(); + /// + /// Gets or sets the title of the media. + /// public string Title { get { return ContentItem.As().Title; } set { ContentItem.As().Title = value; } } + /// + /// Gets or sets the mime type of the media. + /// public string MimeType { get { return Record.MimeType; } set { Record.MimeType = value; } } + /// + /// Gets or sets the caption of the media. + /// public string Caption { get { return Record.Caption; } set { Record.Caption = value; } } + /// + /// Gets or sets the alternate text of the media. + /// public string AlternateText { get { return Record.AlternateText; } set { Record.AlternateText = value; } } - public TermPart TermPart { - get { return _termPartField.Value; } - set { Record.TermPartRecord = value.Record; } + /// + /// Gets or sets the hierarchical location of the media. + /// + public string FolderPath { + get { return Record.FolderPath; } + set { Record.FolderPath = value; } } - public string Resource { - get { return Record.Resource; } - set { Record.Resource = value; } + /// + /// Gets or set the name of the media when is used + /// to store the physical media. If null then the media is not associated + /// with a local file. + /// + public string FileName { + get { return Record.FileName; } + set { Record.FileName = value; } + } + + /// + /// Gets the public Url of the media if stored locally. + /// + public string MediaUrl { + get { return _publicUrl.Value; } } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPartRecord.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPartRecord.cs index eafeb11ed..3b67ac598 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPartRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Models/MediaPartRecord.cs @@ -1,13 +1,12 @@ using Orchard.ContentManagement.Records; -using Orchard.Taxonomies.Models; namespace Orchard.MediaLibrary.Models { public class MediaPartRecord : ContentPartRecord { public virtual string MimeType { get; set; } public virtual string Caption { get; set; } public virtual string AlternateText { get; set; } - public virtual TermPartRecord TermPartRecord { get; set; } - public virtual string Resource { get; set; } + public virtual string FolderPath { get; set; } + public virtual string FileName { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Module.txt b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Module.txt index ad0f661ae..c8347f2fc 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Module.txt +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Module.txt @@ -9,5 +9,5 @@ Features: Orchard.MediaLibrary: Name: Media Library Description: Provides enhanced Media management tools. - Dependencies: Orchard.Taxonomies, Orchard.MediaProcessing, Title + Dependencies: Title, Orchard.MediaProcessing Category: Media \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Orchard.MediaLibrary.csproj b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Orchard.MediaLibrary.csproj index c786b15ab..f1ab7b8fc 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Orchard.MediaLibrary.csproj +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Orchard.MediaLibrary.csproj @@ -72,6 +72,8 @@ + + @@ -104,14 +106,6 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core - - {08191fcd-7258-4f19-95fb-aec3de77b2eb} - Orchard.MediaProcessing - - - {E649EA64-D213-461B-87F7-D67035801443} - Orchard.Taxonomies - @@ -141,12 +135,14 @@ + + + - diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/IMediaLibraryService.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/IMediaLibraryService.cs index 036975c1e..72655ea85 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/IMediaLibraryService.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/IMediaLibraryService.cs @@ -1,34 +1,120 @@ using System.Collections.Generic; using System.IO; +using System.Web; +using Orchard.ContentManagement; +using Orchard.MediaLibrary.Factories; using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.Services { public interface IMediaLibraryService : IDependency { - /// - /// Returns the whole hierarchy of media folders - /// - /// - IEnumerable GetMediaFolders(); - - MediaFolder GetMediaFolder(int id); - IEnumerable GetMediaFolderHierarchy(int id); - - /// - /// Returns the list of all Media Content Types - /// - /// IEnumerable GetMediaTypes(); - + IContentQuery GetMediaContentItems(); + IEnumerable GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType); IEnumerable GetMediaContentItems(int skip, int count, string order, string mediaType); - IEnumerable GetMediaContentItems(int folder, int skip, int count, string order, string mediaType); + int GetMediaContentItemsCount(string folderPath, string mediaType); int GetMediaContentItemsCount(string mediaType); - int GetMediaContentItemsCount(int folder, string mediaType); + MediaPart ImportMedia(string relativePath, string filename); + MediaPart ImportMedia(Stream stream, string relativePath, string filename); + IMediaFactory GetMediaFactory(Stream stream, string mimeType); - MediaPart ImportStream(int termId, Stream stream, string filename); + /// + /// Creates a unique filename to prevent filename collisions. + /// + /// The relative where collisions will be checked. + /// The desired filename. + /// A string representing a unique filename. + string GetUniqueFilename(string folderPath, string filename); - MediaFolder CreateFolder(int? parentFolderId, string name); - void RenameFolder(int folderId, string name); - void DeleteFolder(int folderId); - void MoveMedia(int targetId, int[] mediaItemIds); + /// + /// Returns the public URL for a media file. + /// + /// The relative path of the media folder containing the media. + /// The media file name. + /// The public URL for the media. + string GetMediaPublicUrl(string mediaPath, string fileName); + + /// + /// Retrieves the media folders within a given relative path. + /// + /// The path where to retrieve the media folder from. null means root. + /// The media folder in the given path. + IEnumerable GetMediaFolders(string relativePath); + + /// + /// Retrieves the media files within a given relative path. + /// + /// The path where to retrieve the media files from. null means root. + /// The media files in the given path. + IEnumerable GetMediaFiles(string relativePath); + + /// + /// Creates a media folder. + /// + /// The path where to create the new folder. null means root. + /// The name of the folder to be created. + void CreateFolder(string relativePath, string folderName); + + /// + /// Deletes a media folder. + /// + /// The path to the folder to be deleted. + void DeleteFolder(string folderPath); + + /// + /// Renames a media folder. + /// + /// The path to the folder to be renamed. + /// The new folder name. + void RenameFolder(string folderPath, string newFolderName); + + /// + /// Deletes a media file. + /// + /// The folder path. + /// The file name. + void DeleteFile(string folderPath, string fileName); + + /// + /// Renames a media file. + /// + /// The path to the file's parent folder. + /// The current file name. + /// The new file name. + void RenameFile(string folderPath, string currentFileName, string newFileName); + + /// + /// Moves a media file. + /// + /// The path to the file's parent folder. + /// The file name. + /// The path where the file will be moved to. + /// The new file name. + void MoveFile(string currentPath, string filename, string newPath, string newFilename); + + /// + /// Uploads a media file based on a posted file. + /// + /// The path to the folder where to upload the file. + /// The file to upload. + /// The path to the uploaded file. + string UploadMediaFile(string folderPath, HttpPostedFileBase postedFile); + + /// + /// Uploads a media file based on an array of bytes. + /// + /// The path to the folder where to upload the file. + /// The file name. + /// The array of bytes with the file's contents. + /// The path to the uploaded file. + string UploadMediaFile(string folderPath, string fileName, byte[] bytes); + + /// + /// Uploads a media file based on a stream. + /// + /// The folder path to where to upload the file. + /// The file name. + /// The stream with the file's contents. + /// The path to the uploaded file. + string UploadMediaFile(string folderPath, string fileName, Stream inputStream); } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/MediaLibraryService.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/MediaLibraryService.cs index 9866760f7..b319cb4ac 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/MediaLibraryService.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Services/MediaLibraryService.cs @@ -2,106 +2,57 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Web; using Orchard.ContentManagement; using Orchard.Core.Common.Models; using Orchard.FileSystems.Media; +using Orchard.Localization; using Orchard.MediaLibrary.Factories; using Orchard.MediaLibrary.Models; -using Orchard.Taxonomies.Models; -using Orchard.Taxonomies.Services; using Orchard.Core.Title.Models; +using Orchard.Validation; namespace Orchard.MediaLibrary.Services { public class MediaLibraryService : IMediaLibraryService { - private readonly ITaxonomyService _taxonomyService; - private readonly IContentManager _contentManager; + private readonly IOrchardServices _orchardServices; private readonly IMimeTypeProvider _mimeTypeProvider; + private readonly IStorageProvider _storageProvider; private readonly IEnumerable _mediaFactorySelectors; - public const string MediaLocation = "Media Location"; public MediaLibraryService( - ITaxonomyService taxonomyService, - IContentManager contentManager, + IOrchardServices orchardServices, IMimeTypeProvider mimeTypeProvider, - IEnumerable mediaFactorySelectors ) { - _taxonomyService = taxonomyService; - _contentManager = contentManager; + IStorageProvider storageProvider, + IEnumerable mediaFactorySelectors) { + _orchardServices = orchardServices; _mimeTypeProvider = mimeTypeProvider; + _storageProvider = storageProvider; _mediaFactorySelectors = mediaFactorySelectors; + + T = NullLocalizer.Instance; } - private TaxonomyPart GetMediaLocationTaxonomy() { - return _taxonomyService.GetTaxonomyByName(MediaLocation); - } - - public IEnumerable GetMediaFolders() { - var taxonomy = GetMediaLocationTaxonomy(); - - var terms = _taxonomyService.GetTerms(taxonomy.Id); - var rootFolders = new List(); - var index = new Dictionary(); - - _taxonomyService.CreateHierarchy(terms, (parent, child) => { - MediaFolder parentFolder; - MediaFolder childFolder = CreateMediaFolder(child.TermPart); - index.Add(child.TermPart.Id, childFolder); - - // adding to root - if (parent.TermPart != null) { - parentFolder = index.ContainsKey(parent.TermPart.Id) ? index[parent.TermPart.Id] : null; - parentFolder.Folders.Add(childFolder); - } - else { - rootFolders.Add(childFolder); - } - - }); - - return rootFolders; - } - - public MediaFolder GetMediaFolder(int id) { - return CreateMediaFolder(_taxonomyService.GetTerm(id)); - } - - public IEnumerable GetMediaFolderHierarchy(int id) { - var target = CreateMediaFolder(_taxonomyService.GetTerm(id)); - if (target == null) { - yield break; - } - - yield return target; - - while (target.ParentTermId.HasValue) { - target = CreateMediaFolder(_taxonomyService.GetTerm(target.ParentTermId.Value)); - - if (target == null) { - yield break; - } - - yield return target; - } - } + public Localizer T { get; set; } public IEnumerable GetMediaTypes() { - return _contentManager.GetContentTypeDefinitions() + return _orchardServices.ContentManager.GetContentTypeDefinitions() .Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "Widget") .Select(contentTypeDefinition => contentTypeDefinition.Name); } public IContentQuery GetMediaContentItems() { - return _contentManager.Query(); + return _orchardServices.ContentManager.Query(); } - public IEnumerable GetMediaContentItems(int folder, int skip, int count, string order, string mediaType) { - var query = _contentManager.Query(); + public IEnumerable GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType) { + var query = _orchardServices.ContentManager.Query(); if (!String.IsNullOrEmpty(mediaType)) { query = query.ForType(new[] { mediaType }); } - if (folder > 0) { - query = query.Join().Where(m => m.TermPartRecord.Id == folder); + if (!String.IsNullOrEmpty(folderPath)) { + query = query.Join().Where(m => m.FolderPath == folderPath); } switch(order) { @@ -132,38 +83,67 @@ namespace Orchard.MediaLibrary.Services { } public IEnumerable GetMediaContentItems(int skip, int count, string order, string mediaType) { - return GetMediaContentItems(-1, skip, count, order, mediaType); + return GetMediaContentItems(null, skip, count, order, mediaType); } - public int GetMediaContentItemsCount(int folder, string mediaType) { - var query = _contentManager.Query(); + public int GetMediaContentItemsCount(string folderPath, string mediaType) { + var query = _orchardServices.ContentManager.Query(); if (!String.IsNullOrEmpty(mediaType)) { query = query.ForType(new[] { mediaType }); } - if (folder > 0) { - query = query.Join().Where(m => m.TermPartRecord.Id == folder); + if (!String.IsNullOrEmpty(folderPath)) { + query = query.Join().Where(m => m.FolderPath == folderPath); } return query.Count(); } public int GetMediaContentItemsCount(string mediaType) { - return GetMediaContentItemsCount(-1, mediaType); + return GetMediaContentItemsCount(null, mediaType); } - public MediaPart ImportStream(int termId, Stream stream, string filename) { - var mimeType = _mimeTypeProvider.GetMimeType(filename); + public MediaPart ImportMedia(Stream stream, string relativePath, string filename) { + var uniqueFilename = GetUniqueFilename(relativePath, filename); - var mediaFactory = GetMediaFactory(stream, mimeType); - var mediaPart = mediaFactory.CreateMedia(stream, filename, mimeType); - if (mediaPart != null) { - mediaPart.TermPart = _taxonomyService.GetTerm(termId); - _contentManager.Create(mediaPart); + UploadMediaFile(relativePath, uniqueFilename, stream); + return ImportMedia(relativePath, uniqueFilename); + } + + public string GetUniqueFilename(string folderPath, string filename) { + // compute a unique filename + var uniqueFilename = filename; + var index = 1; + while (_storageProvider.FileExists(_storageProvider.Combine(folderPath, uniqueFilename))) { + uniqueFilename = Path.GetFileNameWithoutExtension(filename) + "-" + index++ + Path.GetExtension(filename); } - return mediaPart; + return uniqueFilename; + } + + public MediaPart ImportMedia(string relativePath, string filename) { + + var mimeType = _mimeTypeProvider.GetMimeType(filename); + + if (!_storageProvider.FileExists(_storageProvider.Combine(relativePath, filename))) { + return null; + } + + var storageFile = _storageProvider.GetFile(_storageProvider.Combine(relativePath, filename)); + var mediaFile = BuildMediaFile(relativePath, storageFile); + + using (var stream = storageFile.OpenRead()) { + var mediaFactory = GetMediaFactory(stream, mimeType); + var mediaPart = mediaFactory.CreateMedia(stream, mediaFile.Name, mimeType); + if (mediaPart != null) { + mediaPart.FolderPath = relativePath; + mediaPart.FileName = filename; + _orchardServices.ContentManager.Create(mediaPart); + } + + return mediaPart; + } } public IMediaFactory GetMediaFactory(Stream stream, string mimeType) { @@ -173,59 +153,198 @@ namespace Orchard.MediaLibrary.Services { .OrderByDescending(x => x.Priority); if (!requestMediaFactoryResults.Any() ) - return NullMediaFactory.Instance; + return null; return requestMediaFactoryResults.First().MediaFactory; } - public MediaFolder CreateFolder(int? parentFolderId, string name) { - var taxonomy = GetMediaLocationTaxonomy(); - TermPart parentTerm = parentFolderId.HasValue ? _taxonomyService.GetTerm(parentFolderId.Value) : null; - var term = _taxonomyService.NewTerm(taxonomy); - term.Container = parentTerm == null ? taxonomy.ContentItem : parentTerm.ContentItem; + /// + /// Retrieves the public path based on the relative path within the media directory. + /// + /// + /// "/Media/Default/InnerDirectory/Test.txt" based on the input "InnerDirectory/Test.txt" + /// + /// The relative path within the media directory. + /// The public path relative to the application url. + public string GetPublicUrl(string relativePath) { + Argument.ThrowIfNullOrEmpty(relativePath, "relativePath"); - term.Name = name; - - _taxonomyService.ProcessPath(term); - _contentManager.Create(term, VersionOptions.Published); - - return CreateMediaFolder(term); + return _storageProvider.GetPublicUrl(relativePath); } - public void RenameFolder(int folderId, string name) { - var term = _taxonomyService.GetTerm(folderId); - term.Name = name; + /// + /// Returns the public URL for a media file. + /// + /// The relative path of the media folder containing the media. + /// The media file name. + /// The public URL for the media. + public string GetMediaPublicUrl(string mediaPath, string fileName) { + return GetPublicUrl(Path.Combine(mediaPath, fileName)); } - public void DeleteFolder(int folderId) { - var term = _taxonomyService.GetTerm(folderId); - _taxonomyService.DeleteTerm(term); + /// + /// Retrieves the media folders within a given relative path. + /// + /// The path where to retrieve the media folder from. null means root. + /// The media folder in the given path. + public IEnumerable GetMediaFolders(string relativePath) { + return _storageProvider + .ListFolders(relativePath) + .Select(BuildMediaFolder) + .Where(f => !f.Name.Equals("RecipeJournal", StringComparison.OrdinalIgnoreCase)) + .Where(f => !f.Name.StartsWith("_")) + .ToList(); } - private MediaFolder CreateMediaFolder(TermPart termPart) { - if (termPart == null) { - return null; - } - - return new MediaFolder{ - Name = termPart.Name, - MediaPath = termPart.FullPath, - TermId = termPart.Id, - ParentTermId = termPart.Container != null ? termPart.Container.Id : default(int?) + private static MediaFolder BuildMediaFolder(IStorageFolder folder) { + return new MediaFolder { + Name = folder.GetName(), + Size = folder.GetSize(), + LastUpdated = folder.GetLastUpdated(), + MediaPath = folder.GetPath() }; } - public void MoveMedia(int targetId, int[] mediaItemIds) { - var targetFolder = _taxonomyService.GetTerm(targetId); - if (targetFolder == null) { - throw new ArgumentException("Target folder doesn't exist"); - } + /// + /// Retrieves the media files within a given relative path. + /// + /// The path where to retrieve the media files from. null means root. + /// The media files in the given path. + public IEnumerable GetMediaFiles(string relativePath) { + return _storageProvider.ListFiles(relativePath).Select(file => + BuildMediaFile(relativePath, file)).ToList(); + } - var mediaItems = GetMediaContentItems().Where(x => mediaItemIds.Contains(x.Id)).List(); + private MediaFile BuildMediaFile(string relativePath, IStorageFile file) { + return new MediaFile { + Name = file.GetName(), + Size = file.GetSize(), + LastUpdated = file.GetLastUpdated(), + Type = file.GetFileType(), + FolderName = relativePath, + MediaPath = GetMediaPublicUrl(relativePath, file.GetName()) + }; + } - foreach (var mediaItem in mediaItems) { - mediaItem.TermPart = targetFolder; - } + /// + /// Creates a media folder. + /// + /// The path where to create the new folder. null means root. + /// The name of the folder to be created. + public void CreateFolder(string relativePath, string folderName) { + Argument.ThrowIfNullOrEmpty(folderName, "folderName"); + + _storageProvider.CreateFolder(relativePath == null ? folderName : _storageProvider.Combine(relativePath, folderName)); + } + + /// + /// Deletes a media folder. + /// + /// The path to the folder to be deleted. + public void DeleteFolder(string folderPath) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + + _storageProvider.DeleteFolder(folderPath); + } + + /// + /// Renames a media folder. + /// + /// The path to the folder to be renamed. + /// The new folder name. + public void RenameFolder(string folderPath, string newFolderName) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNullOrEmpty(newFolderName, "newFolderName"); + + _storageProvider.RenameFolder(folderPath, _storageProvider.Combine(Path.GetDirectoryName(folderPath), newFolderName)); + } + + /// + /// Deletes a media file. + /// + /// The folder path. + /// The file name. + public void DeleteFile(string folderPath, string fileName) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNullOrEmpty(fileName, "fileName"); + + _storageProvider.DeleteFile(_storageProvider.Combine(folderPath, fileName)); + } + + /// + /// Renames a media file. + /// + /// The path to the file's parent folder. + /// The current file name. + /// The new file name. + public void RenameFile(string folderPath, string currentFileName, string newFileName) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNullOrEmpty(currentFileName, "currentFileName"); + Argument.ThrowIfNullOrEmpty(newFileName, "newFileName"); + + _storageProvider.RenameFile(_storageProvider.Combine(folderPath, currentFileName), _storageProvider.Combine(folderPath, newFileName)); + } + + /// + /// Moves a media file. + /// + /// The path to the file's parent folder. + /// The file name. + /// The path where the file will be moved to. + /// The new file name. + public void MoveFile(string currentPath, string filename, string newPath, string newFilename) { + Argument.ThrowIfNullOrEmpty(currentPath, "currentPath"); + Argument.ThrowIfNullOrEmpty(newPath, "newPath"); + Argument.ThrowIfNullOrEmpty(filename, "filename"); + Argument.ThrowIfNullOrEmpty(newFilename, "newFilename"); + + _storageProvider.RenameFile(_storageProvider.Combine(currentPath, filename), _storageProvider.Combine(newPath, newFilename)); + } + + /// + /// Uploads a media file based on a posted file. + /// + /// The path to the folder where to upload the file. + /// The file to upload. + /// The path to the uploaded file. + public string UploadMediaFile(string folderPath, HttpPostedFileBase postedFile) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNull(postedFile, "postedFile"); + + return UploadMediaFile(folderPath, Path.GetFileName(postedFile.FileName), postedFile.InputStream); + } + + /// + /// Uploads a media file based on an array of bytes. + /// + /// The path to the folder where to upload the file. + /// The file name. + /// The array of bytes with the file's contents. + /// The path to the uploaded file. + public string UploadMediaFile(string folderPath, string fileName, byte[] bytes) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNullOrEmpty(fileName, "fileName"); + Argument.ThrowIfNull(bytes, "bytes"); + + return UploadMediaFile(folderPath, fileName, new MemoryStream(bytes)); + } + + /// + /// Uploads a media file based on a stream. + /// + /// The folder path to where to upload the file. + /// The file name. + /// The stream with the file's contents. + /// The path to the uploaded file. + public string UploadMediaFile(string folderPath, string fileName, Stream inputStream) { + Argument.ThrowIfNullOrEmpty(folderPath, "folderPath"); + Argument.ThrowIfNullOrEmpty(fileName, "fileName"); + Argument.ThrowIfNull(inputStream, "inputStream"); + + string filePath = _storageProvider.Combine(folderPath, fileName); + _storageProvider.SaveStream(filePath, inputStream); + + return _storageProvider.GetPublicUrl(filePath); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Styles/Images/menu.media.png b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Styles/Images/menu.media.png new file mode 100644 index 0000000000000000000000000000000000000000..3b91435f3817b68f6c64cd3db756cc4cc94d1d3c GIT binary patch literal 360 zcmeAS@N?(olHy`uVBq!ia0vp^0zhoQ!3HEH;(vt$DaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(eheoCO|{#S9GGf*{OTpAtV2C@59p8c`CQpH@ Hierarchy { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerFolderEditViewModel.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerFolderEditViewModel.cs index ce86bbec5..424ce561d 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerFolderEditViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerFolderEditViewModel.cs @@ -6,7 +6,7 @@ namespace Orchard.MediaLibrary.ViewModels { public class MediaManagerFolderEditViewModel { [Required] public string Name { get; set; } - public int FolderId { get; set; } + public string FolderPath { get; set; } public IEnumerable Hierarchy { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerImportViewModel.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerImportViewModel.cs index e181f15bb..767e40a49 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerImportViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerImportViewModel.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; -using Orchard.MediaLibrary.Models; using Orchard.UI.Navigation; namespace Orchard.MediaLibrary.ViewModels { public class MediaManagerImportViewModel { public IEnumerable Menu { get; set; } public IEnumerable ImageSets { get; set; } - public ICollection Hierarchy { get; set; } + public string FolderPath { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerIndexViewModel.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerIndexViewModel.cs index 52c5beef9..24fa9be01 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerIndexViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/MediaManagerIndexViewModel.cs @@ -3,9 +3,8 @@ using Orchard.MediaLibrary.Models; namespace Orchard.MediaLibrary.ViewModels { public class MediaManagerIndexViewModel { - public IEnumerable Folders { get; set; } - public IEnumerable Hierarchy { get; set; } - public int? Folder { get; set; } + public IEnumerable Folders { get; set; } + public string FolderPath { get; set; } public bool DialogMode { get; set; } public string[] MediaTypes { get; set; } } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/OEmbedViewModel.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/OEmbedViewModel.cs index 7a97f466a..3a35f26f4 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/OEmbedViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/ViewModels/OEmbedViewModel.cs @@ -2,7 +2,7 @@ namespace Orchard.MediaLibrary.ViewModels { public class OEmbedViewModel { - public int Id { get; set; } + public string FolderPath { get; set; } public string Url { get; set; } public XDocument Content { get; set; } public bool Success { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Import.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Import.cshtml index 8883f435e..7fad8c36a 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Import.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Import.cshtml @@ -19,10 +19,10 @@
- @T("Media Folders") @foreach (var folder in Model.Hierarchy.Reverse()) { > @folder.Name} + @T("Media Folders") @foreach (var folder in Model.FolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries)) { > @folder}
@@ -32,7 +32,7 @@ string sectionHeaderTextHint = menuItem.Text.TextHint; var itemClassName = "navicon-" + sectionHeaderTextHint.HtmlClassify(); - + }
diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Index.cshtml index e36ab20f7..f45a7d187 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Admin/Index.cshtml @@ -17,8 +17,8 @@
@T("Import") - @T("Create Folder") - @T("Edit Folder") + @T("Create Folder") - @Html.HiddenFor(m => m.ParentFolderId) + @Html.HiddenFor(m => m.FolderPath)
- @Html.ActionLink(T("Cancel").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary" }, new { @class= "button"}) + @Html.ActionLink(T("Cancel").ToString(), "Index", "Admin", new { area = "Orchard.MediaLibrary", folderPath = Model.FolderPath }, new { @class= "button"})
} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Media-Image.Thumbnail.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Media-Image.Thumbnail.cshtml index 04a02173e..3aac8e1a1 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Media-Image.Thumbnail.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Media-Image.Thumbnail.cshtml @@ -10,5 +10,5 @@ }
- +
\ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/OEmbed/Index.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/OEmbed/Index.cshtml index 254dc05c4..511a70d71 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/OEmbed/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/OEmbed/Index.cshtml @@ -1,8 +1,5 @@ @model Orchard.MediaLibrary.ViewModels.OEmbedViewModel -@using System.Text -@using System.Xml; - @@ -57,7 +54,7 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("MediaPost"))) { @Html.Hidden("url", Model.Url) - @Html.Hidden("id", Model.Id) + @Html.Hidden("folderPath", Model.FolderPath) @Html.Hidden("document", Model.Content.ToString()) diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.Summary.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.Summary.cshtml index 0ae3972e6..50a01957c 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.Summary.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.Summary.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.SummaryAdmin.cshtml index 0ae3972e6..50a01957c 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.SummaryAdmin.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.cshtml index 0ae3972e6..50a01957c 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Audio.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.Summary.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.Summary.cshtml index 1420be1ff..3091e51bf 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.Summary.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.Summary.cshtml @@ -5,7 +5,7 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + @T("Download") \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.SummaryAdmin.cshtml index 1420be1ff..3091e51bf 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.SummaryAdmin.cshtml @@ -5,7 +5,7 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + @T("Download") \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.cshtml index 1420be1ff..3091e51bf 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Document.cshtml @@ -5,7 +5,7 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + @T("Download") \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.Summary.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.Summary.cshtml index 978651fd5..55508049f 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.Summary.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.Summary.cshtml @@ -6,7 +6,7 @@ } @* Use a 200x200 profile in order to reuse the general thumbnail *@ - - @mediaPart.AlternateText + + @mediaPart.AlternateText diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.SummaryAdmin.cshtml index daa6df582..1c433b137 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.SummaryAdmin.cshtml @@ -6,5 +6,5 @@ } @* Use a 200x200 profile in order to reuse the general thumbnail *@ -@mediaPart.AlternateText +@mediaPart.AlternateText diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.cshtml index f8322800b..64ebd89b4 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Image.cshtml @@ -5,5 +5,5 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } -@mediaPart.AlternateText +@mediaPart.AlternateText diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Media.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Media.SummaryAdmin.cshtml index 2d55983ca..6e194f49b 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Media.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Media.SummaryAdmin.cshtml @@ -9,7 +9,7 @@
@T("Filename:") - @Path.GetFileName(mediaPart.Resource) + @Path.GetFileName(mediaPart.MediaUrl)
@T("Mime Type:") diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.Summary.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.Summary.cshtml index a418a7174..b7861cd35 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.Summary.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.Summary.cshtml @@ -5,6 +5,6 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + @T("Preview") \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.SummaryAdmin.cshtml index 314ac096c..2bc33d7d5 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/OEmbed.SummaryAdmin.cshtml @@ -5,6 +5,6 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + @T("Preview") diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.Summary.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.Summary.cshtml index b65a5f5c6..ba3d3b49b 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.Summary.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.Summary.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.SummaryAdmin.cshtml index b65a5f5c6..ba3d3b49b 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.SummaryAdmin.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.cshtml index b65a5f5c6..ba3d3b49b 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/Parts/Video.cshtml @@ -5,4 +5,4 @@ var mediaPart = ((ContentItem)Model.ContentItem).As(); } - + diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/WebSearch/Index.cshtml b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/WebSearch/Index.cshtml index 9188ab1d3..731d48aaa 100644 --- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/WebSearch/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Views/WebSearch/Index.cshtml @@ -1,7 +1,6 @@ @using System.Text @using Orchard.ContentManagement @using Orchard.MediaLibrary.Models -@using Orchard.UI.Notify @@ -84,7 +83,7 @@ @Html.Hidden("antiforgerytoken", Html.AntiForgeryTokenValueOrchard()) @Html.Hidden("action", Url.Action("ImagePost")) - @Html.Hidden("id", (int)Model) + @Html.Hidden("folderPath", (string)Model) @using(Script.Foot()) {