public static void AssignSiteExportNewIDs(SiteExport se) { se.NewSiteID = Guid.NewGuid(); se.TheSite.SiteID = se.NewSiteID; foreach (var p in se.ThePages) { AssignContentPageExportNewIDs(p); if (p.ThePage.ContentType == ContentPageType.PageType.BlogEntry) { p.ThePage.ContentCategories.ToList().ForEach(r => r.CategorySlug = se.TheCategories.Where(x => x.ContentCategoryID == r.ContentCategoryID).FirstOrDefault().CategorySlug); p.ThePage.ContentTags.ToList().ForEach(r => r.TagSlug = se.TheTags.Where(x => x.ContentTagID == r.ContentTagID).FirstOrDefault().TagSlug); } } se.ThePages.Where(p => p.ThePage.ContentType == ContentPageType.PageType.BlogEntry).ToList() .ForEach(r => r.ThePage.PageSlug = ContentPageHelper.ScrubFilename(r.ThePage.Root_ContentID, r.ThePage.PageSlug)); se.ThePages.Where(p => p.ThePage.ContentType == ContentPageType.PageType.BlogEntry).ToList() .ForEach(q => q.ThePage.FileName = ContentPageHelper.ScrubFilename(q.ThePage.Root_ContentID, String.Format("/{0}/{1}", q.ThePage.GoLiveDate.ToString(se.TheSite.Blog_DatePattern), q.ThePage.PageSlug))); se.ThePages.ToList().ForEach(r => r.ThePage.FileName = ContentPageHelper.ScrubFilename(r.ThePage.Root_ContentID, r.ThePage.FileName)); }
private void PerformCommonSave(SiteData pageSite, carrot_RootContent rc, carrot_Content c) { c.NavOrder = this.NavOrder; if (this.ContentType == ContentPageType.PageType.BlogEntry) { this.PageSlug = ContentPageHelper.ScrubFilename(this.Root_ContentID, this.PageSlug); this.FileName = ContentPageHelper.CreateFileNameFromSlug(this.SiteID, this.GoLiveDate, this.PageSlug); c.NavOrder = SiteData.BlogSortOrderNumber; } rc.GoLiveDate = pageSite.ConvertSiteTimeToUTC(this.GoLiveDate); rc.RetireDate = pageSite.ConvertSiteTimeToUTC(this.RetireDate); rc.GoLiveDateLocal = pageSite.ConvertUTCToSiteTime(rc.GoLiveDate); rc.PageSlug = this.PageSlug; rc.PageThumbnail = this.Thumbnail; c.Root_ContentID = this.Root_ContentID; rc.Heartbeat_UserId = this.Heartbeat_UserId; rc.EditHeartbeat = this.EditHeartbeat; rc.FileName = this.FileName; rc.PageActive = this.PageActive; rc.ShowInSiteNav = this.ShowInSiteNav; rc.BlockIndex = this.BlockIndex; rc.ShowInSiteMap = this.ShowInSiteMap; rc.FileName = ContentPageHelper.ScrubFilename(this.Root_ContentID, rc.FileName); c.Parent_ContentID = this.Parent_ContentID; c.IsLatestVersion = true; c.TitleBar = this.TitleBar; c.NavMenuText = this.NavMenuText; c.PageHead = this.PageHead; c.PageText = this.PageText; c.LeftPageText = this.LeftPageText; c.RightPageText = this.RightPageText; c.EditUserId = this.EditUserId; c.CreditUserId = this.CreditUserId; c.EditDate = DateTime.UtcNow; c.TemplateFile = this.TemplateFile; FixMeta(); c.MetaKeyword = this.MetaKeyword.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace(" ", " "); c.MetaDescription = this.MetaDescription.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace(" ", " "); this.Root_ContentID = rc.Root_ContentID; this.ContentID = c.ContentID; this.FileName = rc.FileName; this.EditDate = pageSite.ConvertUTCToSiteTime(c.EditDate); this.CreateDate = pageSite.ConvertUTCToSiteTime(rc.CreateDate); this.GoLiveDate = pageSite.ConvertUTCToSiteTime(rc.GoLiveDate); this.RetireDate = pageSite.ConvertUTCToSiteTime(rc.RetireDate); }
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)); }
internal ContentCategory(vw_carrot_CategoryCounted c) { if (c != null) { this.ContentCategoryID = c.ContentCategoryID; this.SiteID = c.SiteID; this.CategorySlug = ContentPageHelper.ScrubSlug(c.CategorySlug); this.CategoryText = c.CategoryText; this.UseCount = c.UseCount; this.PublicUseCount = 1; this.IsPublic = c.IsPublic; SiteData site = SiteData.GetSiteFromCache(c.SiteID); if (site != null) { this.CategoryURL = ContentPageHelper.ScrubFilename(c.ContentCategoryID, String.Format("/{0}/{1}", site.BlogCategoryPath, c.CategorySlug)); } } }
public bool IsUniqueBlog() { DateTime dateGoLive = Convert.ToDateTime(this.GoLiveDate); DateTime dateOrigGoLive = DateTime.MinValue; string thePageSlug = ContentPageHelper.ScrubFilename(this.Root_ContentID, this.PageSlug).ToLowerInvariant(); string theFileName = thePageSlug; using (ContentPageHelper pageHelper = new ContentPageHelper()) { ContentPage cp = pageHelper.FindContentByID(SiteData.CurrentSite.SiteID, this.Root_ContentID); if (cp != null) { dateOrigGoLive = cp.GoLiveDate; } if (cp == null && this.Root_ContentID != Guid.Empty) { ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(this.Root_ContentID); if (cpe != null) { dateOrigGoLive = cpe.ThePage.GoLiveDate; } } theFileName = ContentPageHelper.CreateFileNameFromSlug(SiteData.CurrentSite.SiteID, dateGoLive, thePageSlug); if (SiteData.IsPageSpecial(theFileName) || SiteData.IsLikelyHomePage(theFileName)) { return(false); } ContentPage fn1 = pageHelper.FindByFilename(SiteData.CurrentSite.SiteID, theFileName); if (cp == null && this.Root_ContentID != Guid.Empty) { cp = pageHelper.GetVersion(SiteData.CurrentSite.SiteID, this.Root_ContentID); } if (fn1 == null || (fn1 != null && cp != null && fn1.Root_ContentID == cp.Root_ContentID)) { return(true); } } return(false); }
internal ContentCategory(vw_carrot_CategoryURL c) { if (c != null) { SiteData site = SiteData.GetSiteFromCache(c.SiteID); this.ContentCategoryID = c.ContentCategoryID; this.SiteID = c.SiteID; this.CategoryURL = ContentPageHelper.ScrubFilename(c.ContentCategoryID, c.CategoryUrl); this.CategoryText = c.CategoryText; this.UseCount = c.UseCount; this.PublicUseCount = c.PublicUseCount; this.IsPublic = c.IsPublic; if (c.EditDate.HasValue) { this.EditDate = site.ConvertUTCToSiteTime(c.EditDate.Value); } } }
internal ContentTag(carrot_ContentTag c) { if (c != null) { this.ContentTagID = c.ContentTagID; this.SiteID = c.SiteID; this.TagSlug = ContentPageHelper.ScrubSlug(c.TagSlug); this.TagText = c.TagText; this.IsPublic = c.IsPublic; this.UseCount = 1; this.PublicUseCount = 1; SiteData site = SiteData.GetSiteFromCache(c.SiteID); if (site != null) { this.TagURL = ContentPageHelper.ScrubFilename(c.ContentTagID, String.Format("/{0}/{1}", site.BlogTagPath, c.TagSlug)); } } }
public static void AssignContentPageExportNewIDs(ContentPageExport cpe) { cpe.NewRootContentID = Guid.NewGuid(); cpe.ThePage.Root_ContentID = cpe.NewRootContentID; cpe.ThePage.ContentID = Guid.NewGuid(); cpe.ThePage.SiteID = SiteData.CurrentSiteID; cpe.ThePage.EditUserId = SecurityData.CurrentUserGuid; cpe.ThePage.EditDate = DateTime.UtcNow; cpe.ThePage.FileName = ContentPageHelper.ScrubFilename(cpe.NewRootContentID, cpe.ThePage.FileName); if (!String.IsNullOrEmpty(cpe.ParentFileName)) { cpe.ParentFileName = ContentPageHelper.ScrubFilename(cpe.OriginalParentContentID, cpe.ParentFileName); } foreach (var w in cpe.ThePageWidgets) { w.Root_ContentID = cpe.NewRootContentID; w.Root_WidgetID = Guid.NewGuid(); w.WidgetDataID = Guid.NewGuid(); } }
public bool IsUniqueFilename() { string theFileName = this.FileName; theFileName = ContentPageHelper.ScrubFilename(this.Root_ContentID, theFileName); theFileName = theFileName.ToLowerInvariant(); if (SiteData.IsPageSpecial(theFileName) || SiteData.IsLikelyHomePage(theFileName)) { return(false); } if (SiteData.CurrentSite.GetSpecialFilePathPrefixes().Where(x => theFileName.StartsWith(x.ToLowerInvariant())).Count() > 0 || theFileName.StartsWith(SiteData.CurrentSite.BlogFolderPath.ToLowerInvariant())) { return(false); } using (ContentPageHelper pageHelper = new ContentPageHelper()) { ContentPage fn = pageHelper.FindByFilename(SiteData.CurrentSite.SiteID, theFileName); ContentPage cp = pageHelper.FindContentByID(SiteData.CurrentSite.SiteID, this.Root_ContentID); if (cp == null && this.Root_ContentID != Guid.Empty) { cp = pageHelper.GetVersion(SiteData.CurrentSite.SiteID, this.Root_ContentID); } if (fn == null || (fn != null && cp != null && fn.Root_ContentID == cp.Root_ContentID)) { return(true); } } return(false); }
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); }
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.ToLowerInvariant() == c.PostAuthor.ToLowerInvariant()).FirstOrDefault(); if (wpu != null && wpu.ImportUserID != Guid.Empty) { MembershipUser usr = SecurityData.GetUserByGuid(wpu.ImportUserID); if (usr != null) { cont.CreateUserId = wpu.ImportUserID; cont.EditUserId = wpu.ImportUserID; } } } cont.Root_ContentID = c.ImportRootID; cont.FileName = ContentPageHelper.ScrubFilename(c.ImportRootID, c.ImportFileName); 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 = ContentPageHelper.ScrubFilename(c.ImportRootID, c.ImportFileSlug); 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 = ""; cont.RightPageText = ""; cont.MetaDescription = ""; cont.MetaKeyword = ""; 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.ToLowerInvariant() equals o.ToLowerInvariant() select l).Distinct().ToList(); cont.ContentTags = (from l in lstTags join o in c.Tags on l.TagSlug.ToLowerInvariant() equals o.ToLowerInvariant() select l).Distinct().ToList(); } return(cont); }