protected override void Configure()
        {
            Mapper.CreateMap <Section, SectionDetails>()
            ;

            Mapper.CreateMap <Post, FuturePostViewModel>()
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            ;

            Mapper.CreateMap <Posts_Statistics.ReduceResult, PostsStatisticsViewModel>()
            ;

            Mapper.CreateMap <Post, RecentCommentViewModel>()
            .ForMember(x => x.PostId, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.PostTitle, o => o.MapFrom(m => m.Title))
            .ForMember(x => x.PostSlug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.CommentId, o => o.Ignore())
            .ForMember(x => x.ShortBody, o => o.Ignore())
            ;

            Mapper.CreateMap <PostComments.Comment, RecentCommentViewModel>()
            .ForMember(x => x.PostId, o => o.Ignore())
            .ForMember(x => x.ShortBody, o => o.MapFrom(x => MaxLength(x.Body, 128)))
            .ForMember(x => x.CommentId, o => o.MapFrom(x => x.Id))
            .ForMember(x => x.PostSlug, o => o.Ignore())
            .ForMember(x => x.PostTitle, o => o.Ignore())
            ;
        }
Пример #2
0
        public ActionResult Create(Post post)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var listOfTags = SeparateTags(post.Tags);

                    post.InternalTags = listOfTags;

                    post.FriendlyUrl = SlugConverter.TitleToSlug(post.Title);
                    // TODO check if this url is uniqe

                    DataSession.Store(post);
                    DataSession.SaveChanges();

                    TempData["success"] = "Inlägget sparat";
                    UpdateModel("Index");
                    return(RedirectToAction("Index"));
                }
            }

            catch (Exception)
            {
                TempData["error"] = "MIsslyckades med att publicera inlägget";
            }

            return(View(post));
        }
Пример #3
0
        public SectionMapperProfile()
        {
            CreateMap <Section, SectionDetails>()
            ;

            CreateMap <Post, FuturePostViewModel>()
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            ;

            CreateMap <Posts_Statistics.ReduceResult, PostsStatisticsViewModel>()
            ;

            CreateMap <Post, RecentCommentViewModel>()
            .ForMember(x => x.PostId, o => o.MapFrom(m => m.GetIdForUrl()))
            .ForMember(x => x.PostTitle, o => o.MapFrom(m => m.Title))
            .ForMember(x => x.PostSlug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.CommentId, o => o.Ignore())
            .ForMember(x => x.ShortBody, o => o.Ignore())
            ;

            CreateMap <PostComments.Comment, RecentCommentViewModel>()
            .ForMember(x => x.PostId, o => o.Ignore())
            .ForMember(x => x.ShortBody, o => o.MapFrom(x => MaxLength(x.Body, 128)))
            .ForMember(x => x.CommentId, o => o.MapFrom(x => x.Id))
            .ForMember(x => x.PostSlug, o => o.Ignore())
            .ForMember(x => x.PostTitle, o => o.Ignore())
            ;
        }
Пример #4
0
        public virtual ActionResult PostsSeries(string sectionTitle)
        {
            ViewBag.SectionTitle = sectionTitle;

            var series = RavenSession.Query <Posts_Series.Result, Posts_Series>()
                         .Where(x => x.Count > 1)
                         .OrderByDescending(x => x.MaxDate)
                         .Take(5)
                         .ToList();

            var vm = series.Select(result => new RecentSeriesViewModel
            {
                SeriesId        = result.SerieId,
                SeriesSlug      = SlugConverter.TitleToSlug(result.Series),
                SeriesTitle     = TitleConverter.ToSeriesTitle(result.Posts.First().Title),
                PostsCount      = result.Count,
                PostInformation = result.Posts
                                  .OrderByDescending(post => post.PublishAt)
                                  .FirstOrDefault(post => post.PublishAt <= DateTimeOffset.Now)
            })
                     .Where(x => x.PostInformation != null)
                     .ToList();

            return(View(vm));
        }
Пример #5
0
        public static string Url(Post post)
        {
            var slug    = SlugConverter.TitleToSlug(post.Title);
            var id      = post.GetIdForUrl();
            var blogUrl = ConfigurationHelper.MainBlogUrl.TrimEnd('/');

            return($"{blogUrl}/{id}/{slug}");
        }
