public void CreatePostAndComment()
        {
            using (var client = CreateDefaultClient())
            {
                var post = new Post
                {
                    PostType = "post", // "post" or "page"
                    Title = "Test CreatePostAndComment",
                    Content = "Testing CreatePostAndComment",
                    Status = "draft" // "draft" or "publish"
                };

                var postId = Convert.ToInt32(client.NewPost(post));

                //test id
                Assert.IsTrue(postId > 0);

                var comment = new Comment
                {
                    PostId = postId.ToString(),
                    Author = "WordPressSharpTestPilot",
                    Content = "Hello world!"
                };

                var commentId = client.NewComment(comment);

                //test comment id
                Assert.IsTrue(commentId > 0);

                //clean up
                client.DeletePost(Convert.ToInt32(postId));
            }
        }
示例#2
0
文件: PostBuilder.cs 项目: semlie/ads
        private int sendToWP(Post post)
        {
            using (var client = new WordPressClient(Config))
            {

                var id = Convert.ToInt32(client.NewPost(post));
                return id;
            }
        }
示例#3
0
文件: PostBuilder.cs 项目: semlie/ads
        public Post buildPostData(string title,string content)
        {
            var post = new Post
            {
                Title = title,
                Content = content,
                PublishDateTime = DateTime.Now,
                Status = "publish"

            };
            return post;
        }
        public void CreatePost()
        {
            using (var client = CreateDefaultClient())
            {
                var post = new Post
                {
                    PostType = "post", // "post" or "page"
                    Title = "Test Title",
                    Content = "Test",
                    PublishDateTime = DateTime.Now,
                    Status = "publish" // "draft" or "publish"
                };

                var id = client.NewPost(post);

                Assert.IsFalse(String.IsNullOrEmpty(id));

                client.DeletePost(Convert.ToInt32(id));
            }
        }
        public bool EditPost(Post post)
        {
            var post_put = new Post_Put();
            CopyPropertyValues(post, post_put);

            var terms = new XmlRpcStruct();
            var termTaxes = post.Terms.GroupBy(t => t.Taxonomy);
            foreach (var grp in termTaxes)
            {
                var termIds = grp.Select(g => g.Id).ToArray();
                terms.Add(grp.Key, termIds);
            }

            
            post_put.Terms = terms;


            return WordPressService.EditPost(WordPressSiteConfig.BlogId, WordPressSiteConfig.Username, WordPressSiteConfig.Password, int.Parse(post_put.Id), post_put);
        }
示例#6
0
        /// <summary>
        /// Creates a new entry in WordPress determined by Post.PostType to be a "Post", "Page", or custom post type
        /// </summary>
        /// <param name="post">The post to create</param>
        /// <returns></returns>
        public string NewPost(Post post)    
        {
            var post_put = new Post_Put();
            CopyPropertyValues(post, post_put);

            var terms = new XmlRpcStruct();

            if (post.Terms != null)
            {
                var termTaxes = post.Terms.GroupBy(t => t.Taxonomy);
                foreach (var grp in termTaxes)
                {
                    var termIds = grp.Select(g => g.Id).ToArray();
                    terms.Add(grp.Key, termIds);
                }

                post_put.Terms = terms;
            }
            if (post_put.PostType == "post" && String.IsNullOrEmpty(post_put.CommentStatus))
			{
				post_put.CommentStatus = "open";
			}

            return WordPressService.NewPost(WordPressSiteConfig.BlogId, WordPressSiteConfig.Username, WordPressSiteConfig.Password, post_put);
        }
示例#7
0
文件: PostBuilder.cs 项目: semlie/ads
 public int addPost(Post post)
 {
     post.PostType = "post";
     return sendToWP(post);
 }
示例#8
0
文件: PostBuilder.cs 项目: semlie/ads
 public int addPage(Post post)
 {
     post.PostType = "page";
     return sendToWP(post);
 }
