/// <summary>
        /// Translate the Win32 Error code into the eqivalant error message string.
        /// </summary>
        /// <param name="hResult">Last error code to translate. If undefined, use current last error code.</param>
        /// <returns>Error message string. If unable to translate, returns "Unknown error [errorcode]"</returns>
        public static string GetLastErrorMessage(int hResult = -1)
        {
            string sMsg = string.Empty;
            IntPtr pMsg = IntPtr.Zero;

            if (hResult == -1)
            {
                hResult = Marshal.GetLastWin32Error();
            }

            FormatMsg flags = FormatMsg.AllocateBuffer | FormatMsg.IgnoreInserts | FormatMsg.FromSystem;

            try
            {
                int dwBufferLength = FormatMessage(flags, IntPtr.Zero, hResult, 0, out pMsg, 0, IntPtr.Zero);
                if (dwBufferLength != 0)
                {
                    sMsg = Marshal.PtrToStringUni(pMsg).TrimEnd('\r', '\n');
                }
            }
            catch { }
            finally
            {
                if (pMsg != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pMsg);
                }
            }
            return(sMsg.Length == 0 ? "Unknown error " + hResult.ToString() : sMsg);
        }
示例#2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            sig.BaseDir = Data.ForumRoot + "editors";

            if (!User.IsAuthenticated)
            {
                if (User.CanLogin)
                {
                    Forum.Redirect(Pages.login, "ReturnUrl={0}", Utils.GetSafeRawUrl());
                }
                else
                {
                    Forum.Redirect(Pages.forum);
                }
            }

            if (!IsPostBack)
            {
                string msg    = DB.user_getsignature(PageUserID);
                bool   isHtml = msg.IndexOf('<') >= 0;
                if (isHtml)
                {
                    msg = FormatMsg.HtmlToForumCode(msg);
                }
                sig.Text = msg;

                PageLinks.AddLink(BoardSettings.Name, Forum.GetLink(Pages.forum));
                PageLinks.AddLink(PageUserName, Forum.GetLink(Pages.cp_profile));
                PageLinks.AddLink(GetText("TITLE"), Utils.GetSafeRawUrl());

                save.Text   = GetText("Save");
                cancel.Text = GetText("Cancel");
            }
        }
        protected string GetPrintBody(object o)
        {
            DataRowView row = ( DataRowView )o;

            string message = row ["Message"].ToString();

            message = FormatMsg.FormatMessage(message, new MessageFlags(Convert.ToInt32(row ["Flags"])));

            return(message);
        }
示例#4
0
        protected string FormatMessage(DataRowView row)
        {
            string msg = row["Message"].ToString();

            if (msg.IndexOf('<') >= 0)
            {
                return(msg);
            }

            return(FormatMsg.ForumCodeToHtml(this, row["Message"].ToString()));
        }
示例#5
0
        protected string GetPrintBody(object o)
        {
            DataRowView row    = (DataRowView)o;
            string      msg    = row["Message"].ToString();
            bool        isHtml = msg.IndexOf('<') >= 0;

            if (!isHtml)
            {
                msg = FormatMsg.ForumCodeToHtml(this, msg);
            }
            return(msg);
        }
示例#6
0
        protected string GetThreadedRow(object o)
        {
            DataRowView row = ( DataRowView )o;

            if (!IsThreaded || CurrentMessage == ( int )row ["MessageID"])
            {
                return("");
            }

            System.Text.StringBuilder html = new System.Text.StringBuilder(1000);

            // Threaded
            string brief = row ["Message"].ToString();

            RegexOptions options = RegexOptions.IgnoreCase /*| RegexOptions.Singleline | RegexOptions.Multiline*/;

            options |= RegexOptions.Singleline;
            while (Regex.IsMatch(brief, @"\[quote=(.*?)\](.*)\[/quote\]", options))
            {
                brief = Regex.Replace(brief, @"\[quote=(.*?)\](.*)\[/quote\]", "", options);
            }
            while (Regex.IsMatch(brief, @"\[quote\](.*)\[/quote\]", options))
            {
                brief = Regex.Replace(brief, @"\[quote\](.*)\[/quote\]", "", options);
            }

            while (Regex.IsMatch(brief, @"<.*?>", options))
            {
                brief = Regex.Replace(brief, @"<.*?>", "", options);
            }
            while (Regex.IsMatch(brief, @"\[.*?\]", options))
            {
                brief = Regex.Replace(brief, @"\[.*?\]", "", options);
            }

            brief = General.BadWordReplace(brief);

            if (brief.Length > 42)
            {
                brief = brief.Substring(0, 40) + "...";
            }
            brief = FormatMsg.AddSmiles(brief);

            html.AppendFormat("<tr class='post'><td colspan='3' nowrap>");
            html.AppendFormat(GetIndentImage(row ["Indent"]));
            html.AppendFormat("\n<a href='{0}'>{2} ({1}", YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.posts, "m={0}#{0}", row ["MessageID"]), row ["UserName"], brief);
            html.AppendFormat(" - {0})</a>", YafDateTime.FormatDateTimeShort(row ["Posted"]));
            html.AppendFormat("</td></tr>");

            return(html.ToString());
        }
