コード例 #1
0
    void elemEdit_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            CMSPage.RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }
    }
コード例 #2
0
    /// <summary>
    /// Deletes media library. Called when the "Delete library" button is pressed.
    /// Expects the CreateMediaLibrary method to be run first.
    /// </summary>
    private bool DeleteMediaLibrary()
    {
        // Get the media library
        MediaLibraryInfo deleteLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        // Delete the media library
        MediaLibraryInfoProvider.DeleteMediaLibraryInfo(deleteLibrary);

        return(deleteLibrary != null);
    }
コード例 #3
0
    /// <summary>
    /// Returns direct URL to the media file, user permissions are not checked.
    /// </summary>
    /// <param name="libraryId">Media library ID</param>
    /// <param name="filePath">File path</param>
    public static string GetMediaFileDirectUrl(object libraryId, object filePath)
    {
        MediaLibraryInfo libInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(ValidationHelper.GetInteger(libraryId, 0));

        if (libInfo != null)
        {
            return(MediaFileInfoProvider.GetMediaFileUrl(CMSContext.CurrentSiteName, libInfo.LibraryFolder, filePath.ToString()));
        }
        return(String.Empty);
    }
コード例 #4
0
        /// <summary>
        /// Returns a direct path for the given media file.
        /// The method can return the following URL types:
        ///   ~/mediaLibraryFolder/filename.extension
        ///   ~/getazurefile.aspx?path=, ~/getmazonfile.aspx?path= ...
        ///   http://CDN/mediaLibraryFolder/filename.extension
        /// </summary>
        private static string GetDirectPath(MediaFileInfo mediaFile, SiteInfo mediaFileSite)
        {
            var mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaFile.FileLibraryID);

            if ((mediaLibrary != null) && (mediaFileSite != null))
            {
                return(MediaFileInfoProvider.GetMediaFileUrl(mediaFileSite.SiteName, mediaLibrary.LibraryFolder, mediaFile.FilePath));
            }

            return(null);
        }
コード例 #5
0
        /// <inheritdoc/>
        public void DeleteMediaFolder(int librarySiteID, string libraryName, string folderName)
        {
            // Gets the media library
            string siteName        = SiteInfoProvider.GetSiteName(librarySiteID);
            var    existingLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryName, siteName);

            if (existingLibrary != null)
            {
                // Deletes the "NewFolder" folder within the media library
                MediaLibraryInfoProvider.DeleteMediaLibraryFolder(siteName, existingLibrary.LibraryID, folderName, false);
            }
        }
コード例 #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }
        EditedObject = mli;

        elemEdit.MediaLibraryID      = mli.LibraryID;
        elemEdit.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(elemEdit_OnCheckPermissions);
    }
コード例 #7
0
    private void libraryElem_OnCheckPermissions(string permissionType, CMSAdminControl sender)
    {
        MediaLibraryInfo MediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryId);

        if (permissionType.ToLowerCSafe() == "read")
        {
            // Check 'Read' permission
            if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(MediaLibrary, permissionType))
            {
                RedirectToAccessDenied("cms.medialibrary", "Read");
            }
        }
    }
コード例 #8
0
        /// <summary>
        /// Retrieves media files with the .jpg extension from the 'SampleMediaLibrary'.
        /// </summary>
        public ActionResult ShowMediaFiles()
        {
            //DocSection:GetMediaFiles
            // Creates an instance of the 'SampleMediaLibrary' media library for the current site
            MediaLibraryInfo mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("SampleMediaLibrary", SiteContext.CurrentSiteName);

            // Gets a collection of media files with the .jpg extension from the media library
            IEnumerable <MediaFileInfo> mediaLibraryFiles = MediaFileInfoProvider.GetMediaFiles()
                                                            .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                                                            .WhereEquals("FileExtension", ".jpg");

            //EndDocSection:GetMediaFiles

            return(View(mediaLibraryFiles));
        }
コード例 #9
0
 /// <summary>
 /// Initializes the breadcrumbs controls.
 /// </summary>
 private void InitializeBreadcrumbs()
 {
     if (LibraryID > 0)
     {
         MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryID);
         if (library != null)
         {
             lblEditBack.Text = " <span class=\"TitleBreadCrumbSeparator\">&nbsp;</span> " + HTMLHelper.HTMLEncode(library.LibraryDisplayName);
         }
     }
     else
     {
         lblEditBack.Text = " <span class=\"TitleBreadCrumbSeparator\">&nbsp;</span> " + GetString("Group_General.MediaLibrary.NewLibrary");
     }
 }
