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

📄 createeditpost.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 4 页
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer.Components;
using CommunityServer.Configuration;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;


namespace CommunityServer.Discussions.Controls {

    /// <summary>
    /// This Web control allows the user to create a new post or edit an existing post.
    /// The Mode property determines what action is being taken.  A value of NewPost, the
    /// default, constructs Web controls for creating a new post; a value of ReplyToPost
    /// assumes the person is replying to an existing post; a value of EditPost allows the
    /// user to edit an existing post.
    /// </summary>
    /// <remarks>
    /// When adding a new post, the ForumID must be specified, which indicates what forum the
    /// new post belongs to.  When replying to a post, the PostID property must be specified, indicating
    /// the post that is being replied to.  When editing a post, the PostID property must be
    /// specified, indicating the post to edit.  Failure to specify these required properties
    /// will cause an Exception to be thrown.
    /// </remarks>
    public class CreateEditPost: SkinnedWebControl {

        #region Member Variables
        CSContext csContext   = CSContext.Current;
        string skinFilename	= "View-CreateEditPost.ascx";
        //ViewOptions postView;
        Editor postBody = null;
        
        Forum forum;
        ForumPost postReplyingTo;
        DropDownList pinnedPost;
		//ForumRolloverImageButton allowReply;
        CheckBox isLocked;
        CheckBox subscribeToThread;
        User user;
		TextBox forumsPostedTo;

		HtmlInputFile fileToUpload;
		HyperLink attachmentLink;
		CheckBox deleteAttachment;
		ResourceControl newAttachment;
        CheckBox isAnonymousPost;
        ResourceLabel attachements;
        PostIconRadioButtonList postIcon;
        #endregion

        #region CreateEditPost Constructor
        /// <remarks>
        /// Class contructor used to determine the mode of the server control.
        /// </remarks>
        public CreateEditPost () {

			//fire the authorize post event
			CSEvents.AuthorizePost();

            // Assign a default template name
            //
            if (SkinFilename == null)
                SkinFilename = skinFilename;

            // Get the current user
            //
            user = CSContext.Current.User;

            // Is the user anonymous?
            //
            if (!Context.Request.IsAuthenticated)
                user = Users.GetAnonymousUser();

            // Do we have a PostID?
            //
            if (csContext.PostID > 0) 
            {
                postReplyingTo = Posts.GetPost(csContext.PostID, CSContext.Current.User.UserID);
                forum = postReplyingTo.Section as Forum;
                PostMode = CreateEditPostMode.ReplyToPost;
            }

            // Do we have a ForumID?
            //
            if (csContext.ForumID > 0) 
            {
                forum = Forums.GetForum(csContext.ForumID, false, true, CSContext.Current.User.UserID);
                PostMode = CreateEditPostMode.NewPost;
            }

			// Are we reporting a post?
            //
			if(CSContext.Current.GetIntFromQueryString("ReportPostID",-1) > 0)
				PostMode = CreateEditPostMode.ReportingPost;

            // Is this a private message?
            //
            if ((csContext.ForumID == 0) && (csContext.UserID > 0)) 
            {
                forum = Forums.GetForum(0);
                PostMode = CreateEditPostMode.NewPrivateMessage;
            }

            // Security check to see if the forum allows anonymous posts
            //
            if ( user.IsAnonymous && (!forum.EnableAnonymousPosting || !CSContext.Current.SiteSettings.EnableAnonymousUserPosting) ) 
            {
                if (!csContext.Context.Request.IsAuthenticated) 
                {
                    csContext.Context.Response.Redirect(Globals.GetSiteUrls().Login);
                    csContext.Context.Response.End();
                }
            }

            // If we don't have either a forum id or a post id we have an error
            //
            if ((csContext.ForumID < 0) && (csContext.PostID < 0)) 
            {
                throw new CSException(CSExceptionType.PostNotFound);
            }

            // Is a mode specified?
            //
//            if (null != Context.Request.QueryString["Mode"]) 
//            {
//                string mode = Context.Request.QueryString["Mode"];
//
////                if (mode == "flat")
////                    postView = ViewOptions.Flat;
////                else
////                    postView = ViewOptions.Threaded;
//
//            } 
//            else if (null != Context.Request.Form["Mode"]) 
//            {
//                string mode = Context.Request.Form["Mode"];
//
////                if (mode == "flat")
////                    postView = ViewOptions.Flat;
////                else
////                    postView = ViewOptions.Threaded;
//            }

        }
        #endregion
        
        #region Initialize skin and other display methods

        #region InitializeSkin
        // *********************************************************************
        //  Initializeskin
        //
        /// <remarks>
        /// Initialize the control template and populate the control with values
        /// </remarks>
        // ***********************************************************************/
        override protected void InitializeSkin (Control skin) {

			skin.FindControl("Icons").Visible = (csContext.SiteSettings.EnableEmoticons && csContext.User.Profile.EnableEmoticons);
            // Is the post locked checkbox
            //
            isLocked = (CheckBox) skin.FindControl("IsLocked");
            isLocked.Text = ResourceManager.GetString("CreateEditPost_IsLocked");
            
            // Get anonymous posting reference
            //
            isAnonymousPost = (CheckBox) skin.FindControl( "IsAnonymousPost" );
            isAnonymousPost.Text = ResourceManager.GetString( "CreateEditPost_IsAnonymousPost" );
            
            // Is anonymous posting enabled?
            //
            if (CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous && 
                forum.EnableAnonymousPostingForUsers) {

                isAnonymousPost.Visible = true;
            } else { 
                isAnonymousPost.Visible = false;
            }

            // If we aren't using Emoticons do not render them.
            if (CSContext.Current.SiteSettings.EnableEmoticons) {
                postIcon = (PostIconRadioButtonList) skin.FindControl( "PostIcon" );
                postIcon.AutoCreate = false;

                //if (!Page.IsPostBack)
                    postIcon.DataBind();
            }

			// Get the attachment controls
			//
			fileToUpload = (HtmlInputFile)skin.FindControl("fileToUpload");
			attachmentLink = (HyperLink)skin.FindControl("fileAttachment");
			deleteAttachment = (CheckBox)skin.FindControl("deleteFileAttachment");
			newAttachment = (ResourceControl)skin.FindControl("newAttachment");
            attachements = (ResourceLabel) skin.FindControl("attachements");

            // Does the user wish to subscribe to threads checkbox
            //
            if (!user.IsAnonymous) {
                subscribeToThread = (CheckBox) skin.FindControl("SubscribeToThread");
                subscribeToThread.Text = ResourceManager.GetString("CreateEditPost_SubscribeToThread");

                subscribeToThread.Checked = user.EnableThreadTracking;
				subscribeToThread.Visible = user.EnableThreadTracking;
            } 
            else {
				subscribeToThread = (CheckBox) skin.FindControl("SubscribeToThread");
				subscribeToThread.Checked = false;
                subscribeToThread.Visible = false;
                
                // Make it unavailable for anonymous users
                //
                isAnonymousPost.Visible = false;
            }

            // Set the ID
            //
            skin.ID = "PostForm";

			if ((PostMode == CreateEditPostMode.ReplyToPost) && (forum.SectionID == 0))
				PostMode = CreateEditPostMode.ReplyPrivateMessage;

			
            // Optionally display reply, post, and preview
            //
            switch (PostMode) {
                case CreateEditPostMode.NewPrivateMessage:
                    DisplayPost(skin);
                    DisplayPreview(skin);
                    break;

				case CreateEditPostMode.ReplyPrivateMessage:
				case CreateEditPostMode.ReplyToPost:
					DisplayReply(skin);
					DisplayPost(skin);
					DisplayPreview(skin);
					break;

                default:
                    DisplayPost(skin);
                    DisplayPreview(skin);
                    break;
            }

			// Check if flood interval is enabled and if the user needs to wait.
			//
			if ((PostMode == CreateEditPostMode.NewPost) || (PostMode == CreateEditPostMode.ReplyToPost))
				if(CSContext.Current.SiteSettings.EnableFloodIntervalChecking && !user.IsForumAdministrator)
					if(!Users.CheckUserLastPostDate(user))
						throw new CSException(CSExceptionType.FloodDenied);

        }
        #endregion
        
        #region DisplayPost
        /***********************************************************************
        // DisplayPost
        //
        /// <remarks>
        /// When a user replies to a post, the user control that controls the UI
        /// is loaded and passed to this method. Elements of the form are then wired
        /// up to handle events, such as button clicks
        /// </remarks>
        /// <param name="control">Usercontrol used to control UI formatting</param>
        ***********************************************************************/
        private void DisplayPost (Control skin) {            
            ForumPost post          = null;
            bool isQuote            = false;
            string replyPrePend     = ResourceManager.GetString("CreateEditPost_ReplyPrePend");
			Label title = skin.FindControl("ForumName") as Label;
			Label desc = skin.FindControl("ForumDescription") as Label;
            //RadioButtonList postIcon;
            bool allowAttachment = this.AllowAttachments; // call this only one in this method

            // Are we quoting another post?
            //
            if (csContext.Context.Request.QueryString["Quote"] != null) 
            {                				
                isQuote = true;
            }

            if (isQuote || ((PostMode == CreateEditPostMode.ReplyToPost) || (PostMode == CreateEditPostMode.ReplyPrivateMessage)))
            {
                post = Posts.GetPost(csContext.PostID, CSContext.Current.User.UserID);
            }

            User user = CSContext.Current.User;

            // Is the user allowed to add new attachments?
            //
            if (allowAttachment) {

                if (skin.FindControl("editAttachment") != null) {
                    // These will be overriden only on EditPost
                    //
                    skin.FindControl("editAttachment").Visible = true;

                    if (newAttachment != null)
                        newAttachment.Visible = true;

                    if (fileToUpload != null)
                        fileToUpload.Visible = true;

                    if (attachmentLink != null)
                        attachmentLink.Visible = false;

                    if (deleteAttachment != null)
                        deleteAttachment.Visible = false;
                }
            }

            // Set the title message
            //
            switch (PostMode) 
            {
                case CreateEditPostMode.NewPost:
                    // Access Check
                    Permissions.AccessCheck(forum, Permission.Post, user);
					title.Text = ResourceManager.GetString("CreateEditPost_Title_PostNewMessage");
					desc.Text = ResourceManager.GetString("CreateEditPost_Title_PostNewMessageDesc");

                    break;

                case CreateEditPostMode.NewPrivateMessage:
                    skin.FindControl("MessageTo").Visible = true;
                    break;

				case CreateEditPostMode.ReplyPrivateMessage:
                case CreateEditPostMode.ReplyToPost:
                    // Access Check
                    if (post != null) Permissions.AccessCheck(forum, Permission.Reply, user, post);
					title.Text = ResourceManager.GetString("CreateEditPost_Title_ReplyMessage");
					desc.Text = string.Format(ResourceManager.GetString("CreateEditPost_Inline1"), post.Subject);
					

⌨️ 快捷键说明

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