示例#7
0
        protected string FormatBody(object o)
        {
            DataRowView row  = (DataRowView)o;
            string      html = FormatMsg.FormatMessage(this, row["Message"].ToString(), new MessageFlags(Convert.ToInt32(row["Flags"])));

            string sig = row["user_signature"].ToString();

            if (sig != string.Empty)
            {
                sig   = FormatMsg.FormatMessage(this, sig, new MessageFlags());
                html += "<br/><hr noshade/>" + sig;
            }

            return(html);
        }
示例#8
0
        private void save_Click(object sender, EventArgs e)
        {
            string body = sig.Text;

            body = FormatMsg.RepairHtml(this, body, false);

            if (sig.Text.Length > 0)
            {
                DB.user_savesignature(PageUserID, body);
            }
            else
            {
                DB.user_savesignature(PageUserID, DBNull.Value);
            }
            Forum.Redirect(Pages.cp_profile);
        }
示例#9
0
        protected string FormatBody(object o)
        {
            DataRowView row  = (DataRowView)o;
            string      html = FormatMsg.FormatMessage(this, row["Message"].ToString(), new MessageFlags(Convert.ToInt32(row["Flags"])));

            if (row["user_Signature"].ToString().Length > 0)
            {
                string sig = row["user_signature"].ToString();

                // don't allow any HTML on signatures
                MessageFlags tFlags = new MessageFlags();
                tFlags.IsHTML = false;

                sig   = FormatMsg.FormatMessage(this, sig, tFlags);
                html += "<br/><hr noshade/>" + sig;
            }

            return(html);
        }
示例#10
0
        private void InitQuotedReply(DataRow currentRow, string message, MessageFlags messageFlags)
        {
            if (PageContext.BoardSettings.RemoveNestedQuotes)
            {
                message = FormatMsg.RemoveNestedQuotes(message);
            }

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

            // Ensure quoted replies have bad words removed from them
            message = General.BadWordReplace(message);

            // Quote the original message
            _forumEditor.Text = String.Format("[quote={0}]{1}[/quote]\n", currentRow["username"], message).TrimStart();
        }
示例#11
0
        private void Preview_Click(object sender, System.EventArgs e)
        {
            PreviewRow.Visible = true;

            MessageFlags tFlags = new MessageFlags();

            tFlags.IsHTML   = Message.UsesHTML;
            tFlags.IsBBCode = Message.UsesBBCode;

            string body = FormatMsg.FormatMessage(this, Message.Text, tFlags);

            using (DataTable dt = DB.user_list(PageBoardID, PageUserID, true))
            {
                if (!dt.Rows[0].IsNull("user_Signature"))
                {
                    body += "<br/><hr noshade/>" + FormatMsg.FormatMessage(this, dt.Rows[0]["user_Signature"].ToString(), new MessageFlags());
                }
            }

            PreviewCell.InnerHtml = body;
        }
示例#12
0
        protected string FormatBody(object o)
        {
            DataRowView row = (DataRowView)o;

            return(FormatMsg.FormatMessage(this, row["Body"].ToString(), Convert.ToInt32(row["Flags"])));
        }
