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

📄 moderationmenu.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{
    // *********************************************************************
    //  ModerationMenu
    //
    /// <summary>
    /// This control renders a moderation menu used by forum moderators
    /// to moderate new posts.
    /// </summary>
    // ********************************************************************/ 	
    public class ModerationMenu : TemplatedWebControl 
    {
        #region Child Controls

        Label PostID;
        HyperLink Approve;
		LinkButton ApproveView;
        LinkButton ToggleLockUnlockPost;
        HyperLink ToggleModerateUnModerateUser;
        HyperLink Move;
        HyperLink MergeSplit;
        HyperLink DeletePost;
        HyperLink EditPost;
        HyperLink EditUser;
        HyperLink ModerationHistory;

        ForumPost post;
        Forum forum;
        CSContext csContext;
        bool canModerate = false;
        bool canEdit = false;

        #endregion

		protected override void OnInit(EventArgs e) 
		{
			csContext = CSContext.Current;

			if (SkinName == null)
				ExternalSkinFileName = "Moderation/Skin-ModerationMenu.ascx";
			else
				ExternalSkinFileName = SkinName;

			AjaxManager.Register(this,"Moderation", true, AjaxDebug.None);
			BuildCallbackScript();

			base.OnInit(e);
		}

		private void BuildCallbackScript()
		{
			StringBuilder sb = new StringBuilder();

			sb.Append("\n<script language='javascript' type=\"text/javascript\">\n");
			sb.Append("\nfunction DoApprovePost(containerID, postID)\n{\n\tModeration.ApprovePostAjax(containerID, postID, ApprovePostCallback);\n}\n");
			sb.Append("\nfunction DoToggleModeration(containerID, userID, controlID)\n{\n\tModeration.ToggleModerationAjax(containerID, userID, controlID, ToggleModerationCallback);\n}\n");
			sb.Append("\nfunction DoQuickDelete(url)\n{\n\tTelligent_Modal.Open(url, 600, 500, QuickDeleteCallback);\n}\n");
			sb.Append("\nfunction DoQuickHistory(url)\n{\n\tTelligent_Modal.Open(url, 600, 300, null);\n}\n");
			sb.Append("\nfunction ApprovePostCallback(response)\n{\n\tHidePost(response.value);\n}\n");
			sb.Append("\nfunction ToggleModerationCallback(response)\n{\n\tSetText(response.value[0], response.value[1]);\n}\n");
			sb.Append("\nfunction QuickDeleteCallback(postID)\n{\n\tif (postID != -1)\n\tHidePost(postID);\n}\n");
			sb.Append("\nfunction HidePost(postID)\n{\n\tvar control = document.getElementById('Post_' + postID);\n\tcontrol.style.display = 'none';\n}\n");
			sb.Append("\nfunction SetText(controlID, text)\n{\n\tvar control = document.getElementById(controlID);\n\tcontrol.innerHTML = text;\n}\n");
			sb.Append("\n</script>");

			Page.RegisterClientScriptBlock("DoWrappersAndAJAXCallbacks", sb.ToString());
		}

        protected override void OnLoad(EventArgs e) 
        {
            DataBind();

            base.OnLoad(e);
        }

        #region DataBind

        public override void DataBind() 
        {
            base.DataBind();
         
            // If the current user does not have moderate permissions on the post, return.
            //
            User user = csContext.User;

            if (this.Post == null)
                return;

            int postID = this.Post.PostID;
            
            // If we don't have the forum, then go get it
            if (forum == null)
                forum = this.Post.Forum;

            canModerate = Permissions.ValidatePermissions( forum, Permission.Moderate, user );
            canModerate |= user.IsForumAdministrator;

            canEdit = Permissions.ValidatePermissions( forum, Permission.EditOthers, user );

            // Stop here if no permissions
            //
            if (!canModerate && !canEdit)
            {
                this.Visible = false;
                return;
            }

            bool trueRedirect = this.UsePathToRedirect;

            if (null != PostID) 
                PostID.Text = this.Post.PostID.ToString();

			// Add the Approve click event handler.
			//
			if (null != Approve) 
			{
				Approve.NavigateUrl = string.Format("javascript:DoApprovePost('{0}', {1});", this.ClientID, this.Post.PostID.ToString());
				Approve.Text = ResourceManager.GetString("ModerationMenu_Approve");
			}

            // Add the ApproveView click event handler.
            //
            if (null != ApproveView) 
            {
                ApproveView.Text = ResourceManager.GetString("ModerationMenu_ApproveView");
                ApproveView.CommandArgument = this.Post.PostID.ToString();
            }

            // Set the EditPost url to the ModeratePostEdit url.
            //
            if (null != EditPost) 
            {
                EditPost.Visible = true;
                // Set the text for the hyperlink
                EditPost.Text = ResourceManager.GetString("ModeratePost_EditPost");
                EditPost.NavigateUrl = Globals.GetSiteUrls().ModeratePostEdit(this.Post.PostID, Globals.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery + "#" + this.Post.PostID.ToString()));
            }

            // Set the DeleteApprovedPost url based on the post level of the post.
            //
			if (null != DeletePost)
			{
				// Set the text for the hyperlink
				//
				if (this.Post.PostLevel == 1) 
					DeletePost.Text = ResourceManager.GetString("ModerationMenu_DeleteThread");
				else
					DeletePost.Text = ResourceManager.GetString("ModerationMenu_DeletePost");

				DeletePost.NavigateUrl = Globals.GetSiteUrls().ModeratePostDelete(this.Post.PostID, Globals.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery));
			}

            // Set the Move url to the ModeratePostMove url if the post level is 1, otherwise disable the move control.
            //
            if (null != Move) 
            {
                if (this.Post.PostLevel == 1) 
                {
                    Move.Text = ResourceManager.GetString("ModeratePost_Move");
                    Move.NavigateUrl = Globals.GetSiteUrls().ModeratePostMove(this.Post.PostID, Globals.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery));
                }
                else
                {
                    Move.Text = Move.Text = ResourceManager.GetString("ModeratePost_Move");
                    Move.NavigateUrl = "";
                    Move.ForeColor = System.Drawing.Color.Gray;
                }
            }

            // Set the Split url to the ModerateThreadSplit url
            //
            if (null != MergeSplit) 
            {
                if (this.Post.PostLevel > 1) 
                {
                    MergeSplit.Text = ResourceManager.GetString("ModerateThread_Split");
                    MergeSplit.NavigateUrl = Globals.GetSiteUrls().ModerateThreadSplit(this.Post.PostID, Globals.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery));
                } 
                else 
                {
                    MergeSplit.NavigateUrl = Globals.GetSiteUrls().ModerateThreadJoin(this.Post.PostID, HttpContext.Current.Request.Url.PathAndQuery);
                    MergeSplit.Text = ResourceManager.GetString("ModerateThread_Join");
                }
            }

            // Toggle Lock / Unlock Post
            //
            if (null != ToggleLockUnlockPost) 
            {
                if (this.Post.PostLevel > 1) 
                {
                    ToggleLockUnlockPost.Visible = false;
                    FindControl("HideLockSpan").Visible = false;
                } 
                else 
                {
                    if (this.Post.IsLocked) 
                    {
                        ToggleLockUnlockPost.Text = ResourceManager.GetString("ModerateThread_UnLock_Thread");
                    } 
                    else 
                    {
                        ToggleLockUnlockPost.Text = ResourceManager.GetString("ModerateThread_Lock_Thread");
                    }
                }

                ToggleLockUnlockPost.CommandArgument = this.Post.PostID.ToString();
            }

            if (canModerate) 
            {
                // set the EditUser url
                //
                if (null != EditUser) 
                {
                    // Set the text for the hyperlink
                    EditUser.Text = ResourceManager.GetString("ModeratePost_EditUser");
                    EditUser.NavigateUrl = Globals.GetSiteUrls().ControlPanelUserEdit(this.Post.User.UserID);
                }
			
                // Toggle Moderate / Unmoderate User
                //
                if (null != ToggleModerateUnModerateUser) 
                {
                    // TODO: Get a fresh copy of user data to have moderation status working right
                    //
                    //User freshUserData = Users.GetUser( this.Post.User.UserID, false, false );
                    //switch (freshUserData.ModerationLevel)

					ToggleModerateUnModerateUser.NavigateUrl = string.Format("javascript:DoToggleModeration('{0}', {1}, '{2}');", this.ClientID, Post.User.UserID.ToString(), ToggleModerateUnModerateUser.ClientID);
                    switch (this.Post.User.ModerationLevel) 
                    {
                        case ModerationLevel.Unmoderated:
                            ToggleModerateUnModerateUser.Text = ResourceManager.GetString("ModerateThread_Moderate_User");

⌨️ 快捷键说明

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