public void BuildNewsImagesXml( XmlDocument doc, XmlElement root) { string imageFolderPath = NewsHelper.MediaFolderPath(basePage.SiteId, news.NewsID); string thumbnailImageFolderPath = imageFolderPath + "thumbs/"; string siteRoot = WebUtils.GetSiteRoot(); int defaultLanguageId = -1; string defaultCulture = WebConfigSettings.DefaultLanguageCulture; if (defaultCulture.Length > 0) { defaultLanguageId = LanguageHelper.GetLanguageIdByCulture(defaultCulture); } List <int> listDisplayOrder = new List <int>(); List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(news.NewsGuid); foreach (ContentMedia media in listMedia) { if (media.LanguageId == -1 || media.LanguageId == languageId || (languageId == -1 && media.LanguageId == defaultLanguageId)) { BuildNewsImagesXml(doc, root, media, imageFolderPath, thumbnailImageFolderPath); if (displaySettings.ShowGroupImages) { if (!listDisplayOrder.Contains(media.DisplayOrder)) { listDisplayOrder.Add(media.DisplayOrder); XmlElement groupImages = doc.CreateElement("GroupImages"); root.AppendChild(groupImages); XmlHelper.AddNode(doc, groupImages, "DisplayOrder", media.DisplayOrder.ToString()); foreach (ContentMedia media2 in listMedia) { if ((media2.LanguageId == -1 || media2.LanguageId == languageId || (languageId == -1 && media2.LanguageId == defaultLanguageId)) && (media2.DisplayOrder == media.DisplayOrder)) { BuildNewsImagesXml(doc, groupImages, media2, imageFolderPath, thumbnailImageFolderPath); } } } } string relativePath = siteRoot + Page.ResolveUrl(imageFolderPath + media.MediaFile); basePage.AdditionalMetaMarkup += "\n<meta property=\"og:image\" content=\"" + relativePath + "\" />"; basePage.AdditionalMetaMarkup += "\n<meta itemprop=\"image\" content=\"" + relativePath + "\" />"; } } }
protected void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { List <ContentMedia> listMedia = null; if (news != null) { listMedia = ContentMedia.GetByContentDesc(news.NewsGuid); grid.DataSource = listMedia; if (listMedia.Count > 0) { btnDeleteImage.Visible = true; } } }
public void BuildNewsImagesXml( XmlDocument doc, XmlElement newsXml, News news, int languageId) { string imageFolderPath = NewsHelper.MediaFolderPath(SiteId, news.NewsID); string thumbnailImageFolderPath = imageFolderPath + "thumbs/"; List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(news.NewsGuid); foreach (ContentMedia media in listMedia) { if (media.LanguageId == -1 || media.LanguageId == languageId) { XmlElement element = doc.CreateElement("NewsImages"); newsXml.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", media.Title); XmlHelper.AddNode(doc, element, "ImageUrl", Page.ResolveUrl(imageFolderPath + media.MediaFile)); XmlHelper.AddNode(doc, element, "ThumbnailUrl", Page.ResolveUrl(thumbnailImageFolderPath + media.ThumbnailFile)); } } }
private void BuildProductMediaXml( XmlDocument doc, XmlElement root) { string imageFolderPath = ProductHelper.MediaFolderPath(CacheHelper.GetCurrentSiteSettings().SiteId, product.ProductId); string thumbnailImageFolderPath = imageFolderPath + "thumbs/"; string siteRoot = WebUtils.GetSiteRoot(); Regex youtubeVideoRegex = new Regex("youtu(?:\\.be|be\\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)"); List <ContentMedia> listMedia = ContentMedia.GetByContentDesc(product.ProductGuid); List <int> mediaTypes = new List <int>(); List <CustomFieldOption> listOptions = new List <CustomFieldOption>(); foreach (ContentMedia media in listMedia) { if (media.MediaType > 0 && !mediaTypes.Contains(media.MediaType)) { mediaTypes.Add(media.MediaType); } } if (mediaTypes.Count > 0) { listOptions = CustomFieldOption.GetByOptionIds(product.SiteId, string.Join(";", mediaTypes.ToArray())); } if (listOptions.Count > 0) { foreach (CustomFieldOption option in listOptions) { XmlElement element = doc.CreateElement("ProductColors"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", option.Name); XmlHelper.AddNode(doc, element, "Color", option.OptionColor); XmlHelper.AddNode(doc, element, "ColorId", option.CustomFieldOptionId.ToString()); foreach (ContentMedia media in listMedia) { if ( (option.CustomFieldOptionId == media.MediaType) && (media.LanguageId == -1 || media.LanguageId == languageId) && (media.MediaType != (int)ProductMediaType.Video) ) { BuildProductImagesXml(doc, element, media, imageFolderPath, thumbnailImageFolderPath); } } } } foreach (ContentMedia media in listMedia) { if (media.LanguageId == -1 || media.LanguageId == languageId) { if (media.MediaType != (int)ProductMediaType.Video) { BuildProductImagesXml(doc, root, media, imageFolderPath, thumbnailImageFolderPath); if (media.MediaType != (int)ProductMediaType.Image) { string relativePath = siteRoot + ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile); basePage.AdditionalMetaMarkup += "\n<meta property=\"og:image\" content=\"" + relativePath + "\" />"; basePage.AdditionalMetaMarkup += "\n<meta itemprop=\"image\" content=\"" + relativePath + "\" />"; } } else { XmlElement element = doc.CreateElement("ProductVideos"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", media.Title); XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString()); XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString()); XmlHelper.AddNode(doc, element, "VideoUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile)); string thumbnailPath = ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile); if (media.ThumbnailFile.Length == 0 && media.MediaFile.ContainsCaseInsensitive("youtu")) { Match youtubeMatch = youtubeVideoRegex.Match(media.MediaFile); string videoId = string.Empty; if (youtubeMatch.Success) { videoId = youtubeMatch.Groups[1].Value; } thumbnailPath = "http://img.youtube.com/vi/" + videoId + "/0.jpg"; } XmlHelper.AddNode(doc, element, "ThumbnailUrl", thumbnailPath); } if (displaySettings.ShowVideo) { XmlElement element = doc.CreateElement("ProductMedia"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", media.Title); XmlHelper.AddNode(doc, element, "DisplayOrder", media.DisplayOrder.ToString()); XmlHelper.AddNode(doc, element, "Type", media.MediaType.ToString()); XmlHelper.AddNode(doc, element, "MediaUrl", ProductHelper.GetMediaFilePath(imageFolderPath, media.MediaFile)); XmlHelper.AddNode(doc, element, "ThumbnailUrl", ProductHelper.GetMediaFilePath(thumbnailImageFolderPath, media.ThumbnailFile)); } } } }