Exemple #1
0
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file,
            UrlHelper url) {

            var user = _membershipService.ValidateUser(userName, password);
            if (!_authorizationService.TryCheckAccess(Permissions.ManageMediaContent, user, null)) {
                throw new OrchardCoreException(T("Access denied"));
            }

            var name = file.Optional<string>("name");
            var bits = file.Optional<byte[]>("bits");

            string directoryName = Path.GetDirectoryName(name);
            if (string.IsNullOrWhiteSpace(directoryName)) { // Some clients only pass in a name path that does not contain a directory component.
                directoryName = "media";
            }

            try {
                // delete the file if it already exists, e.g. an updated image in a blog post
                // it's safe to delete the file as each content item gets a specific folder
                _mediaLibraryService.DeleteFile(directoryName, Path.GetFileName(name));
            }
            catch {
                // current way to delete a file if it exists
            }

            string publicUrl = _mediaLibraryService.UploadMediaFile(directoryName, Path.GetFileName(name), bits);
            _mediaLibraryService.ImportMedia(directoryName, Path.GetFileName(name));
            return new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                .Set("file", publicUrl)
                .Set("url", url.MakeAbsolute(publicUrl))
                .Set("type", file.Optional<string>("type"));
        }
        private XRpcStruct MetaWeblogNewMediaObject(
            UriBuilder uriBuilder,
            string blogId,
            string userName,
            string password,
            XRpcStruct file) {

            var user = _membershipService.ValidateUser(userName, password);
            if (!_authorizationService.TryCheckAccess(Permissions.UploadMediaFiles, user, null)) {
                //TEMP: return appropriate access-denied response for user
                throw new ApplicationException("Access denied");
            }

            var name = file.Optional<string>("name");
            var bits = file.Optional<byte[]>("bits");

            var target = HttpContext.Current.Server.MapPath("~/Media/" + name);
            Directory.CreateDirectory(Path.GetDirectoryName(target));
            using (var stream = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) {
                stream.Write(bits, 0, bits.Length);
            }

            uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + "/Media/" + name.TrimStart('/');
            return new XRpcStruct().Set("url", uriBuilder.Uri.AbsoluteUri);
        }
Exemple #3
0
        private async Task <XRpcStruct> MetaWeblogNewMediaObjectAsync(string userName, string password, XRpcStruct file)
        {
            var user = await ValidateUserAsync(userName, password);

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            var    directoryName = Path.GetDirectoryName(name);
            var    filePath      = _mediaFileStore.Combine(directoryName, Path.GetFileName(name));
            Stream stream        = null;

            try
            {
                stream   = new MemoryStream(bits);
                filePath = await _mediaFileStore.CreateFileFromStreamAsync(filePath, stream);
            }
            finally
            {
                stream?.Dispose();
            }

            var publicUrl = _mediaFileStore.MapPathToPublicUrl(filePath);

            return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                   .Set("file", publicUrl)
                   .Set("url", publicUrl)
                   .Set("type", file.Optional <string>("type")));
        }