コード例 #10
0
    /// <summary>
    /// Deletes media folder. Called when the "Delete folder" button is pressed.
    /// Expects the CreateMediaFolder method to be run first.
    /// </summary>
    private bool DeleteMediaFolder()
    {
        // Get media library
        MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        if (library != null)
        {
            // Delete new media folder object
            MediaLibraryInfoProvider.DeleteMediaLibraryFolder(CurrentSiteName, library.LibraryID, "MyNewFolder", false);

            return(true);
        }

        return(false);
    }
コード例 #11
0
    /// <summary>
    /// Creates department media library.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentMediaLibrary(TreeNode departmentNode)
    {
        // Set general values
        string departmentName = departmentNode.GetDocumentName();
        string codeName       = "Department_" + departmentNode.NodeGUID;
        string suffix         = "";

        // Check if library with same name already exists
        MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName);

        if (mlInfo != null)
        {
            return;
        }

        // Create new object (record) if needed
        mlInfo = new MediaLibraryInfo();

        suffix = " media library";
        mlInfo.LibraryDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        mlInfo.LibraryFolder      = departmentNode.NodeAlias;
        mlInfo.LibraryDescription = "Media library for " + departmentName + " department.";
        mlInfo.LibraryName        = codeName;
        mlInfo.LibrarySiteID      = CMSContext.CurrentSiteID;

        // Set security
        mlInfo.FileCreate   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileDelete   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileModify   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderCreate = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderDelete = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderModify = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.Access       = SecurityAccessEnum.AuthorizedRoles;

        try
        {
            MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo);
        }
        catch
        {
            return;
        }

        // Create additional folders
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Other", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false);
    }
コード例 #12
0
    /// <summary>
    /// Creates group media library.
    /// </summary>
    /// <param name="group">Particular group info object</param>
    private void CreateGroupMediaLibrary(GroupInfo group)
    {
        // Set general values
        string codeName = "Library_group_" + group.GroupGUID;

        // Check if library with same name already exists
        MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName);

        if (mlInfo != null)
        {
            return;
        }
        else
        {
            // Create new object (record) if needed
            mlInfo = new MediaLibraryInfo();
            string suffix = " media";
            mlInfo.LibraryDisplayName = TextHelper.LimitLength(group.GroupDisplayName, 200 - suffix.Length, "") + suffix;
            mlInfo.LibraryFolder      = group.GroupName;
            mlInfo.LibraryName        = codeName;
            mlInfo.LibraryDescription = "";
            mlInfo.LibraryGroupID     = group.GroupID;
            mlInfo.LibrarySiteID      = CMSContext.CurrentSiteID;

            // Set security
            mlInfo.FileCreate   = SecurityAccessEnum.GroupMembers;
            mlInfo.FileDelete   = SecurityAccessEnum.GroupMembers;
            mlInfo.FileModify   = SecurityAccessEnum.GroupMembers;
            mlInfo.FolderCreate = SecurityAccessEnum.GroupMembers;
            mlInfo.FolderDelete = SecurityAccessEnum.GroupMembers;
            mlInfo.FolderModify = SecurityAccessEnum.GroupMembers;
            mlInfo.Access       = SecurityAccessEnum.GroupMembers;

            try
            {
                MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo);
            }
            catch
            {
                return;
            }

            // Create additional folders
            //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false);
            //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Other", false);
            //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false);
        }
    }
コード例 #13
0
        public IEnumerable <MediaLibraryFileDto> GetMediaLibraryFiles(string folder, string siteName,
                                                                      params string[] extensions)
        {
            var mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(folder, siteName);

            if (mediaLibrary == null)
            {
                return(Enumerable.Empty <MediaLibraryFileDto>());
            }

            return(MediaFileInfoProvider.GetMediaFiles()
                   .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                   .WhereIn("FileExtension", extensions)
                   .ToList()
                   .Select(mf => _mapper.Map <MediaLibraryFileDto>(mf)));
        }
