/// <summary> /// wp.newPage method /// </summary> /// <param name="blogId">blogID in string format</param> /// <param name="userName">login username</param> /// <param name="password">login password</param> /// <param name="mwaPage">The mwa page.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns>The new page.</returns> internal string NewPage(string blogId, string userName, string password, MWAPage mwaPage, bool publish) { PageSettings page = new PageSettings(); PageSettings parentPage = null; Guid parentGuid = Guid.Empty; if ((mwaPage.pageParentID != null)&&(mwaPage.pageParentID.Length == 36)) { parentGuid = new Guid(mwaPage.pageParentID); } if (parentGuid == Guid.Empty) //root level page { if (!UserCanCreateRootLevelPages()) { throw new MetaWeblogException("11", MetaweblogResources.NotAllowedToCreateRootPages); } // TODO: promote these to site settings? //page.AuthorizedRoles = WebConfigSettings.DefaultPageRoles; //page.EditRoles = WebConfigSettings.DefaultRootPageEditRoles; //page.CreateChildPageRoles = WebConfigSettings.DefaultRootPageCreateChildPageRoles; page.AuthorizedRoles = siteSettings.DefaultRootPageViewRoles; page.EditRoles = siteSettings.DefaultRootPageEditRoles; page.CreateChildPageRoles = siteSettings.DefaultRootPageCreateChildPageRoles; } else { parentPage = new PageSettings(parentGuid); if (parentPage.PageId == -1) { throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound); } if (parentPage.SiteId != siteSettings.SiteId) { throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound); } if (!UserCanCreateChildPages(parentPage)) { throw new MetaWeblogException("11", MetaweblogResources.NotAllowedParentPage); } } if (parentPage != null) { page.ParentId = parentPage.PageId; page.ParentGuid = parentPage.PageGuid; page.PageOrder = PageSettings.GetNextPageOrder(siteSettings.SiteId, parentPage.PageId); // by default inherit settings from parent page.AuthorizedRoles = parentPage.AuthorizedRoles; page.EditRoles = parentPage.EditRoles; page.DraftEditOnlyRoles = parentPage.DraftEditOnlyRoles; page.CreateChildPageRoles = parentPage.CreateChildPageRoles; page.CreateChildDraftRoles = parentPage.CreateChildDraftRoles; } if ((mwaPage.pageOrder != null) && (mwaPage.pageOrder.Length > 0)) { page.PageOrder = Convert.ToInt32(mwaPage.pageOrder); } page.SiteId = siteSettings.SiteId; page.SiteGuid = siteSettings.SiteGuid; page.IsPending = !publish; page.PageName = mwaPage.title; //page.PageTitle = mwaPage.title; // this was the override page title it should not be set here if ((mwaPage.mt_keywords != null) && (mwaPage.mt_keywords.Length > 0)) { page.PageMetaKeyWords = mwaPage.mt_keywords; } if (WebConfigSettings.AutoGeneratePageMetaDescriptionForMetaweblogNewPages) { page.PageMetaDescription = UIHelper.CreateExcerpt(mwaPage.description, WebConfigSettings.MetaweblogGeneratedMetaDescriptionMaxLength); } //if (WebConfigSettings.ShowUseUrlSettingInPageSettings) //{ //} string friendlyUrlString = SiteUtils.SuggestFriendlyUrl(page.PageName, siteSettings); page.Url = "~/" + friendlyUrlString; page.UseUrl = true; switch (mwaPage.commentPolicy) { // open case "1": // if the post was previously closed to comments // re-open it using the default allowed days page.EnableComments = true; break; //closed case "0": case "2": default: page.EnableComments = false; break; } // I'm not sure we should support the page created event handler here, people may do redirects there // that would interupt our next steps // maybe need a config setting to decide // page.PageCreated += new PageCreatedEventHandler(PageCreated); page.Save(); FriendlyUrl newFriendlyUrl = new FriendlyUrl(); newFriendlyUrl.SiteId = siteSettings.SiteId; newFriendlyUrl.SiteGuid = siteSettings.SiteGuid; newFriendlyUrl.PageGuid = page.PageGuid; newFriendlyUrl.Url = friendlyUrlString; newFriendlyUrl.RealUrl = "~/Default.aspx?pageid=" + page.PageId.ToInvariantString(); newFriendlyUrl.Save(); // create html module in center pane ModuleDefinition moduleDefinition = new ModuleDefinition(HtmlContent.FeatureGuid); Module m = new Module(); m.SiteId = siteSettings.SiteId; m.SiteGuid = siteSettings.SiteGuid; m.ModuleDefId = moduleDefinition.ModuleDefId; m.FeatureGuid = moduleDefinition.FeatureGuid; m.Icon = moduleDefinition.Icon; m.CacheTime = moduleDefinition.DefaultCacheTime; m.PageId = page.PageId; m.ModuleTitle = page.PageTitle; m.PaneName = "contentpane"; m.CreatedByUserId = siteUser.UserId; m.ShowTitle = WebConfigSettings.ShowModuleTitlesByDefault; m.HeadElement = WebConfigSettings.ModuleTitleTag; m.ModuleOrder = 1; m.Save(); HtmlRepository repository = new HtmlRepository(); HtmlContent html = new HtmlContent(); html.ModuleId = m.ModuleId; html.ModuleGuid = m.ModuleGuid; html.Body = mwaPage.description; //html.CreatedBy = siteUser.UserId; html.UserGuid = siteUser.UserGuid; html.CreatedDate = DateTime.UtcNow; html.LastModUserGuid = siteUser.UserGuid; html.LastModUtc = DateTime.UtcNow; html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged); repository.Save(html); mojoPortal.SearchIndex.IndexHelper.RebuildPageIndexAsync(page); SiteUtils.QueueIndexing(); CacheHelper.ResetSiteMapCache(siteSettings.SiteId); return page.PageGuid.ToString(); }
public static void CreatePage(SiteSettings siteSettings, ContentPage contentPage, PageSettings parentPage) { PageSettings pageSettings = new PageSettings(); pageSettings.PageGuid = Guid.NewGuid(); if (parentPage != null) { pageSettings.ParentGuid = parentPage.PageGuid; pageSettings.ParentId = parentPage.PageId; } pageSettings.SiteId = siteSettings.SiteId; pageSettings.SiteGuid = siteSettings.SiteGuid; pageSettings.AuthorizedRoles = contentPage.VisibleToRoles; pageSettings.EditRoles = contentPage.EditRoles; pageSettings.DraftEditOnlyRoles = contentPage.DraftEditRoles; pageSettings.CreateChildPageRoles = contentPage.CreateChildPageRoles; pageSettings.MenuImage = contentPage.MenuImage; pageSettings.PageMetaKeyWords = contentPage.PageMetaKeyWords; pageSettings.PageMetaDescription = contentPage.PageMetaDescription; CultureInfo uiCulture = Thread.CurrentThread.CurrentUICulture; if (WebConfigSettings.UseCultureOverride) { uiCulture = SiteUtils.GetDefaultUICulture(siteSettings.SiteId); } if (contentPage.ResourceFile.Length > 0) { pageSettings.PageName = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Name, uiCulture, false); if (contentPage.Title.Length > 0) { pageSettings.PageTitle = ResourceHelper.GetResourceString(contentPage.ResourceFile, contentPage.Title, uiCulture, false); } } else { pageSettings.PageName = contentPage.Name; pageSettings.PageTitle = contentPage.Title; } pageSettings.PageOrder = contentPage.PageOrder; pageSettings.Url = contentPage.Url; pageSettings.RequireSsl = contentPage.RequireSsl; pageSettings.ShowBreadcrumbs = contentPage.ShowBreadcrumbs; pageSettings.BodyCssClass = contentPage.BodyCssClass; pageSettings.MenuCssClass = contentPage.MenuCssClass; pageSettings.IncludeInMenu = contentPage.IncludeInMenu; pageSettings.IsClickable = contentPage.IsClickable; pageSettings.IncludeInSiteMap = contentPage.IncludeInSiteMap; pageSettings.IncludeInChildSiteMap = contentPage.IncludeInChildPagesSiteMap; pageSettings.AllowBrowserCache = contentPage.AllowBrowserCaching; pageSettings.ShowChildPageBreadcrumbs = contentPage.ShowChildPageBreadcrumbs; pageSettings.ShowHomeCrumb = contentPage.ShowHomeCrumb; pageSettings.ShowChildPageMenu = contentPage.ShowChildPagesSiteMap; pageSettings.HideAfterLogin = contentPage.HideFromAuthenticated; pageSettings.EnableComments = contentPage.EnableComments; pageSettings.Save(); if (!FriendlyUrl.Exists(siteSettings.SiteId, pageSettings.Url)) { if (!WebPageInfo.IsPhysicalWebPage(pageSettings.Url)) { FriendlyUrl friendlyUrl = new FriendlyUrl(); friendlyUrl.SiteId = siteSettings.SiteId; friendlyUrl.SiteGuid = siteSettings.SiteGuid; friendlyUrl.PageGuid = pageSettings.PageGuid; friendlyUrl.Url = pageSettings.Url.Replace("~/", string.Empty); friendlyUrl.RealUrl = "~/Default.aspx?pageid=" + pageSettings.PageId.ToInvariantString(); friendlyUrl.Save(); } } foreach (ContentPageItem pageItem in contentPage.PageItems) { // tni-20130624: moduleGuidxxxx handling Guid moduleGuid2Use = Guid.Empty; bool updateModule = false; Module findModule = null; if (pageItem.ModuleGuidToPublish != Guid.Empty) { Module existingModule = new Module(pageItem.ModuleGuidToPublish); if (existingModule.ModuleGuid == pageItem.ModuleGuidToPublish && existingModule.SiteId == siteSettings.SiteId) { Module.Publish(pageSettings.PageGuid, existingModule.ModuleGuid, existingModule.ModuleId, pageSettings.PageId, pageItem.Location, pageItem.SortOrder, DateTime.UtcNow, DateTime.MinValue); // tni: I assume there's nothing else to do now so let's go to the next content... continue; } } else if (pageItem.ModuleGuid != Guid.Empty) { findModule = new Module(pageItem.ModuleGuid); if (findModule.ModuleGuid == Guid.Empty) { // Module does not exist, we can create new one with the specified Guid moduleGuid2Use = pageItem.ModuleGuid; } if (findModule.ModuleGuid == pageItem.ModuleGuid && findModule.SiteId == siteSettings.SiteId) { // The module already exist, we'll update existing one updateModule = true; moduleGuid2Use = findModule.ModuleGuid; } } // ModuleDefinition moduleDef = new ModuleDefinition(pageItem.FeatureGuid); // this only adds if its not already there try { SiteSettings.AddFeature(siteSettings.SiteGuid, pageItem.FeatureGuid); } catch (Exception ex) { log.Error(ex); } if (moduleDef.ModuleDefId > -1) { Module module = null; if (updateModule && (findModule != null)) { module = findModule; } else { module = new Module(); module.ModuleGuid = moduleGuid2Use; } module.SiteId = siteSettings.SiteId; module.SiteGuid = siteSettings.SiteGuid; module.PageId = pageSettings.PageId; module.ModuleDefId = moduleDef.ModuleDefId; module.FeatureGuid = moduleDef.FeatureGuid; module.PaneName = pageItem.Location; if (contentPage.ResourceFile.Length > 0) { module.ModuleTitle = ResourceHelper.GetResourceString(contentPage.ResourceFile, pageItem.ContentTitle, uiCulture, false); } else { module.ModuleTitle = pageItem.ContentTitle; } module.ModuleOrder = pageItem.SortOrder; module.CacheTime = pageItem.CacheTimeInSeconds; module.Icon = moduleDef.Icon; module.ShowTitle = pageItem.ShowTitle; module.AuthorizedEditRoles = pageItem.EditRoles; module.DraftEditRoles = pageItem.DraftEditRoles; module.ViewRoles = pageItem.ViewRoles; module.IsGlobal = pageItem.IsGlobal; module.HeadElement = pageItem.HeadElement; module.HideFromAuthenticated = pageItem.HideFromAuthenticated; module.HideFromUnauthenticated = pageItem.HideFromAnonymous; module.Save(); if ((pageItem.Installer != null) && (pageItem.ConfigInfo.Length > 0)) { //this is the newer implementation for populating feature content pageItem.Installer.InstallContent(module, pageItem.ConfigInfo); } else { // legacy implementation for backward compatibility if ( (pageItem.FeatureGuid == HtmlContent.FeatureGuid) && (pageItem.ContentTemplate.EndsWith(".config")) ) { HtmlContent htmlContent = new HtmlContent(); htmlContent.ModuleId = module.ModuleId; htmlContent.Body = ResourceHelper.GetMessageTemplate(uiCulture, pageItem.ContentTemplate); htmlContent.ModuleGuid = module.ModuleGuid; HtmlRepository repository = new HtmlRepository(); repository.Save(htmlContent); } } // tni-20130624: handling module settings foreach (KeyValuePair<string, string> item in pageItem.ModuleSettings) { ModuleSettings.UpdateModuleSetting(module.ModuleGuid, module.ModuleId, item.Key, item.Value); } } } foreach (ContentPage childPage in contentPage.ChildPages) { CreatePage(siteSettings, childPage, pageSettings); } }
public static void PropagateCurrentPagePermissionsToAllChildPages() { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } SiteMapDataSource siteMapDataSource = new SiteMapDataSource(); siteMapDataSource.SiteMapProvider = "mojosite" + siteSettings.SiteId.ToInvariantString(); mojoSiteMapNode currentPageNode = GetCurrentPageSiteMapNode(siteMapDataSource.Provider.RootNode); foreach (SiteMapNode childNode in currentPageNode.GetAllNodes()) { if (!(childNode is mojoSiteMapNode)) { continue; } mojoSiteMapNode node = childNode as mojoSiteMapNode; PageSettings p = new PageSettings(node.PageGuid); p.AuthorizedRoles = currentPageNode.ViewRoles; p.EditRoles = currentPageNode.EditRoles; p.CreateChildPageRoles = currentPageNode.CreateChildPageRoles; p.DraftEditOnlyRoles = currentPageNode.DraftEditRoles; p.CreateChildDraftRoles = currentPageNode.CreateChildDraftPageRoles; p.Save(); } CacheHelper.ResetSiteMapCache(siteSettings.SiteId); }