Exemple #4
0
        private async Task <bool> MetaWeblogEditPostAsync(
            string contentItemId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            var user = await ValidateUserAsync(userName, password);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.DraftRequired);

            if (contentItem == null)
            {
                throw new Exception(S["The specified Blog Post doesn't exist anymore. Please create a new Blog Post."]);
            }

            await CheckAccessAsync(publish?CommonPermissions.PublishContent : CommonPermissions.EditContent, user, contentItem);

            foreach (var driver in _metaWeblogDrivers)
            {
                driver.EditPost(content, contentItem);
            }

            // try to get the UTC time zone by default
            var publishedUtc = content.Optional <DateTime?>("date_created_gmt");

            if (publishedUtc == null)
            {
                // take the local one
                publishedUtc = content.Optional <DateTime?>("dateCreated");
            }
            else
            {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                await _contentManager.PublishAsync(contentItem);
            }
            else
            {
                await _contentManager.SaveDraftAsync(contentItem);
            }

            if (publishedUtc != null)
            {
                contentItem.CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
            {
                driver.Process(contentItem.Id);
            }

            return(true);
        }
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file,
            UrlHelper url)
        {
            List <LocalizedString> validationErrors;
            var user = _membershipService.ValidateUser(userName, password, out validationErrors);

            if (!_authorizationService.TryCheckAccess(Permissions.ManageOwnMedia, user, null) &&
                !_authorizationService.TryCheckAccess(Permissions.EditMediaContent, user, null))
            {
                throw new OrchardCoreException(T("Access denied"));
            }

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            string directoryName = Path.GetDirectoryName(name);

            if (string.IsNullOrWhiteSpace(directoryName))   // Some clients only pass in a name path that does not contain a directory component.
            {
                directoryName = "media";
            }

            // If the user only has access to his own folder, rewrite the folder name
            if (!_authorizationService.TryCheckAccess(Permissions.EditMediaContent, user, null))
            {
                directoryName = Path.Combine(_mediaLibraryService.GetRootedFolderPath(directoryName));
            }

            try {
                // delete the file if it already exists, e.g. an updated image in a blog post
                // it's safe to delete the file as each content item gets a specific folder
                _mediaLibraryService.DeleteFile(directoryName, Path.GetFileName(name));
            }
            catch {
                // current way to delete a file if it exists
            }

            string publicUrl = _mediaLibraryService.UploadMediaFile(directoryName, Path.GetFileName(name), bits);
            var    mediaPart = _mediaLibraryService.ImportMedia(directoryName, Path.GetFileName(name));

            try {
                _contentManager.Create(mediaPart);
            }
            catch {
            }

            return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                   .Set("file", publicUrl)
                   .Set("url", url.MakeAbsolute(publicUrl))
                   .Set("type", file.Optional <string>("type")));
        }
Exemple #6
0
        private bool MetaWeblogEditPost(
            int postId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            IUser user     = ValidateUser(userName, password);
            var   blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);

            if (blogPost == null)
            {
                throw new ArgumentException();
            }

            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);

            var title       = content.Optional <string>("title");
            var description = content.Optional <string>("description");
            var slug        = content.Optional <string>("wp_slug");

            // BodyPart
            if (blogPost.Is <BodyPart>())
            {
                blogPost.As <BodyPart>().Text = description;
            }

            //RoutePart
            if (blogPost.Is <RoutePart>())
            {
                blogPost.As <RoutePart>().Title = title;
                blogPost.As <RoutePart>().Slug  = slug;
                _routableService.FillSlugFromTitle(blogPost.As <RoutePart>());
                blogPost.As <RoutePart>().Path = blogPost.As <RoutePart>().GetPathWithSlug(blogPost.As <RoutePart>().Slug);
            }

            var publishedUtc = content.Optional <DateTime?>("dateCreated");

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                _blogPostService.Publish(blogPost);
            }

            foreach (var driver in drivers)
            {
                driver.Process(blogPost.Id);
            }

            return(true);
        }
Exemple #7
0
        private void MetaWeblogSetCustomCreatedDate(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers) {
            if (!publish)
                return;

            var createdUtc = content.Optional<DateTime?>("dateCreated");
            if (createdUtc == null || createdUtc > DateTime.UtcNow)
                return;

            var driver = new XmlRpcDriver(item => {
                if (!(item is int))
                    return;

                var id = (int)item;
                var contentItem = _contentManager.Get(id, VersionOptions.Latest);
                if (contentItem == null || !contentItem.Is<CommonPart>()) // only pre-dating of content with the CommonPart (obviously)
                    return;

                contentItem.As<CommonPart>().CreatedUtc = createdUtc;
            });

            if (contentItemId > 0)
                driver.Process(contentItemId);
            else
                drivers.Add(driver);
        }
Exemple #8
0
 public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
 {
     if (contentItem.As <TitlePart>() != null)
     {
         contentItem.Alter <TitlePart>(x => x.Title = rpcStruct.Optional <string>("title"));
     }
 }
Exemple #9
0
 public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
 {
     if (contentItem.As <BodyPart>() != null)
     {
         contentItem.Alter <BodyPart>(x => x.Body = rpcStruct.Optional <string>("description"));
     }
 }
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file)
        {
            var user = _membershipService.ValidateUser(userName, password);
            if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null)) {
                //TEMP: return appropriate access-denied response for user
                throw new ApplicationException("Access denied");
            }

            var name = file.Optional<string>("name");
            var bits = file.Optional<byte[]>("bits");

            string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);
            return new XRpcStruct().Set("url", publicUrl);
        }
