/// <summary>
    /// Setup general values.
    /// </summary>
    private void SetupFile()
    {
        // Get file and library info
        if ((FileInfo != null) && (LibraryInfo != null))
        {
            formMediaFileCustomFields.IsLiveSite = IsLiveSite;

            if (MediaLibraryHelper.IsExternalLibrary(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder))
            {
                plcDirPath.Visible = false;
            }
            else
            {
                string url = MediaFileInfoProvider.GetMediaFileUrl(LibrarySiteInfo.SiteName, LibraryInfo.LibraryFolder, FileInfo.FilePath);
                ltrDirPathValue.Text = GetFileLinkHtml(ResolveUrl(url));
            }
            ltrPermaLinkValue.Text = GetFileLinkHtml(ResolveUrl(MediaFileInfoProvider.GetMediaFileUrl(FileInfo.FileGUID, FileInfo.FileName)));
            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(MediaFileInfoProvider.GetMediaFileUrl(FileInfo.FileGUID, CMSContext.CurrentSiteName), "maxsidesize", "200");
                imagePreview.URL        = URLHelper.AddParameterToUrl(imagePreview.URL, "chset", Guid.NewGuid().ToString());
                plcImagePreview.Visible = true;
                plcMediaPreview.Visible = false;

                pnlPrew.Visible = true;
            }
            else if (MediaHelper.IsFlash(FileInfo.FileExtension) || MediaHelper.IsAudio(FileInfo.FileExtension) ||
                     MediaHelper.IsVideo(FileInfo.FileExtension))
            {
                if (MediaHelper.IsAudio(FileInfo.FileExtension))
                {
                    mediaPreview.Height = 45;
                }
                else
                {
                    mediaPreview.Height = 180;
                }
                mediaPreview.Width = 270;

                mediaPreview.AutoPlay   = false;
                mediaPreview.AVControls = true;
                mediaPreview.Loop       = false;
                mediaPreview.Menu       = true;
                mediaPreview.Type       = FileInfo.FileExtension;

                // If is Image show image properties
                mediaPreview.Url        = MediaFileInfoProvider.GetMediaFileUrl(FileInfo.FileGUID, FileInfo.FileName);
                plcMediaPreview.Visible = true;
                plcImagePreview.Visible = false;

                pnlPrew.Visible = true;
            }
            else
            {
                pnlPrew.Visible = false;
            }
        }
        else
        {
            pnlPrew.Visible = false;
        }
    }
Example #2
0
    /// <summary>
    /// Loads preview according item type.
    /// </summary>
    /// <param name="fileName">Name fo the file to load preview for</param>
    private void LoadPreview(string fileName)
    {
        // Load preview
        string url = "";

        if (GetItemUrl != null)
        {
            url = GetItemUrl(fileName);
        }

        string ext = Path.GetExtension(fileName);

        if (ImageHelper.IsImage(ext))
        {
            hdnPreviewType.Value = "image";

            // Get image physical path
            string filePath = (string.IsNullOrEmpty(FolderPath)) ? fileName : DirectoryHelper.CombinePath(FolderPath, fileName);
            filePath = MediaFileInfoProvider.GetMediaFilePath(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder, filePath);

            if (File.Exists(filePath))
            {
                // Load image info
                ImageHelper ih = new ImageHelper();
                ih.LoadImage(File.ReadAllBytes(filePath));

                // Get new dimensions
                int   origWidth     = ValidationHelper.GetInteger(ih.ImageWidth, 0);
                int   origHeight    = ValidationHelper.GetInteger(ih.ImageHeight, 0);
                int[] newDimensions = ImageHelper.EnsureImageDimensions(0, 0, 300, origWidth, origHeight);

                // Image preview
                imagePreview.ShowFileIcons = false;
                imagePreview.URL           = url;
                imagePreview.SizeToURL     = false;
                imagePreview.Width         = newDimensions[0];
                imagePreview.Height        = newDimensions[1];
                imagePreview.Alt           = fileName;
                imagePreview.Tooltip       = fileName;

                // Open link
                lnkOpenImage.Target      = "_blank";
                lnkOpenImage.Text        = GetString("media.file.openimg");
                lnkOpenImage.ToolTip     = GetString("media.file.openimg");
                lnkOpenImage.NavigateUrl = url;
            }
        }
        else if (MediaHelper.IsAudioVideo(ext) || MediaHelper.IsFlash(ext))
        {
            hdnPreviewType.Value = "media";

            // Media preview
            mediaPreview.Height     = 200;
            mediaPreview.Width      = 300;
            mediaPreview.AVControls = true;
            mediaPreview.Loop       = true;
            mediaPreview.Url        = url;
            mediaPreview.Type       = ext;

            // Open link
            lnkOpenMedia.Target      = "_blank";
            lnkOpenMedia.Text        = GetString("media.file.openimg");
            lnkOpenMedia.ToolTip     = GetString("media.file.openimg");
            lnkOpenMedia.NavigateUrl = url;
        }
        else
        {
            hdnPreviewType.Value = "other";

            // Open link
            lnkOpenOther.Target      = "_blank";
            lnkOpenOther.Text        = GetString("general.open");
            lnkOpenOther.ToolTip     = GetString("general.open");
            lnkOpenOther.NavigateUrl = url;
        }
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    public void ReloadData(bool forceReload)
    {
        if (!binded || forceReload)
        {
            if (mData != null)
            {
                MediaFileInfo mfi = new MediaFileInfo(mData);
                if (mfi != null)
                {
                    bool completeUrl = false;

                    // Get the site
                    SiteInfo si          = null;
                    SiteInfo currentSite = CMSContext.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  = CMSContext.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  = CMSContext.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, DefaultImageUrl);
                            }
                        }
                        else
                        {
                            ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page, DefaultImageUrl);
                        }
                    }
                }
            }
            binded = true;
        }
    }
    /// <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  = CMSContext.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  = CMSContext.CurrentSiteName;
                            videoParams.Url       = url;
                            videoParams.Width     = width;
                            videoParams.Height    = height;
                            videoParams.Extension = extension;

                            ltlOutput.Text = MediaHelper.GetAudioVideo(videoParams);
                        }
                    }
                }
            }
        }
    }