示例#1
0
        /// <summary>
        /// The init quoted reply.
        /// </summary>
        /// <param name="currentRow">
        /// The current row.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="messageFlags">
        /// The message flags.
        /// </param>
        private void InitQuotedReply(DataRow currentRow, string message, MessageFlags messageFlags)
        {
            if (this.PageContext.BoardSettings.RemoveNestedQuotes)
            {
                message = YafFormatMessage.RemoveNestedQuotes(message);
            }

            // If the message being quoted in YafBBCode but the editor uses HTML, convert the message text to HTML
            if (messageFlags.IsBBCode && this._forumEditor.UsesHTML)
            {
                message = YafBBCode.ConvertBBCodeToHtmlForEdit(message);
            }

            // Ensure quoted replies have bad words removed from them
            message = this.Get <YafBadWordReplace>().Replace(message);

            // Quote the original message
            this._forumEditor.Text = "[quote={0};{1}]{2}[/quote]\n".FormatWith(this.PageContext.UserDisplayName.GetName(currentRow.Field <int>("UserID")), currentRow.Field <int>("MessageID"), message).TrimStart();
        }
示例#2
0
        /// <summary>
        /// Handles page load event.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // if user isn't authenticated, redirect him to login page
            if (User == null || YafContext.Current.IsGuest)
            {
                RedirectNoAccess();
            }

            // set attributes of editor
            this._editor.BaseDir    = YafForumInfo.ForumClientFileRoot + "editors";
            this._editor.StyleSheet = YafContext.Current.Theme.BuildThemePath("theme.css");

            // this needs to be done just once, not during postbacks
            if (!IsPostBack)
            {
                // create page links
                this.CreatePageLinks();

                // localize button labels
                this.FindUsers.Text = GetText("FINDUSERS");
                this.AllUsers.Text  = GetText("ALLUSERS");
                this.Clear.Text     = GetText("CLEAR");

                // only administrators can send messages to all users
                this.AllUsers.Visible = YafContext.Current.IsAdmin;

                if (this.Request.QueryString.GetFirstOrDefault("p").IsSet())
                {
                    // PM is a reply or quoted reply (isQuoting)
                    // to the given message id "p"
                    bool isQuoting = Request.QueryString.GetFirstOrDefault("q") == "1";

                    // get quoted message
                    DataRow row = DB.pmessage_list(Security.StringToLongOrRedirect(Request.QueryString.GetFirstOrDefault("p"))).GetFirstRow();

                    // there is such a message
                    if (row != null)
                    {
                        // get message sender/recipient
                        var toUserId   = (int)row["ToUserID"];
                        var fromUserId = (int)row["FromUserID"];

                        // verify access to this PM
                        if (toUserId != YafContext.Current.PageUserID && fromUserId != YafContext.Current.PageUserID)
                        {
                            YafBuildLink.AccessDenied();
                        }

                        // handle subject
                        var subject = (string)row["Subject"];
                        if (!subject.StartsWith("Re: "))
                        {
                            subject = string.Format("Re: {0}", subject);
                        }

                        this.PmSubjectTextBox.Text = subject;

                        string displayName = PageContext.UserDisplayName.GetName(fromUserId);

                        // set "To" user and disable changing...
                        this.To.Text           = displayName;
                        this.To.Enabled        = false;
                        this.FindUsers.Enabled = false;
                        this.AllUsers.Enabled  = false;

                        if (isQuoting)
                        {
                            // PM is a quoted reply
                            string body = row["Body"].ToString();

                            if (YafContext.Current.BoardSettings.RemoveNestedQuotes)
                            {
                                body = YafFormatMessage.RemoveNestedQuotes(body);
                            }

                            // Ensure quoted replies have bad words removed from them
                            body = this.Get <YafBadWordReplace>().Replace(body);

                            // Quote the original message
                            body = "[QUOTE={0}]{1}[/QUOTE]".FormatWith(displayName, body);

                            // we don't want any whitespaces at the beginning of message
                            this._editor.Text = body.TrimStart();
                        }
                    }
                }
                else if (this.Request.QueryString.GetFirstOrDefault("u").IsSet() && this.Request.QueryString.GetFirstOrDefault("r").IsSet())
                {
                    // We check here if the user have access to the option
                    if (PageContext.IsModerator || PageContext.IsForumModerator)
                    {
                        // PM is being sent to a predefined user
                        int toUser;
                        int reportMessage;

                        if (Int32.TryParse(this.Request.QueryString.GetFirstOrDefault("u"), out toUser) &&
                            Int32.TryParse(this.Request.QueryString.GetFirstOrDefault("r"), out reportMessage))
                        {
                            // get quoted message
                            DataRow messagesRow =
                                DB.message_listreporters(
                                    Security.StringToLongOrRedirect(this.Request.QueryString.GetFirstOrDefault("r")).ToType <int>(),
                                    Security.StringToLongOrRedirect(this.Request.QueryString.GetFirstOrDefault("u")).ToType <int>()).GetFirstRow();

                            // there is such a message
                            // message info should be always returned as 1 row
                            if (messagesRow != null)
                            {
                                // handle subject
                                this.PmSubjectTextBox.Text = this.GetText("REPORTED_SUBJECT");

                                string displayName = PageContext.UserDisplayName.GetName(messagesRow.Field <int>("UserID"));

                                // set "To" user and disable changing...
                                this.To.Text           = displayName;
                                this.To.Enabled        = false;
                                this.FindUsers.Enabled = false;
                                this.AllUsers.Enabled  = false;

                                // Parse content with delimiter '|'
                                string[] quoteList = messagesRow.Field <string>("ReportText").Split('|');

                                // Quoted replies should have bad words in them
                                // Reply to report PM is always a quoted reply
                                // Quote the original message in a cycle
                                for (int i = 0; i < quoteList.Length; i++)
                                {
                                    // Add quote codes
                                    quoteList[i] = "[QUOTE={0}]{1}[/QUOTE]".FormatWith(displayName, quoteList[i]);

                                    // Replace DateTime delimiter '??' by ': '
                                    // we don't want any whitespaces at the beginning of message
                                    this._editor.Text = quoteList[i].Replace("??", ": ") + this._editor.Text.TrimStart();
                                }
                            }
                        }
                    }
                }
                else if (this.Request.QueryString.GetFirstOrDefault("u").IsSet())
                {
                    // PM is being send as a reply to a reported post

                    // find user
                    int toUserId;

                    if (Int32.TryParse(Request.QueryString.GetFirstOrDefault("u"), out toUserId))
                    {
                        DataRow currentRow = DB.user_list(YafContext.Current.PageBoardID, toUserId, true).GetFirstRow();

                        if (currentRow != null)
                        {
                            this.To.Text    = PageContext.UserDisplayName.GetName(currentRow.Field <int>("UserID"));
                            this.To.Enabled = false;

                            // Simon: Disable for admins
                            DisablePMs = RoleMembershipHelper.IsUserInRole(this.To.Text, "Administrators");

                            // hide find user/all users buttons
                            this.FindUsers.Enabled = false;
                            this.AllUsers.Enabled  = false;
                        }
                    }
                }
                else
                {
                    // Blank PM

                    // multi-receiver info is relevant only when sending blank PM
                    if (YafContext.Current.BoardSettings.PrivateMessageMaxRecipients > 1)
                    {
                        // format localized string
                        this.MultiReceiverInfo.Text = "<br />{0}<br />{1}".FormatWith(YafContext.Current.Localization.GetText("MAX_RECIPIENT_INFO").FormatWith(YafContext.Current.BoardSettings.PrivateMessageMaxRecipients), YafContext.Current.Localization.GetText("MULTI_RECEIVER_INFO"));

                        // display info
                        this.MultiReceiverInfo.Visible = true;
                    }
                }
            }
        }