public static bool BuildSitefinityReference(this CQ htmlElement, LinkedImageTagType tagType) { bool result = false; string attributeSource = ""; switch (tagType) { case LinkedImageTagType.Image: attributeSource = "src"; break; case LinkedImageTagType.Anchor: attributeSource = "href"; break; } string imgFile = Path.GetFileName(htmlElement.Attr(attributeSource)); var sfImg = App.WorkWith().Images().Where(i => i.Status == ContentLifecycleStatus.Master).Get().ToList().Where(i => Path.GetFileName(i.FilePath) == imgFile.ToLower()).FirstOrDefault(); if (sfImg != null) { var manager = LibrariesManager.GetManager(); var album = manager.GetAlbums().Where(a => a.Id == sfImg.Album.Id).FirstOrDefault(); string urlRoot = Telerik.Sitefinity.Configuration.Config.Get <LibrariesConfig>().Images.UrlRoot; var sfImgLive = App.WorkWith().Image(sfImg.Id).GetLive().Get(); var sfRef = "[" + urlRoot + "|" + (LibrariesDataProvider)album.Provider + "]" + sfImgLive.Id; htmlElement.Attr("sfref", sfRef); string relativeUrl = new Uri(sfImg.MediaUrl).AbsolutePath; htmlElement.Attr(attributeSource, relativeUrl); result = true; } return(result); }
public static bool BuildSitefinityReference(this CQ htmlElement, LinkedImageTagType tagType) { bool result = false; string attributeSource = ""; switch (tagType) { case LinkedImageTagType.Image: attributeSource = "src"; break; case LinkedImageTagType.Anchor: attributeSource = "href"; break; } string imgFile = Path.GetFileName(htmlElement.Attr(attributeSource)); var sfImg = App.WorkWith().Images().Where(i => i.Status == ContentLifecycleStatus.Master).Get().ToList().Where(i => Path.GetFileName(i.FilePath) == imgFile.ToLower()).FirstOrDefault(); if (sfImg != null) { var manager = LibrariesManager.GetManager(); var album = manager.GetAlbums().Where(a => a.Id == sfImg.Album.Id).FirstOrDefault(); string urlRoot = Telerik.Sitefinity.Configuration.Config.Get<LibrariesConfig>().Images.UrlRoot; var sfImgLive = App.WorkWith().Image(sfImg.Id).GetLive().Get(); var sfRef = "[" + urlRoot + "|" + (LibrariesDataProvider)album.Provider + "]" + sfImgLive.Id; htmlElement.Attr("sfref", sfRef); string relativeUrl = new Uri(sfImg.MediaUrl).AbsolutePath; htmlElement.Attr(attributeSource, relativeUrl); result = true; } return result; }