⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sectioneditcontrol.ascx.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
				EnableAnonymousPostingRow.Visible = csContext.SiteSettings.EnableAnonymousUserPosting;
				ForumConfiguration config = ForumConfiguration.Instance();
				EnableAnonymousPostingForUsersRow.Visible = config.EnableUserPostingAsAnonymous;
				EnableThreadStatusTrackingRow.Visible = config.EnableThreadStatus;
				EnableThreadStatusDefaultValueRow.Visible = config.EnableThreadStatus;
				

				if ((forum.ForumType == ForumType.Deleted) || (forum.ForumType == ForumType.Reporting)) 
					AllowDelete = false;

				if (csContext.SiteSettings.EnableMailGateway)
				{
					MailingList list = MailingLists.GetMailingList(forum.SectionID);
					if(MailingLists.GetMailingLists().Count < MailGateway.NumberOfLists || (list != null && list.IsMailingList))
					{
						if(list != null)
						{
							LEEmailAddress.Text = list.EmailAddress;
							LEEnableMailingList.Items.FindByValue( list.IsMailingList.ToString() ).Selected = true;
						}
						else
							LEEnableMailingList.SelectedValue = false;
					}
					else
					{
						LEEnableMailingList.Enabled = false;
						LicenseMaxed.Visible = true;
					}

					LEListName.Text = forum.GetExtendedAttribute("ListName");
					LEFooterMessage.Text = forum.GetExtendedAttribute("FooterMessage");

					bool passiveMode = false;
					string b = forum.GetExtendedAttribute("PassiveMode");
					if(!Globals.IsNullorEmpty(b))
					{
						try { passiveMode = bool.Parse(b); }
						catch { }
					}
					LEPassiveMode.SelectedValue = passiveMode;
					LEPassiveModeAddress.Text = forum.GetExtendedAttribute("PassiveModeAddress");
					LEEmailDomain.Text = CSMConfiguration.Instance().DefaultEmailDomain;
				}
			}

		}

	
		protected virtual void UpdateForum( Forum forum ) 
		{
			forum.IsActive = IsActive.SelectedValue;
			forum.Name = Name.Text;
			forum.NavigateUrl = Url.Text;
			forum.Description = Description.Text;
			forum.IsModerated = IsModerated.SelectedValue;
			forum.EnablePostStatistics = EnablePostStatistics.SelectedValue;
			forum.EnablePostPoints = EnablePostPoints.SelectedValue;
			forum.EnableAutoDelete = EnableAutoDelete.SelectedValue;
			forum.EnableAnonymousPosting = EnableAnonymousPosting.SelectedValue;
			forum.IsSearchable = IsSearchable.SelectedValue;
			forum.EnableAnonymousPostingForUsers = EnableAnonymousPostingForUsers.SelectedValue;
			forum.EnableThreadStatus = EnableThreadStatusTracking.SelectedValue;
			forum.DefaultThreadStatusValue = DefaultThreadStatusValue.SelectedValue;
			forum.DefaultLanguage = DefaultLanguage.SelectedValue;

			if (csContext.User.ControlPanelManageView == ControlPanelManageView.Grid)
			{
				forum.GroupID = this.GroupID;
				forum.ParentID = this.ParentSectionID;
			}

			try { forum.AutoDeleteThreshold = Int32.Parse( AutoDeleteThreshold.Text ); }
			catch { AutoDeleteThresholdValidator.IsValid = false; }

			// If we have a URL set the forum type
			if (!Globals.IsNullorEmpty(forum.NavigateUrl))
			{
				// ensure the forum link starts with http
				if (!forum.NavigateUrl.StartsWith("http://"))
					forum.NavigateUrl = "http://" + forum.NavigateUrl;

				forum.ForumType = ForumType.Link;
			}
			else
			{
				// If a link is removed, revert back to normal
				if (forum.ForumType == ForumType.Link)
					forum.ForumType = ForumType.Normal;
			}

			if (Description.Text.Length > 1000)
			{
				DescriptionRequired.IsValid = false;
			}
		}

		protected virtual void PreUpdateMailingList( Forum forum ) 
		{
			if (csContext.SiteSettings.EnableMailGateway)
			{
				// Set the extended attributes
				forum.SetExtendedAttribute("ListName", LEListName.Text);
				forum.SetExtendedAttribute("FooterMessage", LEFooterMessage.Text);
				forum.SetExtendedAttribute("PassiveMode", LEPassiveMode.SelectedValue.ToString());
				forum.SetExtendedAttribute("PassiveModeAddress", LEPassiveModeAddress.Text);
			}
		}

		protected virtual void PostUpdateMailingList( Forum forum ) 
		{
			if (csContext.SiteSettings.EnableMailGateway)
			{
				MailingList origList = MailingLists.GetMailingList(forum.SectionID);
				if(MailingLists.GetMailingLists().Count < MailGateway.NumberOfLists || (origList != null && origList.IsMailingList))
				{
					// Check that if the list is enabled, it has an email address
					if((LEEnableMailingList.SelectedValue == true) && (LEEmailAddress.Text.Trim() == string.Empty))
						LEEmailValidator.IsValid = false;

					// Check that the email address is not a duplicate
					MailingList checkList = MailingLists.GetMailingList(LEEmailAddress.Text.Trim());
					if(checkList != null)
						if(checkList.SectionID != forum.SectionID)
							LEEmailValidator.IsValid = false;

					// Set the core mailing list settings
					MailingList list = new MailingList();
					list.SectionID = forum.SectionID;
					list.EmailAddress = LEEmailAddress.Text.Trim();
					list.IsMailingList = LEEnableMailingList.SelectedValue;

					// Make sure the page is valid before saving.
					if(Page.IsValid)
						MailingLists.UpdateMailingList(list);
				}
			}
		}

		
		protected ArrayList GetForums()
		{
			ArrayList unfiltered = Discussions.Components.Forums.GetForums(false, false, false, true);

			if(GroupID < 0)
			{
				return unfiltered;
			}
			else
			{
				ArrayList filtered = new ArrayList();
				foreach(Forum f in unfiltered)
					if(f.GroupID == GroupID)
						filtered.Add(f);

				return filtered;
			}
		}


		public bool Save()
		{
			Status.Success = false;
			Status.Visible = true;
			Status.ResourceName = "CP_Forums_SectionEdit_StatusFailed";

			if( !csContext.User.IsForumAdministrator ) 
				throw new CSException( CSExceptionType.AdministrationAccessDenied );

			if(Page.IsValid)
			{

				if (AdminGroupList.Visible)
					this.GroupID = int.Parse(AdminGroupList.SelectedValue);

				if (ForumList.Visible)
					this.ParentSectionID = int.Parse(ForumList.SelectedValue);

				if (this.isNewForum)
				{
					Forum forum = this.Section;
					forum.ApplicationType = ApplicationType.Forum;
					forum.ForumType = ForumType.Normal;
					forum.SettingsID = csContext.SiteSettings.SettingsID;

					if (GroupID > 0)
						forum.GroupID = GroupID;

					// Add the GroupID onto the appKey
					string rawKey = String.Format("{0}-{1}", Name.Text, GroupID);
					forum.ApplicationKey = GenerateUniqueApplicationKey(rawKey);

					// Check if this is a subforum
					if (ParentSectionID > 0)
						forum.ParentID = ParentSectionID;

					// Update values from form fields
					UpdateForum(forum);
					PreUpdateMailingList(forum);

					this.SectionID = Discussions.Components.Forums.Add(forum);
					csContext.SectionID = this.SectionID;

					// Save Permissions once we have the new SectionID
					SectionPermissionListControl1.SectionID = SectionID;
					SectionPermissionListControl1.Save();
					SectionPermissionListAdminControl1.SectionID = SectionID;
					SectionPermissionListAdminControl1.Save();
					
					Status.ResourceName = "CP_Forums_SectionEdit_StatusAddSuccess";
					Status.Success = true;

					// Update the main mailing list settings
					PostUpdateMailingList(forum);
				}
				else
				{
					UpdateForum(this.Section);
					PreUpdateMailingList(Section);
					Discussions.Components.Forums.Update(Section);
					PostUpdateMailingList(Section);

					SectionPermissionListControl1.SectionID = SectionID;
					SectionPermissionListControl1.Save();
					SectionPermissionListAdminControl1.SectionID = SectionID;
					SectionPermissionListAdminControl1.Save();

					Status.ResourceName = "CP_Forums_SectionEdit_StatusEditSuccess";
					Status.Success = true;
				}

			}

			return Status.Success;
		}


		public void Delete() 
		{
			Sections.DeleteSection(this.Section);
		}

		private void AdminGroupList_SelectedIndexChanged(object sender, EventArgs e)
		{
			BindForumList();
		}

		private string GenerateUniqueApplicationKey(string rawKey)
		{
			string candidateKey = string.Empty;
			Globals.ValidateApplicationKey(rawKey, out candidateKey);

			while (!IsUniqueApplicationKey(candidateKey))
			{
				candidateKey = candidateKey + new Random().Next(1, 9).ToString();
			}

			return candidateKey;
		}

		private bool IsUniqueApplicationKey(string key)
		{
			foreach(Forum f in GetForums())
				if(f.ApplicationKey == key)
					return false;

			return true;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -