📄 createeditpost.cs
字号:
break;
case CreateEditPostMode.ReportingPost:
// Access Check
break;
case CreateEditPostMode.EditPost:
if(postReplyingTo.PostType == PostType.Poll)
{
if(!Globals.IsNullorEmpty(csContext.ReturnUrl))
Context.Response.Redirect(csContext.ReturnUrl);
else
Context.Response.Redirect(Globals.GetSiteUrls().Home);
}
Permissions.AccessCheck(forum,Permission.Edit,CSContext.Current.User,postReplyingTo);
title.Text = ResourceManager.GetString("CreateEditPost_Title_EditMessage");
desc.Text = string.Format(ResourceManager.GetString("CreateEditPost_Title_EditMessageDesc"), postReplyingTo.Subject);
// Set the editor of the post
if (skin.FindControl("PostEditor") != null)
((Label) skin.FindControl("PostEditor")).Text = user.Username;
// Set the editor of the post
if (skin.FindControl("Edit") != null)
skin.FindControl("Edit").Visible = true;
// Is the post locked?
if (postReplyingTo.IsLocked)
isLocked.Checked = true;
// Set the isLocked Text
isLocked.Text = ResourceManager.GetString("CreateEditPost_IsLocked");
// Show the attachment area, if there already is one
if (allowAttachment && postReplyingTo.HasAttachment) {
if (skin.FindControl("editAttachment") != null) {
//skin.FindControl("editAttachment").Visible = true;
if (fileToUpload != null)
fileToUpload.Visible = false;
if (newAttachment != null)
newAttachment.Visible = false;
if (attachements != null)
attachements.Visible = true;
if (attachmentLink != null) {
attachmentLink.Visible = true;
attachmentLink.Text = postReplyingTo.AttachmentFilename;
attachmentLink.NavigateUrl = Globals.GetSiteUrls().PostAttachment(postReplyingTo.PostID);
}
if (deleteAttachment != null) {
deleteAttachment.Visible = true;
deleteAttachment.Text = ResourceManager.GetString("CreateEditPost_DeleteAttachment");
//deleteAttachment.AutoPostBack = true;
//deleteAttachment.CheckedChanged += new EventHandler(DeleteAttachment_CheckedChanged);
}
}
}
// Set the Subject
if (skin.FindControl("PostSubject") != null) {
((TextBox) skin.FindControl("PostSubject")).Text = csContext.Context.Server.HtmlDecode(postReplyingTo.Subject);
}
postBody = skin.FindControl("PostBody") as Editor;
postBody.Text = postReplyingTo.Body;
// Check if post was anonymous and set it so
//
if (isAnonymousPost.Visible && !Page.IsPostBack) {
isAnonymousPost.Checked = postReplyingTo.IsAnonymousPost;
}
// Do we have a post icon?
//
if (postIcon != null && !Page.IsPostBack)
postIcon.SelectedValue = postReplyingTo.EmoticonID.ToString();
break;
}
// Set the subject if necessary
//
if ((PostMode == CreateEditPostMode.ReplyToPost) || (PostMode == CreateEditPostMode.ReplyPrivateMessage))
{
// Do we need to prepend, e.g. 'Re: '?
//
if (post.Subject.StartsWith(replyPrePend))
((TextBox) skin.FindControl("PostSubject")).Text = Globals.HtmlDecode(post.Subject);
else
((TextBox) skin.FindControl("PostSubject")).Text = replyPrePend + Globals.HtmlDecode(post.Subject);
}
// Set the to if necessary
if (PostMode == CreateEditPostMode.NewPrivateMessage) {
skin.FindControl("MessageTo").Visible = true;
((TextBox) skin.FindControl("To")).Text = Users.GetUser( CSContext.Current.UserID, false ).Username;
}
if (PostMode == CreateEditPostMode.ReplyPrivateMessage) {
skin.FindControl("MessageTo").Visible = true;
((TextBox) skin.FindControl("To")).Text = PrivateMessages.GetFormattedRecipients(post.ThreadID, post.User, user.UserID);
}
if(PostMode == CreateEditPostMode.ReplyPrivateMessage || PostMode == CreateEditPostMode.NewPrivateMessage)
{
subscribeToThread.Visible = false;
subscribeToThread.Checked = false;
}
// Set the Body
//
postBody = skin.FindControl("PostBody") as Editor;
postBody.EnableHtmlModeEditing = user.IsForumAdministrator;
// Set forums we are posting to
//
forumsPostedTo = skin.FindControl("Forums") as TextBox;
forumsPostedTo.Text = forum.Name;
forumsPostedTo.ReadOnly = true;
// If we are quoting a previous post, display that post
//
if (isQuote)
postBody.Text = "[quote user=\"" + post.User.Username + "\"]" + post.Body + "[/quote]";
// Set the Username
if (skin.FindControl("PostAuthor") != null)
((Label) skin.FindControl("PostAuthor")).Text = user.Username;
EnableSticky( skin, postReplyingTo );
// Wireup the preview button
if (skin.FindControl("PreviewButton").GetType().UnderlyingSystemType.ToString() == typeof(Button).ToString() )
{
Button button = (Button) skin.FindControl("PreviewButton");
button.Text = ResourceManager.GetString("CreateEditPost_PreviewButton");
button.Click += new System.EventHandler(PreviewButton_Click);
}
else
{
ForumRolloverImageButton button = (ForumRolloverImageButton) skin.FindControl("PreviewButton");
button.Alt = ResourceManager.GetString("CreateEditPost_PreviewButton");
button.Click += new System.EventHandler(PreviewButton_Click);
}
// Wireup the post button
if (skin.FindControl("PostButton").GetType().UnderlyingSystemType.ToString() == typeof(Button).ToString() )
{
Button button = (Button) skin.FindControl("PostButton");
button.Text = ResourceManager.GetString("CreateEditPost_PostButton");
button.Click += new System.EventHandler(PostButton_Click);
}
else
{
ForumRolloverImageButton button = (ForumRolloverImageButton) skin.FindControl("PostButton");
button.Alt = ResourceManager.GetString("CreateEditPost_PostButton");
button.Click += new System.EventHandler(PostButton_Click);
}
// Wire up the cancel button
if (skin.FindControl("CancelButton") != null)
{
Button button = (Button) skin.FindControl("CancelButton");
button.Text = ResourceManager.GetString("CreateEditPost_Cancel");
button.Click += new System.EventHandler(CancelButton_Click);
}
}
#endregion
#region EnableSticky
private void EnableSticky (Control skin, ForumPost post) {
// Is the user allowed to create sticky posts?
//
if (!user.IsAnonymous) {
// Do we allow the user to make pinned posts?
if ((
(user.IsForumAdministrator)
|| (Permissions.ValidatePermissions( forum, Permission.Sticky, user ))
|| (CommunityServer.Discussions.Moderate.IsForumModerator(user, forum.GroupID, forum.SectionID))
)
&& (PostMode != CreateEditPostMode.ReplyToPost))
{
skin.FindControl("AllowPinnedPosts").Visible = true;
pinnedPost = (DropDownList) skin.FindControl("PinnedPost");
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_0"), "0" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_1"), "1" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_3"), "3" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_7"), "7" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_14"), "14" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_30"), "30" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_90"), "90" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_180"), "180" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_360"), "366" ));
pinnedPost.Items.Add(new ListItem( ResourceManager.GetString("CreateEditPost_Sticky_999"), "999" ));
// Do an autopost back incase we need to flip the isLocked checkbox
pinnedPost.AutoPostBack = true;
pinnedPost.SelectedIndexChanged += new System.EventHandler(PinnedPost_Changed);
// If we're editing a post, populate with the previous sticky setting
if(PostMode == CreateEditPostMode.EditPost && post != null)
{
Thread thread = Threads.GetThread(post.ThreadID);
if(thread != null && thread.IsSticky)
{
// Get time span for 2 years
TimeSpan anouncementTsp = (DateTime.Now - DateTime.Now.AddYears( -2 ));
TimeSpan remainder = thread.StickyDate.Subtract(DateTime.Now);
// The check is +1 day, since it is set for midnight and can sometimes be up to one day extra
if(remainder <= TimeSpan.FromDays(2))
pinnedPost.Items.FindByValue("1").Selected = true;
else if(remainder <= TimeSpan.FromDays(4))
pinnedPost.Items.FindByValue("3").Selected = true;
else if(remainder <= TimeSpan.FromDays(8))
pinnedPost.Items.FindByValue("7").Selected = true;
else if(remainder <= TimeSpan.FromDays(15))
pinnedPost.Items.FindByValue("14").Selected = true;
else if(remainder <= TimeSpan.FromDays(31))
pinnedPost.Items.FindByValue("30").Selected = true;
else if(remainder <= TimeSpan.FromDays(91))
pinnedPost.Items.FindByValue("90").Selected = true;
else if(remainder <= TimeSpan.FromDays(181))
pinnedPost.Items.FindByValue("180").Selected = true;
else if(remainder <= TimeSpan.FromDays(367))
pinnedPost.Items.FindByValue("366").Selected = true;
else {
if(remainder >= TimeSpan.FromDays( anouncementTsp.Days )) // this should be an anouncement
pinnedPost.Items.FindByValue("999").Selected = true;
}
}
}
}
}
}
#endregion
#region DisplayPreview
/***********************************************************************
// DisplayPreview
//
/// <remarks>
/// Displays a preview of a user's post to a message.
/// </remarks>
/// <param name="control">Usercontrol used to control UI formatting</param>
***********************************************************************/
private void DisplayPreview (Control skin) {
Button button;
// Wire up the back button
button = (Button) skin.FindControl("EditButton");
button.Text = ResourceManager.GetString("CreateEditPost_BackButton");
button.Click += new System.EventHandler(BackButton_Click);
}
#endregion
#region DisplayReply
/***********************************************************************
// DisplayReply
//
/// <remarks>
/// When a user replies to a post, the user control that controls the UI
/// is loaded and passed to this method. Details such as the username, subject,
/// and message are extracted and displayed.
/// </remarks>
/// <param name="control">Usercontrol used to control UI formatting</param>
***********************************************************************/
private void DisplayReply (Control control) {
//ForumPost post = null;
Literal postBody;
Literal postDetails;
if((PostMode == CreateEditPostMode.NewPost) ||
(PostMode == CreateEditPostMode.ReportingPost) ||
(PostMode == CreateEditPostMode.EditPost))
return;
// Turn off then we deal with a pool
if (postReplyingTo.PostType == PostType.Poll)
return;
control.FindControl("Reply").Visible = true;
// Set the post body
postBody = control.FindControl("ReplyBody") as Literal;
postBody.Text = postReplyingTo.FormattedBody;
bool swowUserAsAnonymous = (postReplyingTo.IsAnonymousPost && CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous && forum.EnableAnonymousPostingForUsers);
string username = "";
if (!swowUserAsAnonymous)
username = postReplyingTo.Username;
else
username = ResourceManager.GetString("DefaultAnonymousUsername");
postDetails = control.FindControl("ReplyDetails") as Literal;
postDetails.Text = username + " wrote the following post at " + Formatter.FormatDate(postReplyingTo.PostDate, true) + ":";
// Access check
//
Permissions.AccessCheck(forum, Permission.Reply, CSContext.Current.User, postReplyingTo);
// Don't allow replies to locked posts
if (postReplyingTo.IsLocked) {
HttpContext.Current.Response.Redirect(Globals.GetSiteUrls().Post(csContext.PostID));
HttpContext.Current.Response.End();
}
/* There is no need to load again user and post details
User user = CSContext.Current.User;
control.FindControl("Reply").Visible = true;
// Read in information about the post we are replying to
post = Posts.GetPost(csContext.PostID, user.UserID);
// Set the post body
postBody = control.FindControl("ReplyBody") as Literal;
postBody.Text = post.FormattedBody;
bool swowUserAsAnonymous = (postReplyingTo.IsAnonymousPost && CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous && forum.EnableAnonymousPostingForUsers);
string username = "";
if (!swowUserAsAnonymous)
username = post.Username; //postReplyingTo.Username;
else
username = ResourceManager.GetString("DefaultAnonymousUsername");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -