public ActionResult Index() { var properties = GetProperties(); IEnumerable <Picture> pictures = new List <Picture>(); switch (properties.Type) { case Type.Attachments: pictures = this.GetPage().Attachments.ToList().Where(a => a.AttachmentImageWidth > 0).Select(a => new Picture { Url = CMS.DocumentEngine.AttachmentURLProvider.GetAttachmentUrl(a.AttachmentName, this.GetPage().NodeAliasPath), AltText = a.AttachmentTitle, Thumbnail = $"{AttachmentURLProvider.GetAttachmentUrl(a.AttachmentName, this.GetPage().NodeAliasPath)}?maxsidesize=128" }); break; case Type.MediaLibraryFolder: /*var library = MediaLibraryInfoProvider.GetMediaLibraryInfo(properties.MediaLibraryFolder, this.GetPage().NodeSiteName); * if (string.IsNullOrEmpty(properties.MediaLibraryFolder)) * { * properties.MediaLibraryFolder = "%"; * } * var files = MediaFileInfoProvider.GetMediaFiles($"{nameof(MediaFileInfo.FileLibraryID)}={library.LibraryID} AND {nameof(MediaFileInfo.FilePath)} LIKE '{properties.MediaLibrarySubfolder}%'"); * pictures = files.ToList().Select(f => new Picture * { * Url = MediaLibraryHelper.GetMediaFileUrl(f.FileGUID, this.GetPage().NodeSiteName), * AltText = f.FileTitle, * Thumbnail = $"{MediaFileURLProvider.GetMediaFileAbsoluteUrl(this.GetPage().NodeSiteName, f.FileGUID, f.FileName)}?maxsidesize=120" * });*/ if (properties.MediaFiles != null) { pictures = properties.MediaFiles.Select(m => new Picture { Url = MediaLibraryHelper.GetMediaFileUrl(m.FileGuid, this.GetPage().NodeSiteName), AltText = MediaFileInfoProvider.GetMediaFileInfo(m.FileGuid, this.GetPage().NodeSiteName).FileTitle, Thumbnail = $"{MediaFileURLProvider.GetMediaFileAbsoluteUrl(this.GetPage().NodeSiteName, m.FileGuid, MediaFileInfoProvider.GetMediaFileInfo(m.FileGuid, this.GetPage().NodeSiteName).FileName)}?maxsidesize=128" }); } break; case Type.External: pictures = properties.External.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Select(f => new Picture { Url = f, AltText = f, Thumbnail = f }); break; } var viewModel = new ViewModel { Pictures = pictures }; return(PartialView("Widgets/_LightboxGallery", viewModel)); }
private string GetAttachmentUrl(DocumentAttachment attachment, DocumentAttachment mainAttachment, int versionHistoryId) { // Get link for attachment string attachmentUrl; var attName = mainAttachment.AttachmentName; var documentId = mainAttachment.AttachmentDocumentID; var siteName = SiteContext.CurrentSiteName; if (IsLiveSite && (documentId > 0)) { attachmentUrl = ApplicationUrlHelper.ResolveUIUrl( AttachmentURLProvider.GetAttachmentUrl( mainAttachment.AttachmentGUID, URLHelper.GetSafeFileName(attName, siteName) ) ); } else { attachmentUrl = ApplicationUrlHelper.ResolveUIUrl( AttachmentURLProvider.GetAttachmentUrl( mainAttachment.AttachmentGUID, URLHelper.GetSafeFileName(attName, siteName), null, // Do not include version history ID for temporary attachment // Version history ID may be present in case of new culture version where may be mix of temporary and version attachments from source (mainAttachment.AttachmentFormGUID == Guid.Empty) ? versionHistoryId : 0 ) ); } // Add variant identifier if (attachment.IsVariant()) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "variant", attachment.AttachmentVariantDefinitionIdentifier); } // Ensure correct URL for non-temporary attachments, they need to be served from their original site (may be from linked documents) if (mainAttachment.AttachmentFormGUID == Guid.Empty) { var attachmentSiteName = SiteInfoProvider.GetSiteName(mainAttachment.AttachmentSiteID); if (attachmentSiteName != siteName) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", attachmentSiteName); } } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } return(attachmentUrl); }
/// <summary> /// Provides operations necessary to create and store new attachment. /// </summary> private void HandleAttachmentUpload(bool fieldAttachment) { // New attachment DocumentAttachment newAttachment = null; string message = string.Empty; bool fullRefresh = false; bool refreshTree = false; try { // Get the existing document if (DocumentID != 0) { // Get document node = DocumentHelper.GetDocument(DocumentID, TreeProvider); if (node == null) { throw new Exception("Given page doesn't exist!"); } } #region "Check permissions" if (CheckPermissions) { CheckNodePermissions(node); } #endregion // Check the allowed extensions CheckAllowedExtensions(); // Standard attachments if (DocumentID != 0) { // Check out the document if (AutoCheck) { // Get original step Id int originalStepId = node.DocumentWorkflowStepID; // Get current step info WorkflowStepInfo si = WorkflowManager.GetStepInfo(node); if (si != null) { // Decide if full refresh is needed bool automaticPublish = wi.WorkflowAutoPublishChanges; // Document is published or archived or uses automatic publish or step is different than original (document was updated) fullRefresh = si.StepIsPublished || si.StepIsArchived || (automaticPublish && !si.StepIsPublished) || (originalStepId != node.DocumentWorkflowStepID); } using (CMSActionContext ctx = new CMSActionContext() { LogEvents = false }) { VersionManager.CheckOut(node, node.IsPublished, true); } } // Handle field attachment if (fieldAttachment) { // Extension of CMS file before saving string oldExtension = node.DocumentType; newAttachment = DocumentHelper.AddAttachment(node, AttachmentGUIDColumnName, Guid.Empty, Guid.Empty, ucFileUpload.PostedFile, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize); // Update attachment field DocumentHelper.UpdateDocument(node, TreeProvider); // Different extension if ((oldExtension != null) && !oldExtension.EqualsCSafe(node.DocumentType, true)) { refreshTree = true; } } // Handle grouped and unsorted attachments else { // Grouped attachment if (AttachmentGroupGUID != Guid.Empty) { newAttachment = DocumentHelper.AddGroupedAttachment(node, AttachmentGUID, AttachmentGroupGUID, ucFileUpload.PostedFile, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize); } // Unsorted attachment else { newAttachment = DocumentHelper.AddUnsortedAttachment(node, AttachmentGUID, ucFileUpload.PostedFile, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize); } // Log synchronization task if not under workflow if (wi == null) { DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, TreeProvider); } } // Check in the document if (AutoCheck) { using (CMSActionContext ctx = new CMSActionContext() { LogEvents = false }) { VersionManager.CheckIn(node, null, null); } } } // Temporary attachments if (FormGUID != Guid.Empty) { newAttachment = (DocumentAttachment)AttachmentInfoProvider.AddTemporaryAttachment(FormGUID, AttachmentGUIDColumnName, AttachmentGUID, AttachmentGroupGUID, ucFileUpload.PostedFile, SiteContext.CurrentSiteID, ResizeToWidth, ResizeToHeight, ResizeToMaxSideSize); } // Ensure properties update if ((newAttachment != null) && !InsertMode) { AttachmentGUID = newAttachment.AttachmentGUID; } if (newAttachment == null) { throw new Exception("The attachment hasn't been created since no DocumentID or FormGUID was supplied."); } } catch (Exception ex) { // Log the exception EventLogProvider.LogException("Content", "UploadAttachment", ex); message = ex.Message; } finally { string afterSaveScript = string.Empty; // Call aftersave javascript if exists if (!String.IsNullOrEmpty(AfterSaveJavascript)) { if ((message == string.Empty) && (newAttachment != null)) { string url = null; string safeName = URLHelper.GetSafeFileName(newAttachment.AttachmentName, SiteContext.CurrentSiteName); if (node != null) { SiteInfo si = SiteInfoProvider.GetSiteInfo(node.NodeSiteID); if (si != null) { bool usePermanent = DocumentURLProvider.UsePermanentUrls(si.SiteName); if (usePermanent) { url = ResolveUrl(AttachmentURLProvider.GetAttachmentUrl(newAttachment.AttachmentGUID, safeName)); } else { url = ResolveUrl(AttachmentURLProvider.GetAttachmentUrl(safeName, node.NodeAliasPath)); } } } else { url = ResolveUrl(AttachmentURLProvider.GetAttachmentUrl(newAttachment.AttachmentGUID, safeName)); } // Calling javascript function with parameters attachments url, name, width, height if (!string.IsNullOrEmpty(AfterSaveJavascript)) { Hashtable obj = new Hashtable(); if (ImageHelper.IsImage(newAttachment.AttachmentExtension)) { obj[DialogParameters.IMG_URL] = url; obj[DialogParameters.IMG_TOOLTIP] = newAttachment.AttachmentName; obj[DialogParameters.IMG_WIDTH] = newAttachment.AttachmentImageWidth; obj[DialogParameters.IMG_HEIGHT] = newAttachment.AttachmentImageHeight; } else if (MediaHelper.IsAudioVideo(newAttachment.AttachmentExtension)) { obj[DialogParameters.OBJECT_TYPE] = "audiovideo"; obj[DialogParameters.AV_URL] = url; obj[DialogParameters.AV_EXT] = newAttachment.AttachmentExtension; obj[DialogParameters.AV_WIDTH] = DEFAULT_OBJECT_WIDTH; obj[DialogParameters.AV_HEIGHT] = DEFAULT_OBJECT_HEIGHT; } else { obj[DialogParameters.LINK_URL] = url; obj[DialogParameters.LINK_TEXT] = newAttachment.AttachmentName; } // Calling javascript function with parameters attachments url, name, width, height afterSaveScript += ScriptHelper.GetScript(string.Format(@"{5} if (window.{0}) {{ window.{0}('{1}', '{2}', '{3}', '{4}', obj); }} else if((window.parent != null) && window.parent.{0}) {{ window.parent.{0}('{1}', '{2}', '{3}', '{4}', obj); }}", AfterSaveJavascript, url, newAttachment.AttachmentName, newAttachment.AttachmentImageWidth, newAttachment.AttachmentImageHeight, CMSDialogHelper.GetDialogItem(obj))); } } else { afterSaveScript += ScriptHelper.GetAlertScript(message); } } // Create attachment info string string attachmentInfo = ((newAttachment != null) && (newAttachment.AttachmentGUID != Guid.Empty) && (IncludeNewItemInfo)) ? String.Format("'{0}', ", newAttachment.AttachmentGUID) : ""; // Ensure message text message = TextHelper.EnsureLineEndings(message, " "); // Call function to refresh parent window afterSaveScript += ScriptHelper.GetScript(String.Format(@" if ((window.parent != null) && (/parentelemid={0}/i.test(window.location.href)) && (window.parent.InitRefresh_{0} != null)){{ window.parent.InitRefresh_{0}({1}, {2}, {3}, {4}); }}", ParentElemID, ScriptHelper.GetString(message.Trim()), (fullRefresh ? "true" : "false"), (refreshTree ? "true" : "false"), attachmentInfo + (InsertMode ? "'insert'" : "'update'"))); ScriptHelper.RegisterStartupScript(this, typeof(string), "afterSaveScript_" + ClientID, afterSaveScript); } }
/// <summary> /// UniGrid external data bound. /// </summary> protected object GridDocsOnExternalDataBound(object sender, string sourceName, object parameter) { string attName; string attachmentExt; DataRowView drv; switch (sourceName.ToLowerCSafe()) { case "update": { drv = parameter as DataRowView; PlaceHolder plcUpd = new PlaceHolder(); plcUpd.ID = "plcUdateAction"; Panel pnlBlock = new Panel(); pnlBlock.ID = "pnlBlock"; plcUpd.Controls.Add(pnlBlock); // Add update control // 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" + DocumentID; dfuElem.SourceType = MediaSourceEnum.Attachment; dfuElem.DisplayInline = true; if (!createTempAttachment) { dfuElem.AttachmentGUID = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); } dfuElem.ForceLoad = true; dfuElem.FormGUID = FormGUID; dfuElem.AttachmentGUIDColumnName = GUIDColumnName; dfuElem.DocumentID = DocumentID; dfuElem.NodeParentNodeID = NodeParentNodeID; dfuElem.NodeClassName = NodeClassName; dfuElem.ResizeToWidth = ResizeToWidth; dfuElem.ResizeToHeight = ResizeToHeight; dfuElem.ResizeToMaxSideSize = ResizeToMaxSideSize; dfuElem.AllowedExtensions = AllowedExtensions; dfuElem.ShowIconMode = true; dfuElem.InsertMode = false; dfuElem.ParentElemID = ClientID; dfuElem.IncludeNewItemInfo = true; dfuElem.CheckPermissions = CheckPermissions; dfuElem.NodeSiteName = SiteName; dfuElem.IsLiveSite = IsLiveSite; // Setting of the direct single mode dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } int nodeGroupId = ((Node != null) && (Node.DocumentID > 0)) ? Node.GetValue("NodeGroupID", 0) : 0; bool displayGroupAdmin = true; // Check group admin for live site if (IsLiveSite && (nodeGroupId > 0)) { displayGroupAdmin = MembershipContext.AuthenticatedUser.IsGroupAdministrator(nodeGroupId); } // Check if external editing allowed by the form bool allowExt = (Form == null) || Form.AllowExternalEditing; if (allowExt && (FormGUID == Guid.Empty) && displayGroupAdmin) { var ctrl = ExternalEditHelper.LoadExternalEditControl(pnlBlock, FileTypeEnum.Attachment, SiteName, new DataRowContainer(drv), IsLiveSite, Node); if (ctrl != null) { ctrl.ID = "extEdit" + DocumentID; // Ensure form identification if ((Form != null) && (Form.Parent != null)) { ctrl.FormID = Form.Parent.ClientID; } ctrl.SiteName = SiteName; if (FieldInfo != null) { ctrl.AttachmentFieldName = FieldInfo.Name; } ctrl.PreRender += extEdit_PreRender; // Adjust the styles bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL()); pnlBlock.Style.Add("text-align", isRTL ? "right" : "left"); } } return(plcUpd); } case "edit": { // Get file extension string extension = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentExtension"], string.Empty).ToLowerCSafe(); // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); if (sender is CMSGridActionButton) { CMSGridActionButton img = (CMSGridActionButton)sender; if (createTempAttachment) { img.Visible = false; } else { img.ScreenReaderDescription = extension; img.ToolTip = attachmentGuid.ToString(); img.PreRender += img_PreRender; } } } break; case "delete": if (sender is CMSGridActionButton) { CMSGridActionButton imgDelete = (CMSGridActionButton)sender; // Turn off validation imgDelete.CausesValidation = false; imgDelete.PreRender += imgDelete_PreRender; } break; case "attachmentname": { drv = parameter as DataRowView; // Get attachment GUID attachmentGuid = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty); // Get attachment extension attachmentExt = ValidationHelper.GetString(drv["AttachmentExtension"], string.Empty); bool isImage = ImageHelper.IsImage(attachmentExt); bool isTemp = ValidationHelper.GetGuid(drv["AttachmentFormGUID"], Guid.Empty) != Guid.Empty; // Get link for attachment string attachmentUrl = null; attName = ValidationHelper.GetString(drv["AttachmentName"], string.Empty); int documentId = DocumentID; if (documentId > 0) { int versionHistoryId = IsLiveSite ? 0 : VersionHistoryID; attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName), null, versionHistoryId)); } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attachmentGuid, 0)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL for non-temporary attachments if ((OriginalNodeSiteName != SiteContext.CurrentSiteName) && !isTemp) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attName, ATTACHMENT_NAME_LIMIT); // Tooltip string tooltip = null; if (ShowTooltip) { string title = ValidationHelper.GetString(drv["AttachmentTitle"], string.Empty); string description = ValidationHelper.GetString(drv["AttachmentDescription"], string.Empty); int imageWidth = ValidationHelper.GetInteger(drv["AttachmentImageWidth"], 0); int imageHeight = ValidationHelper.GetInteger(drv["AttachmentImageHeight"], 0); tooltip = UIHelper.GetTooltipAttributes(attachmentUrl, imageWidth, imageHeight, title, attachmentName, attachmentExt, description, null, 300); } // Icon string iconTag = UIHelper.GetFileIcon(Page, attachmentExt, tooltip: attachmentName); if (isImage) { return("<a href=\"#\" onclick=\"javascript: window.open('" + attachmentUrl + "'); return false;\" class=\"cms-icon-link\"><span " + tooltip + ">" + iconTag + attachmentName + "</span></a>"); } else { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "disposition", "attachment"); // NOTE: OnClick here is needed to avoid loader to show because even for download links, the pageUnload event is fired return(String.Format("<a href=\"{0}\" onclick=\"javascript: {5}\" class=\"cms-icon-link\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, iconTag, attachmentName, ScriptHelper.GetDisableProgressScript())); } } case "attachmentsize": { long size = ValidationHelper.GetLong(parameter, 0); return(DataHelper.GetSizeString(size)); } } return(parameter); }
/// <summary> /// UniGrid external data bound. /// </summary> protected object gridAttachments_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView drv; switch (sourceName.ToLowerCSafe()) { case "clone": CMSGridActionButton imgClone = sender as CMSGridActionButton; if (imgClone != null) { if (IsLiveSite) { // Hide cloning on live site imgClone.Visible = false; return(imgClone); } string objectType = VersionHistoryID > 0 ? AttachmentHistoryInfo.OBJECT_TYPE : AttachmentInfo.OBJECT_TYPE; int id = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentID"], 0); imgClone.PreRender += imgClone_PreRender; imgClone.OnClientClick = "modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/Objects/Dialogs/CloneObjectDialog.aspx?objectType=" + objectType + "&objectId=" + id) + "', 'CloneObject', 750, 470); return false;"; } break; case "update": { Panel pnlBlock = new Panel { ID = "pnlBlock" }; pnlBlock.Style.Add("margin", "0 auto"); pnlBlock.PreRender += (senderObject, args) => pnlBlock.Width = mUpdateIconPanelWidth; // Add update control // Dynamically load uploader control var dfuElem = Page.LoadUserControl("~/CMSModules/Content/Controls/Attachments/DirectFileUploader/DirectFileUploader.ascx") as DirectFileUploader; drv = parameter as DataRowView; // Set uploader's properties if (dfuElem != null) { dfuElem.SourceType = MediaSourceEnum.DocumentAttachments; dfuElem.ID = "dfuElem" + DocumentID; dfuElem.IsLiveSite = IsLiveSite; dfuElem.EnableSilverlightUploader = false; dfuElem.ControlGroup = "update"; dfuElem.AttachmentGUID = GetAttachmentGuid(drv); dfuElem.DisplayInline = true; dfuElem.UploadMode = MultifileUploaderModeEnum.DirectSingle; dfuElem.MaxNumberToUpload = 1; dfuElem.PreRender += dfuElem_PreRender; pnlBlock.Controls.Add(dfuElem); } // Check if external edit allowed by the form bool allowExt = (Form == null) || Form.AllowExternalEditing; if (allowExt && (FormGUID == Guid.Empty)) { var ctrl = ExternalEditHelper.LoadExternalEditControl(pnlBlock, FileTypeEnum.Attachment, SiteName, new DataRowContainer(drv), IsLiveSite, Node); if (ctrl != null) { ctrl.Enabled = Enabled; ctrl.ID = "extEdit" + DocumentID; // Ensure form identification if ((Form != null) && (Form.Parent != null)) { ctrl.FormID = Form.Parent.ClientID; } ctrl.SiteName = SiteName; ctrl.PreRender += extEdit_PreRender; if (FieldInfo != null) { ctrl.AttachmentFieldName = FieldInfo.Name; } // Adjust styles bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL()); pnlBlock.Style.Add("text-align", isRTL ? "right" : "left"); mUpdateIconPanelWidth = 32; } } return(pnlBlock); } case "edit": // Get file extension string extension = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentExtension"], string.Empty).ToLowerCSafe(); Guid guid = ValidationHelper.GetGuid(((DataRowView)((GridViewRow)parameter).DataItem).Row["AttachmentGUID"], Guid.Empty); CMSGridActionButton img = sender as CMSGridActionButton; if (img != null) { img.ToolTip = String.Format("{0}|{1}", extension, guid); img.PreRender += img_PreRender; } break; case "delete": CMSGridActionButton imgDelete = sender as CMSGridActionButton; if (imgDelete != null) { // Turn off validation imgDelete.CausesValidation = false; imgDelete.PreRender += imgDelete_PreRender; } break; case "moveup": CMSGridActionButton imgUp = sender as CMSGridActionButton; if (imgUp != null) { // Turn off validation imgUp.CausesValidation = false; imgUp.PreRender += imgUp_PreRender; } break; case "movedown": CMSGridActionButton imgDown = sender as CMSGridActionButton; if (imgDown != null) { // Turn off validation imgDown.CausesValidation = false; imgDown.PreRender += imgDown_PreRender; } break; case "attachmentname": { drv = parameter as DataRowView; if (drv == null) { break; } // Get attachment GUID Guid attachmentGuid = GetAttachmentGuid(drv); // Get attachment extension string attachmentExt = GetAttachmentExtension(drv); bool isImage = ImageHelper.IsImage(attachmentExt); // Get link for attachment string attachmentUrl; string attName = ValidationHelper.GetString(drv["AttachmentName"], string.Empty); int documentId = DocumentID; if (Node != null) { if (IsLiveSite && (documentId > 0)) { attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName))); } else { attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attachmentGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName), null, VersionHistoryID)); } } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attachmentGuid, VersionHistoryID)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL for non-temporary attachments if ((OriginalNodeSiteName != SiteContext.CurrentSiteName) && (documentId > 0)) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "sitename", OriginalNodeSiteName); } // Add latest version requirement for live site if (IsLiveSite && (documentId > 0)) { // Add requirement for latest version of files for current document string newparams = "latestfordocid=" + documentId; newparams += "&hash=" + ValidationHelper.GetHashString("d" + documentId); attachmentUrl += "&" + newparams; } // Optionally trim attachment name string attachmentName = TextHelper.LimitLength(attName, ATTACHMENT_NAME_LIMIT); // Tooltip string tooltip = null; if (ShowTooltip) { string title = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "AttachmentTitle"), string.Empty); string description = ValidationHelper.GetString(DataHelper.GetDataRowViewValue(drv, "AttachmentDescription"), string.Empty); int imageWidth = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "AttachmentImageWidth"), 0); int imageHeight = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "AttachmentImageHeight"), 0); tooltip = UIHelper.GetTooltipAttributes(attachmentUrl, imageWidth, imageHeight, title, attachmentName, attachmentExt, description, null, 300); } // Icon string imageTag = UIHelper.GetFileIcon(Page, attachmentExt); if (isImage) { return(String.Format("<a class=\"cms-icon-link\" href=\"#\" onclick=\"javascript: window.open('{0}'); return false;\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, imageTag, attachmentName)); } else { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "disposition", "attachment"); // NOTE: OnClick here is needed to avoid loader to show because even for download links, the pageUnload event is fired return(String.Format("<a class=\"cms-icon-link\" onclick=\"javascript: {5}\" href=\"{0}\"><span id=\"{1}\" {2}>{3}{4}</span></a>", attachmentUrl, attachmentGuid, tooltip, imageTag, attachmentName, ScriptHelper.GetDisableProgressScript())); } } case "attachmentsize": long size = ValidationHelper.GetLong(parameter, 0); return(DataHelper.GetSizeString(size)); } return(parameter); }
/// <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 var attGuid = ValidationHelper.GetGuid(attachmentGuidString, Guid.Empty); if (attGuid != Guid.Empty) { // Get attachment AttachmentInfo attInfo = AttachmentInfoProvider.GetAttachmentInfoWithoutBinary(attGuid, SiteName); if (attInfo != null) { string attName = attInfo.AttachmentName; int documentId = DocumentID; // Get attachment URL string attachmentUrl; if (Node != null) { if (IsLiveSite && (documentId > 0)) { attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName))); } else { attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetAttachmentUrl(attGuid, URLHelper.GetSafeFileName(attName, SiteContext.CurrentSiteName), null, VersionHistoryID)); } } else { attachmentUrl = ResolveUrl(DocumentHelper.GetAttachmentUrl(attGuid, VersionHistoryID)); } attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString()); // Ensure correct URL for non-temporary attachments if ((OriginalNodeSiteName != SiteContext.CurrentSiteName) && (documentId > 0)) { 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)); } } } }