public SiteImportNativeModel()
        {
            this.CreateUsers = true;
            this.MapUsers = true;
            this.HasLoaded = false;

            using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                this.PageCount = pageHelper.GetSitePageCount(SiteData.CurrentSiteID, ContentPageType.PageType.ContentEntry);

                using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
                    this.Templates = cmsHelper.Templates;

                    float iThird = (float)(this.PageCount - 1) / (float)3;
                    Dictionary<string, float> dictTemplates = null;

                    dictTemplates = pageHelper.GetPopularTemplateList(SiteData.CurrentSiteID, ContentPageType.PageType.ContentEntry);
                    if (dictTemplates.Count > 0 && dictTemplates.First().Value >= iThird) {
                        try { this.PageTemplate = dictTemplates.First().Key; } catch { }
                    }

                    dictTemplates = pageHelper.GetPopularTemplateList(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry);
                    if (dictTemplates.Count > 0) {
                        try { this.PostTemplate = dictTemplates.First().Key; } catch { }
                    }
                }
            }
        }
		public void SetVersion(Guid id) {
			this.VersionID = id;

			using (ContentPageHelper pageHelper = new ContentPageHelper()) {
				this.ContentPage = pageHelper.GetVersion(this.SiteID, id);
				this.Root_ContentID = this.ContentPage.Root_ContentID;
			}
		}
		public void SearchTwo() {
			this.Widgets = null;
			this.Pages = null;

			using (ContentPageHelper pageHelper = new ContentPageHelper()) {
				this.SelectedPage = pageHelper.FindContentByID(SiteData.CurrentSiteID, this.SelectedItem);
				this.Widgets = this.SelectedPage.GetWidgetList();
			}
		}
Пример #4
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            guidRootContentID = new Guid(hdnRootID.Value);

            using (ContentPageHelper cph = new ContentPageHelper()) {
                cph.RemoveContent(SiteID, guidRootContentID);
            }

            Response.Redirect(SiteFilename.PageIndexURL);
        }
		public void SetCurrent(Guid id) {
			this.Root_ContentID = id;

			using (ContentPageHelper pageHelper = new ContentPageHelper()) {
				this.ContentPage = pageHelper.FindContentByID(this.SiteID, id);

				this.History.DataSource = pageHelper.GetVersionHistory(this.SiteID, id);
				this.History.TotalRecords = this.History.DataSource.Count();
				this.History.PageSize = this.History.TotalRecords * 2;
			}
		}
Пример #6
0
		public ContentPage GetContentPage() {
			ContentPage cp = null;
			if (SiteData.IsPageSampler) {
				cp = ContentPageHelper.GetSamplerView();
			} else {
				using (ContentPageHelper cph = new ContentPageHelper()) {
					cp = cph.FindContentByID(this.SiteID, this.Root_ContentID);
				}
			}
			return cp;
		}
		public ContentPageExport(Guid siteID, Guid rootContentID) {
			ContentPage cp = null;

			using (ContentPageHelper cph = new ContentPageHelper()) {
				cp = cph.FindContentByID(siteID, rootContentID);
			}

			List<Widget> widgets = cp.GetWidgetList();

			SetVals(cp, widgets);
		}
Пример #8
0
		public void Load() {
			this.TheSite = SiteData.CurrentSite;

			if (SecurityData.AdvancedEditMode && !this.IsPageLocked) {
				using (ContentPageHelper pageHelper = new ContentPageHelper()) {
					bool bRet = pageHelper.RecordPageLock(this.ThePage.Root_ContentID, this.TheSite.SiteID, SecurityData.CurrentUserGuid);
				}
			}

			CMSConfigHelper.IdentifyLinkAsInactive(this.ThePage);
			Guid guidContentID = Guid.Empty;

			if (this.ThePage != null) {
				guidContentID = this.ThePage.Root_ContentID;
				this.TheWidgets = SiteData.GetCurrentPageWidgets(guidContentID);
			} else {
				this.ThePage = new ContentPage();
				this.TheWidgets = new List<Widget>();
			}
		}