Exemple #11
0
        private async Task <XRpcStruct> MetaWeblogNewMediaObjectAsync(string userName, string password, XRpcStruct file)
        {
            var user = await ValidateUserAsync(userName, password);

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            string directoryName = Path.GetDirectoryName(name);
            string filePath      = _mediaFileStore.Combine(directoryName, Path.GetFileName(name));
            bool   saved         = await _mediaFileStore.TrySaveStreamAsync(filePath, new MemoryStream(bits));

            string publicUrl = _mediaFileStore.GetPublicUrl(filePath);

            return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                   .Set("file", publicUrl)
                   .Set("url", publicUrl)
                   .Set("type", file.Optional <string>("type")));
        }
Exemple #12
0
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file)
        {
            var user = _membershipService.ValidateUser(userName, password);

            if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null))
            {
                //TEMP: return appropriate access-denied response for user
                throw new ApplicationException("Access denied");
            }

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            string publicUrl = _mediaService.UploadMediaFile(Path.GetDirectoryName(name), Path.GetFileName(name), bits, true);

            return(new XRpcStruct().Set("url", publicUrl));
        }
Exemple #13
0
        public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
        {
            if (contentItem.As <AutoroutePart>() != null)
            {
                var slug = rpcStruct.Optional <string>("wp_slug");

                if (!string.IsNullOrWhiteSpace(slug))
                {
                    contentItem.Alter <AutoroutePart>(x => x.Path = slug);
                }
            }
        }
Exemple #14
0
        private XRpcStruct MetaWeblogNewMediaObject(
            string userName,
            string password,
            XRpcStruct file,
            UrlHelper url)
        {
            var user = _membershipService.ValidateUser(userName, password);

            if (!_authorizationService.TryCheckAccess(Permissions.ManageMedia, user, null))
            {
                throw new OrchardCoreException(T("Access denied"));
            }

            var name = file.Optional <string>("name");
            var bits = file.Optional <byte[]>("bits");

            string directoryName = Path.GetDirectoryName(name);

            if (string.IsNullOrWhiteSpace(directoryName))   // Some clients only pass in a name path that does not contain a directory component.
            {
                directoryName = "media";
            }

            try {
                // delete the file if it already exists, e.g. an updated image in a blog post
                // it's safe to delete the file as each content item gets a specific folder
                _mediaService.DeleteFile(Path.GetDirectoryName(name), Path.GetFileName(name));
            }
            catch {
                // current way to delete a file if it exists
            }

            string publicUrl = _mediaService.UploadMediaFile(directoryName, Path.GetFileName(name), bits, true);

            return(new XRpcStruct() // Some clients require all optional attributes to be declared Wordpress responds in this way as well.
                   .Set("file", publicUrl)
                   .Set("url", url.MakeAbsolute(publicUrl))
                   .Set("type", file.Optional <string>("type")));
        }
Exemple #15
0
        private void MetaWeblogSetCustomPublishedDate(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection <IXmlRpcDriver> drivers)
        {
            var user = ValidateUser(userName, password);

            if (user == null)
            {
                return;
            }

            var publishedUtc = content.Optional <DateTime?>("dateCreated");

            if (publishedUtc == null || publishedUtc <= DateTime.UtcNow) // only post-dating/scheduling of content with the PublishLaterPart
            {
                return;
            }

            var driver = new XmlRpcDriver(item => {
                if (!(item is int))
                {
                    return;
                }

                var id          = (int)item;
                var contentItem = _contentManager.Get(id, VersionOptions.Latest);
                if (contentItem == null || !contentItem.Is <PublishLaterPart>())
                {
                    return;
                }

                _authorizationService.CheckAccess(Permissions.PublishContent, user, null);

                contentItem.As <PublishLaterPart>().ScheduledPublishUtc.Value = publishedUtc;
                _publishingTaskManager.Publish(contentItem, (DateTime)publishedUtc);
            });

            if (contentItemId > 0)
            {
                driver.Process(contentItemId);
            }
            else
            {
                drivers.Add(driver);
            }
        }
        private void MetaWeblogUpdateTags(int contentItemId, string userName, string password, XRpcStruct content, bool publish, ICollection <IXmlRpcDriver> drivers)
        {
            List <LocalizedString> validationErrors;
            var user = _membershipService.ValidateUser(userName, password, out validationErrors);

            var rawTags = content.Optional <string>("mt_keywords");

            if (string.IsNullOrWhiteSpace(rawTags))
            {
                return;
            }

            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(contentItem, tags);
            });

            if (contentItemId > 0)
            {
                driver.Process(contentItemId);
            }
            else
            {
                drivers.Add(driver);
            }
        }