Пример #6
0
        public static string Url(Post post)
        {
            var slug    = SlugConverter.TitleToSlug(post.Title);
            var id      = RavenIdResolver.Resolve(post.Id);
            var blogUrl = ConfigurationHelper.MainBlogUrl.TrimEnd('/');

            return($"{blogUrl}/{id}/{slug}");
        }
        public void IgnoresEntitiesCorrectly()
        {
            var result = SlugConverter.TitleToSlug("Document based modeling: Auctions & Bids");

            Assert.Equal("document-based-modeling-auctions-bids", result);

            result = SlugConverter.TitleToSlug("Hiring Questions–The phone book");
            Assert.Equal("hiring-questions-the-phone-book", result);
        }
        public PostViewModelMapperProfile()
        {
            CreateMap <Post, PostViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => m.GetIdForUrl()))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.IsCommentAllowed, o => o.MapFrom(m => m.AllowComments))
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            ;

            CreateMap <PostComments.Comment, PostViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlResolver.Resolve(m.Url)))
            .ForMember(x => x.Tooltip, o => o.MapFrom(m => string.IsNullOrEmpty(m.Url) ? "Comment by " + m.Author : m.Url))
            .ForMember(x => x.CreatedAt, o => o.MapFrom(m => m.CreatedAt.ToUniversalTime().ToString("MM/dd/yyyy hh:mm tt")))
            ;

            CreateMap <Post, PostReference>()
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Slug, o => o.Ignore())
            ;

            CreateMap <Commenter, CommentInput>()
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.MapFrom(m => m.Key))
            ;

            CreateMap <CommentInput, Commenter>()
            .ForMember(x => x.Id, o => o.Ignore())
            .ForMember(x => x.IsTrustedCommenter, o => o.Ignore())
            .ForMember(x => x.Key, o => o.Ignore())
            .ForMember(x => x.OpenId, o => o.Ignore())
            .ForMember(x => x.NumberOfSpamComments, o => o.Ignore())
            ;

            CreateMap <User, CommentInput>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m.FullName))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlHelper.RelativeToAbsolute(UrlHelper.RouteUrl("homepage"))))
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.Ignore())
            ;

            //CreateMap<UserProfile, CommentInput>()
            //    .ForMember(x => x.Name, o => o.MapFrom(m => m.FirstName + " " + m.LastName))
            //    .ForMember(x => x.Url, o => o.MapFrom(m => m.ProfileURL))
            //    .ForMember(x => x.Body, o => o.Ignore())
            //    .ForMember(x => x.CommenterKey, o => o.Ignore())
            //    ;

            CreateMap <HttpRequestWrapper, Tasks.AddCommentTask.RequestValues>();

            CreateMap <User, PostViewModel.UserDetails>();
        }
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostsViewModel.PostSummary>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlag(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Tags, o => o.MapFrom(m => m.Tags.Select(name => new TagDetails {
                Name = name
            })))
            ;

            Mapper.CreateMap <User, PostsViewModel.PostSummary.UserDetails>();
        }
        protected override void Configure()
        {
            Mapper.CreateMap <Posts_Series.PostInformation, PostInSeries>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.PublishAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Title, o => o.MapFrom(m => m.Title))
            ;

            Mapper.CreateMap <Posts_Series.Result, SeriesInfo>()
            .ForMember(x => x.SeriesTitle, o => o.MapFrom(x => x.Series))
            .ForMember(x => x.PostsInSeries, o => o.Ignore())
            ;
        }
Пример #11
0
        protected override void ConcreteExecute(IJobExecutionContext context)
        {
            var usedUrls = new HashSet <string>();

            if (AllApps == null)
            {
                AllApps = Store.GetAll(s => s.Query <App>()
                                       .Customize(x => x.WaitForNonStaleResults()))
                          .ToList();
            }

            var changed = new List <App>();

            foreach (var app in AllApps)
            {
                if (string.IsNullOrEmpty(app.FriendlyUrl) || usedUrls.Contains(app.FriendlyUrl))
                {
                    var friendlyUrlBase = SlugConverter.TitleToSlug(app.Title);
                    var friendlyUrl     = friendlyUrlBase;
                    int index           = 2;
                    while (usedUrls.Contains(friendlyUrl))
                    {
                        friendlyUrl = string.Format("{0}{1}", friendlyUrlBase, index++);
                    }

                    app.FriendlyUrl = friendlyUrl;
                    changed.Add(app);
                }
                usedUrls.Add(app.FriendlyUrl);
            }

            using (var session = Store.OpenSession())
            {
                session.Advanced.MaxNumberOfRequestsPerSession = 10000;
                for (int index = 0; index < changed.Count; index++)
                {
                    var app = changed[index];
                    session.Store(app);

                    if (index % 500 == 0)
                    {
                        Console.WriteLine("Saving {0}/{1} items", index, changed.Count);
                        session.SaveChanges();
                        Thread.Sleep(4000);
                    }
                }

                session.SaveChanges();
            }
        }
