/// <summary> /// Gets the selected size URL. /// </summary> /// <param name="image">The image.</param> /// <returns></returns> protected virtual string GetSelectedSizeUrl(SfImage image) { if (image.Id == Guid.Empty) { return(string.Empty); } string imageUrl; var urlAsAbsolute = Config.Get <SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls; if (this.DisplayMode == ImageDisplayMode.Thumbnail || !string.IsNullOrWhiteSpace(this.ThumbnailName)) { imageUrl = image.ResolveThumbnailUrl(this.ThumbnailName, urlAsAbsolute); } else if (this.DisplayMode == ImageDisplayMode.Custom) { imageUrl = this.ThumbnailUrl; } else { var originalImageUrl = image.ResolveMediaUrl(urlAsAbsolute); imageUrl = originalImageUrl; } return(imageUrl); }
public void CreateImageControllerWithPropertiesAndImageItemPresented() { var image = new SfImage("App", new Guid("D4110267-C59C-4816-A080-64F59D9425DC")); var testModel = new DummyImageModel(image) { DisplayMode = ImageDisplayMode.Thumbnail, Id = new Guid("D4110267-C59C-4816-A080-64F59D9425DC"), UseAsLink = false }; // Arrange using (var controller = new DummyImageController(testModel)) { // Act var view = controller.Index() as ViewResult; // Assert Assert.IsNotNull(view.Model); var imageModel = view.Model as ImageViewModel; Assert.IsNotNull(imageModel.Item); Assert.IsTrue(imageModel.SelectedSizeUrl == "GetSelectedSizeUrl"); Assert.IsTrue(imageModel.Item.DataItem.Id == image.Id); Assert.IsTrue(imageModel.Item.DataItem.ApplicationName == image.ApplicationName); } }
/// <inheritDoc/> public virtual ImageViewModel GetViewModel() { var viewModel = new ImageViewModel() { AlternativeText = this.AlternativeText, Title = this.Title, DisplayMode = this.DisplayMode, ThumbnailName = this.ThumbnailName, ThumbnailUrl = this.ThumbnailUrl, CustomSize = this.CustomSize != null ? new JavaScriptSerializer().Deserialize <CustomSizeModel>(this.CustomSize) : null, UseAsLink = this.UseAsLink, CssClass = this.CssClass }; SfImage image; if (this.Id != Guid.Empty) { image = this.GetImage(); if (image != null) { viewModel.SelectedSizeUrl = this.GetSelectedSizeUrl(image); viewModel.LinkedContentUrl = GetLinkedUrl(image); } } else { image = new SfImage(); } viewModel.Item = new ItemViewModel(image); return(viewModel); }
public void CreateImageControllerWithPropertiesAndImageItemPresented() { var image = new SfImage("App", new Guid("D4110267-C59C-4816-A080-64F59D9425DC")); var testModel = new DummyImageModel(image) { DisplayMode = ImageDisplayMode.Thumbnail, Id = new Guid("D4110267-C59C-4816-A080-64F59D9425DC"), UseAsLink = false }; // Arrange using (var controller = new DummyImageController(testModel)) { // Act var view = controller.Index() as ViewResult; // Assert Assert.IsNotNull(view.Model); var imageModel = view.Model as ImageViewModel; Assert.IsNotNull(imageModel.Item); Assert.IsTrue(imageModel.SelectedSizeUrl == "GetSelectedSizeUrl"); Assert.IsTrue(imageModel.Item.DataItem.Id == image.Id); Assert.IsTrue(imageModel.Item.DataItem.ApplicationName == image.ApplicationName); } }
private void GetThumbnailSizes(out int width, out int height, SfImage image) { width = 0; height = 0; var thumbnailName = this.ThumbnailName != null ? this.ThumbnailName : string.Empty; var thumbnailProfile = this.GetDefaultAlbumThumbnailProfile(thumbnailName); if (thumbnailProfile != null) { var selectedThumbnail = image.Thumbnails.Where(t => t.Name == thumbnailProfile.Name).FirstOrDefault(); if (selectedThumbnail == null) { selectedThumbnail = LazyThumbnailGenerator.Instance.CreateThumbnail(image, thumbnailName); } if (selectedThumbnail != null) { width = selectedThumbnail.Width; height = selectedThumbnail.Height; } } }
public static string GetSelectedSizeUrl(SfImage image) { if (image.Id == Guid.Empty) { return(string.Empty); } var urlAsAbsolute = Config.Get <SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls; return(image.ResolveMediaUrl(urlAsAbsolute)); }
/// <summary> /// Gets the selected size URL. /// </summary> /// <param name="image">The image.</param> /// <returns></returns> protected virtual string GetSelectedSizeUrl(SfImage image) { if (image.Id == Guid.Empty) { return(string.Empty); } string imageUrl; var urlAsAbsolute = Config.Get <SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls; var originalImageUrl = image.ResolveMediaUrl(urlAsAbsolute); imageUrl = originalImageUrl; return(imageUrl); }
/// <summary> /// Gets the related media URL. /// </summary> /// <param name="item">The DynamicContent.</param> /// <returns>The media's relative Url</returns> public static string GetRelatedMediaUrl(DynamicContent item, string fieldName) { var relatedItem = item.GetRelatedItems(fieldName).FirstOrDefault(); if (relatedItem != null) { var imageId = relatedItem.Id; LibrariesManager manager = LibrariesManager.GetManager(); Telerik.Sitefinity.Libraries.Model.Image image = manager.GetImage(imageId); if (image != null) { return(image.MediaUrl); } } return(null); }
/// <summary> /// Handles the ItemDataBound event of the RadRotator1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Telerik.Web.UI.RadRotatorEventArgs"/> instance containing the event data.</param> protected void RadRotator1_ItemDataBound(object sender, RadRotatorEventArgs e) { var link = e.Item.FindControl("newsLink") as HyperLink; var image = e.Item.FindControl("newsImage") as Image; var imageBackgroundPanel = e.Item.FindControl("ImageBackgroundPanel") as Panel; var title = e.Item.FindControl("newsTitle") as Label; var text = e.Item.FindControl("newsText") as Label; NewsItem newsItem = (NewsItem)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsItem"].GetValue(e.Item.DataItem); Telerik.Sitefinity.Libraries.Model.Image newsImage = (Telerik.Sitefinity.Libraries.Model.Image)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsImage"].GetValue(e.Item.DataItem); if (image != null) { image.ImageUrl = newsImage.MediaUrl; } if (imageBackgroundPanel != null) { imageBackgroundPanel.BackImageUrl = newsImage.MediaUrl; } if (title != null) { title.Text = newsItem.Title; } if (text != null) { text.Text = newsItem.Summary; } if (link != null && this.TargetNewsPage != null) { link.NavigateUrl = DataResolver.Resolve(newsItem, "URL", null, this.TargetNewsPage.Id.ToString()); } var wrapperDiv = e.Item.FindControl("wrapperDiv") as Panel; if (wrapperDiv != null) { wrapperDiv.Width = this.Width; wrapperDiv.Height = this.Height; } }
public static string GetItemThumbnailImageUrl(this ItemViewModel dataItem, string targetField, int imageIndex) { if (dataItem.Fields != null) { DynamicDataItemFieldAccessor accessor = dataItem.Fields; ItemViewModel[] targetFieldValue = accessor.GetMemberValue(targetField) as ItemViewModel[]; if (targetFieldValue == null || targetFieldValue.Length == 0 || targetFieldValue.Length < imageIndex || targetFieldValue[imageIndex] == null) { return(string.Empty); } Telerik.Sitefinity.Libraries.Model.Image imageDataItem = targetFieldValue[imageIndex].DataItem as Telerik.Sitefinity.Libraries.Model.Image; return(imageDataItem.ThumbnailUrl); } return(string.Empty); }
/// <summary> /// Gets the linked page URL. /// </summary> /// <returns></returns> private string GetLinkedUrl(SfImage image) { string linkedUrl = null; if (this.UseAsLink && this.LinkedPageId != Guid.Empty) { var pageManager = PageManager.GetManager(); var node = pageManager.GetPageNode(this.LinkedPageId); if (node != null) { var relativeUrl = node.GetFullUrl(Telerik.Sitefinity.Services.SystemManager.CurrentContext.Culture, false, true); linkedUrl = UrlPath.ResolveUrl(relativeUrl, false); } } else if (this.UseAsLink && this.LinkedPageId == Guid.Empty) { linkedUrl = image.ResolveMediaUrl(false); } return(linkedUrl); }
/// <summary> /// Gets the linked page URL. /// </summary> /// <returns></returns> private string GetLinkedUrl(SfImage image) { string linkedUrl = null; if (this.UseAsLink && this.LinkedPageId != Guid.Empty) { var pageManager = PageManager.GetManager(); var node = pageManager.GetPageNode(this.LinkedPageId); if (node != null) { var relativeUrl = node.GetFullUrl(CultureInfo.CurrentUICulture, false); linkedUrl = UrlPath.ResolveUrl(relativeUrl, false); } } else if (this.UseAsLink && this.LinkedPageId == Guid.Empty) { linkedUrl = image.ResolveMediaUrl(false); } return(linkedUrl); }
/// <summary> /// Gets the linked page URL. /// </summary> /// <returns></returns> private string GetLinkedUrl(SfImage image) { string linkedUrl = null; if (this.UseAsLink && this.LinkedPageId != Guid.Empty) { var pageManager = PageManager.GetManager(); var node = pageManager.GetPageNode(this.LinkedPageId); if (node != null) { var provider = SiteMapBase.GetCurrentProvider(); var siteMapNode = provider.FindSiteMapNodeFromKey(node.Id.ToString()); linkedUrl = UrlPath.ResolveUrl(siteMapNode.Url, true); } } else if (this.UseAsLink && this.LinkedPageId == Guid.Empty) { linkedUrl = image.ResolveMediaUrl(true); } return(linkedUrl); }
public void CreateImageControllerWithProperties_CallTheIndexAction_EnsuresViewPropertiesArePresented() { var image = new SfImage("App", new Guid("D4110267-C59C-4816-A080-64F59D9425DC")); var testModel = new DummyImageModel(image) { AlternativeText = "AlternativeText", CssClass = "CssClass", CustomSize = "{'MaxWidth':11,'MaxHeight':11,'Width':null,'Height':null,'ScaleUp':true,'Quality':'Medium','Method':'ResizeFitToAreaArguments'}", DisplayMode = ImageDisplayMode.Thumbnail, Id = new Guid("D4110267-C59C-4816-A080-64F59D9425DC"), LinkedPageId = Guid.Empty, ProviderName = "OpenAccessDefaultProvider", ThumbnailName = "ThumbnailName", ThumbnailUrl = "ThumbnailUrl", Title = "Title", UseAsLink = false }; // Arrange using (var controller = new DummyImageController(testModel)) { // Act var view = controller.Index() as ViewResult; // Assert Assert.IsNotNull(view.Model); var imageModel = view.Model as ImageViewModel; Assert.IsNotNull(imageModel); Assert.IsTrue(imageModel.AlternativeText == testModel.AlternativeText); Assert.IsTrue(imageModel.CssClass == testModel.CssClass); Assert.IsTrue(imageModel.CustomSize.Equals(new JavaScriptSerializer().Deserialize <CustomSizeModel>(testModel.CustomSize))); Assert.IsTrue(imageModel.DisplayMode == testModel.DisplayMode); Assert.IsTrue(imageModel.ThumbnailName == testModel.ThumbnailName); Assert.IsTrue(imageModel.ThumbnailUrl == testModel.ThumbnailUrl); Assert.IsTrue(imageModel.Title == testModel.Title); } }
public void CreateImageControllerWithProperties_CallTheIndexAction_EnsuresViewPropertiesArePresented() { var image = new SfImage("App", new Guid("D4110267-C59C-4816-A080-64F59D9425DC")); var testModel = new DummyImageModel(image) { AlternativeText = "AlternativeText", CssClass = "CssClass", CustomSize = "{'MaxWidth':11,'MaxHeight':11,'Width':null,'Height':null,'ScaleUp':true,'Quality':'Medium','Method':'ResizeFitToAreaArguments'}", DisplayMode = ImageDisplayMode.Thumbnail, Id = new Guid("D4110267-C59C-4816-A080-64F59D9425DC"), LinkedPageId = Guid.Empty, ProviderName = "OpenAccessDefaultProvider", ThumbnailName = "ThumbnailName", ThumbnailUrl = "ThumbnailUrl", Title = "Title", UseAsLink = false }; // Arrange using (var controller = new DummyImageController(testModel)) { // Act var view = controller.Index() as ViewResult; // Assert Assert.IsNotNull(view.Model); var imageModel = view.Model as ImageViewModel; Assert.IsNotNull(imageModel); Assert.IsTrue(imageModel.AlternativeText == testModel.AlternativeText); Assert.IsTrue(imageModel.CssClass == testModel.CssClass); Assert.IsTrue(imageModel.CustomSize.Equals(new JavaScriptSerializer().Deserialize<CustomSizeModel>(testModel.CustomSize))); Assert.IsTrue(imageModel.DisplayMode == testModel.DisplayMode); Assert.IsTrue(imageModel.ThumbnailName == testModel.ThumbnailName); Assert.IsTrue(imageModel.ThumbnailUrl == testModel.ThumbnailUrl); Assert.IsTrue(imageModel.Title == testModel.Title); } }
public static string GetCurrentSiteFav() { var provider = LibrariesManager.GetManager().Provider.Name; LibrariesManager librariesManager = LibrariesManager.GetManager(provider); Telerik.Sitefinity.Libraries.Model.Image img = new Telerik.Sitefinity.Libraries.Model.Image(); img = librariesManager.GetImages().Where(i => i.Extension == ".ico" && i.Title.ToString().ToLower() == "favicon" && i.Status == ContentLifecycleStatus.Live && i.Visible).FirstOrDefault(); string url = "/favicon.ico"; if (img != null) { url = img.MediaUrl; } else { img = librariesManager.GetImages().Where(i => i.Title.ToString().ToLower() == "favicon" && i.Status == ContentLifecycleStatus.Live && i.Visible).FirstOrDefault(); if (img != null) { url = img.MediaUrl; } } return(url); }
public static Telerik.Sitefinity.Libraries.Model.Image ProcessStatuses(LibrariesManager manager, Telerik.Sitefinity.Libraries.Model.Image image, string status) { if (image == null) { return(null); } #region return right version of item bool isStatusSet = false; if (!string.IsNullOrEmpty(status)) { ContentLifecycleStatus itemStatus; if (Enum.TryParse <ContentLifecycleStatus>(status, out itemStatus)) { switch (itemStatus) { case ContentLifecycleStatus.Master: if (image.Status != ContentLifecycleStatus.Master) { image = (Telerik.Sitefinity.Libraries.Model.Image)manager.Lifecycle.GetMaster(image); isStatusSet = true; } break; case ContentLifecycleStatus.Temp: if (image.Status != ContentLifecycleStatus.Temp) { image = (Telerik.Sitefinity.Libraries.Model.Image)manager.Lifecycle.GetTemp(image); isStatusSet = true; } break; case ContentLifecycleStatus.Live: if (image.Status != ContentLifecycleStatus.Live) { image = (Telerik.Sitefinity.Libraries.Model.Image)manager.Lifecycle.GetLive(image); isStatusSet = true; } break; default: if (itemStatus != ContentLifecycleStatus.Deleted && image.Status != ContentLifecycleStatus.Live) { image = (Telerik.Sitefinity.Libraries.Model.Image)manager.Lifecycle.GetLive(image); isStatusSet = true; } break; } } } if (!isStatusSet) { if (image.Status != ContentLifecycleStatus.Live) { image = (Telerik.Sitefinity.Libraries.Model.Image)manager.Lifecycle.GetLive(image); isStatusSet = true; } } #endregion return(image); }
/// <summary> /// Updates the OG item model. /// </summary> /// <param name="itemsType">Type of the item</param> /// <param name="ogModel">The open graph model</param> /// <param name="pageUrl">The url</param> /// <returns> true or false</returns> private bool GetDataItemByType(Type itemsType, OpengraphModuleConfig ogModel, string pageUrl) { switch (itemsType.FullName) { //Default type case "Telerik.Sitefinity.News.Model.NewsItem": NewsManager newsManager = NewsManager.GetManager(); List <Telerik.Sitefinity.News.Model.NewsItem> items = newsManager.GetNewsItems().Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true).ToList(); Telerik.Sitefinity.News.Model.NewsItem item = items.FirstOrDefault(newsItem => newsItem.ItemDefaultUrl == pageUrl); if (item == null) { return(false); } //Default openGraphModel.ogTitle = item.Title.ToString(); //Given property if (item.DoesFieldExist(ogModel.TitlePropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = item.Summary != null?item.Summary.ToString() : openGraphDefaultDescription; //Given property if (item.DoesFieldExist(ogModel.DescriptionPropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image image = null; IDataItem newsImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (item.DoesFieldExist(ogModel.ImagePropertyName)) { if (item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { newsImage = item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (item.DoesFieldExist("OpenGraphImage")) { if (item.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (item.DoesFieldExist("LgszOpenGraphImage")) { if (item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (newsImage != null) { image = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == newsImage.Id); } if (image != null) { openGraphModel.ogImage = image.Url; } return(true); default: DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); try { string redirectUrl; DynamicContent currentDynamicItem = dynamicModuleManager.Provider.GetItemFromUrl(itemsType, pageUrl, true, out redirectUrl) as DynamicContent; if (currentDynamicItem == null) { return(false); } //Given property openGraphModel.ogTitle = openGraphDefaultTitle; if (!String.IsNullOrEmpty(ogModel.TitlePropertyName)) { openGraphModel.ogTitle = ParseFieldTags(ogModel.TitlePropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = openGraphDefaultDescription; if (!String.IsNullOrEmpty(ogModel.DescriptionPropertyName)) { openGraphModel.ogDescription = ParseFieldTags(ogModel.DescriptionPropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image img = null; IDataItem dynamicContentImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (currentDynamicItem.DoesFieldExist(ogModel.ImagePropertyName)) { if (currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("OpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("LgszOpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (dynamicContentImage != null) { img = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == dynamicContentImage.Id); } if (img != null) { openGraphModel.ogImage = img.Url; } return(true); } catch (Exception) { return(false); } } }
/// <summary> /// Gets the selected size URL. /// </summary> /// <param name="image">The image.</param> /// <returns></returns> protected virtual string GetSelectedSizeUrl(SfImage image) { if (image.Id == Guid.Empty) return string.Empty; string imageUrl; var urlAsAbsolute = Config.Get<SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls; var originalImageUrl = image.ResolveMediaUrl(urlAsAbsolute); imageUrl = originalImageUrl; return imageUrl; }
public SitefinityVirtualImage(Telerik.Sitefinity.Libraries.Model.Image image, LibrariesManager manager) { this.Image = image; this.Manager = manager; }
protected virtual string GetSelectedSizeUrl(SfImage image) { return(SfImageHelper.GetSelectedSizeUrl(image)); }
/// <inheritDoc/> public virtual ImageViewModel GetViewModel() { var viewModel = new ImageViewModel() { AlternativeText = this.AlternativeText, Title = this.Title, DisplayMode = this.DisplayMode, ThumbnailName = this.ThumbnailName, ThumbnailUrl = this.ThumbnailUrl, CustomSize = this.CustomSize != null ? new JavaScriptSerializer().Deserialize<CustomSizeModel>(this.CustomSize) : null, UseAsLink = this.UseAsLink, CssClass = this.CssClass }; SfImage image; if (this.Id != Guid.Empty) { image = this.GetImage(); if (image != null) { viewModel.SelectedSizeUrl = this.GetSelectedSizeUrl(image); viewModel.LinkedContentUrl = GetLinkedUrl(image); } } else { image = new SfImage(); } viewModel.Item = new ItemViewModel(image); return viewModel; }
/// <summary> /// Gets the selected size URL. /// </summary> /// <param name="image">The image.</param> /// <returns></returns> protected virtual string GetSelectedSizeUrl(SfImage image) { if (image.Id == Guid.Empty) return string.Empty; string imageUrl; var urlAsAbsolute = Config.Get<SystemConfig>().SiteUrlSettings.GenerateAbsoluteUrls; if (this.DisplayMode == ImageDisplayMode.Thumbnail || !string.IsNullOrWhiteSpace(this.ThumbnailName)) { imageUrl = image.ResolveThumbnailUrl(this.ThumbnailName, urlAsAbsolute); } else if (this.DisplayMode == ImageDisplayMode.Custom) { imageUrl = this.ThumbnailUrl; } else { var originalImageUrl = image.ResolveMediaUrl(urlAsAbsolute); imageUrl = originalImageUrl; } return imageUrl; }
/// <summary> /// Gets the linked page URL. /// </summary> /// <returns></returns> private string GetLinkedUrl(SfImage image) { string linkedUrl = null; if (this.UseAsLink && this.LinkedPageId != Guid.Empty) { var pageManager = PageManager.GetManager(); var node = pageManager.GetPageNode(this.LinkedPageId); if (node != null) { var relativeUrl = node.GetFullUrl(); linkedUrl = UrlPath.ResolveUrl(relativeUrl, true); } } else if (this.UseAsLink && this.LinkedPageId == Guid.Empty) { linkedUrl = image.ResolveMediaUrl(true); } return linkedUrl; }