Esempio n. 1
0
 protected void GrabAttachments(WordPressPost wpPage)
 {
     if (chkFileGrab.Checked)
     {
         wpPage.GrabAttachments(ddlFolders.SelectedValue, wpSite);
     }
 }
Esempio n. 2
0
        public WordPressResult AddPost(WordPressPost post)
        {
            HttpClient client = CreateHttpClient(WordPressPostsUrl, HttpMethods.Post);

            var content = new StringContent(JsonConvert.SerializeObject(post).ToString(), Encoding.UTF8, "application/json");

            var response = client.PostAsync(WordPressPostsUrl, content).Result;

            if (response.IsSuccessStatusCode)
            {
                string resultString = response.Content.ReadAsStringAsync().Result;
                resultString = GetJsonFromResponseText(resultString);
                JObject jsonResult = JObject.Parse(resultString);

                return(new WordPressResult()
                {
                    IsSuccess = true,
                    Id = jsonResult.Value <int>("id"),
                    Url = jsonResult.Value <string>("link")
                });
            }
            else
            {
                //TODO get error details and add them to the result
                return(new WordPressResult()
                {
                    IsSuccess = false,
                });
            }
        }
Esempio n. 3
0
 protected void GrabAttachments(WordPressPost wpPage)
 {
     if (this.DownloadImages)
     {
         wpPage.GrabAttachments(this.SelectedFolder, this.Site);
     }
 }
        public WordPressResult CreatePodcastPost(PodcastPost podcastPost)
        {
            //1. read in template
            string templateText = ReadTemplate();

            //2. make substitutions to template
            List <string> substitutions = new List <string> {
                podcastPost.Speaker,                //{0}
                podcastPost.BibleText,              //{1}
                podcastPost.GetFormattedDuration(), //{2}
                podcastPost.GetFormattedSize(),     //{3}
                podcastPost.PodcastMediaUrl,        //{4}
                podcastPost.Title                   //{5}
            };
            string content = string.Format(templateText, substitutions.ToArray());

            //3. call WordPress to add the post
            WordPressPost wordPressPost = new WordPressPost()
            {
                status         = "publish",
                title          = GetTitlePrefixedWithDate(podcastPost),
                content        = content,
                date           = podcastPost.Date.ToString("yyyy-MM-dd hh:mm:ss"),
                categories     = new [] { _configurationService.Configuration.WordPressPodcastCategoryId },
                author         = _configurationService.Configuration.WordPressAuthorId,
                featured_media = podcastPost.FeaturedMediaId
            };
            WordPressResult result = _wordPressService.AddPost(wordPressPost);

            //4. return result
            return(result);
        }
Esempio n. 5
0
        protected void RepairBody(WordPressPost wpp)
        {
            wpp.CleanBody();

            if (chkFixBodies.Checked)
            {
                wpp.RepairBody();
            }
        }
Esempio n. 6
0
        protected void RepairBody(WordPressPost wpp)
        {
            wpp.CleanBody();

            if (this.FixHtmlBodies)
            {
                wpp.RepairBody();
            }
        }
