protected string Edit() { string res = ""; anm_Utility ut = new anm_Utility(); if (Request.IsAuthenticated) { MembershipUser user = Membership.GetUser(); string role = ut.GetRole(user.UserName); if (role == "1") { string idn = ""; if (Request.QueryString["comment"] != null) { idn = ut.GetIdNewsByComment(Request.QueryString["comment"]); } else { idn = Request.QueryString["news"]; } res = "<a href='" + Page.Request.Url.AbsolutePath.ToString() + "?p=EditArticle&idnews=" + idn + "'>|" + GetGlobalResourceObject("language", "Edit") + "|</a>"; } } return(res); }
protected void SendComment(object sender, EventArgs e) { String comment = Page.Request.Form["commentarea"]; MembershipUser currentUser = Membership.GetUser(); anm_Utility ut = new anm_Utility(); string idn = ""; if (HttpContext.Current.Request.QueryString["news"] != null) { idn = HttpContext.Current.Request.QueryString["news"]; } else { idn = ut.GetIdNewsByComment(Request.QueryString["comment"]); } string titlenews = ut.GetTitleNews(idn); string url = Page.Request.Url.AbsolutePath.ToString() + "?p=articles&news=" + idn; if (currentUser == null && (ut.GetSetting("Anonymous") == "False" || ut.GetSetting("Anonymous") == "")) { Response.Redirect(url + "&err=5#response"); } else if (comment.Length == 0) { Response.Redirect(url + "&err=1#response"); } else if (comment.Length > 2000) { Response.Redirect(url + "&err=4#response"); } else { if (ut.GetSetting("CaptchaComments") == "True") { if (txtcaptcha.Text.ToString() != Request.Cookies["Captcha"]["value"]) { Response.Redirect(url + "&err=3#response"); } } Boolean bbcode; String commento; try { bbcode = Convert.ToBoolean(ut.GetSetting("BBcode")); } catch { bbcode = false; } if (bbcode) { commento = ut.ConvertBBCodeToHTML(comment); } else { Regex exp; exp = new Regex(@"\<blockquote\>(.+?)\</blockquote\>"); commento = exp.Replace(comment, ""); exp = new Regex(@"\[QUOTE\=(.+?)\](.+?)\[/QUOTE\]"); commento = exp.Replace(commento, "<blockquote><strong>$1 wrote</strong>:<br/>$2</blockquote>"); exp = new Regex(@"\[QUOTE\](.+?)\[/QUOTE\]"); commento = exp.Replace(commento, "<blockquote>$1</blockquote>"); commento = commento.Replace("<br />", "\n"); commento = commento.Replace("\r\n", "<br />"); commento = commento.Replace("\n", "<br />"); commento = commento.Replace("</blockquote><br />", "</blockquote>"); } Boolean approve; try { approve = Convert.ToBoolean(ut.GetSetting("ApproveComments")); } catch { approve = true; } string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; string idnews = idn.ToString(); int nc = ut.GetCommentsNews(idnews); try { string strConn = ConfigurationManager.ConnectionStrings["anmcs"].ToString(); SqlConnection conn = new SqlConnection(strConn); SqlCommand command = new SqlCommand("anm_InsertComment", conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@idnews", SqlDbType.Int).Value = idnews; if (currentUser == null) { command.Parameters.Add("@commentator", SqlDbType.NVarChar).Value = "Anonymous"; } else { command.Parameters.Add("@commentator", SqlDbType.NVarChar).Value = currentUser.UserName.ToString(); } command.Parameters.Add("@comment", SqlDbType.NText).Value = commento; command.Parameters.Add("@ip", SqlDbType.NVarChar).Value = ip; command.Parameters.Add("@approved", SqlDbType.NVarChar).Value = !approve; conn.Open(); int rows = command.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { lblerror.Text = ex.Message; lblerror.Visible = true; } if (approve) { Response.Redirect(Page.Request.Url.AbsolutePath.ToString() + "?p=confirm&mes=" + GetGlobalResourceObject("language", "CommentSent") + "&link=" + idnews); } else { ut.IcreaseComments(idnews, nc + 1); Response.Redirect(apath + "/articles/" + idn + "/" + ut.RemoveNonAlfaNumeric(titlenews) + ".aspx#comments"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { anm_Utility ut = new anm_Utility(); string idn = HttpContext.Current.Request.QueryString["news"]; string titlenews = ut.GetTitleNews(idn); Page.Title = titlenews + " - " + ut.GetSetting("SiteName"); if (Request.QueryString["page"] != null) { currentpage = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"].ToString()); } if (Request.QueryString["comment"] != null) { string idc = Request.QueryString["comment"]; int rownumber = 0; try { idn = ut.GetIdNewsByComment(Request.QueryString["comment"]); string strConn = ConfigurationManager.ConnectionStrings["anmcs"].ToString(); SqlConnection myConnection = new SqlConnection(strConn); SqlCommand myCommand2 = new SqlCommand(); myCommand2.Connection = myConnection; myConnection.Open(); myCommand2.CommandText = "SELECT RowNumber FROM (SELECT idcomment, ROW_NUMBER() OVER(ORDER BY idcomment DESC) AS RowNumber FROM [anm_Comments] WHERE [idnews] = " + idn + " and [approved] = 'true') AS NewsWithRowNumbers WHERE idcomment = " + idc + ""; SqlDataReader reader2 = myCommand2.ExecuteReader(); if (reader2.Read()) { rownumber = Convert.ToInt32(reader2["RowNumber"].ToString()); } myConnection.Close(); } catch { Response.Redirect(apath + "/homepage.aspx"); } int maxRows = 15; if (ut.GetSetting("NumComments") != "") { maxRows = Convert.ToInt32(ut.GetSetting("NumComments")); } int page = (rownumber / maxRows) + 1; if (rownumber % maxRows == 0) { page = page - 1; } titlenews = ut.GetTitleNews(idn); currentpage = page; Page.Title = titlenews + " - " + GetGlobalResourceObject("language", "Comment").ToString() + " " + idc + " - " + ut.GetSetting("SiteName"); } SqlDataSource2.SelectParameters["idnews"].DefaultValue = idn; SqlDataSource1.SelectParameters["idnews"].DefaultValue = idn; string path = Page.Request.Url.AbsolutePath.ToString(); string idnews = idn; HLrssComments.NavigateUrl = HLsubscribeCom.NavigateUrl = apath + "/subscribecomments/" + idnews + ".aspx"; HLsubscribeCom.Text = GetGlobalResourceObject("language", "Subscribe").ToString() + " " + GetGlobalResourceObject("language", "Comments").ToString(); if (Request.QueryString["err"] == "1") { lblerror.Visible = true; lblerror.Text = GetGlobalResourceObject("language", "insertcomment").ToString(); errorcaptcha.Visible = false; Panelcomm.Visible = false; } if (Request.QueryString["err"] == "4") { lblerror.Visible = true; lblerror.Text = GetGlobalResourceObject("language", "commentlength").ToString(); errorcaptcha.Visible = false; Panelcomm.Visible = false; } if (Request.QueryString["err"] == "3") { errorcaptcha.Visible = true; lblerror.Visible = false; Panelcomm.Visible = false; } if (Request.QueryString["err"] == "5") { Panelcomm.Visible = true; lblerror.Visible = false; errorcaptcha.Visible = false; } if (Request.IsAuthenticated) { MembershipUser user = Membership.GetUser(); string role = ut.GetRole(user.UserName); if (role == "1" || role == "2") { HLAdminComm.Text = "| [ADMIN] " + GetGlobalResourceObject("language", "ManageComments") + " |"; HLAdminComm.NavigateUrl = path + "?p=AdminComments&idnews=" + idnews; } Panelcomm.Visible = false; } else if (ut.GetSetting("Anonymous") == "False") { HyperLink4.NavigateUrl = apath + "/default.aspx?p=NewUser"; HyperLink5.NavigateUrl = apath + "/default.aspx?p=Login"; Panelcomm.Visible = true; btnSendC.Visible = false; } imgRssIcon.ImageUrl = apath + "/images/rssicon.gif"; int maximumRows = 15; int numarticles = 0; numarticles = ut.GetNumberComments(idn); if (ut.GetSetting("NumComments") != "") { maximumRows = Convert.ToInt32(ut.GetSetting("NumComments")); } int maxpage = (numarticles / maximumRows) + 1; if (numarticles % maximumRows == 0) { maxpage = numarticles / maximumRows; } string linknav = "<div class='linkpage'>"; if (currentpage != 0) { int page = currentpage; SqlDataSource2.SelectParameters["startRowIndex"].DefaultValue = (maximumRows * (page - 1)).ToString(); if (numarticles > maximumRows) { for (int i = (page - 5); i < (page + 10); i++) { if (i >= 1 && i <= (maxpage)) { if (page == i) { linknav += "<a href='" + apath + "/page" + i + "/comments/articles/" + idn + "/" + ut.RemoveNonAlfaNumeric(titlenews) + ".aspx#comments' class='pagenavselected'>" + i + "</a> "; } else { linknav += "<a href='" + apath + "/page" + i + "/comments/articles/" + idn + "/" + ut.RemoveNonAlfaNumeric(titlenews) + ".aspx#comments' class='pagenav'>" + i + "</a> "; } } } } } else { currentpage = 1; SqlDataSource2.SelectParameters["startRowIndex"].DefaultValue = "0"; for (int i = 1; i < 11; i++) { if (i == 1) { linknav += "<a href='" + apath + "/page" + i + "/comments/articles/" + idn + "/" + ut.RemoveNonAlfaNumeric(titlenews) + ".aspx#comments' class='pagenavselected'>" + i + "</a> "; } if (i > 1 && i <= maxpage) { linknav += "<a href='" + apath + "/page" + i + "/comments/articles/" + idn + "/" + ut.RemoveNonAlfaNumeric(titlenews) + ".aspx#comments' class='pagenav'>" + i + "</a> "; } } } if (linknav != "<div class='linkpage'>") { linknav += "- " + GetGlobalResourceObject("language", "Page") + " " + currentpage + " " + GetGlobalResourceObject("language", "Of") + " " + maxpage + "</div>"; } else { linknav = ""; } LTpagelink.Text = linknav; if (maxpage == 1) { LTpagelink.Visible = false; } SqlDataSource2.SelectParameters["maximumRows"].DefaultValue = maximumRows.ToString(); if ((ut.GetSetting("CaptchaComments") == "True" && ut.GetSetting("Anonymous") == "False" && Request.IsAuthenticated) || (ut.GetSetting("CaptchaComments") == "True" && ut.GetSetting("Anonymous") == "True") || (ut.GetSetting("CaptchaComments") == "True" && ut.GetSetting("Anonymous") == null)) { string text = (Guid.NewGuid().ToString()).Substring(0, 5); Response.Cookies["Captcha"]["value"] = text; imgcaptcha.ImageUrl = path + "?p=captcha"; UpdatePanel1.Visible = lblcaptcha.Visible = txtcaptcha.Visible = true; } } }