Beispiel #1
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public int UpdateComment(CommentInfo comment)
        {
            string cmdText = string.Format(@"update [{0}comments] set
                            PostId=@PostId,
                            ParentId=@ParentId,
                            UserId=@UserId,
                            Author=@Author,
                            Email=@Email,
                            AuthorUrl=@AuthorUrl,
                            Contents=@Contents,
                            EmailNotify=@EmailNotify,
                            IpAddress=@IpAddress,
                            CreateTime=@CreateTime,
                            Approved=@Approved
                            where CommentId=@CommentId ",ConfigHelper.Tableprefix);

            SqliteParameter[] prams = {
                                        SqliteHelper.MakeInParam("@PostId", DbType.Int32,4, comment.PostId),
                                        SqliteHelper.MakeInParam("@ParentId", DbType.Int32,4, comment.ParentId),
                                        SqliteHelper.MakeInParam("@UserId", DbType.Int32,4, comment.UserId),
                                        SqliteHelper.MakeInParam("@Author", DbType.String,255, comment.Author),
                                        SqliteHelper.MakeInParam("@Email", DbType.String,255, comment.Email),
                                        SqliteHelper.MakeInParam("@AuthorUrl", DbType.String,255, comment.AuthorUrl),
                                        SqliteHelper.MakeInParam("@Contents", DbType.String,255, comment.Contents),
                                        SqliteHelper.MakeInParam("@EmailNotify", DbType.Int32,4 ,    comment.EmailNotify),
                                        SqliteHelper.MakeInParam("@IpAddress", DbType.String,255, comment.IpAddress),
                                        SqliteHelper.MakeInParam("@CreateTime", DbType.Date,8, comment.CreateTime),
                                        SqliteHelper.MakeInParam("@Approved", DbType.Int32,4 ,   comment.Approved),
                                        SqliteHelper.MakeInParam("@CommentId", DbType.Int32,4, comment.CommentId),

                                    };
            return SqliteHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);
        }
Beispiel #2
0
 /// <summary>
 /// 数据转换
 /// </summary>
 /// <param name="read"></param>
 /// <returns></returns>
 private static List<CommentInfo> DataReaderToCommentList(SqliteDataReader read)
 {
     var list = new List<CommentInfo>();
     while (read.Read())
     {
         var comment = new CommentInfo
                           {
                               CommentId = Convert.ToInt32(read["CommentId"]),
                               ParentId = Convert.ToInt32(read["ParentId"]),
                               PostId = Convert.ToInt32(read["PostId"]),
                               UserId = Convert.ToInt32(read["UserId"]),
                               Author = Convert.ToString(read["Author"]),
                               Email = Convert.ToString(read["Email"]),
                               AuthorUrl = Convert.ToString(read["AuthorUrl"]),
                               Contents = Convert.ToString(read["Contents"]),
                               EmailNotify = Convert.ToInt32(read["EmailNotify"]),
                               IpAddress = Convert.ToString(read["IpAddress"]),
                               CreateTime = Convert.ToDateTime(read["CreateTime"]),
                               Approved = Convert.ToInt32(read["Approved"])
                           };
         list.Add(comment);
     }
     read.Close();
     return list;
 }
Beispiel #3
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public int InsertComment(CommentInfo comment)
        {
            string cmdText = string.Format(@"insert into [{0}comments](
                            PostId, ParentId,UserId,Author,Email,AuthorUrl,Contents,EmailNotify,IpAddress,CreateTime,Approved)
                             values (
                            @PostId, @ParentId,@UserId,@Author,@Email,@AuthorUrl,@Contents,@EmailNotify,@IpAddress,@CreateTime,@Approved)",ConfigHelper.Tableprefix);

            SqliteParameter[] prams = {
                                        SqliteHelper.MakeInParam("@PostId", DbType.Int32,4, comment.PostId),
                                        SqliteHelper.MakeInParam("@ParentId", DbType.Int32,4, comment.ParentId),
                                        SqliteHelper.MakeInParam("@UserId", DbType.Int32,4, comment.UserId),
                                        SqliteHelper.MakeInParam("@Author", DbType.String,255, comment.Author),
                                        SqliteHelper.MakeInParam("@Email", DbType.String,255, comment.Email),
                                        SqliteHelper.MakeInParam("@AuthorUrl", DbType.String,255, comment.AuthorUrl),
                                        SqliteHelper.MakeInParam("@Contents", DbType.String,255, comment.Contents),
                                        SqliteHelper.MakeInParam("@EmailNotify", DbType.Int32,4 ,    comment.EmailNotify),
                                        SqliteHelper.MakeInParam("@IpAddress", DbType.String,255, comment.IpAddress),
                                        SqliteHelper.MakeInParam("@CreateTime", DbType.Date,8, comment.CreateTime),
                                        SqliteHelper.MakeInParam("@Approved", DbType.Int32,4 ,   comment.Approved),
            };
            SqliteHelper.ExecuteNonQuery(CommandType.Text, cmdText, prams);

            int newId = Convert.ToInt32(SqliteHelper.ExecuteScalar(string.Format("select  [CommentId] from [{0}comments]  order by [CommentId] desc limit 1",ConfigHelper.Tableprefix)));
            return newId;
        }
