Beispiel #1
0
        /// <summary>
        /// Gets a collection of views for the <paramref name="galleryObject" />.
        /// </summary>
        /// <param name="galleryObject">The gallery object. May be an album or media object.</param>
        /// <param name="browsers">An <see cref="System.Array"/> of browser ids for the current browser. This
        /// is a list of strings that represent the various categories of browsers the current browser belongs
        /// to. This is typically populated by calling ToArray() on the Request.Browser.Browsers property.</param>
        /// <returns>Returns a collection of <see cref="Entity.DisplayObject" /> instances.</returns>
        private static List <DisplayObject> GetViews(IGalleryObject galleryObject, Array browsers)
        {
            var views = new List <DisplayObject>(3);

            IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(galleryObject, galleryObject.Thumbnail, browsers);

            views.Add(new DisplayObject
            {
                ViewSize     = (int)moBuilder.DisplayType,
                ViewType     = (int)moBuilder.MimeType.TypeCategory,
                HtmlOutput   = moBuilder.GenerateHtml(),
                ScriptOutput = moBuilder.GenerateScript(),
                Width        = moBuilder.Width,
                Height       = moBuilder.Height,
                Url          = moBuilder.GenerateUrl()
            });

            if (HasOptimizedVersion(galleryObject))
            {
                moBuilder = new MediaObjectHtmlBuilder(galleryObject, galleryObject.Optimized, browsers);
                DisplayObject optimizedDisplayObject = new DisplayObject
                {
                    ViewSize     = (int)moBuilder.DisplayType,
                    ViewType     = (int)moBuilder.MimeType.TypeCategory,
                    HtmlOutput   = moBuilder.GenerateHtml(),
                    ScriptOutput = moBuilder.GenerateScript(),
                    Width        = moBuilder.Width,
                    Height       = moBuilder.Height,
                    Url          = moBuilder.GenerateUrl()
                };
                views.Add(optimizedDisplayObject);
            }

            if (HasOriginalVersion(galleryObject))
            {
                moBuilder = new MediaObjectHtmlBuilder(galleryObject, galleryObject.Original, browsers);
                views.Add(new DisplayObject
                {
                    ViewSize     = (int)moBuilder.DisplayType,
                    ViewType     = (int)moBuilder.MimeType.TypeCategory,
                    HtmlOutput   = moBuilder.GenerateHtml(),
                    ScriptOutput = moBuilder.GenerateScript(),
                    Width        = moBuilder.Width,
                    Height       = moBuilder.Height,
                    Url          = moBuilder.GenerateUrl()
                });
            }

            return(views);
        }