Пример #9
0
		private void LoadHeadCaption() {
			if (this.TheSite.Blog_Root_ContentID == this.ThePage.Root_ContentID
				&& _headingText == null && this.TypeLabelPrefixes.Any()) {
				_headingText = String.Empty;
				using (ContentPageHelper pageHelper = new ContentPageHelper()) {
					PageViewType pvt = pageHelper.GetBlogHeadingFromURL(this.TheSite, SiteData.CurrentScriptName);
					_headingText = pvt.ExtraTitle;

					TypeHeadingOption titleOpts = this.TypeLabelPrefixes.Where(x => x.KeyValue == pvt.CurrentViewType).FirstOrDefault();

					if (titleOpts == null
						&& (pvt.CurrentViewType == PageViewType.ViewType.DateDayIndex
						|| pvt.CurrentViewType == PageViewType.ViewType.DateMonthIndex
						|| pvt.CurrentViewType == PageViewType.ViewType.DateYearIndex)) {
						titleOpts = this.TypeLabelPrefixes.Where(x => x.KeyValue == PageViewType.ViewType.DateIndex).FirstOrDefault();
					}

					if (titleOpts != null) {
						if (!String.IsNullOrEmpty(titleOpts.FormatText)) {
							pvt.ExtraTitle = string.Format(titleOpts.FormatText, pvt.RawValue);
							_headingText = pvt.ExtraTitle;
						}
						if (!String.IsNullOrEmpty(titleOpts.LabelText)) {
							this.ThePage.PageHead = String.Format("{0} {1}", titleOpts.LabelText, _headingText);
							this.ThePage.TitleBar = this.ThePage.PageHead;
							_headingText = this.ThePage.PageHead;
						}
					}
				}
			}
		}
        public ContentPage SavePost()
        {
            ContentPage page = this.ContentPage;
            ContentPage pageContents = null;

            using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                pageContents = pageHelper.FindContentByID(SiteData.CurrentSiteID, page.Root_ContentID);
            }
            if (pageContents == null) {
                pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry);
            }

            pageContents.GoLiveDate = page.GoLiveDate;
            pageContents.RetireDate = page.RetireDate;

            pageContents.IsLatestVersion = true;
            pageContents.Thumbnail = page.Thumbnail;

            pageContents.TemplateFile = page.TemplateFile;

            pageContents.TitleBar = page.TitleBar;
            pageContents.NavMenuText = page.NavMenuText;
            pageContents.PageHead = page.PageHead;
            pageContents.FileName = page.FileName;
            pageContents.PageSlug = page.PageSlug;

            pageContents.MetaDescription = page.MetaDescription;
            pageContents.MetaKeyword = page.MetaKeyword;

            pageContents.EditDate = SiteData.CurrentSite.Now;
            pageContents.NavOrder = SiteData.BlogSortOrderNumber;

            pageContents.PageText = page.PageText;
            pageContents.LeftPageText = page.LeftPageText;
            pageContents.RightPageText = page.RightPageText;

            pageContents.PageActive = page.PageActive;
            pageContents.ShowInSiteNav = false;
            pageContents.ShowInSiteMap = false;
            pageContents.BlockIndex = page.BlockIndex;

            pageContents.Parent_ContentID = page.Parent_ContentID;

            pageContents.CreditUserId = page.CreditUserId;

            pageContents.EditUserId = SecurityData.CurrentUserGuid;

            List<ContentCategory> lstCat = (from l in SiteData.CurrentSite.GetCategoryList()
                                            join cr in this.SelectedCategories on l.ContentCategoryID.ToString().ToLowerInvariant() equals cr.ToLowerInvariant()
                                            select l).ToList();
            List<ContentTag> lstTag = (from l in SiteData.CurrentSite.GetTagList()
                                       join cr in this.SelectedTags on l.ContentTagID.ToString().ToLowerInvariant() equals cr.ToLowerInvariant()
                                       select l).ToList();

            pageContents.ContentCategories = lstCat;
            pageContents.ContentTags = lstTag;

            pageContents.SavePageEdit();
            SaveTextWidgets();

            return pageContents;
        }
		public void Save() {
			this.CopyCount = 0;
			if (this.Widgets != null) {
				List<Guid> lstSel = this.Widgets.Where(x => x.Selected).Select(x => x.Root_WidgetID).ToList();

				using (ContentPageHelper pageHelper = new ContentPageHelper()) {
					this.SelectedPage = pageHelper.FindContentByID(SiteData.CurrentSiteID, this.SelectedItem);
					this.Widgets = this.SelectedPage.GetWidgetList();
				}

				using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
					cmsHelper.OverrideKey(this.Root_ContentID);

					if (cmsHelper.cmsAdminWidget != null) {
						List<Widget> cacheWidget = cmsHelper.cmsAdminWidget;

						List<Widget> ww = (from w in this.SelectedPage.GetWidgetList()
										   where lstSel.Contains(w.Root_WidgetID) && w.IsLatestVersion == true
										   select w).ToList();

						if (ww != null) {
							this.CopyCount = ww.Count;

							foreach (var w in ww) {
								Guid newWidget = Guid.NewGuid();

								Widget wCpy = new Widget {
									Root_ContentID = this.Root_ContentID,
									Root_WidgetID = newWidget,
									WidgetDataID = Guid.NewGuid(),
									PlaceholderName = this.PlaceholderName,
									ControlPath = w.ControlPath,
									ControlProperties = w.ControlProperties,
									IsLatestVersion = true,
									IsPendingChange = true,
									IsWidgetActive = true,
									IsWidgetPendingDelete = false,
									WidgetOrder = w.WidgetOrder,
									GoLiveDate = w.GoLiveDate,
									RetireDate = w.RetireDate,
									EditDate = SiteData.CurrentSite.Now
								};

								cacheWidget.Add(wCpy);
							}
						}

						cmsHelper.cmsAdminWidget = cacheWidget;
					}
				}
			}
		}
        public void ImportStuff()
        {
            this.HasLoaded = false;
            this.Site = ContentImportExportUtils.GetSerializedSiteExport(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.TheTags.RemoveAll(x => tags.Contains(x.TagSlug.ToLower()));
                this.Site.TheCategories.RemoveAll(x => cats.Contains(x.CategorySlug.ToLower()));

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

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

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

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

            if (this.ImportSnippets) {
                List<string> snippets = site.GetContentSnippetList().Select(x => x.ContentSnippetSlug.ToLower()).ToList();

                this.Site.TheSnippets.RemoveAll(x => snippets.Contains(x.ContentSnippetSlug.ToLower()));

                sMsg += "<li>Imported Content Snippets</li>";

                List<ContentSnippet> lstSnip = (from l in this.Site.TheSnippets.Distinct()
                                                select new ContentSnippet {
                                                    SiteID = site.SiteID,
                                                    Root_ContentSnippetID = Guid.NewGuid(),
                                                    ContentSnippetID = Guid.NewGuid(),
                                                    CreateUserId = SecurityData.CurrentUserGuid,
                                                    CreateDate = site.Now,
                                                    EditUserId = SecurityData.CurrentUserGuid,
                                                    EditDate = site.Now,
                                                    RetireDate = l.RetireDate,
                                                    GoLiveDate = l.GoLiveDate,
                                                    ContentSnippetActive = l.ContentSnippetActive,
                                                    ContentBody = l.ContentBody,
                                                    ContentSnippetSlug = l.ContentSnippetSlug,
                                                    ContentSnippetName = l.ContentSnippetName
                                                }).ToList();

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

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

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

            //iterate author collection and find if in the system
            foreach (SiteExportUser seu in this.Site.TheUsers) {
                SecurityData sd = new SecurityData();

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

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

                if (this.CreateUsers) {
                    if (seu.ImportUserID == Guid.Empty) {
                        ApplicationUser user = new ApplicationUser { UserName = seu.Login, Email = seu.Email };
                        var result = sd.CreateApplicationUser(user, out usr);
                        if (result.Succeeded) {
                            usr = ExtendedUserData.FindByUsername(seu.Login);
                        }
                        seu.ImportUserID = usr.UserId;
                    }

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

            if (this.ImportPages) {
                sMsg += "<li>Imported Pages</li>";
                this.Content = site.GetFullSiteFileList();

                int iOrder = 0;

                SiteNav navHome = GetHomePage(site);

                if (navHome != null) {
                    iOrder = 2;
                }

                foreach (var impCP in (from c in this.Site.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                       orderby c.ThePage.NavOrder, c.ThePage.NavMenuText
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.ContentType = ContentPageType.PageType.ContentEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = this.Site.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = this.Site.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = this.Site.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = iOrder;
                    cp.TemplateFile = this.PageTemplate;

                    ContentPageExport parent = (from c in this.Site.ThePages
                                                where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                                  && c.ThePage.FileName.ToLower() == impCP.ParentFileName.ToLower()
                                                select c).FirstOrDefault();

                    BasicContentData navParent = null;
                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

                    if (parent != null) {
                        cp.Parent_ContentID = parent.NewRootContentID;
                        navParent = GetFileInfoFromList(site, parent.ThePage.FileName);
                    }

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

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;

                        if (navData.NavOrder == 0) {
                            cp.NavOrder = 0;
                        }
                    }
                    //preserve homepage
                    if (navHome != null && navHome.FileName.ToLower() == cp.FileName.ToLower()) {
                        cp.NavOrder = 0;
                    }
                    //if the file url in the upload has an existing ID, use that, not the ID from the queue
                    if (navParent != null) {
                        cp.Parent_ContentID = navParent.Root_ContentID;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();

                    iOrder++;
                }
            }
            SetMsg(sMsg);

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

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

                foreach (var impCP in (from c in this.Site.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.BlogEntry
                                       orderby c.ThePage.CreateDate
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.Parent_ContentID = null;
                    cp.ContentType = ContentPageType.PageType.BlogEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = this.Site.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = this.Site.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = this.Site.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = SiteData.BlogSortOrderNumber;
                    cp.TemplateFile = this.PostTemplate;

                    cp.ContentCategories = (from l in lstCategories
                                            join o in impCP.ThePage.ContentCategories on l.CategorySlug.ToLower() equals o.CategorySlug.ToLower()
                                            select l).Distinct().ToList();

                    cp.ContentTags = (from l in lstTags
                                      join o in impCP.ThePage.ContentTags on l.TagSlug.ToLower() equals o.TagSlug.ToLower()
                                      select l).Distinct().ToList();

                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

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

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();
                }

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

            if (this.ImportComments) {
                sMsg += "<li>Imported Comments</li>";
                this.Content = site.GetFullSiteFileList();

                foreach (var impCP in (from c in this.Site.TheComments
                                       orderby c.TheComment.CreateDate
                                       select c).ToList()) {
                    int iCommentCount = -1;
                    PostComment pc = impCP.TheComment;
                    BasicContentData navData = GetFileInfoFromList(site, pc.FileName);
                    if (navData != null) {
                        pc.Root_ContentID = navData.Root_ContentID;
                        pc.ContentCommentID = Guid.NewGuid();

                        iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP, pc.PostCommentText);
                        if (iCommentCount < 1) {
                            iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP);
                        }

                        if (iCommentCount < 1) {
                            pc.Save();
                        }
                    }
                }
            }

            SetMsg(sMsg);
        }
Пример #13
0
		public bool IsUniqueBlog() {
			DateTime dateGoLive = Convert.ToDateTime(this.GoLiveDate);
			DateTime dateOrigGoLive = DateTime.MinValue;

			string thePageSlug = ContentPageHelper.ScrubFilename(this.Root_ContentID, this.PageSlug).ToLower();

			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;
		}
Пример #14
0
        public static ContentPage GetCurrentLivePage()
        {
            ContentPage pageContents = null;

            using (ContentPageHelper pageHelper = new ContentPageHelper()) {

                bool IsPageTemplate = false;
                string sCurrentPage = SiteData.CurrentScriptName;
                string sScrubbedURL = SiteData.AlternateCurrentScriptName;

                if (sScrubbedURL.ToLower() != sCurrentPage.ToLower()) {
                    sCurrentPage = sScrubbedURL;
                }

                if (SecurityData.IsAdmin || SecurityData.IsSiteEditor) {
                    pageContents = pageHelper.FindByFilename(SiteData.CurrentSiteID, sCurrentPage);
                } else {
                    pageContents = pageHelper.GetLatestContentByURL(SiteData.CurrentSiteID, true, sCurrentPage);
                }

                if (pageContents == null && SiteData.IsPageReal) {
                    IsPageTemplate = true;
                }

                if ((SiteData.IsPageSampler || IsPageTemplate || !IsWebView) && pageContents == null) {
                    pageContents = ContentPageHelper.GetSamplerView();
                }

                if (IsPageTemplate) {
                    pageContents.TemplateFile = sCurrentPage;
                }
            }

            return pageContents;
        }
Пример #15
0
        public static ContentPage GetPage(string sCurrentPage)
        {
            ContentPage pageContents = null;

            using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                if (SecurityData.IsAdmin || SecurityData.IsSiteEditor) {
                    if (sCurrentPage.Length <= 1 || sCurrentPage == SiteData.DefaultDirectoryFilename) {
                        pageContents = pageHelper.FindHome(SiteData.CurrentSiteID);
                    } else {
                        pageContents = pageHelper.FindByFilename(SiteData.CurrentSiteID, sCurrentPage);
                    }
                } else {
                    if (sCurrentPage.Length <= 1 || sCurrentPage == SiteData.DefaultDirectoryFilename) {
                        pageContents = pageHelper.FindHome(SiteData.CurrentSiteID, true);
                    } else {
                        pageContents = pageHelper.GetLatestContentByURL(SiteData.CurrentSiteID, true, sCurrentPage);
                    }
                }
            }

            return pageContents;
        }
Пример #16
0
 public void OverrideKey(string sPageName)
 {
     filePage = null;
     using (ContentPageHelper pageHelper = new ContentPageHelper()) {
         filePage = pageHelper.FindByFilename(SiteData.CurrentSiteID, sPageName);
     }
 }
Пример #17
0
 protected void LoadGuids()
 {
     if (filePage == null) {
         using (ContentPageHelper pageHelper = new ContentPageHelper()) {
             if (SiteData.IsPageSampler && filePage == null) {
                 filePage = ContentPageHelper.GetSamplerView();
             } else {
                 if (SiteData.CurrentScriptName.ToLower().StartsWith(SiteData.AdminFolderPath)) {
                     Guid guidPage = Guid.Empty;
                     if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["pageid"])) {
                         guidPage = new Guid(HttpContext.Current.Request.QueryString["pageid"].ToString());
                     }
                     filePage = pageHelper.FindContentByID(SiteData.CurrentSiteID, guidPage);
                 } else {
                     filePage = pageHelper.FindByFilename(SiteData.CurrentSiteID, SiteData.CurrentScriptName);
                 }
             }
         }
     }
 }
Пример #18
0
 public void OverrideKey(Guid guidContentID)
 {
     filePage = null;
     using (ContentPageHelper pageHelper = new ContentPageHelper()) {
         filePage = pageHelper.FindContentByID(SiteData.CurrentSiteID, guidContentID);
     }
 }
Пример #19
0
        public void LoadPageControls()
        {
            this.CurrentWebPage.Header.Controls.Add(new Literal { Text = "\r\n" });

            List<HtmlMeta> lstMD = GetHtmlMeta(this.CurrentWebPage.Header);

            HtmlMeta metaGenerator = new HtmlMeta();
            metaGenerator.Name = "generator";
            metaGenerator.Content = SiteData.CarrotCakeCMSVersion;
            this.CurrentWebPage.Header.Controls.Add(metaGenerator);
            this.CurrentWebPage.Header.Controls.Add(new Literal { Text = "\r\n" });

            if (guidContentID == SiteData.CurrentSiteID && SiteData.IsPageReal) {
                IsPageTemplate = true;
            }

            if (theSite != null && pageContents != null) {
                if (theSite.BlockIndex || pageContents.BlockIndex) {
                    bool bCrawlExist = false;
                    HtmlMeta metaNoCrawl = new HtmlMeta();
                    metaNoCrawl.Name = "robots";

                    if (lstMD.Where(x => x.Name == "robots").Count() > 0) {
                        metaNoCrawl = lstMD.Where(x => x.Name == "robots").FirstOrDefault();
                        bCrawlExist = true;
                    }

                    metaNoCrawl.Content = "noindex,nofollow,noarchive";

                    if (!bCrawlExist) {
                        this.CurrentWebPage.Header.Controls.Add(metaNoCrawl);
                        this.CurrentWebPage.Header.Controls.Add(new Literal { Text = "\r\n" });
                    }
                }
            }

            if (pageContents != null) {
                HtmlMeta metaDesc = new HtmlMeta();
                HtmlMeta metaKey = new HtmlMeta();
                bool bDescExist = false;
                bool bKeyExist = false;

                if (lstMD.Where(x => x.Name == "description").Count() > 0) {
                    metaDesc = lstMD.Where(x => x.Name == "description").FirstOrDefault();
                    bDescExist = true;
                }
                if (lstMD.Where(x => x.Name == "keywords").Count() > 0) {
                    metaKey = lstMD.Where(x => x.Name == "keywords").FirstOrDefault();
                    bKeyExist = true;
                }

                metaDesc.Name = "description";
                metaKey.Name = "keywords";
                metaDesc.Content = string.IsNullOrEmpty(pageContents.MetaDescription) ? theSite.MetaDescription : pageContents.MetaDescription;
                metaKey.Content = string.IsNullOrEmpty(pageContents.MetaKeyword) ? theSite.MetaKeyword : pageContents.MetaKeyword;

                int indexPos = 6;
                if (this.CurrentWebPage.Header.Controls.Count > indexPos) {
                    if (!string.IsNullOrEmpty(metaDesc.Content) && !bDescExist) {
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, new Literal { Text = "\r\n" });
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, metaDesc);
                    }
                    if (!string.IsNullOrEmpty(metaKey.Content) && !bKeyExist) {
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, new Literal { Text = "\r\n" });
                        this.CurrentWebPage.Header.Controls.AddAt(indexPos, metaKey);
                    }
                } else {
                    if (!string.IsNullOrEmpty(metaDesc.Content) && !bDescExist) {
                        this.CurrentWebPage.Header.Controls.Add(metaDesc);
                        this.CurrentWebPage.Header.Controls.Add(new Literal { Text = "\r\n" });
                    }
                    if (!string.IsNullOrEmpty(metaKey.Content) && !bKeyExist) {
                        this.CurrentWebPage.Header.Controls.Add(metaKey);
                        this.CurrentWebPage.Header.Controls.Add(new Literal { Text = "\r\n" });
                    }
                }

                metaDesc.Visible = !string.IsNullOrEmpty(metaDesc.Content);
                metaKey.Visible = !string.IsNullOrEmpty(metaKey.Content);
            }

            contCenter = new ContentContainer();
            contLeft = new ContentContainer();
            contRight = new ContentContainer();

            if (pageContents != null) {

                using (ContentPageHelper pageHelper = new ContentPageHelper()) {

                    PageViewType pvt = pageHelper.GetBlogHeadingFromURL(theSite, SiteData.CurrentScriptName);
                    string sTitleAddendum = pvt.ExtraTitle;

                    if (!string.IsNullOrEmpty(sTitleAddendum)) {
                        if (!string.IsNullOrEmpty(pageContents.PageHead)) {
                            pageContents.PageHead = pageContents.PageHead.Trim() + ": " + sTitleAddendum;
                        } else {
                            pageContents.PageHead = sTitleAddendum;
                        }
                        pageContents.TitleBar = pageContents.TitleBar.Trim() + ": " + sTitleAddendum;
                    }

                    PagedDataSummary pd = (PagedDataSummary)cu.FindControl(typeof(PagedDataSummary), this.CurrentWebPage);

                    if (pd != null) {
                        PagedDataSummaryTitleOption titleOpts = pd.TypeLabelPrefixes.Where(x => x.KeyValue == pvt.CurrentViewType).FirstOrDefault();

                        if (titleOpts == null
                            && (pvt.CurrentViewType == PageViewType.ViewType.DateDayIndex
                            || pvt.CurrentViewType == PageViewType.ViewType.DateMonthIndex
                            || pvt.CurrentViewType == PageViewType.ViewType.DateYearIndex)) {

                            titleOpts = pd.TypeLabelPrefixes.Where(x => x.KeyValue == PageViewType.ViewType.DateIndex).FirstOrDefault();
                        }

                        if (titleOpts != null && !string.IsNullOrEmpty(titleOpts.FormatText)) {
                            pvt.ExtraTitle = string.Format(titleOpts.FormatText, pvt.RawValue);
                            sTitleAddendum = pvt.ExtraTitle;
                        }

                        if (titleOpts != null && !string.IsNullOrEmpty(titleOpts.LabelText)) {
                            pageContents.PageHead = titleOpts.LabelText + " " + sTitleAddendum;
                            pageContents.NavMenuText = pageContents.PageHead;
                            pageContents.TitleBar = pageContents.PageHead;
                        }
                    }
                }

                this.CurrentWebPage.Title = SetPageTitle(pageContents);

                DateTime dtModified = theSite.ConvertSiteTimeToLocalServer(pageContents.EditDate);
                string strModifed = dtModified.ToString("r");
                HttpContext.Current.Response.AppendHeader("Last-Modified", strModifed);
                HttpContext.Current.Response.Cache.SetLastModified(dtModified);

                DateTime dtExpire = DateTime.Now.AddSeconds(15);

                contCenter.Text = pageContents.PageText;
                contLeft.Text = pageContents.LeftPageText;
                contRight.Text = pageContents.RightPageText;

                contCenter.DatabaseKey = pageContents.Root_ContentID;
                contLeft.DatabaseKey = pageContents.Root_ContentID;
                contRight.DatabaseKey = pageContents.Root_ContentID;

                pageContents = CMSConfigHelper.IdentifyLinkAsInactive(pageContents);

                if (this.CurrentWebPage.User.Identity.IsAuthenticated) {

                    HttpContext.Current.Response.Cache.SetNoServerCaching();
                    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    dtExpire = DateTime.Now.AddMinutes(-10);
                    HttpContext.Current.Response.Cache.SetExpires(dtExpire);

                    if (!SecurityData.AdvancedEditMode) {

                        if (SecurityData.IsAdmin || SecurityData.IsSiteEditor) {
                            if (!SiteData.IsPageSampler && !IsPageTemplate) {
                                Control editor = this.CurrentWebPage.LoadControl(SiteFilename.EditNotifierControlPath);
                                this.CurrentWebPage.Form.Controls.Add(editor);
                            }
                        }

                    } else {

                        contCenter.IsAdminMode = true;
                        contLeft.IsAdminMode = true;
                        contRight.IsAdminMode = true;

                        contCenter.ZoneChar = "c";
                        contLeft.ZoneChar = "l";
                        contRight.ZoneChar = "r";

                        contCenter.TextZone = ContentContainer.TextFieldZone.TextCenter;
                        contLeft.TextZone = ContentContainer.TextFieldZone.TextLeft;
                        contRight.TextZone = ContentContainer.TextFieldZone.TextRight;

                        contCenter.Text = pageContents.PageText;
                        contLeft.Text = pageContents.LeftPageText;
                        contRight.Text = pageContents.RightPageText;

                        Control editor = this.CurrentWebPage.LoadControl(SiteFilename.AdvancedEditControlPath);
                        this.CurrentWebPage.Form.Controls.Add(editor);

                        MarkWidgets(this.CurrentWebPage, true);
                    }
                } else {
                    HttpContext.Current.Response.Cache.SetExpires(dtExpire);
                }

                if (pageWidgets.Count > 0) {
                    CMSConfigHelper cmsHelper = new CMSConfigHelper();

                    //find each placeholder in use ONCE!
                    List<LabeledControl> lstPlaceholders = (from ph in pageWidgets
                                                            where ph.Root_ContentID == pageContents.Root_ContentID
                                                            select new LabeledControl {
                                                                ControlLabel = ph.PlaceholderName,
                                                                KeyControl = FindTheControl(ph.PlaceholderName, this.CurrentWebPage)
                                                            }).Distinct().ToList();

                    List<Widget> lstWidget = null;

                    if (SecurityData.AdvancedEditMode) {
                        lstWidget = (from w in pageWidgets
                                     orderby w.WidgetOrder, w.EditDate
                                     where w.Root_ContentID == pageContents.Root_ContentID
                                       && w.IsWidgetActive == true
                                       && w.IsWidgetPendingDelete == false
                                     select w).ToList();
                    } else {
                        lstWidget = (from w in pageWidgets
                                     orderby w.WidgetOrder, w.EditDate
                                     where w.Root_ContentID == pageContents.Root_ContentID
                                       && w.IsWidgetActive == true
                                       && w.IsRetired == false && w.IsUnReleased == false
                                       && w.IsWidgetPendingDelete == false
                                     select w).ToList();
                    }

                    Assembly a = Assembly.GetExecutingAssembly();

                    foreach (Widget theWidget in lstWidget) {

                        WidgetContainer plcHolder = (WidgetContainer)(from d in lstPlaceholders
                                                                      where d.ControlLabel == theWidget.PlaceholderName
                                                                      select d.KeyControl).FirstOrDefault();
                        if (plcHolder != null) {
                            plcHolder.EnableViewState = true;
                            Control widget = new Control();

                            if (theWidget.ControlPath.EndsWith(".ascx")) {
                                if (File.Exists(this.CurrentWebPage.Server.MapPath(theWidget.ControlPath))) {
                                    try {
                                        widget = this.CurrentWebPage.LoadControl(theWidget.ControlPath);
                                    } catch (Exception ex) {
                                        Literal lit = new Literal();
                                        lit.Text = "<b>ERROR: " + theWidget.ControlPath + "</b> <br />\r\n" + ex.ToString();
                                        widget = lit;
                                    }
                                } else {
                                    Literal lit = new Literal();
                                    lit.Text = "MISSING FILE: " + theWidget.ControlPath + "<br />\r\n";
                                    widget = lit;
                                }
                            }

                            if (theWidget.ControlPath.ToLower().StartsWith("class:")) {
                                try {
                                    string className = theWidget.ControlPath.Replace("CLASS:", "");
                                    Type t = Type.GetType(className);
                                    Object o = Activator.CreateInstance(t);

                                    if (o != null) {
                                        widget = o as Control;
                                    } else {
                                        Literal lit = new Literal();
                                        lit.Text = "OOPS: " + theWidget.ControlPath + "<br />\r\n";
                                        widget = lit;
                                    }
                                } catch (Exception ex) {
                                    Literal lit = new Literal();
                                    lit.Text = "<b>ERROR: " + theWidget.ControlPath + "</b> <br />\r\n" + ex.ToString();
                                    widget = lit;
                                }
                            }

                            widget.EnableViewState = true;

                            IWidget w = null;
                            if (widget is IWidget) {
                                w = widget as IWidget;
                                w.SiteID = SiteData.CurrentSiteID;
                                w.PageWidgetID = theWidget.Root_WidgetID;
                                w.RootContentID = theWidget.Root_ContentID;
                            }

                            if (widget is IWidgetParmData) {
                                IWidgetParmData wp = widget as IWidgetParmData;
                                List<WidgetProps> lstProp = theWidget.ParseDefaultControlProperties();

                                wp.PublicParmValues = lstProp.ToDictionary(t => t.KeyName, t => t.KeyValue);
                            }

                            if (widget is IWidgetRawData) {
                                IWidgetRawData wp = widget as IWidgetRawData;
                                wp.RawWidgetData = theWidget.ControlProperties;
                            }

                            if (widget is IWidgetEditStatus) {
                                IWidgetEditStatus wes = widget as IWidgetEditStatus;
                                wes.IsBeingEdited = SecurityData.AdvancedEditMode;
                            }

                            Dictionary<string, string> lstMenus = new Dictionary<string, string>();
                            if (widget is IWidgetMultiMenu) {
                                IWidgetMultiMenu wmm = widget as IWidgetMultiMenu;
                                lstMenus = wmm.JSEditFunctions;
                            }

                            if (SecurityData.AdvancedEditMode) {

                                WidgetWrapper plcWrapper = plcHolder.AddWidget(widget, theWidget);

                                CMSPlugin plug = (from p in cmsHelper.ToolboxPlugins
                                                  where p.FilePath.ToLower() == plcWrapper.ControlPath.ToLower()
                                                  select p).FirstOrDefault();

                                if (plug != null) {
                                    plcWrapper.ControlTitle = plug.Caption;
                                }

                                plcWrapper.ID = WrapCtrlId;

                                if (w != null) {
                                    if (w.EnableEdit) {
                                        if (lstMenus.Count < 1) {
                                            string sScript = w.JSEditFunction;
                                            if (string.IsNullOrEmpty(sScript)) {
                                                sScript = "cmsGenericEdit('" + pageContents.Root_ContentID + "','" + plcWrapper.DatabaseKey + "')";
                                            }

                                            plcWrapper.JSEditFunction = sScript;
                                        } else {
                                            plcWrapper.JSEditFunctions = lstMenus;
                                        }
                                    }
                                }
                            } else {
                                plcHolder.AddWidget(widget);
                            }

                            widget.ID = CtrlId;

                        }
                    }

                    cmsHelper.Dispose();
                }
            }
        }