Beispiel #4
0
        /// <summary>
        /// 保存评论
        /// </summary>
        public void SaveComment()
        {
            int contentMaxLength = 1000;    //内容最长长度

            int postid = Jqpress.Framework.Web.PressRequest.GetFormInt("postid", 0);
            string author = StringHelper.CutString(Jqpress.Framework.Web.PressRequest.GetFormString("commentauthor"), 0, 20);
            string email = StringHelper.CutString(Jqpress.Framework.Web.PressRequest.GetFormString("commentemail"), 0, 50);
            string siteurl = StringHelper.CutString(Jqpress.Framework.Web.PressRequest.GetFormString("commentsiteurl"), 0, 100);
            int parentid = Jqpress.Framework.Web.PressRequest.GetFormInt("ReplyToCommentId", 0);
            string content = Jqpress.Framework.Web.PressRequest.GetFormString("commentcontent");
            int remeber = Jqpress.Framework.Web.PressRequest.GetFormInt("commentremember", 0);
            int emailnotify = Jqpress.Framework.Web.PressRequest.GetFormInt("commentemail", 0);
            string verifycode = Jqpress.Framework.Web.PressRequest.GetFormString("commentverifycode");

            CommentInfo c = new CommentInfo();

            c.ParentId = parentid;
            c.Contents = StringHelper.TextToHtml(StringHelper.CutString(content, 0, contentMaxLength));
            c.CreateTime = DateTime.Now;
            c.Email = Jqpress.Framework.Web.HttpHelper.HtmlEncode(email);
            c.EmailNotify = emailnotify;
            c.IpAddress = Jqpress.Framework.Web.PressRequest.GetIP();
            c.ParentId = 0;
            c.PostId = postid;
            c.UserId = 0;
            c.Author = author;
            c.AuthorUrl = siteurl;

            PostInfo post = PostService.GetPost(postid);
            switch (BlogConfig.GetSetting().CommentApproved)
            {
                case 1:
                    c.Approved = (int)ApprovedStatus.Success;
                    break;
                case 2:
                    string[] blackwords = BlogConfig.GetSetting().CommentSpamwords.Split(',');
                    bool hasBlackword = false;
                    foreach (string word in blackwords)
                    {
                        if (c.Contents.IndexOf(word) != -1)
                        {
                            hasBlackword = true;
                            break;
                        }
                    }
                    c.Approved = hasBlackword ? (int)ApprovedStatus.Wait : (int)ApprovedStatus.Success;
                    break;
                case 3:
                default:
                    c.Approved = (int)ApprovedStatus.Wait;
                    break;
            }

            int newID = CommentService.InsertComment(c);
            string response = "<li id=\"comment-comment-"+newID+"\" class=\"comment even thread-even depth-1\">";
            response += "<div class=\"comment-body\" id=\"div-comment-"+newID+"\">";
            response += "<div class=\"comment-author vcard\">";
            response += "<img width=\"26\" height=\"26\" class=\"avatar avatar-26 photo avatar-default\" ";
            response += "src=\"http://www.gravatar.com/avatar/" + c.GravatarCode + "?size=26\" \">";
            response += "<cite class=\"fn\">"+c.Author+"</cite> ";
            response += "<span class=\"says\">说:</span></div>";
            response += " <p> ";
            response += c.Contents;
            response += "</p>";
            response += "</li>";
            HttpContext.Current.Response.Write(response);
            SendMail(postid,email,post,content,author,siteurl,c,parentid);
            HttpContext.Current.Response.End();

            /*
             * <li id="comment-comment-${item.commentid}" class="comment even thread-even depth-1">
             <div class="comment-author vcard">
            <img width="26" height="26" class="avatar avatar-26 photo avatar-default"
            src="http://www.gravatar.com/avatar/${item.gravatarcode}?size=26" alt="${item.nickname}">
             *
            <cite class="fn">${item.authorlink}</cite> <span class="says">说:</span></div>
             */
        }