Esempio n. 7
0
        private void ImportStuff()
        {
            SiteData.CurrentSite = null;

            SiteData site = SiteData.CurrentSite;

            litMessage.Text = "<p>No Items Selected For Import</p>";
            string sMsg = "";

            if (chkSite.Checked || chkPages.Checked || chkPosts.Checked)
            {
                List <string> tags = site.GetTagList().Select(x => x.TagSlug.ToLowerInvariant()).ToList();
                List <string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLowerInvariant()).ToList();

                wpSite.Tags.RemoveAll(x => tags.Contains(x.InfoKey.ToLowerInvariant()));
                wpSite.Categories.RemoveAll(x => cats.Contains(x.InfoKey.ToLowerInvariant()));

                sMsg += "<p>Imported Tags and Categories</p>";

                List <ContentTag> lstTag = (from l in wpSite.Tags.Distinct()
                                            select new ContentTag {
                    ContentTagID = Guid.NewGuid(),
                    IsPublic = true,
                    SiteID = site.SiteID,
                    TagSlug = l.InfoKey,
                    TagText = l.InfoLabel
                }).Distinct().ToList();

                List <ContentCategory> lstCat = (from l in wpSite.Categories.Distinct()
                                                 select new ContentCategory {
                    ContentCategoryID = Guid.NewGuid(),
                    IsPublic = true,
                    SiteID = site.SiteID,
                    CategorySlug = l.InfoKey,
                    CategoryText = l.InfoLabel
                }).Distinct().ToList();

                foreach (var v in lstTag)
                {
                    v.Save();
                }
                foreach (var v in lstCat)
                {
                    v.Save();
                }
            }
            SetMsg(sMsg);

            if (chkSite.Checked)
            {
                sMsg            += "<p>Updated Site Name</p>";
                site.SiteName    = wpSite.SiteTitle;
                site.SiteTagline = wpSite.SiteDescription;
                site.Save();
            }
            SetMsg(sMsg);

            if (!chkMapAuthor.Checked)
            {
                wpSite.Authors = new List <WordPressUser>();
            }

            //itterate author collection and find if in the system
            foreach (WordPressUser wpu in wpSite.Authors)
            {
                wpu.ImportUserID = Guid.Empty;

                MembershipUser usr = null;
                //attempt to find the user in the userbase
                usr = SecurityData.GetUserListByEmail(wpu.Email).FirstOrDefault();
                if (usr != null)
                {
                    wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString());
                }
                else
                {
                    usr = SecurityData.GetUserListByName(wpu.Login).FirstOrDefault();
                    if (usr != null)
                    {
                        wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString());
                    }
                }

                if (chkAuthors.Checked)
                {
                    if (wpu.ImportUserID == Guid.Empty)
                    {
                        usr = Membership.CreateUser(wpu.Login, ProfileManager.GenerateSimplePassword(), wpu.Email);
                        Roles.AddUserToRole(wpu.Login, SecurityData.CMSGroup_Users);
                        wpu.ImportUserID = new Guid(usr.ProviderUserKey.ToString());
                    }

                    if (wpu.ImportUserID != Guid.Empty)
                    {
                        ExtendedUserData ud = new ExtendedUserData(wpu.ImportUserID);
                        if (ud != null)
                        {
                            if (!String.IsNullOrEmpty(wpu.FirstName) || !String.IsNullOrEmpty(wpu.LastName))
                            {
                                ud.FirstName = wpu.FirstName;
                                ud.LastName  = wpu.LastName;
                                ud.Save();
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format("Could not find new user: {0} ({1})", wpu.Login, wpu.Email));
                        }
                    }
                }
            }

            wpSite.Comments.ForEach(r => r.ImportRootID = Guid.Empty);

            using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                if (chkPages.Checked)
                {
                    sMsg += "<p>Imported Pages</p>";

                    int     iOrder  = 0;
                    SiteNav navHome = navHelper.FindHome(site.SiteID, false);
                    if (navHome != null)
                    {
                        iOrder = 2;
                    }

                    foreach (var wpp in (from c in wpSite.Content
                                         where c.PostType == WordPressPost.WPPostType.Page
                                         orderby c.PostOrder, c.PostTitle
                                         select c).ToList())
                    {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(wpSite, wpp, site);
                        cp.SiteID       = site.SiteID;
                        cp.ContentType  = ContentPageType.PageType.ContentEntry;
                        cp.EditDate     = SiteData.CurrentSite.Now;
                        cp.NavOrder     = iOrder;
                        cp.TemplateFile = ddlTemplatePage.SelectedValue;

                        WordPressPost parent = (from c in wpSite.Content
                                                where c.PostType == WordPressPost.WPPostType.Page &&
                                                c.PostID == wpp.ParentPostID
                                                select c).FirstOrDefault();

                        SiteNav navParent = null;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant());
                        if (parent != null)
                        {
                            navParent = navHelper.GetLatestVersion(site.SiteID, false, parent.ImportFileName.ToLowerInvariant());
                        }

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            if (navData.NavOrder == 0)
                            {
                                cp.NavOrder = 0;
                            }
                        }

                        if (navParent != null)
                        {
                            cp.Parent_ContentID = navParent.Root_ContentID;
                        }
                        else
                        {
                            if (parent != null)
                            {
                                cp.Parent_ContentID = parent.ImportRootID;
                            }
                        }
                        //preserve homepage
                        if (navHome != null && navHome.FileName.ToLowerInvariant() == cp.FileName.ToLowerInvariant())
                        {
                            cp.NavOrder = 0;
                        }

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate     = navData.RetireDate;
                            cp.GoLiveDate     = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        wpSite.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);

                        iOrder++;
                    }
                }

                if (chkPosts.Checked)
                {
                    sMsg += "<p>Imported Posts</p>";

                    foreach (var wpp in (from c in wpSite.Content
                                         where c.PostType == WordPressPost.WPPostType.BlogPost
                                         orderby c.PostOrder
                                         select c).ToList())
                    {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(wpSite, wpp, site);
                        cp.SiteID           = site.SiteID;
                        cp.Parent_ContentID = null;
                        cp.ContentType      = ContentPageType.PageType.BlogEntry;
                        cp.EditDate         = SiteData.CurrentSite.Now;
                        cp.NavOrder         = SiteData.BlogSortOrderNumber;
                        cp.TemplateFile     = ddlTemplatePost.SelectedValue;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLowerInvariant());

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate     = navData.RetireDate;
                            cp.GoLiveDate     = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        wpSite.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);
                    }

                    using (ContentPageHelper cph = new ContentPageHelper()) {
                        //cph.BulkBlogFileNameUpdateFromDate(site.SiteID);
                        cph.ResolveDuplicateBlogURLs(site.SiteID);
                        cph.FixBlogNavOrder(site.SiteID);
                    }
                }
            }
            SetMsg(sMsg);

            wpSite.Comments.RemoveAll(r => r.ImportRootID == Guid.Empty);

            if (wpSite.Comments.Any())
            {
                sMsg += "<p>Imported Comments</p>";
            }

            foreach (WordPressComment wpc in wpSite.Comments)
            {
                int iCommentCount = -1;

                iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP, wpc.CommentContent);
                if (iCommentCount < 1)
                {
                    iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP);
                }

                if (iCommentCount < 1)
                {
                    PostComment pc = new PostComment();
                    pc.ContentCommentID = Guid.NewGuid();
                    pc.Root_ContentID   = wpc.ImportRootID;
                    pc.CreateDate       = site.ConvertUTCToSiteTime(wpc.CommentDateUTC);
                    pc.IsApproved       = false;
                    pc.IsSpam           = false;

                    pc.CommenterIP     = wpc.AuthorIP;
                    pc.CommenterName   = wpc.Author;
                    pc.CommenterEmail  = wpc.AuthorEmail;
                    pc.PostCommentText = wpc.CommentContent;
                    pc.CommenterURL    = wpc.AuthorURL;

                    if (wpc.Approved == "1")
                    {
                        pc.IsApproved = true;
                    }
                    if (wpc.Approved.ToLowerInvariant() == "trash")
                    {
                        pc.IsSpam = true;
                    }
                    if (wpc.Type.ToLowerInvariant() == "trackback" || wpc.Type.ToLowerInvariant() == "pingback")
                    {
                        pc.CommenterEmail = wpc.Type;
                    }

                    pc.Save();
                }
            }
            SetMsg(sMsg);

            BindData();
        }
