protected void Page_Load(object sender, EventArgs e) { string currentForumPost = ""; string[] post = QueryHelper.GetString("postid", "").Split(';'); postId = ValidationHelper.GetInteger(post[0], 0); if (post.Length >= 2) { forumId = ValidationHelper.GetInteger(post[1], 0); this.postListing.ForumId = forumId; } // Show current post postInfo = ForumPostInfoProvider.GetForumPostInfo(postId); if (postInfo != null) { currentForumPost = HTMLHelper.HTMLEncode(postInfo.PostSubject); this.postListing.PostInfo = postInfo; } // If not post, show current forum else if (forumId > 0) { ForumInfo fi = ForumInfoProvider.GetForumInfo(forumId); if (fi != null) { currentForumPost = fi.ForumDisplayName; } } this.postListing.IsLiveSite = false; this.InitializeMasterPage(currentForumPost); }
/// <summary> /// Reloads the form data. /// </summary> public override void ReloadData() { hdnPost.Value = null; postId = 0; post = null; DisplayControl("new"); }
/// <summary> /// Handles the Click event of the btnApprove control. /// </summary> protected void btnApprove_Click(object sender, EventArgs e) { // Check permissions if (!CheckPermissions("cms.forums", PERMISSION_MODIFY)) { return; } // Approve the post ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(ValidationHelper.GetInteger(PostID, 0)); if (fpi != null) { fpi.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; fpi.PostApproved = true; ForumPostInfoProvider.SetForumPostInfo(fpi); } // Reload the parent window RefreshParentWindow(); }
protected void postEdit_OnCheckPermissions(string permissionType, CMSAdminControl sender) { int groupId = 0; ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(postEdit.EditPostID); if (fpi != null) { ForumInfo fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID); if (fi != null) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { groupId = fgi.GroupGroupID; } } } // Check permissions CheckPermissions(groupId, CMSAdminControl.PERMISSION_MANAGE); }
/// <summary> /// Approve, reject or delete post. /// </summary> protected void gridApprove_OnAction(string actionName, object actionArgument) { switch (actionName.ToLowerCSafe()) { case "deletepost": ForumPostInfoProvider.DeleteForumPostInfo(ValidationHelper.GetInteger(actionArgument, 0)); break; case "approve": ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(ValidationHelper.GetInteger(actionArgument, 0)); if (fpi != null) { fpi.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; fpi.PostApproved = true; ForumPostInfoProvider.SetForumPostInfo(fpi); } break; } RaiseOnAction(actionName, actionArgument); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> protected void Page_Load(object sender, EventArgs e) { // Get postId, groupId postId = QueryHelper.GetInteger("postid", 0); groupId = 0; ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(postId); if (fpi != null) { ForumInfo fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID); if (fi != null) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { groupId = fgi.GroupGroupID; } } } // Check permissions CheckGroupPermissions(groupId, "Read"); if (groupId > 0) { // Set the post ID PostApprove.PostID = postId; PostApproveFooter.PostID = postId; // Set methods which check the permissions PostApprove.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(PostApprove_OnCheckPermissions); PostApproveFooter.OnCheckPermissions += new CMSAdminControl.CheckPermissionsEventHandler(PostApprove_OnCheckPermissions); // Page title this.CurrentMaster.Title.TitleText = GetString("forums_forumnewpost_header.preview"); this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Forums_ForumPost/object.png"); } }
/// <summary> /// Preview click handler. /// </summary> protected void btnPreview_Click(object sender, EventArgs e) { ForumPostInfo fp = new ForumPostInfo(); fp.PostUserMail = txtEmail.Text; fp.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); fp.PostText = ucBBEditor.Text; if (fi.ForumHTMLEditor) { fp.PostText = htmlTemplateBody.ResolvedValue; } fp.PostTime = DateTime.Now; fp.PostSubject = txtSubject.Text; fp.PostUserSignature = txtSignature.Text; fp.PostForumID = (editPi != null) ? editPi.PostForumID : ForumID; fp.PostUserID = (editPi != null) ? editPi.PostUserID : CMSContext.CurrentUser.UserID; if (replyPi != null) { fp.PostLevel = replyPi.PostLevel + 1; } ForumPost1.DisplayOnly = true; ForumPost1.PostData = fp.Generalized.DataClass; pnlReplyPost.Visible = true; lblHeader.Text = GetString("Forums_ForumNewPost_Header.Preview"); // Fire the event if (OnPreview != null) { OnPreview(this, null); } }
/// <summary> /// Deletes forum post. Called when the "Delete post" button is pressed. /// Expects the CreateForumPost method to be run first. /// </summary> private bool DeleteForumPost() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10; // Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(posts)) { // Get the forum post ForumPostInfo deletePost = new ForumPostInfo(posts.Tables[0].Rows[0]); // Delete the forum post ForumPostInfoProvider.DeleteForumPostInfo(deletePost); return(true); } return(false); }
/// <summary> /// Renders ForumPost control for specified node. /// </summary> /// <param name="postRow">Forum post data row</param> /// <param name="sbRendered">String builder instance containing rendered text of control</param> private string DynamicForumPostRender(DataRow postRow, out StringBuilder sbRendered) { // Create detail of post to string sbRendered = new StringBuilder(); string mId = ""; ForumPostInfo fpi = new ForumPostInfo(postRow); if (ShowMode != ShowModeEnum.TreeMode) { StringWriter sw = new StringWriter(sbRendered); Html32TextWriter writer = new Html32TextWriter(sw); ForumViewer post = (ForumViewer)Page.LoadUserControl("~/CMSModules/Forums/Controls/Posts/ForumPost.ascx"); post.ID = "forumPost" + fpi.PostId; CopyValues(post); post.SetValue("PostInfo", fpi); post.ReloadData(); post.RenderControl(writer); mId = ClientID + fpi.PostId; } return(mId); }
/// <summary> /// Creates forum post. Called when the "Create post" button is pressed. /// </summary> private bool CreateForumPost() { // Get the forum ForumInfo forum = ForumInfoProvider.GetForumInfo("MyNewForum", SiteContext.CurrentSiteID); if (forum != null) { // Create new forum post object ForumPostInfo newPost = new ForumPostInfo(); // Set the properties newPost.PostUserID = MembershipContext.AuthenticatedUser.UserID; newPost.PostUserMail = MembershipContext.AuthenticatedUser.Email; newPost.PostUserName = MembershipContext.AuthenticatedUser.UserName; newPost.PostForumID = forum.ForumID; newPost.SiteId = forum.ForumSiteID; newPost.PostTime = DateTime.Now; newPost.PostApproved = true; newPost.PostText = "This is my new post"; newPost.PostSubject = "My new post"; // Save the forum post ForumPostInfoProvider.SetForumPostInfo(newPost); return true; } return false; }
protected void Page_Load(object sender, EventArgs e) { bool process = true; if (!Visible || StopProcessing) { process = false; } fi = ForumInfoProvider.GetForumInfo(ForumID); replyPi = ForumPostInfoProvider.GetForumPostInfo(ReplyToPostID); editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); if ((fi == null) && (editPi != null)) { fi = ForumInfoProvider.GetForumInfo(editPi.PostForumID); ForumID = fi.ForumID; } // Check whether the post still exists if (EditPostID > 0) { EditedObject = editPi; } // Check whether the post still exists if ((ForumID > 0) && (fi == null)) { RedirectToInformation("editedobject.notexists"); } #region "HTML Editor properties" // 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.RemovePlugin("contextmenu"); // Disable context menu htmlTemplateBody.IsLiveSite = IsLiveSite; htmlTemplateBody.MediaDialogConfig.UseFullURL = true; htmlTemplateBody.LinkDialogConfig.UseFullURL = true; #endregion // Regular expression to validate email (e-mail is not required) rfvEmail.ValidationExpression = @"^([\w0-9_\-\+]+(\.[\w0-9_\-\+]+)*@[\w0-9_-]+(\.[\w0-9_-]+)+)*$"; if (fi != null) { if ((fi.ForumType == 0) && (replyPi == null)) { plcThreadType.Visible = true; } if (fi.ForumRequireEmail) { rfvEmailRequired.Enabled = true; rfvEmailRequired.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.emailRequireErrorMsg"); } #region "Forum text" rfvText.Enabled = !fi.ForumHTMLEditor; htmlTemplateBody.Visible = fi.ForumHTMLEditor; ucBBEditor.Visible = !fi.ForumHTMLEditor; if (fi.ForumHTMLEditor) { // 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*/" } }; // Register script for HTML Editor forum buttons control if (!fi.ForumEnableURL) { htmlTemplateBody.RemoveButton("InsertUrl"); if (!fi.ForumEnableAdvancedURL) { // Remove the keyboard shortcut for the link insertion keystrokes.Remove("link"); } } if (!fi.ForumEnableImage) { htmlTemplateBody.RemoveButton("InsertImage"); } if (!fi.ForumEnableQuote) { htmlTemplateBody.RemoveButton("InsertQuote"); } if (!fi.ForumEnableAdvancedURL) { htmlTemplateBody.RemoveButton("InsertLink"); } if (!fi.ForumEnableAdvancedImage) { htmlTemplateBody.RemoveButton("InsertImageOrMedia"); } if (!fi.ForumEnableFontBold) { htmlTemplateBody.RemoveButton("Bold"); keystrokes.Remove("bold"); } if (!fi.ForumEnableFontItalics) { htmlTemplateBody.RemoveButton("Italic"); keystrokes.Remove("italic"); } if (!fi.ForumEnableFontUnderline) { htmlTemplateBody.RemoveButton("Underline"); keystrokes.Remove("underline"); } if (!fi.ForumEnableFontStrike) { htmlTemplateBody.RemoveButton("Strike"); } if (!fi.ForumEnableFontColor) { htmlTemplateBody.RemoveButton("TextColor"); htmlTemplateBody.RemoveButton("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.ShowBold = fi.ForumEnableFontBold; ucBBEditor.ShowItalic = fi.ForumEnableFontItalics; ucBBEditor.ShowUnderline = fi.ForumEnableFontUnderline; ucBBEditor.ShowStrike = fi.ForumEnableFontStrike; ucBBEditor.ShowCode = fi.ForumEnableCodeSnippet; ucBBEditor.ShowColor = fi.ForumEnableFontColor; ucBBEditor.ShowURL = fi.ForumEnableURL; ucBBEditor.ShowAdvancedImage = fi.ForumEnableAdvancedImage; ucBBEditor.ShowAdvancedURL = fi.ForumEnableAdvancedURL; // WAI validation lblText.AssociatedControlClientID = ucBBEditor.TextArea.ClientID; } #endregion } // Do not show subscribe checkbox if no post can't be added under the post if ((replyPi != null) && (replyPi.PostLevel >= ForumPostInfoProvider.MaxPostLevel - 1)) { plcSubscribe.Visible = false; } #region "Resources" rfvEmail.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.emailErrorMsg"); 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"); lblPostIsAnswerLabel.Text = GetString("ForumPost_Edit.PostIsAnswer"); lblPostIsNotAnswerLabel.Text = GetString("ForumPost_Edit.PostIsNotAnswer"); #endregion if (!IsLiveSite && !RequestHelper.IsPostBack() && process) { ReloadData(); } }
/// <summary> /// Logs "post" activity. /// </summary> /// <param name="fp">Forum post object</param> /// <param name="fi">Forum info</param> private void LogPostActivity(ForumPostInfo fp, ForumInfo fi) { Activity forumPost = new ActivityForumPost(fp, fi, DocumentContext.CurrentDocument, fi.ForumLogActivity, AnalyticsContext.ActivityEnvironmentVariables); forumPost.Log(); }
protected void postNew_OnInsertPost(object sender, EventArgs e) { // Set properties postId = postNew.EditPostID; treeElem.Selected = postId; postEdit.EditPostID = postId; postView.PostID = postId; postNew.ReplyToPostID = 0; // Save post to database post = ForumPostInfoProvider.GetForumPostInfo(postId); hdnPost.Value = postId.ToString(); DisplayControl("view"); }
/// <summary> /// Reload data. /// </summary> public override void ReloadData() { ForumPostInfo fpi = null; ForumInfo fi = null; #region "Load data" if (PostData != null) { fpi = new ForumPostInfo(PostData); } if (fpi == null) { fpi = PostInfo; } if (fpi != null) { PostData = fpi.Generalized.DataClass; fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID); } else { return; } #endregion if (fi.ForumEnableAdvancedImage) { ltlText.AllowedControls = ControlsHelper.ALLOWED_FORUM_CONTROLS; } else { ltlText.AllowedControls = "none"; } lnkUserName.Text = HTMLHelper.HTMLEncode(fpi.PostUserName); // Display converted datetime for live site lblDate.Text = " (" + CMSContext.ConvertDateTime(ValidationHelper.GetDateTime(fpi.PostTime, DateTimeHelper.ZERO_TIME), this).ToString() + ")"; lblSubject.Text = HTMLHelper.HTMLEncode(fpi.PostSubject); DiscussionMacroHelper dmh = new DiscussionMacroHelper(); dmh.EnableBold = fi.ForumEnableFontBold; dmh.EnableItalics = fi.ForumEnableFontItalics; dmh.EnableStrikeThrough = fi.ForumEnableFontStrike; dmh.EnableUnderline = fi.ForumEnableFontUnderline; dmh.EnableCode = fi.ForumEnableCodeSnippet; dmh.EnableColor = fi.ForumEnableFontColor; dmh.EnableImage = fi.ForumEnableImage || fi.ForumEnableAdvancedImage; dmh.EnableQuote = fi.ForumEnableQuote; dmh.EnableURL = fi.ForumEnableURL || fi.ForumEnableAdvancedURL; dmh.MaxImageSideSize = fi.ForumImageMaxSideSize; dmh.QuotePostText = GetString("DiscussionMacroResolver.QuotePostText"); if (fi.ForumHTMLEditor) { dmh.EncodeText = false; dmh.ConvertLineBreaksToHTML = false; } else { dmh.EncodeText = true; dmh.ConvertLineBreaksToHTML = true; } ltlText.Text = "<div class=\"PostText\">" + dmh.ResolveMacros(fpi.PostText) + "</div>"; userAvatar.Text = AvatarImage(fpi); if (DisplayBadgeInfo) { if (fpi.PostUserID > 0) { UserInfo ui = UserInfoProvider.GetUserInfo(fpi.PostUserID); if ((ui != null) && !ui.IsPublic()) { BadgeInfo bi = BadgeInfoProvider.GetBadgeInfo(ui.UserSettings.UserBadgeID); if (bi != null) { ltlBadge.Text = "<div class=\"Badge\">" + HTMLHelper.HTMLEncode(bi.BadgeDisplayName) + "</div>"; } } } // Set public badge if no badge is set if (String.IsNullOrEmpty(ltlBadge.Text)) { ltlBadge.Text = "<div class=\"Badge\">" + GetString("Forums.PublicBadge") + "</div>"; } } if (EnableSignature) { if (fpi.PostUserSignature.Trim() != "") { plcSignature.Visible = true; ltrSignature.Text = HTMLHelper.HTMLEncode(fpi.PostUserSignature); } } if (!DisplayOnly) { string threadId = ForumPostInfoProvider.GetPostRootFromIDPath(ValidationHelper.GetString(GetData(PostData, "PostIdPath"), "")).ToString(); // Reply if (IsAvailable(PostData, ForumActionType.Reply)) { lnkReply.Visible = true; lnkReply.Text = GetString("Forums_WebInterface_ForumPost.replyLinkText"); lnkReply.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.Reply), "threadid", threadId); } else { lnkReply.Visible = false; } // Quote if (IsAvailable(PostData, ForumActionType.Quote)) { lnkQuote.Visible = true; lnkQuote.Text = GetString("Forums_WebInterface_ForumPost.quoteLinkText"); lnkQuote.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.Quote), "threadid", threadId); } else { lnkQuote.Visible = false; } // Display subscribe link if (IsAvailable(PostData, ForumActionType.SubscribeToPost)) { lnkSubscribe.Visible = true; lnkSubscribe.Text = GetString("Forums_WebInterface_ForumPost.Subscribe"); lnkSubscribe.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.SubscribeToPost), "threadid", threadId); } else { lnkSubscribe.Visible = false; } lnkUserName.CssClass = "PostUserLink"; if (!String.IsNullOrEmpty(fpi.PostUserMail) && (fi.ForumDisplayEmails)) { lnkUserName.NavigateUrl = "mailto:" + HTMLHelper.HTMLEncode(fpi.PostUserMail) + "?subject=" + HTMLHelper.HTMLEncode(fpi.PostSubject); lnkUserName.CssClass = "PostUser"; } } // Display action panel only if reply to link or subscription link are visible plcActions.Visible = ((lnkReply.Visible || lnkSubscribe.Visible || lnkQuote.Visible) & !DisplayOnly); if ((lnkReply.Visible) && (lnkQuote.Visible || lnkSubscribe.Visible)) { lblActionSeparator.Visible = true; } if ((lnkQuote.Visible) && (lnkSubscribe.Visible)) { lblActionSeparator2.Visible = true; } }
/// <summary> /// Logs "post" activity. /// </summary> /// <param name="bci">Forum subscription</param> /// <param name="fi">Forum info</param> private void LogPostActivity(ForumPostInfo fp, ForumInfo fi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (fp == null) || (fi == null) || !fi.ForumLogActivity || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ForumPostsEnabled(siteName)) { return; } int contactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); Dictionary<string, object> contactData = new Dictionary<string, object>(); contactData.Add("ContactEmail", fp.PostUserMail); contactData.Add("ContactLastName", fp.PostUserName); ModuleCommands.OnlineMarketingUpdateContactFromExternalSource(contactData, false, contactId); var data = new ActivityData() { ContactID = contactId, SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.FORUM_POST, TitleData = fi.ForumName, ItemID = fi.ForumID, ItemDetailID = fp.PostId, URL = URLHelper.CurrentRelativePath, NodeID = CMSContext.CurrentDocument.NodeID, Culture = CMSContext.CurrentDocument.DocumentCulture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Reload data. /// </summary> public override void ReloadData() { ForumPostInfo fpi = null; ForumInfo fi; #region "Load data" if (PostData != null) { fpi = new ForumPostInfo(PostData); } if (fpi == null) { fpi = PostInfo; } if (fpi != null) { PostData = fpi.Generalized.DataClass; fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID); } else { return; } #endregion if (fi.ForumEnableAdvancedImage) { ltlText.AllowedControls = ControlsHelper.ALLOWED_FORUM_CONTROLS; } else { ltlText.AllowedControls = "none"; } lnkUserName.Text = HTMLHelper.HTMLEncode(fpi.PostUserName); // Display converted datetime for live site lblDate.Text = " (" + TimeZoneMethods.ConvertDateTime(ValidationHelper.GetDateTime(fpi.PostTime, DateTimeHelper.ZERO_TIME), this).ToString() + ")"; lblSubject.Text = HTMLHelper.HTMLEncode(fpi.PostSubject); DiscussionMacroResolver dmh = new DiscussionMacroResolver(); dmh.EnableBold = fi.ForumEnableFontBold; dmh.EnableItalics = fi.ForumEnableFontItalics; dmh.EnableStrikeThrough = fi.ForumEnableFontStrike; dmh.EnableUnderline = fi.ForumEnableFontUnderline; dmh.EnableCode = fi.ForumEnableCodeSnippet; dmh.EnableColor = fi.ForumEnableFontColor; dmh.EnableImage = fi.ForumEnableImage || fi.ForumEnableAdvancedImage; dmh.EnableQuote = fi.ForumEnableQuote; dmh.EnableURL = fi.ForumEnableURL || fi.ForumEnableAdvancedURL; dmh.MaxImageSideSize = fi.ForumImageMaxSideSize; dmh.QuotePostText = GetString("DiscussionMacroResolver.QuotePostText"); if (fi.ForumHTMLEditor) { dmh.EncodeText = false; dmh.ConvertLineBreaksToHTML = false; } else { dmh.EncodeText = true; dmh.ConvertLineBreaksToHTML = true; } ltlText.Text = "<div class=\"PostText\">" + dmh.ResolveMacros(fpi.PostText) + "</div>"; userAvatar.Text = AvatarImage(fpi); if (DisplayBadgeInfo) { if (fpi.PostUserID > 0) { UserInfo ui = UserInfoProvider.GetUserInfo(fpi.PostUserID); if ((ui != null) && !ui.IsPublic()) { BadgeInfo bi = BadgeInfoProvider.GetBadgeInfo(ui.UserSettings.UserBadgeID); if (bi != null) { ltlBadge.Text = "<div class=\"Badge\">" + HTMLHelper.HTMLEncode(bi.BadgeDisplayName) + "</div>"; } } } // Set public badge if no badge is set if (String.IsNullOrEmpty(ltlBadge.Text)) { ltlBadge.Text = "<div class=\"Badge\">" + GetString("Forums.PublicBadge") + "</div>"; } } if (EnableSignature) { if (fpi.PostUserSignature.Trim() != "") { plcSignature.Visible = true; ltrSignature.Text = HTMLHelper.HTMLEncode(fpi.PostUserSignature); } } if (!DisplayOnly) { string threadId = ForumPostInfoProvider.GetPostRootFromIDPath(ValidationHelper.GetString(GetData(PostData, "PostIdPath"), "")).ToString(); // Reply if (IsAvailable(PostData, ForumActionType.Reply)) { lnkReply.Visible = true; lnkReply.Text = GetString("Forums_WebInterface_ForumPost.replyLinkText"); lnkReply.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.Reply), "threadid", threadId); } else { lnkReply.Visible = false; } // Quote if (IsAvailable(PostData, ForumActionType.Quote)) { lnkQuote.Visible = true; lnkQuote.Text = GetString("Forums_WebInterface_ForumPost.quoteLinkText"); lnkQuote.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.Quote), "threadid", threadId); } else { lnkQuote.Visible = false; } // Display subscribe link if (IsAvailable(PostData, ForumActionType.SubscribeToPost)) { lnkSubscribe.Visible = true; lnkSubscribe.Text = GetString("Forums_WebInterface_ForumPost.Subscribe"); lnkSubscribe.NavigateUrl = URLHelper.UpdateParameterInUrl(GetURL(PostData, ForumActionType.SubscribeToPost), "threadid", threadId); } else { lnkSubscribe.Visible = false; } lnkUserName.CssClass = "PostUserLink"; if (!String.IsNullOrEmpty(fpi.PostUserMail) && (fi.ForumDisplayEmails)) { lnkUserName.NavigateUrl = "mailto:" + HTMLHelper.HTMLEncode(fpi.PostUserMail) + "?subject=" + HTMLHelper.HTMLEncode(fpi.PostSubject); lnkUserName.CssClass = "PostUser"; } } // Display action panel only if reply to link or subscription link are visible plcActions.Visible = ((lnkReply.Visible || lnkSubscribe.Visible || lnkQuote.Visible) & !DisplayOnly); if ((lnkReply.Visible) && (lnkQuote.Visible || lnkSubscribe.Visible)) { lblActionSeparator.Visible = true; } if ((lnkQuote.Visible) && (lnkSubscribe.Visible)) { lblActionSeparator2.Visible = true; } }
/// <summary> /// Loads the forums DropDownList for topic move. /// </summary> private void LoadMoveTopicDropdown() { if (drpMoveToForum.Items.Count > 0) { return; } ForumPostInfo fpi = ForumContext.CurrentThread; if ((fpi == null) && (CurrentThread > 0)) { fpi = ForumPostInfoProvider.GetForumPostInfo(CurrentThread); } if (fpi != null) { bool isOk = AdminMode || ((ForumContext.CurrentForum != null) && (ForumContext.CurrentForum.ForumID == fpi.PostForumID)); if (isOk) { var currentForumId = fpi.PostForumID; ForumInfo fi = ForumInfoProvider.GetForumInfo(currentForumId); if (fi != null) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { var whereCondition = new WhereCondition().WhereNotStartsWith("GroupName", "AdHoc").WhereEquals("GroupSiteID", SiteID); if (fgi.GroupGroupID > 0) { whereCondition.WhereEquals("GroupGroupID", fgi.GroupGroupID); } else { whereCondition.WhereNull("GroupGroupID"); } DataSet dsGroups = ForumGroupInfoProvider.GetForumGroups().Where(whereCondition).OrderBy("GroupDisplayName").Columns("GroupID, GroupDisplayName"); if (!DataHelper.DataSourceIsEmpty(dsGroups)) { Hashtable forums = new Hashtable(); // Get all forums for selected groups var groupWhereCondition = new WhereCondition().WhereIn("ForumGroupID", new ObjectQuery <ForumGroupInfo>().Where(whereCondition).Column("GroupID")); DataSet dsForums = ForumInfoProvider.GetForums() .WhereEquals("ForumOpen", 1) .WhereNotEquals("ForumID", currentForumId) .Where(groupWhereCondition) .OrderBy("ForumDisplayName") .Columns("ForumID, ForumDisplayName, ForumGroupID") .TypedResult; if (!DataHelper.DataSourceIsEmpty(dsForums)) { // Load forums into hash table foreach (DataRow drForum in dsForums.Tables[0].Rows) { int groupId = Convert.ToInt32(drForum["ForumGroupID"]); List <string[]> forumNames = forums[groupId] as List <string[]> ?? new List <string[]>(); forumNames.Add(new[] { Convert.ToString(drForum["ForumDisplayName"]), Convert.ToString(drForum["ForumID"]) }); forums[groupId] = forumNames; } } foreach (DataRow dr in dsGroups.Tables[0].Rows) { int groupId = Convert.ToInt32(dr["GroupId"]); List <string[]> forumNames = forums[groupId] as List <string[]>; if (forumNames != null) { // Add forum group item if some forum ListItem li = new ListItem(Convert.ToString(dr["GroupDisplayName"]), "0"); li.Attributes.Add("disabled", "disabled"); drpMoveToForum.Items.Add(li); // Add forum items foreach (string[] forum in forumNames) { // Add forum to DDL drpMoveToForum.Items.Add(new ListItem(" \xA0\xA0\xA0\xA0 " + forum[0], forum[1])); } } } // Display message if no forum exists if (drpMoveToForum.Items.Count == 0) { plcMoveInner.Visible = false; ShowInformation(GetString("Forums.NoForumToMoveIn")); } } } } } } }
protected void Page_Load(object sender, EventArgs e) { CopyValues(postTreeElem); // Hide selected area if forum is AdHoc if (IsAdHocForum) { plcHeader.Visible = false; } // Handle the Move topic mode if (ForumContext.CurrentMode != ForumMode.TopicMove) { plcMoveThread.Visible = false; } else { plcMoveThread.Visible = true; threadMove.TopicMoved += new EventHandler(TopicMoved); } if ((hdnSelected.Value == String.Empty) && (QueryHelper.Contains("moveto"))) { hdnSelected.Value = QueryHelper.GetString("moveto", ""); mSelectedPost = ValidationHelper.GetInteger(hdnSelected.Value, 0); } bool newThread = base.IsAvailable(null, ForumActionType.NewThread); bool newSubscription = base.IsAvailable(null, ForumActionType.SubscribeToForum); bool newFavorites = base.IsAvailable(null, ForumActionType.AddForumToFavorites); bool newBreadCrumbs = (ForumBreadcrumbs1.GenerateBreadcrumbs() != ""); // Hide separators according to the link visibility // Each separator is hidden if the item preceeding the separator is invisible or // no item is behind the separator. if (!newThread || (!newSubscription && !newFavorites && !newBreadCrumbs)) { plcActionSeparator.Visible = false; } if (!newSubscription || (!newFavorites && !newBreadCrumbs)) { plcAddToFavoritesSeparator.Visible = false; } if (!newFavorites || !newBreadCrumbs) { plcBreadcrumbsSeparator.Visible = false; } // postTreeElem.ForumID = ForumContext.CurrentForum.ForumID; //postTreeElem.ShowMode = ShowModeEnum.TreeMode; // Unapproved posts are shown only if onsite mangement is enabled and user is moderator ForumInfo fi = ForumContext.CurrentForum; postTreeElem.SelectOnlyApproved = !((fi != null) && EnableOnSiteManagement && fi.ForumModerated && ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID)); if (postTreeElem.ShowMode == ShowModeEnum.DynamicDetailMode) { // Set javascript for selected mode ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ForumTreeDynamic", ScriptHelper.GetScript("function SelectForumNode(nodeElem, selElem) { if (document.getElementById(nodeElem) != null) { document.getElementById(nodeElem).style.display = 'block';} " + "if (document.getElementById(selElem) != null) {document.getElementById(selElem).style.display = 'none';} return false;}\n ")); } else { ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ForumTreeNormal", ScriptHelper.GetScript("function SelectForumNode(nodeElem) { return false; }\n ")); } // Show post javascript string showScript = "function ShowPost(id){ document.getElementById('" + hdnSelected.ClientID + "').value = id; " + ControlsHelper.GetPostBackEventReference(this, "") + " }"; //Register show post javascript code ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ShowForumPost", ScriptHelper.GetScript(showScript)); // Don't use redirection after action UseRedirectAfterAction = false; int selected = ValidationHelper.GetInteger(hdnSelected.Value, ValidationHelper.GetInteger(Request[hdnSelected.UniqueID], 0)); if (selected > 0) { ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(selected); if (fpi != null) { ucAbuse.ReportObjectID = fpi.PostId; ucAbuse.ReportTitle = ResHelper.GetString("Forums_WebInterface_ForumPost.AbuseReport", CultureHelper.GetDefaultCultureCode(SiteContext.CurrentSiteName)) + fpi.PostText; ucAbuse.CMSPanel.CommunityGroupID = CommunityGroupID; ucAbuse.CMSPanel.SecurityAccess = AbuseReportAccess; ucAbuse.CMSPanel.Roles = AbuseReportRoles; } } }
/// <summary> /// OnPrerender check whether. /// </summary> protected override void OnPreRender(EventArgs e) { postTreeElem.Selected = ValidationHelper.GetInteger(hdnSelected.Value, SelectedPost); if ((mSelectedPost == 0) && (RequestHelper.IsAJAXRequest())) { mSelectedPost = postTreeElem.Selected; } if (mSelectedPost > 0) { ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(mSelectedPost); if ((fpi != null) && (ForumContext.CurrentForum != null) && (fpi.PostForumID == ForumContext.CurrentForum.ForumID)) { plcPostPreview.Visible = true; ltlPostSubject.Text = HTMLHelper.HTMLEncode(fpi.PostSubject); ltlPostText.Text = ResolvePostText(fpi.PostText); ltlSignature.Text = GetSignatureArea(fpi, "<div class=\"SignatureArea\">", "</div>"); ltlPostTime.Text = TimeZoneHelper.ConvertToUserTimeZone(fpi.PostTime, false, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite).ToString(); ltlPostUser.Text = "<span class=\"PostUserName\">" + GetUserName(fpi) + "</span>"; ltlAvatar.Text = AvatarImage(fpi); mUnapproved = !fpi.PostApproved ? " Unapproved" : ""; if (ForumContext.CurrentForum.ForumEnableAdvancedImage) { ltlPostText.AllowedControls = ControlsHelper.ALLOWED_FORUM_CONTROLS; } else { ltlPostText.AllowedControls = "none"; } attachmentDisplayer.ClearData(); attachmentDisplayer.PostID = fpi.PostId; attachmentDisplayer.PostAttachmentCount = fpi.PostAttachmentCount; attachmentDisplayer.ReloadData(); #region "Badge" if (DisplayBadgeInfo) { if (fpi.PostUserID > 0) { UserInfo ui = UserInfoProvider.GetUserInfo(fpi.PostUserID); if ((ui != null) && (!ui.IsPublic())) { BadgeInfo bi = BadgeInfoProvider.GetBadgeInfo(ui.UserSettings.UserBadgeID); if (bi != null) { ltlBadge.Text = "<div class=\"Badge\">" + HTMLHelper.HTMLEncode(bi.BadgeDisplayName) + "</div>"; if (!String.IsNullOrEmpty(bi.BadgeImageURL)) { ltlBadge.Text += "<div class=\"BadgeImage\"><img alt=\"" + HTMLHelper.HTMLEncode(bi.BadgeDisplayName) + "\" src=\"" + HTMLHelper.HTMLEncode(GetImageUrl(bi.BadgeImageURL)) + "\" /></div>"; } } } } // Set public badge if no badge is set if (String.IsNullOrEmpty(ltlBadge.Text)) { ltlBadge.Text = "<div class=\"Badge\">" + GetString("Forums.PublicBadge") + "</div>"; } } #endregion #region "Post actions" // Get the parent thread ID (for reply and quote) int threadId = ForumPostInfoProvider.GetPostRootFromIDPath(fpi.PostIDPath); ltlReply.Text = GetLink(fpi, GetString("Forums_WebInterface_ForumPost.replyLinkText"), "PostActionLink", ForumActionType.Reply, threadId); ltlQuote.Text = GetLink(fpi, GetString("Forums_WebInterface_ForumPost.quoteLinkText"), "PostActionLink", ForumActionType.Quote, threadId); ltlSubscribe.Text = GetLink(fpi, GetString("Forums_WebInterface_ForumPost.Subscribe"), "PostActionLink", ForumActionType.SubscribeToPost, threadId); ltlAnswer.Text = GetLink(fpi, GetString("general.yes"), "ActionLink", ForumActionType.IsAnswer); ltlNotAnswer.Text = GetLink(fpi, GetString("general.no"), "ActionLink", ForumActionType.IsNotAnswer); if (ltlAnswer.Text != String.Empty) { ltlWasHelpful.Text = GetString("Forums_WebInterface_ForumPost.Washelpful") + " "; ltlAnswer.Text += "|"; } ltlAddPostToFavorites.Text = GetLink(fpi, GetString("Forums_WebInterface_ForumPost.AddPostToFavorites"), "ActionLink", ForumActionType.AddPostToFavorites); ltlDelete.Text = GetLink(fpi, GetString("general.delete"), "ActionLink", ForumActionType.Delete); ltlEdit.Text = GetLink(fpi, GetString("general.edit"), "ActionLink", ForumActionType.Edit); ltlAttachments.Text = GetLink(fpi, GetString("general.attachments"), "ActionLink", ForumActionType.Attachment); #endregion // Hide separators if ((ltlReply.Text == "") || (ltlReply.Text != "" && ltlQuote.Text == "")) { plcFirstSeparator.Visible = false; } if ((ltlSubscribe.Text == "") || (ltlSubscribe.Text != "" && ltlQuote.Text == "")) { plcSecondSeparator.Visible = false; } if (ltlReply.Text != "" && ltlSubscribe.Text != "") { plcFirstSeparator.Visible = true; } pnlManage.Visible = (EnableOnSiteManagement && (ForumContext.CurrentForum != null)) ? ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, CommunityGroupID) : false; if (pnlManage.Visible) { ltlApprove.Text = GetLink(fpi, GetString("general.approve"), "ActionLink", ForumActionType.Appprove); ltlApproveAll.Text = GetLink(fpi, GetString("forums.approveall"), "ActionLink", ForumActionType.ApproveAll); ltlReject.Text = GetLink(fpi, GetString("general.reject"), "ActionLink", ForumActionType.Reject); ltlRejectAll.Text = GetLink(fpi, GetString("forums.rejectall"), "ActionLink", ForumActionType.RejectAll); ltlSplit.Text = GetLink(fpi, GetString("forums.splitthread"), "ActionLink", ForumActionType.SplitThread); ltlMove.Text = GetLink(fpi, GetString("forums.movethread"), "ActionLink", ForumActionType.MoveToTheOtherForum, threadId); } } } else { plcPostPreview.Visible = false; } if (ControlsHelper.IsInUpdatePanel(this)) { ControlsHelper.GetUpdatePanel(this).Update(); } base.OnPreRender(e); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); #region "Security" postEdit.OnCheckPermissions += new CheckPermissionsEventHandler(postEdit_OnCheckPermissions); postNew.OnCheckPermissions += new CheckPermissionsEventHandler(postNew_OnCheckPermissions); #endregion this.postNew.OnInsertPost += new EventHandler(postNew_OnInsertPost); this.postNew.OnPreview += new EventHandler(postNew_OnPreview); this.postEdit.OnPreview += new EventHandler(postEdit_OnPreview); this.postEdit.OnCancelClick += new EventHandler(postEdit_OnCancelClick); this.postEdit.OnSaved += new EventHandler(postEdit_OnSaved); // Set forum this.treeElem.ForumID = this.mForumId; this.postNew.ForumID = this.mForumId; this.postEdit.ForumID = this.mForumId; // Get post ID postId = ValidationHelper.GetInteger(this.hdnPost.Value, 0); if (postId > 0) { this.postEdit.EditPostID = postId; post = ForumPostInfoProvider.GetForumPostInfo(postId); } // Unigrid settings UniGrid.Visible = false; UniGrid.Query = ""; UniGrid.OnAction += new OnActionEventHandler(UniGrid_OnAction); UniGrid.OnExternalDataBound += new OnExternalDataBoundEventHandler(UniGrid_OnExternalDataBound); // Initialize page elements this.titleViewElem.TitleText = GetString("ForumPost_View.PostTitleText"); this.titleViewElem.TitleImage = GetImageUrl("Objects/Forums_ForumPost/object.png"); this.titleEditElem.TitleText = GetString("ForumPost_Edit.HeaderCaption"); this.titleEditElem.TitleImage = GetImageUrl("Objects/Forums_ForumPost/object.png"); this.lnkEditBack.Text = GetString("general.view"); this.lnkEditBack.Click += new EventHandler(lnkEditBack_Click); if (post != null) { lblEditBack.Text = breadCrumbsSeparator + HTMLHelper.HTMLEncode(post.PostSubject); InitializeMenu(); } // Add handlers treeElem.OnGetPostIconUrl += new CMSModules_Forums_Controls_PostTree.GetIconEventHandler(treeElem_OnGetPostIconUrl); this.actionsElem.ActionPerformed += new CommandEventHandler(actionsElem_ActionPerformed); }
/// <summary> /// Logs "post" activity. /// </summary> /// <param name="bci">Forum subscription</param> /// <param name="fi">Forum info</param> private void LogPostActivity(ForumPostInfo fp, ForumInfo fi) { string siteName = CMSContext.CurrentSiteName; if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || (fp == null) || (fi == null) || !fi.ForumLogActivity || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) || !ActivitySettingsHelper.ForumPostsEnabled(siteName)) { return; } var data = new ActivityData() { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(), SiteID = CMSContext.CurrentSiteID, Type = PredefinedActivityType.FORUM_POST, TitleData = fi.ForumName, ItemID = fi.ForumID, ItemDetailID = fp.PostId, URL = URLHelper.CurrentRelativePath, NodeID = CMSContext.CurrentDocument.NodeID, Culture = CMSContext.CurrentDocument.DocumentCulture, Campaign = CMSContext.Campaign }; ActivityLogProvider.LogActivity(data); }
/// <summary> /// Deletes forum post. Called when the "Delete post" button is pressed. /// Expects the CreateForumPost method to be run first. /// </summary> private bool DeleteForumPost() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10; // Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(posts)) { // Get the forum post ForumPostInfo deletePost = new ForumPostInfo(posts.Tables[0].Rows[0]); // Delete the forum post ForumPostInfoProvider.DeleteForumPostInfo(deletePost); return true; } return false; }
/// <summary> /// Gets and bulk updates forum posts. Called when the "Get and bulk update posts" button is pressed. /// Expects the CreateForumPost method to be run first. /// </summary> private bool GetAndBulkUpdateForumPosts() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10; // Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(posts)) { // Loop through the individual items foreach (DataRow postDr in posts.Tables[0].Rows) { // Create object from DataRow ForumPostInfo modifyPost = new ForumPostInfo(postDr); // Update the properties modifyPost.PostSubject = modifyPost.PostSubject.ToUpper(); // Save the changes ForumPostInfoProvider.SetForumPostInfo(modifyPost); } return true; } return false; }
/// <summary> /// Handle actions. /// </summary> protected void actionsElem_ActionPerformed(object sender, CommandEventArgs e) { if (!CheckPermissions("cms.forums", PERMISSION_MODIFY)) { return; } switch (e.CommandName.ToLowerCSafe()) { case "stick": ForumPostInfoProvider.StickThread(post); // Get the post object with updated info post = ForumPostInfoProvider.GetForumPostInfo(post.PostId); DisplayControl("view"); break; case "unstick": ForumPostInfoProvider.UnstickThread(post); // Get the post object with updated info post = ForumPostInfoProvider.GetForumPostInfo(post.PostId); DisplayControl("view"); break; case "split": ForumPostInfoProvider.SplitThread(post); // Get the post object with updated info post = ForumPostInfoProvider.GetForumPostInfo(post.PostId); DisplayControl("view"); break; case "lockunlock": // Lock or unlock post post.PostIsLocked = !post.PostIsLocked; ForumPostInfoProvider.SetForumPostInfo(post); DisplayControl("view"); break; case "edit": // Edit DisplayControl("edit"); break; case "delete": // Delete post ForumPostInfoProvider.DeleteForumPostInfo(postId); postNew.ClearForm(); DisplayControl("new"); break; case "reply": // Reply DisplayControl("reply"); break; case "approve": // Approve action if (MembershipContext.AuthenticatedUser != null) { post.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; post.PostApproved = true; ForumPostInfoProvider.SetForumPostInfo(post); } DisplayControl("view"); break; case "reject": // Reject action post.PostApprovedByUserID = 0; post.PostApproved = false; ForumPostInfoProvider.SetForumPostInfo(post); DisplayControl("view"); break; case "approvesubtree": // Approve subtree if ((post != null) && (MembershipContext.AuthenticatedUser != null)) { post.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; post.PostApproved = true; ForumPostInfoProvider.SetForumPostInfo(post); DataSet ds = ForumPostInfoProvider.GetChildPosts(post.PostId); if (!DataHelper.DataSourceIsEmpty(ds)) { // All posts under current post foreach (DataRow dr in ds.Tables[0].Rows) { ForumPostInfo mfpi = new ForumPostInfo(dr); if (!mfpi.PostApproved) { mfpi.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; mfpi.PostApproved = true; ForumPostInfoProvider.SetForumPostInfo(mfpi); } } } DisplayControl("view"); } break; case "rejectsubtree": // Reject subtree if (post != null) { post.PostApprovedByUserID = 0; post.PostApproved = false; ForumPostInfoProvider.SetForumPostInfo(post); DataSet ds = ForumPostInfoProvider.GetChildPosts(post.PostId); if (!DataHelper.DataSourceIsEmpty(ds)) { // All posts under current post foreach (DataRow dr in ds.Tables[0].Rows) { ForumPostInfo mfpi = new ForumPostInfo(dr); if (mfpi.PostApproved) { mfpi.PostApprovedByUserID = 0; mfpi.PostApproved = false; ForumPostInfoProvider.SetForumPostInfo(mfpi); } } } DisplayControl("view"); } break; } hdnPost.Value = postId.ToString(); }
/// <summary> /// Gets and updates forum post. Called when the "Get and update post" button is pressed. /// Expects the CreateForumPost method to be run first. /// </summary> private bool GetAndUpdateForumPost() { // Prepare the parameters string where = "PostSubject LIKE N'My new post%'"; string orderBy = ""; string columns = ""; int topN = 10; // Get the data DataSet posts = ForumPostInfoProvider.GetForumPosts(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(posts)) { ForumPostInfo updatePost = new ForumPostInfo(posts.Tables[0].Rows[0]); // Update the properties updatePost.PostSubject = updatePost.PostSubject.ToLower(); // Save the changes ForumPostInfoProvider.SetForumPostInfo(updatePost); return true; } return false; }
private static bool ValidatePost(ForumPostInfo fpi) { if ((fpi.PostSubject == null) || (fpi.PostText == null) || (fpi.PostUserName == null)) { return false; } return ((fpi.PostSubject.Trim() != "") && (fpi.PostText.Trim() != "") && (fpi.PostUserName.Trim() != "")); }
/// <summary> /// OK click hadler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { #region "Security" // Check whether forum exists if (ForumContext.CurrentForum == null) { return; } // Check security bool securityCheck = true; switch (ForumContext.CurrentState) { case ForumStateEnum.NewThread: securityCheck = IsAvailable(ForumContext.CurrentForum, ForumActionType.NewThread); break; case ForumStateEnum.ReplyToPost: securityCheck = IsAvailable(ForumContext.CurrentForum, ForumActionType.Reply); break; case ForumStateEnum.EditPost: securityCheck = ForumContext.CurrentPost != null && IsAvailable(ForumContext.CurrentPost, ForumActionType.Edit); break; } if (!securityCheck) { lblError.Visible = true; lblError.Text = GetString("ForumNewPost.PermissionDenied"); return; } #region "Captcha" // Check security code if is required if ((ForumContext.CurrentForum.ForumUseCAPTCHA) && (!SecurityCode1.IsValid()) && (ForumContext.CurrentState != ForumStateEnum.EditPost)) { lblError.Visible = true; lblError.Text = GetString("ForumNewPost.InvalidCaptcha"); return; } #endregion #region "Email field" // Create instance of validator Validator validator = new Validator(); // Check whether email is valid string result = validator.IsEmail(txtEmail.Text, rfvEmail.ErrorMessage).Result; // Check whether email is present with correct format if email is required // or when subscribtion to current post is checked if ((ForumContext.CurrentForum.ForumRequireEmail || chkSubscribe.Checked) && (result != "")) { lblError.Visible = true; lblError.Text = result; return; } // Check if email is added if is in correct format if ((txtEmail.Text.Trim() != "") && (result != "")) { lblError.Visible = true; lblError.Text = rfvEmail.ErrorMessage; return; } #endregion #region "Subject" // Check whether subject is filled if (txtSubject.Text.Trim() == "") { lblError.Visible = true; lblError.Text = rfvSubject.ErrorMessage; return; } #endregion #region "Text" validator = new Validator(); // Check post text in HTML editor or text area if (!ForumContext.CurrentForum.ForumHTMLEditor) { // Check whether post text is added in text area if ((result = validator.NotEmpty(DiscussionMacroHelper.RemoveTags(ucBBEditor.Text), rfvText.ErrorMessage).Result) != "") { lblError.Visible = true; lblError.Text = result; return; } } else { // Check whether post text is added in HTML editor if ((result = validator.NotEmpty(htmlTemplateBody.ResolvedValue, rfvText.ErrorMessage).Result) != "") { lblError.Visible = true; lblError.Text = result; return; } } #endregion #region "User name" // Check whether user name is filled if user name field is visible if (ForumContext.CurrentForum.ForumAllowChangeName || CMSContext.CurrentUser.IsPublic() || ((ForumContext.CurrentForum != null) && (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, ForumContext.CommunityGroupID)))) { validator = new Validator(); if ((result = validator.NotEmpty(txtUserName.Text, rfvUserName.ErrorMessage).Result) != "") { lblError.Visible = true; lblError.Text = result; return; } } #endregion #endregion #region "Forum post properties" bool newPost = false; // Current forum info object ForumInfo fi = ForumContext.CurrentForum; // Forum post info object ForumPostInfo fp = null; // Get forum post info with dependence on current state if (ForumContext.CurrentState == ForumStateEnum.EditPost) { // Get existing object fp = ForumContext.CurrentPost; fp.PostLastEdit = DateTime.Now; } else { // Create new forum post info obejct fp = new ForumPostInfo(); newPost = true; } #region "Ad-hoc forum" if (this.IsAdHocForum && (ForumContext.CurrentForum.ForumID == 0)) { if (CMSContext.CurrentDocument == null) { lblError.Visible = true; lblError.Text = GetString("forums.documentdoesnotexist"); return; } fi.ForumGroupID = ForumGroupInfoProvider.GetAdHocGroupInfo(this.SiteID).GroupID; fi.ForumName = "AdHoc-" + Guid.NewGuid(); fi.ForumDisplayName = TextHelper.LimitLength(CMSContext.CurrentDocument.DocumentName, POST_USERNAME_LENGTH, String.Empty); fi.ForumOpen = true; fi.ForumModerated = false; fi.ForumAccess = 040000; fi.ForumThreads = 0; fi.ForumPosts = 0; fi.ForumLogActivity = this.LogActivity; ForumInfoProvider.SetForumInfo(fi); ForumContext.CurrentForum.ForumID = fi.ForumID; ForumContext.ForumID = fi.ForumID; this.ForumID = fi.ForumID; } #endregion // Post forum fp.PostForumID = ForumContext.CurrentForum.ForumID; // Get forum post info with dependence on current state if (ForumContext.CurrentState != ForumStateEnum.EditPost) { // Post time fp.PostTime = DateTime.Now; // User IP adress fp.PostInfo.IPAddress = Request.UserHostAddress; // User agent fp.PostInfo.Agent = Request.UserAgent; // Post user id if (!CMSContext.CurrentUser.IsPublic()) { fp.PostUserID = CMSContext.CurrentUser.UserID; } // Post signature fp.PostUserSignature = txtSignature.Text; } // Post subject fp.PostSubject = txtSubject.Text; // Post user email fp.PostUserMail = txtEmail.Text; // Post type int forumType = ForumContext.CurrentForum.ForumType; if (forumType == 0) { if (ForumContext.CurrentReplyThread == null) { // New thread - use type which user choosed fp.PostType = (radTypeDiscussion.Checked ? 0 : 1); } else { // Reply - use parent type fp.PostType = ForumContext.CurrentReplyThread.PostType; } } else { // Fixed type - use the forum setting fp.PostType = forumType - 1; } bool newThread = (ForumContext.CurrentReplyThread == null); // Set username if change name is allowed if (fi.ForumAllowChangeName || CMSContext.CurrentUser.IsPublic() || ForumContext.UserIsModerator(fp.PostForumID, ForumContext.CommunityGroupID)) { fp.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); } else { // Get forum post info with dependence on current state if (ForumContext.CurrentState != ForumStateEnum.EditPost) { fp.PostUserName = UserName; } } // Post parent id -> reply to if (ForumContext.CurrentReplyThread != null) { fp.PostParentID = ForumContext.CurrentReplyThread.PostId; // Check max relative level if ((this.MaxRelativeLevel > -1) && (ForumContext.CurrentReplyThread.PostLevel >= this.MaxRelativeLevel)) { lblError.Visible = true; lblError.Text = GetString("Forums.MaxRelativeLevelError"); return; } } // Get post text from HTML editor if is enabled fp.PostText = ForumContext.CurrentForum.ForumHTMLEditor ? htmlTemplateBody.ResolvedValue : ucBBEditor.Text; // Approve post if forum is not moderated if (newPost) { if (!ForumContext.CurrentForum.ForumModerated) { fp.PostApproved = true; } else { if (ForumContext.UserIsModerator(fp.PostForumID, this.CommunityGroupID)) { fp.PostApproved = true; fp.PostApprovedByUserID = CMSContext.CurrentUser.UserID; } } } // If signature is enabled then if (EnableSignature) { fp.PostUserSignature = CMSContext.CurrentUser.UserSignature; } #endregion if (!BadWordInfoProvider.CanUseBadWords(CMSContext.CurrentUser, CMSContext.CurrentSiteName)) { // Prepare columns to check Dictionary<string, int> columns = new Dictionary<string, int>(); columns.Add("PostText", 0); columns.Add("PostSubject", 450); columns.Add("PostUserSignature", 0); columns.Add("PostUserName", 200); // Perform bad words check string badMessage = BadWordsHelper.CheckBadWords(fp, columns, "PostApproved", "PostApprovedByUserID", fp.PostText, CMSContext.CurrentUser.UserID); if (badMessage == "") { if (!ValidatePost(fp)) { badMessage = GetString("ForumNewPost.EmptyBadWord"); } } if (badMessage != "") { lblError.Visible = true; lblError.Text = badMessage; return; } } // Flood protection if (FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser)) { lblError.Visible = true; lblError.Text = GetString("General.FloodProtection"); return; } // Check banned ip if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } string baseUrl = ForumContext.CurrentForum.ForumBaseUrl; if (String.IsNullOrEmpty(baseUrl)) { baseUrl = this.FriendlyBaseURL; } string unsubscriptionUrl = ForumContext.CurrentForum.ForumUnsubscriptionUrl; if (String.IsNullOrEmpty(unsubscriptionUrl)) { unsubscriptionUrl = this.UnsubscriptionURL; } // USe parent post id for new post int subscibePostId = newPost ? fp.PostParentID : fp.PostId; // Check subscriptions if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(txtEmail.Text)) && (ForumSubscriptionInfoProvider.IsSubscribed(txtEmail.Text.Trim(), fp.PostForumID, subscibePostId))) { // Post of the forum is already subscribed to this email -> show an error chkSubscribe.Checked = false; lblError.Text = GetString("Forums.EmailAlreadySubscribed"); lblError.Visible = true; return; } // Save post object ForumPostInfoProvider.SetForumPostInfo(fp, baseUrl, unsubscriptionUrl); LogPostActivity(fp, fi); #region "Subscription" // If subscribe is checked create new subscription to the current post if ((chkSubscribe.Checked) && (!ForumSubscriptionInfoProvider.IsSubscribed(fp.PostUserMail, fp.PostForumID, fp.PostId))) { // Create new subscription info object ForumSubscriptionInfo fsi = new ForumSubscriptionInfo(); // Set info properties fsi.SubscriptionForumID = fp.PostForumID; fsi.SubscriptionEmail = fp.PostUserMail; fsi.SubscriptionPostID = fp.PostId; fsi.SubscriptionUserID = fp.PostUserID; fsi.SubscriptionGUID = Guid.NewGuid(); // Save subscription ForumSubscriptionInfoProvider.SetForumSubscriptionInfo(fsi, true, baseUrl, unsubscriptionUrl); LogSubscriptionActivity(fsi, fi); } #endregion // Generate new captcha code SecurityCode1.GenerateNew(); if ((!fp.PostApproved) && (!ForumContext.UserIsModerator(fp.PostForumID, this.CommunityGroupID))) { if (OnModerationRequired != null) { OnModerationRequired(this, null); } } // Keep current user info CurrentUserInfo currentUser = CMSContext.CurrentUser; if (currentUser.IsAuthenticated() && chkAttachFile.Checked && (currentUser.IsGlobalAdministrator || ForumContext.CurrentForum.AllowAttachFiles != SecurityAccessEnum.Nobody)) { // Redirect to the post attachments URLHelper.Redirect(GetURL(fp, ForumActionType.Attachment)); } else { if (!this.StopProcessing) { // Redirect back to the forum or forum thread URLHelper.Redirect(ClearURL()); } } }
/// <summary> /// Preview button click handler. /// </summary> protected void btnPreview_Click(object sender, EventArgs e) { // If external preview is enabled fire OnPreview event if (UseExternalPreview) { #region "Forum properties" // Get forum post info with dependence on current state ForumPostInfo fp = ForumContext.CurrentState == ForumStateEnum.EditPost ? ForumContext.CurrentPost : new ForumPostInfo(); // Post forum fp.PostForumID = ForumContext.CurrentForum.ForumID; // Post time fp.PostTime = DateTime.Now; // Post subject fp.PostSubject = txtSubject.Text; // Post user email fp.PostUserMail = txtEmail.Text; // Post signature fp.PostUserSignature = txtSignature.Text; // Post user id if (!MembershipContext.AuthenticatedUser.IsPublic()) { fp.PostUserID = MembershipContext.AuthenticatedUser.UserID; } // Post user name if (ForumContext.CurrentForum.ForumAllowChangeName || MembershipContext.AuthenticatedUser.IsPublic() || (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, ForumContext.CommunityGroupID))) { fp.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); } else { fp.PostUserName = UserName; } // Post parent id -> reply to if (ForumContext.CurrentReplyThread != null) { fp.PostParentID = ForumContext.CurrentReplyThread.PostId; } // Get post text from HTML editor if is enabled fp.PostText = ForumContext.CurrentForum.ForumHTMLEditor ? htmlTemplateBody.ResolvedValue : ucBBEditor.Text; #endregion if (OnPreview != null) { OnPreview(fp, null); } } else { pnlReplyPost.Visible = true; lblSubjectPreview.Text = txtSubject.Text; // Get forum text from HTML editor or text area if (ForumContext.CurrentForum.ForumHTMLEditor) { lblTextPreview.Text = htmlTemplateBody.ResolvedValue; } else { lblTextPreview.Text = HTMLHelper.EnsureLineEnding(HTMLHelper.HTMLEncode(ucBBEditor.Text), "<br />"); } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); #region "Security" postEdit.OnCheckPermissions += postEdit_OnCheckPermissions; postNew.OnCheckPermissions += postNew_OnCheckPermissions; #endregion postNew.OnInsertPost += postNew_OnInsertPost; postNew.OnPreview += postNew_OnPreview; postEdit.OnPreview += postEdit_OnPreview; postEdit.OnCancelClick += postEdit_OnCancelClick; postEdit.OnSaved += postEdit_OnSaved; // Set forum treeElem.ForumID = mForumId; postNew.ForumID = mForumId; postEdit.ForumID = mForumId; // Get post ID postId = ValidationHelper.GetInteger(hdnPost.Value, 0); if (postId > 0) { postEdit.EditPostID = postId; post = ForumPostInfoProvider.GetForumPostInfo(postId); } // Unigrid settings UniGrid.Visible = false; UniGrid.Query = ""; UniGrid.OnAction += UniGrid_OnAction; UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound; // Initialize page elements titleViewElem.TitleText = GetString("ForumPost_View.PostTitleText"); titleEditElem.TitleText = GetString("ForumPost_Edit.HeaderCaption"); lnkBackHidden.Click += lnkBackHidden_Click; if (post != null) { InitializeBreadcrumbs(post.PostSubject); InitializeMenu(); } // Add handlers treeElem.OnGetStatusIcons += treeElem_OnGetPostIconUrl; actionsElem.ActionPerformed += actionsElem_ActionPerformed; }
/// <summary> /// OK click hadler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { #region "Security" // Check whether forum exists if (ForumContext.CurrentForum == null) { return; } // Check security bool securityCheck = true; switch (ForumContext.CurrentState) { case ForumStateEnum.NewThread: securityCheck = IsAvailable(ForumContext.CurrentForum, ForumActionType.NewThread); break; case ForumStateEnum.ReplyToPost: securityCheck = IsAvailable(ForumContext.CurrentForum, ForumActionType.Reply); break; case ForumStateEnum.EditPost: securityCheck = ForumContext.CurrentPost != null && IsAvailable(ForumContext.CurrentPost, ForumActionType.Edit); break; } if (!securityCheck) { ShowError(GetString("ForumNewPost.PermissionDenied")); return; } #region "Captcha" // Check security code if is required if ((ForumContext.CurrentForum.ForumUseCAPTCHA) && (!SecurityCode1.IsValid()) && (ForumContext.CurrentState != ForumStateEnum.EditPost)) { ShowError(GetString("ForumNewPost.InvalidCaptcha")); return; } #endregion #region "Email field" // Create instance of validator Validator validator = new Validator(); // Check whether email is valid string result = validator.IsEmail(txtEmail.Text, rfvEmail.ErrorMessage).Result; // Check whether email is present with correct format if email is required // or when subscribtion to current post is checked if ((ForumContext.CurrentForum.ForumRequireEmail || chkSubscribe.Checked) && (!String.IsNullOrEmpty(result))) { ShowError(result); return; } // Check if email is added if is in correct format if ((txtEmail.Text.Trim() != "") && (!String.IsNullOrEmpty(result))) { ShowError(rfvEmail.ErrorMessage); return; } #endregion #region "Subject" // Check whether subject is filled if (txtSubject.Text.Trim() == "") { ShowError(rfvSubject.ErrorMessage); return; } #endregion #region "Text" validator = new Validator(); // Check post text in HTML editor or text area if (!ForumContext.CurrentForum.ForumHTMLEditor) { // Check whether post text is added in text area if ((result = validator.NotEmpty(DiscussionMacroHelper.RemoveTags(ucBBEditor.Text), rfvText.ErrorMessage).Result) != "") { ShowError(result); return; } } else { // Check whether post text is added in HTML editor if ((result = validator.NotEmpty(htmlTemplateBody.ResolvedValue, rfvText.ErrorMessage).Result) != "") { ShowError(result); return; } } #endregion #region "User name" // Check whether user name is filled if user name field is visible if (ForumContext.CurrentForum.ForumAllowChangeName || MembershipContext.AuthenticatedUser.IsPublic() || ((ForumContext.CurrentForum != null) && (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, ForumContext.CommunityGroupID)))) { validator = new Validator(); if (!String.IsNullOrEmpty(result = validator.NotEmpty(txtUserName.Text, rfvUserName.ErrorMessage).Result)) { ShowError(result); return; } } #endregion #endregion #region "Forum post properties" bool newPost = false; // Current forum info object ForumInfo fi = ForumContext.CurrentForum; // Forum post info object ForumPostInfo fp = null; // Get forum post info with dependence on current state if (ForumContext.CurrentState == ForumStateEnum.EditPost) { // Get existing object fp = ForumContext.CurrentPost; fp.PostLastEdit = DateTime.Now; } else { // Create new forum post info object fp = new ForumPostInfo(); newPost = true; } #region "Ad-hoc forum" if (IsAdHocForum && (ForumContext.CurrentForum.ForumID == 0)) { if (DocumentContext.CurrentDocument == null) { ShowError(GetString("forums.documentdoesnotexist")); return; } fi.ForumGroupID = ForumGroupInfoProvider.GetAdHocGroupInfo(SiteID).GroupID; fi.ForumName = "AdHoc-" + Guid.NewGuid(); fi.ForumDisplayName = TextHelper.LimitLength(DocumentContext.CurrentDocument.GetDocumentName(), POST_USERNAME_LENGTH, String.Empty); fi.ForumOpen = true; fi.ForumModerated = false; fi.ForumAccess = 040000; fi.ForumThreads = 0; fi.ForumPosts = 0; fi.ForumLogActivity = LogActivity; ForumInfoProvider.SetForumInfo(fi); ForumContext.CurrentForum.ForumID = fi.ForumID; ForumContext.ForumID = fi.ForumID; ForumID = fi.ForumID; } #endregion // Post forum fp.PostForumID = ForumContext.CurrentForum.ForumID; // Get forum post info with dependence on current state if (ForumContext.CurrentState != ForumStateEnum.EditPost) { // Post time fp.PostTime = DateTime.Now; // User IP address fp.PostInfo.IPAddress = RequestContext.UserHostAddress; // User agent fp.PostInfo.Agent = Request.UserAgent; // Post user id if (!MembershipContext.AuthenticatedUser.IsPublic()) { fp.PostUserID = MembershipContext.AuthenticatedUser.UserID; } // Post signature fp.PostUserSignature = txtSignature.Text; } // Post subject fp.PostSubject = txtSubject.Text; // Post user email fp.PostUserMail = txtEmail.Text; // Post type int forumType = ForumContext.CurrentForum.ForumType; if (forumType == 0) { if (ForumContext.CurrentReplyThread == null) { // New thread - use type which user chosen fp.PostType = (radTypeDiscussion.Checked ? 0 : 1); } else { // Reply - use parent type fp.PostType = ForumContext.CurrentReplyThread.PostType; } } else { // Fixed type - use the forum setting fp.PostType = forumType - 1; } bool newThread = (ForumContext.CurrentReplyThread == null); // Set username if change name is allowed if (fi.ForumAllowChangeName || MembershipContext.AuthenticatedUser.IsPublic() || ForumContext.UserIsModerator(fp.PostForumID, ForumContext.CommunityGroupID)) { fp.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); } else { // Get forum post info with dependence on current state if (ForumContext.CurrentState != ForumStateEnum.EditPost) { fp.PostUserName = UserName; } } // Post parent id -> reply to if (ForumContext.CurrentReplyThread != null) { fp.PostParentID = ForumContext.CurrentReplyThread.PostId; // Check max relative level if ((MaxRelativeLevel > -1) && (ForumContext.CurrentReplyThread.PostLevel >= MaxRelativeLevel)) { ShowError(GetString("Forums.MaxRelativeLevelError")); return; } } // Get post text from HTML editor if is enabled fp.PostText = ForumContext.CurrentForum.ForumHTMLEditor ? htmlTemplateBody.ResolvedValue : ucBBEditor.Text; // Approve post if forum is not moderated if (newPost) { if (!ForumContext.CurrentForum.ForumModerated) { fp.PostApproved = true; } else { if (ForumContext.UserIsModerator(fp.PostForumID, CommunityGroupID)) { fp.PostApproved = true; fp.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; } } } // If signature is enabled then if (EnableSignature) { fp.PostUserSignature = MembershipContext.AuthenticatedUser.UserSignature; } #endregion if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { // Prepare columns to check Dictionary <string, int> columns = new Dictionary <string, int>(); columns.Add("PostText", 0); columns.Add("PostSubject", 450); columns.Add("PostUserSignature", 0); columns.Add("PostUserName", 200); // Perform bad words check string badMessage = BadWordsHelper.CheckBadWords(fp, columns, "PostApproved", "PostApprovedByUserID", fp.PostText, MembershipContext.AuthenticatedUser.UserID, () => { return(ValidatePost(fp)); }); if (String.IsNullOrEmpty(badMessage)) { if (!ValidatePost(fp)) { badMessage = GetString("ForumNewPost.EmptyBadWord"); } } if (!String.IsNullOrEmpty(badMessage)) { ShowError(badMessage); return; } } // Flood protection if (FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { ShowError(GetString("General.FloodProtection")); return; } // Check banned ip if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { ShowError(GetString("General.BannedIP")); return; } string baseUrl = ForumContext.CurrentForum.ForumBaseUrl; if (String.IsNullOrEmpty(baseUrl)) { baseUrl = FriendlyBaseURL; } string unsubscriptionUrl = ForumContext.CurrentForum.ForumUnsubscriptionUrl; if (String.IsNullOrEmpty(unsubscriptionUrl)) { unsubscriptionUrl = UnsubscriptionURL; } // USe parent post id for new post int subscibePostId = newPost ? fp.PostParentID : fp.PostId; // Check subscriptions if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(txtEmail.Text)) && (ForumSubscriptionInfoProvider.IsSubscribed(txtEmail.Text.Trim(), fp.PostForumID, subscibePostId))) { // Post of the forum is already subscribed to this email -> show an error chkSubscribe.Checked = false; ShowError(GetString("Forums.EmailAlreadySubscribed")); return; } // Save post object ForumPostInfoProvider.SetForumPostInfo(fp, baseUrl, unsubscriptionUrl); LogPostActivity(fp, fi); #region "Subscription" // If subscribe is checked create new subscription to the current post if ((chkSubscribe.Checked) && (!ForumSubscriptionInfoProvider.IsSubscribed(fp.PostUserMail, fp.PostForumID, fp.PostId))) { // Create new subscription info object ForumSubscriptionInfo fsi = new ForumSubscriptionInfo(); // Set info properties fsi.SubscriptionForumID = fp.PostForumID; fsi.SubscriptionEmail = fp.PostUserMail; fsi.SubscriptionPostID = fp.PostId; fsi.SubscriptionUserID = fp.PostUserID; fsi.SubscriptionGUID = Guid.NewGuid(); // Save subscription ForumSubscriptionInfoProvider.Subscribe(fsi, DateTime.Now, true, true); if (fsi.SubscriptionApproved) { LogSubscriptionActivity(fsi, fi); } } #endregion bool moderationRequired = false; if ((!fp.PostApproved) && (!ForumContext.UserIsModerator(fp.PostForumID, CommunityGroupID))) { moderationRequired = true; if (OnModerationRequired != null) { OnModerationRequired(this, null); } } // Keep current user info CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser; if (currentUser.IsAuthenticated() && chkAttachFile.Checked && (currentUser.IsGlobalAdministrator || ForumContext.CurrentForum.AllowAttachFiles != SecurityAccessEnum.Nobody)) { // Redirect to the post attachments string attachmentUrl = GetURL(fp, ForumActionType.Attachment); if (moderationRequired) { attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "moderated", "1"); } URLHelper.Redirect(attachmentUrl); } else { if (!StopProcessing) { // Redirect back to the forum or forum thread URLHelper.Redirect(ClearURL()); } } }
/// <summary> /// Reloads the form data. /// </summary> public override void ReloadData() { fi = ForumInfoProvider.GetForumInfo(ForumID); replyPi = ForumPostInfoProvider.GetForumPostInfo(ReplyToPostID); editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); var cui = MembershipContext.AuthenticatedUser; // Edit post if (editPi != null) { ForumPost1.PostID = editPi.PostId; ForumPost1.DisplayOnly = true; if (DisableCancelButton) { btnCancel.Enabled = false; } ucBBEditor.Text = editPi.PostText; htmlTemplateBody.ResolvedValue = editPi.PostText; txtSubject.Text = editPi.PostSubject; txtSignature.Text = editPi.PostUserSignature; txtEmail.Text = editPi.PostUserMail; txtUserName.Text = editPi.PostUserName; plcIsAnswer.Visible = true; plcIsNotAnswer.Visible = true; txtPostIsAnswer.Text = editPi.PostIsAnswer.ToString(); txtPostIsNotAnswer.Text = editPi.PostIsNotAnswer.ToString(); if ((fi != null) && (fi.ForumType == 0) && (editPi.PostLevel == 0)) { if (editPi.PostType == 0) { radTypeDiscussion.Checked = true; } else { radTypeQuestion.Checked = true; } } else { plcThreadType.Visible = false; } } else { // Reply to post if (replyPi != null) { pnlReplyPost.Visible = true; ForumPost1.PostID = replyPi.PostId; ForumPost1.DisplayOnly = true; plcThreadType.Visible = false; txtSignature.Text = cui.UserSignature; txtEmail.Text = cui.Email; if (!String.IsNullOrEmpty(cui.UserNickName)) { txtUserName.Text = cui.UserNickName.Trim(); } else { txtUserName.Text = Functions.GetFormattedUserName(cui.UserName, IsLiveSite); } if (!replyPi.PostSubject.StartsWithCSafe(GetString("Forums.ReplyPrefix"))) { txtSubject.Text = GetString("Forums.ReplyPrefix") + replyPi.PostSubject; txtSubject.Text = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, ""); } else { txtSubject.Text = replyPi.PostSubject; } btnCancel.Enabled = true; } // Create new thread else { btnCancel.Enabled = false; txtSignature.Text = cui.UserSignature; txtEmail.Text = cui.Email; if (!String.IsNullOrEmpty(cui.UserNickName)) { txtUserName.Text = cui.UserNickName.Trim(); } else { txtUserName.Text = Functions.GetFormattedUserName(cui.UserName, IsLiveSite); } } } }
/// <summary> /// Renders ForumPost control for specified node. /// </summary> /// <param name="postRow">Forum post data row</param> /// <param name="sbRendered">String builder instance containing rendered text of control</param> private string DynamicForumPostRender(DataRow postRow, out StringBuilder sbRendered) { // Create detail of post to string sbRendered = new StringBuilder(); string mId = ""; ForumPostInfo fpi = new ForumPostInfo(postRow); if (ShowMode != ShowModeEnum.TreeMode) { StringWriter sw = new StringWriter(sbRendered); Html32TextWriter writer = new Html32TextWriter(sw); ForumViewer post = (ForumViewer)Page.LoadUserControl("~/CMSModules/Forums/Controls/Posts/ForumPost.ascx"); post.ID = "forumPost" + fpi.PostId; CopyValues(post); post.SetValue("PostInfo", fpi); post.ReloadData(); post.RenderControl(writer); mId = ClientID + fpi.PostId; } return mId; }
protected void btnOk_Click(object sender, EventArgs e) { if (CommunityGroupID == 0) { // Check forums modify permissions if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.forums", PERMISSION_MODIFY)) { RedirectToAccessDenied("cms.forums", PERMISSION_MODIFY); } } else { // Check group permissions CMSDeskPage.CheckGroupPermissions(CommunityGroupID, PERMISSION_MANAGE); } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedValue, 0); What what = What.Selected; //(What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); List <int> items = new List <int>(); switch (what) { // Only selected posts case What.Selected: foreach (string item in gridPosts.SelectedItems) { items.Add(ValidationHelper.GetInteger(item, 0)); } break; // On posts in unigrid case What.All: DataSet ds = gridPosts.GridView.DataSource as DataSet; if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { int postId = ValidationHelper.GetInteger(dr["PostId"], 0); items.Add(postId); } } break; } // For all specified forum posts foreach (int postId in items) { ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(postId); if (fpi != null) { switch (action) { // Approve post case Action.Approve: fpi.Approve(); break; // Approve subtree case Action.ApproveSubTree: fpi.Approve(MembershipContext.AuthenticatedUser.UserID, true); break; // Reject post case Action.Reject: fpi.Reject(); break; // Reject subtree case Action.RejectSubTree: fpi.Reject(true); break; // Delete post case Action.Delete: ForumPostInfoProvider.DeleteForumPostInfo(fpi); break; } } } // If something happened if (items.Count > 0) { // Get rid of selection gridPosts.ResetSelection(); // Reload unigrid to see changes gridPosts.ReloadData(); // Force refresh post tree ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "RefreshPostTree", ScriptHelper.GetScript("SelectInTree(" + PostId + ", true);")); } }
/// <summary> /// Btn OK handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!CheckPermissions("cms.forums", PERMISSION_MODIFY)) { return; } if (editPi == null) { editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); } // Sets the current or parent post id int subscibePostId = 0; if (editPi != null) { editPi.PostLastEdit = DateTime.Now; editPi.PostIsAnswer = ValidationHelper.GetInteger(txtPostIsAnswer.Text, editPi.PostIsAnswer); editPi.PostIsNotAnswer = ValidationHelper.GetInteger(txtPostIsNotAnswer.Text, editPi.PostIsNotAnswer); } else { // Create new post editPi = new ForumPostInfo(); // Set as reply if (replyPi != null) { editPi.PostParentID = replyPi.PostId; subscibePostId = replyPi.PostId; } editPi.PostUserID = MembershipContext.AuthenticatedUser.UserID; editPi.PostForumID = fi.ForumID; editPi.SiteId = fi.ForumSiteID; editPi.PostTime = DateTime.Now; editPi.PostApproved = true; editPi.PostApprovedByUserID = MembershipContext.AuthenticatedUser.UserID; } #region "Security" string result = new Validator().NotEmpty(txtSubject.Text, rfvSubject.ErrorMessage).NotEmpty(txtUserName, rfvUserName.ErrorMessage).Result; // Check if is some text in TextArea or in HTMLEditor if (result == "") { if (fi.ForumHTMLEditor) { if (htmlTemplateBody.ResolvedValue.Trim() == "") { result = rfvText.ErrorMessage; } editPi.PostText = htmlTemplateBody.ResolvedValue; } else { if (DiscussionMacroResolver.RemoveTags(ucBBEditor.Text).Trim() == "") { result = rfvText.ErrorMessage; } editPi.PostText = ucBBEditor.Text; } } if ((fi.ForumRequireEmail || chkSubscribe.Checked || (txtEmail.Text != String.Empty)) && result == "") { result = new Validator().IsEmail(txtEmail.Text, rfvEmail.ErrorMessage).Result; if (!String.IsNullOrEmpty(result)) { ShowError(result); if (chkSubscribe.Checked && String.IsNullOrEmpty(txtEmail.Text)) { ShowError(GetString("Forums.Emailsubscribe")); } Visible = true; return; } } #endregion // Check subscriptions if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(txtEmail.Text)) && (ForumSubscriptionInfoProvider.IsSubscribed(txtEmail.Text.Trim(), editPi.PostForumID, subscibePostId))) { // Post of the forum is already subscribed to this email -> show an error result = GetString("Forums.EmailAlreadySubscribed"); chkSubscribe.Checked = false; } if (String.IsNullOrEmpty(result)) { if (fi.ForumType == 0) { editPi.PostType = (radTypeQuestion.Checked) ? 1 : 0; } editPi.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); editPi.PostSubject = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, ""); editPi.PostUserMail = txtEmail.Text; editPi.PostUserSignature = txtSignature.Text; ForumPostInfoProvider.SetForumPostInfo(editPi); EditPostID = editPi.PostId; #region "Subscription" if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(editPi.PostUserMail))) { ForumSubscriptionInfo fsi = new ForumSubscriptionInfo(); fsi.SubscriptionForumID = ForumID; fsi.SubscriptionEmail = editPi.PostUserMail; fsi.SubscriptionPostID = editPi.PostId; fsi.SubscriptionUserID = MembershipContext.AuthenticatedUser.UserID; fsi.SubscriptionGUID = Guid.NewGuid(); ForumSubscriptionInfoProvider.Subscribe(fsi, DateTime.Now, true, true); } #endregion ClearForm(); if (OnInsertPost != null) { OnInsertPost(this, null); } RaiseOnSaved(); } else { ShowError(result); return; } }
/// <summary> /// Preview click handler. /// </summary> protected void btnPreview_Click(object sender, EventArgs e) { ForumPostInfo fp = new ForumPostInfo(); fp.PostUserMail = txtEmail.Text; fp.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); fp.PostText = ucBBEditor.Text; if (fi.ForumHTMLEditor) { fp.PostText = htmlTemplateBody.ResolvedValue; } fp.PostTime = DateTime.Now; fp.PostSubject = txtSubject.Text; fp.PostUserSignature = txtSignature.Text; fp.PostForumID = (editPi != null) ? editPi.PostForumID : ForumID; fp.PostUserID = (editPi != null) ? editPi.PostUserID : MembershipContext.AuthenticatedUser.UserID; if (replyPi != null) { fp.PostLevel = replyPi.PostLevel + 1; } ForumPost1.DisplayOnly = true; ForumPost1.PostData = fp.Generalized.DataClass; pnlReplyPost.Visible = true; lblHeader.Text = GetString("Forums_ForumNewPost_Header.Preview"); // Fire the event if (OnPreview != null) { OnPreview(this, null); } }
protected void Page_Load(object sender, EventArgs e) { DataSet results = GetSearchDataSet(); // Bind the results to the control displaying it if (!DataHelper.DataSourceIsEmpty(results)) { uniForumPosts.DataSource = results; uniForumPosts.DataBind(); #region "Results info" string path = String.Empty; string[] splited = null; // If search in threads is enabled if (SearchInThreads != String.Empty) { splited = SearchInThreads.Split(new string[1] { ";" }, StringSplitOptions.RemoveEmptyEntries); if ((splited != null) && (splited.Length == 1)) { // Get post info ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(ValidationHelper.GetInteger(splited[0], 0)); if (fpi != null) { // Get path from Post subject path = HTMLHelper.HTMLEncode(fpi.PostSubject); // Get forum info ForumInfo fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID); if (fi != null) { // Get path from forum display name and post subject path = HTMLHelper.HTMLEncode(fi.ForumDisplayName) + pathSeparator + path; // Get forum group info ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { // Get path from group name, display name and post subject path = HTMLHelper.HTMLEncode(fgi.GroupDisplayName) + pathSeparator + path; } } path = GetString("ForumSearch.InThread") + path; } } } else if (SearchInForums != String.Empty) { splited = SearchInForums.Split(new string[1] { ";" }, StringSplitOptions.RemoveEmptyEntries); if ((splited != null) && (splited.Length == 1)) { // Get forum info ForumInfo fi = ForumInfoProvider.GetForumInfo(ValidationHelper.GetInteger(splited[0], 0)); if (fi != null) { // Path is forum display name path = HTMLHelper.HTMLEncode(fi.ForumDisplayName); // Get forum group info ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { // Path is group display name and forum display name path = HTMLHelper.HTMLEncode(fgi.GroupDisplayName) + pathSeparator + path; } path = GetString("ForumSearch.InForum") + path; } } } else if (SearchInGroups != null) { splited = SearchInGroups.Split(new string[1] { ";" }, StringSplitOptions.RemoveEmptyEntries); if ((splited != null) && (splited.Length == 1)) { // Get forum group info ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(splited[0], SiteID, CommunityGroupID); if (fgi != null) { // Path is group display name path = HTMLHelper.HTMLEncode(fgi.GroupDisplayName); path = GetString("ForumSearch.InForumGroup") + path; } } } // Format search result ltlResultsInfo.Text = "<div class=\"ForumSearchResultsInfo\">" + String.Format(GetString("ForumSearch.SearchResultsInfo"), HTMLHelper.HTMLEncode(QueryHelper.GetString("searchtext", "")), path, results.Tables[0].Rows.Count) + "</div>"; #endregion } else { // No search results lblNoResults.Visible = true; plcResults.Visible = false; lblNoResults.Text = SearchNoResults; } }
protected void Page_Load(object sender, EventArgs e) { bool process = (Visible && !StopProcessing); fi = ForumInfoProvider.GetForumInfo(ForumID); replyPi = ForumPostInfoProvider.GetForumPostInfo(ReplyToPostID); editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); if ((fi == null) && (editPi != null)) { fi = ForumInfoProvider.GetForumInfo(editPi.PostForumID); ForumID = fi.ForumID; } // Check whether the post still exists if (EditPostID > 0) { EditedObject = editPi; } // Check whether the post still exists if ((ForumID > 0) && (fi == null)) { RedirectToInformation("editedobject.notexists"); } #region "HTML Editor properties" // 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 // Regular expression to validate email (e-mail is not required) rfvEmail.ValidationExpression = @"^([\w0-9_\-\+]+(\.[\w0-9_\-\+]+)*@[\w0-9_-]+(\.[\w0-9_-]+)+)*$"; if (fi != null) { if ((fi.ForumType == 0) && (replyPi == null)) { plcThreadType.Visible = true; } if (fi.ForumRequireEmail) { rfvEmailRequired.Enabled = true; rfvEmailRequired.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.emailRequireErrorMsg"); } #region "Forum text" rfvText.Enabled = !fi.ForumHTMLEditor; htmlTemplateBody.Visible = fi.ForumHTMLEditor; ucBBEditor.Visible = !fi.ForumHTMLEditor; if (fi.ForumHTMLEditor) { // 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*/" } }; // Register script for HTML Editor forum buttons control if (!fi.ForumEnableURL) { htmlTemplateBody.RemoveButtons.Add("InsertUrl"); if (!fi.ForumEnableAdvancedURL) { // Remove the keyboard shortcut for the link insertion keystrokes.Remove("link"); } } if (!fi.ForumEnableImage) { htmlTemplateBody.RemoveButtons.Add("InsertImage"); } if (!fi.ForumEnableQuote) { htmlTemplateBody.RemoveButtons.Add("InsertQuote"); } if (!fi.ForumEnableAdvancedURL) { htmlTemplateBody.RemoveButtons.Add("InsertLink"); } if (!fi.ForumEnableAdvancedImage) { htmlTemplateBody.RemoveButtons.Add("InsertImageOrMedia"); } 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.ShowBold = fi.ForumEnableFontBold; ucBBEditor.ShowItalic = fi.ForumEnableFontItalics; ucBBEditor.ShowUnderline = fi.ForumEnableFontUnderline; ucBBEditor.ShowStrike = fi.ForumEnableFontStrike; ucBBEditor.ShowCode = fi.ForumEnableCodeSnippet; ucBBEditor.ShowColor = fi.ForumEnableFontColor; ucBBEditor.ShowURL = fi.ForumEnableURL; ucBBEditor.ShowAdvancedImage = fi.ForumEnableAdvancedImage; ucBBEditor.ShowAdvancedURL = fi.ForumEnableAdvancedURL; // WAI validation lblText.AssociatedControlClientID = ucBBEditor.TextArea.ClientID; } #endregion } // Do not show subscribe checkbox if no post can't be added under the post if ((replyPi != null) && (replyPi.PostLevel >= ForumPostInfoProvider.MaxPostLevel - 1)) { plcSubscribe.Visible = false; } #region "Resources" rfvEmail.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.emailErrorMsg"); 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"); lblPostIsAnswerLabel.Text = GetString("ForumPost_Edit.PostIsAnswer"); lblPostIsNotAnswerLabel.Text = GetString("ForumPost_Edit.PostIsNotAnswer"); #endregion if (!IsLiveSite && !RequestHelper.IsPostBack() && process) { ReloadData(); } }
/// <summary> /// Btn OK handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!CheckPermissions("cms.forums", PERMISSION_MODIFY)) { return; } if (editPi == null) { editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); } // Sets the current or parent post id int subscibePostId = 0; if (editPi != null) { editPi.PostLastEdit = DateTime.Now; editPi.PostIsAnswer = ValidationHelper.GetInteger(txtPostIsAnswer.Text, editPi.PostIsAnswer); editPi.PostIsNotAnswer = ValidationHelper.GetInteger(txtPostIsNotAnswer.Text, editPi.PostIsNotAnswer); } else { // Create new post editPi = new ForumPostInfo(); // Set as reply if (replyPi != null) { editPi.PostParentID = replyPi.PostId; subscibePostId = replyPi.PostId; } editPi.PostUserID = CMSContext.CurrentUser.UserID; editPi.PostForumID = fi.ForumID; editPi.PostTime = DateTime.Now; editPi.PostApproved = true; editPi.PostApprovedByUserID = CMSContext.CurrentUser.UserID; } #region "Security" string result = new Validator().NotEmpty(txtSubject.Text, rfvSubject.ErrorMessage).NotEmpty(txtUserName, rfvUserName.ErrorMessage).Result; // Check if is some text in TextArea or in HTMLEditor if (result == "") { if (fi.ForumHTMLEditor) { if (htmlTemplateBody.ResolvedValue.Trim() == "") { result = rfvText.ErrorMessage; } editPi.PostText = htmlTemplateBody.ResolvedValue; } else { if (DiscussionMacroHelper.RemoveTags(ucBBEditor.Text).Trim() == "") { result = rfvText.ErrorMessage; } editPi.PostText = ucBBEditor.Text; } } if ((fi.ForumRequireEmail || chkSubscribe.Checked || (txtEmail.Text != String.Empty)) && result == "") { result = new Validator().IsEmail(txtEmail.Text, rfvEmail.ErrorMessage).Result; if (!String.IsNullOrEmpty(result)) { ShowError(result); if (chkSubscribe.Checked && String.IsNullOrEmpty(txtEmail.Text)) { ShowError(GetString("Forums.Emailsubscribe")); } Visible = true; return; } } #endregion // Check subscriptions if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(txtEmail.Text)) && (ForumSubscriptionInfoProvider.IsSubscribed(txtEmail.Text.Trim(), editPi.PostForumID, subscibePostId))) { // Post of the forum is already subscribed to this email -> show an error result = GetString("Forums.EmailAlreadySubscribed"); chkSubscribe.Checked = false; } if (String.IsNullOrEmpty(result)) { if (fi.ForumType == 0) { editPi.PostType = (radTypeQuestion.Checked) ? 1 : 0; } editPi.PostUserName = TextHelper.LimitLength(txtUserName.Text, POST_USERNAME_LENGTH, ""); editPi.PostSubject = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, ""); editPi.PostUserMail = txtEmail.Text; editPi.PostUserSignature = txtSignature.Text; ForumPostInfoProvider.SetForumPostInfo(editPi); EditPostID = editPi.PostId; #region "Subscription" if ((chkSubscribe.Checked) && (!String.IsNullOrEmpty(editPi.PostUserMail))) { ForumSubscriptionInfo fsi = new ForumSubscriptionInfo(); fsi.SubscriptionForumID = ForumID; fsi.SubscriptionEmail = editPi.PostUserMail; fsi.SubscriptionPostID = editPi.PostId; fsi.SubscriptionUserID = CMSContext.CurrentUser.UserID; fsi.SubscriptionGUID = Guid.NewGuid(); ForumSubscriptionInfoProvider.Subscribe(fsi, DateTime.Now, true, true); } #endregion ClearForm(); if (OnInsertPost != null) { OnInsertPost(this, null); } RaiseOnSaved(); } else { ShowError(result); return; } }
/// <summary> /// Loads the forums dropdownlist for topic move. /// </summary> private void LoadMoveTopicDropdown() { if (drpMoveToForum.Items.Count > 0) { return; } int currentForumId = 0; ForumPostInfo fpi = ForumContext.CurrentThread; if ((fpi == null) && (CurrentThread > 0)) { fpi = ForumPostInfoProvider.GetForumPostInfo(CurrentThread); } if (fpi != null) { bool isOk = AdminMode ? true : ((ForumContext.CurrentForum != null) && (ForumContext.CurrentForum.ForumID == fpi.PostForumID)); if (isOk) { currentForumId = fpi.PostForumID; ForumInfo fi = ForumInfoProvider.GetForumInfo(currentForumId); if (fi != null) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { string where = null; DataSet dsGroups = null; if (fgi.GroupGroupID > 0) { where = "GroupName NOT LIKE 'AdHoc%' AND GroupSiteID = " + SiteID + " AND GroupGroupID = " + fgi.GroupGroupID; } else { where = "GroupName NOT LIKE 'AdHoc%' AND GroupSiteID = " + SiteID + " AND GroupGroupID IS NULL"; } dsGroups = ForumGroupInfoProvider.GetGroups(where, "GroupDisplayName", 0, "GroupID, GroupDisplayName"); if (!DataHelper.DataSourceIsEmpty(dsGroups)) { Hashtable forums = new Hashtable(); // Get all forums for selected groups string groupWhere = "AND ForumGroupID IN (SELECT GroupID FROM Forums_ForumGroup WHERE " + where + ") "; DataSet dsForums = ForumInfoProvider.GetForums(" ForumOpen = 1 " + " AND NOT ForumID = " + currentForumId + groupWhere, "ForumDisplayName", 0, "ForumID, ForumDisplayName, ForumGroupID"); if (!DataHelper.DataSourceIsEmpty(dsForums)) { // Load forums into hash table foreach (DataRow drForum in dsForums.Tables[0].Rows) { int groupId = Convert.ToInt32(drForum["ForumGroupID"]); List <string[]> forumNames = forums[groupId] as List <string[]>; if (forumNames == null) { forumNames = new List <string[]>(); } forumNames.Add(new string[] { Convert.ToString(drForum["ForumDisplayName"]), Convert.ToString(drForum["ForumID"]) }); forums[groupId] = forumNames; } } foreach (DataRow dr in dsGroups.Tables[0].Rows) { int groupId = Convert.ToInt32(dr["GroupId"]); List <string[]> forumNames = forums[groupId] as List <string[]>; if (forumNames != null) { // Add forum group item if some forum ListItem li = new ListItem(Convert.ToString(dr["GroupDisplayName"]), "0"); li.Attributes.Add("disabled", "disabled"); drpMoveToForum.Items.Add(li); // Add forum items foreach (string[] forum in forumNames) { // Add forum to DDL drpMoveToForum.Items.Add(new ListItem(" \xA0\xA0\xA0\xA0 " + forum[0], forum[1])); } } } // Display message if no forum exists if (drpMoveToForum.Items.Count == 0) { plcMoveInner.Visible = false; ShowInformation(GetString("Forums.NoForumToMoveIn")); } } } } } } }
/// <summary> /// Reloads the form data. /// </summary> public override void ReloadData() { fi = ForumInfoProvider.GetForumInfo(ForumID); replyPi = ForumPostInfoProvider.GetForumPostInfo(ReplyToPostID); editPi = ForumPostInfoProvider.GetForumPostInfo(EditPostID); CurrentUserInfo cui = CMSContext.CurrentUser; // Edit post if (editPi != null) { ForumPost1.PostID = editPi.PostId; ForumPost1.DisplayOnly = true; if (DisableCancelButton) { btnCancel.Enabled = false; } ucBBEditor.Text = editPi.PostText; htmlTemplateBody.ResolvedValue = editPi.PostText; txtSubject.Text = editPi.PostSubject; txtSignature.Text = editPi.PostUserSignature; txtEmail.Text = editPi.PostUserMail; txtUserName.Text = editPi.PostUserName; plcIsAnswer.Visible = true; plcIsNotAnswer.Visible = true; txtPostIsAnswer.Text = editPi.PostIsAnswer.ToString(); txtPostIsNotAnswer.Text = editPi.PostIsNotAnswer.ToString(); if ((fi != null) && (fi.ForumType == 0) && (editPi.PostLevel == 0)) { if (editPi.PostType == 0) { radTypeDiscussion.Checked = true; } else { radTypeQuestion.Checked = true; } } else { plcThreadType.Visible = false; } } else { // Reply to post if (replyPi != null) { pnlReplyPost.Visible = true; ForumPost1.PostID = replyPi.PostId; ForumPost1.DisplayOnly = true; plcThreadType.Visible = false; txtSignature.Text = cui.UserSignature; txtEmail.Text = cui.Email; if (!String.IsNullOrEmpty(cui.UserNickName)) { txtUserName.Text = cui.UserNickName.Trim(); } else { txtUserName.Text = Functions.GetFormattedUserName(cui.UserName, IsLiveSite); } if (!replyPi.PostSubject.StartsWithCSafe(GetString("Forums.ReplyPrefix"))) { txtSubject.Text = GetString("Forums.ReplyPrefix") + replyPi.PostSubject; txtSubject.Text = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, ""); } else { txtSubject.Text = replyPi.PostSubject; } btnCancel.Enabled = true; } // Create new thread else { btnCancel.Enabled = false; txtSignature.Text = cui.UserSignature; txtEmail.Text = cui.Email; if (!String.IsNullOrEmpty(cui.UserNickName)) { txtUserName.Text = cui.UserNickName.Trim(); } else { txtUserName.Text = Functions.GetFormattedUserName(cui.UserName, IsLiveSite); } } } }
/// <summary> /// Renders ForumPost control for specified node. /// </summary> /// <param name="postRow">Forum post data row</param> /// <param name="sbRendered">String builder instance containing rendered text of control</param> /// <returns>Id of the created forumpost control</returns> private string DynamicForumPostRender(DataRow postRow, out StringBuilder sbRendered) { // Create detail of post to string sbRendered = new StringBuilder(); string mId = ""; ForumPostInfo fpi = new ForumPostInfo(postRow); if (this.ShowMode != ShowModeEnum.TreeMode) { StringWriter sw = new StringWriter(sbRendered); Html32TextWriter writer = new Html32TextWriter(sw); CMSModules_Forums_Controls_Posts_ForumPost post = (CMSModules_Forums_Controls_Posts_ForumPost)this.Page.LoadControl("~/CMSModules/Forums/Controls/Posts/ForumPost.ascx"); post.ID = "forumPost" + fpi.PostId; CopyValues(post); post.PostInfo = fpi; post.ReloadData(); post.RenderControl(writer); mId = this.ClientID + fpi.PostId; } return mId; }