Example #1
0
    /// <summary>
    /// Loads the data.
    /// </summary>
    private void LoadData()
    {
        // Get the forum post
        ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(ValidationHelper.GetInteger(PostID, 0));
        ForumInfo     fi  = null;

        if (fpi != null)
        {
            fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID);
        }
        else
        {
            return;
        }

        if (fi.ForumEnableAdvancedImage)
        {
            ltrText.AllowedControls = ControlsHelper.ALLOWED_FORUM_CONTROLS;
        }
        else
        {
            ltrText.AllowedControls = "none";
        }

        // Display converted datetime for live site
        lblDate.Text = CMSContext.ConvertDateTime(ValidationHelper.GetDateTime(fpi.PostTime, DateTimeHelper.ZERO_TIME), this).ToString();

        lblUser.Text    = HTMLHelper.HTMLEncode(fpi.PostUserName);
        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;
        }

        // Resolve the macros and display the post text
        ltrText.Text = dmh.ResolveMacros(fpi.PostText);
    }
Example #2
0
    /// <summary>
    /// Loads the data.
    /// </summary>
    private void LoadData()
    {
        // Get the forum post
        ForumPostInfo fpi = ForumPostInfoProvider.GetForumPostInfo(ValidationHelper.GetInteger(PostID, 0));
        ForumInfo fi = null;

        if (fpi != null)
        {
            fi = ForumInfoProvider.GetForumInfo(fpi.PostForumID);
        }
        else
        {
            return;
        }

        if (fi.ForumEnableAdvancedImage)
        {
            ltrText.AllowedControls = ControlsHelper.ALLOWED_FORUM_CONTROLS;
        }
        else
        {
            ltrText.AllowedControls = "none";
        }

        // Display converted datetime for live site
        lblDate.Text = CMSContext.ConvertDateTime(ValidationHelper.GetDateTime(fpi.PostTime, DateTimeHelper.ZERO_TIME), this).ToString();

        lblUser.Text = HTMLHelper.HTMLEncode(fpi.PostUserName);
        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;
        }

        // Resolve the macros and display the post text
        ltrText.Text = dmh.ResolveMacros(fpi.PostText);
    }
Example #3
0
    /// <summary>
    /// Gets the plain text body of the e-mail message.
    /// </summary>
    /// <param name="ei">The e-mail message object</param>
    /// <returns>Plain-text body</returns>
    private string GetPlainTextBody(EmailInfo ei)
    {
        DiscussionMacroHelper dmh = new DiscussionMacroHelper {
            ResolveToPlainText = true
        };
        string body = dmh.ResolveMacros(ei.EmailPlainTextBody);

        body = HTMLHelper.HTMLEncode(body);

        ltlBodyValue.Visible = true;

        // Replace line breaks with br tags and modify discussion macros
        ltlBodyValue.Text = DiscussionMacroHelper.RemoveTags(HTMLHelper.HTMLEncodeLineBreaks(body));

        return(body);
    }
Example #4
0
    /// <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>
    /// 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());
            }
        }
    }
Example #6
0
    /// <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;
        }
    }
