This commit is contained in:
Sebastiaan Janssen
2013-05-27 10:08:36 -02:00
6 changed files with 122 additions and 44 deletions

View File

@@ -34,7 +34,7 @@ UmbracoSpeechBubble.prototype.ShowMessage = function (icon, header, message, don
if (!dontAutoHide) {
jQuery("#" + this.id).fadeIn("slow").animate({ opacity: 1.0 }, 5000).fadeOut("fast");
} else {
speechBubble.jQuery(".speechClose").show();
jQuery(".speechClose").show();
jQuery("#" + this.id).fadeIn("slow");
}
} else {

View File

@@ -29,9 +29,8 @@
//bind save shortcut
UmbClientMgr.appActions().bindSaveShortCut();
});
})(jQuery);
})(jQuery);
</script>
</asp:Content>

View File

@@ -7,7 +7,6 @@ var UmbracoEmbedDialog = {
tinyMCEPopup.close();
},
showPreview: function () {
$('#insert').attr('disabled', 'disabled');
var url = $('#url').val();
@@ -16,44 +15,39 @@ var UmbracoEmbedDialog = {
$('#preview').html('<img src="img/ajax-loader.gif" alt="loading"/>');
$('#source').val('');
$.ajax(
{
type: 'POST',
async: true,
url: '../../../../umbraco/webservices/api/mediaservice.asmx/Embed',
data: '{ url: "' + url + '", width: "' + width + '", height: "' + height + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
var resultAsJson = msg.d;
switch (resultAsJson.Status) {
case 0:
//not supported
$('#preview').html('Not Supported');
break;
case 1:
//error
$('#preview').html('Error');
break;
case 2:
$('#preview').html(resultAsJson.Markup);
$('#source').val(resultAsJson.Markup);
if (resultAsJson.SupportsDimensions) {
$('#dimensions').show();
} else {
$('#dimensions').hide();
}
$('#insert').removeAttr('disabled');
break;
$.ajax({
type: 'POST',
async: true,
url: '../../../../base/EmbedMediaService/Embed/',
data: { url: url, width: width, height: height },
dataType: 'json',
success: function (result) {
switch (result.Status) {
case 0:
//not supported
$('#preview').html('Not Supported');
break;
case 1:
//error
$('#preview').html('Error');
break;
case 2:
$('#preview').html(result.Markup);
$('#source').val(result.Markup);
if (result.SupportsDimensions) {
$('#dimensions').show();
} else {
$('#dimensions').hide();
}
},
error: function (xhr, ajaxOptions, thrownError) {
$('#preview').html("Error");
//alert(xhr.status);
//alert(thrownError);
}
});
$('#insert').removeAttr('disabled');
break;
}
},
error: function (xhr, ajaxOptions, thrownError) {
$('#preview').html("Error");
}
});
},
beforeResize: function () {
this.width = parseInt($('#width').val(), 10);
@@ -73,11 +67,9 @@ var UmbracoEmbedDialog = {
$('#width').val(this.width);
}
}
if ($('#url').val() != '') {
UmbracoEmbedDialog.showPreview();
}
},
changeSource: function (type) {
if ($('#source').val() != '') {

View File

@@ -1768,6 +1768,7 @@
<Compile Include="WebServices\BulkPublishController.cs" />
<Compile Include="WebServices\CoreStringsController.cs" />
<Compile Include="WebServices\DomainsApiController.cs" />
<Compile Include="WebServices\EmbedMediaService.cs" />
<Compile Include="WebServices\ExamineManagementApiController.cs" />
<Compile Include="WebServices\FolderBrowserService.cs" />
<Compile Include="WebServices\UmbracoAuthorizedHttpHandler.cs" />

View File

@@ -0,0 +1,84 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Script.Serialization;
using System.Xml;
using Umbraco.Core.Configuration;
using Umbraco.Core.Media;
using umbraco.BusinessLogic;
using Umbraco.Web.BaseRest;
namespace Umbraco.Web.WebServices
{
[RestExtension("EmbedMediaService")]
public class EmbedMediaService
{
[RestExtensionMethod(ReturnXml = false)]
public static string Embed()
{
var currentUser = User.GetCurrent();
if (currentUser == null)
throw new UnauthorizedAccessException("You must be logged in to use this service");
var url = HttpContext.Current.Request.Form["url"];
var width = int.Parse(HttpContext.Current.Request.Form["width"]);
var height = int.Parse(HttpContext.Current.Request.Form["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<XmlNode>().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 new JavaScriptSerializer().Serialize(result);
}
}
result.Status = Status.NotSupported;
return new JavaScriptSerializer().Serialize(result);
}
}
}

View File

@@ -166,6 +166,8 @@ namespace umbraco.presentation.webservices
[ScriptMethod]
public string ProgressStatus(string Key)
{
AuthorizeRequest(true);
return Application[helper.Request("key")].ToString();
}