diff --git a/src/Orchard.Web/Core/XmlRpc/IXmlRpcDriver.cs b/src/Orchard.Web/Core/XmlRpc/IXmlRpcDriver.cs index 949fa104b..223969dd1 100644 --- a/src/Orchard.Web/Core/XmlRpc/IXmlRpcDriver.cs +++ b/src/Orchard.Web/Core/XmlRpc/IXmlRpcDriver.cs @@ -1,5 +1,5 @@ namespace Orchard.Core.XmlRpc { public interface IXmlRpcDriver { - void Process(int id); + void Process(object item); } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs index 756af11dd..f9972c7b9 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Web.Mvc; using System.Web.Routing; using System.Xml.Linq; @@ -90,7 +89,8 @@ namespace Orchard.Blogs.Services { urlHelper, Convert.ToInt32(context.Request.Params[0].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); } @@ -151,7 +151,7 @@ namespace Orchard.Blogs.Services { throw new ArgumentException(); 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)); } return array; @@ -177,7 +177,7 @@ namespace Orchard.Blogs.Services { var slug = content.Optional("wp_slug"); var blogPost = _contentManager.New("BlogPost"); - + // BodyPart if (blogPost.Is()) { blogPost.As().Text = description; @@ -212,19 +212,25 @@ namespace Orchard.Blogs.Services { UrlHelper urlHelper, int postId, string userName, - string password) { + string password, + IEnumerable drivers) { var user = _membershipService.ValidateUser(userName, password); _authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null); - var blogPost = _blogPostService.Get(postId); + var blogPost = _blogPostService.Get(postId, VersionOptions.Latest); if (blogPost == null) 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 drivers) { + private bool MetaWeblogEditPost(int postId, string userName, string password, XRpcStruct content, bool publish, IEnumerable drivers) { var user = _membershipService.ValidateUser(userName, password); _authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null); @@ -251,7 +257,7 @@ namespace Orchard.Blogs.Services { return true; } - private bool MetaWeblogDeletePost(string appkey, string postId, string userName, string password, bool publish, ICollection drivers) { + private bool MetaWeblogDeletePost(string appkey, string postId, string userName, string password, bool publish, IEnumerable drivers) { var user = _membershipService.ValidateUser(userName, password); _authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null); diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Tags/Services/XmlRpcHandler.cs index b44d6b3f8..c6262a6b2 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Services/XmlRpcHandler.cs @@ -7,6 +7,7 @@ using Orchard.Core.XmlRpc; using Orchard.Core.XmlRpc.Models; using Orchard.Security; using Orchard.Tags.Helpers; +using Orchard.Tags.Models; namespace Orchard.Tags.Services { public class XmlRpcHandler : IXmlRpcHandler { @@ -15,7 +16,6 @@ namespace Orchard.Tags.Services { private readonly IContentManager _contentManager; private readonly ITagService _tagService; private readonly IOrchardServices _orchardServices; - private IEnumerable _tags; public XmlRpcHandler( IMembershipService membershipService, @@ -39,6 +39,10 @@ namespace Orchard.Tags.Services { public void Process(XmlRpcContext context) { 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": var tags = MetaWeblogGetTags( Convert.ToString(context.Request.Params[0].Value), @@ -46,6 +50,14 @@ namespace Orchard.Tags.Services { Convert.ToString(context.Request.Params[2].Value)); context.Response = new XRpcMethodResponse().Add(tags); 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": MetaWeblogUpdateTags( GetId(context.Response), @@ -69,6 +81,38 @@ namespace Orchard.Tags.Services { } } + private void MetaWeblogAttachTagsToPost(XRpcStruct postStruct, int postId, string userName, string password, ICollection 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().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) { return response != null && response.Params.Count == 1 && response.Params[0].Value is int ? Convert.ToInt32(response.Params[0].Value) @@ -77,7 +121,7 @@ namespace Orchard.Tags.Services { private XRpcArray MetaWeblogGetTags(string appKey, string userName, string password) { var user = _membershipService.ValidateUser(userName, password); - _authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null); + _authorizationService.CheckAccess(StandardPermissions.AccessAdminPanel, user, null); var array = new XRpcArray(); foreach (var tag in _tagService.GetTags()) { @@ -103,16 +147,20 @@ namespace Orchard.Tags.Services { if (string.IsNullOrWhiteSpace(rawTags)) return; - var driver = new XmlRpcDriver(id => { - var contentItem = _contentManager.Get(id); + var tags = TagHelpers.ParseCommaSeparatedTagNames(rawTags); + var driver = new XmlRpcDriver(item => { + if (!(item is int)) + return; + + var id = (int)item; + var contentItem = _contentManager.Get(id, VersionOptions.Latest); if (contentItem == null) return; _orchardServices.WorkContext.CurrentUser = user; - _tagService.UpdateTagsForContentItem(id, _tags); + _tagService.UpdateTagsForContentItem(id, tags); }); - _tags = TagHelpers.ParseCommaSeparatedTagNames(rawTags); if (contentItemId > 0) driver.Process(contentItemId); else @@ -120,14 +168,14 @@ namespace Orchard.Tags.Services { } public class XmlRpcDriver : IXmlRpcDriver { - private readonly Action _process; + private readonly Action _process; - public XmlRpcDriver(Action process) { + public XmlRpcDriver(Action process) { _process = process; } - public void Process(int id) { - _process(id); + public void Process(object item) { + _process(item); } } }