int _minTokensInComment = 2; // Minimum words required in the Comments Text. #endregion Fields #region Methods /* private void LoadComments(string iid) { CommentDiv.Controls.Add(new LiteralControl(gui.LineBreak)); CommentDiv.Controls.Add(new LiteralControl(gui.LineBreak)); // string queryString = "SELECT CID, UID, Date, Comment FROM getputs.comments WHERE IID=" + iid + " ORDER BY DATE_FORMAT(Date, '%Y-%m-%d %k:%i:%S') DESC;"; string queryString = "SELECT CID, UID, Date, Comment FROM getputs.comments WHERE IID=" + iid + " ORDER BY DATE_FORMAT(Date, '%Y-%m-%d %k:%i:%S') ASC;"; MySqlDataReader retList; retList = dbOps.ExecuteReader(queryString); if (retList != null && retList.HasRows) while (retList.Read()) { string cid = Convert.ToString(retList["CID"]); string uid = Convert.ToString(retList["UID"]); string date = Convert.ToString(retList["Date"]); string comment = Convert.ToString(retList["Comment"]); LinkButton userLB = new LinkButton(); userLB.Click += new EventHandler(userLB_Click); userLB.Text = uid; userLB.CssClass = "CSS_Submitter"; //userLB.Font.Underline = false; //userLB.Font.Size = FontUnit.Small; //userLB.ForeColor = System.Drawing.Color.Blue; CommentDiv.Controls.Add(userLB); CommentDiv.Controls.Add(new LiteralControl(seperator)); string dateFormatString = gui.SmallFontStart + gui.GrayFontStart + general.GetFormattedDate(date) + gui.GrayFontEnd + gui.SmallFontEnd; Label dateLabel = new Label(); dateLabel.Text = dateFormatString; dateLabel.CssClass = "CSS_SubmissionFreshness"; //dateLabel.Font.Size = FontUnit.Small; //dateLabel.ForeColor = System.Drawing.Color.Gray; CommentDiv.Controls.Add(dateLabel); CommentDiv.Controls.Add(new LiteralControl(gui.LineBreak)); CommentDiv.Controls.Add(new LiteralControl(comment)); CommentDiv.Controls.Add(new LiteralControl(gui.LineBreak)); CommentDiv.Controls.Add(new LiteralControl(gui.LineBreak)); } retList.Close(); } */ protected void CommentButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(user)) { Response.Redirect(links.LoginLink, false); } else { MessageLabel.Text = string.Empty; string comment = CommentTB.Text.Trim(); comment = general.EscapeCharacters(comment); if (string.IsNullOrEmpty(comment)) { MessageLabel.Text = gui.RedFontStart + "Please enter a valid comment." + gui.RedFontEnd; } else { List<string> commentTokens = tagger.GetTokens(comment, false, false, false); if (commentTokens.Count >= _minTokensInComment && commentTokens.Count <= _maxTokensInComment) { // Get the IP Address string ip = general.GetIP(this.Request); // Check if the Comment is a Spam Comment. SpamDetection spamDetection = new SpamDetection(); if (spamDetection.IsSpam(user, ip, comment)) { // Spam // Store this item as spam. This DB of spam comments might be helpful in training a filter. MessageLabel.Text = gui.RedFontStart + "Our Spam Filter detected this Comment to be spam." + gui.RedFontEnd; } else { // Not Spam // Get the Tags for the Comment. string commentTagString = string.Empty; //// Vatsal Shah | 2009-04-21 | Am turning tagging off for now. Not too sure whether we should have this feature. //if (tagger.IsTaggingOn) //{ // List<string> commentTags = tagger.GetImportantTagsList(commentTokens, tagger.GetPOSTags(commentTokens)); // commentTagString = general.ConvertListToCSV(commentTags); //} string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // string queryString = "SELECT NComments FROM item WHERE iid = " + iid + ";"; // SELECT MAX(CID) FROM comments WHERE IID = 200; string queryString = "SELECT MAX(CID) FROM comments WHERE IID = " + iid + ";"; int cid = dbOps.ExecuteScalar(queryString) + 1; // queryString = "INSERT INTO comments (CID, IID, UID, Date, Comment) VALUES(" + cid.ToString() + ", " + iid.ToString() + ", '" + user + "', '" + date + "', '" + comment + "');"; // queryString = "INSERT INTO comments (CID, IID, UID, Date, Comment, IP) VALUES(" + cid.ToString() + ", " + iid.ToString() + ", '" + user + "', '" + date + "', '" + comment + "' , INET_ATON('" + ip + "'));"; queryString = "INSERT INTO comments (CID, IID, UID, Date, Comment, IP, Tags) VALUES(" + cid.ToString() + ", " + iid.ToString() + ", '" + user + "', '" + date + "', '" + comment + "' , INET_ATON('" + ip + "'), '" + commentTagString + "');"; int retValue = dbOps.ExecuteNonQuery(queryString); if (retValue > 0) { // Update the NComments section in getputs.item Table. queryString = "UPDATE item SET NComments=NComments+1 WHERE iid=" + iid.ToString() + ";"; retValue = dbOps.ExecuteNonQuery(queryString); if (retValue > 0) { MessageLabel.Text = gui.GreenFontStart + "Comment Added." + gui.GreenFontEnd; CommentTB.Text = string.Empty; } } else { MessageLabel.Text = gui.RedFontStart + "Please Try Again." + gui.RedFontEnd; } } } else { if (commentTokens.Count < _maxTokensInComment) { MessageLabel.Text = gui.RedFontStart + "Too few words in the comment." + gui.RedFontEnd; } else if(commentTokens.Count > _maxTokensInComment) { MessageLabel.Text = gui.RedFontStart + "Too many words in the comment." + gui.RedFontEnd; } } } } }
protected void Page_Load(object sender, EventArgs e) { dbOps = DBOperations.Instance; links = Links.Instance; general = General.Instance; gui = GUIVariables.Instance; engine = ProcessingEngine.Instance; categories = Categories.Instance; tokenizer = Tokenizer.Instance; tagger =Tagger.Instance; imageEngine = ImageEngine.Instance; log = Logger.Instance; spamDetection = (SpamDetection)Application["spamDetection"]; #region CookieAlreadyExists // START: If a getputsCookie with the Username already exists, do not show the Login Page. if (Request.Cookies["getputsCookie"] != null) { HttpCookie getputsCookie = Request.Cookies["getputsCookie"]; UID = dbOps.Decrypt(getputsCookie["UID"].ToString().Trim()); } if (string.IsNullOrEmpty(UID)) { Response.Redirect(links.LoginLink, false); } // END: If a getputsCookie with the Username already exists, do not show the Login Page. #endregion CookieAlreadyExists StringBuilder explanationSB = new StringBuilder(); explanationSB.Append(gui.GreenFontStart); explanationSB.Append(gui.BoldFontStart); explanationSB.Append("Posting News has never been this easy!"); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.HTMLTab + "(1) Copy and Paste the Link of the news/webpage you want to Post."); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.HTMLTab + "(2) Click on the \"Get Title\" Button to automatically get the Title,"); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.HTMLTab + "OR, Write a Descriptive Title."); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.HTMLTab + "(3) Select an appropriate Category."); explanationSB.Append(gui.LineBreak); explanationSB.Append("And you are done!"); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.BoldFontEnd); explanationSB.Append(gui.GreenFontEnd); explanationSB.Append(gui.LineBreak); explanationSB.Append(gui.LineBreak); explanationSB.Append("If submitting a link, keep the text section empty."); explanationSB.Append(gui.LineBreak); explanationSB.Append("If submitting text, keep the link section empty."); explanationSB.Append(gui.LineBreak); explanationSB.Append("If there is a link, the text section will be ignored."); ExplanationLabel.Text = explanationSB.ToString(); AddTags(); // For the Bookmarklet. // Check the Tools.aspx page for matching the Title/Link parameters. if (!string.IsNullOrEmpty(Request.QueryString["title"]) && !string.IsNullOrEmpty(Request.QueryString["url"])) { TitleTB.Text = Request.QueryString["title"].Trim(); LinkTB.Text = Request.QueryString["url"]; } // If not using ReCaptcha Project, but using the Captcha Library. //if (!IsPostBack) //{ // HttpContext.Current.Session["CaptchaImageText"] = general.GenerateRandomCode(); // // log.Log("Inside !IsPostBack : " + HttpContext.Current.Session["CaptchaImageText"].ToString()); //} }