Пример #1
0
        internal bool EditPost(string postID, string userName, string password, MWAPost sentPost, bool publish)
        {
            ValidateRequest(userName, password);

            var repository = Ioc.Resolve <IRepository>();

            var user = repository.Find <UserProfile>().GetBy(string.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author);
            var post = repository.Get <Post>(postID.ToInt());

            post.Author      = user.Name;
            post.Title       = sentPost.title;
            post.Content     = sentPost.description;
            post.IsPublished = publish;
            post.Slug        = sentPost.slug;
            post.Description = sentPost.excerpt;

            post.Categories.Clear();
            foreach (string item in sentPost.categories.Where(x => x != null && x.Trim() != ""))
            {
                post.Categories.Add(new Category(item.Trim(), ""));
            }

            post.Tags.Clear();
            foreach (string item in sentPost.tags.Where(x => x != null && x.Trim() != ""))
            {
                post.Tags.Add(item.Trim());
            }

            if (sentPost.postDate != DateTime.MinValue)
            {
                post.DateCreated = sentPost.postDate;
            }

            repository.Save(post);

            return(true);
        }
Пример #2
0
        private void LoadXMLRequest(string xml)
        {
            var request = new XmlDocument();
            try
            {
                if (!(xml.StartsWith("<?xml") || xml.StartsWith("<method")))
                    xml = xml.Substring(xml.IndexOf("<?xml"));
                request.LoadXml(xml);
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("01", "Invalid XMLRPC Request. (" + ex.Message + ")");
            }

            // Method name is always first
            _methodName = request.DocumentElement.ChildNodes[0].InnerText;

            // Parameters are next (and last)
            _inputParams = new List<XmlNode>();
            foreach (XmlNode node in request.SelectNodes("/methodCall/params/param"))
                _inputParams.Add(node);

            // Determine what params are what by method name
            switch (_methodName)
            {
                case "metaWeblog.newPost":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _post = GetPost(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "metaWeblog.editPost":
                    _postID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _post = GetPost(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "metaWeblog.getPost":
                    _postID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "metaWeblog.newMediaObject":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _media = GetMediaObject(_inputParams[3]);
                    break;
                case "metaWeblog.getCategories":
                case "wp.getAuthors":
                case "wp.getPageList":
                case "wp.getPages":
                case "wp.getTags":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "metaWeblog.getRecentPosts":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _numberOfPosts = Int32.Parse(_inputParams[3].InnerText, CultureInfo.InvariantCulture);
                    break;
                case "blogger.getUsersBlogs":
                case "metaWeblog.getUsersBlogs":
                    _appKey = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "blogger.deletePost":
                    _appKey = _inputParams[0].InnerText;
                    _postID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "blogger.getUserInfo":
                    _appKey = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    break;
                case "wp.newPage":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _page = GetPage(_inputParams[3]);
                    if (_inputParams[4].InnerText == "0" || _inputParams[4].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "wp.getPage":
                    _blogID = _inputParams[0].InnerText;
                    _pageID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    break;
                case "wp.editPage":
                    _blogID = _inputParams[0].InnerText;
                    _pageID = _inputParams[1].InnerText;
                    _userName = _inputParams[2].InnerText;
                    _password = _inputParams[3].InnerText;
                    _page = GetPage(_inputParams[4]);
                    if (_inputParams[5].InnerText == "0" || _inputParams[5].InnerText == "false")
                        _publish = false;
                    else
                        _publish = true;
                    break;
                case "wp.deletePage":
                    _blogID = _inputParams[0].InnerText;
                    _userName = _inputParams[1].InnerText;
                    _password = _inputParams[2].InnerText;
                    _pageID = _inputParams[3].InnerText;
                    break;
                default:
                    throw new MetaWeblogException("02", "Unknown Method. (" + _methodName + ")");
            }
        }
Пример #3
0
        private MWAPost GetPost(XmlNode node)
        {
            var temp = new MWAPost();
            var cats = new List<string>();
            var tags = new List<string>();

            // Require Title and Description
            try
            {
                temp.title = node.SelectSingleNode("value/struct/member[name='title']").LastChild.InnerText;
                temp.description = node.SelectSingleNode("value/struct/member[name='description']").LastChild.InnerText;
            }
            catch (Exception ex)
            {
                throw new MetaWeblogException("05",
                                              "Post Struct Element, Title or Description,  not Sent. (" + ex.Message +
                                              ")");
            }
            if (node.SelectSingleNode("value/struct/member[name='link']") == null)
                temp.link = "";
            else
                temp.link = node.SelectSingleNode("value/struct/member[name='link']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='mt_allow_comments']") == null)
                temp.commentPolicy = "";
            else
                temp.commentPolicy =
                    node.SelectSingleNode("value/struct/member[name='mt_allow_comments']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='mt_excerpt']") == null)
                temp.excerpt = "";
            else
                temp.excerpt = node.SelectSingleNode("value/struct/member[name='mt_excerpt']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='wp_slug']") == null)
                temp.slug = "";
            else
                temp.slug = node.SelectSingleNode("value/struct/member[name='wp_slug']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='wp_author_id']") == null)
                temp.author = "";
            else
                temp.author = node.SelectSingleNode("value/struct/member[name='wp_author_id']").LastChild.InnerText;

            if (node.SelectSingleNode("value/struct/member[name='categories']") != null)
            {
                XmlNode categoryArray = node.SelectSingleNode("value/struct/member[name='categories']").LastChild;
                foreach (XmlNode catnode in categoryArray.SelectNodes("array/data/value/string"))
                {
                    cats.Add(catnode.InnerText);
                }
            }
            temp.categories = cats;

            // postDate has a few different names to worry about
            if (node.SelectSingleNode("value/struct/member[name='dateCreated']") != null)
            {
                try
                {
                    string tempDate =
                        node.SelectSingleNode("value/struct/member[name='dateCreated']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempDate, "yyyyMMdd'T'HH':'mm':'ss",
                                                        CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }
            else if (node.SelectSingleNode("value/struct/member[name='pubDate']") != null)
            {
                try
                {
                    string tempPubDate =
                        node.SelectSingleNode("value/struct/member[name='pubDate']").LastChild.InnerText;
                    temp.postDate = DateTime.ParseExact(tempPubDate, "yyyyMMdd'T'HH':'mm':'ss",
                                                        CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                }
                catch
                {
                    // Ignore PubDate Error
                }
            }

            // WLW tags implementation using mt_keywords
            if (node.SelectSingleNode("value/struct/member[name='mt_keywords']") != null)
            {
                string tagsList = node.SelectSingleNode("value/struct/member[name='mt_keywords']").LastChild.InnerText;
                foreach (string item in tagsList.Split(','))
                {
                    tags.Add(item.Trim().ToLowerInvariant());
                }
            }
            temp.tags = tags;

            return temp;
        }
Пример #4
0
        internal string NewPost(string blogId, string userName, string password, MWAPost sentPost, bool publish)
        {
            ValidateRequest(userName, password);

            var repository = Ioc.Resolve<IRepository>();

            var user = repository.Find<UserProfile>().GetBy(string.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author);
            var post = new Post(user.Name, sentPost.title, sentPost.description, sentPost.excerpt, sentPost.slug, publish);

            foreach (string item in sentPost.categories.Where(x => x != null && x.Trim() != ""))
                post.Categories.Add(new Category(item.Trim(), ""));

            foreach (string item in sentPost.tags.Where(x => x != null && x.Trim() != ""))
                post.Tags.Add(item.Trim());

            if (sentPost.postDate != DateTime.MinValue)
                post.DateCreated = sentPost.postDate;

            repository.Save(post);

            return post.Id.ToString();
        }
Пример #5
0
        internal MWAPost GetPost(string postID, string userName, string password)
        {
            ValidateRequest(userName, password);

            MWAPost sendPost = new MWAPost();

            var repository = Ioc.Resolve<IRepository>();
            Post post = repository.Get<Post>(x => x.Id == postID.ToInt());

            sendPost.postID = post.Id.ToString();
            sendPost.postDate = post.DateCreated;
            sendPost.title = post.Title;
            sendPost.description = post.Content;

            //TODO: ????
            //sendPost.link = post.AbsoluteLink.AbsoluteUri;
            sendPost.slug = post.Slug;
            sendPost.excerpt = post.Description;

            sendPost.publish = post.IsPublished;

            var categories = new List<string>();
            for (int i = 0; i < post.Categories.Count; i++)
            {
                var category = repository.Get<Category>(x => x.Id == post.Categories[i].Id);
                categories.Add(category.Title);
            }
            sendPost.categories = categories;

            List<string> tags = new List<string>();
            for (int i = 0; i < post.Tags.Count; i++)
                tags.Add(post.Tags[i]);

            sendPost.tags = tags;

            return sendPost;
        }
Пример #6
0
        internal bool EditPost(string postID, string userName, string password, MWAPost sentPost, bool publish)
        {
            ValidateRequest(userName, password);

            var repository = Ioc.Resolve<IRepository>();

            var user = repository.Find<UserProfile>().GetBy(string.IsNullOrEmpty(sentPost.author) ? userName : sentPost.author);
            var post = repository.Get<Post>(postID.ToInt());

            post.Author = user.Name;
            post.Title = sentPost.title;
            post.Content = sentPost.description;
            post.IsPublished = publish;
            post.Slug = sentPost.slug;
            post.Description = sentPost.excerpt;

            post.Categories.Clear();
            foreach (string item in sentPost.categories.Where(x => x != null && x.Trim() != ""))
                post.Categories.Add(new Category(item.Trim(), ""));

            post.Tags.Clear();
            foreach (string item in sentPost.tags.Where(x => x != null && x.Trim() != ""))
                post.Tags.Add(item.Trim());

            if (sentPost.postDate != DateTime.MinValue)
                post.DateCreated = sentPost.postDate;

            repository.Save(post);

            return true;
        }