示例#13
0
        private void Page_Load(object sender, EventArgs e)
        {
            Editor.BaseDir = Data.ForumRoot + "editors";

            if (!User.IsAuthenticated)
            {
                if (User.CanLogin)
                {
                    Forum.Redirect(Pages.login, "ReturnUrl={0}", Utils.GetSafeRawUrl());
                }
                else
                {
                    Forum.Redirect(Pages.forum);
                }
            }

            if (!IsPostBack)
            {
                BindData();
                PageLinks.AddLink(BoardSettings.Name, Forum.GetLink(Pages.forum));
                Save.Text      = GetText("Save");
                Cancel.Text    = GetText("Cancel");
                FindUsers.Text = GetText("FINDUSERS");
                AllUsers.Text  = GetText("ALLUSERS");

                if (IsAdmin)
                {
                    AllUsers.Visible = true;
                }
                else
                {
                    AllUsers.Visible = false;
                }

                int ToUserID = 0;

                if (Request.QueryString["p"] != null)
                {
                    using (DataTable dt = DB.userpmessage_list(Request.QueryString["p"]))
                    {
                        DataRow row = dt.Rows[0];
                        Subject.Text = (string)row["Subject"];

                        if (Subject.Text.Length < 4 || Subject.Text.Substring(0, 4) != "Re: ")
                        {
                            Subject.Text = "Re: " + Subject.Text;
                        }

                        ToUserID = (int)row["FromUserID"];

                        string body   = row["Body"].ToString();
                        bool   isHtml = body.IndexOf('<') >= 0;

                        if (BoardSettings.RemoveNestedQuotes)
                        {
                            RegexOptions m_options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline;
                            Regex        quote     = new Regex(@"\[quote(\=.*)?\](.*?)\[/quote\]", m_options);
                            // remove quotes from old messages
                            body = quote.Replace(body, "");
                        }

                        if (isHtml)
                        {
                            body = FormatMsg.HtmlToForumCode(body);
                        }
                        body = String.Format("[QUOTE={0}]{1}[/QUOTE]", row["FromUser"], body);

                        Editor.Text = body;
                    }
                }
                if (Request.QueryString["u"] != null)
                {
                    ToUserID = int.Parse(Request.QueryString["u"].ToString());
                }

                if (ToUserID != 0)
                {
                    using (DataTable dt = DB.user_list(PageBoardID, ToUserID, true))
                    {
                        To.Text    = (string)dt.Rows[0]["user_nick"];
                        To.Enabled = false;
                    }
                }
            }
        }
 private static extern int FormatMessage(FormatMsg dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId, out IntPtr pMsg, int nSize, IntPtr Arguments);
示例#15
0
        protected string FormatUserBox()
        {
            System.Data.DataRowView row = DataRow;
            string html = "";

            // Avatar
            if (ForumPage.BoardSettings.AvatarUpload && row["HasAvatarImage"] != null && long.Parse(row["HasAvatarImage"].ToString()) > 0)
            {
                html += String.Format("<img src='{1}image.aspx?u={0}'><br clear=\"all\"/>", row["UserID"], Data.ForumRoot);
            }
            else if (row["user_avatar"].ToString().Length > 0)
            {
                string s = row["user_avatar"].ToString();
                if (s == null || s == string.Empty)
                {
                    s = User.DefaultAvatar;
                }
                html += String.Format("<img src='{0}' width='50px' height='50px'><br clear=\"all\"/>",
                                      s
                                      );
            }

            // Rank Image
            if (row["RankImage"].ToString().Length > 0)
            {
                html += String.Format("<img align=left src=\"{0}images/ranks/{1}\"/><br clear=\"all\"/>", Data.ForumRoot, row["RankImage"]);
            }

            // Rank
            html += String.Format("{0}: {1}<br clear=\"all\"/>", ForumPage.GetText("rank"), row["RankName"]);

            // Groups
            if (ForumPage.BoardSettings.ShowGroups)
            {
                using (DataTable dt = DB.usergroup_list(row["UserID"]))
                {
                    html += String.Format("{0}: ", ForumPage.GetText("groups"));
                    bool bFirst = true;
                    foreach (DataRow grp in dt.Rows)
                    {
                        if (bFirst)
                        {
                            html  += grp["Name"].ToString();
                            bFirst = false;
                        }
                        else
                        {
                            html += String.Format(", {0}", grp["Name"]);
                        }
                    }
                    html += "<br/>";
                }
            }

            // Extra row
            html += "<br/>";

            // Joined
            html += String.Format("{0}: {1}<br/>", ForumPage.GetText("joined"), ForumPage.FormatDateShort((DateTime)row["user_registDate"]));

            // Posts
            html += String.Format("{0}: {1:N0}<br/>", ForumPage.GetText("posts"), row["Posts"]);

            // Location
            if (row["Location"].ToString().Length > 0)
            {
                html += String.Format("{0}: {1}<br/>", ForumPage.GetText("location"), FormatMsg.RepairHtml(ForumPage, row["Location"].ToString(), false));
            }

            return(html);
        }