Пример #20
0
        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 = 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);
            }
        }
        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.ToLowerInvariant()).ToList();
                List<string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLowerInvariant()).ToList();

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

                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 && usr.UserId != Guid.Empty) {
                    wpu.ImportUserID = usr.UserId;
                } else {
                    usr = ExtendedUserData.FindByUsername(wpu.Login);
                    if (usr != null && usr.UserId != Guid.Empty) {
                        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{2}", 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.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();

                        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.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();

                        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.ToLowerInvariant() == "trash") {
                        pc.IsSpam = true;
                    }
                    if (wpc.Type.ToLowerInvariant() == "trackback" || wpc.Type.ToLowerInvariant() == "pingback") {
                        pc.CommenterEmail = wpc.Type;
                    }

                    pc.Save();
                }
            }
            SetMsg(sMsg);
        }
		private void SetVals(ContentPage cp, List<Widget> widgets) {
			CarrotCakeVersion = SiteData.CarrotCakeCMSVersion;
			ExportDate = DateTime.UtcNow;
			Guid siteID = cp.SiteID;

			NewRootContentID = Guid.NewGuid();

			cp.LoadAttributes();

			ThePage = cp;
			ThePageWidgets = widgets;

			if (ThePage == null) {
				ThePage = new ContentPage();
				ThePage.Root_ContentID = Guid.NewGuid();
				ThePage.ContentID = ThePage.Root_ContentID;
			}
			if (ThePageWidgets == null) {
				ThePageWidgets = new List<Widget>();
			}

			OriginalRootContentID = ThePage.Root_ContentID;
			OriginalSiteID = ThePage.SiteID;
			OriginalParentContentID = Guid.Empty;
			ParentFileName = "";

			if (ThePage.Parent_ContentID != null) {
				ContentPage parent = new ContentPage();
				using (ContentPageHelper cph = new ContentPageHelper()) {
					parent = cph.FindContentByID(siteID, ThePage.Parent_ContentID.Value);
				}
				ParentFileName = parent.FileName;
				OriginalParentContentID = parent.Root_ContentID;
			}

			ThePage.Root_ContentID = NewRootContentID;
			ThePage.ContentID = NewRootContentID;

			foreach (var w in ThePageWidgets) {
				w.Root_ContentID = NewRootContentID;
				w.Root_WidgetID = Guid.NewGuid();
				w.WidgetDataID = Guid.NewGuid();
			}

			Guid userID1 = Guid.Empty;

			if (!cp.EditUserId.HasValue) {
				userID1 = cp.CreateUserId;
			} else {
				userID1 = cp.EditUserId.Value;
			}

			ExtendedUserData u1 = new ExtendedUserData(userID1);
			this.TheUser = new SiteExportUser(u1);

			Guid userID2 = Guid.Empty;

			if (cp.CreditUserId.HasValue) {
				userID2 = cp.CreditUserId.Value;
			}

			ExtendedUserData u2 = new ExtendedUserData(userID2);
			if (u2 != null) {
				this.CreditUser = new SiteExportUser(u2);
			} else {
				this.CreditUser = null;
			}
		}
