Пример #1
0
        private MetaWeblog.Post Create(Entry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            MetaWeblog.Post post = new MetaWeblog.Post();
            post.description = entry.Content ?? "";
            post.mt_excerpt  = entry.Description ?? "";
            post.dateCreated = entry.CreatedUtc;
            post.title       = entry.Title ?? "";
            post.link        = post.permalink = _dasBlogSettings.GetPermaLinkUrl(entry.EntryId);
            post.postid      = entry.EntryId ?? "";
            post.categories  = entry.GetSplitCategories();
            return(post);
        }
Пример #2
0
        public string metaweblog_newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            if (!_dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = _siteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }

            Entry newPost = new Entry();

            newPost.Initialize();
            newPost.Author = username;

            TrackbackInfoCollection trackbackList = FillEntryFromMetaWeblogPost(newPost, post);

            newPost.IsPublic   = publish;
            newPost.Syndicated = publish;

            // TODO: Figure out how to SaveEntry here
            // SiteUtilities.SaveEntry(newPost, trackbackList, siteConfig, this.logService, this.dataService);

            return(newPost.EntryId);
        }
Пример #3
0
        /// <summary>Fills a DasBlog entry from a MetaWeblog Post structure.</summary>
        /// <param name="entry">DasBlog entry to fill.</param>
        /// <param name="post">MetaWeblog post structure to fill from.</param>
        /// <returns>TrackbackInfoCollection of posts to send trackback pings.</returns>
        private TrackbackInfoCollection FillEntryFromMetaWeblogPost(Entry entry, MetaWeblog.Post post)
        {
            // W.Bloggar doesn't pass in the DataCreated,
            // so we have to check for that
            if (post.dateCreated != DateTime.MinValue)
            {
                entry.CreatedUtc = post.dateCreated.ToUniversalTime();
            }

            //Patched to avoid html entities in title
            entry.Title       = post.title; // TODO: Find out how to decode this...  HttpUtility.HtmlDecode(post.title);
            entry.Content     = post.description;
            entry.Description = NoNull(post.mt_excerpt);

            // If mt_allow_comments is null, then the sender did not specify.  Use default dasBlog behavior in that case
            if (post.mt_allow_comments != null)
            {
                int nAllowComments = Convert.ToInt32(post.mt_allow_comments);
                if (nAllowComments == 0 || nAllowComments == 2)
                {
                    entry.AllowComments = false;
                }
                else
                {
                    entry.AllowComments = true;
                }
            }

            if (post.categories != null && post.categories.Length > 0)
            {
                // handle categories
                string categories = "";

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                bool needSemi = false;
                post.categories = RemoveDups(post.categories, true);
                foreach (string category in post.categories)
                {
                    //watch for "" as a category
                    if (category.Length > 0)
                    {
                        if (needSemi)
                        {
                            sb.Append(";");
                        }
                        sb.Append(category);
                        needSemi = true;
                    }
                }
                categories = sb.ToString();

                if (categories.Length > 0)
                {
                    entry.Categories = categories;
                }
            }

            // We'll always return at least an empty collection
            TrackbackInfoCollection trackbackList = new TrackbackInfoCollection();

            // Only MT supports trackbacks in the post
            if (post.mt_tb_ping_urls != null)
            {
                foreach (string trackbackUrl in post.mt_tb_ping_urls)
                {
                    trackbackList.Add(new TrackbackInfo(
                                          trackbackUrl,
                                          "", //TODO: Replace SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)entry)
                                          entry.Title,
                                          entry.Description,
                                          _dasBlogSettings.SiteConfiguration.Title));
                }
            }
            return(trackbackList);
        }
Пример #4
0
        public bool metaweblog_editPost(string postid, string username, string password, MetaWeblog.Post post, bool publish)
        {
            if (!_dasBlogSettings.SiteConfiguration.EnableBloggerApi)
            {
                throw new ServiceDisabledException();
            }
            UserToken token = _siteSecurity.Login(username, password);

            if (token == null)
            {
                throw new System.Security.SecurityException();
            }
            Entry entry = _dataService.GetEntryForEdit(postid);

            if (entry != null)
            {
                entry.Author = username;
                TrackbackInfoCollection trackbackList = FillEntryFromMetaWeblogPost(entry, post);

                entry.IsPublic   = publish;
                entry.Syndicated = publish;

                // TODO: Figure out how to save here
                // SiteUtilities.SaveEntry(entry, trackbackList, siteConfig, this.logService, this.dataService);
            }
            return(true);
        }