Esempio n. 8
0
        public void ImportStuff()
        {
            this.HasLoaded = false;
            this.Site      = ContentImportExportUtils.GetSerializedWPExport(this.ImportID);

            SiteData.CurrentSite = null;

            SiteData site = SiteData.CurrentSite;

            this.Message = String.Empty;
            string sMsg = String.Empty;

            if (this.ImportSite || this.ImportPages || this.ImportPosts)
            {
                List <string> tags = site.GetTagList().Select(x => x.TagSlug.ToLower()).ToList();
                List <string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLower()).ToList();

                this.Site.Tags.RemoveAll(x => tags.Contains(x.InfoKey.ToLower()));
                this.Site.Categories.RemoveAll(x => cats.Contains(x.InfoKey.ToLower()));

                sMsg += "<li>Imported Tags and Categories</li>";

                List <ContentTag> lstTag = (from l in this.Site.Tags.Distinct()
                                            select new ContentTag {
                    ContentTagID = Guid.NewGuid(),
                    IsPublic = true,
                    SiteID = site.SiteID,
                    TagSlug = l.InfoKey,
                    TagText = l.InfoLabel
                }).Distinct().ToList();

                List <ContentCategory> lstCat = (from l in this.Site.Categories.Distinct()
                                                 select new ContentCategory {
                    ContentCategoryID = Guid.NewGuid(),
                    IsPublic = true,
                    SiteID = site.SiteID,
                    CategorySlug = l.InfoKey,
                    CategoryText = l.InfoLabel
                }).Distinct().ToList();

                foreach (var v in lstTag)
                {
                    v.Save();
                }
                foreach (var v in lstCat)
                {
                    v.Save();
                }
            }
            SetMsg(sMsg);

            if (this.ImportSite)
            {
                sMsg            += "<li>Updated Site Name</li>";
                site.SiteName    = this.Site.SiteTitle;
                site.SiteTagline = this.Site.SiteDescription;
                site.Save();
            }
            SetMsg(sMsg);

            if (!this.MapUsers)
            {
                this.Site.Authors = new List <WordPressUser>();
            }

            //iterate author collection and find if in the system
            foreach (WordPressUser wpu in this.Site.Authors)
            {
                SecurityData sd = new SecurityData();

                ExtendedUserData usr = null;
                wpu.ImportUserID = Guid.Empty;

                //attempt to find the user in the userbase
                usr = ExtendedUserData.FindByEmail(wpu.Email);
                if (usr != null)
                {
                    wpu.ImportUserID = usr.UserId;
                }
                else
                {
                    usr = ExtendedUserData.FindByUsername(wpu.Login);
                    if (usr != null)
                    {
                        wpu.ImportUserID = usr.UserId;
                    }
                }

                if (this.CreateUsers)
                {
                    if (wpu.ImportUserID == Guid.Empty)
                    {
                        ApplicationUser user = new ApplicationUser {
                            UserName = wpu.Login, Email = wpu.Email
                        };
                        var result = sd.CreateApplicationUser(user, out usr);
                        if (result.Succeeded)
                        {
                            usr = ExtendedUserData.FindByUsername(wpu.Login);
                        }
                        else
                        {
                            throw new Exception(String.Format("Could not create user: {0} ({1}) \r\n{3}", wpu.Login, wpu.Email, String.Join("\r\n", result.Errors)));
                        }
                        wpu.ImportUserID = usr.UserId;
                    }

                    if (wpu.ImportUserID != Guid.Empty)
                    {
                        ExtendedUserData ud = new ExtendedUserData(wpu.ImportUserID);
                        if (!String.IsNullOrEmpty(wpu.FirstName) || !String.IsNullOrEmpty(wpu.LastName))
                        {
                            ud.FirstName = wpu.FirstName;
                            ud.LastName  = wpu.LastName;
                            ud.Save();
                        }
                    }
                }
            }

            this.Site.Comments.ForEach(r => r.ImportRootID = Guid.Empty);

            using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                if (this.ImportPages)
                {
                    sMsg += "<li>Imported Pages</li>";

                    int     iOrder  = 0;
                    SiteNav navHome = navHelper.FindHome(site.SiteID, false);
                    if (navHome != null)
                    {
                        iOrder = 2;
                    }

                    foreach (var wpp in (from c in this.Site.Content
                                         where c.PostType == WordPressPost.WPPostType.Page
                                         orderby c.PostOrder, c.PostTitle
                                         select c).ToList())
                    {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(this.Site, wpp, site);
                        cp.SiteID       = site.SiteID;
                        cp.ContentType  = ContentPageType.PageType.ContentEntry;
                        cp.EditDate     = SiteData.CurrentSite.Now;
                        cp.NavOrder     = iOrder;
                        cp.TemplateFile = this.PageTemplate;

                        WordPressPost parent = (from c in this.Site.Content
                                                where c.PostType == WordPressPost.WPPostType.Page &&
                                                c.PostID == wpp.ParentPostID
                                                select c).FirstOrDefault();

                        SiteNav navParent = null;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLower());
                        if (parent != null)
                        {
                            navParent = navHelper.GetLatestVersion(site.SiteID, false, parent.ImportFileName.ToLower());
                        }

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            if (navData.NavOrder == 0)
                            {
                                cp.NavOrder = 0;
                            }
                        }

                        if (navParent != null)
                        {
                            cp.Parent_ContentID = navParent.Root_ContentID;
                        }
                        else
                        {
                            if (parent != null)
                            {
                                cp.Parent_ContentID = parent.ImportRootID;
                            }
                        }
                        //preserve homepage
                        if (navHome != null && navHome.FileName.ToLower() == cp.FileName.ToLower())
                        {
                            cp.NavOrder = 0;
                        }

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate     = navData.RetireDate;
                            cp.GoLiveDate     = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        this.Site.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);

                        iOrder++;
                    }
                }

                if (this.ImportPosts)
                {
                    sMsg += "<li>Imported Posts</li>";

                    foreach (var wpp in (from c in this.Site.Content
                                         where c.PostType == WordPressPost.WPPostType.BlogPost
                                         orderby c.PostOrder
                                         select c).ToList())
                    {
                        GrabAttachments(wpp);
                        RepairBody(wpp);

                        ContentPage cp = ContentImportExportUtils.CreateWPContentPage(this.Site, wpp, site);
                        cp.SiteID           = site.SiteID;
                        cp.Parent_ContentID = null;
                        cp.ContentType      = ContentPageType.PageType.BlogEntry;
                        cp.EditDate         = SiteData.CurrentSite.Now;
                        cp.NavOrder         = SiteData.BlogSortOrderNumber;
                        cp.TemplateFile     = this.PostTemplate;

                        SiteNav navData = navHelper.GetLatestVersion(site.SiteID, false, cp.FileName.ToLower());

                        cp.RetireDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = CMSConfigHelper.CalcNearestFiveMinTime(cp.CreateDate).AddMinutes(-5);

                        //if URL exists already, make this become a new version in the current series
                        if (navData != null)
                        {
                            cp.Root_ContentID = navData.Root_ContentID;
                            cp.RetireDate     = navData.RetireDate;
                            cp.GoLiveDate     = navData.GoLiveDate;
                        }

                        cp.SavePageEdit();

                        this.Site.Comments.Where(x => x.PostID == wpp.PostID).ToList().ForEach(r => r.ImportRootID = cp.Root_ContentID);
                    }

                    using (ContentPageHelper cph = new ContentPageHelper()) {
                        //cph.BulkBlogFileNameUpdateFromDate(site.SiteID);
                        cph.ResolveDuplicateBlogURLs(site.SiteID);
                        cph.FixBlogNavOrder(site.SiteID);
                    }
                }
            }
            SetMsg(sMsg);

            this.Site.Comments.RemoveAll(r => r.ImportRootID == Guid.Empty);

            if (this.Site.Comments.Any())
            {
                sMsg += "<li>Imported Comments</li>";
            }

            foreach (WordPressComment wpc in this.Site.Comments)
            {
                int iCommentCount = -1;

                iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP, wpc.CommentContent);
                if (iCommentCount < 1)
                {
                    iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, wpc.ImportRootID, wpc.CommentDateUTC, wpc.AuthorIP);
                }

                if (iCommentCount < 1)
                {
                    PostComment pc = new PostComment();
                    pc.ContentCommentID = Guid.NewGuid();
                    pc.Root_ContentID   = wpc.ImportRootID;
                    pc.CreateDate       = site.ConvertUTCToSiteTime(wpc.CommentDateUTC);
                    pc.IsApproved       = false;
                    pc.IsSpam           = false;

                    pc.CommenterIP     = wpc.AuthorIP;
                    pc.CommenterName   = wpc.Author;
                    pc.CommenterEmail  = wpc.AuthorEmail;
                    pc.PostCommentText = wpc.CommentContent;
                    pc.CommenterURL    = wpc.AuthorURL;

                    if (wpc.Approved == "1")
                    {
                        pc.IsApproved = true;
                    }
                    if (wpc.Approved.ToLower() == "trash")
                    {
                        pc.IsSpam = true;
                    }
                    if (wpc.Type.ToLower() == "trackback" || wpc.Type.ToLower() == "pingback")
                    {
                        pc.CommenterEmail = wpc.Type;
                    }

                    pc.Save();
                }
            }
            SetMsg(sMsg);
        }