Beispiel #2
0
        /// <summary>
        /// Gets an HTML string representing the content of the <paramref name="galleryObject" />. For example,
        /// albums contain the title and caption while images contain a hyperlinked img tag pointing to
        /// <paramref name="pageUrl" />. Other media objects contain the HTML generated by <paramref name="moBuilder" />.
        /// </summary>
        /// <param name="galleryObject">The gallery object.</param>
        /// <param name="pageUrl">An URL pointing to a gallery page for the <paramref name="galleryObject" />
        /// Images use this value to create a hyperlink that is wrapped around the img tag.</param>
        /// <param name="moBuilder">An instance of <see cref="MediaObjectHtmlBuilder" />.</param>
        /// <returns><see cref="System.String" />.</returns>
        private static string GetGalleryObjectContent(IGalleryObject galleryObject, string pageUrl, MediaObjectHtmlBuilder moBuilder)
        {
            switch (galleryObject.GalleryObjectType)
            {
            case GalleryObjectType.Image:
                return(String.Format("<div><a href='{0}'>{1}</a></div><p>{2}</p><p>{3}</p>", pageUrl, moBuilder.GenerateHtml(), galleryObject.Title, galleryObject.Caption));

            case GalleryObjectType.Album:
                return(String.Format("<p>{0}</p><p>{1}</p>", galleryObject.Title, galleryObject.Caption));

            default:
                // Don't include the hyperlink around the MO HTML because that interferes with audio/video controls.
                return(String.Format("<div>{0}</div><p>{1}</p><p>{2}</p>", moBuilder.GenerateHtml(), galleryObject.Title, galleryObject.Caption));
            }
        }
        /// <summary>
        /// Gets an HTML string representing the content of the <paramref name="galleryObject" />. For example,
        /// albums contain the title and caption while images contain a hyperlinked img tag pointing to 
        /// <paramref name="pageUrl" />. Other media objects contain the HTML generated by <paramref name="moBuilder" />.
        /// </summary>
        /// <param name="galleryObject">The gallery object.</param>
        /// <param name="pageUrl">An URL pointing to a gallery page for the <paramref name="galleryObject" />
        /// Images use this value to create a hyperlink that is wrapped around the img tag.</param>
        /// <param name="moBuilder">An instance of <see cref="MediaObjectHtmlBuilder" />.</param>
        /// <returns><see cref="System.String" />.</returns>
        private static string GetGalleryObjectContent(IGalleryObject galleryObject, string pageUrl, MediaObjectHtmlBuilder moBuilder)
        {
            switch (galleryObject.GalleryObjectType)
            {
                case GalleryObjectType.Image:
                    return String.Format("<div><a href='{0}'>{1}</a></div><p>{2}</p><p>{3}</p>", pageUrl, moBuilder.GenerateHtml(), galleryObject.Title, galleryObject.Caption);

                case GalleryObjectType.Album:
                    return String.Format("<p>{0}</p><p>{1}</p>", galleryObject.Title, galleryObject.Caption);

                default:
                    // Don't include the hyperlink around the MO HTML because that interferes with audio/video controls.
                    return String.Format("<div>{0}</div><p>{1}</p><p>{2}</p>", moBuilder.GenerateHtml(), galleryObject.Title, galleryObject.Caption);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Get information for the specified media object, including its previous and next media object.
        /// </summary>
        /// <param name="mediaObject">The media object.</param>
        /// <param name="displayType">The type of display object to receive (thumbnail, optimized, original).</param>
        /// <param name="isCallBack">Indicates whether the current invocation is caused by an AJAX callback.</param>
        /// <returns>
        /// Returns an instance of MediaObjectWebEntity containing information for the specified media object,
        /// including its previous and next media object.
        /// </returns>
        internal static MediaObjectWebEntity GetMediaObjectHtml(IGalleryObject mediaObject, DisplayObjectType displayType, bool isCallBack)
        {
            // Get the information about the specified media object, its previous one, next one, and the next one in a slide show.
            Array browsers = Utils.GetBrowserIdsForCurrentRequest();

            if ((displayType == DisplayObjectType.Original) && (!Utils.IsUserAuthorized(SecurityActions.ViewOriginalImage, RoleController.GetGalleryServerRolesForUser(), mediaObject.Parent.Id, mediaObject.GalleryId, ((IAlbum)mediaObject.Parent).IsPrivate)))
            {
                displayType = DisplayObjectType.Optimized;
            }

            bool excludePrivateObjects = !Utils.IsAuthenticated;

            MediaObjectWebEntity mo = new MediaObjectWebEntity();

            #region Step 1: Process current media object

            if (mediaObject.Id > 0)
            {
                // This section is enclosed in the above if statement to force all declared variables within it to be local so they are
                // not accidentally re-used in steps 2 or 3. In reality, mediaObject.Id should ALWAYS be greater than 0.
                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(mediaObject, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(mediaObject.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(mediaObject.Original.ExternalHtmlSource, mediaObject.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(mediaObject.Id, mediaObject.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, mediaObject.Title, browsers, displayType, mediaObject.IsPrivate, mediaObject.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Get the siblings of this media object and the index that specifies its position within its siblings.

                //TODO: This technique for identifying the index is very expensive when there are a lot of objects in the album.
                IGalleryObjectCollection siblings = ((IAlbum)mediaObject.Parent).GetChildGalleryObjects(GalleryObjectType.MediaObject, true, excludePrivateObjects);
                int mediaObjectIndex = siblings.IndexOf(mediaObject);

                // Build up the entity object we'll be sending to the client.
                bool moIsImage = (mediaObject is GalleryServerPro.Business.Image);
                bool moIsExternalObject = (mediaObject is GalleryServerPro.Business.ExternalMediaObject);
                mo.Id = mediaObject.Id;
                mo.Index = mediaObjectIndex;
                mo.NumObjectsInAlbum = siblings.Count;
                mo.Title = mediaObject.Title;
                mo.PrevId = GetPreviousMediaObjectId(mediaObjectIndex, siblings);
                mo.NextId = GetNextMediaObjectId(mediaObjectIndex, siblings);
                mo.NextSSId = GetNextMediaObjectIdForSlideshow(mediaObjectIndex, siblings);
                mo.HtmlOutput = htmlOutput;
                mo.ScriptOutput = scriptOutput;
                mo.Width = displayObject.Width;
                mo.Height = displayObject.Height;
                mo.HiResAvailable = (moIsImage && (!String.IsNullOrEmpty(mediaObject.Optimized.FileName)) && (mediaObject.Original.FileName != mediaObject.Optimized.FileName));
                mo.IsDownloadable = !moIsExternalObject;
            }

            #endregion

            #region Step 2: Process previous media object

            if (mo.PrevId > 0)
            {
                IGalleryObject prevMO = Factory.LoadMediaObjectInstance(mo.PrevId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(prevMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(prevMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(prevMO.Original.ExternalHtmlSource, prevMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(prevMO.Id, prevMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, prevMO.Title, browsers, displayType, prevMO.IsPrivate, prevMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Build up the entity object we'll be sending to the client.
                bool prevMoIsImage = (prevMO is GalleryServerPro.Business.Image);
                bool prevMoIsExternalObject = (prevMO is GalleryServerPro.Business.ExternalMediaObject);
                mo.PrevTitle = prevMO.Title;
                mo.PrevHtmlOutput = htmlOutput;
                mo.PrevScriptOutput = scriptOutput;
                mo.PrevWidth = displayObject.Width;
                mo.PrevHeight = displayObject.Height;
                mo.PrevHiResAvailable = (prevMoIsImage && (!String.IsNullOrEmpty(prevMO.Optimized.FileName)) && (prevMO.Original.FileName != prevMO.Optimized.FileName));
                mo.PrevIsDownloadable = !prevMoIsExternalObject;
            }

            #endregion

            #region Step 3: Process next media object

            if (mo.NextId > 0)
            {
                IGalleryObject nextMO = Factory.LoadMediaObjectInstance(mo.NextId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(nextMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(nextMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextMO.Original.ExternalHtmlSource, nextMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextMO.Id, nextMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, nextMO.Title, browsers, displayType, nextMO.IsPrivate, nextMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Build up the entity object we'll be sending to the client.
                bool nextMoIsImage = (nextMO is GalleryServerPro.Business.Image);
                bool nextMoIsExternalObject = (nextMO is GalleryServerPro.Business.ExternalMediaObject);
                mo.NextTitle = nextMO.Title;
                mo.NextHtmlOutput = htmlOutput;
                mo.NextScriptOutput = scriptOutput;
                mo.NextWidth = displayObject.Width;
                mo.NextHeight = displayObject.Height;
                mo.NextHiResAvailable = (nextMoIsImage && (!String.IsNullOrEmpty(nextMO.Optimized.FileName)) && (nextMO.Original.FileName != nextMO.Optimized.FileName));
                mo.NextIsDownloadable = !nextMoIsExternalObject;
            }

            #endregion

            #region Step 4: Process next slide show media object

            if (mo.NextSSId > 0)
            {
                IGalleryObject nextSSMO = Factory.LoadMediaObjectInstance(mo.NextSSId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(nextSSMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                string url = String.Empty;
                if (!String.IsNullOrEmpty(nextSSMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextSSMO.Original.ExternalHtmlSource, nextSSMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextSSMO.Id, nextSSMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, nextSSMO.Title, browsers, displayType, nextSSMO.IsPrivate, nextSSMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                    url = moBuilder.GenerateUrl();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Get the siblings of this media object and the index that specifies its position within its siblings.

                //TODO: This technique for identifying the index is very expensive when there are a lot of objects in the album.
                IGalleryObjectCollection siblings = ((IAlbum)nextSSMO.Parent).GetChildGalleryObjects(GalleryObjectType.MediaObject, true, excludePrivateObjects);
                int mediaObjectIndex = siblings.IndexOf(nextSSMO);

                // Build up the entity object we'll be sending to the client.
                bool nextSSMoIsImage = (nextSSMO is GalleryServerPro.Business.Image);
                mo.NextSSIndex = mediaObjectIndex;
                mo.NextSSTitle = nextSSMO.Title;
                mo.NextSSUrl = url;
                mo.NextSSHtmlOutput = htmlOutput;
                mo.NextSSScriptOutput = scriptOutput;
                mo.NextSSWidth = displayObject.Width;
                mo.NextSSHeight = displayObject.Height;
                mo.NextSSHiResAvailable = (nextSSMoIsImage && (!String.IsNullOrEmpty(nextSSMO.Optimized.FileName)) && (nextSSMO.Original.FileName != nextSSMO.Optimized.FileName));
                mo.NextSSIsDownloadable = true; // Slide show objects are always locally stored images and are therefore always downloadable
            }

            #endregion

            #region Step 5: Update Previous Uri variable

            if (HttpContext.Current.Session != null)
            {
                Uri backURL = Utils.PreviousUri;
                if (isCallBack && (backURL != null))
                {
                    // We are in a callback. Even though the page hasn't changed, the user is probably viewing a different media object,
                    // so update the moid query string parameter so that the referring url points to the current media object.
                    backURL = UpdateUriQueryString(backURL, "moid", mediaObject.Id.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    backURL = Utils.GetCurrentPageUri();
                }

                Utils.PreviousUri = backURL;
            }

            #endregion

            return mo;
        }
        /// <summary>
        /// Gets a collection of views corresponding to the gallery object and other specs in <paramref name="moBuilderOptions" />.
        /// </summary>
        /// <param name="moBuilderOptions">A set of properties to be used when building the output.</param>
        /// <returns>Returns a collection of <see cref="Entity.DisplayObject" /> instances.</returns>
        private static List<Entity.DisplayObject> GetViews(MediaObjectHtmlBuilderOptions moBuilderOptions)
        {
            var views = new List<Entity.DisplayObject>(3);

            moBuilderOptions.DisplayType = DisplayObjectType.Thumbnail;

            var moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions);

            views.Add(new Entity.DisplayObject
            {
                ViewSize = (int)DisplayObjectType.Thumbnail,
                ViewType = (int)moBuilder.MimeType.TypeCategory,
                HtmlOutput = moBuilder.GenerateHtml(),
                ScriptOutput = moBuilder.GenerateScript(),
                Width = moBuilder.Width,
                Height = moBuilder.Height,
                Url = moBuilder.GetMediaObjectUrl()
            });

            if (HasOptimizedVersion(moBuilderOptions.GalleryObject))
            {
                moBuilderOptions.DisplayType = DisplayObjectType.Optimized;

                moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions);

                views.Add(new Entity.DisplayObject
                {
                    ViewSize = (int)DisplayObjectType.Optimized,
                    ViewType = (int)moBuilder.MimeType.TypeCategory,
                    HtmlOutput = moBuilder.GenerateHtml(),
                    ScriptOutput = moBuilder.GenerateScript(),
                    Width = moBuilder.Width,
                    Height = moBuilder.Height,
                    Url = moBuilder.GetMediaObjectUrl()
                });
            }

            if (HasOriginalVersion(moBuilderOptions.GalleryObject))
            {
                moBuilderOptions.DisplayType = moBuilderOptions.GalleryObject.Original.DisplayType; // May be Original or External

                moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions);

                views.Add(new Entity.DisplayObject
                {
                    ViewSize = (int)DisplayObjectType.Original,
                    ViewType = (int)moBuilder.MimeType.TypeCategory,
                    HtmlOutput = moBuilder.GenerateHtml(),
                    ScriptOutput = moBuilder.GenerateScript(),
                    Width = moBuilder.Width,
                    Height = moBuilder.Height,
                    Url = moBuilder.GetMediaObjectUrl()
                });
            }

            return views;
        }