Пример #12
0
        public SeriesMapperProfile()
        {
            CreateMap <Posts_Series.PostInformation, PostInSeries>()
            .ForMember(x => x.Id, o => o.MapFrom(m => Post.GetIdForUrl(m.Id)))
            .ForMember(x => x.PublishAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Title, o => o.MapFrom(m => m.Title))
            ;

            CreateMap <Posts_Series.Result, SeriesInfo>()
            .ForMember(x => x.SeriesTitle, o => o.MapFrom(x => x.Series))
            .ForMember(x => x.PostsInSeries, o => o.Ignore())
            ;
        }
Пример #13
0
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostsViewModel.PostSummary>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            ;

            Mapper.CreateMap <User, PostsViewModel.PostSummary.UserDetails>();

            Mapper.CreateMap <string, TagDetails>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m))
            ;
        }
        public PostsViewModelMapperProfile()
        {
            CreateMap <Post, PostsViewModel.PostSummary>()
            .ForMember(x => x.Id, o => o.MapFrom(m => Post.GetIdForUrl(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            ;

            CreateMap <User, PostsViewModel.PostSummary.UserDetails>();

            CreateMap <string, TagDetails>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m))
            ;
        }
Пример #15
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));
        }
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostSummaryJson>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Title, o => o.MapFrom(m => HttpUtility.HtmlDecode(m.Title)))
            .ForMember(x => x.Start, o => o.MapFrom(m => m.PublishAt.ToString("yyyy-MM-ddTHH:mm:ssZ")))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlHelper.Action("Details", "Posts", new { Id = RavenIdResolver.Resolve(m.Id), Slug = SlugConverter.TitleToSlug(m.Title) })))
            .ForMember(x => x.AllDay, o => o.UseValue(false))
            ;

            Mapper.CreateMap <Post, PostInput>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Tags, o => o.MapFrom(m => TagsResolver.ResolveTags(m.Tags)))
            ;

            Mapper.CreateMap <PostInput, Post>()
            .ForMember(x => x.Id, o => o.Ignore())
            .ForMember(x => x.AuthorId, o => o.Ignore())
            .ForMember(x => x.LegacySlug, o => o.Ignore())
            .ForMember(x => x.ShowPostEvenIfPrivate, o => o.Ignore())
            .ForMember(x => x.SkipAutoReschedule, o => o.Ignore())
            .ForMember(x => x.IsDeleted, o => o.Ignore())
            .ForMember(x => x.CommentsCount, o => o.Ignore())
            .ForMember(x => x.CommentsId, o => o.Ignore())
            .ForMember(x => x.LastEditedByUserId, o => o.Ignore())
            .ForMember(x => x.LastEditedAt, o => o.Ignore())
            .ForMember(x => x.Tags, o => o.MapFrom(m => TagsResolver.ResolveTagsInput(m.Tags)))
            .ForMember(x => x.PublishAt, o => o.MapFrom(m => m.PublishAt.HasValue ? m.PublishAt.Value : DateTimeOffset.MinValue))
            ;

            Mapper.CreateMap <Post, AdminPostDetailsViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlug(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.Key, o => o.MapFrom(m => m.ShowPostEvenIfPrivate))
            ;

            Mapper.CreateMap <PostComments.Comment, AdminPostDetailsViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            ;
        }
