/// <summary> /// Builds the syndication item from the <paramref name="galleryObject" /> and having the properties specified /// in <paramref name="options" />. /// </summary> /// <param name="galleryObject">The gallery object.</param> /// <param name="options">The options that direct the creation of HTML and URLs for a media object.</param> /// <returns>An instance of <see cref="SyndicationItem" />.</returns> private static SyndicationItem BuildSyndicationItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions options) { options.GalleryObject = galleryObject; options.DisplayType = (galleryObject.GalleryObjectType == GalleryObjectType.External ? DisplayObjectType.External : DisplayObjectType.Optimized); var moBuilder = new MediaObjectHtmlBuilder(options); var pageUrl = moBuilder.GetPageUrl(); var content = GetGalleryObjectContent(galleryObject, pageUrl, moBuilder); var item = new SyndicationItem( RssEncode(HtmlValidator.RemoveHtml(galleryObject.Title, false)), SyndicationContent.CreateHtmlContent(content), new Uri(pageUrl), galleryObject.Id.ToString(CultureInfo.InvariantCulture), galleryObject.DateLastModified); item.PublishDate = galleryObject.DateAdded; item.Authors.Add(new SyndicationPerson() { Name = galleryObject.CreatedByUserName }); item.Categories.Add(new SyndicationCategory(galleryObject.GalleryObjectType.ToString())); return(item); }
/// <summary> /// Convert <paramref name="mqItem" /> to an instance of <see cref="MediaQueueItemWebEntity" />. Returns null if <paramref name="mqItem" /> is null. /// </summary> /// <param name="mqItem">The media queue item. May be null.</param> /// <returns><see cref="MediaQueueItemWebEntity" /> or null.</returns> private static MediaQueueItemWebEntity ToMediaQueueItem(MediaQueueItem mqItem) { if (mqItem == null) { return(null); } var mo = Factory.LoadMediaObjectInstance(mqItem.MediaObjectId); var moBuilderOptions = MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(mo); moBuilderOptions.DisplayType = DisplayObjectType.Thumbnail; var moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions); return(new MediaQueueItemWebEntity() { MediaQueueId = mqItem.MediaQueueId, MediaObjectId = mqItem.MediaObjectId, StatusInt = mqItem.Status, Status = mqItem.Status, ConversionType = mqItem.ConversionType, DateAdded = mqItem.DateAdded, DateConversionStarted = mqItem.DateConversionStarted, DateConversionCompleted = mqItem.DateConversionCompleted, DurationMs = GetDurationMs(mqItem), StatusDetail = mqItem.StatusDetail, OriginalFilename = mo.Original.FileName, NewFilename = mqItem.NewFilename, ThumbnailUrl = GetThumbnailUrl(moBuilder), MediaObjectTitle = mo.Title, AlbumId = mo.Parent.Id, AlbumTitle = mo.Parent.Title }); }
/// <summary> /// Calculates the URL to the thumbnail image of a media asset, with the host name excluded. /// Ex: "/gs/handler/getmedia.ashx?moid=34&dt=1&g=1" /// </summary> /// <param name="moBuilder">An instance of <see cref="MediaObjectHtmlBuilder" />.</param> /// <returns>An instance of <see cref="System.String" />.</returns> private static string GetThumbnailUrl(MediaObjectHtmlBuilder moBuilder) { // We remove the host URL (e.g. "http://localhost/dev/gs") to avoid sending the wrong host name to a user. For example, if two users are on the // media queue page but on different hosts (e.g. localhost and rdog), the GetMediaObjectUrl() function below will return the same host URL for // both users, potentially resulting in a broken link for one of them. This is because Utils.GetHostUrl() requires an HTTP context and when one // is not present (such as with SignalR), it falls back to the last known host URL (which may be for a different user). return(moBuilder.GetMediaObjectUrl().Replace(Utils.GetHostUrl(), string.Empty)); }
/// <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); }
/// <summary> /// Asynchronously writes an object of the specified type. /// </summary> /// <param name="type">The type of the object to write.</param> /// <param name="value">The object value to write. It may be null. If not null, must be able to /// be cast to an <see cref="IAlbum" />.</param> /// <param name="writeStream">The <see cref="T:System.IO.Stream" /> to which to write.</param> /// <param name="content">The <see cref="T:System.Net.Http.HttpContent" /> if available. It may be null.</param> /// <param name="transportContext">The <see cref="T:System.Net.TransportContext" /> if available. It may be null.</param> /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that will perform the write.</returns> /// <exception cref="GallerySecurityException">Thrown when the application is not running an Enterprise License. /// </exception> public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { if (value == null) { return(null); } var album = (IAlbum)value; var options = MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(album, DisplayObjectType.Thumbnail); var isAuthenticated = Utils.IsAuthenticated; options.DestinationPageUrl = album.FeedFormatterOptions.DestinationUrl; // Ex: "/dev/gs/default.aspx" return(Task.Factory.StartNew(() => BuildSyndicationFeed(album, writeStream, content.Headers.ContentType.MediaType, options, isAuthenticated))); }
/// <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> /// Builds the syndication item from the <paramref name="galleryObject" /> and having the properties specified /// in <paramref name="options" />. /// </summary> /// <param name="galleryObject">The gallery object.</param> /// <param name="options">The options that direct the creation of HTML and URLs for a media object.</param> /// <returns>An instance of <see cref="SyndicationItem" />.</returns> private static SyndicationItem BuildSyndicationItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions options) { options.GalleryObject = galleryObject; options.DisplayType = (galleryObject.GalleryObjectType == GalleryObjectType.External ? DisplayObjectType.External : DisplayObjectType.Optimized); var moBuilder = new MediaObjectHtmlBuilder(options); var pageUrl = moBuilder.GetPageUrl(); var content = GetGalleryObjectContent(galleryObject, pageUrl, moBuilder); var item = new SyndicationItem( RssEncode(HtmlValidator.RemoveHtml(galleryObject.Title, false)), SyndicationContent.CreateHtmlContent(content), new Uri(pageUrl), galleryObject.Id.ToString(CultureInfo.InvariantCulture), galleryObject.DateLastModified); item.PublishDate = galleryObject.DateAdded; item.Authors.Add(new SyndicationPerson() { Name = galleryObject.CreatedByUserName }); item.Categories.Add(new SyndicationCategory(galleryObject.GalleryObjectType.ToString())); return item; }
/// <summary> /// Gets the media object with the specified <paramref name="id" />. /// Example: api/mediaitems/4/get /// </summary> /// <param name="id">The media object ID.</param> /// <returns>An instance of <see cref="Entity.MediaItem" />.</returns> /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the media object is not found, the user /// doesn't have permission to view it, or some other error occurs.</exception> public Entity.MediaItem Get(int id) { try { IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(id); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), mediaObject.Parent.Id, mediaObject.GalleryId, Utils.IsAuthenticated, mediaObject.Parent.IsPrivate, ((IAlbum)mediaObject.Parent).IsVirtualAlbum); var siblings = mediaObject.Parent.GetChildGalleryObjects(GalleryObjectType.MediaObject, !Utils.IsAuthenticated).ToSortedList(); int mediaObjectIndex = siblings.IndexOf(mediaObject); return(GalleryObjectController.ToMediaItem(mediaObject, mediaObjectIndex + 1, MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(mediaObject))); } catch (InvalidMediaObjectException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(String.Format("Could not find media object with ID = {0}", id)), ReasonPhrase = "Media Object Not Found" }); } catch (GallerySecurityException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (Exception ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = Utils.GetExStringContent(ex), ReasonPhrase = "Server Error" }); } }
private static string GetGpsMapUrl(IGalleryObject galleryObject, string latitude, string longitude, string gpsLocation) { //string urlTemplate = "<a href='http://bing.com/maps/default.aspx?sp=point.{GpsLatitude}_{GpsLongitude}_{TitleNoHtml}__{MediaObjectPageUrl}_{MediaObjectUrl}&style=a&lvl=13' target='_blank' title='View map'>{GpsLocation}</a>"; //string urlTemplate = "<a href='http://maps.google.com/maps?q={GpsLatitude},{GpsLongitude}+({TitleNoHtml})' target='_blank' title='View map'>{GpsLocation}</a>"; string urlTemplate = Factory.LoadGallerySetting(galleryObject.GalleryId).GpsMapUrlTemplate; if (String.IsNullOrEmpty(urlTemplate)) { return(String.Empty); } // Replace the tokens with actual values. urlTemplate = urlTemplate.Replace("{GpsLatitude}", latitude); urlTemplate = urlTemplate.Replace("{GpsLongitude}", longitude); urlTemplate = urlTemplate.Replace("{TitleNoHtml}", Util.UrlEncode(Util.RemoveHtmlTags(galleryObject.Title, true))); urlTemplate = urlTemplate.Replace("{MediaObjectPageUrl}", Util.UrlEncode(String.Concat(Util.GetHostUrl(), Util.GetUrl(PageId.mediaobject, "moid={0}", galleryObject.Id)))); urlTemplate = urlTemplate.Replace("{MediaObjectUrl}", Util.UrlEncode(String.Concat(Util.GetHostUrl(), MediaObjectHtmlBuilder.GenerateUrl(galleryObject.GalleryId, galleryObject.Id, DisplayObjectType.Thumbnail)))); urlTemplate = urlTemplate.Replace("{GpsLocation}", gpsLocation); return(urlTemplate); }
/// <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> /// 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; }
public MediaObjectHtmlBuilderOptions GetMediaObjectHtmlBuilderOptions(IGalleryObject galleryObject) { return(MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(galleryObject, _urlController)); }
/// <summary> /// Gets the HTML to display a nicely formatted thumbnail image of the specified <paramref name="galleryObject" />, including a /// border, shadows and (possibly) rounded corners. This function is the same as calling the overloaded version with /// includeHyperlinkToObject and allowAlbumTextWrapping parameters both set to <c>false</c>. /// </summary> /// <param name="galleryObject">The gallery object to be used as the source for the thumbnail image.</param> /// <returns>Returns HTML that displays a nicely formatted thumbnail image of the specified <paramref name="galleryObject" /></returns> public static string GetThumbnailHtml(IGalleryObject galleryObject) { var moBuilder = new MediaObjectHtmlBuilder(MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(galleryObject, DisplayObjectType.Thumbnail)); return moBuilder.GetThumbnailHtml(); }
/// <summary> /// Get an absolute URL to the thumbnail, optimized, or original media object. /// Ex: "http://site.com/gallery/gs/handler/getmedia.ashx?moid=34&dt=1&g=1" /// The URL can be used to assign to the src attribute of an image tag (<img src='...' />). /// Not tested: It should be possible to pass an album and request the url to its thumbnail image. /// </summary> /// <param name="galleryObject">The gallery object for which an URL to the specified image is to be generated.</param> /// <param name="displayType">A DisplayObjectType enumeration value indicating the version of the /// object for which the URL should be generated. Possible values: Thumbnail, Optimized, Original. /// An exception is thrown if any other enumeration is passed.</param> /// <returns>Returns the URL to the thumbnail, optimized, or original version of the requested media object.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="galleryObject" /> is null.</exception> public static string GetGalleryObjectUrl(IGalleryObject galleryObject, DisplayObjectType displayType) { if (galleryObject == null) { throw new ArgumentNullException("galleryObject"); } if (galleryObject is Album && (displayType != DisplayObjectType.Thumbnail)) { throw new ArgumentException(String.Format("It is invalid to request an URL for an album display type '{0}'.", displayType)); } var moBuilder = new MediaObjectHtmlBuilder(MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(galleryObject, displayType)); return moBuilder.GetMediaObjectUrl(); }
/// <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; }