コード例 #14
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControlLoad()
    {
        // Handle filter change event
        if (this.DataSourceControl != null)
        {
            this.DataSourceControl.OnFilterChanged += new ActionEventHandler(DataSourceControl_OnFilterChanged);
        }

        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(this.MediaLibraryName, CMSContext.CurrentSiteName);

        if (mli != null)
        {
            this.mMediaLibraryRoot = MediaLibraryHelper.GetMediaRootFolderPath(CMSContext.CurrentSiteName) + mli.LibraryFolder;
            this.mMediaLibraryUrl  = URLHelper.GetAbsoluteUrl("~/" + CMSContext.CurrentSiteName + "/media/" + mli.LibraryFolder);
        }
        this.repItems.ItemDataBound += new RepeaterItemEventHandler(repItems_ItemDataBound);
    }
コード例 #15
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControlLoad()
    {
        // Handle filter change event
        if (DataSourceControl != null)
        {
            DataSourceControl.OnFilterChanged += DataSourceControl_OnFilterChanged;
        }

        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(MediaLibraryName, SiteContext.CurrentSiteName);

        if (mli != null)
        {
            mMediaLibraryRoot = MediaLibraryHelper.GetMediaRootFolderPath(SiteContext.CurrentSiteName) + mli.LibraryFolder;
            mMediaLibraryUrl  = URLHelper.GetAbsoluteUrl("~/" + SiteContext.CurrentSiteName + "/media/" + mli.LibraryFolder);
        }
        repItems.ItemDataBound += repItems_ItemDataBound;
    }
コード例 #16
0
    /// <summary>
    /// Returns direct URL to the media file, user permissions are not checked.
    /// </summary>
    /// <param name="libraryId">Media library ID</param>
    /// <param name="filePath">File path</param>
    /// <param name="fileGuid">File GUID</param>
    /// <param name="fileName">File name</param>
    /// <param name="useSecureLinks">Generate secure link</param>
    public static string GetMediaFileUrl(object libraryId, object filePath, object fileGuid, object fileName, object useSecureLinks)
    {
        MediaLibraryInfo libInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(ValidationHelper.GetInteger(libraryId, 0));

        if (libInfo != null)
        {
            if (ValidationHelper.GetBoolean(useSecureLinks, true))
            {
                return(MediaFileInfoProvider.GetMediaFileUrl(ValidationHelper.GetGuid(fileGuid, Guid.Empty), fileName.ToString()));
            }
            else
            {
                return(MediaFileInfoProvider.GetMediaFileUrl(CMSContext.CurrentSiteName, libInfo.LibraryFolder, filePath.ToString()));
            }
        }
        return(String.Empty);
    }
コード例 #17
0
    /// <summary>
    /// Gets and updates media library. Called when the "Get and update library" button is pressed.
    /// Expects the CreateMediaLibrary method to be run first.
    /// </summary>
    private bool GetAndUpdateMediaLibrary()
    {
        // Get the media library
        MediaLibraryInfo updateLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);

        if (updateLibrary != null)
        {
            // Update the property
            updateLibrary.LibraryDisplayName = updateLibrary.LibraryDisplayName.ToLower();

            // Update the media library
            MediaLibraryInfoProvider.SetMediaLibraryInfo(updateLibrary);

            return(true);
        }

        return(false);
    }
コード例 #18
0
        public IEnumerable <MediaLibraryFileDto> GetMediaLibraryFiles(string folder, string sitename, params string[] extensions)
        {
            // Gets an instance of the media library for the current site
            var mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(folder, sitename);

            // Gets a collection of media files and their extensions from the media library
            return(MediaFileInfoProvider.GetMediaFiles()
                   .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                   .WhereIn("FileExtension", extensions)
                   .ToList()
                   .Select(m => new MediaLibraryFileDto()
            {
                Title = m.FileTitle,
                Extension = m.FileExtension,
                DirectUrl = MediaLibraryHelper.GetDirectUrl(m),
                PermanentUrl = MediaLibraryHelper.GetPermanentUrl(m)
            }));
        }
コード例 #19
0
        private static void AssignImage(SKUTreeNode product, string mediaLibraryName, string imagePath)
        {
            var library = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaLibraryName, SiteContext.CurrentSiteName);

            if (library == null)
            {
                throw new KeyNotFoundException($"Unable to assign image to SKU '{product.SKU.SKUNumber}'. Media library '{mediaLibraryName}' not found.");
            }

            var image = MediaFileInfoProvider.GetMediaFileInfo(library.LibraryID, imagePath);

            if (image == null)
            {
                throw new KeyNotFoundException($"Unable to assign image to SKU '{product.SKU.SKUNumber}'. File '{imagePath}' not found.");
            }

            product.RemoveImage();
            product.SetImage(image);
        }
