Example #1
0
        public void GrabAttachments(string folderName, WordPressSite wpSite)
        {
            int iPost = this.PostID;

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

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

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

                    cmsHelper.GetFile(img.AttachmentURL, img.ImportFileSlug);
                    string sURL1    = img.AttachmentURL.Substring(img.AttachmentURL.IndexOf("://") + 3);
                    string sURLLess = sURL1.Substring(sURL1.IndexOf("/"));

                    this.PostContent = this.PostContent.Replace(img.AttachmentURL, img.ImportFileSlug);
                }
            }
        }
		protected void Page_Load(object sender, EventArgs e) {
			pnlReview.Visible = false;
			pnlUpload.Visible = false;
			litTrust.Visible = false;

			if (SiteData.CurrentTrustLevel != AspNetHostingPermissionLevel.Unrestricted) {
				chkFileGrab.Checked = true;
				chkFileGrab.Enabled = false;
				litTrust.Visible = true;
			}

			if (!string.IsNullOrEmpty(Request.QueryString["id"])) {
				gTheID = new Guid(Request.QueryString["id"].ToString());
			} else {
				pnlUpload.Visible = true;
			}

			lblWarning.Text = "";
			lblWarning.Attributes["style"] = "color: #000000;";

			if (gTheID != Guid.Empty) {
				wpSite = ContentImportExportUtils.GetSerializedWPExport(gTheID);
			}

			if (!IsPostBack && gTheID != Guid.Empty) {
				pnlReview.Visible = true;
				LoadLists();
			}
		}
		protected void Page_Load(object sender, EventArgs e) {
			guidImportID = GetGuidParameterFromQuery("importid");

			iPageCount = pageHelper.GetSitePageCount(SiteID, ContentPageType.PageType.ContentEntry);

			litTrust.Visible = false;
			if (SiteData.CurrentTrustLevel != AspNetHostingPermissionLevel.Unrestricted) {
				chkFileGrab.Checked = false;
				chkFileGrab.Enabled = false;
				litTrust.Visible = true;
			}

			litMessage.Text = "";

			if (guidImportID != Guid.Empty) {
				wpSite = ContentImportExportUtils.GetSerializedWPExport(guidImportID);

				litName.Text = wpSite.SiteTitle;
				litDescription.Text = wpSite.SiteDescription;
				litImportSource.Text = wpSite.ImportSource;
				litWXR.Text = wpSite.wxrVersion;
				litDate.Text = wpSite.ExtractDate.ToString();

				if (!IsPostBack) {
					BuildFolderList();

					BindData();
				}
			}
		}
Example #4
0
        public WordPressSite GetContent(XmlDocument doc)
        {
            WordPressSite site = GetAllData(doc);

            site.Content.RemoveAll(x => x.PostType == WordPressPost.WPPostType.Attachment || x.PostType == WordPressPost.WPPostType.Unknown);

            return(site);
        }
Example #5
0
        public static WordPressSite DeserializeWPExportAll(string sXML)
        {
            WPBlogReader  wbp  = new WPBlogReader();
            XmlDocument   doc  = wbp.LoadText(sXML);
            WordPressSite site = wbp.GetAllData(doc);

            return(site);
        }
Example #6
0
        public static void AssignWPExportNewIDs(SiteData sd, WordPressSite wps)
        {
            wps.NewSiteID = Guid.NewGuid();

            wps.Content.Where(p => p.PostType == WordPressPost.WPPostType.BlogPost).ToList()
            .ForEach(q => q.ImportFileName = ContentPageHelper.ScrubPath("/" + sd.ConvertUTCToSiteTime(q.PostDateUTC).ToString(sd.Blog_DatePattern) + "/" + q.ImportFileSlug));

            wps.Content.ToList().ForEach(r => r.ImportFileName = ContentPageHelper.ScrubPath(r.ImportFileName.Replace("//", "/")));
        }
        public static void AssignWPExportNewIDs(SiteData sd, WordPressSite wps)
        {
            wps.NewSiteID = Guid.NewGuid();

            wps.Content.Where(p => p.PostType == WordPressPost.WPPostType.BlogPost).ToList()
            .ForEach(q => q.ImportFileName = ContentPageHelper.ScrubFilename(q.ImportRootID, String.Format("/{0}/{1}", sd.ConvertUTCToSiteTime(q.PostDateUTC).ToString(sd.Blog_DatePattern), q.ImportFileSlug)));

            wps.Content.ToList().ForEach(r => r.ImportFileName = ContentPageHelper.ScrubFilename(r.ImportRootID, r.ImportFileName));
        }
