Exemple #1
0
        private static XRpcStruct CreateBlogStruct(
            BlogPostPart blogPostPart,
            UrlHelper urlHelper)
        {
            var url = urlHelper.AbsoluteAction(() => urlHelper.ItemDisplayUrl(blogPostPart));

            if (blogPostPart.HasDraft())
            {
                url = urlHelper.AbsoluteAction("Preview", "Item", new { area = "Contents", id = blogPostPart.ContentItem.Id });
            }

            var blogStruct = new XRpcStruct()
                             .Set("postid", blogPostPart.Id)
                             .Set("title", HttpUtility.HtmlEncode(blogPostPart.Title))

                             .Set("description", blogPostPart.Text)
                             .Set("link", url)
                             .Set("permaLink", url);

            blogStruct.Set("wp_slug", blogPostPart.As <IAliasAspect>().Path);


            if (blogPostPart.PublishedUtc != null)
            {
                blogStruct.Set("dateCreated", blogPostPart.PublishedUtc);
                blogStruct.Set("date_created_gmt", blogPostPart.PublishedUtc);
            }

            return(blogStruct);
        }
        private void ProcessBlogPostsCount(BlogPostPart blogPostPart)
        {
            CommonPart commonPart = blogPostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                _blogService.ProcessBlogPostsCount(commonPart.Container.Id);
            }
        }
Exemple #3
0
        private void UpdateBlogPostCount(BlogPostPart blogPostPart)
        {
            CommonPart commonPart = blogPostPart.As <CommonPart>();

            if (commonPart != null &&
                commonPart.Record.Container != null)
            {
                BlogPart blogPart = blogPostPart.BlogPart ??
                                    _blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As <BlogPart>();

                // Ensure the "right" set of published posts for the blog is obtained
                blogPart.PostCount = _blogPostService.PostCount(blogPart);
            }
        }
Exemple #4
0
        private static XRpcStruct CreateBlogStruct(
            BlogPostPart blogPostPart,
            UrlHelper urlHelper)
        {
            var url        = urlHelper.AbsoluteAction(() => urlHelper.BlogPost(blogPostPart));
            var blogStruct = new XRpcStruct()
                             .Set("postid", blogPostPart.Id)
                             .Set("title", blogPostPart.Title)
                             .Set("wp_slug", blogPostPart.Slug)
                             .Set("description", blogPostPart.Text)
                             .Set("link", url)
                             .Set("permaLink", url);

            if (blogPostPart.PublishedUtc != null)
            {
                blogStruct.Set("dateCreated", blogPostPart.PublishedUtc);
                blogStruct.Set("date_created_gmt", blogPostPart.PublishedUtc);
            }

            return(blogStruct);
        }
        private void ReduceBlogArchive(BlogPostPart blogPostPart)
        {
            _blogArchiveRepository.Flush();

            // don't reduce archive count if the content item is not published
            if (!blogPostPart.HasPublished)
            {
                return;
            }

            var commonPart = blogPostPart.As <ICommonPart>();

            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
            {
                return;
            }

            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;
            var datetime = TimeZoneInfo.ConvertTimeFromUtc(commonPart.CreatedUtc.Value, timeZone);

            var previousArchiveRecord = _blogArchiveRepository.Table
                                        .FirstOrDefault(x => x.BlogPart == blogPostPart.BlogPart.Record &&
                                                        x.Month == datetime.Month &&
                                                        x.Year == datetime.Year);

            if (previousArchiveRecord == null)
            {
                return;
            }

            if (previousArchiveRecord.PostCount > 1)
            {
                previousArchiveRecord.PostCount--;
            }
            else
            {
                _blogArchiveRepository.Delete(previousArchiveRecord);
            }
        }
