public static Components.Enclosure CopyValuesToEnclosure(this Enclosure source)
        {
            var enclosure = new Components.Enclosure();

            source.CopyValuesTo(enclosure);
            return(enclosure);
        }
        private string PostContent(string username, string password, ref Post post, bool publish, PostType postType)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);

            var entry = new Entry(postType)
            {
                PostType = postType, IsActive = publish, Author = Blog.Author, Email = Blog.Email
            };

            post.CopyValuesTo(entry);
            entry.AllowComments     = true;
            entry.DisplayOnHomePage = true;

            DateTime dateTimeInPost = post.dateCreated != null ? post.dateCreated.Value : DateTime.UtcNow;

            // Store in the blog's timezone
            dateTimeInPost = Blog.TimeZone.FromUtc(dateTimeInPost);

            entry.DateCreated = entry.DateModified = Blog.TimeZone.Now;
            if (publish)
            {
                entry.DateSyndicated = dateTimeInPost;
            }

            entry.IncludeInMainSyndication = true;
            entry.IsAggregated             = true;
            entry.SyndicateDescriptionOnly = false;

            int postId;

            try
            {
                //TODO: Review whether keywords should be true.
                postId = EntryPublisher.Publish(entry);
                if (Blog.TrackbacksEnabled)
                {
                    NotificationServices.Run(entry, Blog, Url);
                }

                if (post.enclosure != null)
                {
                    Components.Enclosure enclosure = post.enclosure.Value.CopyValuesToEnclosure();
                    enclosure.EntryId = postId;
                    Repository.Create(enclosure);
                }

                AddCommunityCredits(entry);
            }
            catch (Exception e)
            {
                throw new XmlRpcFaultException(0, e.Message + " " + e.StackTrace);
            }
            if (postId < 0)
            {
                throw new XmlRpcFaultException(0, Resources.XmlRpcFault_AddPostFailed);
            }
            return(postId.ToString(CultureInfo.InvariantCulture));
        }
        public bool editPost(string postid, string username, string password, Post post, bool publish)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);

            Entry entry = GetBlogPost(postid);

            if (entry != null)
            {
                entry.Author = Blog.Author;
                entry.Email  = Blog.Email;
                entry.Categories.Clear();
                post.CopyValuesTo(entry);
                entry.IncludeInMainSyndication = true;
                entry.PostType = PostType.BlogPost;

                //User trying to change future dating.
                if (publish && post.dateCreated != null &&
                    Blog.TimeZone.IsInFuture(post.dateCreated.Value, TimeZoneInfo.Utc))
                {
                    entry.DateSyndicated = post.dateCreated.Value;
                }
                entry.IsActive = publish;

                entry.DateModified = Blog.TimeZone.Now;

                EntryPublisher.Publish(entry);

                if (entry.Enclosure == null)
                {
                    if (post.enclosure != null)
                    {
                        Components.Enclosure enclosure = post.enclosure.Value.CopyValuesToEnclosure();
                        enclosure.EntryId = entry.Id;
                        Repository.Create(enclosure);
                    }
                }
                else // if(entry.Enclosure != null)
                {
                    if (post.enclosure != null)
                    {
                        Components.Enclosure enclosure = entry.Enclosure;
                        post.enclosure.Value.CopyValuesTo(enclosure);
                        Repository.Update(enclosure);
                    }
                    else
                    {
                        Repository.DeleteEnclosure(entry.Enclosure.Id);
                    }
                }
            }
            return(true);
        }