Exemple #17
0
        private void MetaWeblogSetCustomCreatedDate(int contentItemId, string userName, string password, XRpcStruct content, bool publish, ICollection <IXmlRpcDriver> drivers)
        {
            if (!publish)
            {
                return;
            }

            var createdUtc = content.Optional <DateTime?>("dateCreated");

            if (createdUtc == null || createdUtc > DateTime.UtcNow)
            {
                return;
            }

            var driver = new XmlRpcDriver(item => {
                if (!(item is int))
                {
                    return;
                }

                var id          = (int)item;
                var contentItem = _contentManager.Get(id, VersionOptions.Latest);
                if (contentItem == null || !contentItem.Is <CommonPart>()) // only pre-dating of content with the CommonPart (obviously)
                {
                    return;
                }

                contentItem.As <CommonPart>().CreatedUtc = createdUtc;
            });

            if (contentItemId > 0)
            {
                driver.Process(contentItemId);
            }
            else
            {
                drivers.Add(driver);
            }
        }
        private void MetaWeblogUpdateTags(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers)
        {
            var user = _membershipService.ValidateUser(userName, password);

            var rawTags = content.Optional<string>("mt_keywords");
            if (string.IsNullOrWhiteSpace(rawTags))
                return;

            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(contentItem, tags);
            });

            if (contentItemId > 0)
                driver.Process(contentItemId);
            else
                drivers.Add(driver);
        }
        private bool MetaWeblogEditPost(
            int postId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish) {

            var user = _membershipService.ValidateUser(userName, password);
            _authorizationService.CheckAccess(StandardPermissions.AccessFrontEnd, user, null);

            var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);
            if (blogPost == null)
                throw new ArgumentException();


            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            blogPost.Title = title;
            blogPost.Slug = slug;
            blogPost.Text = description;

            if (publish) {
                _blogPostService.Publish(blogPost);
            }

            return true;
        }