Пример #17
0
        protected override void Configure()
        {
            Mapper.CreateMap <Post, PostViewModel.PostDetails>()
            .ForMember(x => x.Id, o => o.MapFrom(m => RavenIdResolver.Resolve(m.Id)))
            .ForMember(x => x.Slug, o => o.MapFrom(m => SlugConverter.TitleToSlag(m.Title)))
            .ForMember(x => x.PublishedAt, o => o.MapFrom(m => m.PublishAt))
            .ForMember(x => x.IsCommentAllowed, o => o.MapFrom(m => m.AllowComments))
            .ForMember(x => x.Author, o => o.Ignore())
            .ForMember(x => x.Tags, o => o.MapFrom(m => m.Tags.Select(name => new TagDetails {
                Name = name
            })))
            ;

            Mapper.CreateMap <PostComments.Comment, PostViewModel.Comment>()
            .ForMember(x => x.Body, o => o.MapFrom(m => MarkdownResolver.Resolve(m.Body)))
            .ForMember(x => x.EmailHash, o => o.MapFrom(m => EmailHashResolver.Resolve(m.Email)))
            .ForMember(x => x.IsImportant, o => o.MapFrom(m => m.Important))
            .ForMember(x => x.Url, o => o.MapFrom(m => UrlResolver.Resolve(m.Url)))
            .ForMember(x => x.Tooltip, o => o.MapFrom(m => string.IsNullOrEmpty(m.Url) ? "Comment by " + m.Author : m.Url))
            .ForMember(x => x.CreatedAt, o => o.MapFrom(m => m.CreatedAt.ToString("MM/dd/yyyy hh:mm tt")))
            ;

            Mapper.CreateMap <Post, PostReference>()
            .ForMember(x => x.Slug, o => o.Ignore())
            ;

            Mapper.CreateMap <Commenter, CommentInput>()
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.MapFrom(m => m.Key))
            ;

            Mapper.CreateMap <User, CommentInput>()
            .ForMember(x => x.Name, o => o.MapFrom(m => m.FullName))
            .ForMember(x => x.Url, o => o.MapFrom(m => ConfigurationManager.AppSettings["MainUrl"] + UrlHelper.RouteUrl("Default")))
            .ForMember(x => x.Body, o => o.Ignore())
            .ForMember(x => x.CommenterKey, o => o.Ignore())
            ;

            Mapper.CreateMap <HttpRequestWrapper, RequestValues>();

            Mapper.CreateMap <User, PostViewModel.UserDetails>();
        }
Пример #18
0
        Post IMetaWeblog.GetPost(string postid, string username, string password)
        {
            ValidateUser(username, password);
            var thePost = session.Load <Models.Post>(postid);

            if (thePost.IsDeleted)
            {
                throw new InvalidOperationException("You cannot get deleted post");
            }

            return(new Post
            {
                wp_slug = SlugConverter.TitleToSlag(thePost.Title),
                description = thePost.Body,
                dateCreated = thePost.PublishAt.DateTime,
                categories = thePost.Tags.ToArray(),
                title = thePost.Title,
                postid = thePost.Id,
            });
        }
        private IList <PostInSeries> GetPostsForCurrentSeries(Posts_Series.Result series)
        {
            IList <PostInSeries> postsInSeries = null;

            if (series != null)
            {
                postsInSeries = series
                                .Posts
                                .Select(s => new PostInSeries
                {
                    Id        = RavenIdResolver.Resolve(s.Id),
                    Slug      = SlugConverter.TitleToSlug(s.Title),
                    Title     = HttpUtility.HtmlDecode(TitleConverter.ToPostTitle(s.Title)),
                    PublishAt = s.PublishAt
                })
                                .OrderByDescending(p => p.PublishAt)
                                .ToList();
            }

            return(postsInSeries);
        }
Пример #20
0
        Post[] IMetaWeblog.GetRecentPosts(string blogid, string username, string password,
                                          int numberOfPosts)
        {
            ValidateUser(username, password);

            var list = session.Query <Models.Post>()
                       .Where(p => p.IsDeleted == false)
                       .OrderByDescending(x => x.PublishAt)
                       .Take(numberOfPosts)
                       .ToList();

            return(list.Select(thePost => new Post
            {
                wp_slug = SlugConverter.TitleToSlag(thePost.Title),
                description = thePost.Body,
                dateCreated = thePost.PublishAt.DateTime,
                categories = thePost.Tags.ToArray(),
                title = thePost.Title,
                postid = thePost.Id,
            }).ToArray());
        }