示例#16
0
        protected string FormatBody()
        {
            DataRowView row = DataRow;

            string html2 = FormatMsg.FormatMessage(ForumPage, row["Message"].ToString(), new MessageFlags(Convert.ToInt32(row["Flags"])));

            // define valid image extensions
            string[] aImageExtensions = { "jpg", "gif", "png" };

            if (long.Parse(row["HasAttachments"].ToString()) > 0)
            {
                string stats       = ForumPage.GetText("ATTACHMENTINFO");
                string strFileIcon = ForumPage.GetThemeContents("ICONS", "ATTACHED_FILE");

                html2 += "<p>";

                using (DataTable dt = DB.attachment_list(row["MessageID"], null, null))
                {
                    // show file then image attachments...
                    int tmpDisplaySort = 0;

                    while (tmpDisplaySort <= 1)
                    {
                        bool bFirstItem = true;

                        foreach (DataRow dr in dt.Rows)
                        {
                            string strFilename = Convert.ToString(dr["FileName"]).ToLower();
                            bool   bShowImage  = false;

                            // verify it's not too large to display (might want to make this a board setting)
                            if (Convert.ToInt32(dr["Bytes"]) <= 262144)
                            {
                                // is it an image file?
                                for (int i = 0; i < aImageExtensions.Length; i++)
                                {
                                    if (strFilename.EndsWith(aImageExtensions[i]))
                                    {
                                        bShowImage = true;
                                        break;
                                    }
                                }
                            }

                            if (bShowImage && tmpDisplaySort == 1)
                            {
                                if (bFirstItem)
                                {
                                    html2     += "<i class=\"smallfont\">";
                                    html2     += String.Format(ForumPage.GetText("IMAGE_ATTACHMENT_TEXT"), Convert.ToString(row["UserName"]));
                                    html2     += "</i><br/>";
                                    bFirstItem = false;
                                }
                                html2 += String.Format("<img src=\"{0}image.aspx?a={1}\" alt=\"{2}\"><br/>", Data.ForumRoot, dr["AttachmentID"], Server.HtmlEncode(Convert.ToString(dr["FileName"])));
                            }
                            else if (!bShowImage && tmpDisplaySort == 0)
                            {
                                if (bFirstItem)
                                {
                                    html2     += String.Format("<b class=\"smallfont\">{0}</b><br/>", ForumPage.GetText("ATTACHMENTS"));
                                    bFirstItem = false;
                                }
                                // regular file attachment
                                int kb = (1023 + (int)dr["Bytes"]) / 1024;
                                html2 += String.Format("<img border='0' src='{0}'> <b><a href=\"{1}image.aspx?a={2}\">{3}</a></b> <span class='smallfont'>{4}</span><br/>", strFileIcon, Data.ForumRoot, dr["AttachmentID"], dr["FileName"], String.Format(stats, kb, dr["Downloads"]));
                            }
                        }
                        // now show images
                        tmpDisplaySort++;
                        html2 += "<br/>";
                    }
                }
            }

            if (row["Signature"] != DBNull.Value && row["Signature"].ToString().ToLower() != "<p>&nbsp;</p>" && ForumPage.BoardSettings.AllowSignatures)
            {
                // don't allow any HTML on signatures
                MessageFlags tFlags = new MessageFlags();
                tFlags.IsHTML = false;

                html2 += "<br/><hr noshade/>" + FormatMsg.FormatMessage(ForumPage, row["Signature"].ToString(), tFlags);
            }

            return(html2);
        }