Beispiel #5
0
        public void SendMail(int postid, string email, PostInfo post, string content, string author, string siteurl, CommentInfo c,int parentid)
        {
            #region 发邮件
            try
            {

                if (BlogConfig.GetSetting().SendMailNotifyByComment == 1) //给订阅者发邮件
                {
                    //先不考虑审核的问题
                    List<CommentInfo> list = CommentService.GetCommentList(int.MaxValue, 1, -1, postid, 0, -1, 1, string.Empty);

                    List<string> emailList = new List<string>();

                    foreach (CommentInfo cmt in list)
                    {
                        if (!Jqpress.Framework.Utils.Validate.IsValidEmail(cmt.Email))
                        {
                            continue;
                        }
                        //自己不用发
                        if (email == cmt.Email)
                        {
                            continue;
                        }
                        //不重复发送
                        if (emailList.Contains(cmt.Email))
                        {
                            continue;
                        }
                        emailList.Add(cmt.Email);

                        string subject = string.Empty;
                        string body = string.Empty;

                        subject = string.Format("[评论订阅通知]{0}", post.Title);
                        body += string.Format("您订阅的{0}有新评论了:<br/>", post.Title);
                        body += "<hr/>";
                        body += content;
                        body += "<hr/>";
                        body += "<br />评论作者: " + author;

                        if (!string.IsNullOrEmpty(siteurl))
                        {
                            body += string.Format(" (<a href=\"{0}\">{0}</a>)", siteurl);
                        }

                        body += "<br />评论时间: " + DateTime.Now;
                        body += string.Format("<br />原文连接: <a href=\"{0}\" title=\"{1}\" >{1}</a>", post.Url, post.Title);

                        body += "<br />注:系统自动通知邮件,不要回复。";

                        EmailHelper.SendAsync(cmt.Email, subject, body);
                    }
                }

                if (BlogConfig.GetSetting().SendMailAuthorByComment == 1 && c.ParentId <= 0)       //给文章作者发邮件 回复时不发邮件
                {
                    string subject = string.Empty;
                    string body = string.Empty;

                    subject = string.Format("[新评论通知]{0}", post.Title);
                    body += string.Format("您发表的{0}有新评论了:<br/>", post.Title);
                    body += "<hr/>";
                    body += content;
                    body += "<hr/>";
                    body += "<br />评论作者: " + author;

                    if (!string.IsNullOrEmpty(siteurl))
                    {
                        body += string.Format(" (<a href=\"{0}\">{0}</a>)", siteurl);
                    }

                    body += "<br />评论时间: " + DateTime.Now;
                    body += string.Format("<br />原文连接: <a href=\"{0}\" title=\"{1}\" >{1}</a>", post.Url, post.Title);

                    body += "<br />注:系统自动通知邮件,不要回复。";

                    UserInfo user = UserService.GetUser(post.UserId);
                    if (user != null && Jqpress.Framework.Utils.Validate.IsValidEmail(user.Email))
                    {
                        EmailHelper.SendAsync(user.Email, subject, body);
                    }
                }
                if (BlogConfig.GetSetting().SendMailNotifyByComment == 1)//回复时发邮件
                {
                    //获取原品论者的邮箱
                    string replyemail = CommentService.GetComment(parentid).Email;
                    string subject = string.Empty;
                    string body = string.Empty;

                    subject = string.Format("[评论回复通知]{0}", post.Title);
                    body += string.Format("您对 {0} 发表的评论有回复了:<br/>", post.Title);
                    body += "<hr/>";
                    body += content;
                    body += "<hr/>";
                    body += "<br />评论作者: " + author;

                    if (!string.IsNullOrEmpty(siteurl))
                    {
                        body += string.Format(" (<a href=\"{0}\">{0}</a>)", siteurl);
                    }

                    body += "<br />回复时间: " + DateTime.Now;
                    body += string.Format("<br />原文连接: <a href=\"{0}\" title=\"{1}\" >{1}</a>", post.Url, post.Title);

                    body += "<br />注:系统自动通知邮件,不要回复。";

                    if (email != "" && Jqpress.Framework.Utils.Validate.IsValidEmail(replyemail))
                    {
                        EmailHelper.SendAsync(email, subject, body);
                    }
                }

            }catch(Exception e){

            }
            #endregion
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static int UpdateComment(CommentInfo comment)
        {
            _recentcomments = null;

            return DatabaseProvider.Instance.UpdateComment(comment);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static int InsertComment(CommentInfo comment)
        {
            int result = DatabaseProvider.Instance.InsertComment(comment);

            //统计
            StatisticsService.UpdateStatisticsCommentCount(1);

            //用户
            UserService.UpdateUserCommentCount(comment.UserId, 1);

            //文章
            PostService.UpdatePostCommentCount(comment.PostId, 1);

            _recentcomments = null;

            return result;
        }