コード例 #1
0
ファイル: MetaWeblog.cs プロジェクト: harder/GraffitiCMS
        public MetaWeblog.Post getPost(string postid, string username, string password)
        {
            if (ValidateUser(username, password))
            {
                VersionStoreCollection vsc = VersionStore.GetVersionHistory(Convert.ToInt32(postid));

                Graffiti.Core.Post p = new Graffiti.Core.Post();

                if (vsc != null && vsc.Count > 0)
                {
                    List <Graffiti.Core.Post> the_Posts = new List <Graffiti.Core.Post>();
                    foreach (VersionStore vs in vsc)
                    {
                        the_Posts.Add(ObjectManager.ConvertToObject <Graffiti.Core.Post>(vs.Data));
                    }

                    the_Posts.Sort(delegate(Graffiti.Core.Post p1, Graffiti.Core.Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); });
                    p = the_Posts[0];
                }
                else
                {
                    p = new Graffiti.Core.Post(postid);
                }

                return(ConvertToPost(p));
            }

            throw new XmlRpcFaultException(0, "User does not exist");
        }
コード例 #2
0
ファイル: MetaWeblog.cs プロジェクト: harder/GraffitiCMS
        protected static MetaWeblog.Post ConvertToPost(Graffiti.Core.Post wp)
        {
            MetaWeblog.Post p = new Post();

            if (wp.Category.ParentId > 0)
            {
                p.categories = new string[] { new CategoryController().GetCachedCategory(wp.Category.ParentId, false).Name + " > " + wp.Category.Name }
            }
            ;
            else
            {
                p.categories = new string[] { wp.Category.Name }
            };
            p.dateCreated  = wp.Published;       //.ToUniversalTime();
            p.description  = wp.PostBody;
            p.mt_text_more = wp.ExtendedBody;

            p.link        = new Macros().FullUrl(wp.Url);
            p.permalink   = p.link;
            p.postid      = wp.Id;
            p.title       = wp.Title;
            p.wp_slug     = p.mt_basename = Util.UnCleanForUrl(wp.Name);
            p.mt_keywords = wp.TagList;
            p.mt_tags     = wp.TagList;
            return(p);
        }

        #endregion
    }
コード例 #3
0
ファイル: MetaWeblog.cs プロジェクト: harder/GraffitiCMS
        public bool editPost(string postid, string username, string password, Post post, bool publish)
        {
            if (ValidateUser(username, password))
            {
                Graffiti.Core.Post wp   = new Graffiti.Core.Post(postid);
                IGraffitiUser      user = GraffitiUsers.Current;

                if (post.categories != null && post.categories.Length > 0)
                {
                    wp.CategoryId = AddOrFetchCategory(post.categories[0], user).Id;
                }

                wp.Name = post.wp_slug ?? wp.Name;

                if (!string.IsNullOrEmpty(post.mt_text_more))
                {
                    wp.ExtendedBody = post.mt_text_more;
                }
                else
                {
                    wp.ExtendedBody = null;
                }
                wp.PostBody = post.description;

                wp.Title       = post.title;
                wp.PostStatus  = (publish ? PostStatus.Publish : PostStatus.Draft);
                wp.IsPublished = publish;
                wp.TagList     = post.GetTagList() ?? wp.TagList;

                try
                {
                    if (post.dateCreated != DateTime.MinValue)
                    {
                        DateTime dtUTC   = post.dateCreated;
                        DateTime dtLocal = dtUTC.ToLocalTime();
                        wp.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet);
                        //wp.Published = post.dateCreated;
                    }
                }
                catch {  }

                try
                {
                    PostRevisionManager.CommitPost(wp, user, SiteSettings.Get().FeaturedId == wp.Id, wp.Category.FeaturedId == wp.Id);
                    return(true);
                }
                catch (Exception ex)
                {
                    if (ex.Message.IndexOf("UNIQUE") > -1)
                    {
                        throw new XmlRpcFaultException(2,
                                                       "Sorry, but the name of this post is not unqiue and the post was not saved");
                    }

                    else
                    {
                        Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace);
                        throw;
                    }
                }
            }

            throw new XmlRpcFaultException(0, "User does not exist");
        }
コード例 #4
0
ファイル: MetaWeblog.cs プロジェクト: harder/GraffitiCMS
        public string newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            if (ValidateUser(username, password))
            {
                IGraffitiUser      user      = GraffitiUsers.Current;
                Graffiti.Core.Post postToAdd = new Graffiti.Core.Post();
                postToAdd.ContentType = "text/html";

                postToAdd.PostStatus     = (publish ? PostStatus.Publish : PostStatus.Draft);
                postToAdd.IsPublished    = publish;
                postToAdd.PostBody       = post.description;
                postToAdd.Title          = post.title;
                postToAdd.TagList        = post.GetTagList();
                postToAdd.UserName       = username;
                postToAdd.EnableComments = CommentSettings.Get().EnableCommentsDefault;

                if (post.categories != null && post.categories.Length > 0)
                {
                    postToAdd.CategoryId = AddOrFetchCategory(post.categories[0], user).Id;
                }
                else
                {
                    postToAdd.CategoryId = CategoryController.UnCategorizedId;
                }

                postToAdd.Name = post.GetSlug();

                if (!string.IsNullOrEmpty(post.mt_text_more))
                {
                    postToAdd.ExtendedBody = post.mt_text_more;
                }



                // Get UserTime safely (some clients pass in a DateTime that is not valid)
                try
                {
                    if (post.dateCreated != DateTime.MinValue)
                    {
                        DateTime dtUTC   = post.dateCreated;
                        DateTime dtLocal = dtUTC.ToLocalTime();
                        postToAdd.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet);
                    }
                }
                catch { postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); }

                if (postToAdd.Published <= new DateTime(2000, 1, 1))
                {
                    postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);
                }

                try
                {
                    return(PostRevisionManager.CommitPost(postToAdd, user, false, false).ToString());
                }
                catch (Exception ex)
                {
                    if (ex.Message.IndexOf("UNIQUE") > -1)
                    {
                        throw new XmlRpcFaultException(2, "Duplicate Post Name");
                    }

                    else
                    {
                        Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace);
                        throw;
                    }
                }
            }


            throw new XmlRpcFaultException(0, "User does not exist");
        }
