コード例 #1
0
ファイル: MetaWeblog.cs プロジェクト: kkozmic/RaccoonBlog
        string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
        {
            var user = ValidateUser(username, password);
            var comments = new PostComments();
            session.Store(comments);

            var publishDate = post.dateCreated == null
                                ? postScheduleringStrategy.Schedule()
                                : postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

            var newPost = new Models.Post
            {
                AuthorId = user.Id,
                Body = post.description,
                CommentsId = comments.Id,
                CreatedAt = DateTimeOffset.Now,
                SkipAutoReschedule = post.dateCreated != null,
                PublishAt = publishDate,
                Tags = post.categories,
                Title = post.title,
                CommentsCount = 0,
            };
            session.Store(newPost);
            session.SaveChanges();

            return newPost.Id;
        }
コード例 #2
0
ファイル: AddCommentTask.cs プロジェクト: ayende/RaccoonBlog
		private void SetCommenter(Commenter commenter, PostComments.Comment comment)
		{
			if (requestValues.IsAuthenticated)
				return;

			commentInput.MapPropertiesToInstance(commenter);
			commenter.IsTrustedCommenter = comment.IsSpam == false;

			if (comment.IsSpam)
				commenter.NumberOfSpamComments++;

			DocumentSession.Store(commenter);
			comment.CommenterId = commenter.Id;
		}
コード例 #3
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment)
        {
            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = post.Title;
            viewModel.BlogName = Session.Load<BlogConfig>("Blog/Config").Title;

            var subject = string.Format("Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName);

            if(comment.IsSpam)
                subject = "Spam " + subject;

            CommandExecutor.ExcuteLater(new SendEmailCommand(viewModel.Email,subject, "NewComment", viewModel));
        }
コード例 #4
0
        public ActionResult Add(PostInput input)
        {
            if (!ModelState.IsValid)
                return View("Edit", input);

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            // Create the post comments object and link between it and the post
            var comments = new PostComments
            {
                Comments = new List<PostComments.Comment>(),
                Spam = new List<PostComments.Comment>()
            };
            RavenSession.Store(comments);

            // Create new post object
            var post = new Post
                        {
                            Tags = TagsResolver.ResolveTagsInput(input.Tags),
                            PublishAt = input.PublishAt,
                            AllowComments = input.AllowComments,
                            AuthorId = user.Id,
                            LastEditedByUserId = user.Id,
                            LastEditedAt = DateTimeOffset.Now,
                            CommentsId = comments.Id,
                            ContentType = input.ContentType,
                            Body = input.Body,
                            CreatedAt = DateTimeOffset.Now,
                            Title = input.Title,
                        };

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);
            comments.Post = new PostComments.PostReference
            {
                Id = post.Id,
                PublishAt = post.PublishAt,
            };

            return RedirectToAction("Details", new { id = post.Id.ToIntId() });
        }