コード例 #20
0
 /// <summary>
 /// Delete Image by Guid
 /// </summary>
 /// <param name="imageGuid"></param>
 public static void DeleteImage(string imagePath, string folderName)
 {
     try
     {
         MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo(!string.IsNullOrEmpty(folderName) ? folderName : "CampaignProducts", SiteContext.CurrentSiteName);
         if (!DataHelper.DataSourceIsEmpty(library))
         {
             MediaFileInfo deleteFile = MediaFileInfoProvider.GetMediaFileInfo(SiteContext.CurrentSiteName, imagePath, !string.IsNullOrEmpty(folderName) ? folderName : "CampaignProducts");
             if (!DataHelper.IsEmpty(deleteFile))
             {
                 MediaFileInfoProvider.DeleteMediaFileInfo(deleteFile);
             }
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("UploadImage", "DeleteImage", ex, SiteContext.CurrentSite.SiteID, ex.Message);
     }
 }
コード例 #21
0
        /// <summary>
        /// Insert image to Media Library
        /// </summary>
        /// <param name="productImage"></param>
        /// <returns></returns>
        public static string UploadImageToMeadiaLibrary(FileUpload productImage, string folderName)
        {
            string imagePath = string.Empty;

            try
            {
                string folderPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/");
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                string filePath = Path.GetFileName(productImage.PostedFile.FileName);
                productImage.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + filePath));
                MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo(!string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "CampaignProducts", SiteContext.CurrentSiteName);
                if (library == null)
                {
                    CreateMeadiaLiabrary(folderName);
                    library = MediaLibraryInfoProvider.GetMediaLibraryInfo(!string.IsNullOrEmpty(folderName) ? folderName.Replace(" ", "") : "CampaignProducts", SiteContext.CurrentSiteName);
                }
                filePath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + filePath);
                CMS.IO.FileInfo file = CMS.IO.FileInfo.New(filePath);
                if (file != null)
                {
                    MediaFileInfo mediaFile = new MediaFileInfo(filePath, library.LibraryID);
                    mediaFile.FileName      = Path.GetFileNameWithoutExtension(productImage.PostedFile.FileName);
                    mediaFile.FileTitle     = Path.GetFileNameWithoutExtension(productImage.PostedFile.FileName);
                    mediaFile.FilePath      = "Images/";
                    mediaFile.FileExtension = file.Extension;
                    mediaFile.FileMimeType  = MimeTypeHelper.GetMimetype(file.Extension);
                    mediaFile.FileSiteID    = SiteContext.CurrentSiteID;
                    mediaFile.FileLibraryID = library.LibraryID;
                    mediaFile.FileSize      = file.Length;
                    MediaFileInfoProvider.SetMediaFileInfo(mediaFile);
                    File.Delete(filePath);
                    imagePath = MediaFileURLProvider.GetMediaFileUrl(mediaFile.FileGUID, mediaFile.FileName);
                }
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("UploadImage", "UploadImageToMeadiaLibrary", ex, SiteContext.CurrentSite.SiteID, ex.Message);
            }
            return(imagePath);
        }
コード例 #22
0
 /// <summary>
 /// Initializes the control properties.
 /// </summary>
 protected void SetupControl()
 {
     if (StopProcessing)
     {
         this.uploader.StopProcessing = true;
     }
     else
     {
         MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(this.LibraryName, CMSContext.CurrentSiteName);
         if (mli != null)
         {
             this.uploader.LibraryID           = mli.LibraryID;
             this.uploader.DestinationPath     = this.DestinationPath;
             this.uploader.EnableUploadPreview = this.EnableUploadPreview;
             this.uploader.PreviewSuffix       = this.PreviewSuffix;
             this.uploader.OnNotAllowed       += new CMS.UIControls.CMSAdminControl.NotAllowedEventHandler(uploader_OnNotAllowed);
         }
     }
 }