Exemple #20
0
        private int MetaWeblogNewPost(
            string blogId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);

            // User needs permission to edit or publish its own blog posts
            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, null);

            BlogPart blog = _contentManager.Get <BlogPart>(Convert.ToInt32(blogId));

            if (blog == null)
            {
                throw new ArgumentException();
            }

            var title       = content.Optional <string>("title");
            var description = content.Optional <string>("description");
            var slug        = content.Optional <string>("wp_slug");

            var blogPost = _contentManager.New <BlogPostPart>("BlogPost");

            // BodyPart
            if (blogPost.Is <BodyPart>())
            {
                blogPost.As <BodyPart>().Text = description;
            }

            //CommonPart
            if (blogPost.Is <ICommonPart>())
            {
                blogPost.As <ICommonPart>().Owner     = user;
                blogPost.As <ICommonPart>().Container = blog;
            }

            //RoutePart
            if (blogPost.Is <RoutePart>())
            {
                blogPost.As <RoutePart>().Title = title;
                blogPost.As <RoutePart>().Slug  = slug;
                _routableService.FillSlugFromTitle(blogPost.As <RoutePart>());
                blogPost.As <RoutePart>().Path = blogPost.As <RoutePart>().GetPathWithSlug(blogPost.As <RoutePart>().Slug);
            }

            _contentManager.Create(blogPost, VersionOptions.Draft);

            var publishedUtc = content.Optional <DateTime?>("dateCreated");

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                _blogPostService.Publish(blogPost);
            }

            foreach (var driver in drivers)
            {
                driver.Process(blogPost.Id);
            }

            return(blogPost.Id);
        }
        private int MetaWeblogNewPost(
            string blogId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable<IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);

            // User needs permission to edit or publish its own blog posts
            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, null);

            BlogPart blog = _contentManager.Get<BlogPart>(Convert.ToInt32(blogId));
            if (blog == null)
                throw new ArgumentException();

            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            var blogPost = _contentManager.New<BlogPostPart>("BlogPost");

            // BodyPart
            if (blogPost.Is<BodyPart>()) {
                blogPost.As<BodyPart>().Text = description;
            }

            //CommonPart
            if (blogPost.Is<ICommonPart>()) {
                blogPost.As<ICommonPart>().Owner = user;
                blogPost.As<ICommonPart>().Container = blog;
            }

            //RoutePart
            if (blogPost.Is<RoutePart>()) {
                blogPost.As<RoutePart>().Title = title;
                blogPost.As<RoutePart>().Slug = slug;
                _routableService.FillSlugFromTitle(blogPost.As<RoutePart>());
                blogPost.As<RoutePart>().Path = blogPost.As<RoutePart>().GetPathWithSlug(blogPost.As<RoutePart>().Slug);
            }

            _contentManager.Create(blogPost, VersionOptions.Draft);

            var publishedUtc = content.Optional<DateTime?>("dateCreated");
            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
                _blogPostService.Publish(blogPost);

            foreach (var driver in drivers)
                driver.Process(blogPost.Id);

            return blogPost.Id;
        }
        private bool MetaWeblogEditPost(
            int postId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable<IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);
            var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);
            if (blogPost == null)
                throw new ArgumentException();

            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);

            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            // BodyPart
            if (blogPost.Is<BodyPart>()) {
                blogPost.As<BodyPart>().Text = description;
            }

            //RoutePart
            if (blogPost.Is<RoutePart>()) {
                blogPost.As<RoutePart>().Title = title;
                blogPost.As<RoutePart>().Slug = slug;
                _routableService.FillSlugFromTitle(blogPost.As<RoutePart>());
                blogPost.As<RoutePart>().Path = blogPost.As<RoutePart>().GetPathWithSlug(blogPost.As<RoutePart>().Slug);
            }

            var publishedUtc = content.Optional<DateTime?>("dateCreated");
            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
                _blogPostService.Publish(blogPost);

            foreach (var driver in drivers)
                driver.Process(blogPost.Id);

            return true;
        }
Exemple #23
0
        private int MetaWeblogNewPost(
            string blogId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);

            // User needs permission to edit or publish its own blog posts
            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, null);

            BlogPart blog = _contentManager.Get <BlogPart>(Convert.ToInt32(blogId));

            if (blog == null)
            {
                throw new ArgumentException();
            }

            var title       = content.Optional <string>("title");
            var description = content.Optional <string>("description");
            var slug        = content.Optional <string>("wp_slug");

            var blogPost = _contentManager.New <BlogPostPart>("BlogPost");

            // BodyPart
            if (blogPost.Is <BodyPart>())
            {
                blogPost.As <BodyPart>().Text = description;
            }

            //CommonPart
            if (blogPost.Is <ICommonPart>())
            {
                blogPost.As <ICommonPart>().Owner     = user;
                blogPost.As <ICommonPart>().Container = blog;
            }

            //TitlePart
            if (blogPost.Is <TitlePart>())
            {
                blogPost.As <TitlePart>().Title = HttpUtility.HtmlDecode(title);
            }

            //AutoroutePart
            dynamic dBlogPost = blogPost;

            if (dBlogPost.AutoroutePart != null)
            {
                dBlogPost.AutoroutePart.DisplayAlias = slug;
            }

            _contentManager.Create(blogPost, VersionOptions.Draft);

            // try to get the UTC timezone by default
            var publishedUtc = content.Optional <DateTime?>("date_created_gmt");

            if (publishedUtc == null)
            {
                // take the local one
                publishedUtc = content.Optional <DateTime?>("dateCreated");
            }
            else
            {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                _blogPostService.Publish(blogPost);
            }

            if (publishedUtc != null)
            {
                blogPost.As <CommonPart>().CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
            {
                driver.Process(blogPost.Id);
            }

            return(blogPost.Id);
        }
