protected SiteNav GetHomePage(SiteData site) { if (_navHome == null) { using (SiteNavHelper navHelper = new SiteNavHelper()) { _navHome = navHelper.FindHome(site.SiteID, false); } } return _navHome; }
public void ProcessRequest(HttpContext context) { using (SiteNavHelper navHelper = new SiteNavHelper()) { SiteNav navData = null; string sFileRequested = context.Request.Path; sRequestedURL = sFileRequested; string sScrubbedURL = sFileRequested; sRequestedURL = SiteData.AppendDefaultPath(sRequestedURL); try { sScrubbedURL = SiteData.AlternateCurrentScriptName; if (sScrubbedURL.ToLower() != sRequestedURL.ToLower()) { sFileRequested = sScrubbedURL; bURLOverride = true; } VirtualDirectory.RegisterRoutes(); } catch (Exception ex) { //assumption is database is probably empty / needs updating, so trigger the under construction view if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete()) { if (navData == null) { navData = SiteNavHelper.GetEmptyHome(); } } else { //something bad has gone down, toss back the error throw; } } sFileRequested = SiteData.AppendDefaultPath(sFileRequested); if (context.User.Identity.IsAuthenticated) { try { if (context.Request.UrlReferrer != null && !string.IsNullOrEmpty(context.Request.UrlReferrer.AbsolutePath)) { if (context.Request.UrlReferrer.AbsolutePath.ToLower().Contains(FormsAuthentication.LoginUrl.ToLower()) || FormsAuthentication.LoginUrl.ToLower() == sFileRequested.ToLower()) { if (SiteFilename.DashboardURL.ToLower() != sFileRequested.ToLower() && SiteFilename.SiteInfoURL.ToLower() != sFileRequested.ToLower()) { sFileRequested = SiteData.AdminDefaultFile; } } } } catch (Exception ex) { } } if (sFileRequested.ToLower().EndsWith(".aspx") || sFileRequested.Length < 3) { bool bIgnorePublishState = SecurityData.AdvancedEditMode || SecurityData.IsAdmin || SecurityData.IsSiteEditor; string queryString = String.Empty; queryString = context.Request.QueryString.ToString(); if (string.IsNullOrEmpty(queryString)) { queryString = String.Empty; } if (!CMSConfigHelper.CheckRequestedFileExistence(sFileRequested, SiteData.CurrentSiteID) || sFileRequested.ToLower() == SiteData.DefaultDirectoryFilename) { context.Items[REQ_PATH] = context.Request.PathInfo; context.Items[REQ_QUERY] = context.Request.QueryString.ToString(); // handle a case where this site was migrated from a format where all pages varied on a consistent querystring // allow this QS parm to be set in a config file. if (sFileRequested.Length < 3 || sFileRequested.ToLower() == SiteData.DefaultDirectoryFilename) { string sParm = String.Empty; if (SiteData.OldSiteQuerystring != string.Empty) { if (context.Request.QueryString[SiteData.OldSiteQuerystring] != null) { sParm = context.Request.QueryString[SiteData.OldSiteQuerystring].ToString(); } } if (!string.IsNullOrEmpty(sParm)) { sFileRequested = "/" + sParm + ".aspx"; SiteData.Show301Message(sFileRequested); context.Response.Redirect(sFileRequested); context.Items[REQ_PATH] = sFileRequested; context.Items[REQ_QUERY] = String.Empty; } } try { bool bIsHomePage = false; if (sFileRequested.Length < 3 || sFileRequested.ToLower() == SiteData.DefaultDirectoryFilename) { navData = navHelper.FindHome(SiteData.CurrentSiteID, !bIgnorePublishState); if (sFileRequested.ToLower() == SiteData.DefaultDirectoryFilename && navData != null) { sFileRequested = navData.FileName; bIsHomePage = true; } } if (!bIsHomePage) { string pageName = sFileRequested; navData = navHelper.GetLatestVersion(SiteData.CurrentSiteID, !bIgnorePublishState, pageName); } if (sFileRequested.ToLower() == SiteData.DefaultDirectoryFilename && navData == null) { navData = SiteNavHelper.GetEmptyHome(); } } catch (Exception ex) { //assumption is database is probably empty / needs updating, so trigger the under construction view if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete()) { if (navData == null) { navData = SiteNavHelper.GetEmptyHome(); } } else { //something bad has gone down, toss back the error throw; } } if (navData != null) { string sSelectedTemplate = navData.TemplateFile; // selectivly engage the cms helper only if in advance mode if (SecurityData.AdvancedEditMode) { using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) { if (cmsHelper.cmsAdminContent != null) { try { sSelectedTemplate = cmsHelper.cmsAdminContent.TemplateFile.ToLower(); } catch { } } } } if (!CMSConfigHelper.CheckFileExistence(sSelectedTemplate)) { sSelectedTemplate = SiteData.DefaultTemplateFilename; } sVirtualReqFile = sFileRequested; if (bURLOverride) { sVirtualReqFile = sRequestedURL; sFileRequested = sRequestedURL; } RewriteCMSPath(context, sSelectedTemplate, queryString); } else { SiteData.PerformRedirectToErrorPage(404, sFileRequested); SiteData.Show404MessageFull(true); } } else { sVirtualReqFile = sFileRequested; RewriteCMSPath(context, sVirtualReqFile, queryString); } } context.ApplicationInstance.CompleteRequest(); } }
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(); }
protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestCtx) { string requestedUri = (string)requestCtx.RouteData.Values["RequestedUri"]; requestedUri = String.IsNullOrEmpty(requestedUri) ? String.Empty : requestedUri.ToLower(); if (!requestedUri.StartsWith("/")) { requestedUri = String.Format("/{0}", requestedUri); } if (requestedUri.EndsWith("/")) { requestedUri = requestedUri.Substring(0, requestedUri.Length - 1); } if (requestedUri.EndsWith(".ashx")) { if (requestedUri == "/rss.ashx") { requestCtx.RouteData.Values["controller"] = ContentCtrlr; requestCtx.RouteData.Values["action"] = "RSSFeed"; return base.GetHttpHandler(requestCtx); } if (requestedUri == "/sitemap.ashx") { requestCtx.RouteData.Values["controller"] = ContentCtrlr; requestCtx.RouteData.Values["action"] = "SiteMap"; return base.GetHttpHandler(requestCtx); } //if (requestedUri == "/trackback.ashx") { // will be dead link // requestCtx.RouteData.Values["controller"] = ContentCtrlr; // requestCtx.RouteData.Values["action"] = "Trackback"; // return base.GetHttpHandler(requestCtx); //} requestCtx.RouteData.Values["controller"] = "Carrotware.CMS.Core.CmsHome"; requestCtx.RouteData.Values["action"] = "Default_ashx"; return base.GetHttpHandler(requestCtx); } else { string sCurrentPage = SiteData.CurrentScriptName; try { string sScrubbedURL = SiteData.AlternateCurrentScriptName; if (sScrubbedURL.ToLower() != sCurrentPage.ToLower()) { requestedUri = sScrubbedURL; } SiteNav navData = null; bool bIsHomePage = false; bool bIgnorePublishState = SecurityData.AdvancedEditMode || SecurityData.IsAdmin || SecurityData.IsSiteEditor; using (SiteNavHelper navHelper = new SiteNavHelper()) { if (requestedUri.Length < 2 || requestedUri == SiteData.DefaultDirectoryFilename) { navData = navHelper.FindHome(SiteData.CurrentSiteID, !bIgnorePublishState); if (navData != null) { requestedUri = navData.FileName; bIsHomePage = true; } } if (!bIsHomePage) { navData = navHelper.GetLatestVersion(SiteData.CurrentSiteID, !bIgnorePublishState, requestedUri); } if ((requestedUri.Length < 2 || requestedUri == SiteData.DefaultDirectoryFilename) && navData == null) { navData = SiteNavHelper.GetEmptyHome(); } requestCtx.RouteData.Values["controller"] = ContentCtrlr; if (navData != null) { requestCtx.RouteData.Values["action"] = "Default"; } else { requestCtx.RouteData.Values["action"] = "_PageNotFound"; } requestCtx.RouteData.Values["id"] = null; } } catch (Exception ex) { if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete()) { requestCtx.RouteData.Values["controller"] = ContentCtrlr; requestCtx.RouteData.Values["action"] = "Default"; requestCtx.RouteData.Values["id"] = null; } else { //something bad has gone down, toss back the error throw; } } } return base.GetHttpHandler(requestCtx); }