mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : 1.x
This commit is contained in:
@@ -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<BlogPostPart, DateTime> _previousCreatedUtc = new Dictionary<BlogPostPart,DateTime>();
|
||||
|
||||
public BlogPartArchiveHandler(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService) {
|
||||
public BlogPartArchiveHandler(
|
||||
IRepository<BlogPartArchiveRecord> blogArchiveRepository,
|
||||
IBlogPostService blogPostService,
|
||||
WorkContext workContext) {
|
||||
|
||||
_workContext = workContext;
|
||||
|
||||
OnVersioning<BlogPostPart>((context, bp1, bp2) => {
|
||||
var commonPart = bp1.As<CommonPart>();
|
||||
if(commonPart == null || !commonPart.CreatedUtc.HasValue || !bp1.IsPublished)
|
||||
@@ -24,23 +31,30 @@ namespace Orchard.Blogs.Handlers {
|
||||
_previousCreatedUtc[bp2] = commonPart.CreatedUtc.Value;
|
||||
});
|
||||
|
||||
OnPublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||
OnUnpublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||
OnRemoved<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||
OnPublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp));
|
||||
OnUnpublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp));
|
||||
OnRemoved<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, bp));
|
||||
}
|
||||
|
||||
private void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart) {
|
||||
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 = _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;
|
||||
|
||||
|
@@ -20,21 +20,21 @@
|
||||
if (year == lastYear) {
|
||||
<li>
|
||||
<h4>@year</h4>
|
||||
@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")
|
||||
</li>
|
||||
}
|
||||
|
||||
if (year != lastYear) {
|
||||
<li class="previous">
|
||||
<h4>@year <span>(@yearMonths.Sum(ym => ym.Value))</span></h4>
|
||||
@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")
|
||||
</li>
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
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 {
|
||||
<div class="message info">@T("None found")</div>
|
||||
|
@@ -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<string, object> 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<string, object> htmlAttributes) {
|
||||
var tagBuilder = new TagBuilder("a") { InnerHtml = linkContents.ToHtmlString() };
|
||||
tagBuilder.MergeAttributes(htmlAttributes);
|
||||
tagBuilder.MergeAttribute("href", href);
|
||||
return new HtmlString(tagBuilder.ToString(TagRenderMode.Normal));
|
||||
|
Reference in New Issue
Block a user