Exemple #24
0
        private bool MetaWeblogEditPost(
            int postId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            IUser user     = ValidateUser(userName, password);
            var   blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);

            if (blogPost == null)
            {
                throw new OrchardCoreException(T("The specified Blog Post doesn't exist anymore. Please create a new Blog Post."));
            }

            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);

            var title       = content.Optional <string>("title");
            var description = content.Optional <string>("description");
            var slug        = content.Optional <string>("wp_slug");

            // BodyPart
            if (blogPost.Is <BodyPart>())
            {
                blogPost.As <BodyPart>().Text = description;
            }

            //TitlePart
            if (blogPost.Is <TitlePart>())
            {
                blogPost.As <TitlePart>().Title = HttpUtility.HtmlDecode(title);
            }
            //AutoroutePart
            dynamic dBlogPost = blogPost;

            if (dBlogPost.AutoroutePart != null)
            {
                dBlogPost.AutoroutePart.DisplayAlias = slug;
            }

            // try to get the UTC timezone by default
            var publishedUtc = content.Optional <DateTime?>("date_created_gmt");

            if (publishedUtc == null)
            {
                // take the local one
                publishedUtc = content.Optional <DateTime?>("dateCreated");
            }
            else
            {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                _blogPostService.Publish(blogPost);
            }

            if (publishedUtc != null)
            {
                blogPost.As <CommonPart>().CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
            {
                driver.Process(blogPost.Id);
            }

            return(true);
        }
