diff --git a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js
index bb51ca6c7a..bc8961da09 100644
--- a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js
+++ b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js
@@ -376,6 +376,19 @@ angular.module('umbraco.services')
return openDialog(options);
},
+ /**
+ * @ngdoc method
+ * @name umbraco.services.dialogService#ysodDialog
+ * @methodOf umbraco.services.dialogService
+ *
+ * @description
+ * Opens a dialog to an embed dialog
+ */
+ embedDialog: function (options) {
+ options.template = 'views/common/dialogs/embed.html';
+ options.show = true;
+ return openDialog(options);
+ },
/**
* @ngdoc method
* @name umbraco.services.dialogService#ysodDialog
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.controller.js
new file mode 100644
index 0000000000..38d147edcf
--- /dev/null
+++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.controller.js
@@ -0,0 +1,23 @@
+angular.module("umbraco").controller("Umbraco.Dialogs.EmbedController", function ($scope, $http) {
+ $scope.url = "";
+ $scope.width = 500;
+ $scope.height = 300;
+ $scope.constrain = true;
+ $scope.preview = "";
+
+ $scope.showPreview = function () {
+
+ $http({ method: 'POST', url: '/umbraco/UmbracoApi/Embed/Embed', params: { url: $scope.url, width: $scope.width, height: $scope.height } })
+ .success(function (data) {
+ $scope.preview = data.Markup;
+ })
+ .error(function () {
+
+ });
+
+ };
+
+ $scope.insert = function () {
+ $scope.submit($scope.preview);
+ };
+});
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.html
new file mode 100644
index 0000000000..c27c9e8f3e
--- /dev/null
+++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/embed.html
@@ -0,0 +1,35 @@
+
diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js
index b93e860a82..13c0d72f85 100644
--- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js
@@ -11,7 +11,7 @@ angular.module("umbraco")
menubar : false,
statusbar: false,
height: 340,
- toolbar: "bold italic | styleselect | alignleft aligncenter alignright | bullist numlist | outdent indent | link image mediapicker iconpicker",
+ toolbar: "bold italic | styleselect | alignleft aligncenter alignright | bullist numlist | outdent indent | link image mediapicker iconpicker embeddialog",
setup : function(editor) {
@@ -69,7 +69,20 @@ angular.module("umbraco")
editor.insertContent(i);
}});
}
- });
+ });
+
+
+ editor.addButton('embeddialog', {
+ icon: 'media',
+ tooltip: 'Embed',
+ onclick: function () {
+ dialogService.embedDialog({
+ scope: $scope, callback: function (data) {
+ editor.insertContent(data);
+ }
+ });
+ }
+ });
}
});
diff --git a/src/Umbraco.Web/Editors/EmbedController.cs b/src/Umbraco.Web/Editors/EmbedController.cs
new file mode 100644
index 0000000000..b84fdff99f
--- /dev/null
+++ b/src/Umbraco.Web/Editors/EmbedController.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Xml;
+using Umbraco.Core.Configuration;
+using Umbraco.Web.Mvc;
+using Umbraco.Web.WebApi.Filters;
+using Constants = Umbraco.Core.Constants;
+using Umbraco.Core.Media;
+using System.IO;
+
+namespace Umbraco.Web.Editors
+{
+ [PluginController("UmbracoApi")]
+ public class EmbedController : UmbracoAuthorizedJsonController
+ {
+ public Result Embed(string url, int width, int height)
+ {
+ var result = new Result();
+
+ //todo cache embed doc
+ var xmlConfig = new XmlDocument();
+ xmlConfig.Load(GlobalSettings.FullpathToRoot + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "EmbeddedMedia.config");
+
+ foreach (XmlNode node in xmlConfig.SelectNodes("//provider"))
+ {
+ var regexPattern = new Regex(node.SelectSingleNode("./urlShemeRegex").InnerText, RegexOptions.IgnoreCase);
+
+ if (regexPattern.IsMatch(url))
+ {
+ var prov = (IEmbedProvider)Activator.CreateInstance(Type.GetType(node.Attributes["type"].Value));
+
+ if (node.Attributes["supportsDimensions"] != null)
+ result.SupportsDimensions = node.Attributes["supportsDimensions"].Value == "True";
+ else
+ result.SupportsDimensions = prov.SupportsDimensions;
+
+ var settings = node.ChildNodes.Cast().ToDictionary(settingNode => settingNode.Name);
+
+ foreach (var prop in prov.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(ProviderSetting), true)))
+ {
+
+ if (settings.Any(s => s.Key.ToLower() == prop.Name.ToLower()))
+ {
+ var setting = settings.FirstOrDefault(s => s.Key.ToLower() == prop.Name.ToLower()).Value;
+ var settingType = typeof(Media.EmbedProviders.Settings.String);
+
+ if (setting.Attributes["type"] != null)
+ settingType = Type.GetType(setting.Attributes["type"].Value);
+
+ var settingProv = (IEmbedSettingProvider)Activator.CreateInstance(settingType);
+ prop.SetValue(prov, settingProv.GetSetting(settings.FirstOrDefault(s => s.Key.ToLower() == prop.Name.ToLower()).Value), null);
+ }
+ }
+ try
+ {
+ result.Markup = prov.GetMarkup(url, width, height);
+ result.Status = Status.Success;
+ }
+ catch
+ {
+ result.Status = Status.Error;
+ }
+
+ return result;
+ }
+ }
+
+ result.Status = Status.NotSupported;
+ return result;
+ }
+ }
+}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 565e298c46..f8acec4882 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -304,6 +304,7 @@
+