/// <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); }
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> /// 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; }