Exemple #6
0
 private static void SetModelProperties(BuildShapeContext context, BlogPostPart blogPost)
 {
     context.Shape.Blog = blogPost.BlogPart;
 }
        private static void RecalculateBlogArchive(IRepository <BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart)
        {
            blogArchiveRepository.Flush();

            // remove all current blog archive records
            var blogArchiveRecords =
                from bar in blogArchiveRepository.Table
                where bar.BlogPart == blogPostPart.BlogPart.Record
                select bar;

            blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete);

            // get all blog posts for the current blog
            var posts = blogPostService.Get(blogPostPart.BlogPart, VersionOptions.Published);

            // create a dictionary of all the year/month combinations and their count of posts that are published in this blog
            var inMemoryBlogArchives = new Dictionary <DateTime, int>(posts.Count());

            foreach (var post in posts)
            {
                if (!post.Has <CommonPart>())
                {
                    continue;
                }

                var commonPart = post.As <CommonPart>();
                var key        = new DateTime(commonPart.PublishedUtc.Value.Year, commonPart.PublishedUtc.Value.Month, 1);

                if (inMemoryBlogArchives.ContainsKey(key))
                {
                    inMemoryBlogArchives[key]++;
                }
                else
                {
                    inMemoryBlogArchives[key] = 1;
                }
            }

            // create the new blog archive records based on the in memory values
            foreach (KeyValuePair <DateTime, int> item in inMemoryBlogArchives)
            {
                blogArchiveRepository.Create(new BlogPartArchiveRecord {
                    BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value
                });
            }
        }
        public DateTime?GetScheduledPublishUtc(BlogPostPart blogPostPart)
        {
            var task = _publishingTaskManager.GetPublishTask(blogPostPart.ContentItem);

            return(task == null ? null : task.ScheduledUtc);
        }
 public void Unpublish(BlogPostPart blogPostPart)
 {
     _contentManager.Unpublish(blogPostPart.ContentItem);
 }
 public void Publish(BlogPostPart blogPostPart, DateTime scheduledPublishUtc)
 {
     _publishingTaskManager.Publish(blogPostPart.ContentItem, scheduledPublishUtc);
 }
 public void Publish(BlogPostPart blogPostPart)
 {
     _publishingTaskManager.DeleteTasks(blogPostPart.ContentItem);
     _contentManager.Publish(blogPostPart.ContentItem);
 }
 public void Delete(BlogPostPart blogPostPart)
 {
     _publishingTaskManager.DeleteTasks(blogPostPart.ContentItem);
     _contentManager.Remove(blogPostPart.ContentItem);
 }
Exemple #13
0
 public static string BlogPostUnpublish(this UrlHelper urlHelper, BlogPostPart blogPostPart)
 {
     return(urlHelper.Action("Unpublish", "BlogPostAdmin", new { blogId = blogPostPart.BlogPart.Id, postId = blogPostPart.Id, area = "Orchard.Blogs" }));
 }
Exemple #14
0
        private void RecalculateBlogArchive(IRepository <BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart)
        {
            blogArchiveRepository.Flush();

            var commonPart = blogPostPart.As <CommonPart>();

            if (commonPart == null || !commonPart.CreatedUtc.HasValue)
            {
                return;
            }

            // get the time zone for the current request
            var timeZone = _workContextAccessor.GetContext().CurrentTimeZone;

            var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue;

            previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone);

            var previousMonth = previousCreatedUtc.Month;
            var previousYear  = previousCreatedUtc.Year;

            var newCreatedUtc = commonPart.CreatedUtc;

            newCreatedUtc = newCreatedUtc.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone) : newCreatedUtc;

            var newMonth = newCreatedUtc.HasValue ? newCreatedUtc.Value.Month : 0;
            var newYear  = newCreatedUtc.HasValue ? newCreatedUtc.Value.Year : 0;

            // if archives are the same there is nothing to do
            if (previousMonth == newMonth && previousYear == newYear)
            {
                return;
            }

            // decrement previous archive record
            var previousArchiveRecord = blogArchiveRepository.Table
                                        .Where(x => x.BlogPart == blogPostPart.BlogPart.Record &&
                                               x.Month == previousMonth &&
                                               x.Year == previousYear)
                                        .FirstOrDefault();

            if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0)
            {
                previousArchiveRecord.PostCount--;
            }

            // if previous count is now zero, delete the record
            if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0)
            {
                blogArchiveRepository.Delete(previousArchiveRecord);
            }

            // increment new archive record
            var newArchiveRecord = blogArchiveRepository.Table
                                   .Where(x => x.BlogPart == blogPostPart.BlogPart.Record &&
                                          x.Month == newMonth &&
                                          x.Year == newYear)
                                   .FirstOrDefault();

            // if record can't be found create it
            if (newArchiveRecord == null)
            {
                newArchiveRecord = new BlogPartArchiveRecord {
                    BlogPart = blogPostPart.BlogPart.Record, Year = newYear, Month = newMonth, PostCount = 0
                };
                blogArchiveRepository.Create(newArchiveRecord);
            }

            newArchiveRecord.PostCount++;
        }
 public static string BlogPost(this UrlHelper urlHelper, BlogPostPart blogPostPart)
 {
     return(urlHelper.Action("Item", "BlogPost", new { blogPath = blogPostPart.BlogPart.As <IRoutableAspect>().Path, postSlug = blogPostPart.As <IRoutableAspect>().GetEffectiveSlug(), area = "Orchard.Blogs" }));
 }