Beispiel #1
0
        public ActionResult Move(string folderPath, int[] mediaItemIds)
        {
            // check permission on destination folder
            if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, folderPath))
            {
                Services.Notifier.Error(T("Couldn't move media items"));
                return(new HttpUnauthorizedResult());
            }

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            foreach (var media in Services.ContentManager.Query().ForPart <MediaPart>().ForContentItems(mediaItemIds).List())
            {
                // don't try to rename the file if there is no associated media file
                if (!string.IsNullOrEmpty(media.FileName))
                {
                    // check permission on source folder
                    if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.DeleteMediaContent, media.FolderPath))
                    {
                        return(new HttpUnauthorizedResult());
                    }
                    var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
                    _mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
                    media.FileName = uniqueFilename;
                }

                media.FolderPath = folderPath;
            }

            return(Json(true));
        }
Beispiel #2
0
        public override void Submitted(FormSubmittedEventContext context)
        {
            foreach (var element in context.Form.Elements.Flatten())
            {
                var fileFieldElement = element as FileField;
                if (fileFieldElement == null)
                {
                    continue;
                }

                var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);
                if (postedFileValue == null)
                {
                    continue;
                }

                var postedFiles = (HttpPostedFileBase[])postedFileValue.RawValue;
                if (postedFiles == null && postedFiles.Length != 1)
                {
                    continue;
                }

                var folderPath   = _tokenizer.Replace(fileFieldElement.FilePath, new { });
                var uniqFileName = _mediaLibraryService.GetUniqueFilename(folderPath, postedFiles[0].FileName);
                var path         = _storageProvider.Combine(fileFieldElement.FilePath, uniqFileName);

                context.Values[fileFieldElement.Name + ":size"] = postedFiles[0].ContentLength.ToString();
                context.Values[fileFieldElement.Name]           = path;
                fileFieldElement.PostedValue = path;
            }
        }
        public ActionResult Move(string folderPath, int[] mediaItemIds)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't move media items")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!_mediaLibraryService.CanManageMediaFolder(folderPath))
            {
                return(new HttpUnauthorizedResult());
            }

            foreach (var media in Services.ContentManager.Query().ForPart <MediaPart>().ForContentItems(mediaItemIds).List())
            {
                // don't try to rename the file if there is no associated media file
                if (!string.IsNullOrEmpty(media.FileName))
                {
                    var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
                    _mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
                    media.FileName = uniqueFilename;
                }

                media.FolderPath = folderPath;
            }

            return(Json(true));
        }
        public ActionResult Clone(int mediaItemId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia))
            {
                Services.Notifier.Add(UI.Notify.NotifyType.Error, T("Couldn't clone media items"));
                return(new HttpUnauthorizedResult());
            }

            try {
                var media = Services.ContentManager.Get(mediaItemId).As <MediaPart>();

                if (!_mediaLibraryService.CheckMediaFolderPermission(Permissions.ImportMediaContent, media.FolderPath))
                {
                    return(Json(false));
                }

                var newFileName = _mediaLibraryService.GetUniqueFilename(media.FolderPath, media.FileName);

                var settings = Services.WorkContext.CurrentSite.As <MediaLibrarySettingsPart>();

                // skip file if the allowed extensions is defined and doesn't match
                if (!settings.IsFileAllowed(Path.GetFileName(newFileName)))
                {
                    return(Json(false));
                }

                _mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);

                var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
                var clonedMediaPart   = clonedContentItem.As <MediaPart>();
                var clonedTitlePart   = clonedContentItem.As <TitlePart>();

                clonedMediaPart.FileName   = newFileName;
                clonedMediaPart.FolderPath = media.FolderPath;
                clonedMediaPart.MimeType   = media.MimeType;
                clonedTitlePart.Title      = clonedTitlePart.Title + " Copy";
                Services.ContentManager.Create(clonedContentItem);
                Services.ContentManager.Publish(clonedContentItem);

                return(Json(true));
            }
            catch (Exception e) {
                Logger.Error(e, "Could not clone media item.");
                return(Json(false));
            }
        }
Beispiel #5
0
        public ActionResult Clone(int mediaItemId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageOwnMedia, T("Couldn't clone media items")))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                var media = Services.ContentManager.Get(mediaItemId).As <MediaPart>();

                if (!_mediaLibraryService.CanManageMediaFolder(media.FolderPath))
                {
                    return(new HttpUnauthorizedResult());
                }

                var newFileName = _mediaLibraryService.GetUniqueFilename(media.FolderPath, media.FileName);

                _mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);

                var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
                var clonedMediaPart   = clonedContentItem.As <MediaPart>();
                var clonedTitlePart   = clonedContentItem.As <TitlePart>();

                clonedMediaPart.FileName   = newFileName;
                clonedMediaPart.FolderPath = media.FolderPath;
                clonedMediaPart.MimeType   = media.MimeType;
                clonedTitlePart.Title      = clonedTitlePart.Title + " Copy";
                Services.ContentManager.Create(clonedContentItem);
                Services.ContentManager.Publish(clonedContentItem);

                return(Json(true));
            }
            catch (Exception e) {
                Logger.Error(e, "Could not clone media item.");
                return(Json(false));
            }
        }