示例#17
0
        private void DisplayPost_PreRender(object sender, EventArgs e)
        {
            Attach.Visible = !PostDeleted && CanAttach && !IsLocked;

            Attach.NavigateUrl   = YafBuildLink.GetLinkNotEscaped(ForumPages.attachments, "m={0}", MessageId);
            Edit.Visible         = !PostDeleted && CanEditPost && !IsLocked;
            Edit.NavigateUrl     = YafBuildLink.GetLinkNotEscaped(ForumPages.postmessage, "m={0}", MessageId);
            MovePost.Visible     = PageContext.ForumModeratorAccess && !IsLocked;
            MovePost.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.movemessage, "m={0}", MessageId);
            Delete.Visible       = !PostDeleted && CanDeletePost && !IsLocked;
            Delete.NavigateUrl   = YafBuildLink.GetLinkNotEscaped(ForumPages.deletemessage, "m={0}&action=delete", MessageId);
            UnDelete.Visible     = CanUnDeletePost && !IsLocked;
            UnDelete.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.deletemessage, "m={0}&action=undelete", MessageId);
            Quote.Visible        = !PostDeleted && CanReply && !IsLocked;
            Quote.NavigateUrl    = YafBuildLink.GetLinkNotEscaped(YAF.Classes.Utils.ForumPages.postmessage, "t={0}&f={1}&q={2}", PageContext.PageTopicID, PageContext.PageForumID, MessageId);

            // report posts
            ReportButton.Visible = PageContext.BoardSettings.AllowReportAbuse && !IsGuest;    // Mek Addition 08/18/2007
            ReportButton.Text    = PageContext.Localization.GetText("REPORTPOST");            // Mek Addition 08/18/2007
            ReportButton.Attributes.Add("onclick", String.Format("return confirm('{0}');", PageContext.Localization.GetText("CONFIRM_REPORTPOST")));

            // report spam
            ReportSpamButton.Visible = PageContext.BoardSettings.AllowReportSpam && !IsGuest;     // Mek Addition 08/18/2007
            ReportSpamButton.Text    = PageContext.Localization.GetText("REPORTSPAM");            // Mek Addition 08/18/2007
            ReportSpamButton.Attributes.Add("onclick", String.Format("return confirm('{0}');", PageContext.Localization.GetText("CONFIRM_REPORTSPAM")));

            // private messages
            Pm.Visible     = !IsGuest && !PostDeleted && PageContext.User != null && PageContext.BoardSettings.AllowPrivateMessages && !IsSponserMessage;
            Pm.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.pmessage, "u={0}", UserId);

            // emailing
            Email.Visible     = !IsGuest && !PostDeleted && PageContext.User != null && PageContext.BoardSettings.AllowEmailSending && !IsSponserMessage;
            Email.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_email, "u={0}", UserId);

            // home page
            Home.Visible = !PostDeleted && !String.IsNullOrEmpty(UserProfile.Homepage);
            SetupThemeButtonWithLink(Home, UserProfile.Homepage);

            // blog page
            Blog.Visible = !PostDeleted && !String.IsNullOrEmpty(UserProfile.Blog);
            SetupThemeButtonWithLink(Blog, UserProfile.Blog);

            // MSN
            Msn.Visible     = !PostDeleted && PageContext.User != null && !String.IsNullOrEmpty(UserProfile.MSN);
            Msn.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_email, "u={0}", UserId);

            // Yahoo IM
            Yim.Visible     = !PostDeleted && PageContext.User != null && !String.IsNullOrEmpty(UserProfile.YIM);
            Yim.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_yim, "u={0}", UserId);

            // AOL IM
            Aim.Visible     = !PostDeleted && PageContext.User != null && !String.IsNullOrEmpty(UserProfile.AIM);
            Aim.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_aim, "u={0}", UserId);

            // ICQ
            Icq.Visible     = !PostDeleted && PageContext.User != null && !String.IsNullOrEmpty(UserProfile.ICQ);
            Icq.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_icq, "u={0}", UserId);

            // Skype
            Skype.Visible     = !PostDeleted && PageContext.User != null && !String.IsNullOrEmpty(UserProfile.Skype);
            Skype.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.im_skype, "u={0}", UserId);

            if (!PostDeleted)
            {
                AdminInformation.InnerHtml = @"<span class=""smallfont"">";
                if (Convert.ToDateTime(DataRow ["Edited"]) > Convert.ToDateTime(DataRow ["Posted"]).AddSeconds(PageContext.BoardSettings.EditTimeOut))
                {
                    // message has been edited
                    // show, why the post was edited or deleted?
                    string whoChanged = (Convert.ToBoolean(DataRow["IsModeratorChanged"])) ? PageContext.Localization.GetText("EDITED_BY_MOD") : PageContext.Localization.GetText("EDITED_BY_USER");
                    AdminInformation.InnerHtml += String.Format(@"| <span class=""editedinfo"">{0} {1}:</span> {2}", PageContext.Localization.GetText("EDITED"), whoChanged, YafDateTime.FormatDateTimeShort(Convert.ToDateTime(DataRow["Edited"])));
                    if (Server.HtmlDecode(Convert.ToString(DataRow ["EditReason"])) != "")
                    {
                        // reason was specified
                        AdminInformation.InnerHtml += String.Format(" |<b> {0}:</b> {1}", PageContext.Localization.GetText("EDIT_REASON"), FormatMsg.RepairHtml((string)DataRow["EditReason"], true));
                    }
                    else
                    {
                        //reason was not specified
                        AdminInformation.InnerHtml += String.Format(" |<b> {0}:</b> {1}", PageContext.Localization.GetText("EDIT_REASON"), PageContext.Localization.GetText("EDIT_REASON_NA"));
                    }
                }
            }
            else
            {
                AdminInformation.InnerHtml = @"<span class=""smallfont"">";
                if (Server.HtmlDecode(Convert.ToString(DataRow ["DeleteReason"])) != String.Empty)
                {
                    // reason was specified
                    AdminInformation.InnerHtml += String.Format(" |<b> {0}:</b> {1}", PageContext.Localization.GetText("EDIT_REASON"), FormatMsg.RepairHtml((string)DataRow["DeleteReason"], true));
                }
                else
                {
                    //reason was not specified
                    AdminInformation.InnerHtml += String.Format(" |<b> {0}:</b> {1}", PageContext.Localization.GetText("EDIT_REASON"), PageContext.Localization.GetText("EDIT_REASON_NA"));
                }
            }

            // display admin only info
            if (PageContext.IsAdmin)
            {
                AdminInformation.InnerHtml += String.Format(" |<b> {0}:</b> {1}", PageContext.Localization.GetText("IP"), DataRow["IP"].ToString());
            }
            AdminInformation.InnerHtml += "</span>";
        }
