示例#1
0
        public ContentPage GetPost(Guid?id, Guid?versionid, Guid?importid, string mode)
        {
            ContentPage pageContents = null;

            this.ImportID  = importid;
            this.VersionID = versionid;
            this.Mode      = (String.IsNullOrEmpty(mode) || mode.Trim().ToLowerInvariant() != "raw") ? "html" : "raw";

            using (ContentPageHelper pageHelper = new ContentPageHelper()) {
                if (!id.HasValue && !versionid.HasValue && !importid.HasValue)
                {
                    if (pageContents == null)
                    {
                        pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry);
                    }

                    pageContents.Root_ContentID = Guid.Empty;
                }
                else
                {
                    if (importid.HasValue)
                    {
                        ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(importid.Value);
                        if (cpe != null)
                        {
                            pageContents          = cpe.ThePage;
                            pageContents.EditDate = SiteData.CurrentSite.Now;

                            var rp = pageHelper.GetLatestContentByURL(SiteData.CurrentSiteID, false, pageContents.FileName);
                            if (rp != null)
                            {
                                pageContents.Root_ContentID = rp.Root_ContentID;
                                pageContents.ContentID      = rp.ContentID;
                            }
                            else
                            {
                                pageContents.Root_ContentID = Guid.Empty;
                                pageContents.ContentID      = Guid.Empty;
                            }
                            pageContents.Parent_ContentID = null;
                            pageContents.NavOrder         = SiteData.BlogSortOrderNumber;
                        }
                    }
                    if (versionid.HasValue)
                    {
                        pageContents = pageHelper.GetVersion(SiteData.CurrentSiteID, versionid.Value);
                    }
                    if (id.HasValue && pageContents == null)
                    {
                        pageContents = pageHelper.FindContentByID(SiteData.CurrentSiteID, id.Value);
                    }
                }
            }

            OverrideCache(pageContents);

            SetPage(pageContents);

            return(pageContents);
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Master.ActivateTab(AdminBaseMasterPage.SectionID.BlogContentAdd);

            RedirectIfNoSite();

            lblUpdated.Text    = SiteData.CurrentSite.Now.ToString();
            lblCreateDate.Text = SiteData.CurrentSite.Now.ToString();

            guidContentID        = GetGuidIDFromQuery();
            guidVersionContentID = GetGuidParameterFromQuery("versionid");
            guidImportContentID  = GetGuidParameterFromQuery("importid");

            sPageMode = GetStringParameterFromQuery("mode");
            if (sPageMode.ToLower() == "raw")
            {
                reBody.CssClass      = "rawEditor";
                reLeftBody.CssClass  = "rawEditor";
                reRightBody.CssClass = "rawEditor";
                divCenter.Visible    = false;
                divRight.Visible     = false;
                divLeft.Visible      = false;
            }

            if (!IsPostBack)
            {
                DateTime dtSite = CalcNearestFiveMinTime(SiteData.CurrentSite.Now);
                txtReleaseDate.Text = dtSite.ToShortDateString();
                txtReleaseTime.Text = dtSite.ToShortTimeString();
                txtRetireDate.Text  = dtSite.AddYears(200).ToShortDateString();
                txtRetireTime.Text  = dtSite.AddYears(200).ToShortTimeString();

                hdnRootID.Value = Guid.Empty.ToString();

                GeneralUtilities.BindList(listCats, SiteData.CurrentSite.GetCategoryList().OrderBy(x => x.CategoryText));
                GeneralUtilities.BindList(listTags, SiteData.CurrentSite.GetTagList().OrderBy(x => x.TagText));

                ContentPage pageContents = null;
                if (guidVersionContentID != Guid.Empty)
                {
                    pageContents = pageHelper.GetVersion(SiteID, guidVersionContentID);
                }
                if (guidContentID != Guid.Empty && pageContents == null)
                {
                    pageContents = pageHelper.FindContentByID(SiteID, guidContentID);
                }

                if (guidImportContentID != Guid.Empty)
                {
                    ContentPageExport cpe = ContentImportExportUtils.GetSerializedContentPageExport(guidImportContentID);

                    if (cpe != null)
                    {
                        pageContents                  = cpe.ThePage;
                        pageContents.EditDate         = SiteData.CurrentSite.Now;
                        pageContents.Parent_ContentID = null;
                    }

                    var rp = pageHelper.GetLatestContentByURL(SiteID, false, pageContents.FileName);
                    if (rp != null)
                    {
                        pageContents.Root_ContentID = rp.Root_ContentID;
                        pageContents.ContentID      = rp.ContentID;
                    }
                    else
                    {
                        pageContents.Root_ContentID = Guid.Empty;
                        pageContents.ContentID      = Guid.Empty;
                    }
                    pageContents.Parent_ContentID = null;
                    pageContents.NavOrder         = SiteData.BlogSortOrderNumber;
                }

                //if (pageContents == null) {
                //    pageContents = new ContentPage(SiteData.CurrentSiteID, ContentPageType.PageType.BlogEntry);
                //}

                List <ContentPage> lstContent = pageHelper.GetAllLatestContentList(SiteID);

                GeneralUtilities.BindList(ddlTemplate, cmsHelper.Templates);

                chkDraft.Visible   = false;
                divEditing.Visible = false;

                Dictionary <string, float> dictTemplates = pageHelper.GetPopularTemplateList(SiteID, ContentPageType.PageType.BlogEntry);
                if (dictTemplates.Any())
                {
                    try {
                        GeneralUtilities.SelectListValue(ddlTemplate, dictTemplates.First().Key);
                    } catch { }
                }

                if (pageContents == null)
                {
                    btnDeleteButton.Visible = false;
                }

                if (pageContents != null)
                {
                    bool bRet = pageHelper.RecordPageLock(pageContents.Root_ContentID, SiteData.CurrentSite.SiteID, SecurityData.CurrentUserGuid);

                    if (pageContents.ContentType != ContentPageType.PageType.BlogEntry)
                    {
                        Response.Redirect(SiteFilename.PageAddEditURL + "?id=" + Request.QueryString.ToString());
                    }

                    cmsHelper.OverrideKey(pageContents.Root_ContentID);
                    cmsHelper.cmsAdminContent = pageContents;
                    cmsHelper.cmsAdminWidget  = pageContents.GetWidgetList();

                    BindTextDataGrid();

                    guidRootContentID = pageContents.Root_ContentID;
                    hdnRootID.Value   = guidRootContentID.ToString();

                    txtOldFile.Text = pageContents.FileName;

                    if (guidImportContentID != Guid.Empty)
                    {
                        txtOldFile.Text = "";
                    }

                    Dictionary <string, string> dataVersions = (from v in pageHelper.GetVersionHistory(SiteID, pageContents.Root_ContentID)
                                                                join u in ExtendedUserData.GetUserList() on v.EditUserId equals u.UserId
                                                                orderby v.EditDate descending
                                                                select new KeyValuePair <string, string>(v.ContentID.ToString(), string.Format("{0} ({1}) {2}", v.EditDate, u.UserName, (v.IsLatestVersion ? " [**] " : " ")))
                                                                ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                    GeneralUtilities.BindListDefaultText(ddlVersions, dataVersions, null, "Page Versions", "00000");

                    bLocked = pageHelper.IsPageLocked(pageContents);

                    pnlHB.Visible      = !bLocked;
                    pnlButtons.Visible = !bLocked;
                    divEditing.Visible = bLocked;
                    chkDraft.Visible   = !bLocked;
                    pnlHBEmpty.Visible = bLocked;

                    if (bLocked && pageContents.Heartbeat_UserId != null)
                    {
                        MembershipUser usr = SecurityData.GetUserByGuid(pageContents.Heartbeat_UserId.Value);
                        litUser.Text = "Read only mode. User '" + usr.UserName + "' is currently editing the page.";
                    }

                    txtTitle.Text    = pageContents.TitleBar;
                    txtNav.Text      = pageContents.NavMenuText;
                    txtHead.Text     = pageContents.PageHead;
                    txtPageSlug.Text = pageContents.PageSlug;
                    txtThumb.Text    = pageContents.Thumbnail;

                    txtDescription.Text = pageContents.MetaDescription;
                    txtKey.Text         = pageContents.MetaKeyword;

                    lblUpdated.Text    = pageContents.EditDate.ToString();
                    lblCreateDate.Text = pageContents.CreateDate.ToString();

                    reBody.Text      = pageContents.PageText;
                    reLeftBody.Text  = pageContents.LeftPageText;
                    reRightBody.Text = pageContents.RightPageText;

                    chkActive.Checked = pageContents.PageActive;
                    chkHide.Checked   = pageContents.BlockIndex;

                    GeneralUtilities.BindDataBoundControl(gvTracks, pageContents.GetTrackbacks());

                    txtReleaseDate.Text = pageContents.GoLiveDate.ToShortDateString();
                    txtReleaseTime.Text = pageContents.GoLiveDate.ToShortTimeString();
                    txtRetireDate.Text  = pageContents.RetireDate.ToShortDateString();
                    txtRetireTime.Text  = pageContents.RetireDate.ToShortTimeString();

                    if (pageContents.CreditUserId.HasValue)
                    {
                        var usr = new ExtendedUserData(pageContents.CreditUserId.Value);
                        hdnCreditUserID.Value = usr.UserName;
                        txtSearchUser.Text    = string.Format("{0} ({1})", usr.UserName, usr.EmailAddress);
                    }

                    pageContents.Parent_ContentID = null;

                    GeneralUtilities.SelectListValue(ddlTemplate, pageContents.TemplateFile.ToLower());

                    GeneralUtilities.SelectListValues(listTags, pageContents.ContentTags.Cast <IContentMetaInfo>().Select(x => x.ContentMetaInfoID.ToString()).ToList());
                    GeneralUtilities.SelectListValues(listCats, pageContents.ContentCategories.Cast <IContentMetaInfo>().Select(x => x.ContentMetaInfoID.ToString()).ToList());
                }
            }

            SetBlankText(reBody);
            SetBlankText(reLeftBody);
            SetBlankText(reRightBody);

            if (ddlVersions.Items.Count < 1)
            {
                pnlReview.Visible = false;
            }
        }
