public ActionResult Index(string folderPath = "", bool dialog = false) { // let other modules enhance the ui by providing custom navigation and actions var explorer = Services.ContentManager.New("MediaLibraryExplorer"); explorer.Weld(new MediaLibraryExplorerPart()); var explorerShape = Services.ContentManager.BuildDisplay(explorer); var viewModel = new MediaManagerIndexViewModel { DialogMode = dialog, Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy), FolderPath = folderPath, MediaTypes = _mediaLibraryService.GetMediaTypes(), CustomActionsShapes = explorerShape.Actions, CustomNavigationShapes = explorerShape.Navigation, }; foreach (var shape in explorerShape.Actions.Items) { shape.MediaManagerIndexViewModel = viewModel; } foreach (var shape in explorerShape.Navigation.Items) { shape.MediaManagerIndexViewModel = viewModel; } return(View(viewModel)); }
public ActionResult Index(string folderPath = "", bool dialog = false) { if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath)) { Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Cannot select media")); return(new HttpUnauthorizedResult()); } var userMediaFolder = _mediaLibraryService.GetUserMediaFolder(); if (Services.Authorizer.Authorize(Permissions.ManageOwnMedia) && !Services.Authorizer.Authorize(Permissions.ManageMediaContent)) { _storageProvider.TryCreateFolder(userMediaFolder.MediaPath); } // If the user is trying to access a folder above his boundaries, redirect him to his home folder var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.SelectMediaContent, folderPath) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(RedirectToAction("Index", new { folderPath = rootMediaFolder.MediaPath, dialog })); } // let other modules enhance the ui by providing custom navigation and actions var explorer = Services.ContentManager.New("MediaLibraryExplorer"); explorer.Weld(new MediaLibraryExplorerPart()); var explorerShape = Services.ContentManager.BuildDisplay(explorer); var rootMediaFolderPath = rootMediaFolder == null ? null : rootMediaFolder.MediaPath; var viewModel = new MediaManagerIndexViewModel { DialogMode = dialog, FolderPath = folderPath, RootFolderPath = rootMediaFolderPath, ChildFoldersViewModel = new MediaManagerChildFoldersViewModel { Children = _mediaLibraryService.GetMediaFolders(rootMediaFolderPath) }, MediaTypes = _mediaLibraryService.GetMediaTypes(), CustomActionsShapes = explorerShape.Actions, CustomNavigationShapes = explorerShape.Navigation, }; foreach (var shape in explorerShape.Actions.Items) { shape.MediaManagerIndexViewModel = viewModel; } foreach (var shape in explorerShape.Navigation.Items) { shape.MediaManagerIndexViewModel = viewModel; } return(View(viewModel)); }
public ActionResult DownloadFile(Guid guid, string name) { var fileRecord = fileRepository.Table.FirstOrDefault(c => c.FolderGuid == guid); if (fileRecord != null) { var item = _services.ContentManager.Get(fileRecord.ContentItemRecord.Id); if (item != null) { if (!item.Has <FileUploadPart>()) { return(HttpNotFound()); } if (!this.contentOwnershipService.CurrentUserCanEditContent(item)) { throw new UnauthorizedAccessException(); } } } else { return(HttpNotFound()); } var folders = _mediaService.GetMediaFolders("Uploads"); var folder = folders.SingleOrDefault(x => x.Name == guid.ToString()); if (folder == null) { return(HttpNotFound()); } var file = _mediaService.GetMediaFiles(folder.MediaPath).SingleOrDefault(x => x.Name == name); if (file == null) { return(HttpNotFound()); } var path = HostingEnvironment.MapPath(Path.Combine("~/Media/Default/", folder.MediaPath, file.Name)); byte[] bytes = null; using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var reader = new BinaryReader(stream); bytes = reader.ReadBytes((int)stream.Length); } return(File(bytes, file.Type, file.Name)); }
protected string GetThumbnailFolder(string mediaPath) { // Creates a thumbnail folder if doesn't exists if (!_mediaService.GetMediaFolders(mediaPath).Select(o => o.Name).Contains(ThumbnailFolder)) { _mediaService.CreateFolder(mediaPath, ThumbnailFolder); } return(_storageProvider.Combine(mediaPath, ThumbnailFolder)); }
public ActionResult Index(string folderPath = "", bool dialog = false) { if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Cannot view media"))) { return(new HttpUnauthorizedResult()); } // let other modules enhance the ui by providing custom navigation and actions var explorer = Services.ContentManager.New("MediaLibraryExplorer"); explorer.Weld(new MediaLibraryExplorerPart()); var explorerShape = Services.ContentManager.BuildDisplay(explorer); var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); var viewModel = new MediaManagerIndexViewModel { DialogMode = dialog, FolderPath = folderPath, ChildFoldersViewModel = new MediaManagerChildFoldersViewModel { Children = _mediaLibraryService.GetMediaFolders(rootMediaFolder == null ? null : rootMediaFolder.MediaPath) }, MediaTypes = _mediaLibraryService.GetMediaTypes(), CustomActionsShapes = explorerShape.Actions, CustomNavigationShapes = explorerShape.Navigation, }; foreach (var shape in explorerShape.Actions.Items) { shape.MediaManagerIndexViewModel = viewModel; } foreach (var shape in explorerShape.Navigation.Items) { shape.MediaManagerIndexViewModel = viewModel; } return(View(viewModel)); }
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); } } var viewModel = new MediaManagerIndexViewModel { DialogMode = dialog, Folders = _mediaLibraryService.GetMediaFolders(null).Select(GetFolderHierarchy), FolderPath = folderPath, MediaTypes = mediaTypes.ToArray() }; return(View(viewModel)); }
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 = _mediaLibraryService.GetMediaFolders(folderPath, Services.WorkContext.CurrentUser), FolderPath = folderPath }; return(View(viewModel)); }
public IEnumerable <string> GetFaviconSuggestions() { List <string> faviconSuggestions = null; var rootMediaFolders = _mediaService .GetMediaFolders(".") .Where(f => f.Name.Equals(FaviconMediaFolder, StringComparison.OrdinalIgnoreCase)); if (rootMediaFolders.Any()) { faviconSuggestions = new List <string>( _mediaService.GetMediaFiles(FaviconMediaFolder) .Select(f => _mediaService.GetMediaPublicUrl(FaviconMediaFolder, f.Name))); } return(faviconSuggestions); }
//TODO: Remove Image repository as soon as it can cascade the saving public ImageGalleryService(IMediaLibraryService mediaService, IRepository<ImageGallerySettingsRecord> repository, IRepository<ImageGalleryImageSettingsRecord> imageRepository, IThumbnailService thumbnailService, IRepository<ImageGalleryRecord> imageGalleryPartRepository, IOrchardServices services, IStorageProvider storageProvider) { _storageProvider = storageProvider; _services = services; _imageGalleryPartRepository = imageGalleryPartRepository; _repository = repository; _mediaService = mediaService; _imageRepository = imageRepository; _thumbnailService = thumbnailService; if (_mediaService.GetMediaFolders(string.Empty).All(o => o.Name != ImageGalleriesMediaFolder)) { _mediaService.CreateFolder(string.Empty, ImageGalleriesMediaFolder); } }
//TODO: Remove Image repository as soon as it can cascade the saving public ImageGalleryService(IMediaLibraryService mediaService, IRepository <ImageGallerySettingsRecord> repository, IRepository <ImageGalleryImageSettingsRecord> imageRepository, IThumbnailService thumbnailService, IRepository <ImageGalleryRecord> imageGalleryPartRepository, IOrchardServices services, IStorageProvider storageProvider) { _storageProvider = storageProvider; _services = services; _imageGalleryPartRepository = imageGalleryPartRepository; _repository = repository; _mediaService = mediaService; _imageRepository = imageRepository; _thumbnailService = thumbnailService; if (_mediaService.GetMediaFolders(string.Empty).All(o => o.Name != ImageGalleriesMediaFolder)) { _mediaService.CreateFolder(string.Empty, ImageGalleriesMediaFolder); } }
private IEnumerable <String> GetPossibleMapIcons() { // Get possible icons List <String> possibleMapIcons; var rootMediaFolders = _mediaLibraryService .GetMediaFolders(".") .Where(f => f.Name.Equals(BingMapListService.MAPICONS_MEDIA_FOLDER, StringComparison.OrdinalIgnoreCase)); if (rootMediaFolders.Any()) { possibleMapIcons = new List <string>( _mediaLibraryService.GetMediaFiles(BingMapListService.MAPICONS_MEDIA_FOLDER) .Select(f => f.Name)); } else { possibleMapIcons = new List <String>(); } return(possibleMapIcons); }
public ActionResult Create(string folderPath) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't create media folder"))) { return(new HttpUnauthorizedResult()); } // If the user is trying to access a folder above his boundaries, redirect him to his home folder var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(RedirectToAction("Create", new { folderPath = rootMediaFolder.MediaPath })); } var viewModel = new MediaManagerFolderCreateViewModel { Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath), FolderPath = folderPath }; return(View(viewModel)); }
public ActionResult Create(string folderPath) { if (!(_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, folderPath) || _mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, folderPath))) { Services.Notifier.Error(T("Couldn't create media folder")); return(RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary", folderPath = folderPath })); } // If the user is trying to access a folder above his boundaries, redirect him to his home folder var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(RedirectToAction("Create", new { folderPath = rootMediaFolder.MediaPath })); } var viewModel = new MediaManagerFolderCreateViewModel { Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath), FolderPath = folderPath }; return(View(viewModel)); }
public IEnumerable <Models.ImageGallery> GetImageGalleries() { return(_mediaService.GetMediaFolders(ImageGalleriesMediaFolder).Select(CreateImageGalleryFromMediaFolder)); }
public ActionResult DeleteFile(Guid guid, string name, string returnValue) { var fileRecord = fileRepository.Table.FirstOrDefault(c => c.FolderGuid == guid); ContentItem item = null; if (fileRecord != null) { item = _services.ContentManager.Get(fileRecord.ContentItemRecord.Id); if (item != null) { if (!item.Has <FileUploadPart>()) { return(HttpNotFound()); } if (!this.contentOwnershipService.CurrentUserCanEditContent(item)) { throw new UnauthorizedAccessException(); } } } var folders = _mediaService.GetMediaFolders("Uploads"); var folder = folders.SingleOrDefault(x => x.Name == guid.ToString()); if (folder == null) { return(HttpNotFound()); } if (this.storageProvider.FileExists(this.storageProvider.Combine(folder.MediaPath, name))) { _mediaService.DeleteFile(folder.MediaPath, name); } fileRecord.FilesCount = _mediaService.GetMediaFiles(folder.MediaPath).Count(); if (item != null) { int userId = _services.WorkContext.CurrentUser.Id; string description = string.Format(CultureInfo.CurrentUICulture, "Delete the file '{0}' from '{1}'", name, this.GetContentItemDescriptionForActivityStream(item)); RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); routeValueDictionary.Add("action", "Display"); routeValueDictionary.Add("controller", "Item"); routeValueDictionary.Add("area", "Orchard.CRM.Core"); routeValueDictionary.Add("id", fileRecord.ContentItemRecord.Id); this.activityStreamService.WriteChangesToStreamActivity(userId, item.Id, item.VersionRecord.Id, new ActivityStreamChangeItem[] { }, description, routeValueDictionary); } if (Request.IsAjaxRequest()) { return(this.Json(new { IsDone = true }, JsonRequestBehavior.AllowGet)); } else if (!string.IsNullOrEmpty(returnValue)) { return(Redirect(returnValue)); } else if (fileRecord != null) { return(this.RedirectToAction("Display", "Ticket", new { area = "Orchard.CRM.Core", id = fileRecord.ContentItemRecord.Id })); } else { return(this.RedirectToAction("Search", "Ticket", new { area = "Orchard.CRM.Core" })); } }