示例#18
0
        /// <summary>
        /// Handles page load event.
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            // if user isn't authenticated, redirect him to login page
            if (User == null || PageContext.IsGuest)
            {
                YafBuildLink.Redirect(ForumPages.login, "ReturnUrl={0}", General.GetSafeRawUrl());
            }

            // set attributes of editor
            _editor.BaseDir    = YafForumInfo.ForumRoot + "editors";
            _editor.StyleSheet = YafBuildLink.ThemeFile("theme.css");

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

                // localize button labels
                Save.Text      = GetText("SAVE");
                Preview.Text   = GetText("PREVIEW");
                Cancel.Text    = GetText("CANCEL");
                FindUsers.Text = GetText("FINDUSERS");
                AllUsers.Text  = GetText("ALLUSERS");
                Clear.Text     = GetText("CLEAR");

                // only administrators can send messages to all users
                AllUsers.Visible = PageContext.IsAdmin;

                if (!String.IsNullOrEmpty(Request.QueryString ["p"]))
                {
                    // PM is a reply or quoted reply (isQuoting)
                    // to the given message id "p"
                    bool isQuoting = Request.QueryString ["q"] == "1";

                    // get quoted message
                    DataTable dt = DB.pmessage_list(Security.StringToLongOrRedirect(Request.QueryString ["p"]));

                    // there is such a message
                    if (dt.Rows.Count > 0)
                    {
                        // message info is in first row
                        DataRow row = dt.Rows [0];
                        // get message sender/recipient
                        int toUserId   = ( int )row ["ToUserID"];
                        int fromUserId = ( int )row ["FromUserID"];

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

                        // handle subject
                        string subject = ( string )row ["Subject"];
                        if (!subject.StartsWith("Re: "))
                        {
                            subject = "Re: " + subject;
                        }
                        Subject.Text = subject;

                        // set "To" user and disable changing...
                        To.Text           = row ["FromUser"].ToString();
                        To.Enabled        = false;
                        FindUsers.Enabled = false;
                        AllUsers.Enabled  = false;

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

                            if (PageContext.BoardSettings.RemoveNestedQuotes)
                            {
                                body = FormatMsg.RemoveNestedQuotes(body);
                            }

                            // Ensure quoted replies have bad words removed from them
                            body = General.BadWordReplace(body);

                            // Quote the original message
                            body = String.Format("[QUOTE={0}]{1}[/QUOTE]", row ["FromUser"], body);

                            // we don't want any whitespaces at the beginning of message
                            _editor.Text = body.TrimStart();
                        }
                    }
                }
                else if (!String.IsNullOrEmpty(Request.QueryString ["u"]))
                {
                    // PM is being sent to a predefined user
                    int toUserId;

                    if (Int32.TryParse(Request.QueryString ["u"], out toUserId))
                    {
                        // get user's name
                        using (DataTable dt = DB.user_list(PageContext.PageBoardID, toUserId, true))
                        {
                            To.Text    = dt.Rows [0] ["Name"] as string;
                            To.Enabled = false;
                            // hide find user/all users buttons
                            FindUsers.Enabled = false;
                            AllUsers.Enabled  = false;
                        }
                    }
                }
                else
                {
                    // Blank PM

                    // multi-receiver info is relevant only when sending blank PM
                    if (PageContext.BoardSettings.PrivateMessageMaxRecipients > 1)
                    {
                        // format localized string
                        MultiReceiverInfo.Text = String.Format(
                            "<br />{0}<br />{1}",
                            String.Format(
                                PageContext.Localization.GetText("MAX_RECIPIENT_INFO"),
                                PageContext.BoardSettings.PrivateMessageMaxRecipients
                                ),
                            PageContext.Localization.GetText("MULTI_RECEIVER_INFO")
                            );
                        // display info
                        MultiReceiverInfo.Visible = true;
                    }
                }
            }
        }
示例#19
0
        protected string FormatBody(object o)
        {
            DataRowView row = (DataRowView)o;

            return(FormatMsg.ForumCodeToHtml(this, (string)row["Body"]));
        }