Example #7
0
    /// <summary>
    /// Initialize resources, holders, controls etc.
    /// </summary>
    protected void Initialize()
    {
        #region "Captcha"

        if ((ForumContext.CurrentForum.ForumUseCAPTCHA) && (ForumContext.CurrentState != ForumStateEnum.EditPost))
        {
            // Do not generate security every time
            SecurityCode1.AlwaysGenerate        = false;
            SecurityCode1.KeepCodeAutomatically = false;
        }
        else
        {
            plcCaptcha.Visible = false;
        }

        #endregion

        #region "Settings of HTML editor"

        // Set HTML editor properties
        htmlTemplateBody.AutoDetectLanguage    = false;
        htmlTemplateBody.DefaultLanguage       = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlTemplateBody.EditorAreaCSS         = "";
        htmlTemplateBody.ToolbarSet            = "Forum";
        htmlTemplateBody.DisableObjectResizing = true; // Disable image resizing
        htmlTemplateBody.RemovePlugin("contextmenu");  // Disable context menu
        htmlTemplateBody.IsLiveSite = this.IsLiveSite;
        htmlTemplateBody.MediaDialogConfig.UseFullURL = true;
        htmlTemplateBody.LinkDialogConfig.UseFullURL  = true;

        #endregion

        #region "Resource strings"

        // Resources
        rfvSubject.ErrorMessage  = GetString("Forums_WebInterface_ForumNewPost.subjectErrorMsg");
        lblText.Text             = GetString("Forums_WebInterface_ForumNewPost.text");
        rfvText.ErrorMessage     = GetString("Forums_WebInterface_ForumNewPost.textErrorMsg");
        rfvUserName.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.usernameErrorMsg");
        btnOk.Text            = GetString("general.ok");
        btnCancel.Text        = GetString("general.cancel");
        btnPreview.Text       = GetString("Forums_WebInterface_ForumNewPost.Preview");
        lblSubscribe.Text     = GetString("Forums_WebInterface_ForumNewPost.Subscription");
        lblSignature.Text     = GetString("Forums_WebInterface_ForumNewPost.Signature");
        rfvEmail.ErrorMessage = GetString("Forums_WebInterface_ForumNewPost.emailErrorMsg");
        lblCaptcha.Text       = GetString("Forums_WebInterface_ForumNewPost.captcha");
        lblAttachFile.Text    = GetString("For.NewPost.Attach");
        lblNickName.Text      = GetString("Forums_WebInterface_ForumNewPost.NickName");

        // Regular expression to validate email (e-mail is not required)
        rfvEmail.ValidationExpression = @"^([\w0-9_\-\+]+(\.[\w0-9_\-\+]+)*@[\w0-9_-]+(\.[\w0-9_-]+)+)*$";

        // WAI validation
        lblCaptcha.AssociatedControlClientID = SecurityCode1.InputClientID;

        #endregion

        #region "Controls visibility"

        ForumInfo fi = ForumContext.CurrentForum;

        // Hide or display html editor/ text area
        if (fi.ForumHTMLEditor)
        {
            ucBBEditor.Visible = false;
            rfvText.Enabled    = false;

            // Define customizable shortcuts
            Hashtable keystrokes = new Hashtable()
            {
                { "link", "CKEDITOR.CTRL + 76 /*L*/" },
                { "bold", "CKEDITOR.CTRL + 66 /*B*/" },
                { "italic", "CKEDITOR.CTRL + 73 /*I*/" },
                { "underline", "CKEDITOR.CTRL + 85 /*U*/" }
            };

            if (!fi.ForumEnableURL)
            {
                htmlTemplateBody.RemoveButton("InsertUrl");
                if (!fi.ForumEnableAdvancedURL)
                {
                    // Remove the keyborad shortcut for the link insertion
                    keystrokes.Remove("link");
                }
            }
            if (!fi.ForumEnableAdvancedURL)
            {
                htmlTemplateBody.RemoveButton("InsertLink");
            }
            if (!fi.ForumEnableImage)
            {
                htmlTemplateBody.RemoveButton("InsertImage");
            }
            if (!fi.ForumEnableAdvancedImage)
            {
                htmlTemplateBody.RemoveButton("InsertImageOrMedia");
            }
            if (!fi.ForumEnableQuote)
            {
                htmlTemplateBody.RemoveButton("InsertQuote");
            }
            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        = this.IsLiveSite;
            ucBBEditor.ShowImage         = fi.ForumEnableImage;
            ucBBEditor.ShowQuote         = fi.ForumEnableQuote;
            ucBBEditor.ShowURL           = fi.ForumEnableURL;
            ucBBEditor.ShowBold          = fi.ForumEnableFontBold;
            ucBBEditor.ShowItalic        = fi.ForumEnableFontItalics;
            ucBBEditor.ShowUnderline     = fi.ForumEnableFontUnderline;
            ucBBEditor.ShowStrike        = fi.ForumEnableFontStrike;
            ucBBEditor.ShowColor         = fi.ForumEnableFontColor;
            ucBBEditor.ShowCode          = fi.ForumEnableCodeSnippet;
            ucBBEditor.ShowAdvancedImage = fi.ForumEnableAdvancedImage;
            ucBBEditor.ShowAdvancedURL   = fi.ForumEnableAdvancedURL;
            htmlTemplateBody.Visible     = false;
        }

        if ((fi.ForumModerated) && (!ForumContext.UserIsModerator(fi.ForumID, this.CommunityGroupID)))
        {
            pnlInfo.Visible = true;
            lblInfo.Text    = GetString("forums.requiremoderation");
        }

        if ((CMSContext.CurrentUser.IsPublic()) || (!CheckPermission("AttachFiles", fi.AllowAttachFiles, fi.ForumGroupID, fi.ForumID)) || (fi.ForumModerated && !ForumContext.UserIsModerator(fi.ForumID, this.CommunityGroupID)))
        {
            plcAttachFile.Visible = false;
        }

        // If user can choose thread type and this is not reply, show the options
        if ((fi.ForumType == 0) && (ForumContext.CurrentReplyThread == null))
        {
            // Only thread can be set
            if ((ForumContext.CurrentState != ForumStateEnum.EditPost) || (ForumContext.CurrentPost.PostLevel == 0))
            {
                plcThreadType.Visible = true;
            }
        }

        // Hide or display subscription checkbox with dependence
        // on allow subscription property value and security
        if ((!AllowSubscription) || (!CheckPermission("Subscribe", fi.AllowSubscribe, fi.ForumGroupID, fi.ForumID)))
        {
            SubscribeHolder.Visible = false;
        }

        // Display signature if is allowed
        if (!AllowSignature)
        {
            plcSignature.Visible = false;
        }

        bool newThread = (ForumContext.CurrentReplyThread == null);

        // Display username textbox if is change name allowed or label with user name
        if (fi.ForumAllowChangeName || CMSContext.CurrentUser.IsPublic() || ((ForumContext.CurrentForum != null) && (ForumContext.UserIsModerator(ForumContext.CurrentForum.ForumID, ForumContext.CommunityGroupID))))
        {
            if (!RequestHelper.IsPostBack())
            {
                // Do not show 'public' for unauthenticated user
                if (!CMSContext.CurrentUser.IsPublic())
                {
                    txtUserName.Text = UserName;
                }
            }
            plcNickName.Visible = false;
        }
        else
        {
            if (ForumContext.CurrentMode != ForumMode.Edit)
            {
                lblNickNameValue.Text = HTMLHelper.HTMLEncode(UserName);
            }
            else
            {
                lblNickNameValue.Text = HTMLHelper.HTMLEncode(ForumContext.CurrentPost.PostUserName);
            }
            plcUserName.Visible = false;
        }

        // Prefill user email and reset the security code
        if (!RequestHelper.IsPostBack())
        {
            txtEmail.Text = CMSContext.CurrentUser.Email;
            SecurityCode1.GenerateNew();
        }

        if (ForumContext.CurrentReplyThread != null)
        {
            string replyPrefix = GetString("forums.replyprefix");
            if (!ForumContext.CurrentReplyThread.PostSubject.StartsWith(replyPrefix))
            {
                txtSubject.Text = replyPrefix + ForumContext.CurrentReplyThread.PostSubject;
                txtSubject.Text = TextHelper.LimitLength(txtSubject.Text, POST_SUBJECT_LENGTH, "");
            }
            else
            {
                txtSubject.Text = ForumContext.CurrentReplyThread.PostSubject;
            }
            txtSubject.Text = txtSubject.Text;


            // New post - check max level for subscribcribtion
            if (ForumContext.CurrentReplyThread.PostLevel >= ForumPostInfoProvider.MaxPostLevel - 1)
            {
                SubscribeHolder.Visible = false;
            }
        }
        // Edit post - check max level for subscribcribtion
        else if ((ForumContext.CurrentPost != null) && (ForumContext.CurrentPost.PostLevel >= ForumPostInfoProvider.MaxPostLevel))
        {
            SubscribeHolder.Visible = false;
        }


        // Hide subscription if not enabled
        if (!this.EnableSubscription)
        {
            SubscribeHolder.Visible = false;
        }

        #endregion

        #region "Post Data"

        if (!RequestHelper.IsPostBack())
        {
            // Check whether current state is edit
            if (ForumContext.CurrentState == ForumStateEnum.EditPost)
            {
                txtEmail.Text     = ForumContext.CurrentPost.PostUserMail;
                txtSignature.Text = ForumContext.CurrentPost.PostUserSignature;
                txtSubject.Text   = ForumContext.CurrentPost.PostSubject;
                txtUserName.Text  = ForumContext.CurrentPost.PostUserName;

                SetPostText(ForumContext.CurrentPost.PostText);


                radTypeDiscussion.Checked = true;

                if (ForumContext.CurrentPost.PostType == 1)
                {
                    radTypeQuestion.Checked = true;
                }
            }
            else if ((ForumContext.CurrentMode == ForumMode.Quote) && (ForumContext.CurrentReplyThread != null))
            {
                // Indicates whether wysiwyg editor is used
                bool isHtml = ForumContext.CurrentForum.ForumHTMLEditor;
                // Keeps post user name
                string userName = ForumContext.CurrentReplyThread.PostUserName;

                // Encode username for wysiwyg editor
                if (isHtml)
                {
                    userName = HTMLHelper.HTMLEncode(userName);
                }

                SetPostText(DiscussionMacroHelper.GetQuote(userName, ForumContext.CurrentReplyThread.PostText));

                // Set new line after
                if (isHtml)
                {
                    htmlTemplateBody.ResolvedValue += "<br /><br />";
                }
                else
                {
                    ucBBEditor.Text += "\n";
                }
            }
        }

        #endregion
    }