Пример #23
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.ToLower()).ToList();
                List<string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLower()).ToList();

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

                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 (!string.IsNullOrEmpty(wpu.FirstName) || !string.IsNullOrEmpty(wpu.LastName)) {
                            ud.FirstName = wpu.FirstName;
                            ud.LastName = wpu.LastName;
                            ud.Save();
                        }
                    }
                }
            }

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

            using (SiteNavHelper navHelper = new SiteNavHelper()) {
                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.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 = CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = 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.ToLower());

                        cp.RetireDate = CalcNearestFiveMinTime(cp.CreateDate).AddYears(200);
                        cp.GoLiveDate = 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.ToLower() == "trash") {
                        pc.IsSpam = true;
                    }
                    if (wpc.Type.ToLower() == "trackback" || wpc.Type.ToLower() == "pingback") {
                        pc.CommenterEmail = wpc.Type;
                    }

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

            BindData();
        }
Пример #24
0
		public bool IsUniqueFilename() {
			string theFileName = this.FileName;

			theFileName = ContentPageHelper.ScrubFilename(this.Root_ContentID, theFileName);

			theFileName = theFileName.ToLower();

			if (SiteData.IsPageSpecial(theFileName) || SiteData.IsLikelyHomePage(theFileName)) {
				return false;
			}

			if (SiteData.CurrentSite.GetSpecialFilePathPrefixes().Where(x => theFileName.StartsWith(x.ToLower())).Count() > 0
				|| theFileName.StartsWith(SiteData.CurrentSite.BlogFolderPath.ToLower())) {
				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;
		}
Пример #25
0
        protected bool FoldersAreValid()
        {
            string sFolderPath = this.Blog_FolderPath ?? String.Empty;

            if (SiteData.CurretSiteExists) {
                using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                    var exists = pageHelper.ExistingPagesBeginWith(this);

                    return !exists;
                }
            } else {
                return true;
            }

            return false;
        }