示例#20
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            DataRow msg = null;

            if (Request.QueryString["q"] != null)
            {
                using (DataTable dt = DB.message_list(Request.QueryString["q"]))
                    msg = dt.Rows[0];
            }
            else if (Request.QueryString["m"] != null)
            {
                using (DataTable dt = DB.message_list(Request.QueryString["m"]))
                    msg = dt.Rows[0];

                if (!ForumModeratorAccess && PageUserID != (int)msg["UserID"])
                {
                    Data.AccessDenied();
                }
            }

            if (PageForumID == 0)
            {
                Data.AccessDenied();
            }
            if (Request["t"] == null && !ForumPostAccess)
            {
                Data.AccessDenied();
            }
            if (Request["t"] != null && !ForumReplyAccess)
            {
                Data.AccessDenied();
            }

            //Message.EnableRTE = BoardSettings.AllowRichEdit;
            Message.BaseDir = Data.ForumRoot + "editors";

            Title.Text = GetText("NEWTOPIC");

            if (!IsPostBack)
            {
                Priority.Items.Add(new ListItem(GetText("normal"), "0"));
                Priority.Items.Add(new ListItem(GetText("sticky"), "1"));
                Priority.Items.Add(new ListItem(GetText("announcement"), "2"));
                Priority.SelectedIndex = 0;

                Preview.Text    = GetText("preview");
                PostReply.Text  = GetText("Save");
                Cancel.Text     = GetText("Cancel");
                CreatePoll.Text = GetText("createpoll");

                PriorityRow.Visible   = ForumPriorityAccess;
                CreatePollRow.Visible = Request.QueryString["t"] == null && ForumPollAccess;

                PageLinks.AddLink(BoardSettings.Name, Forum.GetLink(Pages.forum));
                PageLinks.AddLink(PageCategoryName, Forum.GetLink(Pages.forum, "c={0}", PageCategoryID));
                PageLinks.AddForumLinks(PageForumID);

                if (Request.QueryString["t"] != null)
                {
                    // new post...
                    DataRow topic = DB.topic_info(Request.QueryString["t"]);
                    if (((int)topic["Flags"] & (int)TopicFlags.Locked) == (int)TopicFlags.Locked)
                    {
                        Response.Redirect(Request.UrlReferrer.ToString());
                    }
                    SubjectRow.Visible = false;
                    Title.Text         = GetText("reply");

                    if (Config.IsDotNetNuke || Config.IsRainbow)
                    {
                        // can't use the last post iframe
                        LastPosts.Visible    = true;
                        LastPosts.DataSource = DB.post_list_reverse10(Request.QueryString["t"]);
                        LastPosts.DataBind();
                    }
                    else
                    {
                        LastPostsIFrame.Visible = true;
                        LastPostsIFrame.Attributes.Add("src", "framehelper.aspx?g=lastposts&t=" + Request.QueryString["t"]);
                    }
                }

                if (Request.QueryString["q"] != null)
                {
                    // reply to post...
                    bool isHtml = msg["Message"].ToString().IndexOf('<') >= 0;

                    string tmpMessage = msg["Message"].ToString();

                    if (BoardSettings.RemoveNestedQuotes)
                    {
                        RegexOptions m_options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline;
                        Regex        quote     = new Regex(@"\[quote(\=.*)?\](.*?)\[/quote\]", m_options);
                        // remove quotes from old messages
                        tmpMessage = quote.Replace(tmpMessage, "");
                    }

                    if (isHtml)
                    {
                        Message.Text = String.Format("[quote={0}]{1}[/quote]", msg["username"], FormatMsg.HtmlToForumCode(tmpMessage));
                    }
                    else
                    {
                        Message.Text = String.Format("[quote={0}]{1}[/quote]", msg["username"], tmpMessage);
                    }
                }
                else if (Request.QueryString["m"] != null)
                {
                    // edit message...
                    string body   = msg["message"].ToString();
                    bool   isHtml = body.IndexOf('<') >= 0;
                    if (isHtml)
                    {
                        //throw new Exception("TODO: Convert this html message to forumcodes");
                        body = FormatMsg.HtmlToForumCode(body);
                    }
                    Message.Text = body;
                    Title.Text   = GetText("EDIT");

                    Subject.Text = Server.HtmlDecode(Convert.ToString(msg["Topic"]));

                    if ((Convert.ToInt32(msg["TopicOwnerID"]) == Convert.ToInt32(msg["UserID"])) || ForumModeratorAccess)
                    {
                        // allow editing of the topic subject
                        Subject.Enabled = true;
                    }
                    else
                    {
                        // disable the subject
                        Subject.Enabled = false;
                    }

                    CreatePollRow.Visible          = false;
                    Priority.SelectedItem.Selected = false;
                    Priority.Items.FindByValue(msg["Priority"].ToString()).Selected = true;
                }

                From.Text = PageUserName;
                if (User.IsAuthenticated)
                {
                    FromRow.Visible = false;
                }
            }
        }
 [DllImport("kernel32.dll", CharSet = CharSet.Auto)] private static extern int FormatMessage(FormatMsg dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId, out IntPtr pMsg, int nSize, IntPtr Arguments);
示例#22
0
        /// <summary>
        /// Formats the message and replaces Forum Code to HTML.
        /// </summary>
        /// <param name="o">The object DataRowView that is going to be converted.</param>
        /// <returns>Returns the convertted string.</returns>
        public string FormatMessage(object o)
        {
            DataRowView row = (DataRowView)o;

            return(FormatMsg.FormatMessage(this, row["Message"].ToString(), new MessageFlags(Convert.ToInt32(row["Flags"]))));
        }
