diff --git a/src/Umbraco.Web.UI/config/EmbeddedMedia.config b/src/Umbraco.Web.UI/config/EmbeddedMedia.config
index 86f00b1ef4..cf9fb4f22d 100644
--- a/src/Umbraco.Web.UI/config/EmbeddedMedia.config
+++ b/src/Umbraco.Web.UI/config/EmbeddedMedia.config
@@ -1,17 +1,11 @@
diff --git a/src/Umbraco.Web/Media/EmbedProviders/AbstractOEmbedProvider.cs b/src/Umbraco.Web/Media/EmbedProviders/AbstractOEmbedProvider.cs
index 22b912e8b1..2bf01d40b2 100644
--- a/src/Umbraco.Web/Media/EmbedProviders/AbstractOEmbedProvider.cs
+++ b/src/Umbraco.Web/Media/EmbedProviders/AbstractOEmbedProvider.cs
@@ -1,6 +1,9 @@
using System.Text;
using System.Xml;
using System.Collections.Generic;
+using System.Net;
+using System.Net.Http;
+using Newtonsoft.Json;
using Umbraco.Core.Media;
namespace Umbraco.Web.Media.EmbedProviders
@@ -39,16 +42,34 @@ namespace Umbraco.Web.Media.EmbedProviders
return fullUrl.ToString();
}
+ public virtual string DownloadResponse(string url)
+ {
+ using (var webClient = new WebClient())
+ {
+ return webClient.DownloadString(url);
+ }
+ }
+
+ public virtual T GetJsonResponse(string url) where T : class
+ {
+ var response = DownloadResponse(url);
+ return JsonConvert.DeserializeObject(response);
+ }
+
public virtual XmlDocument GetXmlResponse(string url)
{
- var webClient = new System.Net.WebClient();
-
- var response = webClient.DownloadString(url);
-
+ var response = DownloadResponse(url);
var doc = new XmlDocument();
doc.LoadXml(response);
return doc;
}
+
+ public virtual string GetXmlProperty(XmlDocument doc, string property)
+ {
+ var selectSingleNode = doc.SelectSingleNode(property);
+ return selectSingleNode != null ? selectSingleNode.InnerText : string.Empty;
+ }
+
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Media/EmbedProviders/Flickr.cs b/src/Umbraco.Web/Media/EmbedProviders/Flickr.cs
deleted file mode 100644
index 3e9cae2675..0000000000
--- a/src/Umbraco.Web/Media/EmbedProviders/Flickr.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Web;
-
-namespace Umbraco.Web.Media.EmbedProviders
-{
- public class Flickr : AbstractOEmbedProvider
- {
- public override string GetMarkup(string url, int maxWidth, int maxHeight)
- {
- var flickrUrl = BuildFullUrl(url, maxWidth, maxHeight);
- var doc = GetXmlResponse(flickrUrl);
-
- string imageUrl = doc.SelectSingleNode("/oembed/url").InnerText;
- string imageWidth = doc.SelectSingleNode("/oembed/width").InnerText;
- string imageHeight = doc.SelectSingleNode("/oembed/height").InnerText;
- string imageTitle = doc.SelectSingleNode("/oembed/title").InnerText;
-
- return string.Format("
",
- imageUrl, imageWidth, imageHeight, HttpUtility.HtmlEncode(imageTitle));
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Media/EmbedProviders/OEmbedJson.cs b/src/Umbraco.Web/Media/EmbedProviders/OEmbedJson.cs
new file mode 100644
index 0000000000..161294be76
--- /dev/null
+++ b/src/Umbraco.Web/Media/EmbedProviders/OEmbedJson.cs
@@ -0,0 +1,13 @@
+namespace Umbraco.Web.Media.EmbedProviders
+{
+ public class OEmbedJson : AbstractOEmbedProvider
+ {
+ public override string GetMarkup(string url, int maxWidth, int maxHeight)
+ {
+ string requestUrl = BuildFullUrl(url, maxWidth, maxHeight);
+
+ var jsonResponse = GetJsonResponse(requestUrl);
+ return jsonResponse.GetHtml();
+ }
+ }
+}
diff --git a/src/Umbraco.Web/Media/EmbedProviders/OEmbedPhoto.cs b/src/Umbraco.Web/Media/EmbedProviders/OEmbedPhoto.cs
new file mode 100644
index 0000000000..acc75cb876
--- /dev/null
+++ b/src/Umbraco.Web/Media/EmbedProviders/OEmbedPhoto.cs
@@ -0,0 +1,22 @@
+using System.Web;
+using System.Xml;
+
+namespace Umbraco.Web.Media.EmbedProviders
+{
+ public class OEmbedPhoto : AbstractOEmbedProvider
+ {
+ public override string GetMarkup(string url, int maxWidth, int maxHeight)
+ {
+ string requestUrl = BuildFullUrl(url, maxWidth, maxHeight);
+
+ XmlDocument doc = GetXmlResponse(requestUrl);
+ string imageUrl = GetXmlProperty(doc, "/oembed/url");
+ string imageWidth = GetXmlProperty(doc, "/oembed/width");
+ string imageHeight = GetXmlProperty(doc, "/oembed/height");
+ string imageTitle = GetXmlProperty(doc, "/oembed/title");
+
+ return string.Format("
",
+ imageUrl, imageWidth, imageHeight, HttpUtility.HtmlEncode(imageTitle));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Media/EmbedProviders/OEmbedResponse.cs b/src/Umbraco.Web/Media/EmbedProviders/OEmbedResponse.cs
new file mode 100644
index 0000000000..84164bc47f
--- /dev/null
+++ b/src/Umbraco.Web/Media/EmbedProviders/OEmbedResponse.cs
@@ -0,0 +1,61 @@
+using System.Text;
+using System.Web;
+using Newtonsoft.Json;
+
+namespace Umbraco.Web.Media.EmbedProviders
+{
+ ///
+ /// Wrapper class for OEmbed response
+ ///
+ public class OEmbedResponse
+ {
+ public string Type { get; set; }
+
+ public string Version { get; set; }
+
+ public string Title { get; set; }
+
+ [JsonProperty("author_name")]
+ public string AuthorName { get; set; }
+
+ [JsonProperty("author_url")]
+ public string AuthorUrl { get; set; }
+
+ [JsonProperty("provider_name")]
+ public string ProviderName { get; set; }
+
+ [JsonProperty("provider_url")]
+ public string ProviderUrl { get; set; }
+
+ [JsonProperty("thumbnail_url")]
+ public string ThumbnailUrl { get; set; }
+
+ [JsonProperty("thumbnail_height")]
+ public int? ThumbnailHeight { get; set; }
+
+ [JsonProperty("thumbnail_width")]
+ public int? ThumbnailWidth { get; set; }
+
+ public string Html { get; set; }
+
+ public string Url { get; set; }
+
+ public int? Height { get; set; }
+
+ public int? Width { get; set; }
+
+ ///
+ /// Gets the HTML.
+ ///
+ /// The response html
+ public string GetHtml()
+ {
+ if (Type == "photo")
+ {
+ return "
";
+ }
+
+ return string.IsNullOrEmpty(Html) == false ? Html : string.Empty;
+ }
+ }
+}
diff --git a/src/Umbraco.Web/Media/EmbedProviders/OEmbedVideo.cs b/src/Umbraco.Web/Media/EmbedProviders/OEmbedVideo.cs
index c0e1e3f986..be155b521a 100644
--- a/src/Umbraco.Web/Media/EmbedProviders/OEmbedVideo.cs
+++ b/src/Umbraco.Web/Media/EmbedProviders/OEmbedVideo.cs
@@ -6,12 +6,10 @@ namespace Umbraco.Web.Media.EmbedProviders
{
public override string GetMarkup(string url, int maxWidth, int maxHeight)
{
- string videoUrl = BuildFullUrl(url, maxWidth, maxHeight) ;
-
- XmlDocument doc = GetXmlResponse(videoUrl);
-
- // add xslt transformation to return markup
- return doc.SelectSingleNode("/oembed/html").InnerText;
+ string requestUrl = BuildFullUrl(url, maxWidth, maxHeight);
+
+ XmlDocument doc = GetXmlResponse(requestUrl);
+ return GetXmlProperty(doc, "/oembed/Html");
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Media/EmbedProviders/Twitgoo.cs b/src/Umbraco.Web/Media/EmbedProviders/Twitgoo.cs
index 624c0634d8..a28dd97809 100644
--- a/src/Umbraco.Web/Media/EmbedProviders/Twitgoo.cs
+++ b/src/Umbraco.Web/Media/EmbedProviders/Twitgoo.cs
@@ -6,10 +6,7 @@ namespace Umbraco.Web.Media.EmbedProviders
{
public override bool SupportsDimensions
{
- get
- {
- return false;
- }
+ get { return false; }
}
public override string GetMarkup(string url, int maxWidth, int maxHeight)
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 110c8d017e..17322a218f 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -304,6 +304,9 @@
+
+
+
@@ -910,7 +913,6 @@
-