/// <summary> /// Initialize resources, holders, controls etc. /// </summary> protected void Initialize() { #region "Captcha" // Hide captcha when not needed if (!ForumContext.CurrentForum.ForumUseCAPTCHA || (ForumContext.CurrentState == ForumStateEnum.EditPost)) { plcCaptcha.Visible = false; } #endregion #region "Settings of HTML editor" // Set HTML editor properties htmlTemplateBody.AutoDetectLanguage = false; htmlTemplateBody.DefaultLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; htmlTemplateBody.EditorAreaCSS = ""; htmlTemplateBody.ToolbarSet = "Forum"; htmlTemplateBody.DisableObjectResizing = true; // Disable image resizing htmlTemplateBody.RemovePlugins.Add("contextmenu"); // Disable context menu htmlTemplateBody.IsLiveSite = IsLiveSite; htmlTemplateBody.MediaDialogConfig.UseFullURL = true; htmlTemplateBody.LinkDialogConfig.UseFullURL = true; #endregion #region "Resource strings" // Resources rfvSubject.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.subjectErrorMsg"); lblText.Text = GetString("Forums_WebInterface_ForumNewPost.text"); rfvText.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.textErrorMsg"); rfvUserName.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.usernameErrorMsg"); btnOk.Text = GetString("general.ok"); btnCancel.Text = GetString("general.cancel"); btnPreview.Text = GetString("Forums_WebInterface_ForumNewPost.Preview"); lblSubscribe.Text = GetString("Forums_WebInterface_ForumNewPost.Subscription"); lblSignature.Text = GetString("Forums_WebInterface_ForumNewPost.Signature"); lblCaptcha.Text = GetString("Forums_WebInterface_ForumNewPost.captcha"); lblAttachFile.Text = GetString("For.NewPost.Attach"); lblNickName.Text = GetString("Forums_WebInterface_ForumNewPost.NickName"); // WAI validation lblCaptcha.AssociatedControlClientID = SecurityCode1.InputClientID; #endregion #region "Controls visibility" ForumInfo fi = ForumContext.CurrentForum; // Hide or display html editor/ text area if (fi.ForumHTMLEditor) { ucBBEditor.Visible = false; rfvText.Enabled = false; // Define customizable shortcuts Hashtable keystrokes = new Hashtable() { { "link", "CKEDITOR.CTRL + 76 /*L*/" }, { "bold", "CKEDITOR.CTRL + 66 /*B*/" }, { "italic", "CKEDITOR.CTRL + 73 /*I*/" }, { "underline", "CKEDITOR.CTRL + 85 /*U*/" } }; if (!fi.ForumEnableURL) { htmlTemplateBody.RemoveButtons.Add("InsertUrl"); if (!fi.ForumEnableAdvancedURL) { // Remove the keyborad shortcut for the link insertion keystrokes.Remove("link"); } } if (!fi.ForumEnableAdvancedURL) { htmlTemplateBody.RemoveButtons.Add("InsertLink"); } if (!fi.ForumEnableImage) { htmlTemplateBody.RemoveButtons.Add("InsertImage"); } if (!fi.ForumEnableAdvancedImage) { htmlTemplateBody.RemoveButtons.Add("InsertImageOrMedia"); } if (!fi.ForumEnableQuote) { htmlTemplateBody.RemoveButtons.Add("InsertQuote"); } if (!fi.ForumEnableFontBold) { htmlTemplateBody.RemoveButtons.Add("Bold"); keystrokes.Remove("bold"); } if (!fi.ForumEnableFontItalics) { htmlTemplateBody.RemoveButtons.Add("Italic"); keystrokes.Remove("italic"); } if (!fi.ForumEnableFontUnderline) { htmlTemplateBody.RemoveButtons.Add("Underline"); keystrokes.Remove("underline"); } if (!fi.ForumEnableFontStrike) { htmlTemplateBody.RemoveButtons.Add("Strike"); } if (!fi.ForumEnableFontColor) { htmlTemplateBody.RemoveButtons.Add("TextColor"); htmlTemplateBody.RemoveButtons.Add("BGColor"); } // Generate keystrokes string for the CK Editor StringBuilder sb = new StringBuilder("[ [ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ], [ CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ], [ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ], [ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ], [ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ], [ CKEDITOR.ALT + ( CKEDITOR.env.ie || CKEDITOR.env.webkit ? 189 : 109 ) /*-*/, 'toolbarCollapse' ], [ CKEDITOR.ALT + 48 /*0*/, 'a11yHelp' ]"); string format = ", [ {0}, '{1}' ]"; foreach (DictionaryEntry entry in keystrokes) { sb.Append(String.Format(format, entry.Value, entry.Key)); } sb.Append("]"); htmlTemplateBody.Keystrokes = sb.ToString(); } else { ucBBEditor.IsLiveSite = IsLiveSite; ucBBEditor.ShowImage = fi.ForumEnableImage; ucBBEditor.ShowQuote = fi.ForumEnableQuote; ucBBEditor.ShowURL = fi.ForumEnableURL; ucBBEditor.ShowBold = fi.ForumEnableFontBold; ucBBEditor.ShowItalic = fi.ForumEnableFontItalics; ucBBEditor.ShowUnderline = fi.ForumEnableFontUnderline; ucBBEditor.ShowStrike = fi.ForumEnableFontStrike; ucBBEditor.ShowColor = fi.ForumEnableFontColor; ucBBEditor.ShowCode = fi.ForumEnableCodeSnippet; ucBBEditor.ShowAdvancedImage = fi.ForumEnableAdvancedImage; ucBBEditor.ShowAdvancedURL = fi.ForumEnableAdvancedURL; htmlTemplateBody.Visible = false; } if ((fi.ForumModerated) && (!ForumContext.UserIsModerator(fi.ForumID, CommunityGroupID))) { ShowInformation(GetString("forums.requiremoderation")); } bool userCanModerate = fi.ForumModerated && ForumContext.UserIsModerator(fi.ForumID, CommunityGroupID); if ((MembershipContext.AuthenticatedUser.IsPublic()) || (!ForumInfoProvider.IsAuthorizedPerForum(fi.ForumID, fi.ForumGroupID, "AttachFiles", fi.AllowAttachFiles, MembershipContext.AuthenticatedUser) && !userCanModerate)) { plcAttachFile.Visible = false; } // If user can choose thread type and this is not reply, show the options if ((fi.ForumType == 0) && (ForumContext.CurrentReplyThread == null)) { // Only thread can be set if ((ForumContext.CurrentState != ForumStateEnum.EditPost) || (ForumContext.CurrentPost.PostLevel == 0)) { plcThreadType.Visible = true; } } // Hide or display subscription checkbox with dependence // on allow subscription property value and security if ((!AllowSubscription) || (!ForumInfoProvider.IsAuthorizedPerForum(fi.ForumID, fi.ForumGroupID, "Subscribe", fi.AllowSubscribe, MembershipContext.AuthenticatedUser))) { SubscribeHolder.Visible = false; } // Display signature if is allowed if (!AllowSignature) { plcSignature.Visible = false; } // Display username textbox if is change name allowed or label with user name if (fi.ForumAllowChangeName || MembershipContext.AuthenticatedUser.IsPublic() || ((ForumContext.CurrentForum != null) && (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, ForumContext.CommunityGroupID)))) { if (!RequestHelper.IsPostBack()) { // Do not show 'public' for unauthenticated user if (!MembershipContext.AuthenticatedUser.IsPublic()) { txtUserName.Text = UserName; } } plcNickName.Visible = false; } else { if (ForumContext.CurrentMode != ForumMode.Edit) { lblNickNameValue.Text = HTMLHelper.HTMLEncode(UserName); } else { lblNickNameValue.Text = HTMLHelper.HTMLEncode(ForumContext.CurrentPost.PostUserName); } plcUserName.Visible = false; } // Prefill user email and reset the security code if (!RequestHelper.IsPostBack()) { txtEmail.Text = MembershipContext.AuthenticatedUser.Email; } if (ForumContext.CurrentReplyThread != null) { string replyPrefix = GetString("forums.replyprefix"); if (!ForumContext.CurrentReplyThread.PostSubject.StartsWithCSafe(replyPrefix)) { txtSubject.Text = replyPrefix + ForumContext.CurrentReplyThread.PostSubject; txtSubject.Text = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, ""); } else { txtSubject.Text = ForumContext.CurrentReplyThread.PostSubject; } txtSubject.Text = txtSubject.Text; // New post - check max level for subscribcribtion if (ForumContext.CurrentReplyThread.PostLevel >= ForumPostInfoProvider.MaxPostLevel - 1) { SubscribeHolder.Visible = false; } } // Edit post - check max level for subscribcribtion else if ((ForumContext.CurrentPost != null) && (ForumContext.CurrentPost.PostLevel >= ForumPostInfoProvider.MaxPostLevel)) { SubscribeHolder.Visible = false; } // Hide subscription if not enabled if (!EnableSubscription) { SubscribeHolder.Visible = false; } #endregion #region "Post Data" if (!RequestHelper.IsPostBack()) { // Check whether current state is edit if (ForumContext.CurrentState == ForumStateEnum.EditPost) { txtEmail.Text = ForumContext.CurrentPost.PostUserMail; txtSignature.Text = ForumContext.CurrentPost.PostUserSignature; txtSubject.Text = ForumContext.CurrentPost.PostSubject; txtUserName.Text = ForumContext.CurrentPost.PostUserName; SetPostText(ForumContext.CurrentPost.PostText); radTypeDiscussion.Checked = true; if (ForumContext.CurrentPost.PostType == 1) { radTypeQuestion.Checked = true; } } else if ((ForumContext.CurrentMode == ForumMode.Quote) && (ForumContext.CurrentReplyThread != null)) { // Indicates whether wysiwyg editor is used bool isHtml = ForumContext.CurrentForum.ForumHTMLEditor; // Keeps post user name string userName = ForumContext.CurrentReplyThread.PostUserName; // Encode username for wysiwyg editor if (isHtml) { userName = HTMLHelper.HTMLEncode(userName); } SetPostText(DiscussionMacroResolver.GetQuote(userName, ForumContext.CurrentReplyThread.PostText)); // Set new line after if (isHtml) { htmlTemplateBody.ResolvedValue += "<br /><br />"; } else { ucBBEditor.Text += "\n"; } } } #endregion }
/// <summary> /// Check permissions. /// </summary> /// <param name="state">Current state</param> public ForumStateEnum CheckPermissions(ForumStateEnum state) { // Return original state for selected types if ((state == ForumStateEnum.Forums) || (state == ForumStateEnum.Unknown) || (state == ForumStateEnum.Search)) { return(state); } // If forum doesn't exist display default if (ForumContext.CurrentForum == null) { return(ForumStateEnum.Forums); } // If forum is closed => hide if ((!IsAdHocForum) && (!ForumContext.CurrentForum.ForumOpen)) { return(ForumStateEnum.Forums); } // Sets threads state for every action if forum is locked if (ForumContext.CurrentForum.ForumIsLocked) { switch (state) { case ForumStateEnum.NewSubscription: case ForumStateEnum.NewThread: case ForumStateEnum.ReplyToPost: case ForumStateEnum.SubscribeToPost: return(ForumStateEnum.Threads); // Allow attachment view for forum moderators case ForumStateEnum.Attachments: if (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID)) { return(state); } return(ForumStateEnum.Threads); } } // If user is global admin, forum admin, community admin or moderator if (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID)) { return(state); } // Sets thread state for locked post if ((ForumContext.CurrentThread != null) && (ForumContext.CurrentThread.PostIsLocked)) { if (!ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID)) { switch (state) { case ForumStateEnum.NewSubscription: case ForumStateEnum.SubscribeToPost: case ForumStateEnum.NewThread: case ForumStateEnum.ReplyToPost: case ForumStateEnum.Attachments: return(ForumStateEnum.Thread); } } } bool hasPermissions = true; // Check permissions for action switch (state) { case ForumStateEnum.ReplyToPost: hasPermissions = ForumInfoProvider.IsAuthorizedPerForum(ForumContext.CurrentForum.ForumID, ForumContext.CurrentForum.ForumGroupID, "Reply", ForumContext.CurrentForum.AllowReply, MembershipContext.AuthenticatedUser); break; case ForumStateEnum.NewThread: hasPermissions = ForumInfoProvider.IsAuthorizedPerForum(ForumContext.CurrentForum.ForumID, ForumContext.CurrentForum.ForumGroupID, "Post", ForumContext.CurrentForum.AllowPost, MembershipContext.AuthenticatedUser); break; case ForumStateEnum.Attachments: hasPermissions = ForumInfoProvider.IsAuthorizedPerForum(ForumContext.CurrentForum.ForumID, ForumContext.CurrentForum.ForumGroupID, "AttachFiles", ForumContext.CurrentForum.AllowAttachFiles, MembershipContext.AuthenticatedUser); break; case ForumStateEnum.TopicMove: hasPermissions = ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID); break; case ForumStateEnum.SubscribeToPost: case ForumStateEnum.NewSubscription: hasPermissions = ForumInfoProvider.IsAuthorizedPerForum(ForumContext.CurrentForum.ForumID, ForumContext.CurrentForum.ForumGroupID, "Subscribe", ForumContext.CurrentForum.AllowSubscribe, MembershipContext.AuthenticatedUser) && EnableSubscription; break; case ForumStateEnum.EditPost: hasPermissions = ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID) || (ForumContext.CurrentForum.ForumAuthorEdit && (ForumContext.CurrentPost != null && !MembershipContext.AuthenticatedUser.IsPublic() && (ForumContext.CurrentPost.PostUserID == MembershipContext.AuthenticatedUser.UserID))); break; } // Check ForumAccess permission if (ForumContext.CurrentForum != null) { hasPermissions = hasPermissions && ForumInfoProvider.IsAuthorizedPerForum(ForumContext.CurrentForum.ForumID, ForumContext.CurrentForum.ForumGroupID, "AccessToForum", ForumContext.CurrentForum.AllowAccess, MembershipContext.AuthenticatedUser); } // Check whether user has permissions for selected state if (!hasPermissions) { // Check whether public user should be redirected to logon page if (RedirectUnauthorized && MembershipContext.AuthenticatedUser.IsPublic()) { URLHelper.Redirect(URLHelper.AddParameterToUrl(ResolveUrl(LogonPageURL), "returnurl", HttpUtility.UrlEncode(RequestContext.CurrentURL))); } else if (!String.IsNullOrEmpty(AccessDeniedPageURL)) { URLHelper.Redirect(URLHelper.AddParameterToUrl(ResolveUrl(AccessDeniedPageURL), "returnurl", HttpUtility.UrlEncode(RequestContext.CurrentURL))); } // Sets state with dependence on current settings else { if (startingMode == 0) { return(ForumStateEnum.Forums); } else { return(ForumStateEnum.AccessDenied); } } } return(state); }