public void SetPage(ContentPage page) { this.ContentPage = page; this.OriginalFileName = page.FileName; this.SelectedCategories = this.ContentPage.ContentCategories.Select(x => x.ContentCategoryID.ToString().ToLower()).ToList(); this.SelectedTags = this.ContentPage.ContentTags.Select(x => x.ContentTagID.ToString().ToLower()).ToList(); this.InitSelections(); if (this.ContentPage != null) { using (ContentPageHelper pageHelper = new ContentPageHelper()) { if (this.ContentPage.Root_ContentID != Guid.Empty) { this.VersionHistory = (from v in pageHelper.GetVersionHistory(this.ContentPage.SiteID, this.ContentPage.Root_ContentID) join u in ExtendedUserData.GetUserList() on v.EditUserId equals u.UserId orderby v.EditDate descending select new KeyValuePair <string, string>(v.ContentID.ToString(), String.Format("{0} ({1}) {2}", v.EditDate, u.UserName, (v.IsLatestVersion ? " [**] " : " "))) ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } else { this.ContentPage.CreateDate = DateTime.UtcNow.Date; this.ContentPage.EditDate = DateTime.UtcNow.Date; this.ContentPage.ContentID = Guid.NewGuid(); if (this.ContentPage.ContentType == ContentPageType.PageType.ContentEntry) { this.ContentPage.NavOrder = pageHelper.GetSitePageCount(this.ContentPage.SiteID, this.ContentPage.ContentType) * 2; } else { this.ContentPage.Parent_ContentID = null; this.ContentPage.NavOrder = SiteData.BlogSortOrderNumber; } DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); this.ContentPage.GoLiveDate = dtSite; this.ContentPage.RetireDate = dtSite.AddYears(200); float iThird = (float)(this.ContentPage.NavOrder - 1) / (float)3; Dictionary <string, float> dictTemplates = pageHelper.GetPopularTemplateList(this.ContentPage.SiteID, this.ContentPage.ContentType); if (dictTemplates.Any() && dictTemplates.First().Value >= iThird) { try { this.ContentPage.TemplateFile = dictTemplates.First().Key; } catch { } } } } RefreshWidgetList(); } }
protected void btnSave_Click(object sender, EventArgs e) { pageContents = new ContentPage(SiteID, ContentPageType.PageType.ContentEntry); DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); int iOrder = pageHelper.GetMaxNavOrder(SiteID) + 1; Guid?parentContentID = ParentPagePicker.SelectedPage; pageContents.Parent_ContentID = parentContentID; pageContents.TitleBar = txtTitle.Text; pageContents.NavMenuText = txtNav.Text; pageContents.PageHead = txtHead.Text; pageContents.FileName = txtFileName.Text; pageContents.MetaDescription = txtDescription.Text; pageContents.MetaKeyword = txtKey.Text; pageContents.Heartbeat_UserId = SecurityData.CurrentUserGuid; pageContents.EditHeartbeat = dtSite.AddMinutes(5); pageContents.EditUserId = SecurityData.CurrentUserGuid; pageContents.IsLatestVersion = true; pageContents.EditDate = SiteData.CurrentSite.Now; pageContents.NavOrder = iOrder; pageContents.PageActive = false; pageContents.ShowInSiteMap = true; pageContents.ShowInSiteNav = true; pageContents.ContentType = ContentPageType.PageType.ContentEntry; pageContents.GoLiveDate = dtSite; pageContents.RetireDate = dtSite.AddYears(200); pageContents.SavePageEdit(); pnlAdd.Visible = false; pnlSaved.Visible = true; litPageName.Text = pageContents.FileName; lnkNew.NavigateUrl = pageContents.FileName; if (pageContents.FileName.ToLowerInvariant().EndsWith(SiteData.DefaultDirectoryFilename)) { VirtualDirectory.RegisterRoutes(true); } Master.ShowSave(); }
protected void btnSave_Click(object sender, EventArgs e) { SiteData site = siteHelper.GetCurrentSite(); string sDatePatternOld = "yy-MM-dd"; string sTimezoneOld = "ZZZ"; if (site == null) { site = new SiteData(); site.SiteID = SiteID; } if (site != null) { sDatePatternOld = site.Blog_DatePattern; sTimezoneOld = site.TimeZoneIdentifier; site.SiteName = txtSiteName.Text; site.SiteTagline = txtTagline.Text; site.SiteTitlebarPattern = txtTitleBar.Text; site.MainURL = txtURL.Text; site.MetaKeyword = txtKey.Text; site.MetaDescription = txtDescription.Text; site.BlockIndex = chkHide.Checked; site.SendTrackbacks = chkSendTrackback.Checked; site.AcceptTrackbacks = chkAcceptTrackbacks.Checked; site.TimeZoneIdentifier = ddlTimeZone.SelectedValue; site.Blog_FolderPath = txtFolderPath.Text; site.Blog_CategoryPath = txtCategoryPath.Text; site.Blog_DatePath = txtDatePath.Text; site.Blog_TagPath = txtTagPath.Text; site.Blog_EditorPath = txtEditorPath.Text; site.Blog_DatePattern = ddlDatePattern.SelectedValue; site.Blog_Root_ContentID = ParentPagePicker.SelectedPage; } site.Save(); if (sDatePatternOld != ddlDatePattern.SelectedValue || sTimezoneOld != ddlTimeZone.SelectedValue) { using (ContentPageHelper cph = new ContentPageHelper()) { cph.BulkBlogFileNameUpdateFromDate(SiteID); } } if (!bNewSite) { Response.Redirect(SiteData.CurrentScriptName); } else { DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); if (chkHomepage.Checked) { ContentPage pageContents = new ContentPage { SiteID = SiteID, Root_ContentID = Guid.NewGuid(), ContentID = Guid.NewGuid(), EditDate = SiteData.CurrentSite.Now, CreateUserId = SecurityData.CurrentUserGuid, CreateDate = SiteData.CurrentSite.Now, GoLiveDate = dtSite.AddMinutes(-5), RetireDate = dtSite.AddYears(200), TitleBar = "Home", NavMenuText = "Home", PageHead = "Home", FileName = "/home.aspx", PageText = SiteData.StarterHomePageSample, LeftPageText = String.Empty, RightPageText = String.Empty, NavOrder = 0, IsLatestVersion = true, PageActive = true, ShowInSiteNav = true, ShowInSiteMap = true, BlockIndex = false, EditUserId = SecurityData.CurrentUserGuid, ContentType = ContentPageType.PageType.ContentEntry, TemplateFile = SiteData.DefaultTemplateFilename }; pageContents.SavePageEdit(); } Response.Redirect(SiteFilename.DashboardURL); } }
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(); }
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); }
protected void Page_Load(object sender, EventArgs e) { Master.ActivateTab(AdminBaseMasterPage.SectionID.ContentSnippet); guidRootItemID = GetGuidIDFromQuery(); guidVersionItemID = GetGuidParameterFromQuery("versionid"); guidItemID = guidRootItemID; if (guidItemID == Guid.Empty) { guidItemID = guidVersionItemID; } if (!IsPostBack) { DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); ucReleaseDate.SetDate(dtSite); ucRetireDate.SetDate(dtSite.AddYears(200)); ContentSnippet item = null; if (guidRootItemID != Guid.Empty) { item = ContentSnippet.Get(guidRootItemID); } else { item = ContentSnippet.GetVersion(guidVersionItemID); } if (item != null) { bool bRet = item.RecordSnippetLock(SecurityData.CurrentUserGuid); bLocked = item.IsSnippetLocked(); if (bLocked && item.Heartbeat_UserId != null) { MembershipUser usr = SecurityData.GetUserByGuid(item.Heartbeat_UserId.Value); litUser.Text = "Read only mode. User '" + usr.UserName + "' is currently editing the snippet."; } txtSlug.Text = item.ContentSnippetSlug; txtLabel.Text = item.ContentSnippetName; reBody.Text = item.ContentBody; guidRootItemID = item.Root_ContentSnippetID; ucReleaseDate.SetDate(item.GoLiveDate); ucRetireDate.SetDate(item.RetireDate); chkPublic.Checked = item.ContentSnippetActive; btnDeleteButton.Visible = true; pnlReview.Visible = true; Dictionary <string, string> dataVersions = (from v in ContentSnippet.GetHistory(guidRootItemID) join u in ExtendedUserData.GetUserList() on v.EditUserId equals u.UserId orderby v.EditDate descending select new KeyValuePair <string, string>(v.ContentSnippetID.ToString(), string.Format("{0} ({1}) {2}", v.EditDate, u.UserName, (v.IsLatestVersion ? " [**] " : " "))) ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); GeneralUtilities.BindListDefaultText(ddlVersions, dataVersions, null, "Versions", "00000"); } else { btnDeleteButton.Visible = false; pnlReview.Visible = false; } } sPageMode = GetStringParameterFromQuery("mode"); if (sPageMode.ToLowerInvariant() == "raw") { reBody.CssClass = "rawEditor"; divCenter.Visible = false; } pnlHB.Visible = !bLocked; pnlHBEmpty.Visible = bLocked; pnlButtons.Visible = !bLocked; divEditing.Visible = bLocked; }
protected void Page_Load(object sender, EventArgs e) { Master.ActivateTab(AdminBaseMasterPage.SectionID.BlogContentAdd); RedirectIfNoSite(); lblUpdated.Text = SiteData.CurrentSite.Now.ToString(); lblCreateDate.Text = SiteData.CurrentSite.Now.ToString(); guidContentID = GetGuidIDFromQuery(); guidVersionContentID = GetGuidParameterFromQuery("versionid"); guidImportContentID = GetGuidParameterFromQuery("importid"); sPageMode = GetStringParameterFromQuery("mode"); if (sPageMode.ToLowerInvariant() == "raw") { reBody.CssClass = "rawEditor"; reLeftBody.CssClass = "rawEditor"; reRightBody.CssClass = "rawEditor"; divCenter.Visible = false; divRight.Visible = false; divLeft.Visible = false; } if (!IsPostBack) { DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); ucReleaseDate.SetDate(dtSite); ucRetireDate.SetDate(dtSite.AddYears(200)); hdnRootID.Value = Guid.Empty.ToString(); GeneralUtilities.BindList(listCats, SiteData.CurrentSite.GetCategoryList().OrderBy(x => x.CategoryText)); GeneralUtilities.BindList(listTags, SiteData.CurrentSite.GetTagList().OrderBy(x => x.TagText)); ContentPage pageContents = null; if (guidVersionContentID != Guid.Empty) { pageContents = pageHelper.GetVersion(SiteID, guidVersionContentID); } if (guidContentID != Guid.Empty && pageContents == null) { pageContents = pageHelper.FindContentByID(SiteID, guidContentID); } if (guidImportContentID != Guid.Empty) { ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID); if (cpe != null) { pageContents = cpe.ThePage; pageContents.EditDate = SiteData.CurrentSite.Now; pageContents.Parent_ContentID = null; } var rp = pageHelper.GetLatestContentByURL(SiteID, false, pageContents.FileName); if (rp != null) { pageContents.Root_ContentID = rp.Root_ContentID; pageContents.ContentID = rp.ContentID; } else { pageContents.Root_ContentID = Guid.Empty; pageContents.ContentID = Guid.Empty; } pageContents.Parent_ContentID = null; pageContents.NavOrder = SiteData.BlogSortOrderNumber; } //if (pageContents == null) { // pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry); //} List <ContentPage> lstContent = pageHelper.GetAllLatestContentList(SiteID); GeneralUtilities.BindList(ddlTemplate, cmsHelper.Templates); chkDraft.Visible = false; divEditing.Visible = false; Dictionary <string, float> dictTemplates = pageHelper.GetPopularTemplateList(SiteID, ContentPageType.PageType.BlogEntry); if (dictTemplates.Any()) { try { GeneralUtilities.SelectListValue(ddlTemplate, dictTemplates.First().Key); } catch { } } if (pageContents == null) { btnDeleteButton.Visible = false; } if (pageContents != null) { bool bRet = pageHelper.RecordPageLock(pageContents.Root_ContentID, SiteData.CurrentSite.SiteID, SecurityData.CurrentUserGuid); if (pageContents.ContentType != ContentPageType.PageType.BlogEntry) { Response.Redirect(SiteFilename.PageAddEditURL + "?id=" + Request.QueryString.ToString()); } cmsHelper.OverrideKey(pageContents.Root_ContentID); cmsHelper.cmsAdminContent = pageContents; cmsHelper.cmsAdminWidget = pageContents.GetWidgetList(); BindTextDataGrid(); guidRootContentID = pageContents.Root_ContentID; hdnRootID.Value = guidRootContentID.ToString(); txtOldFile.Text = pageContents.FileName; if (guidImportContentID != Guid.Empty) { txtOldFile.Text = ""; } Dictionary <string, string> dataVersions = (from v in pageHelper.GetVersionHistory(SiteID, pageContents.Root_ContentID) join u in ExtendedUserData.GetUserList() on v.EditUserId equals u.UserId orderby v.EditDate descending select new KeyValuePair <string, string>(v.ContentID.ToString(), string.Format("{0} ({1}) {2}", v.EditDate, u.UserName, (v.IsLatestVersion ? " [**] " : " "))) ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); GeneralUtilities.BindListDefaultText(ddlVersions, dataVersions, null, "Page Versions", "00000"); bLocked = pageHelper.IsPageLocked(pageContents); pnlHB.Visible = !bLocked; pnlButtons.Visible = !bLocked; divEditing.Visible = bLocked; chkDraft.Visible = !bLocked; pnlHBEmpty.Visible = bLocked; if (bLocked && pageContents.Heartbeat_UserId != null) { MembershipUser usr = SecurityData.GetUserByGuid(pageContents.Heartbeat_UserId.Value); litUser.Text = "Read only mode. User '" + usr.UserName + "' is currently editing the page."; } txtTitle.Text = pageContents.TitleBar; txtNav.Text = pageContents.NavMenuText; txtHead.Text = pageContents.PageHead; txtPageSlug.Text = pageContents.PageSlug; txtThumb.Text = pageContents.Thumbnail; txtDescription.Text = pageContents.MetaDescription; txtKey.Text = pageContents.MetaKeyword; lblUpdated.Text = pageContents.EditDate.ToString(); lblCreateDate.Text = pageContents.CreateDate.ToString(); reBody.Text = pageContents.PageText; reLeftBody.Text = pageContents.LeftPageText; reRightBody.Text = pageContents.RightPageText; chkActive.Checked = pageContents.PageActive; chkHide.Checked = pageContents.BlockIndex; GeneralUtilities.BindDataBoundControl(gvTracks, pageContents.GetTrackbacks()); ucReleaseDate.SetDate(pageContents.GoLiveDate); ucRetireDate.SetDate(pageContents.RetireDate); if (pageContents.CreditUserId.HasValue) { var usr = new ExtendedUserData(pageContents.CreditUserId.Value); hdnCreditUserID.Value = usr.UserName; txtSearchUser.Text = string.Format("{0} ({1})", usr.UserName, usr.EmailAddress); } pageContents.Parent_ContentID = null; GeneralUtilities.SelectListValue(ddlTemplate, pageContents.TemplateFile.ToLowerInvariant()); GeneralUtilities.SelectListValues(listTags, pageContents.ContentTags.Cast <IContentMetaInfo>().Select(x => x.ContentMetaInfoID.ToString()).ToList()); GeneralUtilities.SelectListValues(listCats, pageContents.ContentCategories.Cast <IContentMetaInfo>().Select(x => x.ContentMetaInfoID.ToString()).ToList()); } } SetBlankText(reBody); SetBlankText(reLeftBody); SetBlankText(reRightBody); if (ddlVersions.Items.Count < 1) { pnlReview.Visible = false; } }
protected void SavePage(bool bRedirect) { ContentPage pageContents = null; if (guidVersionContentID != Guid.Empty) { pageContents = pageHelper.GetVersion(SiteID, guidVersionContentID); } if (guidContentID != Guid.Empty && pageContents == null) { pageContents = pageHelper.FindContentByID(SiteID, guidContentID); } if (guidImportContentID != Guid.Empty) { pageContents = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID).ThePage; if (pageContents != null) { pageContents.SiteID = SiteID; pageContents.EditDate = SiteData.CurrentSite.Now; pageContents.CreateUserId = SecurityData.CurrentUserGuid; pageContents.CreateDate = SiteData.CurrentSite.Now; var rp = pageHelper.GetLatestContentByURL(SiteID, false, pageContents.FileName); if (rp != null) { pageContents.Root_ContentID = rp.Root_ContentID; pageContents.ContentID = rp.ContentID; } else { pageContents.Root_ContentID = Guid.Empty; pageContents.ContentID = Guid.Empty; } pageContents.Parent_ContentID = null; pageContents.NavOrder = SiteData.BlogSortOrderNumber; } } if (pageContents == null) { pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry); } DateTime dtSite = CMSConfigHelper.CalcNearestFiveMinTime(SiteData.CurrentSite.Now); pageContents.GoLiveDate = dtSite.AddMinutes(-5); pageContents.RetireDate = dtSite.AddYears(200); pageContents.IsLatestVersion = true; pageContents.Thumbnail = txtThumb.Text; pageContents.TemplateFile = ddlTemplate.SelectedValue; pageContents.TitleBar = txtTitle.Text; pageContents.NavMenuText = txtNav.Text; pageContents.PageHead = txtHead.Text; pageContents.PageSlug = txtPageSlug.Text; pageContents.MetaDescription = txtDescription.Text; pageContents.MetaKeyword = txtKey.Text; pageContents.EditDate = SiteData.CurrentSite.Now; pageContents.NavOrder = SiteData.BlogSortOrderNumber; pageContents.PageText = reBody.Text; pageContents.LeftPageText = reLeftBody.Text; pageContents.RightPageText = reRightBody.Text; pageContents.PageActive = chkActive.Checked; pageContents.ShowInSiteNav = false; pageContents.ShowInSiteMap = false; pageContents.BlockIndex = chkHide.Checked; pageContents.ContentType = ContentPageType.PageType.BlogEntry; pageContents.Parent_ContentID = null; if (String.IsNullOrEmpty(hdnCreditUserID.Value)) { pageContents.CreditUserId = null; } else { var usr = new ExtendedUserData(hdnCreditUserID.Value); pageContents.CreditUserId = usr.UserId; } pageContents.GoLiveDate = ucReleaseDate.GetDate(); pageContents.RetireDate = ucRetireDate.GetDate(); pageContents.EditUserId = SecurityData.CurrentUserGuid; pageContents.NewTrackBackURLs = txtTrackback.Text; List <ContentCategory> lstCat = new List <ContentCategory>(); List <ContentTag> lstTag = new List <ContentTag>(); lstCat = (from cr in GeneralUtilities.GetSelectedValues(listCats).Select(x => new Guid(x)) join l in SiteData.CurrentSite.GetCategoryList() on cr equals l.ContentCategoryID select l).ToList(); lstTag = (from cr in GeneralUtilities.GetSelectedValues(listTags).Select(x => new Guid(x)) join l in SiteData.CurrentSite.GetTagList() on cr equals l.ContentTagID select l).ToList(); pageContents.ContentCategories = lstCat; pageContents.ContentTags = lstTag; if (!chkDraft.Checked) { pageContents.SavePageEdit(); } else { pageContents.SavePageAsDraft(); } //if importing, copy in all meta data possible if (guidImportContentID != Guid.Empty) { List <Widget> widgets = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID).ThePageWidgets; foreach (var wd in widgets) { wd.Root_ContentID = pageContents.Root_ContentID; wd.Root_WidgetID = Guid.NewGuid(); wd.WidgetDataID = Guid.NewGuid(); wd.IsPendingChange = true; wd.EditDate = SiteData.CurrentSite.Now; wd.Save(); } ContentImportExportUtils.RemoveSerializedExportData(guidImportContentID); } cmsHelper.OverrideKey(pageContents.Root_ContentID); if (cmsHelper.cmsAdminWidget != null) { var ww = (from w in cmsHelper.cmsAdminWidget where w.IsLatestVersion == true && w.IsPendingChange == true && (w.ControlPath.StartsWith("CLASS:Carrotware.CMS.UI.Controls.ContentRichText,") || w.ControlPath.StartsWith("CLASS:Carrotware.CMS.UI.Controls.ContentPlainText,")) select w); foreach (Widget w in ww) { w.Save(); } } cmsHelper.cmsAdminContent = null; cmsHelper.cmsAdminWidget = null; if (pageContents.FileName.ToLowerInvariant().EndsWith(SiteData.DefaultDirectoryFilename)) { VirtualDirectory.RegisterRoutes(true); } if (!bRedirect) { if (sPageMode.Length < 1) { Response.Redirect(SiteData.CurrentScriptName + "?id=" + pageContents.Root_ContentID.ToString()); } else { Response.Redirect(SiteData.CurrentScriptName + "?mode=raw&id=" + pageContents.Root_ContentID.ToString()); } } else { Response.Redirect(pageContents.FileName); } }