示例#23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Put user code to initialize the page here
            RssFeed rf = new RssFeed();

            XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

            writer.Formatting = Formatting.Indented;
            rf.WriteRSSPrologue(writer);

            // Usage rf.AddRSSItem(writer, "Item Title", "http://test.com", "This is a test item");

            switch (Request.QueryString["pg"])
            {
            case "latestposts":
                if (!PageContext.ForumReadAccess)
                {
                    YafBuildLink.AccessDenied();
                }
                using (DataTable dt = DB.topic_latest(PageContext.PageBoardID, 7, PageContext.PageUserID))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        rf.AddRSSItem(writer,
                                      General.BadWordReplace(row["Subject"].ToString()),
                                      YafForumInfo.ServerURL +
                                      YafBuildLink.GetLinkNotEscaped(ForumPages.posts, "t={0}", Request.QueryString["t"]),
                                      General.BadWordReplace(row["Message"].ToString()),
                                      Convert.ToDateTime(row["Posted"]).ToString("r"));
                    }
                }
                break;

            case "latestannouncements":
                if (!PageContext.ForumReadAccess)
                {
                    YafBuildLink.AccessDenied();
                }
                using (DataTable dt = DB.topic_announcements(PageContext.PageBoardID, 7, PageContext.PageUserID))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        rf.AddRSSItem(writer,
                                      General.BadWordReplace(row["Subject"].ToString()),
                                      YafForumInfo.ServerURL +
                                      YafBuildLink.GetLinkNotEscaped(ForumPages.posts, "t={0}", Request.QueryString["t"]),
                                      General.BadWordReplace(row["Message"].ToString()),
                                      Convert.ToDateTime(row["Posted"]).ToString("r"));
                    }
                }
                break;

            case "posts":
                if (!PageContext.ForumReadAccess)
                {
                    YafBuildLink.AccessDenied();
                }

                if (Request.QueryString["t"] != null)
                {
                    using (
                        DataTable dt =
                            DB.post_list(PageContext.PageTopicID, 1, PageContext.BoardSettings.ShowDeletedMessages))
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            rf.AddRSSItem(writer,
                                          General.BadWordReplace(row["Subject"].ToString()),
                                          YafForumInfo.ServerURL +
                                          YafBuildLink.GetLinkNotEscaped(ForumPages.posts, "t={0}", Request.QueryString["t"]),
                                          FormatMsg.FormatMessage(row["Message"].ToString(), new MessageFlags(row["Flags"])),
                                          Convert.ToDateTime(row["Posted"]).ToString("r"));
                        }
                    }
                }

                break;

            case "forum":
                using (
                    DataTable dt = DB.forum_listread(PageContext.PageBoardID, PageContext.PageUserID, null, null))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        rf.AddRSSItem(writer,
                                      General.BadWordReplace(row["Forum"].ToString()),
                                      YafForumInfo.ServerURL + YafBuildLink.GetLinkNotEscaped(ForumPages.topics, "f={0}", row["ForumID"]),
                                      General.BadWordReplace(row["Description"].ToString()));
                    }
                }
                break;

            case "topics":
                if (!PageContext.ForumReadAccess)
                {
                    YafBuildLink.AccessDenied();
                }

                int forumId;
                if (Request.QueryString["f"] != null &&
                    int.TryParse(Request.QueryString["f"], out forumId))
                {
                    //vzrus changed to separate DLL specific code
                    using (DataTable dt = DB.rsstopic_list(forumId))
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            rf.AddRSSItem(writer,
                                          General.BadWordReplace(row["Topic"].ToString()),
                                          YafForumInfo.ServerURL + YafBuildLink.GetLinkNotEscaped(ForumPages.posts, "t={0}", row["TopicID"]),
                                          General.BadWordReplace(row["Topic"].ToString()),
                                          Convert.ToDateTime(row["Posted"]).ToString("r"));
                        }
                    }
                }

                break;

            case "active":
                using (
                    DataTable dt =
                        DB.topic_active(PageContext.PageBoardID, PageContext.PageUserID,
                                        DateTime.Now + TimeSpan.FromHours(-24), (PageContext.Settings.CategoryID == 0) ? null : (object)PageContext.Settings.CategoryID))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        rf.AddRSSItem(writer,
                                      General.BadWordReplace(row["Subject"].ToString()),
                                      YafForumInfo.ServerURL +
                                      YafBuildLink.GetLinkNotEscaped(ForumPages.posts, "t={0}", row["LinkTopicID"]),
                                      General.BadWordReplace(row["Subject"].ToString()));
                    }
                }
                break;

            default:
                break;
            }

            rf.WriteRSSClosing(writer);
            writer.Flush();

            writer.Close();

            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType     = "text/xml";
            Response.Cache.SetCacheability(HttpCacheability.Public);

            Response.End();
        }