コード例 #23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        mediafileGuid = QueryHelper.GetGuid("mediafileguid", Guid.Empty);
        isPreview     = QueryHelper.GetBoolean("isPreview", false);

        // Get media file information
        if (mfi == null)
        {
            mfi = MediaFileInfoProvider.GetMediaFileInfo(mediafileGuid, CurrentSiteName);
        }

        if (mfi != null)
        {
            // Get media library information
            MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(mfi.FileLibraryID);

            if (mli != null)
            {
                // Get path to media file folder
                string path = Path.GetDirectoryName(DirectoryHelper.CombinePath(MediaLibraryInfoProvider.GetMediaLibraryFolderPath(mli.LibraryID), mfi.FilePath));

                // Enable control if permissions are sufficient to edit image
                Enabled = DirectoryHelper.CheckPermissions(path, false, true, true, true);

                if (!Enabled)
                {
                    // Set error message
                    baseImageEditor.LblLoadFailed.Visible        = true;
                    baseImageEditor.LblLoadFailed.ResourceString = "img.errors.filesystempermissions";
                }
            }
        }

        // Enable or disable image editor
        baseImageEditor.Enabled = Enabled;

        baseImageEditor.LoadImageType        += new CMSAdminControls_ImageEditor_BaseImageEditor.OnLoadImageType(baseImageEditor_LoadImageType);
        baseImageEditor.InitializeProperties += new CMSAdminControls_ImageEditor_BaseImageEditor.OnInitializeProperties(baseImageEditor_InitializeProperties);
        baseImageEditor.InitializeLabels     += new CMSAdminControls_ImageEditor_BaseImageEditor.OnInitializeLabels(baseImageEditor_InitializeLabels);
        baseImageEditor.SaveImage            += new CMSAdminControls_ImageEditor_BaseImageEditor.OnSaveImage(baseImageEditor_SaveImage);
        baseImageEditor.GetMetaData          += new CMSAdminControls_ImageEditor_BaseImageEditor.OnGetMetaData(baseImageEditor_GetMetaData);
        baseImageEditor.LoadImageUrl         += new CMSAdminControls_ImageEditor_BaseImageEditor.OnLoadImageUrl(baseImageEditor_LoadImageUrl);
    }
コード例 #24
0
 /// <summary>
 /// Initializes the control properties.
 /// </summary>
 protected void SetupControl()
 {
     if (StopProcessing)
     {
         uploader.StopProcessing = true;
     }
     else
     {
         MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryName, SiteContext.CurrentSiteName);
         if (mli != null)
         {
             uploader.LibraryID           = mli.LibraryID;
             uploader.DestinationPath     = DestinationPath;
             uploader.EnableUploadPreview = EnableUploadPreview;
             uploader.PreviewSuffix       = PreviewSuffix;
             uploader.OnNotAllowed       += uploader_OnNotAllowed;
         }
     }
 }
コード例 #25
0
        public static ISearchDocument GetSearchDocument(MediaFileInfo fileInfo, SearchIndexInfo indexInfo)
        {
            var contentBuilder = new StringBuilder();

            contentBuilder.Append(GetContent(fileInfo) + SEPARATOR);

            var doc = CMS.Search.SearchHelper.CreateDocument(new SearchDocumentParameters
            {
                Index   = indexInfo,
                Type    = CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX,
                Id      = fileInfo.FileID.ToString(),
                Created = fileInfo.FileCreatedWhen
            });
            var keywords     = fileInfo.GetValue("FileKeywords")?.ToString() ?? string.Empty;
            var mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(fileInfo.FileLibraryID);

            contentBuilder.Append(fileInfo.FileTitle + SEPARATOR);
            contentBuilder.Append(fileInfo.FileDescription + SEPARATOR);
            contentBuilder.Append(fileInfo.FileCustomData + SEPARATOR);
            contentBuilder.Append(fileInfo.FileName + SEPARATOR);
            contentBuilder.Append(keywords + SEPARATOR);

            CMS.Search.SearchHelper.AddGeneralField(doc, SearchFieldsConstants.CONTENT, HTMLHelper.HtmlToPlainText(contentBuilder.ToString()), false, true);
            CMS.Search.SearchHelper.AddGeneralField(doc, "Keywords", keywords, true, true);

            CMS.Search.SearchHelper.AddGeneralField(doc, SearchFieldsConstants.CUSTOM_TITLE, fileInfo.FileName, true, false, true);
            CMS.Search.SearchHelper.AddGeneralField(doc, SearchFieldsConstants.CUSTOM_DATE, fileInfo.FileCreatedWhen, true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, SearchFieldsConstants.CUSTOM_IMAGEURL, MediaLibraryHelper.GetMediaFileUrl(fileInfo.FileGUID, SiteInfoProvider.GetSiteInfo(fileInfo.FileSiteID).SiteName), true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileName), fileInfo.FileName, true, false, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileDescription), fileInfo.FileDescription, true, false, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileGUID), fileInfo.FileGUID, true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileLibraryID), fileInfo.FileLibraryID.ToString(), true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FilePath), fileInfo.FilePath, true, false, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileMimeType), fileInfo.FileMimeType, true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileImageWidth), fileInfo.FileImageWidth.ToString(), true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileImageHeight), fileInfo.FileImageHeight.ToString(), true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaFileInfo.FileSize), fileInfo.FileSize, true, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaLibraryInfo.LibraryDisplayName), mediaLibrary.LibraryDisplayName, true, false, false);
            CMS.Search.SearchHelper.AddGeneralField(doc, nameof(MediaLibraryInfo.LibraryFolder), mediaLibrary.LibraryFolder, true, false, false);

            return(doc);
        }