Пример #26
0
		private void LoadGuids() {
			using (ContentPageHelper pageHelper = new ContentPageHelper()) {
				if (!String.IsNullOrEmpty(CurrentEditPage)) {
					filePage = pageHelper.FindByFilename(SiteData.CurrentSite.SiteID, CurrentEditPage);
					if (filePage != null) {
						CurrentPageGuid = filePage.Root_ContentID;
					}
				} else {
					if (CurrentPageGuid != Guid.Empty) {
						filePage = pageHelper.FindContentByID(SiteData.CurrentSite.SiteID, CurrentPageGuid);
						if (filePage != null) {
							CurrentEditPage = filePage.FileName;
						}
					} else {
						filePage = new ContentPage();
					}
				}
			}
		}
		public ActionResult DeleteContentPage(ContentPageModel model) {
			using (ContentPageHelper cph = new ContentPageHelper()) {
				cph.RemoveContent(this.SiteID, model.ContentPage.Root_ContentID);
			}

			if (model.ContentPage.ContentType == ContentPageType.PageType.BlogEntry) {
				return RedirectToAction("BlogPostIndex");
			}

			return RedirectToAction("PageIndex");
		}
Пример #28
0
 public static ContentPage GetPage(Guid guidContentID)
 {
     ContentPage pageContents = null;
     using (ContentPageHelper pageHelper = new ContentPageHelper()) {
         pageContents = pageHelper.FindContentByID(CurrentSiteID, guidContentID);
     }
     return pageContents;
 }