Esempio n. 9
0
        /// <summary>
        /// Load a post from incoming JSON object
        /// </summary>
        /// <param name="JsonPost">JSON object representing a single post.</param>
        /// <returns>WordPressPost populated from JSON</returns>
        private static WordPressPost loadPostFromJToken(JToken JsonPost)
        {
            WordPressPost post = new WordPressPost();

            post.Id           = (int)JsonPost["id"];
            post.Title        = (string)JsonPost["title"];
            post.Slug         = (string)JsonPost["slug"];
            post.Content      = (string)JsonPost["content"];
            post.Excerpt      = (string)JsonPost["excerpt"];
            post.CreateDate   = (DateTime)JsonPost["date"];
            post.ModifiedDate = (DateTime)JsonPost["modified"];
            var Author = JsonPost["author"];

            if (Author != null)
            {
                post.Author = (string)Author["first_name"] + " " + (string)Author["last_name"] + " " + (string)Author["slug"];
            }

            // grab the content count and the text of all the comments for this post.
            post.CommentCount = (int)JsonPost["comment_count"];
            string commentContent = "";

            if (post.CommentCount > 0)
            {
                foreach (var Comment in JsonPost["comments"])
                {
                    string content = (string)Comment["content"];
                    commentContent += content;
                }
            }
            post.CommentContent = commentContent;


            // grab all the tags
            var tags = JsonPost["tags"];

            if (tags != null)
            {
                string tagContent = "";
                foreach (var tag in tags)
                {
                    string tagTitle = (string)tag["title"];
                    tagContent += tagTitle + ",";
                }
                post.Tags = tagContent;
            }

            // grab all the categories
            var categories = JsonPost["categories"];

            if (categories != null)
            {
                string categoryContent = "";
                foreach (var category in categories)
                {
                    string categoryTitle = (string)category["title"];
                    categoryContent += categoryTitle + ",";
                }
                post.Categories = categoryContent;
            }

            return(post);
        }
        public async void UpdateData(WordPressPost post)
        {
            Post = await WordPressHelper.Client.GetPostAsync(Int32.Parse(post.Id));

            GenerateHtmlContent();
        }
 public PostViewModel(WordPressPost post)
 {
     UpdateData(post);
 }
