/// <summary> /// Ensures the info objects. /// </summary> private void LoadInfos() { switch (baseImageEditor.ImageType) { case ImageHelper.ImageTypeEnum.Metafile: if (mf == null) { mf = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true); } break; case ImageHelper.ImageTypeEnum.PhysicalFile: // Skip loading info for physical files break; default: if (ai == null) { baseImageEditor.Tree = new TreeProvider(MembershipContext.AuthenticatedUser); // If using workflow then get versioned attachment if (VersionHistoryID != 0) { ai = DocumentHelper.GetAttachment(attachmentGuid, VersionHistoryID); } // Else get file without binary data else { ai = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } } break; } }
/// <summary> /// Updates parameters used by Edit button when displaying image editor. /// </summary> /// <param name="attachmentGuidString">GUID identifying attachment</param> private void UpdateEditParameters(string attachmentGuidString) { if (ShowTooltip) { // Try to get attachment GUID Guid attGuid = ValidationHelper.GetGuid(attachmentGuidString, Guid.Empty); if (attGuid != null) { // Get attachment AttachmentInfo attInfo = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attGuid, SiteName); if (attInfo != null) { // Get attachment URL string attachmentUrl = null; if (Node != null) { attachmentUrl = CMSContext.ResolveUIUrl(TreePathUtils.GetAttachmentUrl(attGuid, URLHelper.GetSafeFileName(attInfo.AttachmentName, CMSContext.CurrentSiteName), VersionHistoryID, null)); } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attGuid, VersionHistoryID)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL if (OriginalNodeSiteName != CMSContext.CurrentSiteName) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Generate new tooltip command string newToolTip = null; string title = attInfo.AttachmentTitle; string description = attInfo.AttachmentDescription; // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attInfo.AttachmentName, ATTACHMENT_NAME_LIMIT, "..."); int imageWidth = attInfo.AttachmentImageWidth; int imageHeight = attInfo.AttachmentImageHeight; bool isImage = ImageHelper.IsImage(attInfo.AttachmentExtension); int tooltipWidth = 300; string url = isImage ? attachmentUrl : null; string tooltipBody = UIHelper.GetTooltip(url, imageWidth, imageHeight, title, attachmentName, description, null, ref tooltipWidth); if (!string.IsNullOrEmpty(tooltipBody)) { newToolTip = String.Format("Tip('{0}', WIDTH, -300)", tooltipBody); } // Get update script string updateScript = String.Format("$j(\"#{0}\").attr('onmouseover', '').unbind('mouseover').mouseover(function(){{ {1} }});", attGuid, newToolTip); // Execute update ScriptHelper.RegisterStartupScript(Page, typeof(Page), "AttachmentUpdateEdit", ScriptHelper.GetScript(updateScript)); } } } }
/// <summary> /// Ensures the info objects. /// </summary> private void LoadInfos() { switch (baseImageEditor.ImageType) { default: case ImageHelper.ImageTypeEnum.Attachment: if (ai == null) { baseImageEditor.Tree = new TreeProvider(CMSContext.CurrentUser); // If using workflow then get versioned attachment if (VersionHistoryID != 0) { AttachmentHistoryInfo attachmentVersion = VersionManager.GetAttachmentVersion(VersionHistoryID, attachmentGuid); if (attachmentVersion == null) { ai = null; } else { ai = new AttachmentInfo(attachmentVersion.Generalized.DataClass); ai.AttachmentID = attachmentVersion.AttachmentHistoryID; } } // else get file without binary data else { ai = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } } break; case ImageHelper.ImageTypeEnum.Metafile: if (mf == null) { mf = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true); } break; case ImageHelper.ImageTypeEnum.PhysicalFile: // Skip loading info for physical files break; } }
/// <summary> /// Initializes common properties used for processing image. /// </summary> private void baseImageEditor_InitializeProperties() { var currentUser = MembershipContext.AuthenticatedUser; // Process attachment switch (baseImageEditor.ImageType) { // Process physical file case ImageHelper.ImageTypeEnum.PhysicalFile: { if (!String.IsNullOrEmpty(filePath)) { if ((currentUser != null) && currentUser.IsGlobalAdministrator) { try { // Load the file from disk string physicalPath = Server.MapPath(filePath); byte[] data = File.ReadAllBytes(physicalPath); baseImageEditor.ImgHelper = new ImageHelper(data); } catch { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.rights")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; // Process metafile case ImageHelper.ImageTypeEnum.Metafile: { // Get metafile mf = MetaFileInfoProvider.GetMetaFileInfoWithoutBinary(metafileGuid, CurrentSiteName, true); // If file is not null and current user is global administrator then set image if (mf != null) { if (UserInfoProvider.IsAuthorizedPerObject(mf.MetaFileObjectType, mf.MetaFileObjectID, PermissionsEnum.Modify, CurrentSiteName, MembershipContext.AuthenticatedUser)) { // Ensure metafile binary data mf.MetaFileBinary = MetaFileInfoProvider.GetFile(mf, CurrentSiteName); if (mf.MetaFileBinary != null) { baseImageEditor.ImgHelper = new ImageHelper(mf.MetaFileBinary); } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.rights")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; default: { baseImageEditor.Tree = new TreeProvider(currentUser); // If using workflow then get versioned attachment if (VersionHistoryID != 0) { // Get the versioned attachment AttachmentHistoryInfo attachmentVersion = VersionManager.GetAttachmentVersion(VersionHistoryID, attachmentGuid); if (attachmentVersion != null) { // Create new attachment object ai = new AttachmentInfo(attachmentVersion.Generalized.DataClass); if (ai != null) { AttachmentHistoryID = attachmentVersion.AttachmentHistoryID; ai.AttachmentVersionHistoryID = VersionHistoryID; } } } // Else get file without binary data else { ai = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attachmentGuid, CurrentSiteName); } // If file is not null and current user is set if (ai != null) { TreeNode node; if (ai.AttachmentDocumentID > 0) { node = baseImageEditor.Tree.SelectSingleDocument(ai.AttachmentDocumentID); } else { // Get parent node ID in case attachment is edited for document not created yet int parentNodeId = QueryHelper.GetInteger("parentId", 0); node = baseImageEditor.Tree.SelectSingleNode(parentNodeId); } // If current user has appropriate permissions then set image - check hash fro live site otherwise check node permissions if ((currentUser != null) && (node != null) && ((IsLiveSite && QueryHelper.ValidateHash("hash")) || (!IsLiveSite && (currentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))) { // Ensure attachment binary data if (VersionHistoryID == 0) { ai.AttachmentBinary = AttachmentInfoProvider.GetFile(ai, CurrentSiteName); } if (ai.AttachmentBinary != null) { baseImageEditor.ImgHelper = new ImageHelper(ai.AttachmentBinary); } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.filemodify")); } } else { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.loading")); } } break; } // Check that image is in supported formats if ((!baseImageEditor.LoadingFailed) && (baseImageEditor.ImgHelper.ImageFormatToString() == null)) { baseImageEditor.LoadingFailed = true; baseImageEditor.ShowError(GetString("img.errors.format")); } // Disable editor if loading failed if (baseImageEditor.LoadingFailed) { Enabled = false; } }
/// <summary> /// Initializes properties. /// </summary> private void InitializeAttachment() { AttachmentInfo attachmentInfo = null; if (InfoObject != null) { attachmentInfo = InfoObject as AttachmentInfo; } else { // If using workflow then get versioned attachment if (VersionHistoryID != 0) { // Get the versioned attachment with binary data AttachmentHistoryInfo attachmentHistory = VersionManager.GetAttachmentVersion(VersionHistoryID, ObjectGuid, false); // Create new attachment object attachmentInfo = (attachmentHistory != null) ? new AttachmentInfo(attachmentHistory.Generalized.DataClass) : null; if (attachmentInfo != null) { attachmentInfo.AttachmentVersionHistoryID = VersionHistoryID; } } // Else get file without binary data else { attachmentInfo = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(ObjectGuid, SiteName); } InfoObject = attachmentInfo; } if (attachmentInfo != null) { // Check permissions if (CheckPermissions) { // If attachment is temporary, check 'Create' permission on parent node. Else check 'Modify' permission. NodePermissionsEnum permission = nodeIsParent ? NodePermissionsEnum.Create : NodePermissionsEnum.Modify; if (Node == null) { RedirectToInformation(GetString("editeddocument.notexists")); } if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, permission) != AuthorizationResultEnum.Allowed) { RedirectToAccessDenied(GetString("metadata.errors.filemodify")); } } // Fire event GetObjectExtension if (GetObjectExtension != null) { GetObjectExtension(attachmentInfo.AttachmentExtension); } } else { RedirectToInformation(GetString("editedobject.notexists")); } }