Example #8
0
    protected void btnSendMessage_Click(object sender, EventArgs e)
    {
        // This is because of ASP.NET default behaviour
        // The first empty line was trimmed after each postback
        if (BBEditor.Text.StartsWithCSafe("\n"))
        {
            BBEditor.Text = "\n" + BBEditor.Text;
        }
        // Flood protection
        if (!FloodProtectionHelper.CheckFlooding(CMSContext.CurrentSiteName, CMSContext.CurrentUser))
        {
            CurrentUserInfo currentUser = CMSContext.CurrentUser;

            // Check banned IP
            if (BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
            {
                int recipientId = ucMessageUserSelector.Visible
                                      ? ucMessageUserSelector.SelectedUserID
                                      : ValidationHelper.GetInteger(hdnUserId.Value, 0);
                string message  = string.Empty;
                string nickName = HTMLHelper.HTMLEncode(txtFrom.Text.Trim());
                if (!ValidateBody(DiscussionMacroHelper.RemoveTags(ucBBEditor.Text)))
                {
                    message = GetString("SendMessage.EmptyBody");
                }


                // Check sender nick name if anonymous
                if (isAnonymousUser && (nickName == string.Empty))
                {
                    message = GetString("SendMesage.NoNickName");
                }

                UserInfo recipient = null;

                // Check recipient
                if (recipientId == 0)
                {
                    if (string.IsNullOrEmpty(ucMessageUserSelector.UserNameTextBox.Text.Trim()))
                    {
                        message = GetString("SendMesage.NoRecipient");
                    }
                    else
                    {
                        message = GetString("SendMesage.UserDoesntExists");
                    }
                }
                else
                {
                    recipient = UserInfoProvider.GetUserInfo(recipientId);

                    // Normal users can't send message to user from other site except for global admin
                    if (!recipient.IsInSite(CMSContext.CurrentSiteName) && !currentUser.IsGlobalAdministrator)
                    {
                        message = GetString("SendMesage.UserDoesntExists");
                    }

                    int defRecipientId = ValidationHelper.GetInteger(DefaultRecipient, 0);

                    // If default recipient selected and is same as message recipient, skip check on hidden users
                    if (recipient.UserID != defRecipientId)
                    {
                        //                  Manually disabled users              Hidden users if not replying to them                                       Not approved users
                        bool userAllowed = (recipient.UserIsDisabledManually || (recipient.UserIsHidden && (SendMessageMode != MessageActionEnum.Reply)) || recipient.UserSettings.UserWaitingForApproval);

                        // If live site mode hide not allowed users for all users except for global admins and public user for all users
                        if ((IsLiveSite && userAllowed && !currentUser.IsGlobalAdministrator) || (recipient.UserName.ToLowerCSafe() == "public"))
                        {
                            message = GetString("SendMesage.UserDoesntExists");
                        }
                    }
                }

                if (message == string.Empty)
                {
                    // Send message
                    try
                    {
                        // Check if current user is in recipient's ignore list
                        bool isIgnored = IgnoreListInfoProvider.IsInIgnoreList(recipientId, currentUser.UserID);


                        Message             = new MessageInfo();
                        Message.MessageBody = ucBBEditor.Text;
                        string subject = (txtSubject.Text.Trim() == string.Empty) ? GetString("Messaging.NoSubject") : txtSubject.Text.Trim();
                        Message.MessageSubject           = TextHelper.LimitLength(subject, 200);
                        Message.MessageRecipientUserID   = recipientId;
                        Message.MessageRecipientNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(recipient.UserName, recipient.FullName, recipient.UserNickName, IsLiveSite), 200);
                        Message.MessageSent = DateTime.Now;

                        // Anonymous user
                        if (isAnonymousUser)
                        {
                            Message.MessageSenderNickName = TextHelper.LimitLength(nickName, 200);
                            Message.MessageSenderDeleted  = true;
                        }
                        else
                        {
                            Message.MessageSenderUserID   = currentUser.UserID;
                            Message.MessageSenderNickName = TextHelper.LimitLength(Functions.GetFormattedUserName(currentUser.UserName, currentUser.FullName, currentUser.UserNickName, IsLiveSite), 200);

                            // If the user is ignored, delete message automatically
                            if (isIgnored)
                            {
                                Message.MessageRecipientDeleted = true;
                            }
                        }

                        string error = string.Empty;

                        // Check bad words
                        if (!BadWordInfoProvider.CanUseBadWords(currentUser, CMSContext.CurrentSiteName))
                        {
                            // Prepare columns to check
                            Dictionary <string, int> columns = new Dictionary <string, int>();
                            columns.Add("MessageSubject", 200);
                            columns.Add("MessageBody", 0);
                            columns.Add("MessageSenderNickName", 200);
                            columns.Add("MessageRecipientNickName", 200);

                            // Perform bad word check
                            error = BadWordsHelper.CheckBadWords(Message, columns, currentUser.UserID, () => { return(ValidateBody(Message.MessageBody)); });
                        }

                        if (error != string.Empty)
                        {
                            ShowError(error);
                        }
                        else
                        {
                            // Check message subject, if empty set no subject text
                            if (Message.MessageSubject.Trim() == string.Empty)
                            {
                                Message.MessageSubject = GetString("Messaging.NoSubject");
                            }

                            // Whole text has been removed
                            if (!ValidateBody(Message.MessageBody))
                            {
                                ShowError(GetString("SendMessage.EmptyBodyBadWords"));
                            }
                            else
                            {
                                // Save the message
                                MessageInfoProvider.SetMessageInfo(Message);

                                // Send notification email, if not ignored
                                if (!isIgnored)
                                {
                                    MessageInfoProvider.SendNotificationEmail(Message, recipient, currentUser, CMSContext.CurrentSiteName);
                                }

                                ShowConfirmation(GetString("SendMesage.MessageSent"));
                                MessageId = 0;
                                ucMessageUserSelector.SelectedUserID = 0;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex.Message);
                        ErrorMessage = ex.Message;
                    }
                }
                // Error in the form
                else
                {
                    ShowError(message);
                    ErrorMessage = message;
                }
            }
            else
            {
                ShowError(GetString("General.BannedIP"));
            }
        }
        else
        {
            ShowError(GetString("General.FloodProtection"));
        }

        // External event
        if (SendButtonClick != null)
        {
            SendButtonClick(sender, e);
        }
    }
    /// <summary>
    /// Gets the plain text body of the e-mail message.
    /// </summary>
    /// <param name="ei">The e-mail message object</param>
    /// <returns>Plain-text body</returns>
    private string GetPlainTextBody(EmailInfo ei)
    {
        DiscussionMacroHelper dmh = new DiscussionMacroHelper { ResolveToPlainText = true };
        string body = dmh.ResolveMacros(ei.EmailPlainTextBody);

        body = HTMLHelper.HTMLEncode(body);

        ltlBodyValue.Visible = true;

        // Replace line breaks with br tags and modify discussion macros
        ltlBodyValue.Text = DiscussionMacroHelper.RemoveTags(HTMLHelper.HTMLEncodeLineBreaks(body));

        return body;
    }
Example #10
0
    public void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
            ucMessageUserButtons.StopProcessing = true;
            ucUserPicture.StopProcessing        = true;
        }
        else
        {
            ucMessageUserButtons.StopProcessing = false;
            ucUserPicture.StopProcessing        = false;

            if (Message != null)
            {
                // Get current user info
                currentUserInfo = CMSContext.CurrentUser;
                // Get message user info
                if (MessageMode == MessageModeEnum.Inbox)
                {
                    messageUserInfo = UserInfoProvider.GetUserInfo(Message.MessageSenderUserID);
                }
                else
                {
                    messageUserInfo = UserInfoProvider.GetUserInfo(Message.MessageRecipientUserID);
                }

                // Display only to authorized user
                if ((currentUserInfo.UserID == Message.MessageRecipientUserID) || (currentUserInfo.UserID == Message.MessageSenderUserID) || currentUserInfo.IsGlobalAdministrator)
                {
                    pnlViewMessage.Visible = true;
                    lblDateCaption.Text    = GetString("Messaging.Date");
                    lblSubjectCaption.Text = GetString("general.subject");
                    lblFromCaption.Text    = (MessageMode == MessageModeEnum.Inbox) ? GetString("Messaging.From") : GetString("Messaging.To");

                    // Sender exists
                    if (messageUserInfo != null)
                    {
                        ucUserPicture.Visible = true;
                        ucUserPicture.UserID  = messageUserInfo.UserID;

                        // Disable message user buttons on live site for hidden or disabled users
                        if (IsLiveSite && !currentUserInfo.IsGlobalAdministrator && (!messageUserInfo.Enabled || messageUserInfo.UserIsHidden))
                        {
                            ucMessageUserButtons.RelatedUserId = 0;
                        }
                        else
                        {
                            ucMessageUserButtons.RelatedUserId = messageUserInfo.UserID;
                        }
                        lblFrom.Text = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(messageUserInfo.UserName, messageUserInfo.FullName, messageUserInfo.UserNickName, IsLiveSite));
                    }
                    else
                    {
                        ucMessageUserButtons.RelatedUserId = 0;
                        lblFrom.Text = HTMLHelper.HTMLEncode(Message.MessageSenderNickName);
                    }
                    string body = Message.MessageBody;
                    // Resolve macros
                    DiscussionMacroHelper dmh = new DiscussionMacroHelper();
                    body = dmh.ResolveMacros(body);

                    lblSubject.Text = HTMLHelper.HTMLEncodeLineBreaks(Message.MessageSubject);
                    if (IsLiveSite)
                    {
                        lblDate.Text = CMSContext.ConvertDateTime(Message.MessageSent, this).ToString();
                    }
                    else
                    {
                        lblDate.Text = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(Message.MessageSent, currentUserInfo, CMSContext.CurrentSite, out usedTimeZone);
                    }
                    lblBody.Text = body;
                }
            }
            else
            {
                lblError.Text    = GetString("Messaging.MessageDoesntExist");
                lblError.Visible = true;
            }
        }
    }
    /// <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>
    /// Performs reporting of abuse.
    /// </summary>
    public void PerformAction()
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            ShowError(GetString("General.BannedIP"));
            return;
        }

        string report = txtText.Text;

        // Check that text area is not empty or too long
        report = report.Trim();
        report = TextHelper.LimitLength(report, 1000);

        if (report.Length > 0)
        {
            // Create new AbuseReport
            AbuseReportInfo abuseReport = new AbuseReportInfo();
            if (ReportTitle != "")
            {
                // Set AbuseReport properties
                // Decode first, from forums it can be encoded
                ReportTitle = Server.HtmlDecode(ReportTitle);
                // Remove BBCode tags
                ReportTitle               = DiscussionMacroHelper.RemoveTags(ReportTitle);
                abuseReport.ReportTitle   = TextHelper.LimitLength(ReportTitle, 100);
                abuseReport.ReportURL     = URLHelper.GetAbsoluteUrl(ReportURL);
                abuseReport.ReportCulture = CMSContext.PreferredCultureCode;
                if (ReportObjectID > 0)
                {
                    abuseReport.ReportObjectID = ReportObjectID;
                }

                if (ReportObjectType != "")
                {
                    abuseReport.ReportObjectType = ReportObjectType;
                }

                abuseReport.ReportComment = report;

                if (CMSContext.CurrentUser.UserID > 0)
                {
                    abuseReport.ReportUserID = CMSContext.CurrentUser.UserID;
                }

                abuseReport.ReportWhen   = DateTime.Now;
                abuseReport.ReportStatus = AbuseReportStatusEnum.New;
                abuseReport.ReportSiteID = CMSContext.CurrentSite.SiteID;

                // Save AbuseReport
                AbuseReportInfoProvider.SetAbuseReportInfo(abuseReport);

                LogActivity(abuseReport);

                ShowConfirmation(GetString(ConfirmationText), true);
                txtText.Visible      = false;
                ReportButton.Visible = false;
            }
            else
            {
                ShowError(GetString("abuse.errors.reporttitle"));
            }
        }
        else
        {
            ShowError(GetString("abuse.errors.reportcomment"));
        }

        // Additional form modification
        ReportButton.Visible        = false;
        CancelButton.ResourceString = "general.close";
    }
    public void ReloadData()
    {
        if (StopProcessing)
        {
            // Do nothing
            ucMessageUserButtons.StopProcessing = true;
            ucUserPicture.StopProcessing = true;
        }
        else
        {
            ucMessageUserButtons.StopProcessing = false;
            ucUserPicture.StopProcessing = false;

            if (Message != null)
            {
                // Get current user info
                currentUserInfo = CMSContext.CurrentUser;
                // Get message user info
                if (MessageMode == MessageModeEnum.Inbox)
                {
                    messageUserInfo = UserInfoProvider.GetUserInfo(Message.MessageSenderUserID);
                }
                else
                {
                    messageUserInfo = UserInfoProvider.GetUserInfo(Message.MessageRecipientUserID);
                }

                // Display only to authorized user
                if ((currentUserInfo.UserID == Message.MessageRecipientUserID) || (currentUserInfo.UserID == Message.MessageSenderUserID) || currentUserInfo.IsGlobalAdministrator)
                {
                    pnlViewMessage.Visible = true;
                    lblDateCaption.Text = GetString("Messaging.Date");
                    lblSubjectCaption.Text = GetString("general.subject");
                    lblFromCaption.Text = (MessageMode == MessageModeEnum.Inbox) ? GetString("Messaging.From") : GetString("Messaging.To");

                    // Sender exists
                    if (messageUserInfo != null)
                    {
                        ucUserPicture.Visible = true;
                        ucUserPicture.UserID = messageUserInfo.UserID;

                        // Gravatar support
                        string avType = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSAvatarType");
                        if (avType == AvatarInfoProvider.USERCHOICE)
                        {
                           avType = messageUserInfo.UserSettings.UserAvatarType;
                        }

                        ucUserPicture.UserAvatarType = avType;

                        // Disable message user buttons on live site for hidden or disabled users
                        if (IsLiveSite && !currentUserInfo.IsGlobalAdministrator && (messageUserInfo.UserIsDisabledManually || messageUserInfo.UserIsHidden))
                        {
                            ucMessageUserButtons.RelatedUserId = 0;
                        }
                        else
                        {
                            ucMessageUserButtons.RelatedUserId = messageUserInfo.UserID;
                        }
                        lblFrom.Text = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(messageUserInfo.UserName, messageUserInfo.FullName, messageUserInfo.UserNickName, IsLiveSite));
                    }
                    else
                    {
                        ucMessageUserButtons.RelatedUserId = 0;
                        lblFrom.Text = HTMLHelper.HTMLEncode(Message.MessageSenderNickName);
                    }
                    string body = Message.MessageBody;
                    // Resolve macros
                    DiscussionMacroHelper dmh = new DiscussionMacroHelper();
                    body = dmh.ResolveMacros(body);

                    lblSubject.Text = HTMLHelper.HTMLEncodeLineBreaks(Message.MessageSubject);
                    if (IsLiveSite)
                    {
                        lblDate.Text = CMSContext.ConvertDateTime(Message.MessageSent, this).ToString();
                    }
                    else
                    {
                        lblDate.Text = TimeZoneHelper.GetCurrentTimeZoneDateTimeString(Message.MessageSent, currentUserInfo, CMSContext.CurrentSite, out usedTimeZone);
                    }
                    lblBody.Text = body;
                }
            }
            else
            {
                ShowError(GetString("Messaging.MessageDoesntExist"));
            }
        }
    }