public override void LoadProperties(Hashtable properties) { if (properties != null) { // Display the properties pnlEmpty.Visible = false; pnlTabs.CssClass = "Dialog_Tabs"; #region "Image general tab" // Display size selector only if required or image string ext = ValidationHelper.GetString(properties[DialogParameters.URL_EXT], ""); CurrentIsImage = ImageHelper.IsImage(ext); CurrentIsMedia = !CurrentIsImage ? (MediaHelper.IsAudioVideo(ext) || MediaHelper.IsFlash(ext)) : false; if (tabImageGeneral.Visible) { string url = ValidationHelper.GetString(properties[DialogParameters.URL_URL], ""); string fileName = ValidationHelper.GetString(properties[DialogParameters.FILE_NAME], ""); long fileSize = ValidationHelper.GetLong(properties[DialogParameters.FILE_SIZE], 0); lblUrlText.Text = url; lblNameText.Text = AttachmentHelper.GetFullFileName(Path.GetFileNameWithoutExtension(fileName), ext); if ((plcSizeArea.Visible = CurrentIsImage)) { lblSizeText.Text = DataHelper.GetSizeString(fileSize); } ViewState[DialogParameters.IMG_SIZETOURL] = ValidationHelper.GetBoolean(properties[DialogParameters.IMG_SIZETOURL], false); } #endregion #region "General items" ViewState[DialogParameters.URL_EXT] = (properties[DialogParameters.URL_EXT] != null ? ValidationHelper.GetString(properties[DialogParameters.URL_EXT], "") : ValidationHelper.GetString(properties[DialogParameters.IMG_EXT], "")); ViewState[DialogParameters.URL_URL] = ValidationHelper.GetString(properties[DialogParameters.URL_URL], ""); EditorClientID = ValidationHelper.GetString(properties[DialogParameters.EDITOR_CLIENTID], ""); #endregion } }
/// <summary> /// Page pre render event /// </summary> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if ((FileInfo != null) && (LibraryInfo != null) && HasPreview) { plcPreview.Visible = true; string fileName = AttachmentHelper.GetFullFileName(FileInfo.FileName, FileInfo.FileExtension); string permanentUrl = MediaFileURLProvider.GetMediaFileUrl(FileInfo.FileGUID, fileName); permanentUrl = URLHelper.UpdateParameterInUrl(permanentUrl, "preview", "1"); lblPreviewPermaLink.Text = GetFileLinkHtml(permanentUrl, LibraryInfo.LibrarySiteID); if (MediaLibraryHelper.IsExternalLibrary(SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder)) { plcPrevDirPath.Visible = false; } else { plcPrevDirPath.Visible = true; var directUrl = GetPreviewDirectPath(); lblPrevDirectLinkVal.Text = GetFileLinkHtml(directUrl, LibraryInfo.LibrarySiteID); } } else { lblNoPreview.Text = GetString("media.file.nothumb"); plcNoPreview.Visible = true; plcPreview.Visible = false; } pnlUpdatePreviewDetails.Update(); // Refresh versions tab if selected and reload was forced if (mForceReload && (pnlTabs.SelectedTabIndex == tabVersions.Index)) { ScriptHelper.RegisterStartupScript(this, typeof(string), "ReloadVersionsTab", "$cmsj(\"#" + objectVersionList.RefreshButton.ClientID + "\").click();", true); } }
/// <summary> /// Initializes the control properties. /// </summary> public void ReloadData(bool forceReload) { if (binded && !forceReload) { return; } if (mData != null) { MediaFileInfo mfi = new MediaFileInfo(mData); SiteInfo currentSite = SiteContext.CurrentSite; SiteInfo si = mfi.FileSiteID == currentSite.SiteID ? currentSite : SiteInfo.Provider.Get(mfi.FileSiteID); if (si != null) { if (DisplayActiveContent) { string url = ""; // Complete URL only for other site than current bool completeUrl = (si.SiteID != currentSite.SiteID); if (UseSecureLinks) { string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension); url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName) : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName); } else { MediaLibraryInfo li = MediaLibraryInfo.Provider.Get(mfi.FileLibraryID); if (li != null) { url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath) : MediaFileURLProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } } url = UrlResolver.ResolveUrl(url); if (ImageHelper.IsImage(mfi.FileExtension) && File.Exists(MediaFileInfoProvider.GetMediaFilePath(mfi.FileLibraryID, mfi.FilePath))) { // Get new dimensions int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mfi.FileImageWidth, mfi.FileImageHeight); // If dimensions changed use secure link if ((newDims[0] != mfi.FileImageWidth) || (newDims[1] != mfi.FileImageHeight)) { string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension); url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName) : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName); url = UrlResolver.ResolveUrl(url); } else { // Use width and height from properties in case dimensions are bigger than original newDims[0] = Width; newDims[1] = Height; } // Initialize image parameters ImageParameters imgParams = new ImageParameters(); imgParams.Alt = mfi.FileDescription; imgParams.Width = newDims[0]; imgParams.Height = newDims[1]; imgParams.Url = url; ltlOutput.Text = MediaHelper.GetImage(imgParams); } else if (MediaHelper.IsAudioVideo(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters audioVideoParams = new AudioVideoParameters(); audioVideoParams.SiteName = SiteContext.CurrentSiteName; audioVideoParams.Url = url; audioVideoParams.Width = Width; audioVideoParams.Height = Height; audioVideoParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(audioVideoParams); } else { ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } else { ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } } binded = true; }
/// <summary> /// Returns URL of the media item according site settings. /// </summary> /// <param name="fileInfo">File info object</param> /// <param name="site">Information on site file belongs to</param> /// <param name="fileGuid">GUID of the file URL is generated for</param> /// <param name="fileName">Name of the file URL is generated for</param> /// <param name="fileExtension">Extension of the file URL is generated for</param> /// <param name="filePath">Media file path of the file URL is generated for</param> /// <param name="isPreview">Indicates whether the file URL is generated for preview</param> /// <param name="height">Specifies height of the image</param> /// <param name="width">Specifies width of the image</param> /// <param name="maxSideSize">Maximum dimension for images displayed for thumbnails view</param> public string GetItemUrl(MediaFileInfo fileInfo, SiteInfo site, Guid fileGuid, string fileName, string fileExtension, string filePath, bool isPreview, int height, int width, int maxSideSize) { string mediaFileUrl; bool resize = (maxSideSize > 0); fileName = AttachmentHelper.GetFullFileName(fileName, fileExtension); bool generateAbsoluteURL = Config?.UseFullURL ?? false; generateAbsoluteURL = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseMediaFileAbsoluteURLs"], generateAbsoluteURL); bool isDifferentSite = false; if (generateAbsoluteURL || (isDifferentSite = IsLibrarySiteDifferentThanCurrentSite())) { if (site.SiteIsContentOnly && isDifferentSite) { mediaFileUrl = UsePermanentUrls ? MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName) : MediaFileURLProvider.GetMediaFileUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath); mediaFileUrl = URLHelper.CombinePath(mediaFileUrl, '/', site.SitePresentationURL, null); } else if (UsePermanentUrls || resize || isPreview) // If permanent URLs should be generated { // URL in format 'http://domainame/getmedia/123456-25245-45454-45455-5455555545/testfile.gif' mediaFileUrl = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, fileGuid, fileName); } else { // URL in format 'http://domainame/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif' mediaFileUrl = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath); } } else { if (UsePermanentUrls || resize || isPreview) { // URL in format '/cms/getmedia/123456-25245-45454-45455-5455555545/testfile.gif' mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName); } else { if (fileInfo != null) { mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(fileInfo, SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder); } else { // URL in format '/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif' mediaFileUrl = MediaFileURLProvider.GetMediaFileUrl(SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder, filePath); } } } // If image dimensions are specified if (resize) { mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "maxsidesize", maxSideSize.ToString()); } if (height > 0) { mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "height", height.ToString()); } if (width > 0) { mediaFileUrl = URLHelper.AddParameterToUrl(mediaFileUrl, "width", width.ToString()); } // Media selector should returns non-resolved URL in all cases bool isMediaSelector = (OutputFormat == OutputFormatEnum.URL) && (SelectableContent == SelectableContentEnum.OnlyMedia); return((isMediaSelector || ((Config != null) && Config.ContentUseRelativeUrl)) ? mediaFileUrl : UrlResolver.ResolveUrl(mediaFileUrl)); }
/// <summary> /// Returns URL of the media item according site settings. /// </summary> /// <param name="argument">Argument containing information on current media item</param> /// <param name="data">Data row object holding all the data on the current file</param> /// <param name="isPreview">Indicates whether the file has a preview file or not</param> /// <param name="height">Specifies height of the image</param> /// <param name="width">Specifies width of the image</param> /// <param name="maxSideSize">Specifies maximum size of the image</param> private string GetItemUrlInternal(string argument, IDataContainer data, bool isPreview, int height, int width, int maxSideSize) { MediaFileInfo mfi = null; // Get filename with extension string fileName; if (data.ContainsColumn("FileExtension")) { string ext = ValidationHelper.GetString(data.GetValue("FileExtension"), ""); // In format 'name' fileName = ValidationHelper.GetString(data.GetValue("FileName"), ""); fileName = AttachmentHelper.GetFullFileName(fileName, ext); } else { // In format 'name.ext' fileName = data.GetValue("FileName").ToString(); } // Try to get imported data row DataRow importedRow = GetInformationInternal("fileisnotindatabase", fileName) as DataRow; if (importedRow != null) { mfi = new MediaFileInfo(importedRow); } // If data row is not from DB check external library if (!data.ContainsColumn("FileGUID")) { bool isExternal = false; // Check if is external media library if (data.ContainsColumn("FilePath")) { // Get file path string filePath = ValidationHelper.GetString(data.GetValue("FilePath"), String.Empty); if (!String.IsNullOrEmpty(filePath)) { // Test if file path is inside system root folder string rootPath = Server.MapPath("~/"); if (!filePath.StartsWithCSafe(rootPath)) { isExternal = true; } } } if (isExternal && data.ContainsColumn("FileName")) { return(mfi != null ? GetItemUrl(mfi, isPreview, height, width, maxSideSize) : String.Empty); } } // Files are obtained from the FS if (data.ContainsColumn("FileURL")) { // Information comming from FileSystem (FS) return(URLHelper.GetAbsoluteUrl(data.GetValue("FileURL").ToString())); } else { return(mfi != null ? GetItemUrl(mfi, isPreview, height, width, maxSideSize) : GetItemUrl(argument, isPreview, height, width, maxSideSize)); } }
/// <summary> /// Setup general values. /// </summary> private void SetupFile() { // Get file and library info if ((FileInfo != null) && (LibraryInfo != null)) { formMediaFileCustomFields.IsLiveSite = IsLiveSite; if (MediaLibraryHelper.IsExternalLibrary(SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder)) { plcDirPath.Visible = false; } else { string url = MediaFileURLProvider.GetMediaFileUrl(LibrarySiteInfo.SiteName, LibraryInfo.LibraryFolder, FileInfo.FilePath); ltrDirPathValue.Text = GetFileLinkHtml(ResolveUrl(url)); } var permanentUrl = MediaFileURLProvider.GetMediaFileUrl(FileInfo.FileGUID, AttachmentHelper.GetFullFileName(FileInfo.FileName, FileInfo.FileExtension)); ltrPermaLinkValue.Text = GetFileLinkHtml(ResolveUrl(permanentUrl)); if (ImageHelper.IsImage(FileInfo.FileExtension)) { // Ensure max side size 200 int[] maxsize = ImageHelper.EnsureImageDimensions(0, 0, 200, FileInfo.FileImageWidth, FileInfo.FileImageHeight); imagePreview.Width = maxsize[0]; imagePreview.Height = maxsize[1]; // If is Image show image properties imagePreview.URL = URLHelper.AddParameterToUrl(permanentUrl, "maxsidesize", "200"); imagePreview.URL = URLHelper.AddParameterToUrl(imagePreview.URL, "chset", Guid.NewGuid().ToString()); plcImagePreview.Visible = true; plcMediaPreview.Visible = false; pnlPrew.Visible = true; } else if (MediaHelper.IsAudioVideo(FileInfo.FileExtension)) { mediaPreview.Height = MediaHelper.IsAudio(FileInfo.FileExtension) ? 45 : 180; mediaPreview.Width = 270; mediaPreview.AutoPlay = false; mediaPreview.AVControls = true; mediaPreview.Loop = false; mediaPreview.Type = FileInfo.FileExtension; // If is Image show image properties mediaPreview.Url = permanentUrl; plcMediaPreview.Visible = true; plcImagePreview.Visible = false; pnlPrew.Visible = true; } else { pnlPrew.Visible = false; } } else { pnlPrew.Visible = false; } }
/// <summary> /// Returns argument set for the passed file data row. /// </summary> /// <param name="data">Data row object holding all the data on current file</param> public string GetArgumentSet(IDataContainer data) { string className = ValidationHelper.GetString(data.GetValue("ClassName"), String.Empty).ToLowerCSafe(); string name; // Get file name with extension switch (SourceType) { case MediaSourceEnum.DocumentAttachments: name = AttachmentHelper.GetFullFileName(Path.GetFileNameWithoutExtension(data.GetValue("AttachmentName").ToString()), data.GetValue("AttachmentExtension").ToString()); break; case MediaSourceEnum.MetaFile: name = MetaFileInfoProvider.GetFullFileName(Path.GetFileNameWithoutExtension(data.GetValue("MetaFileName").ToString()), data.GetValue("MetaFileExtension").ToString()); break; default: name = data.GetValue("DocumentName").ToString(); break; } StringBuilder sb = new StringBuilder(); // Common information for both content & attachments sb.Append("name|" + CMSDialogHelper.EscapeArgument(name)); // Load attachment info only for CMS.File document type if (((SourceType != MediaSourceEnum.Content) && (SourceType != MediaSourceEnum.MetaFile)) || (className == "cms.file")) { sb.Append("|AttachmentExtension|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentExtension"))); sb.Append("|AttachmentImageWidth|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentImageWidth"))); sb.Append("|AttachmentImageHeight|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentImageHeight"))); sb.Append("|AttachmentSize|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentSize"))); sb.Append("|AttachmentGUID|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentGUID"))); } else if (SourceType == MediaSourceEnum.MetaFile) { sb.Append("|MetaFileExtension|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileExtension"))); sb.Append("|MetaFileImageWidth|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileImageWidth"))); sb.Append("|MetaFileImageHeight|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileImageHeight"))); sb.Append("|MetaFileSize|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileSize"))); sb.Append("|MetaFileGUID|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileGUID"))); sb.Append("|SiteID|" + CMSDialogHelper.EscapeArgument(data.GetValue("MetaFileSiteID"))); } else { sb.Append("|AttachmentExtension||AttachmentImageWidth||AttachmentImageHeight||AttachmentSize||AttachmentGUID|"); } // Get source type specific information if (SourceType == MediaSourceEnum.Content) { sb.Append("|NodeSiteID|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeSiteID"))); sb.Append("|SiteName|" + CMSDialogHelper.EscapeArgument(data.GetValue("SiteName"))); sb.Append("|NodeGUID|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeGUID"))); sb.Append("|NodeID|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeID"))); sb.Append("|NodeAlias|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeAlias"))); sb.Append("|NodeAliasPath|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeAliasPath"))); sb.Append("|DocumentUrlPath|" + CMSDialogHelper.EscapeArgument(data.GetValue("DocumentUrlPath"))); sb.Append("|DocumentExtensions|" + CMSDialogHelper.EscapeArgument(data.GetValue("DocumentExtensions"))); sb.Append("|ClassName|" + CMSDialogHelper.EscapeArgument(data.GetValue("ClassName"))); sb.Append("|NodeLinkedNodeID|" + CMSDialogHelper.EscapeArgument(data.GetValue("NodeLinkedNodeID"))); } else if (SourceType != MediaSourceEnum.MetaFile) { string formGuid = data.ContainsColumn("AttachmentFormGUID") ? data.GetValue("AttachmentFormGUID").ToString() : Guid.Empty.ToString(); string siteId = data.ContainsColumn("AttachmentSiteID") ? data.GetValue("AttachmentSiteID").ToString() : "0"; sb.Append("|SiteID|" + CMSDialogHelper.EscapeArgument(siteId)); sb.Append("|FormGUID|" + CMSDialogHelper.EscapeArgument(formGuid)); sb.Append("|AttachmentDocumentID|" + CMSDialogHelper.EscapeArgument(data.GetValue("AttachmentDocumentID"))); } return(sb.ToString()); }
/// <summary> /// Returns URL of the media item according site settings. /// </summary> /// <param name="site">Information on site file belongs to</param> /// <param name="fileGuid">GUID of the file URL is generated for</param> /// <param name="fileName">Name of the file URL is generated for</param> /// <param name="filePath">Media file path of the file URL is generated for</param> /// <param name="isPreview">Indicates whether the file URL is generated for preview</param> /// <param name="maxSideSize">Maximum dimension for images displayed for tile and thumbnails view</param> public string GetItemUrl(MediaFileInfo fileInfo, SiteInfo site, Guid fileGuid, string fileName, string fileExtension, string filePath, bool isPreview, int height, int width, int maxSideSize) { string result = ""; bool resize = (maxSideSize > 0); fileName = UsePermanentUrls ? AttachmentHelper.GetFullFileName(fileName, fileExtension) : fileName; bool generateFullURL = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseMediaFileAbsoluteURLs"], false); if ((Config != null) && (Config.UseFullURL || generateFullURL || (CMSContext.CurrentSiteID != LibraryInfo.LibrarySiteID) || (CMSContext.CurrentSiteID != GetCurrentSiteId()))) { // If permanent URLs should be generated if (UsePermanentUrls || resize || isPreview) { // URL in format 'http://domainame/getmedia/123456-25245-45454-45455-5455555545/testfile.gif' result = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, fileGuid, fileName); } else { // URL in format 'http://domainame/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif' result = MediaFileURLProvider.GetMediaFileAbsoluteUrl(site.SiteName, LibraryInfo.LibraryFolder, filePath); } } else { if (UsePermanentUrls || resize || isPreview) { // URL in format '/cms/getmedia/123456-25245-45454-45455-5455555545/testfile.gif' result = MediaFileURLProvider.GetMediaFileUrl(fileGuid, fileName); } else { if (fileInfo != null) { result = MediaFileURLProvider.GetMediaFileUrl(fileInfo, CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder); } else { // URL in format '/cms/EcommerceSite/media/testlibrary/folder1/testfile.gif' result = MediaFileURLProvider.GetMediaFileUrl(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder, filePath); } } } // If image dimensions are specified if (resize) { result = URLHelper.AddParameterToUrl(result, "maxsidesize", maxSideSize.ToString()); } if (height > 0) { result = URLHelper.AddParameterToUrl(result, "height", height.ToString()); } if (width > 0) { result = URLHelper.AddParameterToUrl(result, "width", width.ToString()); } // Media selctor should returns non-resolved URL in all cases bool isMediaSelector = (OutputFormat == OutputFormatEnum.URL) && (SelectableContent == SelectableContentEnum.OnlyMedia); return(isMediaSelector ? result : URLHelper.ResolveUrl(result, true, false)); }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridOnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "update": PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; // Dynamically load uploader control DirectFileUploader dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; // Set uploader's properties if (dfuElem != null) { dfuElem.ID = "dfuElem" + LibraryID; dfuElem.DisplayInline = true; dfuElem.SourceType = MediaSourceEnum.MediaLibraries; dfuElem.MediaFileID = MediaFileID; dfuElem.LibraryID = LibraryID; dfuElem.LibraryFolderPath = LibraryFolderPath; dfuElem.ParentElemID = ClientID; dfuElem.IsMediaThumbnail = IsMediaThumbnail; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ForceLoad = true; dfuElem.IsLiveSite = IsLiveSite; // New settings added dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.Height = 16; dfuElem.Width = 16; dfuElem.MaxNumberToUpload = 1; if (Enabled && EnableUpdate) { dfuElem.Enabled = true; } else { dfuElem.Enabled = false; } plcUpd.Controls.Add(dfuElem); } return(plcUpd); case "edit": // Get file extension if ((FileInfo != null) && (LibraryInfo != null)) { var editButton = (CMSGridActionButton)sender; if (AuthenticationHelper.IsAuthenticated()) { string fileExt = (IsMediaThumbnail ? previewExt : FileInfo.FileExtension); // If the file is not an image don't allow image editing if (!ImageHelper.IsSupportedByImageEditor(fileExt) || !Enabled) { // Disable edit icon in case that attachment is not an image editButton.Enabled = false; } else { string query = string.Format("?refresh=1&siteid={0}&MediaFileGUID={1}{2}", LibraryInfo.LibrarySiteID, FileInfo.FileGUID, (IsMediaThumbnail ? "&isPreview=1" : "")); query = URLHelper.AddUrlParameter(query, "hash", QueryHelper.GetHash(query)); editButton.OnClientClick = "EditThumbnailImage('" + query + "'); return false;"; } editButton.ToolTip = GetString("general.edit"); } else { editButton.Visible = false; } } break; case "delete": var deleteButton = (CMSGridActionButton)sender; if (!Enabled) { // Disable delete icon in case that editing is not allowed deleteButton.Enabled = false; } break; case "filename": if ((LibraryInfo != null) && (FileInfo != null)) { string fileUrl = ""; string fileExt = ""; string fileName = ""; // Get file extension if (IsMediaThumbnail) { fileName = previewName; fileExt = previewExt; fileUrl = ResolveUrl("~/CMSPages/GetMediaFile.aspx?preview=1&fileguid=" + FileInfo.FileGUID); } else { fileExt = FileInfo.FileExtension; fileName = FileInfo.FileName; fileUrl = MediaFileURLProvider.GetMediaFileAbsoluteUrl(FileInfo.FileGUID, AttachmentHelper.GetFullFileName(FileInfo.FileName, FileInfo.FileExtension)); } fileUrl = URLHelper.UpdateParameterInUrl(fileUrl, "chset", Guid.NewGuid().ToString()); string tooltip = null; string iconTag = UIHelper.GetFileIcon(Page, fileExt, tooltip: fileName); bool isImage = ImageHelper.IsImage(fileExt); if (isImage) { tooltip = ""; if (File.Exists(previewPath)) { FileStream file = FileStream.New(previewPath, FileMode.Open, FileAccess.Read); Image img = Image.FromStream(file); file.Close(); if (img != null) { int[] imgDims = ImageHelper.EnsureImageDimensions(0, 0, 150, img.Width, img.Height); string setRTL = (CultureHelper.IsUICultureRTL() ? ", LEFT, true" : ""); tooltip = "onmouseout=\"UnTip()\" onmouseover=\"Tip('<div style=\\'width:" + imgDims[0] + "px; text-align:center;\\'><img src=\\'" + URLHelper.AddParameterToUrl(fileUrl, "maxsidesize", "150") + "\\' alt=\\'" + fileName + "\\' /></div>'" + setRTL + ")\""; // Dispose image img.Dispose(); } } } if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + fileUrl + "'); return false;\" class=\"cms-icon-link\"><span " + tooltip + ">" + iconTag + fileName + "</span></a>"); } else { return("<a href=\"" + fileUrl + "\" class=\"cms-icon-link\">" + iconTag + fileName + "</a>"); } } return(""); case "filesize": return(DataHelper.GetSizeString(ValidationHelper.GetLong(parameter, 0))); } return(parameter); }