Пример #21
0
        Post[] IMetaWeblog.GetRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            ValidateUser(username, password);

            using (var session = MvcApplication.DocumentStore.OpenSession())
            {
                var list = session.Query <Models.Post>()
                           .OrderByDescending(x => x.PublishAt)
                           .Take(numberOfPosts)
                           .ToList();

                return(list.Select(thePost => new Post
                {
                    wp_slug = SlugConverter.TitleToSlug(thePost.Title),
                    description = thePost.CompiledContent(true).ToString(),
                    dateCreated = thePost.PublishAt.DateTime,
                    categories = thePost.Tags.ToArray(),
                    title = thePost.Title,
                    postid = thePost.Id,
                }).ToArray());
            }
        }
Пример #22
0
        Post IMetaWeblog.GetPost(string postid, string username, string password)
        {
            ValidateUser(username, password);

            using (var session = MvcApplication.DocumentStore.OpenSession())
            {
                var thePost = session.Load <Models.Post>(postid);
                if (thePost.IsDeleted)
                {
                    throw new InvalidOperationException("You cannot get deleted post");
                }

                return(new Post
                {
                    wp_slug = SlugConverter.TitleToSlug(thePost.Title),
                    description = thePost.CompiledContent(true).ToString(),
                    dateCreated = thePost.PublishAt.DateTime,
                    categories = thePost.Tags.ToArray(),
                    title = thePost.Title,
                    postid = thePost.Id,
                });
            }
        }
        public virtual ActionResult CommentsRss(int?id)
        {
            RavenQueryStatistics stats = null;
            var commentsTuples         = RavenSession.QueryForRecentComments(q =>
            {
                if (id != null)
                {
                    var postId = "posts/" + id;
                    q          = q.Where(x => x.PostId == postId);
                }
                return(q.Statistics(out stats).Take(30));
            });

            string responseETagHeader;

            if (CheckEtag(stats, out responseETagHeader))
            {
                return(HttpNotModified());
            }

            var rss = new XDocument(
                new XElement("rss",
                             new XAttribute("version", "2.0"),
                             new XElement("channel",
                                          new XElement("title", BlogConfig.Title),
                                          new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("homepage"))),
                                          new XElement("description", BlogConfig.MetaDescription ?? BlogConfig.Title),
                                          new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)),
                                          new XElement("ttl", "60"),
                                          from commentsTuple in commentsTuples
                                          let comment                                                        = commentsTuple.Item1
                                                                              let post                       = commentsTuple.Item2
                                                                                                    let link = Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title) }) + "#comment" + comment.Id
                                                                                                               select new XElement("item",
                                                                                                                                   new XElement("title", comment.Author + " commented on " + post.Title),
                                                                                                                                   new XElement("description", comment.Body),
                                                                                                                                   new XElement("link", link),
                                                                                                                                   new XElement("guid", link),
                                                                                                                                   new XElement("pubDate", comment.CreatedAt.ToString("R"))
                                                                                                                                   )
                                          )
                             )
                );

            return(Xml(rss, responseETagHeader));
        }
 private string GetPostLink(Post post)
 {
     if (post.Id == null)             // invalid feed
     {
         return(Url.AbsoluteAction("Index", "Posts"));
     }
     return(Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title), Key = post.ShowPostEvenIfPrivate }));
 }
Пример #25
0
        public ActionResult CommentsAdmin(int id, CommentCommandOptions command, int[] commentIds)
        {
            if (commentIds.Length < 1)
            {
                ModelState.AddModelError("CommentIdsAreEmpty", "Not comments was selected.");
            }

            var post = Session.Load <Post>(id);

            if (post == null)
            {
                return(HttpNotFound());
            }

            var slug = SlugConverter.TitleToSlag(post.Title);

            if (ModelState.IsValid == false)
            {
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { Success = false, message = ModelState.GetFirstErrorMessage() }));
                }

                return(Details(id, slug));
            }

            var comments      = Session.Load <PostComments>(id);
            var requestValues = Request.MapTo <RequestValues>();

            switch (command)
            {
            case CommentCommandOptions.Delete:
                comments.Comments.RemoveAll(c => commentIds.Contains(c.Id));
                comments.Spam.RemoveAll(c => commentIds.Contains(c.Id));
                break;

            case CommentCommandOptions.MarkSpam:
                var spams = comments.Comments
                            .Where(c => commentIds.Contains(c.Id))
                            .ToArray();

                comments.Comments.RemoveAll(spams.Contains);
                comments.Spam.RemoveAll(spams.Contains);
                foreach (var comment in spams)
                {
                    new AskimetService(Session).MarkSpam(comment);
                }
                break;

            case CommentCommandOptions.MarkHam:
                var ham = comments.Spam
                          .Where(c => commentIds.Contains(c.Id))
                          .ToArray();

                comments.Spam.RemoveAll(ham.Contains);
                foreach (var comment in ham)
                {
                    comment.IsSpam = false;
                    new AskimetService(Session).MarkHam(comment);
                }
                comments.Comments.AddRange(ham);
                break;

            default:
                throw new InvalidOperationException(command + " command is not recognized.");
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new { Success = true }));
            }
            return(RedirectToAction("Details", new { id, slug }));
        }