コード例 #26
0
        private void EnsureLibrary()
        {
            var siteName = SiteInfoProvider.GetSiteInfo(SiteId).SiteName;

            _mediaLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryName, siteName);
            if (_mediaLibrary == null)
            {
                _mediaLibrary = new MediaLibraryInfo()
                {
                    LibraryDisplayName = LibraryName,
                    LibraryName        = LibraryName,
                    LibraryDescription = LibraryDescription,
                    LibraryFolder      = LibraryFolder,
                    LibrarySiteID      = SiteId,
                    Access             = CMS.Helpers.SecurityAccessEnum.AuthenticatedUsers
                };

                MediaLibraryInfoProvider.SetMediaLibraryInfo(_mediaLibrary);
            }
        }
コード例 #27
0
    /// <summary>
    /// Returns a value indicating whether the specified media library code name is unique.
    /// </summary>
    /// <param name="codeName">A code name of the media library.</param>
    private bool IsCodeNameUnique(string codeName)
    {
        MediaLibraryInfo library = null;

        if (MediaLibraryGroupID > 0)
        {
            library = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteID, MediaLibraryGroupID);
        }
        else
        {
            library = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName);
        }

        if ((library != null) && (library.LibraryID != MediaLibraryID))
        {
            return(false);
        }

        return(true);
    }
        protected override void SetMediaFileInfoInternal(
            MediaFileInfo mediaFile,
            bool saveFileToDisk,
            int userId,
            bool ensureUniqueFileName)
        {
            base.SetMediaFileInfoInternal(mediaFile, saveFileToDisk, userId, ensureUniqueFileName);

            var compressor        = CompressorFactory.GetCompressor(mediaFile.FileMimeType);
            var libraryFolderPath = MediaLibraryInfoProvider.GetMediaLibraryFolderPath(mediaFile.FileLibraryID);

            if (compressor != null && libraryFolderPath != null)
            {
                var siteInfo    = SiteContext.CurrentSite;
                var libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(mediaFile.FileLibraryID);
                var filePath    = Path.Combine(libraryFolderPath, mediaFile.FilePath);
                var result      = compressor.Compress(filePath, true);
                mediaFile.FileSize = result.FileSizeInBytes;
                base.SetMediaFileInfoInternal(mediaFile, false, userId, ensureUniqueFileName);
            }
        }
コード例 #29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(libraryId);

        EditedObject = mli;

        // Check 'Read' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            RedirectToAccessDenied("cms.medialibrary", "Read");
        }

        // Check 'Manage' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Manage"))
        {
            librarySecurity.Enable = false;
        }

        librarySecurity.MediaLibraryID      = libraryId;
        librarySecurity.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(librarySecurity_OnCheckPermissions);
    }
コード例 #30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(QueryHelper.GetInteger("libraryid", 0));

        EditedObject = mli;

        // Check 'Read' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Read"))
        {
            CMSPage.RedirectToCMSDeskAccessDenied("cms.medialibrary", "Read");
        }

        // Check 'Manage' permission
        if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "Manage"))
        {
            this.librarySecurity.Enable = false;
        }

        this.librarySecurity.MediaLibraryID      = QueryHelper.GetInteger("libraryid", 0);
        this.librarySecurity.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(librarySecurity_OnCheckPermissions);
    }