示例#3
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 (ud != null)
                        {
                            if (!String.IsNullOrEmpty(seu.FirstName) || !String.IsNullOrEmpty(seu.LastName))
                            {
                                ud.FirstName = seu.FirstName;
                                ud.LastName  = seu.LastName;
                                ud.Save();
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format("Could not find new user: {0} ({1})", seu.Login, seu.Email));
                        }
                    }
                }
            }

            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();
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            guidContentID = GetGuidIDFromQuery();

            guidNodeID = GetGuidParameterFromQuery("node");

            if (!String.IsNullOrEmpty(Request.QueryString["comment"]))
            {
                bExportComments = true;
            }

            if (!String.IsNullOrEmpty(Request.QueryString["datebegin"]))
            {
                dateBegin = Convert.ToDateTime(Request.QueryString["datebegin"].ToString()).Date;
            }
            if (!String.IsNullOrEmpty(Request.QueryString["dateend"]))
            {
                dateEnd = Convert.ToDateTime(Request.QueryString["dateend"].ToString()).Date;
            }
            if (!String.IsNullOrEmpty(Request.QueryString["exportwhat"]))
            {
                ExportWhat = (SiteExport.ExportType)Enum.Parse(typeof(SiteExport.ExportType), Request.QueryString["exportwhat"].ToString(), true);;
            }

            string theXML   = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
            string fileName = "export.xml";

            if (guidContentID != Guid.Empty)
            {
                ContentPageExport content = ContentImportExportUtils.GetExportPage(SiteData.CurrentSiteID, guidContentID);
                theXML = ContentImportExportUtils.GetExportXML <ContentPageExport>(content);

                fileName = "page_" + content.ThePage.NavMenuText + "_" + guidContentID.ToString();
            }
            else
            {
                SiteExport site = ContentImportExportUtils.GetExportSite(SiteData.CurrentSiteID, ExportWhat);

                site.ThePages.RemoveAll(x => x.ThePage.GoLiveDate < dateBegin);
                site.ThePages.RemoveAll(x => x.ThePage.GoLiveDate > dateEnd);

                if (guidNodeID != Guid.Empty)
                {
                    List <Guid> lst = pageHelper.GetPageHierarchy(SiteData.CurrentSiteID, guidNodeID);
                    site.ThePages.RemoveAll(x => !lst.Contains(x.OriginalRootContentID) && x.ThePage.ContentType == ContentPageType.PageType.ContentEntry);
                }

                if (ExportWhat == SiteExport.ExportType.BlogData)
                {
                    site.ThePages.RemoveAll(x => x.ThePage.ContentType == ContentPageType.PageType.ContentEntry);
                }
                if (ExportWhat == SiteExport.ExportType.ContentData)
                {
                    site.ThePages.RemoveAll(x => x.ThePage.ContentType == ContentPageType.PageType.BlogEntry);
                }

                if (bExportComments)
                {
                    site.LoadComments();
                }

                theXML = ContentImportExportUtils.GetExportXML <SiteExport>(site);

                fileName = "site_" + site.TheSite.SiteName + "_" + site.TheSite.SiteID.ToString();
            }

            fileName = fileName + "-" + SiteData.CurrentSite.Now.ToString("yyyy-MM-dd") + ".xml";

            fileName = fileName.Replace(" ", "_");

            Response.Expires     = 5;
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));

            Response.Write(theXML);

            Response.StatusCode        = 200;
            Response.StatusDescription = "OK";
            Response.End();
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string sXML = "";

            if (upFile.HasFile)
            {
                using (StreamReader sr = new StreamReader(upFile.FileContent)) {
                    sXML = sr.ReadToEnd();
                }
            }
            string sTest = "";

            if (!String.IsNullOrEmpty(sXML) && sXML.Length > 500)
            {
                sTest = sXML.Substring(0, 250).ToLower();

                try {
                    if (sTest.Contains("<contentpageexport xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\">"))
                    {
                        ContentPageExport cph = ContentImportExportUtils.DeserializeContentPageExport(sXML);
                        ContentImportExportUtils.AssignContentPageExportNewIDs(cph);
                        ContentImportExportUtils.SaveSerializedDataExport <ContentPageExport>(cph.NewRootContentID, cph);

                        if (cph.ThePage.ContentType == ContentPageType.PageType.ContentEntry)
                        {
                            Response.Redirect(SiteFilename.PageAddEditURL + "?importid=" + cph.NewRootContentID.ToString());
                        }
                        else
                        {
                            Response.Redirect(SiteFilename.BlogPostAddEditURL + "?importid=" + cph.NewRootContentID.ToString());
                        }
                    }

                    if (sTest.Contains("<siteexport xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\">"))
                    {
                        SiteExport site = ContentImportExportUtils.DeserializeSiteExport(sXML);
                        ContentImportExportUtils.AssignSiteExportNewIDs(site);
                        ContentImportExportUtils.SaveSerializedDataExport <SiteExport>(site.NewSiteID, site);

                        Response.Redirect(SiteFilename.SiteImportURL + "?importid=" + site.NewSiteID.ToString());
                    }

                    if (sXML.Contains("<channel>") && sXML.Contains("<rss"))
                    {
                        int iChnl = sXML.IndexOf("<channel>");
                        sTest = sXML.Substring(0, iChnl).ToLower();
                    }

                    if (sTest.Contains("<!-- this is a wordpress extended rss file generated by wordpress as an export of your") &&
                        sTest.Contains("http://purl.org/rss") &&
                        sTest.Contains("http://wordpress.org/export"))
                    {
                        WordPressSite wps = ContentImportExportUtils.DeserializeWPExport(sXML);
                        ContentImportExportUtils.AssignWPExportNewIDs(SiteData.CurrentSite, wps);
                        ContentImportExportUtils.SaveSerializedDataExport <WordPressSite>(wps.NewSiteID, wps);

                        Response.Redirect(SiteFilename.WPSiteImportURL + "?importid=" + wps.NewSiteID.ToString());
                    }

                    lblWarning.Text = "File did not appear to match an expected format.";
                    lblWarning.Attributes["style"] = "color: #990000;";
                } catch (Exception ex) {
                    lblWarning.Text = ex.ToString();
                    lblWarning.Attributes["style"] = "color: #990000;";
                }
            }
            else
            {
                lblWarning.Text = "No file appeared in the upload queue.";
                lblWarning.Attributes["style"] = "color: #990000;";
            }
        }
        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.ToLowerInvariant()).ToList();
                List <string> cats = site.GetCategoryList().Select(x => x.CategorySlug.ToLowerInvariant()).ToList();

                this.Site.TheTags.RemoveAll(x => tags.Contains(x.TagSlug.ToLowerInvariant()));
                this.Site.TheCategories.RemoveAll(x => cats.Contains(x.CategorySlug.ToLowerInvariant()));

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

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

                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 && usr.UserId != Guid.Empty)
                {
                    seu.ImportUserID = usr.UserId;
                }
                else
                {
                    usr = ExtendedUserData.FindByUsername(seu.Login);
                    if (usr != null && usr.UserId != Guid.Empty)
                    {
                        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);
                        }
                        else
                        {
                            throw new Exception(String.Format("Could not create user: {0} ({1}) \r\n{2}", seu.Login, seu.Email, String.Join("\r\n", result.Errors)));
                        }
                        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.ToLowerInvariant() == impCP.ParentFileName.ToLowerInvariant()
                                                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.ToLowerInvariant() == cp.FileName.ToLowerInvariant())
                    {
                        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.ToLowerInvariant() equals o.CategorySlug.ToLowerInvariant()
                                            select l).Distinct().ToList();

                    cp.ContentTags = (from l in lstTags
                                      join o in impCP.ThePage.ContentTags on l.TagSlug.ToLowerInvariant() equals o.TagSlug.ToLowerInvariant()
                                      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);
        }