diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs index bd291867c..19b222303 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs @@ -12,10 +12,17 @@ using Orchard.Data; namespace Orchard.Blogs.Handlers { [UsedImplicitly] public class BlogPartArchiveHandler : ContentHandler { + private readonly WorkContext _workContext; // contains the creation time of a blog part before it has been changed private readonly Dictionary _previousCreatedUtc = new Dictionary(); - public BlogPartArchiveHandler(IRepository blogArchiveRepository, IBlogPostService blogPostService) { + public BlogPartArchiveHandler( + IRepository blogArchiveRepository, + IBlogPostService blogPostService, + WorkContext workContext) { + + _workContext = workContext; + OnVersioning((context, bp1, bp2) => { var commonPart = bp1.As(); if(commonPart == null || !commonPart.CreatedUtc.HasValue || !bp1.IsPublished) @@ -24,23 +31,30 @@ namespace Orchard.Blogs.Handlers { _previousCreatedUtc[bp2] = commonPart.CreatedUtc.Value; }); - OnPublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); - OnUnpublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); - OnRemoved((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); + OnPublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp)); + OnUnpublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp)); + OnRemoved((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp)); } - private void RecalculateBlogArchive(IRepository blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart) { + private void RecalculateBlogArchive(IRepository blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As(); if(commonPart == null || !commonPart.CreatedUtc.HasValue) return; + // get the time zone for the current request + var timeZone = _workContext.CurrentTimeZone; + var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue; - var previousMonth = previousCreatedUtc != null ? previousCreatedUtc.Month : 0; - var previousYear = previousCreatedUtc != null ? previousCreatedUtc.Year : 0; + 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; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts.Blogs.BlogArchives.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts.Blogs.BlogArchives.cshtml index ada36172e..91739c58d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts.Blogs.BlogArchives.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts.Blogs.BlogArchives.cshtml @@ -20,21 +20,21 @@ if (year == lastYear) {
  • @year

    - @Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0} ({1})", monthNames[t.Key.ToDateTime().Month - 1], t.Value), Url.BlogArchiveMonth((BlogPart)Model.Blog, t.Key.Year, t.Key.Month)), "archiveMonthList") + @Html.UnorderedList(yearMonths, (t, i) => Html.Link(Html.Raw(string.Format("{0} ({1})", monthNames[t.Key.ToDateTime().Month - 1], t.Value)), Url.BlogArchiveMonth((BlogPart)Model.Blog, t.Key.Year, t.Key.Month)), "archiveMonthList")
  • } if (year != lastYear) { } } } else if (archives.Count() > 0) { - @Html.UnorderedList(archives, (t, i) => Html.Link(string.Format("{0} {2} ({1})", monthNames[t.Key.ToDateTime().Month - 1], t.Value, t.Key.ToDateTime().Year), Url.BlogArchiveMonth((BlogPart)Model.Blog, t.Key.Year, t.Key.Month)), "archiveMonthList") + @Html.UnorderedList(archives, (t, i) => Html.Link(Html.Raw(string.Format("{0} {2} ({1})", monthNames[t.Key.ToDateTime().Month - 1], t.Value, t.Key.ToDateTime().Year)), Url.BlogArchiveMonth((BlogPart)Model.Blog, t.Key.Year, t.Key.Month)), "archiveMonthList") } else {
    @T("None found")
    diff --git a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs index 0e18824b5..134dffbc0 100644 --- a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs +++ b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs @@ -198,12 +198,23 @@ namespace Orchard.Mvc.Html { return htmlHelper.Link(linkContents, href, null); } + public static IHtmlString Link(this HtmlHelper htmlHelper, IHtmlString linkContents, string href) { + return htmlHelper.Link(linkContents, href, null); + } + public static IHtmlString Link(this HtmlHelper htmlHelper, string linkContents, string href, object htmlAttributes) { return htmlHelper.Link(linkContents, href, new RouteValueDictionary(htmlAttributes)); } public static IHtmlString Link(this HtmlHelper htmlHelper, string linkContents, string href, IDictionary htmlAttributes) { - TagBuilder tagBuilder = new TagBuilder("a") { InnerHtml = htmlHelper.Encode(linkContents) }; + var tagBuilder = new TagBuilder("a") { InnerHtml = htmlHelper.Encode(linkContents) }; + tagBuilder.MergeAttributes(htmlAttributes); + tagBuilder.MergeAttribute("href", href); + return new HtmlString(tagBuilder.ToString(TagRenderMode.Normal)); + } + + public static IHtmlString Link(this HtmlHelper htmlHelper, IHtmlString linkContents, string href, IDictionary htmlAttributes) { + var tagBuilder = new TagBuilder("a") { InnerHtml = linkContents.ToHtmlString() }; tagBuilder.MergeAttributes(htmlAttributes); tagBuilder.MergeAttribute("href", href); return new HtmlString(tagBuilder.ToString(TagRenderMode.Normal));