/// <summary> /// Initializes all the nested controls. /// </summary> private void SetupControls() { MediaFileInfo mFile = MediaFileInfoProvider.GetMediaFileInfo(FileGuid, SiteName); if (mFile != null) { SiteInfo si = SiteInfoProvider.GetSiteInfo(mFile.FileSiteID); if (si != null) { MediaLibraryInfo mLibrary = MediaLibraryInfoProvider.GetMediaLibraryInfo(mFile.FileLibraryID); string extension = mFile.FileExtension.ToLowerCSafe().TrimStart('.'); string path = MediaFileInfoProvider.GetMediaFilePath(SiteName, mLibrary.LibraryFolder, mFile.FilePath); string url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(SiteName, mFile.FileGUID, mFile.FileName); if (ImageHelper.IsImage(extension) && File.Exists(path)) { // Get image dimension // New dimensions int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mFile.FileImageWidth, mFile.FileImageHeight); // If new dimensions are diferent use them if (((newDims[0] != mFile.FileImageWidth) || (newDims[1] != mFile.FileImageHeight)) && (newDims[0] > 0) && (newDims[1] > 0)) { string dimensions = "?width=" + newDims[0] + "&height=" + newDims[1]; ltlOutput.Text = "<img alt=\"" + mFile.FileName + "\" src=\"" + url + dimensions + "\" width=\"" + newDims[0] + "\" height=\"" + newDims[1] + "\" border=\"0\" />"; } else { ltlOutput.Text = "<img alt=\"" + mFile.FileName + "\" src=\"" + url + "\" width=\"" + Width + "\" height=\"" + Height + "\" border=\"0\" />"; } } else { // Set default dimensions of rendered object if required int width = (Width > 0) ? Width : DEFAULT_WIDTH; int height = (Height > 0) ? Height : DEFAULT_HEIGHT; if (MediaHelper.IsFlash(extension)) { // Initialize flash parameters FlashParameters flashParams = new FlashParameters(); flashParams.Height = height; flashParams.Width = width; flashParams.Url = url; ltlOutput.Text = MediaHelper.GetFlash(flashParams); } else { if (MediaHelper.IsAudio(extension)) { // Initialize audio/video parameters AudioVideoParameters audioParams = new AudioVideoParameters(); audioParams.SiteName = SiteContext.CurrentSiteName; audioParams.Url = url; audioParams.Width = width; audioParams.Height = height; audioParams.Extension = extension; ltlOutput.Text = MediaHelper.GetAudioVideo(audioParams); } else if (MediaHelper.IsVideo(extension)) { // Initialize audio/video parameters AudioVideoParameters videoParams = new AudioVideoParameters(); videoParams.SiteName = SiteContext.CurrentSiteName; videoParams.Url = url; videoParams.Width = width; videoParams.Height = height; videoParams.Extension = extension; ltlOutput.Text = MediaHelper.GetAudioVideo(videoParams); } } } } } }
/// <summary> /// Initializes the control properties. /// </summary> public void ReloadData(bool forceReload) { if (!binded || forceReload) { if (mData != null) { MediaFileInfo mfi = new MediaFileInfo(mData); bool completeUrl = false; // Get the site SiteInfo si; SiteInfo currentSite = SiteContext.CurrentSite; if (mfi.FileSiteID == currentSite.SiteID) { si = currentSite; } else { si = SiteInfoProvider.GetSiteInfo(mfi.FileSiteID); } if (si != null) { // Complete URL only for other site than current if (si.SiteID != currentSite.SiteID) { completeUrl = true; } string url = ""; if (UseSecureLinks) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } else { MediaLibraryInfo li = MediaLibraryInfoProvider.GetMediaLibraryInfo(mfi.FileLibraryID); if (li != null) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } else { url = MediaFileInfoProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } } } if (DisplayActiveContent) { 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)) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } 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.IsFlash(mfi.FileExtension)) { // Initialize flash parameters FlashParameters flashParams = new FlashParameters(); flashParams.Url = url; flashParams.Width = Width; flashParams.Height = Height; ltlOutput.Text = MediaHelper.GetFlash(flashParams); } else if (MediaHelper.IsAudio(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters audioParams = new AudioVideoParameters(); audioParams.SiteName = SiteContext.CurrentSiteName; audioParams.Url = url; audioParams.Width = Width; audioParams.Height = Height; audioParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(audioParams); } else if (MediaHelper.IsVideo(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters videoParams = new AudioVideoParameters(); videoParams.SiteName = SiteContext.CurrentSiteName; videoParams.Url = url; videoParams.Width = Width; videoParams.Height = Height; videoParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(videoParams); } else { ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } else { ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } } binded = true; } }