Exemple #1
0
        protected void Submit_ContentCommentForm(object sender, EventArgs e)
        {
            bool bCaptcha = false;

            Captcha captcha = (Captcha)GetEntryFormControl("ContentCommentCaptcha");

            if (captcha != null)
            {
                bCaptcha = captcha.Validate();
            }
            else
            {
                bCaptcha = true;
            }

            if (bCaptcha)
            {
                HttpRequest request = HttpContext.Current.Request;

                bool bIgnorePublishState = SecurityData.AdvancedEditMode || SecurityData.IsAdmin || SecurityData.IsSiteEditor;

                SiteNav navData = navHelper.GetLatestVersion(SiteData.CurrentSiteID, !bIgnorePublishState, SiteData.CurrentScriptName);

                Label   lblContentCommentFormMsg = (Label)GetEntryFormControl("ContentCommentFormMsg");
                TextBox txtCommenterName         = (TextBox)GetEntryFormControl("CommenterName");
                TextBox txtCommenterEmail        = (TextBox)GetEntryFormControl("CommenterEmail");
                TextBox txtVisitorComments       = (TextBox)GetEntryFormControl("VisitorComments");
                TextBox txtCommenterURL          = (TextBox)GetEntryFormControl("CommenterURL");

                string sIP = request.ServerVariables["REMOTE_ADDR"].ToString();

                PostComment pc = new PostComment();
                pc.ContentCommentID = Guid.NewGuid();
                pc.Root_ContentID   = navData.Root_ContentID;
                pc.CreateDate       = SiteData.CurrentSite.Now;
                pc.IsApproved       = false;
                pc.IsSpam           = false;
                pc.CommenterIP      = sIP;

                if (txtCommenterName != null)
                {
                    pc.CommenterName = txtCommenterName.Text;
                }
                if (txtCommenterEmail != null)
                {
                    pc.CommenterEmail = txtCommenterEmail.Text;
                }
                if (txtVisitorComments != null)
                {
                    pc.PostCommentText = txtVisitorComments.Text;
                }
                if (txtCommenterURL != null)
                {
                    pc.CommenterURL = txtCommenterURL.Text;
                }

                if (SiteData.IsWebView && SecurityData.IsAuthenticated)
                {
                    if ((this.AutoApproveAdmin))
                    {
                        pc.IsApproved = SecurityData.IsAdmin;
                    }
                    if (!String.IsNullOrEmpty(this.AutoApproveGroupName))
                    {
                        pc.IsApproved = SecurityData.IsUserInRole(this.AutoApproveGroupName);
                    }
                }

                pc.Save();

                if (!String.IsNullOrEmpty(this.DirectEmail) || this.NotifyEditors || !String.IsNullOrEmpty(this.DirectEmailKeyName))
                {
                    List <string> emails = new List <string>();

                    if (!String.IsNullOrEmpty(this.DirectEmail))
                    {
                        emails.Add(this.DirectEmail);
                    }
                    if (!String.IsNullOrEmpty(this.DirectEmailKeyName))
                    {
                        emails.Add(ConfigurationManager.AppSettings[this.DirectEmailKeyName].ToString());
                    }
                    if (this.NotifyEditors)
                    {
                        ContentPage page = navData.GetContentPage();
                        emails.Add(page.CreateUser.EmailAddress);

                        if (page.EditUser.UserId != page.CreateUser.UserId)
                        {
                            emails.Add(page.EditUser.EmailAddress);
                        }
                        if (page.CreditUserId.HasValue)
                        {
                            emails.Add(page.CreditUser.EmailAddress);
                        }
                    }

                    string sEmail = String.Join(",", emails.ToArray());

                    string strHTTPHost = String.Empty;
                    try { strHTTPHost = request.ServerVariables["HTTP_HOST"] + String.Empty; } catch { strHTTPHost = String.Empty; }

                    string hostName = strHTTPHost.ToLowerInvariant();

                    string strHTTPProto = "http://";
                    try {
                        strHTTPProto = request.ServerVariables["SERVER_PORT_SECURE"] + String.Empty;
                        if (strHTTPProto == "1")
                        {
                            strHTTPProto = "https://";
                        }
                        else
                        {
                            strHTTPProto = "http://";
                        }
                    } catch { }

                    string mailSubject = String.Format("Comment Form From {0}", hostName);

                    strHTTPHost = String.Format("{0}{1}", strHTTPProto, strHTTPHost).ToLowerInvariant();

                    string sBody = "Name:   " + pc.CommenterName
                                   + "\r\nEmail:   " + pc.CommenterEmail
                                   + "\r\nURL:   " + pc.CommenterURL
                                   + "\r\n-----------------\r\nComment:\r\n" + HttpUtility.HtmlEncode(pc.PostCommentText)
                                   + "\r\n=================\r\n\r\nIP:   " + pc.CommenterIP
                                   //+ "\r\nSite Page:   " + request.ServerVariables["script_name"].ToString()
                                   + "\r\nSite URL:   " + String.Format("{0}{1}", strHTTPHost, request.ServerVariables["script_name"])
                                   + "\r\nSite Time:   " + SiteData.CurrentSite.Now.ToString()
                                   + "\r\nUTC Time:   " + DateTime.UtcNow.ToString();

                    EmailHelper.SendMail(null, sEmail, mailSubject, sBody, false);
                }

                //if (lbl != null && txt1 != null && txt2 != null) {
                //    lbl.Text = "Clicked the button: " + txt1.Text + " - " + txt2.Text;
                //}

                phEntry.Visible  = false;
                phThanks.Visible = true;
            }
        }