Merge branch 'dev-v7-oembed' of https://github.com/tcmorris/Umbraco-CMS into tcmorris-dev-v7-oembed

Conflicts:
	src/Umbraco.Web/Umbraco.Web.csproj
This commit is contained in:
Shannon
2015-06-25 16:57:52 +02:00
parent 7b28e64c9e
commit 5487ec1d5f
9 changed files with 189 additions and 48 deletions

View File

@@ -1,17 +1,11 @@
<?xml version="1.0"?>
<embed>
<!-- Flickr Settings-->
<provider name="Flickr" type="Umbraco.Web.Media.EmbedProviders.Flickr, umbraco">
<provider name="Flickr" type="Umbraco.Web.Media.EmbedProviders.OEmbedPhoto, umbraco">
<urlShemeRegex><![CDATA[flickr\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.flickr.com/services/oembed/]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Screenr Settings -->
<provider name="Screenr" type="Umbraco.Web.Media.EmbedProviders.OEmbedVideo, umbraco" supportsDimensions="False">
<urlShemeRegex><![CDATA[screenr\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.screenr.com/api/oembed.xml]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- SlideShare Settings -->
<provider name="SlideShare" type="Umbraco.Web.Media.EmbedProviders.OEmbedRich, umbraco">
<urlShemeRegex><![CDATA[slideshare\.net/]]></urlShemeRegex>
@@ -20,16 +14,54 @@
<param name="format">xml</param>
</requestParams>
</provider>
<!-- Kickstarter Settings-->
<provider name="Kickstarter" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[kickstarter\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.kickstarter.com/services/oembed]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Getty Images Settings-->
<provider name="GettyImages" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[gty\.im/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://embed.gettyimages.com/oembed]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Poll Everywhere Settigs -->
<provider name="PollEverywhere" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[polleverywhere\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.polleverywhere.com/services/oembed/]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Poll Daddy Settigs -->
<provider name="PollDaddy" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[polldaddy\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://polldaddy.com/oembed/]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- IFTTT Settigs -->
<provider name="IFTTT" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[ifttt\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.ifttt.com/oembed/]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Instagram Settigs -->
<provider name="Instagram" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[instagram\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://api.instagram.com/oembed]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Rdio Settigs -->
<provider name="Rdio" type="Umbraco.Web.Media.EmbedProviders.OEmbedJson, umbraco">
<urlShemeRegex><![CDATA[rdio\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.rdio.com/api/oembed/]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- SoundCloud Settigs -->
<provider name="SoundCloud" type="Umbraco.Web.Media.EmbedProviders.OEmbedRich, umbraco">
<urlShemeRegex><![CDATA[soundcloud\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://soundcloud.com/oembed]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Twitgoo Settings , not an OEmbed one -->
<provider name="Twitgoo" type="Umbraco.Web.Media.EmbedProviders.Twitgoo, umbraco">
<urlShemeRegex><![CDATA[twitgoo\.com/]]></urlShemeRegex>
</provider>
</provider>
<!-- Youtube Settings -->
<provider name="Youtube" type="Umbraco.Web.Media.EmbedProviders.OEmbedVideo, umbraco">
<urlShemeRegex><![CDATA[youtu(?:\.be|be\.com)/(?:(.*)v(/|=)|(.*/)?)([a-zA-Z0-9-_]+)]]></urlShemeRegex>
@@ -68,4 +100,20 @@
<apiEndpoint><![CDATA[http://vimeo.com/api/oembed.xml]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Ted -->
<provider name="Ted" type="Umbraco.Web.Media.EmbedProviders.OEmbedVideo, umbraco">
<urlShemeRegex><![CDATA[ted\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.ted.com/talks/oembed.xml]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Screenr Settings -->
<provider name="Screenr" type="Umbraco.Web.Media.EmbedProviders.OEmbedVideo, umbraco" supportsDimensions="False">
<urlShemeRegex><![CDATA[screenr\.com/]]></urlShemeRegex>
<apiEndpoint><![CDATA[http://www.screenr.com/api/oembed.xml]]></apiEndpoint>
<requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco"></requestParams>
</provider>
<!-- Twitgoo Settings , not an OEmbed one -->
<provider name="Twitgoo" type="Umbraco.Web.Media.EmbedProviders.Twitgoo, umbraco">
<urlShemeRegex><![CDATA[twitgoo\.com/]]></urlShemeRegex>
</provider>
</embed>

View File

@@ -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<T>(string url) where T : class
{
var response = DownloadResponse(url);
return JsonConvert.DeserializeObject<T>(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;
}
}
}

View File

@@ -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("<img src=\"{0}\" width\"{1}\" height=\"{2}\" alt=\"{3}\" />",
imageUrl, imageWidth, imageHeight, HttpUtility.HtmlEncode(imageTitle));
}
}
}

View File

@@ -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<OEmbedResponse>(requestUrl);
return jsonResponse.GetHtml();
}
}
}

View File

@@ -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("<img src=\"{0}\" width\"{1}\" height=\"{2}\" alt=\"{3}\" />",
imageUrl, imageWidth, imageHeight, HttpUtility.HtmlEncode(imageTitle));
}
}
}

View File

@@ -0,0 +1,61 @@
using System.Text;
using System.Web;
using Newtonsoft.Json;
namespace Umbraco.Web.Media.EmbedProviders
{
/// <summary>
/// Wrapper class for OEmbed response
/// </summary>
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; }
/// <summary>
/// Gets the HTML.
/// </summary>
/// <returns>The response html</returns>
public string GetHtml()
{
if (Type == "photo")
{
return "<img src=\"" + Url + "\" width=\"" + Width + "\" height=\"" + Height + "\" alt=\"" + HttpUtility.HtmlEncode(Title) + "\" />";
}
return string.IsNullOrEmpty(Html) == false ? Html : string.Empty;
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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)

View File

@@ -304,6 +304,9 @@
<Compile Include="HtmlHelperBackOfficeExtensions.cs" />
<Compile Include="PropertyEditors\DatePreValueEditor.cs" />
<Compile Include="Security\Identity\GetUserSecondsMiddleWare.cs" />
<Compile Include="Media\EmbedProviders\OEmbedJson.cs" />
<Compile Include="Media\EmbedProviders\OEmbedResponse.cs" />
<Compile Include="Media\EmbedProviders\OEmbedPhoto.cs" />
<Compile Include="UmbracoDefaultOwinStartup.cs" />
<Compile Include="IUmbracoContextAccessor.cs" />
<Compile Include="Models\ContentEditing\Relation.cs" />
@@ -910,7 +913,6 @@
<Compile Include="Scheduling\Scheduler.cs" />
<Compile Include="Media\EmbedProviders\AbstractOEmbedProvider.cs" />
<Compile Include="Media\EmbedProviders\AbstractProvider.cs" />
<Compile Include="Media\EmbedProviders\Flickr.cs" />
<Compile Include="Media\EmbedProviders\OEmbedRich.cs" />
<Compile Include="Media\EmbedProviders\OEmbedVideo.cs" />
<Compile Include="Media\EmbedProviders\Settings\Dictionary.cs" />