public bool Save(HtmlContent content) { bool result = false; if (content == null) { return(result); } content.LastModUtc = DateTime.UtcNow; if (content.ItemId > -1) { result = DBHtmlContent.UpdateHtmlContent( content.ItemId, content.ModuleId, content.Title, content.Excerpt, content.Body, content.MoreLink, content.SortOrder, content.BeginDate, content.EndDate, content.LastModUtc, content.LastModUserGuid, content.ExcludeFromRecentContent); } else { content.ItemGuid = Guid.NewGuid(); int newId = DBHtmlContent.AddHtmlContent( content.ItemGuid, content.ModuleGuid, content.ModuleId, content.Title, content.Excerpt, content.Body, content.MoreLink, content.SortOrder, content.BeginDate, content.EndDate, content.CreatedDate, content.CreatedBy, content.UserGuid, content.ExcludeFromRecentContent); content.ItemId = newId; result = (newId > -1); } if (result) { ContentChangedEventArgs e = new ContentChangedEventArgs(); content.OnContentChanged(e); } return(result); }
public bool Delete(HtmlContent content) { if (content == null) { return false; } bool result = DBHtmlContent.DeleteHtmlContent(content.ItemId); if (result) { ContentChangedEventArgs e = new ContentChangedEventArgs(); e.IsDeleted = true; content.OnContentChanged(e); } return result; }
public HtmlContent Fetch(int moduleId) { if (moduleId < 0) { return null; } using (IDataReader reader = DBHtmlContent.GetHtmlContent(moduleId, DateTime.UtcNow)) { if (reader.Read()) { HtmlContent content = new HtmlContent(); LoadFromReader(content, reader); return content; } } return null; }
public bool Delete(HtmlContent content) { if (content == null) { return(false); } bool result = DBHtmlContent.DeleteHtmlContent(content.ItemId); if (result) { ContentChangedEventArgs e = new ContentChangedEventArgs(); e.IsDeleted = true; content.OnContentChanged(e); } return(result); }
public HtmlContent Fetch(int moduleId) { if (moduleId < 0) { return(null); } using (IDataReader reader = DBHtmlContent.GetHtmlContent(moduleId, DateTime.UtcNow)) { if (reader.Read()) { HtmlContent content = new HtmlContent(); LoadFromReader(content, reader); return(content); } } return(null); }
public void InstallContent(Module module, string configInfo) { HtmlContent htmlContent = new HtmlContent(); htmlContent.ModuleId = module.ModuleId; if (configInfo.StartsWith("~/")) { if (File.Exists(HostingEnvironment.MapPath(configInfo))) { htmlContent.Body = File.ReadAllText(HostingEnvironment.MapPath(configInfo), Encoding.UTF8); } } else { htmlContent.Body = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentUICulture, configInfo); } htmlContent.ModuleGuid = module.ModuleGuid; SiteSettings siteSettings = new SiteSettings(module.SiteId); SiteUser adminUser = null; if (siteSettings.UseEmailForLogin) { adminUser = new SiteUser(siteSettings, "*****@*****.**"); if (adminUser.UserId == -1) { adminUser = null; } } else { adminUser = new SiteUser(siteSettings, "admin"); if (adminUser.UserId == -1) { adminUser = null; } } if (adminUser != null) { htmlContent.UserGuid = adminUser.UserGuid; htmlContent.LastModUserGuid = adminUser.UserGuid; } HtmlRepository repository = new HtmlRepository(); repository.Save(htmlContent); }
public void CreateHistory(Guid siteGuid) { if (this.itemGuid == Guid.Empty) { return; } HtmlContent currentVersion = new HtmlContent(moduleID); if (currentVersion.Body == this.Body) { return; } ContentHistory history = new ContentHistory(); history.ContentGuid = currentVersion.ModuleGuid; history.ContentText = currentVersion.Body; history.SiteGuid = siteGuid; history.UserGuid = currentVersion.LastModUserGuid; history.CreatedUtc = currentVersion.LastModUtc; history.Save(); }
private void LoadFromReader(HtmlContent content, IDataReader reader) { if (content == null) { return; } if (reader == null) { return; } content.ItemId = Convert.ToInt32(reader["ItemID"]); content.ModuleId = Convert.ToInt32(reader["ModuleID"]); content.Title = reader["Title"].ToString(); content.Body = reader["Body"].ToString(); //legacy fields not used //content.Excerpt = reader["Excerpt"].ToString(); //content.MoreLink = reader["MoreLink"].ToString(); //content.SortOrder = Convert.ToInt32(reader["SortOrder"]); //content.BeginDate = Convert.ToDateTime(reader["BeginDate"]); //content.EndDate = Convert.ToDateTime(reader["EndDate"]); content.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]); //if (reader["UserID"] != DBNull.Value) //content.CreatedBy = Convert.ToInt32(reader["UserID"]); content.ItemGuid = new Guid(reader["ItemGuid"].ToString()); content.ModuleGuid = new Guid(reader["ModuleGuid"].ToString()); string user = reader["UserGuid"].ToString(); if (user.Length == 36) content.UserGuid = new Guid(user); user = reader["LastModUserGuid"].ToString(); if (user.Length == 36) content.LastModUserGuid = new Guid(user); if (reader["LastModUtc"] != DBNull.Value) content.LastModUtc = Convert.ToDateTime(reader["LastModUtc"]); content.CreatedByName = reader["CreatedByName"].ToString(); content.CreatedByFirstName = reader["CreatedByFirstName"].ToString(); content.CreatedByLastName = reader["CreatedByLastName"].ToString(); content.CreatedByEmail = reader["CreatedByEmail"].ToString(); content.AuthorAvatar = reader["AvatarUrl"].ToString(); content.AuthorBio = reader["AuthorBio"].ToString(); content.AuthorUserId = Convert.ToInt32(reader["AuthorUserID"]); content.LastModByName = reader["LastModByName"].ToString(); content.LastModByFirstName = reader["LastModByFirstName"].ToString(); content.LastModByLastName = reader["LastModByLastName"].ToString(); content.LastModByEmail = reader["LastModByEmail"].ToString(); content.ExcludeFromRecentContent = Convert.ToBoolean(reader["ExcludeFromRecentContent"]); }
public bool Save(HtmlContent content) { bool result = false; if (content == null) { return result; } content.LastModUtc = DateTime.UtcNow; if (content.ItemId > -1) { result = DBHtmlContent.UpdateHtmlContent( content.ItemId, content.ModuleId, content.Title, content.Excerpt, content.Body, content.MoreLink, content.SortOrder, content.BeginDate, content.EndDate, content.LastModUtc, content.LastModUserGuid, content.ExcludeFromRecentContent); } else { content.ItemGuid = Guid.NewGuid(); int newId = DBHtmlContent.AddHtmlContent( content.ItemGuid, content.ModuleGuid, content.ModuleId, content.Title, content.Excerpt, content.Body, content.MoreLink, content.SortOrder, content.BeginDate, content.EndDate, content.CreatedDate, content.CreatedBy, content.UserGuid, content.ExcludeFromRecentContent); content.ItemId = newId; result = (newId > -1); } if (result) { ContentChangedEventArgs e = new ContentChangedEventArgs(); content.OnContentChanged(e); } return result; }
private string GetModifiedByName(HtmlContent html) { if (displaySettings.UseAuthorFirstAndLastName) { if ((html.LastModByFirstName.Length > 0) && (html.LastModByLastName.Length > 0)) { return html.LastModByFirstName + " " + html.LastModByLastName; } } return html.LastModByName; }
private void Do3LevelApproval(HtmlContent html, SiteUser currentUser) { ContentWorkflow workInProgress = ContentWorkflow.GetWorkInProgress(ModuleGuid); if (workInProgress != null) { if (workInProgress.Status == ContentWorkflowStatus.AwaitingPublishing) { html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged); if (workInProgress.Status == ContentWorkflowStatus.AwaitingPublishing) { html.PublishApprovedContent(siteSettings.SiteGuid, currentUser.UserGuid); } else { html.ApproveContent(siteSettings.SiteGuid, currentUser.UserGuid, false); } } else { SiteUser draftSubmitter = new SiteUser(siteSettings, workInProgress.RecentActionByUserLogin); html.ApproveContentForPublishing(siteSettings.SiteGuid, currentUser.UserGuid); //Module module = new Module(workInProgress.ModuleId); //string publisherRoles = currentPage.EditRoles + module.AuthorizedEditRoles; string publisherRoles = currentPage.EditRoles + ModuleConfiguration.AuthorizedEditRoles; if (!WebConfigSettings.DisableWorkflowNotification) { WorkflowHelper.SendPublishRequestNotification( SiteUtils.GetSmtpSettings(), siteSettings, draftSubmitter, currentUser, workInProgress, publisherRoles, SiteUtils.GetCurrentPageUrl()); } } } }
private void ShowModified(HtmlContent html, ContentWorkflow workInProgress) { if ((html == null) && (workInProgress == null)) { return; } string modifiedByUserDateFormat = Resource.ModifiedByUserDateFormat; if (displaySettings.OverrideModifiedByUserDateFormat.Length > 0) { modifiedByUserDateFormat = displaySettings.OverrideModifiedByUserDateFormat; } string modifiedDateFormat = Resource.ModifiedDateFormat; if (displaySettings.OverrideModifiedDateFormat.Length > 0) { modifiedDateFormat = displaySettings.OverrideModifiedDateFormat; } string modifiedByUserFormat = Resource.ModifiedByUserFormat; if (displaySettings.OverrideModifiedByUserFormat.Length > 0) { modifiedByUserFormat = displaySettings.OverrideModifiedByUserFormat; } if (config.ShowModifiedBy && config.ShowModifiedDate) { if (workInProgress != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedByUserDateFormat, workInProgress.CreatedDateUtc.ToLocalTime(timeZone).ToString(displaySettings.DateFormat), GetModifiedByName(workInProgress) ); } else if (html != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedByUserDateFormat, html.LastModUtc.ToLocalTime(timeZone).ToString(displaySettings.DateFormat), GetModifiedByName(html) ); } } else if (config.ShowModifiedDate) { if (workInProgress != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedDateFormat, workInProgress.LastModUtc.ToLocalTime(timeZone).ToString(displaySettings.DateFormat) ); } else if (html != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedDateFormat, html.LastModUtc.ToLocalTime(timeZone).ToString(displaySettings.DateFormat) ); } } else if (config.ShowModifiedBy) { if (workInProgress != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedByUserFormat, GetModifiedByName(workInProgress) ); } else if (html != null) { litModifiedBy.Text = string.Format(CultureInfo.InvariantCulture, modifiedByUserFormat, GetModifiedByName(html) ); } } pnlModifiedBy.Visible = true; }
/// <summary> /// Edits the page. /// </summary> /// <param name="blogId"> /// The blog id. /// </param> /// <param name="pageId"> /// The page id. /// </param> /// <param name="userName"> /// The user name. /// </param> /// <param name="password"> /// The password. /// </param> /// <param name="mwaPage"> /// The m page. /// </param> /// <param name="publish"> /// The publish. /// </param> /// <returns> /// The edit page. /// </returns> internal bool EditPage(string blogId, string pageId, string userName, string password, MWAPage mwaPage, bool publish) { if ((string.IsNullOrEmpty(pageId))||(pageId.Length != 36)) { throw new MetaWeblogException("11", MetaweblogResources.PageNotFound); } PageSettings page = CacheHelper.GetPage(new Guid(pageId)); if (page.PageId == -1) { //doesn't exist throw new MetaWeblogException("11", MetaweblogResources.PageNotFound); } if (page.SiteId != siteSettings.SiteId) { //doesn't exist throw new MetaWeblogException("11", MetaweblogResources.PageNotFound); } //if (!publish) //{ // throw new MetaWeblogException("11", "Sorry draft pages are not supported through this API."); //} Module m = GetFirstCenterPaneHtmlModule(page); if (m == null) { throw new MetaWeblogException("11", MetaweblogResources.ContentInstanceNotFound); } if (!UserCanEdit(page, m)) { throw new MetaWeblogException("11", MetaweblogResources.AccessDenied); } PageSettings parentPage = null; Hashtable moduleSettings = ModuleSettings.GetModuleSettings(m.ModuleId); HtmlConfiguration config = new HtmlConfiguration(moduleSettings); HtmlRepository repository = new HtmlRepository(); HtmlContent html = repository.Fetch(m.ModuleId); if (html == null) { html = new HtmlContent(); html.ModuleId = m.ModuleId; html.ModuleGuid = m.ModuleGuid; } bool titleChanged = (m.ModuleTitle != mwaPage.title); // updated 2011-11-30 don't change page name for existing pages // only update the module title // avoid changing the home page name // while most content pages should have the module title the same as the page name for best seo // this is usually not the case for the home page, ie the content is not titled "home" //if (!IsHomePage(page.PageId)) //{ // page.PageName = mwaPage.title; //} if (titleChanged) { m.ModuleTitle = mwaPage.title; m.Save(); } html.Body = mwaPage.description; if ((mwaPage.mt_keywords != null) &&(mwaPage.mt_keywords.Length > 0)) { page.PageMetaKeyWords = mwaPage.mt_keywords; } bool needToClearSiteMapCache = false; bool pageOrderChanged = false; if ((mwaPage.pageOrder != null)&&(mwaPage.pageOrder.Length > 0)) { int newPageOrder = Convert.ToInt32(mwaPage.pageOrder); if (page.PageOrder != newPageOrder) { page.PageOrder = newPageOrder; needToClearSiteMapCache = true; pageOrderChanged = true; } } bool makeDraft = !publish; if (page.IsPending != makeDraft) { page.IsPending = makeDraft; needToClearSiteMapCache = true; } if ((mwaPage.pageParentID != null) &&(mwaPage.pageParentID.Length == 36)) { Guid parentGuid = new Guid(mwaPage.pageParentID); if (page.PageGuid == parentGuid) { throw new MetaWeblogException("11", MetaweblogResources.PageCantBeItsOwnParent); } // if parent pageid hasn't changed no need to doo anything if (parentGuid != page.ParentGuid) { if (parentGuid == Guid.Empty) { if (UserCanCreateRootLevelPages()) { page.ParentId = -1; page.PageGuid = Guid.Empty; needToClearSiteMapCache = true; } else { throw new MetaWeblogException("11", MetaweblogResources.NotAllowedToCreateRootPages); } } else { parentPage = new PageSettings(parentGuid); if (parentPage.SiteId != siteSettings.SiteId) { throw new MetaWeblogException("11", MetaweblogResources.ParentPageNotFound); } if ( (parentPage.PageId > -1) && (parentPage.PageId != page.PageId) // page cannot be its own parent && (parentPage.ParentId != page.PageId) // a child of the page cannot become its parent ) { // parent page exists //verify user can create pages below parent if (!UserCanCreateChildPages(parentPage)) { throw new MetaWeblogException("11", MetaweblogResources.NotAllowedParentPage); } // descendant of page (grandchildren cannot become parent) // so make sure selected parent is not a descendant of the current page if (IsValidParentPage(page, parentPage)) { page.ParentId = parentPage.PageId; page.PageGuid = parentPage.PageGuid; needToClearSiteMapCache = true; } else { throw new MetaWeblogException("11", MetaweblogResources.DescendentParentsNotAllowed); } } } } } // keep verison history if enabled bool enableContentVersioning = config.EnableContentVersioning; if ((siteSettings.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally)) { enableContentVersioning = true; } if ((html.ItemId > -1)&&(enableContentVersioning)) { html.CreateHistory(siteSettings.SiteGuid); } html.LastModUserGuid = siteUser.UserGuid; html.LastModUtc = DateTime.UtcNow; page.LastModifiedUtc = DateTime.UtcNow; html.ModuleGuid = m.ModuleGuid; html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged); repository.Save(html); CacheHelper.ClearModuleCache(m.ModuleId); switch (mwaPage.commentPolicy) { //closed case "0": case "2": page.EnableComments = false; break; // open case "1": // if the post was previously closed to comments // re-open it using the default allowed days page.EnableComments = true; break; //else unspecified, no change } if (page.UrlHasBeenAdjustedForFolderSites) { page.Url = page.UnmodifiedUrl; } page.Save(); if (pageOrderChanged) { if ((parentPage == null) && (page.ParentGuid != Guid.Empty)) { parentPage = new PageSettings(page.ParentGuid); } } if (parentPage != null) { parentPage.ResortPages(); } if (needToClearSiteMapCache) { CacheHelper.ResetSiteMapCache(siteSettings.SiteId); } SiteUtils.QueueIndexing(); return true; }
/// <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(); }
private void LoadFromReader(HtmlContent content, IDataReader reader) { if (content == null) { return; } if (reader == null) { return; } content.ItemId = Convert.ToInt32(reader["ItemID"]); content.ModuleId = Convert.ToInt32(reader["ModuleID"]); content.Title = reader["Title"].ToString(); content.Body = reader["Body"].ToString(); //legacy fields not used //content.Excerpt = reader["Excerpt"].ToString(); //content.MoreLink = reader["MoreLink"].ToString(); //content.SortOrder = Convert.ToInt32(reader["SortOrder"]); //content.BeginDate = Convert.ToDateTime(reader["BeginDate"]); //content.EndDate = Convert.ToDateTime(reader["EndDate"]); content.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]); //if (reader["UserID"] != DBNull.Value) //content.CreatedBy = Convert.ToInt32(reader["UserID"]); content.ItemGuid = new Guid(reader["ItemGuid"].ToString()); content.ModuleGuid = new Guid(reader["ModuleGuid"].ToString()); string user = reader["UserGuid"].ToString(); if (user.Length == 36) { content.UserGuid = new Guid(user); } user = reader["LastModUserGuid"].ToString(); if (user.Length == 36) { content.LastModUserGuid = new Guid(user); } if (reader["LastModUtc"] != DBNull.Value) { content.LastModUtc = Convert.ToDateTime(reader["LastModUtc"]); } content.CreatedByName = reader["CreatedByName"].ToString(); content.CreatedByFirstName = reader["CreatedByFirstName"].ToString(); content.CreatedByLastName = reader["CreatedByLastName"].ToString(); content.CreatedByEmail = reader["CreatedByEmail"].ToString(); content.AuthorAvatar = reader["AvatarUrl"].ToString(); content.AuthorBio = reader["AuthorBio"].ToString(); content.AuthorUserId = Convert.ToInt32(reader["AuthorUserID"]); content.LastModByName = reader["LastModByName"].ToString(); content.LastModByFirstName = reader["LastModByFirstName"].ToString(); content.LastModByLastName = reader["LastModByLastName"].ToString(); content.LastModByEmail = reader["LastModByEmail"].ToString(); content.ExcludeFromRecentContent = Convert.ToBoolean(reader["ExcludeFromRecentContent"]); }
private static void IndexItem(HtmlContent content) { bool disableSearchIndex = ConfigHelper.GetBoolProperty("DisableSearchIndex", false); if (disableSearchIndex) { return; } Module module = new Module(content.ModuleId); Guid htmlFeatureGuid = new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10"); ModuleDefinition htmlFeature = new ModuleDefinition(htmlFeatureGuid); // get list of pages where this module is published List<PageModule> pageModules = PageModule.GetPageModulesByModule(content.ModuleId); foreach (PageModule pageModule in pageModules) { PageSettings pageSettings = new PageSettings( content.SiteId, pageModule.PageId); //don't index pending/unpublished pages if (pageSettings.IsPending) { continue; } IndexItem indexItem = new IndexItem(); if (content.SearchIndexPath.Length > 0) { indexItem.IndexPath = content.SearchIndexPath; } indexItem.SiteId = content.SiteId; indexItem.ExcludeFromRecentContent = content.ExcludeFromRecentContent; indexItem.PageId = pageModule.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.ModuleViewRoles = module.ViewRoles; if (pageSettings.UseUrl) { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); indexItem.UseQueryStringParams = false; } // generally we should not include the page meta because it can result in duplicate results // one for each instance of html content on the page because they all use the smae page meta. // since page meta should reflect the content of the page it is sufficient to just index the content if ((ConfigurationManager.AppSettings["IndexPageMeta"] != null) && (ConfigurationManager.AppSettings["IndexPageMeta"] == "true")) { indexItem.PageMetaDescription = pageSettings.PageMetaDescription; indexItem.PageMetaKeywords = pageSettings.PageMetaKeyWords; } indexItem.FeatureId = htmlFeatureGuid.ToString(); indexItem.FeatureName = htmlFeature.FeatureName; indexItem.FeatureResourceFile = htmlFeature.ResourceFile; indexItem.ItemId = content.ItemId; indexItem.ModuleId = content.ModuleId; indexItem.ModuleTitle = module.ModuleTitle; indexItem.Title = content.Title; indexItem.Content = SecurityHelper.RemoveMarkup(content.Body); indexItem.PublishBeginDate = pageModule.PublishBeginDate; indexItem.PublishEndDate = pageModule.PublishEndDate; if ((content.CreatedByFirstName.Length > 0) && (content.CreatedByLastName.Length > 0)) { indexItem.Author = string.Format(CultureInfo.InvariantCulture, Resource.FirstLastFormat, content.CreatedByFirstName, content.CreatedByLastName); } else { indexItem.Author = content.CreatedByName; } indexItem.CreatedUtc = content.CreatedDate; indexItem.LastModUtc = content.LastModUtc; if (!module.IncludeInSearch) { indexItem.RemoveOnly = true; } IndexHelper.RebuildIndex(indexItem); } log.Debug("Indexed " + content.Title); }
private void LoadSettings() { ScriptConfig.IncludeColorBox = true; repository = new HtmlRepository(); try { // this keeps the action from changing during ajax postback in folder based sites SiteUtils.SetFormAction(Page, Request.RawUrl); } catch (MissingMethodException) { //this method was introduced in .NET 3.5 SP1 } virtualRoot = WebUtils.GetApplicationRoot(); currentUser = SiteUtils.GetCurrentSiteUser(); timeOffset = SiteUtils.GetUserTimeOffset(); lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl(); module = GetHtmlModule(); if (module == null) { SiteUtils.RedirectToAccessDeniedPage(this); return; } if (module.ModuleTitle.Length == 0) { //this is not persisted just used for display if there is no title module.ModuleTitle = Resource.EditHtmlSettingsLabel; } heading.Text = Server.HtmlEncode(module.ModuleTitle); userCanEdit = UserCanEdit(moduleId); userCanEditAsDraft = UserCanOnlyEditModuleAsDraft(moduleId, HtmlContent.FeatureGuid); divExcludeFromRecentContent.Visible = userCanEdit; pageSize = config.VersionPageSize; enableContentVersioning = config.EnableContentVersioning; if ((siteSettings.ForceContentVersioning) || (WebConfigSettings.EnforceContentVersioningGlobally)) { enableContentVersioning = true; } if ((WebUser.IsAdminOrContentAdmin) || (SiteUtils.UserIsSiteEditor())) { isAdmin = true; } edContent.WebEditor.ToolBar = ToolBar.FullWithTemplates; if (moduleSettings.Contains("HtmlEditorHeightSetting")) { edContent.WebEditor.Height = Unit.Parse(moduleSettings["HtmlEditorHeightSetting"].ToString()); } divHistoryDelete.Visible = (enableContentVersioning && isAdmin); pnlHistory.Visible = enableContentVersioning; SetupScript(); html = repository.Fetch(moduleId); if (html == null) { html = new HtmlContent(); html.ModuleId = moduleId; html.ModuleGuid = module.ModuleGuid; } if ((!userCanEdit) && (userCanEditAsDraft)) { btnUpdate.Visible = false; btnUpdateDraft.Visible = true; } btnUpdateDraft.Text = Resource.EditHtmlUpdateDraftButton; if ((WebConfigSettings.EnableContentWorkflow) && (siteSettings.EnableContentWorkflow)) { workInProgress = ContentWorkflow.GetWorkInProgress(this.module.ModuleGuid); //bool draftOnlyAccess = UserCanOnlyEditModuleAsDraft(moduleId); if (workInProgress != null) { // let editors toggle between draft and live view in the editor if (userCanEdit) { SetupWorkflowControls(true); } switch (workInProgress.Status) { case ContentWorkflowStatus.Draft: //there is a draft version currently available, therefore dont allow the non draft version to be edited: btnUpdateDraft.Visible = true; btnUpdate.Visible = false; if (ViewMode == PageViewMode.WorkInProgress) { //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusDraft; heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.DraftFormat, module.ModuleTitle); lblContentStatusLabel.SetOrAppendCss("wf-draft"); //JOE DAVIS if (userCanEdit) { btnPublishDraft.Visible = true; } } break; case ContentWorkflowStatus.ApprovalRejected: //rejected content - allow update as draft only btnUpdateDraft.Visible = true; btnUpdate.Visible = false; if (ViewMode == PageViewMode.WorkInProgress) { //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusRejected; heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentRejectedFormat, module.ModuleTitle); lblContentStatusLabel.SetOrAppendCss("wf-rejected"); //JOE DAVIS } break; case ContentWorkflowStatus.AwaitingApproval: //pending approval - dont allow any edited: // 2010-01-18 let editors update the draft if they want to before approving it. btnUpdateDraft.Visible = userCanEdit; btnUpdate.Visible = false; if (ViewMode == PageViewMode.WorkInProgress) { //litModuleTitle.Text += " - " + Resource.ApprovalProcessStatusAwaitingApproval; heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingApprovalFormat, module.ModuleTitle); lblContentStatusLabel.SetOrAppendCss("wf-awaitingapproval"); //JOE DAVIS } break; //JOE DAVIS case ContentWorkflowStatus.AwaitingPublishing: //pending publishing - allow editors, publishers, admin to update before publishing btnUpdateDraft.Visible = userCanEdit; btnUpdate.Visible = false; if (ViewMode == PageViewMode.WorkInProgress) { heading.Text = string.Format(CultureInfo.InvariantCulture, Resource.ContentAwaitingPublishingFormat, module.ModuleTitle); lblContentStatusLabel.SetOrAppendCss("wf-awaitingpublishing"); } break; } } else { //workInProgress is null there is no draft if (userCanEdit) { btnUpdateDraft.Text = Resource.CreateDraftButton; btnUpdateDraft.Visible = true; } } if ((userCanEdit) && (ViewMode == PageViewMode.Live)) { btnUpdateDraft.Visible = false; btnUpdate.Visible = true; } } AddClassToBody("htmledit"); }
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); } }
private void UpdateContent() { if (string.IsNullOrEmpty(submittedContent)) { return; } if (!EditIsAllowed()) { return; } if ((ViewMode == PageViewMode.WorkInProgress)&&(WebConfigSettings.EnableContentWorkflow) && (CurrentSite.EnableContentWorkflow)) { if (workInProgress != null) { if (!editDraft) { return; } workInProgress.ContentText = submittedContent; workInProgress.LastModUserGuid = currentUser.UserGuid; workInProgress.Save(); } else { //draft version doesn't exist - create it: ContentWorkflow.CreateDraftVersion( CurrentSite.SiteGuid, submittedContent, string.Empty, -1, Guid.Empty, this.module.ModuleGuid, currentUser.UserGuid); } } else { // edit live content if (userCanOnlyEditAsDraft) { return; } html = repository.Fetch(module.ModuleId); if (html == null) { html = new HtmlContent(); html.ModuleId = module.ModuleId; html.ModuleGuid = module.ModuleGuid; } html.Body = submittedContent; //these will really only be saved if it is a new html instance html.CreatedDate = DateTime.UtcNow; html.UserGuid = currentUser.UserGuid; html.LastModUserGuid = currentUser.UserGuid; if (module != null) { html.ModuleGuid = module.ModuleGuid; } html.LastModUtc = DateTime.UtcNow; if ((enableContentVersioning) && (html.ItemId > -1)) { html.CreateHistory(CurrentSite.SiteGuid); } html.ContentChanged += new ContentChangedEventHandler(html_ContentChanged); repository.Save(html); CurrentPage.UpdateLastModifiedTime(); CacheHelper.ClearModuleCache(module.ModuleId); SiteUtils.QueueIndexing(); } }