public ActionResult Edit(string folderPath, string filename) { if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.EditMediaContent, folderPath)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } var media = Services.ContentManager.Query <MediaPart, MediaPartRecord>().Where(x => x.FolderPath == folderPath && x.FileName == filename).Slice(0, 1).FirstOrDefault(); if (media == null) { return(HttpNotFound()); } var contentItem = Services.ContentManager.New("ImageEditor").As <ImageEditorPart>(); contentItem.ImagePart = media.As <ImagePart>(); contentItem.MediaPart = media.As <MediaPart>(); var shape = Services.ContentManager.BuildDisplay(contentItem); shape.MediaContentItem(media.ContentItem); return(View(shape)); }
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 ImagePost(string folderPath, string type, string url) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } try { var buffer = new WebClient().DownloadData(url); var stream = new MemoryStream(buffer); var mediaPart = _mediaLibraryService.ImportMedia(stream, folderPath, Path.GetFileName(url), type); _contentManager.Create(mediaPart); return(new JsonResult { Data = new { folderPath, MediaPath = mediaPart.FileName } }); } catch (Exception e) { return(new JsonResult { Data = new { error = e.Message } }); } }
public static string GetRootedFolderPath(this IMediaLibraryService service, string folderPath) { var rootMediaFolder = service.GetRootMediaFolder(); if (rootMediaFolder != null) { return(service.Combine(rootMediaFolder.MediaPath, folderPath ?? "")); } return(folderPath); }
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 Index(string folderPath, string type) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } var viewModel = new ImportMediaViewModel { FolderPath = folderPath, Type = type }; 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 static bool CanManageMediaFolder(this IMediaLibraryService service, string folderPath) { // The current user can manage a media if he has access to the whole hierarchy // or the media is under his personal storage folder. var rootMediaFolder = service.GetRootMediaFolder(); if (rootMediaFolder == null) { return(true); } var mediaPath = service.Combine(folderPath, " ").Trim(); var rootPath = service.Combine(rootMediaFolder.MediaPath, " ").Trim(); return(mediaPath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase)); }
public ActionResult Upload(string folderPath, string type) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } var statuses = new List <object>(); // Loop through each file in the request for (int i = 0; i < HttpContext.Request.Files.Count; i++) { // Pointer to file var file = HttpContext.Request.Files[i]; var filename = Path.GetFileName(file.FileName); // if the file has been pasted, provide a default name if (file.ContentType.Equals("image/png", StringComparison.InvariantCultureIgnoreCase) && !filename.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { filename = "clipboard.png"; } var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type); _contentManager.Create(mediaPart); statuses.Add(new { id = mediaPart.Id, name = mediaPart.Title, type = mediaPart.MimeType, size = file.ContentLength, progress = 1.0, url = mediaPart.FileName, }); } // Return JSON return(Json(statuses, JsonRequestBehavior.AllowGet)); }
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 Upload(string folderPath, string type) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } var statuses = new List <object>(); var settings = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>(); var allowedExtensions = (settings.UploadAllowedFileTypeWhitelist ?? "") .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Where(x => x.StartsWith(".")); // Loop through each file in the request for (int i = 0; i < HttpContext.Request.Files.Count; i++) { // Pointer to file var file = HttpContext.Request.Files[i]; var filename = Path.GetFileName(file.FileName); // if the file has been pasted, provide a default name if (file.ContentType.Equals("image/png", StringComparison.InvariantCultureIgnoreCase) && !filename.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase)) { filename = "clipboard.png"; } // skip file if the allowed extensions is defined and doesn't match if (allowedExtensions.Any()) { if (!allowedExtensions.Any(e => filename.EndsWith(e, StringComparison.OrdinalIgnoreCase))) { statuses.Add(new { error = T("This file type is not allowed: {0}", Path.GetExtension(filename)).Text, progress = 1.0, }); continue; } } var mediaPart = _mediaLibraryService.ImportMedia(file.InputStream, folderPath, filename, type); Services.ContentManager.Create(mediaPart); statuses.Add(new { id = mediaPart.Id, name = mediaPart.Title, type = mediaPart.MimeType, size = file.ContentLength, progress = 1.0, url = mediaPart.FileName, }); } // Return JSON return(Json(statuses, JsonRequestBehavior.AllowGet)); }
public ActionResult IndexPOST(string folderPath, string url, string type, string title, string html, string thumbnail, string width, string height, string description) { if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia)) { return(new HttpUnauthorizedResult()); } // Check permission. var rootMediaFolder = _mediaLibraryService.GetRootMediaFolder(); if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent) && !_mediaLibraryService.CanManageMediaFolder(folderPath)) { return(new HttpUnauthorizedResult()); } var viewModel = new OEmbedViewModel { Url = url, FolderPath = folderPath }; var webClient = new WebClient { Encoding = Encoding.UTF8 }; try { // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed"> var source = webClient.DownloadString(url); // seek type="text/xml+oembed" or application/xml+oembed var oembedSignature = source.IndexOf("type=\"text/xml+oembed\"", StringComparison.OrdinalIgnoreCase); if (oembedSignature == -1) { oembedSignature = source.IndexOf("type=\"application/xml+oembed\"", StringComparison.OrdinalIgnoreCase); } if (oembedSignature != -1) { var tagStart = source.Substring(0, oembedSignature).LastIndexOf('<'); var tagEnd = source.IndexOf('>', oembedSignature); var tag = source.Substring(tagStart, tagEnd - tagStart); var matches = new Regex("href=\"([^\"]+)\"").Matches(tag); if (matches.Count > 0) { var href = matches[0].Groups[1].Value; try { var content = webClient.DownloadString(Server.HtmlDecode(href)); viewModel.Content = XDocument.Parse(content); } catch { // bubble exception } } } if (viewModel.Content == null) { viewModel.Content = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement("oembed") ); } var root = viewModel.Content.Root; if (!String.IsNullOrWhiteSpace(url)) { root.El("url", url); } if (!String.IsNullOrWhiteSpace(type)) { root.El("type", type.ToLowerInvariant()); } if (!String.IsNullOrWhiteSpace(title)) { root.El("title", title); } if (!String.IsNullOrWhiteSpace(html)) { root.El("html", html); } if (!String.IsNullOrWhiteSpace(thumbnail)) { root.El("thumbnail", thumbnail); } if (!String.IsNullOrWhiteSpace(width)) { root.El("width", width); } if (!String.IsNullOrWhiteSpace(height)) { root.El("height", height); } if (!String.IsNullOrWhiteSpace(description)) { root.El("description", description); } Response.AddHeader("X-XSS-Protection", "0"); // Prevents Chrome from freaking out over embedded preview } catch { return(View(viewModel)); } return(View(viewModel)); }