コード例 #5
0
ファイル: MetaWeblog.cs プロジェクト: chartek/graffiticms
        public bool editPost(string postid,	string username,string password,Post post,bool publish)
        {
            if(ValidateUser(username,password))
            {
                Graffiti.Core.Post wp = new Graffiti.Core.Post(postid);
                IGraffitiUser user = GraffitiUsers.Current;

                if(post.categories != null && post.categories.Length > 0)
                {
                    wp.CategoryId = AddOrFetchCategory(post.categories[0],user).Id;
                }

                wp.Name = post.wp_slug ?? wp.Name;

                if (!string.IsNullOrEmpty(post.mt_text_more))
                {
                    wp.ExtendedBody = post.mt_text_more;
                }
                else
                {
                    wp.ExtendedBody = null;
                }
                wp.PostBody = post.description;

                wp.Title = post.title;
                wp.PostStatus = (publish ? PostStatus.Publish : PostStatus.Draft);
                wp.IsPublished = publish;
                wp.TagList = post.GetTagList() ?? wp.TagList;

                try
                {
                    if (post.dateCreated != DateTime.MinValue)
                    {
                        DateTime dtUTC = post.dateCreated;
                        DateTime dtLocal = dtUTC.ToLocalTime();
                        wp.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet);
                        //wp.Published = post.dateCreated;
                    }

                }
                catch {  }

                try
                {
                    PostRevisionManager.CommitPost(wp, user, SiteSettings.Get().FeaturedId == wp.Id,wp.Category.FeaturedId == wp.Id);
                    return true;
                }
                catch (Exception ex)
                {
                    if(ex.Message.IndexOf("UNIQUE") > -1)
                    throw new XmlRpcFaultException(2,
                                                   "Sorry, but the name of this post is not unqiue and the post was not saved");

                    else
                    {
                        Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid,ex.Message,ex.StackTrace);
                        throw;
                    }
                }

            }

            throw new XmlRpcFaultException(0,"User does not exist");
        }
コード例 #6
0
ファイル: MetaWeblog.cs プロジェクト: chartek/graffiticms
        public string newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            if(ValidateUser(username,password))
            {
                IGraffitiUser user = GraffitiUsers.Current;
                Graffiti.Core.Post postToAdd = new Graffiti.Core.Post();
                postToAdd.ContentType = "text/html";

                postToAdd.PostStatus = (publish ? PostStatus.Publish : PostStatus.Draft);
                postToAdd.IsPublished = publish;
                postToAdd.PostBody = post.description;
                postToAdd.Title = post.title;
                postToAdd.TagList = post.GetTagList();
                postToAdd.UserName = username;
                postToAdd.EnableComments = CommentSettings.Get().EnableCommentsDefault;

                if (post.categories != null && post.categories.Length > 0)
                {
                    postToAdd.CategoryId = AddOrFetchCategory(post.categories[0],user).Id;
                }
                else
                {
                    postToAdd.CategoryId = CategoryController.UnCategorizedId;
                }

                postToAdd.Name = post.GetSlug();

                if (!string.IsNullOrEmpty(post.mt_text_more))
                {
                    postToAdd.ExtendedBody = post.mt_text_more;
                }

                // Get UserTime safely (some clients pass in a DateTime that is not valid)
                try
                {
                    if (post.dateCreated != DateTime.MinValue)
                    {
                        DateTime dtUTC = post.dateCreated;
                        DateTime dtLocal = dtUTC.ToLocalTime();
                        postToAdd.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet);
                    }
                }
                catch { postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); }

                if(postToAdd.Published <= new DateTime(2000,1,1))
                    postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);

                try
                {
                    return PostRevisionManager.CommitPost(postToAdd, user, false, false).ToString();
                }
                catch(Exception ex)
                {
                    if (ex.Message.IndexOf("UNIQUE") > -1)
                        throw new XmlRpcFaultException(2,"Duplicate Post Name");

                    else
                    {
                        Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace);
                        throw;
                    }
                }

            }

            throw new XmlRpcFaultException(0,"User does not exist");
        }
コード例 #7
0
ファイル: MetaWeblog.cs プロジェクト: chartek/graffiticms
        public MetaWeblog.Post getPost(string postid,string username,string password)
        {
            if(ValidateUser(username,password))
            {
                VersionStoreCollection vsc = VersionStore.GetVersionHistory(Convert.ToInt32(postid));

                Graffiti.Core.Post p = new Graffiti.Core.Post();

                if (vsc != null && vsc.Count > 0)
                {
                    List<Graffiti.Core.Post> the_Posts = new List<Graffiti.Core.Post>();
                    foreach (VersionStore vs in vsc)
                    {
                        the_Posts.Add(ObjectManager.ConvertToObject<Graffiti.Core.Post>(vs.Data));
                    }

                    the_Posts.Sort(delegate(Graffiti.Core.Post p1, Graffiti.Core.Post p2) { return Comparer<int>.Default.Compare(p2.Version, p1.Version); });
                    p = the_Posts[0];
                }
                else
                {
                    p = new Graffiti.Core.Post(postid);
                }

                return ConvertToPost(p);
            }

            throw new XmlRpcFaultException(0,"User does not exist");
        }