Example #8
0
        public static WordPressSite GetSerializedWPExport(Guid siteID)
        {
            WordPressSite c = null;

            try {
                string sXML = GetSerialized(siteID);
                c = GetSerialData <WordPressSite>(sXML) as WordPressSite;
            } catch (Exception ex) { }
            return(c);
        }
Example #9
0
 public override bool Equals(Object obj)
 {
     //Check for null and compare run-time types.
     if (obj == null || GetType() != obj.GetType())
     {
         return(false);
     }
     if (obj is WordPressSite)
     {
         WordPressSite p = (WordPressSite)obj;
         return((this.SiteTitle == p.SiteTitle) &&
                (this.SiteURL == p.SiteURL));
     }
     else
     {
         return(false);
     }
 }
Example #10
0
        public WordPressSite GetAllData(XmlDocument doc)
        {
            WordPressSite site = new WordPressSite();

            List <WordPressPost>    lstWPP  = new List <WordPressPost>();
            List <WordPressComment> lstWPC  = new List <WordPressComment>();
            List <WordPressUser>    lstAuth = new List <WordPressUser>();

            XmlNode rssNode = doc.SelectSingleNode("//rss");

            XmlNamespaceManager rssNamespace = new XmlNamespaceManager(doc.NameTable);

            foreach (XmlAttribute attrib in rssNode.Attributes)
            {
                if (attrib != null && attrib.Value.ToLowerInvariant().StartsWith("http"))
                {
                    rssNamespace.AddNamespace(attrib.LocalName, attrib.Value);
                }
            }

            site.SiteTitle       = rssNode.SelectSingleNode("channel/title").InnerText;
            site.SiteDescription = rssNode.SelectSingleNode("channel/description").InnerText;
            site.SiteURL         = rssNode.SelectSingleNode("channel/link").InnerText;
            site.ImportSource    = rssNode.SelectSingleNode("channel/generator").InnerText;
            site.ExtractDate     = Convert.ToDateTime(rssNode.SelectSingleNode("channel/pubDate").InnerText);
            site.wxrVersion      = rssNode.SelectSingleNode("channel/wp:wxr_version", rssNamespace).InnerText;

            site.Categories = new List <InfoKVP>();

            XmlNodeList catNodes = doc.SelectNodes("//rss/channel/wp:category", rssNamespace);

            foreach (XmlNode node in catNodes)
            {
                string slug  = node.SelectSingleNode("wp:category_nicename", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:cat_name", rssNamespace).InnerText;
                site.Categories.Add(new InfoKVP(slug, title));
            }
            catNodes = doc.SelectNodes("//rss/channel/item/category[@domain='category']");
            foreach (XmlNode node in catNodes)
            {
                if (node.Attributes["nicename"] != null)
                {
                    string slug  = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Categories.Add(new InfoKVP(slug, title));
                }
            }

            site.Tags = new List <InfoKVP>();

            XmlNodeList tagNodes = doc.SelectNodes("//rss/channel/wp:tag", rssNamespace);

            foreach (XmlNode node in tagNodes)
            {
                string slug  = node.SelectSingleNode("wp:tag_slug", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:tag_name", rssNamespace).InnerText;
                site.Tags.Add(new InfoKVP(slug, title));
            }
            tagNodes = doc.SelectNodes("//rss/channel/item/category[@domain='post_tag']");
            foreach (XmlNode node in tagNodes)
            {
                if (node.Attributes["nicename"] != null)
                {
                    string slug  = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Tags.Add(new InfoKVP(slug, title));
                }
            }

            XmlNodeList rssAuthors = doc.SelectNodes("//rss/channel/wp:author", rssNamespace);

            foreach (XmlNode node in rssAuthors)
            {
                WordPressUser wpu = new WordPressUser();
                wpu.AuthorId = int.Parse(node.SelectSingleNode("wp:author_id", rssNamespace).InnerText);
                wpu.Login    = node.SelectSingleNode("wp:author_login", rssNamespace).InnerText;
                wpu.Email    = node.SelectSingleNode("wp:author_email", rssNamespace).InnerText;
                try { wpu.FirstName = node.SelectSingleNode("wp:author_first_name", rssNamespace).InnerText; } catch { }
                try { wpu.LastName = node.SelectSingleNode("wp:author_last_name", rssNamespace).InnerText; } catch { }
                wpu.ImportUserID = Guid.Empty;

                lstAuth.Add(wpu);
            }

            XmlNodeList nodes = doc.SelectNodes("//rss/channel/item");

            foreach (XmlNode node in nodes)
            {
                WordPressPost wpp = new WordPressPost();
                wpp.PostType     = WordPressPost.WPPostType.Unknown;
                wpp.IsPublished  = false;
                wpp.PostOrder    = 0;
                wpp.ImportRootID = Guid.NewGuid();

                wpp.PostTitle = node.SelectSingleNode("title").InnerText.Trim();
                wpp.PostName  = node.SelectSingleNode("wp:post_name", rssNamespace).InnerText.Trim();

                if (string.IsNullOrEmpty(wpp.PostName))
                {
                    wpp.PostName = wpp.PostTitle.ToLowerInvariant();
                }
                if (string.IsNullOrEmpty(wpp.PostName))
                {
                    wpp.PostName = wpp.ImportRootID.ToString().ToLowerInvariant();
                }
                if (string.IsNullOrEmpty(wpp.PostTitle))
                {
                    wpp.PostTitle = "(No Title)";
                }

                wpp.PostName = ContentPageHelper.ScrubSlug(wpp.PostName);

                wpp.PostAuthor = node.SelectSingleNode("dc:creator", rssNamespace).InnerText;

                string postType = node.SelectSingleNode("wp:post_type", rssNamespace).InnerText;

                switch (postType)
                {
                case "attachment":
                    wpp.PostType = WordPressPost.WPPostType.Attachment;
                    break;

                case "post":
                    wpp.PostType = WordPressPost.WPPostType.BlogPost;
                    break;

                case "page":
                    wpp.PostType = WordPressPost.WPPostType.Page;
                    break;
                }

                if (wpp.PostName.Length > 200 && wpp.PostType == WordPressPost.WPPostType.Page)
                {
                    wpp.PostName = wpp.PostName.Substring(0, 175).Trim();
                }
                if (wpp.PostName.Length > 255 && (wpp.PostType == WordPressPost.WPPostType.BlogPost || wpp.PostType == WordPressPost.WPPostType.Attachment))
                {
                    wpp.PostName = wpp.PostName.Substring(0, 250).Trim();
                }

                wpp.PostDateUTC = DateTime.UtcNow;
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date", rssNamespace).InnerText); } catch { }
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date_gmt", rssNamespace).InnerText); } catch { }

                wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;

                if (node.SelectSingleNode("wp:attachment_url", rssNamespace) != null)
                {
                    wpp.AttachmentURL = node.SelectSingleNode("wp:attachment_url", rssNamespace).InnerText;
                }

                wpp.ImportFileSlug = ContentPageHelper.ScrubFilename(wpp.ImportRootID, "/" + wpp.PostName.Trim() + ".aspx");
                wpp.ImportFileName = ContentPageHelper.ScrubFilename(wpp.ImportRootID, wpp.ImportFileSlug);

                if (wpp.PostType == WordPressPost.WPPostType.Attachment)
                {
                    wpp.ImportFileSlug = wpp.AttachmentURL.Substring(wpp.AttachmentURL.LastIndexOf("/")).Replace("//", "/").Trim();
                    wpp.ImportFileName = wpp.ImportFileSlug;

                    if (node.SelectSingleNode("excerpt:encoded", rssNamespace) != null)
                    {
                        wpp.PostTitle = node.SelectSingleNode("excerpt:encoded", rssNamespace).InnerText;
                    }
                    if (node.SelectSingleNode("content:encoded", rssNamespace) != null)
                    {
                        wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;
                    }
                }

                if (string.IsNullOrEmpty(wpp.PostContent))
                {
                    wpp.PostContent = "";
                }
                wpp.PostContent = wpp.PostContent.Replace("\r\n", "\n").Trim();

                wpp.ParentPostID = int.Parse(node.SelectSingleNode("wp:post_parent", rssNamespace).InnerText);
                wpp.PostID       = int.Parse(node.SelectSingleNode("wp:post_id", rssNamespace).InnerText);
                wpp.PostOrder    = int.Parse(node.SelectSingleNode("wp:menu_order", rssNamespace).InnerText);

                if (node.SelectSingleNode("wp:status", rssNamespace).InnerText == "publish")
                {
                    wpp.IsPublished = true;
                }

                if (wpp.PostType == WordPressPost.WPPostType.BlogPost ||
                    (wpp.PostType == WordPressPost.WPPostType.Page && wpp.ParentPostID > 0))
                {
                    wpp.PostOrder = wpp.PostOrder + 10;
                }

                wpp.Categories = new List <string>();
                XmlNodeList nodesCat = node.SelectNodes("category[@domain='category']");
                foreach (XmlNode n in nodesCat)
                {
                    if (n.Attributes["nicename"] != null)
                    {
                        wpp.Categories.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.Tags = new List <string>();
                XmlNodeList nodesTag = node.SelectNodes("category[@domain='post_tag']");
                foreach (XmlNode n in nodesTag)
                {
                    if (n.Attributes["nicename"] != null)
                    {
                        wpp.Tags.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.CleanBody();

                lstWPP.Add(wpp);

                //=================
                XmlNodeList nodesC = node.SelectNodes("wp:comment", rssNamespace);
                foreach (XmlNode nodeC in nodesC)
                {
                    WordPressComment wpc = new WordPressComment();
                    wpc.ImportRootID   = Guid.Empty;
                    wpc.PostID         = wpp.PostID;
                    wpc.CommentID      = int.Parse(nodeC.SelectSingleNode("wp:comment_id", rssNamespace).InnerText);
                    wpc.Author         = nodeC.SelectSingleNode("wp:comment_author", rssNamespace).InnerText;
                    wpc.AuthorIP       = nodeC.SelectSingleNode("wp:comment_author_IP", rssNamespace).InnerText;
                    wpc.AuthorEmail    = nodeC.SelectSingleNode("wp:comment_author_email", rssNamespace).InnerText;
                    wpc.AuthorURL      = nodeC.SelectSingleNode("wp:comment_author_url", rssNamespace).InnerText;
                    wpc.CommentContent = nodeC.SelectSingleNode("wp:comment_content", rssNamespace).InnerText;

                    wpc.Approved = nodeC.SelectSingleNode("wp:comment_approved", rssNamespace).InnerText;
                    wpc.Type     = nodeC.SelectSingleNode("wp:comment_type", rssNamespace).InnerText;

                    wpc.CommentDateUTC = DateTime.UtcNow;
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date", rssNamespace).InnerText); } catch { }
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date_gmt", rssNamespace).InnerText); } catch { }

                    lstWPC.Add(wpc);
                }
            }

            foreach (WordPressPost w in lstWPP.Where(x => x.ParentPostID > 0 && x.PostType == WordPressPost.WPPostType.Page))
            {
                if (lstWPP.Where(x => x.PostID == w.ParentPostID &&
                                 x.PostType == WordPressPost.WPPostType.Page).Count() > 0)
                {
                    WordPressPost p = lstWPP.Where(x => x.PostID == w.ParentPostID).FirstOrDefault();
                    w.ImportFileName = "/" + p.PostName.Trim() + w.ImportFileSlug;
                }
            }

            site.Content  = lstWPP;
            site.Comments = lstWPC;
            site.Authors  = lstAuth;

            return(site);
        }
Example #11
0
        public WordPressSite GetAllData(XmlDocument doc)
        {
            WordPressSite site = new WordPressSite();

            List<WordPressPost> lstWPP = new List<WordPressPost>();
            List<WordPressComment> lstWPC = new List<WordPressComment>();
            List<WordPressUser> lstAuth = new List<WordPressUser>();

            XmlNode rssNode = doc.SelectSingleNode("//rss");

            XmlNamespaceManager rssNamespace = new XmlNamespaceManager(doc.NameTable);

            foreach (XmlAttribute attrib in rssNode.Attributes) {
                if (attrib != null && attrib.Value.ToLower().StartsWith("http")) {
                    rssNamespace.AddNamespace(attrib.LocalName, attrib.Value);
                }
            }

            site.SiteTitle = rssNode.SelectSingleNode("channel/title").InnerText;
            site.SiteDescription = rssNode.SelectSingleNode("channel/description").InnerText;
            site.SiteURL = rssNode.SelectSingleNode("channel/link").InnerText;
            site.ImportSource = rssNode.SelectSingleNode("channel/generator").InnerText;
            site.ExtractDate = Convert.ToDateTime(rssNode.SelectSingleNode("channel/pubDate").InnerText);
            site.wxrVersion = rssNode.SelectSingleNode("channel/wp:wxr_version", rssNamespace).InnerText;

            site.Categories = new List<InfoKVP>();

            XmlNodeList catNodes = doc.SelectNodes("//rss/channel/wp:category", rssNamespace);
            foreach (XmlNode node in catNodes) {
                string slug = node.SelectSingleNode("wp:category_nicename", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:cat_name", rssNamespace).InnerText;
                site.Categories.Add(new InfoKVP(slug, title));
            }
            catNodes = doc.SelectNodes("//rss/channel/item/category[@domain='category']");
            foreach (XmlNode node in catNodes) {
                if (node.Attributes["nicename"] != null) {
                    string slug = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Categories.Add(new InfoKVP(slug, title));
                }
            }

            site.Tags = new List<InfoKVP>();

            XmlNodeList tagNodes = doc.SelectNodes("//rss/channel/wp:tag", rssNamespace);
            foreach (XmlNode node in tagNodes) {
                string slug = node.SelectSingleNode("wp:tag_slug", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:tag_name", rssNamespace).InnerText;
                site.Tags.Add(new InfoKVP(slug, title));
            }
            tagNodes = doc.SelectNodes("//rss/channel/item/category[@domain='post_tag']");
            foreach (XmlNode node in tagNodes) {
                if (node.Attributes["nicename"] != null) {
                    string slug = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Tags.Add(new InfoKVP(slug, title));
                }
            }

            XmlNodeList rssAuthors = doc.SelectNodes("//rss/channel/wp:author", rssNamespace);
            foreach (XmlNode node in rssAuthors) {
                WordPressUser wpu = new WordPressUser();
                wpu.AuthorId = int.Parse(node.SelectSingleNode("wp:author_id", rssNamespace).InnerText);
                wpu.Login = node.SelectSingleNode("wp:author_login", rssNamespace).InnerText;
                wpu.Email = node.SelectSingleNode("wp:author_email", rssNamespace).InnerText;
                try { wpu.FirstName = node.SelectSingleNode("wp:author_first_name", rssNamespace).InnerText; } catch { }
                try { wpu.LastName = node.SelectSingleNode("wp:author_last_name", rssNamespace).InnerText; } catch { }
                wpu.ImportUserID = Guid.Empty;

                lstAuth.Add(wpu);
            }

            XmlNodeList nodes = doc.SelectNodes("//rss/channel/item");

            foreach (XmlNode node in nodes) {
                WordPressPost wpp = new WordPressPost();
                wpp.PostType = WordPressPost.WPPostType.Unknown;
                wpp.IsPublished = false;
                wpp.PostOrder = 0;
                wpp.ImportRootID = Guid.NewGuid();

                wpp.PostTitle = node.SelectSingleNode("title").InnerText.Trim();
                wpp.PostName = node.SelectSingleNode("wp:post_name", rssNamespace).InnerText.Trim();

                if (string.IsNullOrEmpty(wpp.PostName)) {
                    wpp.PostName = wpp.PostTitle.ToLower();
                }
                if (string.IsNullOrEmpty(wpp.PostName)) {
                    wpp.PostName = wpp.ImportRootID.ToString().ToLower();
                }
                if (string.IsNullOrEmpty(wpp.PostTitle)) {
                    wpp.PostTitle = "(No Title)";
                }

                wpp.PostName = ContentPageHelper.ScrubSlug(wpp.PostName);

                wpp.PostAuthor = node.SelectSingleNode("dc:creator", rssNamespace).InnerText;

                string postType = node.SelectSingleNode("wp:post_type", rssNamespace).InnerText;

                switch (postType) {
                    case "attachment":
                        wpp.PostType = WordPressPost.WPPostType.Attachment;
                        break;
                    case "post":
                        wpp.PostType = WordPressPost.WPPostType.BlogPost;
                        break;
                    case "page":
                        wpp.PostType = WordPressPost.WPPostType.Page;
                        break;
                }

                if (wpp.PostName.Length > 200 && wpp.PostType == WordPressPost.WPPostType.Page) {
                    wpp.PostName = wpp.PostName.Substring(0, 175).Trim();
                }
                if (wpp.PostName.Length > 255 && (wpp.PostType == WordPressPost.WPPostType.BlogPost || wpp.PostType == WordPressPost.WPPostType.Attachment)) {
                    wpp.PostName = wpp.PostName.Substring(0, 250).Trim();
                }

                wpp.PostDateUTC = DateTime.UtcNow;
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date", rssNamespace).InnerText); } catch { }
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date_gmt", rssNamespace).InnerText); } catch { }

                wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;

                if (node.SelectSingleNode("wp:attachment_url", rssNamespace) != null) {
                    wpp.AttachmentURL = node.SelectSingleNode("wp:attachment_url", rssNamespace).InnerText;
                }

                wpp.ImportFileSlug = ContentPageHelper.ScrubFilename(wpp.ImportRootID, "/" + wpp.PostName.Trim() + ".aspx");
                wpp.ImportFileName = ContentPageHelper.ScrubFilename(wpp.ImportRootID, wpp.ImportFileSlug);

                if (wpp.PostType == WordPressPost.WPPostType.Attachment) {
                    wpp.ImportFileSlug = wpp.AttachmentURL.Substring(wpp.AttachmentURL.LastIndexOf("/")).Replace("//", "/").Trim();
                    wpp.ImportFileName = wpp.ImportFileSlug;

                    if (node.SelectSingleNode("excerpt:encoded", rssNamespace) != null) {
                        wpp.PostTitle = node.SelectSingleNode("excerpt:encoded", rssNamespace).InnerText;
                    }
                    if (node.SelectSingleNode("content:encoded", rssNamespace) != null) {
                        wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;
                    }
                }

                if (string.IsNullOrEmpty(wpp.PostContent)) {
                    wpp.PostContent = "";
                }
                wpp.PostContent = wpp.PostContent.Replace("\r\n", "\n").Trim();

                wpp.ParentPostID = int.Parse(node.SelectSingleNode("wp:post_parent", rssNamespace).InnerText);
                wpp.PostID = int.Parse(node.SelectSingleNode("wp:post_id", rssNamespace).InnerText);
                wpp.PostOrder = int.Parse(node.SelectSingleNode("wp:menu_order", rssNamespace).InnerText);

                if (node.SelectSingleNode("wp:status", rssNamespace).InnerText == "publish") {
                    wpp.IsPublished = true;
                }

                if (wpp.PostType == WordPressPost.WPPostType.BlogPost
                    || (wpp.PostType == WordPressPost.WPPostType.Page && wpp.ParentPostID > 0)) {
                    wpp.PostOrder = wpp.PostOrder + 10;
                }

                wpp.Categories = new List<string>();
                XmlNodeList nodesCat = node.SelectNodes("category[@domain='category']");
                foreach (XmlNode n in nodesCat) {
                    if (n.Attributes["nicename"] != null) {
                        wpp.Categories.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.Tags = new List<string>();
                XmlNodeList nodesTag = node.SelectNodes("category[@domain='post_tag']");
                foreach (XmlNode n in nodesTag) {
                    if (n.Attributes["nicename"] != null) {
                        wpp.Tags.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.CleanBody();

                lstWPP.Add(wpp);

                //=================
                XmlNodeList nodesC = node.SelectNodes("wp:comment", rssNamespace);
                foreach (XmlNode nodeC in nodesC) {
                    WordPressComment wpc = new WordPressComment();
                    wpc.ImportRootID = Guid.Empty;
                    wpc.PostID = wpp.PostID;
                    wpc.CommentID = int.Parse(nodeC.SelectSingleNode("wp:comment_id", rssNamespace).InnerText);
                    wpc.Author = nodeC.SelectSingleNode("wp:comment_author", rssNamespace).InnerText;
                    wpc.AuthorIP = nodeC.SelectSingleNode("wp:comment_author_IP", rssNamespace).InnerText;
                    wpc.AuthorEmail = nodeC.SelectSingleNode("wp:comment_author_email", rssNamespace).InnerText;
                    wpc.AuthorURL = nodeC.SelectSingleNode("wp:comment_author_url", rssNamespace).InnerText;
                    wpc.CommentContent = nodeC.SelectSingleNode("wp:comment_content", rssNamespace).InnerText;

                    wpc.Approved = nodeC.SelectSingleNode("wp:comment_approved", rssNamespace).InnerText;
                    wpc.Type = nodeC.SelectSingleNode("wp:comment_type", rssNamespace).InnerText;

                    wpc.CommentDateUTC = DateTime.UtcNow;
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date", rssNamespace).InnerText); } catch { }
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date_gmt", rssNamespace).InnerText); } catch { }

                    lstWPC.Add(wpc);
                }
            }

            foreach (WordPressPost w in lstWPP.Where(x => x.ParentPostID > 0 && x.PostType == WordPressPost.WPPostType.Page)) {
                if (lstWPP.Where(x => x.PostID == w.ParentPostID
                            && x.PostType == WordPressPost.WPPostType.Page).Count() > 0) {
                    WordPressPost p = lstWPP.Where(x => x.PostID == w.ParentPostID).FirstOrDefault();
                    w.ImportFileName = "/" + p.PostName.Trim() + w.ImportFileSlug;
                }
            }

            site.Content = lstWPP;
            site.Comments = lstWPC;
            site.Authors = lstAuth;

            return site;
        }
Example #12
0
        public void GrabAttachments(string folderName, WordPressSite wpSite)
        {
            int iPost = this.PostID;

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

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

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

                    cmsHelper.GetFile(img.AttachmentURL, img.ImportFileSlug);
                    string sURL1 = img.AttachmentURL.Substring(img.AttachmentURL.IndexOf("://") + 3);
                    string sURLLess = sURL1.Substring(sURL1.IndexOf("/"));

                    this.PostContent = this.PostContent.Replace(img.AttachmentURL, img.ImportFileSlug);
                }
            }
        }
Example #13
0
        public static ContentPage CreateWPContentPage(WordPressSite wps, WordPressPost c, SiteData site)
        {
            ContentPage cont = null;

            ContentPageType.PageType contType = ContentPageType.PageType.Unknown;
            switch (c.PostType)
            {
            case WordPressPost.WPPostType.BlogPost:
                contType = ContentPageType.PageType.BlogEntry;
                break;

            case WordPressPost.WPPostType.Page:
                contType = ContentPageType.PageType.ContentEntry;
                break;
            }

            if (c != null)
            {
                cont           = new ContentPage(site.SiteID, contType);
                cont.ContentID = Guid.NewGuid();

                cont.CreateUserId = SecurityData.CurrentUserGuid;
                cont.EditUserId   = SecurityData.CurrentUserGuid;

                if (!String.IsNullOrEmpty(c.PostAuthor))
                {
                    WordPressUser wpu = wps.Authors.Where(x => x.Login.ToLower() == c.PostAuthor.ToLower()).FirstOrDefault();

                    if (wpu != null && wpu.ImportUserID != Guid.Empty)
                    {
                        ApplicationUser usr = SecurityData.GetUserByID(wpu.ImportUserID.ToString());
                        if (usr != null)
                        {
                            cont.CreateUserId = wpu.ImportUserID;
                            cont.EditUserId   = wpu.ImportUserID;
                        }
                    }
                }

                cont.Root_ContentID   = c.ImportRootID;
                cont.FileName         = c.ImportFileName.Replace("//", "/");
                cont.PageSlug         = null;
                cont.NavOrder         = c.PostOrder;
                cont.Parent_ContentID = null;

                cont.CreateDate  = site.ConvertUTCToSiteTime(c.PostDateUTC);
                cont.PageActive  = c.IsPublished;
                cont.ContentType = ContentPageType.PageType.Unknown;

                if (c.PostType == WordPressPost.WPPostType.BlogPost)
                {
                    cont.ContentType      = ContentPageType.PageType.BlogEntry;
                    cont.PageSlug         = c.ImportFileSlug.Replace("//", "/");
                    cont.NavOrder         = SiteData.BlogSortOrderNumber;
                    cont.Parent_ContentID = null;
                }
                if (c.PostType == WordPressPost.WPPostType.Page)
                {
                    cont.ContentType = ContentPageType.PageType.ContentEntry;
                }

                if (cont.ContentType == ContentPageType.PageType.ContentEntry)
                {
                    cont.ShowInSiteMap = true;
                    cont.ShowInSiteNav = true;
                }
                else
                {
                    cont.ShowInSiteMap = false;
                    cont.ShowInSiteNav = false;
                }

                cont.IsLatestVersion = true;

                cont.IsLatestVersion = true;
                cont.TitleBar        = c.PostTitle;
                cont.NavMenuText     = c.PostTitle;
                cont.PageHead        = c.PostTitle;
                cont.PageText        = c.PostContent;
                cont.LeftPageText    = String.Empty;
                cont.RightPageText   = String.Empty;

                cont.MetaDescription = String.Empty;
                cont.MetaKeyword     = String.Empty;

                cont.ContentCategories = new List <ContentCategory>();
                cont.ContentTags       = new List <ContentTag>();

                List <ContentTag>      lstTags       = site.GetTagList();
                List <ContentCategory> lstCategories = site.GetCategoryList();

                cont.ContentCategories = (from l in lstCategories
                                          join o in c.Categories on l.CategorySlug.ToLower() equals o.ToLower()
                                          select l).Distinct().ToList();

                cont.ContentTags = (from l in lstTags
                                    join o in c.Tags on l.TagSlug.ToLower() equals o.ToLower()
                                    select l).Distinct().ToList();
            }

            return(cont);
        }