Esempio n. 12
0
        protected void BuildWidgetInstall()
        {
            pnlReview.Visible = true;

            SiteData site = SiteData.CurrentSite;

            CMSAdminModuleMenu thisModule = cmsHelper.GetCurrentAdminModuleControl();
            string             sDir       = thisModule.ControlFile.Substring(0, thisModule.ControlFile.LastIndexOf("/"));
            List <CMSPlugin>   lstPlug    = cmsHelper.GetPluginsInFolder(sDir);

            CMSPlugin plug = lstPlug.Where(x => x.FilePath.EndsWith("PhotoGalleryPrettyPhoto.ascx")).FirstOrDefault();

            GalleryHelper gh = new GalleryHelper(site.SiteID);

            foreach (GridViewRow row in gvPages.Rows)
            {
                Guid gRootPage = Guid.Empty;
                Guid gGallery  = Guid.Empty;
                int  iPost     = 0;

                CheckBox chkSelect = (CheckBox)row.FindControl("chkSelect");

                if (chkSelect.Checked)
                {
                    HiddenField hdnPostID = (HiddenField)row.FindControl("hdnPostID");

                    iPost = int.Parse(hdnPostID.Value);

                    List <WordPressPost> lstA = (from a in wpSite.Content
                                                 where a.PostType == WordPressPost.WPPostType.Attachment &&
                                                 a.ParentPostID == iPost
                                                 orderby a.PostDateUTC
                                                 select a).Distinct().ToList();

                    lstA.ToList().ForEach(q => q.ImportFileSlug = ddlFolders.SelectedValue + "/" + q.ImportFileSlug);
                    lstA.ToList().ForEach(q => q.ImportFileSlug = q.ImportFileSlug.Replace("//", "/").Replace("//", "/"));

                    WordPressPost post = (from p in wpSite.Content
                                          where p.PostID == iPost
                                          select p).FirstOrDefault();

                    ContentPage cp = null;

                    List <ContentPage> lstCP = pageHelper.FindPageByTitleAndDate(site.SiteID, post.PostTitle, post.PostName, post.PostDateUTC);

                    if (lstCP != null && lstCP.Any())
                    {
                        cp = lstCP.FirstOrDefault();
                    }

                    if (cp != null)
                    {
                        gRootPage = cp.Root_ContentID;
                        if (cp.PageText.Contains("[gallery]"))
                        {
                            cp.PageText = cp.PageText.Replace("[gallery]", "");
                            cp.SavePageEdit();
                        }
                    }

                    GalleryGroup gal = gh.GalleryGroupGetByName(post.PostTitle);

                    if (gal == null)
                    {
                        gal              = new GalleryGroup();
                        gal.SiteID       = site.SiteID;
                        gal.GalleryID    = Guid.Empty;
                        gal.GalleryTitle = post.PostTitle;

                        gal.Save();
                    }

                    gGallery = gal.GalleryID;

                    int iPos = 0;

                    foreach (var img in lstA)
                    {
                        img.ImportFileSlug = img.ImportFileSlug.Replace("//", "/").Replace("//", "/");

                        if (!chkFileGrab.Checked)
                        {
                            cmsHelper.GetFile(img.AttachmentURL, img.ImportFileSlug);
                        }

                        if (!string.IsNullOrEmpty(img.ImportFileSlug))
                        {
                            GalleryImageEntry theImg = gh.GalleryImageEntryGetByFilename(gGallery, img.ImportFileSlug);

                            if (theImg == null)
                            {
                                theImg = new GalleryImageEntry();
                                theImg.GalleryImage   = img.ImportFileSlug;
                                theImg.GalleryImageID = Guid.Empty;
                                theImg.GalleryID      = gGallery;
                            }
                            theImg.ImageOrder = iPos;
                            theImg.Save();

                            GalleryMetaData theMeta = gh.GalleryMetaDataGetByFilename(img.ImportFileSlug);

                            if (theMeta == null)
                            {
                                theMeta = new GalleryMetaData();
                                theMeta.GalleryImageMetaID = Guid.Empty;
                                theMeta.SiteID             = site.SiteID;
                            }

                            if (!string.IsNullOrEmpty(img.PostTitle) || !string.IsNullOrEmpty(img.PostContent))
                            {
                                theMeta.ImageTitle    = img.PostTitle;
                                theMeta.ImageMetaData = img.PostContent;

                                theMeta.Save();
                            }
                        }
                        iPos++;
                    }

                    if (gRootPage != Guid.Empty)
                    {
                        List <Widget> lstW = (from w in cp.GetWidgetList()
                                              where w.ControlPath.ToLower() == plug.FilePath.ToLower() &&
                                              w.ControlProperties.ToLower().Contains(gGallery.ToString().ToLower())
                                              select w).ToList();

                        if (lstW.Count < 1)
                        {
                            Widget newWidget = new Widget();
                            newWidget.ControlProperties = null;
                            newWidget.Root_ContentID    = gRootPage;
                            newWidget.Root_WidgetID     = Guid.NewGuid();
                            newWidget.WidgetDataID      = newWidget.Root_WidgetID;
                            newWidget.ControlPath       = plug.FilePath;
                            newWidget.EditDate          = SiteData.CurrentSite.Now;

                            newWidget.IsLatestVersion       = true;
                            newWidget.IsWidgetActive        = true;
                            newWidget.IsWidgetPendingDelete = false;
                            newWidget.WidgetOrder           = -1;
                            newWidget.PlaceholderName       = txtPlaceholderName.Text;

                            List <WidgetProps> lstProps = new List <WidgetProps>();
                            lstProps.Add(new WidgetProps {
                                KeyName = "ShowHeading", KeyValue = chkShowHeading.Checked.ToString()
                            });
                            lstProps.Add(new WidgetProps {
                                KeyName = "ScaleImage", KeyValue = chkScaleImage.Checked.ToString()
                            });
                            lstProps.Add(new WidgetProps {
                                KeyName = "ThumbSize", KeyValue = ddlSize.SelectedValue
                            });
                            lstProps.Add(new WidgetProps {
                                KeyName = "PrettyPhotoSkin", KeyValue = ddlSkin.SelectedValue
                            });
                            lstProps.Add(new WidgetProps {
                                KeyName = "GalleryID", KeyValue = gGallery.ToString()
                            });

                            newWidget.SaveDefaultControlProperties(lstProps);

                            newWidget.Save();
                        }
                    }
                }
            }
        }