-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathFlickr.cs
More file actions
41 lines (32 loc) · 1.67 KB
/
Flickr.cs
File metadata and controls
41 lines (32 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Net;
using System.Xml;
using Umbraco.Cms.Core.Serialization;
namespace Umbraco.Cms.Core.Media.EmbedProviders;
/// <summary>
/// Embed Provider for Flickr the popular online image hosting and video hosting service.
/// </summary>
public class Flickr : OEmbedProviderBase
{
public Flickr(IJsonSerializer jsonSerializer)
: base(jsonSerializer)
{
}
public override string ApiEndpoint => "http://www.flickr.com/services/oembed/";
public override string[] UrlSchemeRegex => new[] { @"flickr.com\/photos\/*", @"flic.kr\/p\/*" };
public override Dictionary<string, string> RequestParams => new();
[Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")]
public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
{
return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult();
}
public override async Task<string?> GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken)
{
var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
XmlDocument xmlDocument = await base.GetXmlResponseAsync(requestUrl, cancellationToken);
var imageUrl = GetXmlProperty(xmlDocument, "/oembed/url");
var imageWidth = GetXmlProperty(xmlDocument, "/oembed/width");
var imageHeight = GetXmlProperty(xmlDocument, "/oembed/height");
var imageTitle = GetXmlProperty(xmlDocument, "/oembed/title");
return string.Format("<img src=\"{0}\" width=\"{1}\" height=\"{2}\" alt=\"{3}\" />", imageUrl, imageWidth, imageHeight, WebUtility.HtmlEncode(imageTitle));
}
}