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

📄 moderationcontextmenu.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
				menu.Items.Add(item);
			}

			if (canModerate) 
			{
				// Set the text for the hyperlink
				item = new CA.MenuItem();
				item.Text = ResourceManager.GetString("ModeratePost_EditUser");
				item.NavigateUrl = Globals.GetSiteUrls().ControlPanelUserEdit(this.Post.User.UserID);
				menu.Items.Add(item);

				// Toggle Moderate / Unmoderate User
				//
				item = new CA.MenuItem();
				switch (this.Post.User.ModerationLevel) 
				{
					case ModerationLevel.Unmoderated:
						item.Text = ResourceManager.GetString("ModerateThread_Moderate_User");
						break;

					case ModerationLevel.Moderated:
						item.Text = ResourceManager.GetString("ModerateThread_UnModerate_User");
						break;

					default:
						item = null;
						break;
				}
                
				if (item != null)
				{
					item.ClientSideCommand = Page.GetPostBackClientEvent(this, "ModerateUnModerateUser:" + this.Post.User.UserID.ToString());
					menu.Items.Add(item);
				}

				// Set the ModerationHistory url.
				//
				if (csContext.SiteSettings.EnableUserModerationCounters) 
				{
					item = new CA.MenuItem();
					item.Text = ResourceManager.GetString("ModeratePost_ModerationHistory");
					item.NavigateUrl = Globals.GetSiteUrls().ModerationHistory(Post.PostID, Globals.UrlEncode(ForumUrls.Instance().Forum(this.Post.SectionID)));
					menu.Items.Add(item);
				}
			}
		}
        
		#endregion

		#region Properties

		/// <summary>
		/// Property UsePathToRedirect (bool)
		/// </summary>
		public bool UsePathToRedirect
		{
			get 
			{  
				object obj = ViewState["UsePathToRedirect"];
				return obj == null ? false : (bool)obj;
			}
			set {  ViewState["UsePathToRedirect"] = value; }
		}

		private ForumPost post = null;
		public ForumPost Post 
		{
			get 
			{
				return post;
			}
			set 
			{
				post = value;
			}
		}

		private Forum forum = null;
		public Forum Forum 
		{
			get 
			{
				return forum;
			}
			set 
			{
				forum = value;
			}
		}

		protected bool UserHasAccess
		{
			get
			{
				if (Forum != null)
				{
					canModerate = Permissions.ValidatePermissions(Forum, Permission.Moderate, csContext.User);
					canModerate |= csContext.User.IsForumAdministrator;

					canEdit = Permissions.ValidatePermissions(Forum, Permission.EditOthers, csContext.User);

					return (canModerate || canEdit);
				}
				else
					return false;
			}
		}

		#endregion

		#region Events

		public event EventHandler PostModerateRefresh;
		private void OnPostModerateRefresh(EventArgs e)
		{
			if(PostModerateRefresh != null)
				PostModerateRefresh(null, e);
		}

		#endregion

		#region Event Handlers

		// *********************************************************************
		//  Approve_Click
		//
		/// <summary>
		/// Event handler for approving a post
		/// </summary>
		// ***********************************************************************/
		private void Approve_Click(string commandArgument) 
		{   
			int postID = int.Parse(commandArgument);
			ForumPost post = Posts.GetPost(postID, csContext.User.UserID);

			// Approve the post.
			Moderate.ApprovePost(post, csContext.User.UserID);

			//Context.Response.Redirect(Globals.GetSiteUrls().ModerateForum(csContext.SectionID));
			Context.Response.Redirect(Globals.GetSiteUrls().ModerateForum(post.Forum.SectionID));
			Context.Response.End();
		}
        
		// *********************************************************************
		//  UnModerateUser_Click
		//
		/// <summary>
		/// Event handler for unmoderating a user.
		/// </summary>
		// ***********************************************************************/
		private void ModerateUnModerateUser_Click (string commandArgument) 
		{
			User user = Users.GetUser(int.Parse(commandArgument), false, false);
			Moderate.ToggleUserSettings( ModerateUserSetting.ToggleModerate, user, csContext.User.UserID);

			//Basically, if in mod menu then redirect to mod menu - otherwise, you are in forum so redirect to where you are
			if (this.UsePathToRedirect)
			{
				Context.Response.Redirect(Globals.GetSiteUrls().ModerateForum(csContext.SectionID));
				Context.Response.End();
			}
			else
			{
				Context.Response.Redirect(Globals.GetSiteUrls().Post(this.Post.PostID));
				Context.Response.End();
			}
		}

		// *********************************************************************
		//  LockUnlock_Click
		//
		/// <summary>
		/// Event handler for approving a post and replying to the post.
		/// </summary>
		// ***********************************************************************/
		private void LockUnlock_Click (string commandArgument) 
		{
			int postID = int.Parse(commandArgument);
			ForumPost post = Posts.GetPost(postID, csContext.User.UserID);

			// Check for access before submitting
			Permissions.AccessCheck( post.Section, Permission.Moderate, csContext.User, post );

			// Doing this twice just in case the exception thrown from the access check doesn't fully abort execution
			if(Permissions.ValidatePermissions(post.Section, Permission.Moderate, csContext.User, post))
				Moderate.TogglePostSettings(ModeratePostSetting.ToggleLock, post, csContext.User.UserID);

			// Fire an event to refresh the thread
			OnPostModerateRefresh(new System.EventArgs());
		}

		// *********************************************************************
		//  ApproveReply_Click
		//
		/// <summary>
		/// Event handler for approving a post and replying to the post.
		/// </summary>
		// ***********************************************************************/
		private void ApproveReply_Click(string commandArgument) 
		{
			int postID = int.Parse(commandArgument);
			ForumPost post = Posts.GetPost(postID, csContext.User.UserID);

			// Approve the post.
			Moderate.ApprovePost(post, csContext.User.UserID);

			// Redirect the user to the PostReply url.
			Context.Response.Redirect(ForumUrls.Instance().PostReply(postID));
			Context.Response.End();
		}

		// *********************************************************************
		//  ApproveEdit_Click
		//
		/// <summary>
		/// Event handler for approving a post and editing the post.
		/// </summary>
		// ***********************************************************************/
		private void ApproveEdit_Click(string commandArgument) 
		{
			int postID = int.Parse(commandArgument);
			ForumPost post = Posts.GetPost(postID, csContext.User.UserID);

			// Approve the post.
			Moderate.ApprovePost(post, csContext.User.UserID);

			// Redirect the user to the edit post url.
			Context.Response.Redirect(Globals.GetSiteUrls().ModeratePostEdit(postID, SiteUrls.Instance().Post(Post.PostID)));
			Context.Response.End();
		}

		#endregion

		#region IPostBackEventHandler Members

		public void RaisePostBackEvent(string eventArgument)
		{
			string[] e = eventArgument.Split(':');
			switch (e[0])
			{
				case "Approve":
					this.Approve_Click(e[1]);
					break;

				case "ApproveReply":
					this.ApproveReply_Click(e[1]);
					break;

				case "ApproveEdit":
					this.ApproveEdit_Click(e[1]);
					break;

				case "LockUnlock":
					this.LockUnlock_Click(e[1]);
					break;

				case "ModerateUnModerateUser":
					this.ModerateUnModerateUser_Click(e[1]);
					break;
			}	
		}

		#endregion
	}
}

⌨️ 快捷键说明

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