コード例 #1
0
        string IMetaWeblog.AddPost(string blogid, string username, string password, MetaWeblogPost post, bool publish)
        {
            var user = ValidateUser(username, password);

            var node = BlogRoot().Children(x => x.DocumentTypeAlias.InvariantEquals("ArticulateArchive")).FirstOrDefault();
            if (node == null)
            {
                throw new XmlRpcFaultException(0, "No Articulate Archive node found");
            }

            var content = _applicationContext.Services.ContentService.CreateContent(
                post.Title, node.Id, "ArticulateRichText", user.Id);

            AddOrUpdateContent(content, post, user, publish);

            return content.Id.ToString(CultureInfo.InvariantCulture);
        }
コード例 #2
0
        private void AddOrUpdateContent(IContent content, MetaWeblogPost post, IUser user, bool publish)
        {
            content.Name = post.Title;
            content.SetValue("author", user.Name);
            if (content.HasProperty("richText"))
            {
                content.SetValue("richText", post.Content);
            }
            if (!post.Slug.IsNullOrWhiteSpace())
            {
                content.SetValue("umbracoUrlName", post.Slug);
            }
            if (!post.Excerpt.IsNullOrWhiteSpace())
            {
                content.SetValue("excerpt", post.Excerpt);
            }
            if (post.AllowComments == 1)
            {
                content.SetValue("enableComments", 1);
            }
            else if (post.AllowComments == 2)
            {
                content.SetValue("enableComments", 0);
            }
            content.SetTags("categories", post.Categories, true, "ArticulateCategories");
            var tags = post.Tags.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
            content.SetTags("tags", tags, true, "ArticulateTags");

            if (publish)
            {
                if (post.CreateDate != DateTime.MinValue)
                {
                    content.SetValue("publishedDate", post.CreateDate);
                }

                _applicationContext.Services.ContentService.SaveAndPublishWithStatus(content, user.Id);
            }
            else
            {
                _applicationContext.Services.ContentService.Save(content, user.Id);
            }
        }
コード例 #3
0
        private void AddOrUpdateContent(IContent content, MetaWeblogPost post, IUser user, bool publish, bool extractFirstImageAsProperty)
        {
            content.Name = post.Title;
            content.SetValue("author", user.Name);
            if (content.HasProperty("richText"))
            {
                var firstImage = "";

                //we need to replace all absolute image paths with relative ones
                var contentToSave = _mediaSrc.Replace(post.Content, match =>
                {
                    if (match.Groups.Count == 2)
                    {
                        var imageSrc = match.Groups[1].Value.EnsureStartsWith('/');
                        if (firstImage.IsNullOrWhiteSpace())
                        {
                            firstImage = imageSrc;
                        }
                        return " src=\"" + imageSrc + "\"";
                    }
                    return null;
                });

                var imagesProcessed = 0;

                //now replace all absolute anchor paths with relative ones
                contentToSave = _mediaHref.Replace(contentToSave, match =>
                {
                    if (match.Groups.Count == 2)
                    {
                        var href = " href=\"" +
                               match.Groups[1].Value.EnsureStartsWith('/') +
                               "\" class=\"a-image-" + imagesProcessed + "\" ";

                        imagesProcessed++;

                        return href;
                    }
                    return null;
                });

                content.SetValue("richText", contentToSave);

                if (extractFirstImageAsProperty
                    && content.HasProperty("postImage")
                    && !firstImage.IsNullOrWhiteSpace())
                {
                    content.SetValue("postImage", firstImage);
                    //content.SetValue("postImage", JsonConvert.SerializeObject(JObject.FromObject(new
                    //{
                    //    src = firstImage
                    //})));
                }
            }

            if (!post.Slug.IsNullOrWhiteSpace())
            {
                content.SetValue("umbracoUrlName", post.Slug);
            }
            if (!post.Excerpt.IsNullOrWhiteSpace())
            {
                content.SetValue("excerpt", post.Excerpt);
            }

            if (post.AllowComments == 1)
            {
                content.SetValue("enableComments", 1);
            }
            else if (post.AllowComments == 2)
            {
                content.SetValue("enableComments", 0);
            }

            content.SetTags("categories", post.Categories, true, "ArticulateCategories");
            var tags = post.Tags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
            content.SetTags("tags", tags, true, "ArticulateTags");

            if (publish)
            {
                if (post.CreateDate != DateTime.MinValue)
                {
                    content.SetValue("publishedDate", post.CreateDate);
                }

                _applicationContext.Services.ContentService.SaveAndPublishWithStatus(content, user.Id);
            }
            else
            {
                _applicationContext.Services.ContentService.Save(content, user.Id);
            }
        }
コード例 #4
0
        bool IMetaWeblog.UpdatePost(string postid, string username, string password, MetaWeblogPost post, bool publish)
        {
            var user = ValidateUser(username, password);

            var asInt = postid.TryConvertTo<int>();
            if (!asInt)
            {
                return false;
            }

            //first see if it's published
            var content = _applicationContext.Services.ContentService.GetById(asInt.Result);
            if (content == null)
            {
                return false;
            }

            AddOrUpdateContent(content, post, user, publish);

            return true;
        }
コード例 #5
0
        bool IMetaWeblog.UpdatePost(string postid, string username, string password, MetaWeblogPost post, bool publish)
        {
            var user = ValidateUser(username, password);

            var asInt = postid.TryConvertTo<int>();
            if (!asInt)
            {
                return false;
            }

            //first see if it's published
            var content = _applicationContext.Services.ContentService.GetById(asInt.Result);
            if (content == null)
            {
                return false;
            }

            var node = BlogRoot().Children(x => x.DocumentTypeAlias.InvariantEquals("ArticulateArchive")).FirstOrDefault();
            if (node == null)
            {
                throw new XmlRpcFaultException(0, "No Articulate Archive node found");
            }

            var extractFirstImageAsProperty = true;
            if (node.HasProperty("extractFirstImage"))
            {
                extractFirstImageAsProperty = node.GetPropertyValue<bool>("extractFirstImage");
            }

            AddOrUpdateContent(content, post, user, publish, extractFirstImageAsProperty);

            return true;
        }