コード例 #5
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment, User postAuthor)
        {
            if (_requestValues.IsAuthenticated)
                return; // we don't send email for authenticated users

            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = HttpUtility.HtmlDecode(post.Title);
            viewModel.PostSlug = SlugConverter.TitleToSlug(post.Title);
            viewModel.BlogName = DocumentSession.Load<BlogConfig>("Blog/Config").Title;
            viewModel.Key = post.ShowPostEvenIfPrivate.MapTo<string>();

            var subject = string.Format("{2}Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName, comment.IsSpam ? "[Spam] " : string.Empty);

            TaskExecutor.ExcuteLater(new SendEmailTask(viewModel.Email, subject, "NewComment", postAuthor.Email, viewModel));
        }
コード例 #6
0
        private void SendNewCommentEmail(Post post, PostComments.Comment comment)
        {
            if (_requestValues.IsAuthenticated)
                return; // we don't send email for authenticated users

            var viewModel = comment.MapTo<NewCommentEmailViewModel>();
            viewModel.PostId = RavenIdResolver.Resolve(post.Id);
            viewModel.PostTitle = HttpUtility.HtmlDecode(post.Title);
            viewModel.BlogName = Session.Load<BlogConfig>("Blog/Config").Title;

            var subject = string.Format("Comment on: {0} from {1}", viewModel.PostTitle, viewModel.BlogName);

            if(comment.IsSpam)
                subject = "Spam " + subject;

            CommandExecutor.ExcuteLater(new SendEmailCommand(viewModel.Email,subject, "NewComment", viewModel));
        }
コード例 #7
0
ファイル: MetaWeblog.cs プロジェクト: ayende/RaccoonBlog
		string IMetaWeblog.AddPost(string blogid, string username, string password, Post post, bool publish)
		{
			Models.Post newPost;
			using (var session = MvcApplication.DocumentStore.OpenSession())
			{
				var user = ValidateUser(username, password);
				var comments = new PostComments
								{
									Comments = new List<PostComments.Comment>(),
									Spam = new List<PostComments.Comment>()
								};
				session.Store(comments);

				var postScheduleringStrategy = new PostSchedulingStrategy(session, DateTimeOffset.Now);
				var publishDate = post.dateCreated == null
									? postScheduleringStrategy.Schedule()
									: postScheduleringStrategy.Schedule(new DateTimeOffset(post.dateCreated.Value));

				newPost = new Models.Post
								{
									AuthorId = user.Id,
									Body = post.description,
									CommentsId = comments.Id,
									CreatedAt = DateTimeOffset.Now,
									SkipAutoReschedule = post.dateCreated != null,
									PublishAt = publishDate,
									Tags = post.categories,
									Title = post.title,
									CommentsCount = 0,
									AllowComments = true,
								};
				session.Store(newPost);
				comments.Post = new PostComments.PostReference
									{
										Id = newPost.Id,
										PublishAt = publishDate
									};

				session.SaveChanges();
			}

			return newPost.Id;
		}
コード例 #8
0
        public static bool CheckForSpam(PostComments.Comment comment)
        {
            var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                Blog = BlogUrl,
                UserIp = comment.UserHostAddress,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Body,
                CommentType = "comment",
                CommentAuthor = comment.Author,
                CommentAuthorEmail = comment.Email,
                CommentAuthorUrl = comment.Url,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
コード例 #9
0
		public static void MarkHam(PostComments.Comment comment)
		{
			var api = new Akismet(AkismetKey, BlogUrl, comment.UserAgent);
			if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

			var akismetComment = new AkismetComment
			{
				Blog = BlogUrl,
				UserIp = comment.UserHostAddress,
				UserAgent = comment.UserAgent,
				CommentContent = comment.Body,
				CommentType = "comment",
				CommentAuthor = comment.Author,
				CommentAuthorEmail = comment.Email,
				CommentAuthorUrl = comment.Url,
			};
#if !DEBUG
			api.SubmitHam(akismetComment);
#endif
		}
コード例 #10
0
ファイル: AskimetService.cs プロジェクト: kkozmic/RaccoonBlog
        public void MarkHam(PostComments.Comment comment)
        {
            //Create a new instance of the Akismet API and verify your key is valid.
            string blog = ConfigurationManager.AppSettings["MainUrl"];
            var api = new Akismet(akismetKey, blog, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                Blog = blog,
                UserIp = comment.UserHostAddress,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Body,
                CommentType = "comment",
                CommentAuthor = comment.Author,
                CommentAuthorEmail = comment.Email,
                CommentAuthorUrl = comment.Url,
            };
            #if !DEBUG
            api.SubmitHam(akismetComment);
            #endif
        }
コード例 #11
0
ファイル: AskimetService.cs プロジェクト: kkozmic/RaccoonBlog
        public bool CheckForSpam(PostComments.Comment comment)
        {
            //Create a new instance of the Akismet API and verify your key is valid.
            string blog = ConfigurationManager.AppSettings["MainUrl"];
            var api = new Akismet(akismetKey, blog, comment.UserAgent);
            if (!api.VerifyKey()) throw new Exception("Akismet API key invalid.");

            var akismetComment = new AkismetComment
            {
                Blog = blog,
                UserIp = comment.UserHostAddress,
                UserAgent = comment.UserAgent,
                CommentContent = comment.Body,
                CommentType = "comment",
                CommentAuthor = comment.Author,
                CommentAuthorEmail = comment.Email,
                CommentAuthorUrl = comment.Url,
            };

            //Check if Akismet thinks this comment is spam. Returns TRUE if spam.
            return api.CommentCheck(akismetComment);
        }
コード例 #12
0
ファイル: PostsController.cs プロジェクト: nzaugg/RaccoonBlog
		public ActionResult Update(PostInput input)
		{
			if (!ModelState.IsValid)
				return View("Edit", input);

			var post = RavenSession.Load<Post>(input.Id) ?? new Post {CreatedAt = DateTimeOffset.Now};
			input.MapPropertiesToInstance(post);

			// Be able to record the user making the actual post
			var user = RavenSession.GetCurrentUser();
			if (string.IsNullOrEmpty(post.AuthorId))
			{
				post.AuthorId = user.Id;
			}
			else
			{
				post.LastEditedByUserId = user.Id;
				post.LastEditedAt = DateTimeOffset.Now;
			}

			if (post.PublishAt == DateTimeOffset.MinValue)
			{
				var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
				post.PublishAt = postScheduleringStrategy.Schedule();
			}

			// Actually save the post now
			RavenSession.Store(post);

			if (input.IsNewPost())
			{
				// Create the post comments object and link between it and the post
				var comments = new PostComments
				               {
				               	Comments = new List<PostComments.Comment>(),
				               	Spam = new List<PostComments.Comment>(),
				               	Post = new PostComments.PostReference
				               	       {
				               	       	Id = post.Id,
				               	       	PublishAt = post.PublishAt,
				               	       }
				               };

				RavenSession.Store(comments);
				post.CommentsId = comments.Id;	
			}

			return RedirectToAction("Details", new {Id = post.MapTo<PostReference>().DomainId});
		}
コード例 #13
0
ファイル: PostsController.cs プロジェクト: nzaugg/RaccoonBlog
		private void ResetNumberOfSpamComments(PostComments.Comment comment)
		{
			if (comment.CommenterId == null) 
				return;
			var commenter = RavenSession.Load<Commenter>(comment.CommenterId);
			if (commenter == null) 
				return;
			commenter.NumberOfSpamComments = 0;
		}
コード例 #14
0
        public ActionResult Update(TempInput sendInfo)
        {
            //var post = RavenSession.Load<Post>(input.Id) ?? new Post { CreatedAt = DateTimeOffset.Now };//Post is an empty tool here
            ////////////////

            sendInfo.Id = "0";
            var post = RavenSession.Load<Post>(sendInfo.Id) ?? new Post { CreatedAt = DateTimeOffset.Now };//Post is an empty tool here

            //input.MapPropertiesToInstance(post);//Entering data  ///////////////////////

            post.Title = sendInfo.Title;
            if (sendInfo.AllowComments == "on")
                post.AllowComments = true;
            else post.AllowComments = false;
            post.Body = sendInfo.Body;
            post.CreatedAt = DateTimeOffset.Now;

            //Convert PublishAt (string) into dateTime
            string mm = sendInfo.PublishAt.Substring(0, 2);
            int mmInt = int.Parse(mm);
            string dd = sendInfo.PublishAt.Substring(3,2);
            int ddInt = int.Parse(dd);
            string yy = sendInfo.PublishAt.Substring(6, 4);
            int yyInt = int.Parse(yy);
            // Convert into date
            DateTime TempDate=new DateTime(yyInt,mmInt,ddInt);
            // Convert into DateTimeOffset
            DateTimeOffset TempDateOffSet=new DateTimeOffset(TempDate);
            // Entering the date into post
            post.PublishAt = TempDateOffSet;

               // Entering the tag
            string tempTag = sendInfo.Tags;
            ICollection<string> t=new Collection<string>();
            t.Add(tempTag);
            post.Tags.Add(tempTag);

            //if (!ModelState.IsValid)             ////////////////////
            //    return View("Edit", input);    //////////////////

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();
            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt = DateTimeOffset.Now;
            }

            if (post.PublishAt <= DateTimeOffset.Now)

            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
                post.PublishAt = DateTimeOffset.Now;
                post.CreatedAt = DateTimeOffset.Now;
            }

            // Actually save the post now
            RavenSession.Store(post);

            //if (input.IsNewPost())    //////////////////////
            //{
                // Create the post comments object and link between it and the post
                var comments = new PostComments
                               {
                                   Comments = new List<PostComments.Comment>(),
                                   Spam = new List<PostComments.Comment>(),
                                   Post = new PostComments.PostReference
                                          {
                                              Id = post.Id,
                                              PublishAt = post.PublishAt,
                                          }
                               };

                RavenSession.Store(comments);
                post.CommentsId = comments.Id;
            //}                   ////////////////

            return RedirectToAction("Details", new { Id = post.MapTo<PostReference>().DomainId });
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: wheeliemow/RaccoonBlog
		private static void ImportDatabase(IDocumentStore store)
		{
			Stopwatch sp = Stopwatch.StartNew();

			using (var e = new SubtextEntities())
			{
				Console.WriteLine("Starting...");

				IOrderedEnumerable<Post> theEntireDatabaseOhMygod = e.Posts
					.Include("Comments")
					.Include("Links")
					.Include("Links.Categories")
					.ToList()
					.OrderBy(x => x.DateSyndicated);

				Console.WriteLine("Loading data took {0:#,#} ms", sp.ElapsedMilliseconds);

				var usersList = new List<User>();
				using (IDocumentSession s = store.OpenSession())
				{
					var users = new[]
					{
						new {Email = "*****@*****.**", FullName = "Ayende Rahien", TwitterNick = "ayende", RelatedTwitterNick=(string)null},
						new {Email = "*****@*****.**", FullName = "Fitzchak Yitzchaki", TwitterNick = "fitzchak", RelatedTwitterNick="ayende"},
					};
					for (int i = 0; i < users.Length; i++)
					{
						var user = new User
							{
								Id = "users/" + (i + 1),
								Email = users[i].Email,
								FullName = users[i].FullName,
								TwitterNick = users[i].TwitterNick,
								RelatedTwitterNick = users[i].RelatedTwitterNick,
								Enabled = true,
							};
						user.SetPassword("123456");
						s.Store(user);
						usersList.Add(user);
					}
					s.SaveChanges();
				}

				foreach (Post post in theEntireDatabaseOhMygod)
				{
					var ravenPost = new Web.Models.Post
						{
							AuthorId = usersList
									.Where(u=> u.FullName == post.Author)
									.Select(u => u.Id)
									.FirstOrDefault() ?? 
									usersList.First().Id,
							CreatedAt = new DateTimeOffset(post.DateAdded),
							PublishAt = new DateTimeOffset(post.DateSyndicated ?? post.DateAdded),
							Body = post.Text,
							LegacySlug = post.EntryName,
							Title = HttpUtility.HtmlDecode(post.Title),
							Tags = post.Links.Select(x => x.Categories.Title)
								.Where(x => x != "Uncategorized")
								.ToArray(),
							AllowComments = true
						};

					var commentsCollection = new PostComments();
					commentsCollection.Comments = post.Comments
						.Where(comment => comment.StatusFlag == 1)
						.OrderBy(comment => comment.DateCreated)
						.Select(
							comment => new PostComments.Comment
								{
									Id = commentsCollection.GenerateNewCommentId(),
									Author = comment.Author,
									Body = ConvertCommentToMarkdown(comment.Body),
									CreatedAt = comment.DateCreated,
									Email = comment.Email,
									Url = comment.Url,
									Important = comment.IsBlogAuthor ?? false,
									UserAgent = comment.UserAgent,
									UserHostAddress = comment.IpAddress,
									IsSpam = false,
									CommenterId = null,
								}
						).ToList();
					commentsCollection.Spam = post.Comments
						.Where(comment => comment.StatusFlag != 1)
						.OrderBy(comment => comment.DateCreated)
						.Select(
							comment => new PostComments.Comment
								{
									Id = commentsCollection.GenerateNewCommentId(),
									Author = comment.Author,
									Body = ConvertCommentToMarkdown(comment.Body),
									CreatedAt = comment.DateCreated,
									Email = comment.Email,
									Url = comment.Url,
									Important = comment.IsBlogAuthor ?? false,
									UserAgent = comment.UserAgent,
									UserHostAddress = comment.IpAddress,
									IsSpam = true,
									CommenterId = null,
								}
						).ToList();

					ravenPost.CommentsCount = commentsCollection.Comments.Count;

					using (IDocumentSession s = store.OpenSession())
					{
						s.Store(commentsCollection);
						ravenPost.CommentsId = commentsCollection.Id;

						s.Store(ravenPost);
						commentsCollection.Post = new PostComments.PostReference
						{
							Id = ravenPost.Id,
							PublishAt = ravenPost.PublishAt
						};

						s.SaveChanges();
					}
				}
			}
			Console.WriteLine(sp.Elapsed);
		}
コード例 #16
0
 private void ValidateCommentsAllowed(Post post, PostComments comments)
 {
     if (comments.AreCommentsClosed(post, BlogConfig.NumberOfDayToCloseComments))
         ModelState.AddModelError("CommentsClosed", "This post is closed for new comments.");
     if (post.AllowComments == false)
         ModelState.AddModelError("CommentsClosed", "This post does not allow comments.");
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: wheeliemow/RaccoonBlog
        private void importBlogPosts(IDocumentStore store, BlogMLBlog blog, Dictionary<string, User> usersList)
        {
            foreach (var post in blog.Posts)
            {
                var authorId = getAuthorId(usersList, post);

                var ravenPost = new Post
                    {
                        AuthorId = authorId,
                        CreatedAt = new DateTimeOffset(post.DateCreated),
                        PublishAt = new DateTimeOffset(post.DateCreated),
                        Body = post.Content.Text,
                        LegacySlug = SlugConverter.TitleToSlug(post.PostName ?? post.Title),
                        Title = HttpUtility.HtmlDecode(post.Title),
                        Tags =
                            post.Categories.Cast<BlogMLCategoryReference>()
                                .Select(x => blog.Categories.First(c => c.ID == x.Ref).Title)
                                .ToArray(),
                        AllowComments = true
                    };

                var commentsCollection = new PostComments();
                commentsCollection.Spam = new List<PostComments.Comment>();
                commentsCollection.Comments = post.Comments.Cast<BlogMLComment>()
                                                  .Where(comment => comment.Approved)
                                                  .OrderBy(comment => comment.DateCreated)
                                                  .Select(
                                                      comment => new PostComments.Comment
                                                          {
                                                              Id = commentsCollection.GenerateNewCommentId(),
                                                              Author = comment.UserName,
                                                              Body = ConvertCommentToMarkdown(comment.Content.Text),
                                                              CreatedAt = comment.DateCreated,
                                                              Email = comment.UserEMail,
                                                              Url = comment.UserUrl,
                                                              Important =
                                                                  usersList.Any(
                                                                      u => u.Value.FullName == comment.UserName),
                                                              //UserAgent = comment.,
                                                              //UserHostAddress = comment.IpAddress,
                                                              IsSpam = false,
                                                              CommenterId = null,
                                                          }
                    ).ToList();
                commentsCollection.Spam = post.Comments.Cast<BlogMLComment>()
                                              .Where(comment => !comment.Approved)
                                              .OrderBy(comment => comment.DateCreated)
                                              .Select(
                                                  comment => new PostComments.Comment
                                                      {
                                                          Id = commentsCollection.GenerateNewCommentId(),
                                                          Author = comment.UserName,
                                                          Body = ConvertCommentToMarkdown(comment.Content.Text),
                                                          CreatedAt = comment.DateCreated,
                                                          Email = comment.UserEMail,
                                                          Url = comment.UserUrl,
                                                          Important =
                                                              usersList.Any(u => u.Value.FullName == comment.UserName),
                                                          //UserAgent = comment.UserAgent,
                                                          //UserHostAddress = comment.IpAddress,
                                                          IsSpam = true,
                                                          CommenterId = null,
                                                      }
                    ).Where(c => c.Body != null).ToList();

                ravenPost.CommentsCount = commentsCollection.Comments.Count;

                using (var s = store.OpenSession())
                {
                    s.Store(commentsCollection);
                    ravenPost.CommentsId = commentsCollection.Id;

                    s.Store(ravenPost);
                    commentsCollection.Post = new PostComments.PostReference
                        {
                            Id = ravenPost.Id,
                            PublishAt = ravenPost.PublishAt
                        };

                    s.SaveChanges();
                }
            }
        }