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));
        }
示例#2
0
        private void UpdatePost()
        {
            DateTime postDate = NullValue.NullDateTime;

            vCustomPostDate.IsValid = string.IsNullOrEmpty(txtPostDate.Text) || DateTime.TryParse(txtPostDate.Text, out postDate);

            EnableEnclosureValidation(EnclosureEnabled());

            if (Page.IsValid)
            {
                string successMessage = Constants.RES_SUCCESSNEW;

                try
                {
                    Entry entry;
                    if (PostId == null)
                    {
                        ValidateEntryTypeIsNotNone(EntryType);
                        entry = new Entry(EntryType);
                    }
                    else
                    {
                        entry = GetEntryForEditing(PostId.Value);
                        if (entry.PostType != EntryType)
                        {
                            EntryType = entry.PostType;
                        }
                    }

                    entry.Title  = txbTitle.Text;
                    entry.Body   = richTextEditor.Xhtml;
                    entry.Author = Config.CurrentBlog.Author;
                    entry.Email  = Config.CurrentBlog.Email;
                    entry.BlogId = Config.CurrentBlog.Id;

                    //Enclosure
                    int enclosureId = 0;
                    if (entry.Enclosure != null)
                    {
                        enclosureId = entry.Enclosure.Id;
                    }

                    if (EnclosureEnabled())
                    {
                        if (entry.Enclosure == null)
                        {
                            entry.Enclosure = new Enclosure();
                        }
                        Enclosure enc = entry.Enclosure;

                        enc.Title    = txbEnclosureTitle.Text;
                        enc.Url      = txbEnclosureUrl.Text;
                        enc.MimeType = ddlMimeType.SelectedValue.Equals("other") ? txbEnclosureOtherMimetype.Text : ddlMimeType.SelectedValue;
                        long size;
                        Int64.TryParse(txbEnclosureSize.Text, out size);
                        enc.Size         = size;
                        enc.AddToFeed    = Boolean.Parse(ddlAddToFeed.SelectedValue);
                        enc.ShowWithPost = Boolean.Parse(ddlDisplayOnPost.SelectedValue);
                    }
                    else
                    {
                        entry.Enclosure = null;
                    }

                    // Advanced options
                    entry.IsActive                 = ckbPublished.Checked;
                    entry.AllowComments            = chkComments.Checked;
                    entry.CommentingClosed         = chkCommentsClosed.Checked;
                    entry.DisplayOnHomePage        = chkDisplayHomePage.Checked;
                    entry.IncludeInMainSyndication = chkMainSyndication.Checked;
                    entry.SyndicateDescriptionOnly = chkSyndicateDescriptionOnly.Checked;
                    entry.IsAggregated             = chkIsAggregated.Checked;
                    entry.EntryName                = txbEntryName.Text.NullIfEmpty();
                    entry.Description              = txbExcerpt.Text.NullIfEmpty();
                    entry.Categories.Clear();
                    ReplaceSelectedCategoryNames(entry.Categories);

                    if (!postDate.IsNull())
                    {
                        entry.DatePublishedUtc = Blog.TimeZone.ToUtc(postDate);
                    }

                    if (PostId != null)
                    {
                        successMessage        = Constants.RES_SUCCESSEDIT;
                        entry.DateModifiedUtc = DateTime.UtcNow;
                        entry.Id = PostId.Value;

                        var entryPublisher = SubtextContext.ServiceLocator.GetService <IEntryPublisher>();
                        entryPublisher.Publish(entry);

                        if (entry.Enclosure == null && enclosureId != 0)
                        {
                            Repository.DeleteEnclosure(enclosureId);
                        }
                        else if (entry.Enclosure != null && entry.Enclosure.Id != 0)
                        {
                            Repository.Update(entry.Enclosure);
                        }
                        else if (entry.Enclosure != null && entry.Enclosure.Id == 0)
                        {
                            entry.Enclosure.EntryId = entry.Id;
                            Repository.Create(entry.Enclosure);
                        }

                        UpdateCategories();
                    }
                    else
                    {
                        var entryPublisher = SubtextContext.ServiceLocator.GetService <IEntryPublisher>();
                        _postId = entryPublisher.Publish(entry);
                        NotificationServices.Run(entry, Blog, Url);

                        if (entry.Enclosure != null)
                        {
                            entry.Enclosure.EntryId = PostId.Value;
                            Repository.Create(entry.Enclosure);
                        }

                        UpdateCategories();
                        AddCommunityCredits(entry);
                    }
                }
                catch (Exception ex)
                {
                    Messages.ShowError(String.Format(Constants.RES_EXCEPTION,
                                                     Constants.RES_FAILUREEDIT, ex.Message));
                    successMessage = string.Empty;
                }

                //Prepared success messages were reset in the catch block because of some error on posting the content
                if (!String.IsNullOrEmpty(successMessage))
                {
                    ReturnToOrigin(successMessage);
                }
            }
        }