示例#9
0
文件: PostDal.cs 项目: yukseljunk/wps
        public void PublishPost(Post post)
        {
            var catDal = new CategoryDal(_dal);
            var postCategories = catDal.GetCategories(post.Id);
            var defaultCategoryId = catDal.GetInsertDefaultCategoryId();
            var categorySet = postCategories.Contains(defaultCategoryId);
            var uncategorizedSet = postCategories.Contains(1);

            var converterFunctions = new ConverterFunctions();
            var postName = converterFunctions.SeoPostUrl(post.Title);
            var sql = string.Format(
                "Update wp_posts set post_status='publish',post_date=NOW(),post_date_gmt=NOW(),post_modified=NOW(),post_modified_gmt=NOW(),post_name='{1}' where ID={0};",
                post.Id,
                postName.EscapeSql()
                );

            if (!uncategorizedSet)
            {
                sql += string.Format("Insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values({0}, {1},0);", post.Id, 1);
            }
            if (!categorySet)
            {
                sql += string.Format("Insert into wp_term_relationships(object_id,term_taxonomy_id,term_order) values({0}, {1},0);", post.Id, defaultCategoryId);
            }
            _dal.ExecuteNonQuery(sql);
        }
示例#10
0
文件: PostDal.cs 项目: yukseljunk/wps
        public int InsertPost(Post post)
        {
            var customFieldSql = new StringBuilder();
            foreach (var customField in post.CustomFields)
            {
                customFieldSql.Append(
                    string.Format("INSERT INTO wp_postmeta( post_id, meta_key, meta_value) VALUES (@l,'{0}','{1}');",
                        customField.Key.EscapeSql(), customField.Value.EscapeSql()));

            }

            var tagsSql = new StringBuilder();
            if (post.Terms != null)
            {
                foreach (var term in post.Terms)
                {
                    tagsSql.Append(
                        string.Format(
                            "INSERT INTO wp_term_relationships(object_id, term_taxonomy_id, term_order) VALUES (@l,{0},0);",
                            term.Id));

                }
            }

            var imagesSql = new StringBuilder();
            foreach (var imageId in post.ImageIds)
            {
                imagesSql.Append(
                    string.Format("Update wp_posts set post_parent=@l where Id={0};", imageId));

            }

            var converterFunctions = new ConverterFunctions();
            var postName = converterFunctions.SeoUrl(post.Title);
            postName = "";

            var sql = string.Format(
                "INSERT INTO wp_posts(post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, " +
                "ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, " +
                "menu_order, post_type, post_mime_type, comment_count) VALUES " +
                "('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}');" +
                "SET @l=LAST_INSERT_ID();" +
                "Update wp_posts set guid=concat('{22}?p=',@l) where Id=@l;" +
                "{23}{24}{25}SELECT @l;",
                post.Author, post.PublishDateTime.ToString("yyyy-MM-dd HH':'mm':'ss"), post.PublishDateTime.ToString("yyyy-MM-dd HH':'mm':'ss"), post.Content.EscapeSql(), post.Title.EscapeSql(), "", post.Status,
                post.CommentStatus, "open",
                "", postName.EscapeSql(), "", "", DateTime.Now.ToString("yyyy-MM-dd HH':'mm':'ss"), DateTime.Now.ToString("yyyy-MM-dd HH':'mm':'ss"), "", 0, "", 0,
                post.PostType, "", 0, post.BlogUrl.EscapeSql(), customFieldSql.ToString(), tagsSql.ToString(), imagesSql.ToString());

            var postInsertDataSet = _dal.GetData(sql);

            if (postInsertDataSet.Tables.Count == 0) { return -1; }
            if (postInsertDataSet.Tables[0].Rows.Count == 0) { return -1; }
            if (postInsertDataSet.Tables[0].Rows[0].ItemArray.Length == 0) { return -1; }

            var id = postInsertDataSet.Tables[0].Rows[0][0].ToString();
            return int.Parse(id);
        }