mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fixing Live Writer draft support
work item: 16607 --HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
namespace Orchard.Core.XmlRpc {
|
namespace Orchard.Core.XmlRpc {
|
||||||
public interface IXmlRpcDriver {
|
public interface IXmlRpcDriver {
|
||||||
void Process(int id);
|
void Process(object item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@@ -90,7 +89,8 @@ namespace Orchard.Blogs.Services {
|
|||||||
urlHelper,
|
urlHelper,
|
||||||
Convert.ToInt32(context.Request.Params[0].Value),
|
Convert.ToInt32(context.Request.Params[0].Value),
|
||||||
Convert.ToString(context.Request.Params[1].Value),
|
Convert.ToString(context.Request.Params[1].Value),
|
||||||
Convert.ToString(context.Request.Params[2].Value));
|
Convert.ToString(context.Request.Params[2].Value),
|
||||||
|
context._drivers);
|
||||||
context.Response = new XRpcMethodResponse().Add(result);
|
context.Response = new XRpcMethodResponse().Add(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
|
|
||||||
var array = new XRpcArray();
|
var array = new XRpcArray();
|
||||||
foreach (var blogPost in _blogPostService.Get(blog).Take(numberOfPosts)) {
|
foreach (var blogPost in _blogPostService.Get(blog, 0, numberOfPosts, VersionOptions.Latest)) {
|
||||||
array.Add(CreateBlogStruct(blogPost, urlHelper));
|
array.Add(CreateBlogStruct(blogPost, urlHelper));
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
@@ -177,7 +177,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
var slug = content.Optional<string>("wp_slug");
|
var slug = content.Optional<string>("wp_slug");
|
||||||
|
|
||||||
var blogPost = _contentManager.New<BlogPostPart>("BlogPost");
|
var blogPost = _contentManager.New<BlogPostPart>("BlogPost");
|
||||||
|
|
||||||
// BodyPart
|
// BodyPart
|
||||||
if (blogPost.Is<BodyPart>()) {
|
if (blogPost.Is<BodyPart>()) {
|
||||||
blogPost.As<BodyPart>().Text = description;
|
blogPost.As<BodyPart>().Text = description;
|
||||||
@@ -212,19 +212,25 @@ namespace Orchard.Blogs.Services {
|
|||||||
UrlHelper urlHelper,
|
UrlHelper urlHelper,
|
||||||
int postId,
|
int postId,
|
||||||
string userName,
|
string userName,
|
||||||
string password) {
|
string password,
|
||||||
|
IEnumerable<IXmlRpcDriver> drivers) {
|
||||||
|
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
||||||
|
|
||||||
var blogPost = _blogPostService.Get(postId);
|
var blogPost = _blogPostService.Get(postId, VersionOptions.Latest);
|
||||||
if (blogPost == null)
|
if (blogPost == null)
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
|
|
||||||
return CreateBlogStruct(blogPost, urlHelper);
|
var postStruct = CreateBlogStruct(blogPost, urlHelper);
|
||||||
|
|
||||||
|
foreach (var driver in drivers)
|
||||||
|
driver.Process(postStruct);
|
||||||
|
|
||||||
|
return postStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MetaWeblogEditPost(int postId, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers) {
|
private bool MetaWeblogEditPost(int postId, string userName, string password, XRpcStruct content, bool publish, IEnumerable<IXmlRpcDriver> drivers) {
|
||||||
|
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
||||||
@@ -251,7 +257,7 @@ namespace Orchard.Blogs.Services {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MetaWeblogDeletePost(string appkey, string postId, string userName, string password, bool publish, ICollection<IXmlRpcDriver> drivers) {
|
private bool MetaWeblogDeletePost(string appkey, string postId, string userName, string password, bool publish, IEnumerable<IXmlRpcDriver> drivers) {
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Orchard.Core.XmlRpc;
|
|||||||
using Orchard.Core.XmlRpc.Models;
|
using Orchard.Core.XmlRpc.Models;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Tags.Helpers;
|
using Orchard.Tags.Helpers;
|
||||||
|
using Orchard.Tags.Models;
|
||||||
|
|
||||||
namespace Orchard.Tags.Services {
|
namespace Orchard.Tags.Services {
|
||||||
public class XmlRpcHandler : IXmlRpcHandler {
|
public class XmlRpcHandler : IXmlRpcHandler {
|
||||||
@@ -15,7 +16,6 @@ namespace Orchard.Tags.Services {
|
|||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly ITagService _tagService;
|
private readonly ITagService _tagService;
|
||||||
private readonly IOrchardServices _orchardServices;
|
private readonly IOrchardServices _orchardServices;
|
||||||
private IEnumerable<string> _tags;
|
|
||||||
|
|
||||||
public XmlRpcHandler(
|
public XmlRpcHandler(
|
||||||
IMembershipService membershipService,
|
IMembershipService membershipService,
|
||||||
@@ -39,6 +39,10 @@ namespace Orchard.Tags.Services {
|
|||||||
|
|
||||||
public void Process(XmlRpcContext context) {
|
public void Process(XmlRpcContext context) {
|
||||||
switch (context.Request.MethodName) {
|
switch (context.Request.MethodName) {
|
||||||
|
case "metaWeblog.getCategories": // hack... because live writer still asks for it...
|
||||||
|
if (context.Response == null)
|
||||||
|
context.Response = new XRpcMethodResponse();
|
||||||
|
break;
|
||||||
case "wp.getTags":
|
case "wp.getTags":
|
||||||
var tags = MetaWeblogGetTags(
|
var tags = MetaWeblogGetTags(
|
||||||
Convert.ToString(context.Request.Params[0].Value),
|
Convert.ToString(context.Request.Params[0].Value),
|
||||||
@@ -46,6 +50,14 @@ namespace Orchard.Tags.Services {
|
|||||||
Convert.ToString(context.Request.Params[2].Value));
|
Convert.ToString(context.Request.Params[2].Value));
|
||||||
context.Response = new XRpcMethodResponse().Add(tags);
|
context.Response = new XRpcMethodResponse().Add(tags);
|
||||||
break;
|
break;
|
||||||
|
case "metaWeblog.getPost":
|
||||||
|
MetaWeblogAttachTagsToPost(
|
||||||
|
GetPost(context.Response),
|
||||||
|
Convert.ToInt32(context.Request.Params[0].Value),
|
||||||
|
Convert.ToString(context.Request.Params[1].Value),
|
||||||
|
Convert.ToString(context.Request.Params[2].Value),
|
||||||
|
context._drivers);
|
||||||
|
break;
|
||||||
case "metaWeblog.newPost":
|
case "metaWeblog.newPost":
|
||||||
MetaWeblogUpdateTags(
|
MetaWeblogUpdateTags(
|
||||||
GetId(context.Response),
|
GetId(context.Response),
|
||||||
@@ -69,6 +81,38 @@ namespace Orchard.Tags.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MetaWeblogAttachTagsToPost(XRpcStruct postStruct, int postId, string userName, string password, ICollection<IXmlRpcDriver> drivers) {
|
||||||
|
if (postId < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
|
_authorizationService.CheckAccess(StandardPermissions.AccessAdminPanel, user, null);
|
||||||
|
|
||||||
|
var driver = new XmlRpcDriver(item => {
|
||||||
|
var post = item as XRpcStruct;
|
||||||
|
if (post == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var contentItem = _contentManager.Get(postId, VersionOptions.Latest);
|
||||||
|
if (contentItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var tags = contentItem.As<TagsPart>().CurrentTags.Select(tag => tag.TagName);
|
||||||
|
post.Set("mt_keywords", string.Join(", ", tags));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (postStruct != null)
|
||||||
|
driver.Process(postStruct);
|
||||||
|
else
|
||||||
|
drivers.Add(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static XRpcStruct GetPost(XRpcMethodResponse response) {
|
||||||
|
return response != null && response.Params.Count == 1 && response.Params[0].Value is XRpcStruct
|
||||||
|
? response.Params[0].Value as XRpcStruct
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
private static int GetId(XRpcMethodResponse response) {
|
private static int GetId(XRpcMethodResponse response) {
|
||||||
return response != null && response.Params.Count == 1 && response.Params[0].Value is int
|
return response != null && response.Params.Count == 1 && response.Params[0].Value is int
|
||||||
? Convert.ToInt32(response.Params[0].Value)
|
? Convert.ToInt32(response.Params[0].Value)
|
||||||
@@ -77,7 +121,7 @@ namespace Orchard.Tags.Services {
|
|||||||
|
|
||||||
private XRpcArray MetaWeblogGetTags(string appKey, string userName, string password) {
|
private XRpcArray MetaWeblogGetTags(string appKey, string userName, string password) {
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
_authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);
|
_authorizationService.CheckAccess(StandardPermissions.AccessAdminPanel, user, null);
|
||||||
|
|
||||||
var array = new XRpcArray();
|
var array = new XRpcArray();
|
||||||
foreach (var tag in _tagService.GetTags()) {
|
foreach (var tag in _tagService.GetTags()) {
|
||||||
@@ -103,16 +147,20 @@ namespace Orchard.Tags.Services {
|
|||||||
if (string.IsNullOrWhiteSpace(rawTags))
|
if (string.IsNullOrWhiteSpace(rawTags))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var driver = new XmlRpcDriver(id => {
|
var tags = TagHelpers.ParseCommaSeparatedTagNames(rawTags);
|
||||||
var contentItem = _contentManager.Get(id);
|
var driver = new XmlRpcDriver(item => {
|
||||||
|
if (!(item is int))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var id = (int)item;
|
||||||
|
var contentItem = _contentManager.Get(id, VersionOptions.Latest);
|
||||||
if (contentItem == null)
|
if (contentItem == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_orchardServices.WorkContext.CurrentUser = user;
|
_orchardServices.WorkContext.CurrentUser = user;
|
||||||
_tagService.UpdateTagsForContentItem(id, _tags);
|
_tagService.UpdateTagsForContentItem(id, tags);
|
||||||
});
|
});
|
||||||
|
|
||||||
_tags = TagHelpers.ParseCommaSeparatedTagNames(rawTags);
|
|
||||||
if (contentItemId > 0)
|
if (contentItemId > 0)
|
||||||
driver.Process(contentItemId);
|
driver.Process(contentItemId);
|
||||||
else
|
else
|
||||||
@@ -120,14 +168,14 @@ namespace Orchard.Tags.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class XmlRpcDriver : IXmlRpcDriver {
|
public class XmlRpcDriver : IXmlRpcDriver {
|
||||||
private readonly Action<int> _process;
|
private readonly Action<object> _process;
|
||||||
|
|
||||||
public XmlRpcDriver(Action<int> process) {
|
public XmlRpcDriver(Action<object > process) {
|
||||||
_process = process;
|
_process = process;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(int id) {
|
public void Process(object item) {
|
||||||
_process(id);
|
_process(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user