Beispiel #1
0
    /// <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 = 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, SiteContext.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))
            {
                mediaPreview.Height = MediaHelper.IsAudio(FileInfo.FileExtension) ? 45 : 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;
        }
    }
    /// <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;
        }
    }