Exemple #25
0
        private void MetaWeblogSetCustomPublishedDate(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers) {
            var user = ValidateUser(userName, password);
            if (user == null)
                return;

            var publishedUtc = content.Optional<DateTime?>("dateCreated");
            if (publishedUtc == null || publishedUtc <= DateTime.UtcNow) // only post-dating/scheduling of content with the PublishLaterPart
                return;

            var driver = new XmlRpcDriver(item => {
                if (!(item is int))
                    return;

                var id = (int)item;
                var contentItem = _contentManager.Get(id, VersionOptions.Latest);
                if (contentItem == null || !contentItem.Is<PublishLaterPart>())
                    return;

                _authorizationService.CheckAccess(Permissions.PublishContent, user, null);

                contentItem.As<PublishLaterPart>().ScheduledPublishUtc.Value = publishedUtc;
                _publishingTaskManager.Publish(contentItem, (DateTime)publishedUtc);
            });

            if (contentItemId > 0)
                driver.Process(contentItemId);
            else
                drivers.Add(driver);
        }
        private async Task <string> MetaWeblogNewPostAsync(
            string contentItemId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable <IXmlRpcDriver> drivers)
        {
            var user = await ValidateUserAsync(userName, password);

            // User needs permission to edit or publish its own blog posts
            await CheckAccessAsync(publish?Permissions.PublishContent : Permissions.EditContent, user, null);

            var list = await _contentManager.GetAsync(contentItemId);

            if (list == null)
            {
                throw new InvalidOperationException("Could not find content item " + contentItemId);
            }

            var postType = GetContainedContentTypes(list).FirstOrDefault();

            var contentItem = _contentManager.New(postType.Name);

            contentItem.Owner = userName;
            contentItem.Alter <ContainedPart>(x => x.ListContentItemId = list.ContentItemId);

            foreach (var driver in _metaWeblogDrivers)
            {
                driver.EditPost(content, contentItem);
            }

            _contentManager.Create(contentItem, VersionOptions.Draft);

            // try to get the UTC timezone by default
            var publishedUtc = content.Optional <DateTime?>("date_created_gmt");

            if (publishedUtc == null)
            {
                // take the local one
                publishedUtc = content.Optional <DateTime?>("dateCreated");
            }
            else
            {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
            {
                await _contentManager.PublishAsync(contentItem);
            }

            if (publishedUtc != null)
            {
                contentItem.CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
            {
                driver.Process(contentItem.ContentItemId);
            }

            return(contentItem.ContentItemId);
        }
        private int MetaWeblogNewPost(
            string blogId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish) {

            var user = _membershipService.ValidateUser(userName, password);
            _authorizationService.CheckAccess(Permissions.EditBlogPost, user, null);

            var blog = _contentManager.Get<Blog>(Convert.ToInt32(blogId));
            if (blog == null)
                throw new ArgumentException();

            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            var blogPost = _contentManager.New<BlogPost>(BlogPostDriver.ContentType.Name);
            blogPost.Blog = blog;
            blogPost.Title = title;
            blogPost.Slug = slug;
            blogPost.Text = description;
            blogPost.Creator = user;

            _contentManager.Create(blogPost.ContentItem, VersionOptions.Draft);

            if (publish)
                _blogPostService.Publish(blogPost);

            return blogPost.Id;
        }
Exemple #28
0
        private int MetaWeblogNewPost(
            string blogId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable<IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);

            // User needs permission to edit or publish its own blog posts
            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, null);

            BlogPart blog = _contentManager.Get<BlogPart>(Convert.ToInt32(blogId));
            if (blog == null)
                throw new ArgumentException();

            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            var blogPost = _contentManager.New<BlogPostPart>("BlogPost");

            // BodyPart
            if (blogPost.Is<BodyPart>()) {
                blogPost.As<BodyPart>().Text = description;
            }

            //CommonPart
            if (blogPost.Is<ICommonPart>()) {
                blogPost.As<ICommonPart>().Owner = user;
                blogPost.As<ICommonPart>().Container = blog;
            }

            //TitlePart
            if (blogPost.Is<TitlePart>()) {
                blogPost.As<TitlePart>().Title = HttpUtility.HtmlDecode(title);
            }

            //AutoroutePart
            dynamic dBlogPost = blogPost;
            if (dBlogPost.AutoroutePart!=null){
                dBlogPost.AutoroutePart.DisplayAlias = slug;
            }

            _contentManager.Create(blogPost, VersionOptions.Draft);

            // try to get the UTC timezone by default
            var publishedUtc = content.Optional<DateTime?>("date_created_gmt");
            if (publishedUtc == null) {
                // take the local one
                publishedUtc = content.Optional<DateTime?>("dateCreated");
            }
            else {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
                _blogPostService.Publish(blogPost);

            if (publishedUtc != null) {
                blogPost.As<CommonPart>().CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
                driver.Process(blogPost.Id);

            return blogPost.Id;
        }
Exemple #29
0
 public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
 {
     contentItem.DisplayText = rpcStruct.Optional <string>("title");
 }
Exemple #30
0
        private bool MetaWeblogEditPost(
            int postId,
            string userName,
            string password,
            XRpcStruct content,
            bool publish,
            IEnumerable<IXmlRpcDriver> drivers)
        {
            IUser user = ValidateUser(userName, password);
            var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);
            if (blogPost == null) {
                throw new OrchardCoreException(T("The specified Blog Post doesn't exist anymore. Please create a new Blog Post."));
            }

            _authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);

            var title = content.Optional<string>("title");
            var description = content.Optional<string>("description");
            var slug = content.Optional<string>("wp_slug");

            // BodyPart
            if (blogPost.Is<BodyPart>()) {
                blogPost.As<BodyPart>().Text = description;
            }

            //TitlePart
            if (blogPost.Is<TitlePart>()) {
                blogPost.As<TitlePart>().Title = HttpUtility.HtmlDecode(title);
            }
            //AutoroutePart
            dynamic dBlogPost = blogPost;
            if (dBlogPost.AutoroutePart != null) {
                dBlogPost.AutoroutePart.DisplayAlias = slug;
            }

            // try to get the UTC timezone by default
            var publishedUtc = content.Optional<DateTime?>("date_created_gmt");
            if (publishedUtc == null) {
                // take the local one
                publishedUtc = content.Optional<DateTime?>("dateCreated");
            }
            else {
                // ensure it's read as a UTC time
                publishedUtc = new DateTime(publishedUtc.Value.Ticks, DateTimeKind.Utc);
            }

            if (publish && (publishedUtc == null || publishedUtc <= DateTime.UtcNow))
                _blogPostService.Publish(blogPost);

            if (publishedUtc != null) {
                blogPost.As<CommonPart>().CreatedUtc = publishedUtc;
            }

            foreach (var driver in drivers)
                driver.Process(blogPost.Id);

            return true;
        }