Пример #26
0
        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();
                }
            }
        }
Пример #27
0
 private string C(string title)
 {
     return(SlugConverter.TitleToSlag(title));
 }
Пример #28
0
        protected override void ConcreteExecute(IJobExecutionContext context)
        {
            XNamespace ns = XNamespace.Get("http://www.sitemaps.org/schemas/sitemap/0.9");
            XElement   urlset;
            var        siteMaps = new List <string>();

            if (AllApps == null)
            {
                return;
            }

            var appsByCat = AllApps
                            .GroupBy(x => x.Category.Name);

            var topics = Store.GetAll(s => s.Query <AppsList>())
                         .Where(t => t.IsFeatured == false);

            var pages = new[]
            {
                "",
                "/",
                "/Apps/Recent",
                "/Apps/TopGames",
                "/Apps/TopFreeGames",
                "/Apps/TopApps",
                "/Apps/TopFreeApps",
                "/Apps/Topics",
                "/Apps/Search",
                "/Apps/GoneFree",
                "/Stats/Overview",
                "/Stats/Apps",
                "/Stats/Developers",
                "/Home/AboutUs",
                "/Home/Advertise",
                "/Home/ContactUs"
            };

            foreach (var categroy in appsByCat)
            {
                var catName = categroy.Key;

                var siteMapDocument = new XDocument(urlset = new XElement(ns + "urlset"));
                foreach (var app in categroy)
                {
                    urlset.Add(new XElement(ns + "url",
                                            new XElement(ns + "loc", "http://www.winapps.co/Apps/App/" + app.AppId),
                                            new XElement(ns + "changefreq", "daily"),
                                            new XElement(ns + "priority", "0.7")
                                            ));

                    urlset.Add(new XElement(ns + "url",
                                            new XElement(ns + "loc", "http://www.winapps.co/Apps/App/" + app.FriendlyUrl),
                                            new XElement(ns + "changefreq", "daily"),
                                            new XElement(ns + "priority", "0.7")
                                            ));
                }

                var siteMap = "sitemap-" + SlugConverter.TitleToSlug(catName) + ".xml";
                siteMaps.Add(siteMap);
                siteMapDocument.Save(String.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, siteMap));
            }

            var siteMapCategories = new XDocument(urlset = new XElement(ns + "urlset"));

            foreach (var category in appsByCat)
            {
                urlset.Add(new XElement(ns + "url",
                                        new XElement(ns + "loc",
                                                     string.Format(
                                                         "http://www.winapps.co/Apps/Search?category={0}",
                                                         HttpUtility.UrlEncode(category.Key))),
                                        new XElement(ns + "changefreq", "daily"),
                                        new XElement(ns + "priority", "0.9")
                                        ));

                var appsBySubCat = category
                                   .Where(x => x.SubCategory != null)
                                   .GroupBy(x => x.SubCategory.Name);

                if (appsBySubCat.Any())
                {
                    foreach (var subCategory in appsBySubCat)
                    {
                        urlset.Add(new XElement(ns + "url",
                                                new XElement(ns + "loc",
                                                             string.Format(
                                                                 "http://www.winapps.co/Apps/Search?category={0}&Subcategory={1}",
                                                                 HttpUtility.UrlEncode(category.Key),
                                                                 HttpUtility.UrlEncode(subCategory.Key))),
                                                new XElement(ns + "changefreq", "daily"),
                                                new XElement(ns + "priority", "0.9")
                                                ));
                    }

                    urlset.Add(new XElement(ns + "url",
                                            new XElement(ns + "loc",
                                                         string.Format("http://www.winapps.co/Apps/Search?category={0}&Subcategory={1}",
                                                                       HttpUtility.UrlEncode(category.Key),
                                                                       "EMPTY_STRING")),
                                            new XElement(ns + "changefreq", "daily"),
                                            new XElement(ns + "priority", "0.9")
                                            ));
                }
            }
            siteMaps.Add("sitemap-categories.xml");
            siteMapCategories.Save(String.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "sitemap-categories.xml"));


            var siteMapTopics = new XDocument(urlset = new XElement(ns + "urlset"));

            foreach (var topic in topics)
            {
                urlset.Add(new XElement(ns + "url",
                                        new XElement(ns + "loc",
                                                     string.Format(
                                                         "http://www.winapps.co/Apps/Topic?topicId={0}",
                                                         HttpUtility.UrlEncode(topic.Id))),
                                        new XElement(ns + "changefreq", "daily"),
                                        new XElement(ns + "priority", "0.9")
                                        ));
            }
            siteMaps.Add("sitemap-topics.xml");
            siteMapTopics.Save(String.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "sitemap-topics.xml"));


            var siteMapBuiltIn = new XDocument(urlset = new XElement(ns + "urlset"));

            foreach (var page in pages)
            {
                urlset.Add(new XElement(ns + "url",
                                        new XElement(ns + "loc", "http://www.winapps.co" + page),
                                        new XElement(ns + "changefreq", "daily"),
                                        new XElement(ns + "priority", "1.0")
                                        ));
            }
            siteMaps.Add("sitemap-pages.xml");
            siteMapBuiltIn.Save(string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "sitemap-pages.xml"));

            var siteMapIndexDocument = new XDocument(urlset = new XElement(ns + "sitemapindex"));

            foreach (var siteMap in siteMaps)
            {
                urlset.Add(new XElement(ns + "sitemap",
                                        new XElement(ns + "loc", "http://www.winapps.co/sitemaps/" + siteMap),
                                        new XElement(ns + "lastmod", DateTime.Now.ToString("yyyy-MM-dd"))
                                        ));
            }

            siteMapIndexDocument.Save(String.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "sitemap.xml"));
        }