Beispiel #4
0
        private string PostContent(string username, string password, ref Post post, bool publish, PostType postType)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            Entry entry = new Entry(postType);
            entry.Author = info.Author;
            entry.Email = info.Email;
            entry.Body = post.description;
            entry.Title = post.title;
            entry.Description = string.Empty;

            //TODO: Figure out why this is here.
            //		Probably means the poster forgot to set the date.

            DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated);
            var lastEntryDate = DbProvider.Instance().GetLatestEntryDate();

            if (dateTimeInPost.Year >= 2003)
            {
                // this is an indication that we want to move the rest of the posts
                if (dateTimeInPost.AddHours(-1) <= Config.CurrentBlog.TimeZone.Now)
                {
                    DbProvider.Instance().PushOtherPostsDatesAfter(dateTimeInPost);
                }
                entry.DateCreated = dateTimeInPost;
                entry.DateModified = dateTimeInPost;
            }
            else
            {

                if (lastEntryDate == null) // there is no next entry date
                {
                    entry.DateCreated = Config.CurrentBlog.TimeZone.Now;
                }
                else if (lastEntryDate.Value.AddDays(1) < Config.CurrentBlog.TimeZone.Now) // the latest date it too far in the past
                {
                    entry.DateCreated = Config.CurrentBlog.TimeZone.Now;
                }
                else
                {
                    // noon the next day
                    entry.DateCreated = lastEntryDate.Value.Date.AddDays(1).AddHours(12);
                    entry.Body = "<blockquote>Originally posted at " + Config.CurrentBlog.TimeZone.Now.ToShortDateString() +
                        "</blockquote>" + entry.Body;
                }
                entry.DateModified = entry.DateCreated;
            }

            if (post.categories != null)
            {
                entry.Categories.AddRange(post.categories);
            }

            if (!string.IsNullOrEmpty(post.wp_slug))
            {
                entry.EntryName = post.wp_slug;
            }

            entry.PostType = postType;

            entry.IsActive = publish;
            if (publish)
            {
                entry.DateSyndicated = entry.DateCreated;
            }
            entry.AllowComments = true;
            entry.DisplayOnHomePage = true;
            entry.IncludeInMainSyndication = true;
            entry.IsAggregated = true;
            entry.SyndicateDescriptionOnly = false;

            int postID;
            try
            {
                postID = Entries.Create(entry);

                if (!string.IsNullOrEmpty(post.enclosure.url))
                {
                    Components.Enclosure enc = new Components.Enclosure();
                    enc.Url = post.enclosure.url;
                    enc.MimeType = post.enclosure.type;
                    enc.Size = post.enclosure.length;
                    enc.EntryId = postID;
                    Enclosures.Create(enc);
                }

                AddCommunityCredits(entry);
            }
            catch (Exception e)
            {
                throw new XmlRpcFaultException(0, e.Message + " " + e.StackTrace);
            }
            if (postID < 0)
            {
                throw new XmlRpcFaultException(0, "The post could not be added");
            }
            return postID.ToString(CultureInfo.InvariantCulture);
        }
Beispiel #5
0
        public bool editPost(string postid, string username, string password, Post post, bool publish)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            Entry entry = Entries.GetEntry(Int32.Parse(postid), PostConfig.None, true);
            if (entry != null)
            {
                entry.Author = info.Author;
                entry.Email = info.Email;
                entry.Body = post.description;
                entry.Title = post.title;
                entry.Description = string.Empty;
                entry.IncludeInMainSyndication = true;

                entry.Categories.Clear();
                if (post.categories != null)
                    entry.Categories.AddRange(post.categories);

                entry.PostType = PostType.BlogPost;
                //User trying to change future dating.

                DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated);

                if (dateTimeInPost > Config.CurrentBlog.TimeZone.Now && publish)
                {
                    entry.DateSyndicated = dateTimeInPost;
                }
                entry.IsActive = publish;

                entry.DateModified = Config.CurrentBlog.TimeZone.Now;
                int[] categoryIds = { };
                if (entry.Categories.Count > 0)
                {
                    categoryIds = Entries.GetCategoryIdsFromCategoryTitles(entry);
                }

                if (!string.IsNullOrEmpty(post.wp_slug))
                {
                    entry.EntryName = post.wp_slug;
                }

                Entries.Update(entry);
                Entries.SetEntryCategoryList(entry.Id, categoryIds);

                if (entry.Enclosure == null)
                {
                    if (!string.IsNullOrEmpty(post.enclosure.url))
                    {
                        Components.Enclosure enc = new Components.Enclosure();
                        enc.Url = post.enclosure.url;
                        enc.MimeType = post.enclosure.type;
                        enc.Size = post.enclosure.length;
                        enc.EntryId = entry.Id;
                        Enclosures.Create(enc);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(post.enclosure.url))
                    {
                        Components.Enclosure enc = entry.Enclosure;
                        enc.Url = post.enclosure.url;
                        enc.MimeType = post.enclosure.type;
                        enc.Size = post.enclosure.length;
                        Enclosures.Update(enc);
                    }
                    else
                    {
                        Enclosures.Delete(entry.Enclosure.Id);
                    }
                }
            }
            return false;
        }
 public static Components.Enclosure CopyValuesToEnclosure(this Enclosure source)
 {
     var enclosure = new Components.Enclosure();
     source.CopyValuesTo(enclosure);
     return enclosure;
 }
 public static void CopyValuesTo(this Enclosure source, Components.Enclosure enclosure)
 {
     enclosure.Url      = source.url;
     enclosure.MimeType = source.type;
     enclosure.Size     = source.length;
 }