Пример #29
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.ToLower()).ToList();
                List<string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLower()).ToList();

                exSite.TheTags.RemoveAll(x => tags.Contains(x.TagSlug.ToLower()));
                exSite.TheCategories.RemoveAll(x => cats.Contains(x.CategorySlug.ToLower()));

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

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

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

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

            if (chkSnippet.Checked) {
                List<string> snippets = site.GetContentSnippetList().Select(x => x.ContentSnippetSlug.ToLower()).ToList();

                exSite.TheSnippets.RemoveAll(x => snippets.Contains(x.ContentSnippetSlug.ToLower()));

                sMsg += "<p>Imported Content Snippets</p>";

                List<ContentSnippet> lstSnip = (from l in exSite.TheSnippets.Distinct()
                                                select new ContentSnippet {
                                                    SiteID = site.SiteID,
                                                    Root_ContentSnippetID = Guid.NewGuid(),
                                                    ContentSnippetID = Guid.NewGuid(),
                                                    CreateUserId = SecurityData.CurrentUserGuid,
                                                    CreateDate = site.Now,
                                                    EditUserId = SecurityData.CurrentUserGuid,
                                                    EditDate = site.Now,
                                                    RetireDate = l.RetireDate,
                                                    GoLiveDate = l.GoLiveDate,
                                                    ContentSnippetActive = l.ContentSnippetActive,
                                                    ContentBody = l.ContentBody,
                                                    ContentSnippetSlug = l.ContentSnippetSlug,
                                                    ContentSnippetName = l.ContentSnippetName
                                                }).ToList();

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

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

            if (!chkMapAuthor.Checked) {
                exSite.TheUsers = new List<SiteExportUser>();
            }

            //itterate author collection and find if in the system
            foreach (SiteExportUser seu in exSite.TheUsers) {
                seu.ImportUserID = Guid.Empty;

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

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

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

            if (chkPages.Checked) {
                sMsg += "<p>Imported Pages</p>";
                sitePageList = site.GetFullSiteFileList();

                int iOrder = 0;

                SiteNav navHome = GetHomePage(site);

                if (navHome != null) {
                    iOrder = 2;
                }

                foreach (var impCP in (from c in exSite.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                       orderby c.ThePage.NavOrder, c.ThePage.NavMenuText
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.ContentType = ContentPageType.PageType.ContentEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = exSite.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = exSite.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = exSite.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = iOrder;
                    cp.TemplateFile = ddlTemplatePage.SelectedValue;

                    ContentPageExport parent = (from c in exSite.ThePages
                                                where c.ThePage.ContentType == ContentPageType.PageType.ContentEntry
                                                  && c.ThePage.FileName.ToLower() == impCP.ParentFileName.ToLower()
                                                select c).FirstOrDefault();

                    BasicContentData navParent = null;
                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

                    if (parent != null) {
                        cp.Parent_ContentID = parent.NewRootContentID;
                        navParent = GetFileInfoFromList(site, parent.ThePage.FileName);
                    }

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

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;

                        if (navData.NavOrder == 0) {
                            cp.NavOrder = 0;
                        }
                    }
                    //preserve homepage
                    if (navHome != null && navHome.FileName.ToLower() == cp.FileName.ToLower()) {
                        cp.NavOrder = 0;
                    }
                    //if the file url in the upload has an existing ID, use that, not the ID from the queue
                    if (navParent != null) {
                        cp.Parent_ContentID = navParent.Root_ContentID;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();

                    iOrder++;
                }
            }
            SetMsg(sMsg);

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

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

                foreach (var impCP in (from c in exSite.ThePages
                                       where c.ThePage.ContentType == ContentPageType.PageType.BlogEntry
                                       orderby c.ThePage.CreateDate
                                       select c).ToList()) {
                    ContentPage cp = impCP.ThePage;
                    cp.Root_ContentID = impCP.NewRootContentID;
                    cp.ContentID = Guid.NewGuid();
                    cp.SiteID = site.SiteID;
                    cp.Parent_ContentID = null;
                    cp.ContentType = ContentPageType.PageType.BlogEntry;
                    cp.EditDate = SiteData.CurrentSite.Now;
                    cp.EditUserId = exSite.FindImportUser(impCP.TheUser);
                    cp.CreateUserId = exSite.FindImportUser(impCP.TheUser);
                    if (impCP.CreditUser != null) {
                        cp.CreditUserId = exSite.FindImportUser(impCP.CreditUser);
                    }
                    cp.NavOrder = SiteData.BlogSortOrderNumber;
                    cp.TemplateFile = ddlTemplatePost.SelectedValue;

                    cp.ContentCategories = (from l in lstCategories
                                            join o in impCP.ThePage.ContentCategories on l.CategorySlug.ToLower() equals o.CategorySlug.ToLower()
                                            select l).Distinct().ToList();

                    cp.ContentTags = (from l in lstTags
                                      join o in impCP.ThePage.ContentTags on l.TagSlug.ToLower() equals o.TagSlug.ToLower()
                                      select l).Distinct().ToList();

                    BasicContentData navData = GetFileInfoFromList(site, cp.FileName);

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

                        impCP.ThePage.RetireDate = navData.RetireDate;
                        impCP.ThePage.GoLiveDate = navData.GoLiveDate;
                    }

                    cp.RetireDate = impCP.ThePage.RetireDate;
                    cp.GoLiveDate = impCP.ThePage.GoLiveDate;

                    cp.SavePageEdit();
                }

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

            if (chkComments.Checked) {
                sMsg += "<p>Imported Comments</p>";
                sitePageList = site.GetFullSiteFileList();

                foreach (var impCP in (from c in exSite.TheComments
                                       orderby c.TheComment.CreateDate
                                       select c).ToList()) {
                    int iCommentCount = -1;
                    PostComment pc = impCP.TheComment;
                    BasicContentData navData = GetFileInfoFromList(site, pc.FileName);
                    if (navData != null) {
                        pc.Root_ContentID = navData.Root_ContentID;
                        pc.ContentCommentID = Guid.NewGuid();

                        iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP, pc.PostCommentText);
                        if (iCommentCount < 1) {
                            iCommentCount = PostComment.GetCommentCountByContent(site.SiteID, pc.Root_ContentID, pc.CreateDate, pc.CommenterIP);
                        }

                        if (iCommentCount < 1) {
                            pc.Save();
                        }
                    }
                }
            }
            SetMsg(sMsg);

            BindData();
        }
Пример #30
0
        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) + 1;
                        } 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 { }
                        }
                    }
                }
            }
        }