Пример #29
0
        public ActionResult Rss(string tag, Guid key)
        {
            RavenQueryStatistics stats;
            var postsQuery = RavenSession.Query <Post>()
                             .Statistics(out stats);

            if (key != Guid.Empty && key == BlogConfig.RssFuturePostsKey)
            {
                postsQuery = postsQuery.Where(x => x.PublishAt < DateTimeOffset.Now.AddDays(BlogConfig.RssFutureDaysAllowed).AsMinutes());
            }
            else
            {
                postsQuery = postsQuery.Where(x => x.PublishAt < DateTimeOffset.Now.AsMinutes());
            }

            if (string.IsNullOrWhiteSpace(tag) == false)
            {
                postsQuery = postsQuery.Where(x => x.TagsAsSlugs.Any(postTag => postTag == tag));
            }

            var posts = postsQuery.OrderByDescending(x => x.PublishAt)
                        .Take(20)
                        .ToList();

            string responseETagHeader;

            if (CheckEtag(stats, out responseETagHeader))
            {
                return(HttpNotModified());
            }

            var rss = new XDocument(
                new XElement("rss",
                             new XAttribute("version", "2.0"),
                             new XElement("channel",
                                          new XElement("title", BlogConfig.Title),
                                          new XElement("link", Url.RelativeToAbsolute(Url.RouteUrl("Default"))),
                                          new XElement("description", BlogConfig.MetaDescription ?? BlogConfig.Title),
                                          new XElement("copyright", String.Format("{0} (c) {1}", BlogConfig.Copyright, DateTime.Now.Year)),
                                          new XElement("ttl", "60"),
                                          from post in posts
                                          let postLink = Url.AbsoluteAction("Details", "PostDetails", new { Id = RavenIdResolver.Resolve(post.Id), Slug = SlugConverter.TitleToSlug(post.Title) })
                                                         select new XElement("item",
                                                                             new XElement("title", post.Title),
                                                                             new XElement("description", post.CompiledContent()),
                                                                             new XElement("link", postLink),
                                                                             new XElement("guid", postLink),
                                                                             new XElement("pubDate", post.PublishAt.ToString("R"))
                                                                             )
                                          )
                             )
                );

            return(Xml(rss, responseETagHeader));
        }