diff --git a/src/Orchard.Web/Core/Common/Views/Parts/Common.Metadata.SummaryAdmin.cshtml b/src/Orchard.Web/Core/Common/Views/Parts/Common.Metadata.SummaryAdmin.cshtml index b70adc28d..6c45a70b0 100644 --- a/src/Orchard.Web/Core/Common/Views/Parts/Common.Metadata.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Core/Common/Views/Parts/Common.Metadata.SummaryAdmin.cshtml @@ -9,7 +9,7 @@ } \ No newline at end of file diff --git a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.Summary.cshtml b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.Summary.cshtml index 6ce233351..e4551fc72 100644 --- a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.Summary.cshtml +++ b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.Summary.cshtml @@ -6,5 +6,5 @@ DateTime? versionPublishedUtc = publishLaterPart.As() == null ? null : publishLaterPart.As().VersionPublishedUtc; } @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { - @T("Published: {0}", Html.DateTimeRelative(versionPublishedUtc.Value, T)) @T(" | ") + @T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value)) @T(" | ") } \ No newline at end of file diff --git a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.SummaryAdmin.cshtml b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.SummaryAdmin.cshtml index a707dfdfc..b2d406ee2 100644 --- a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.SummaryAdmin.cshtml @@ -26,7 +26,7 @@ @if ((((DateTime?)Model.ScheduledPublishUtc).HasValue && ((DateTime?)Model.ScheduledPublishUtc).Value > DateTime.UtcNow) || (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue)) {
  • @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { - @T("Published: {0}", Html.DateTimeRelative(versionPublishedUtc.Value, T)) + @T("Published: {0}", Display.DateTimeRelative(versionPublishedUtc.Value)) } else { @T( @T("Scheduled") diff --git a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.cshtml b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.cshtml index be7e5bebd..5bbd6d2cf 100644 --- a/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.cshtml +++ b/src/Orchard.Web/Core/PublishLater/Views/Parts/PublishLater.Metadata.cshtml @@ -6,5 +6,5 @@ DateTime? versionPublishedUtc = publishLaterPart.As() == null ? null : publishLaterPart.As().VersionPublishedUtc; } @if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) { - @T("Published: {0}", Html.DateTimeRelative(versionPublishedUtc.Value, T)) + @T("Published: {0}", Display.DateTimeRelative(dateTime: versionPublishedUtc.Value)) } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml index 17bff6a75..a4691c950 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml @@ -3,19 +3,19 @@
      @foreach (var comment in Model) { -
    • -
      -
      -

      - @Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" }) - - said - -

      -
      -

      @comment.Record.CommentText

      -
      -
    • +
    • +
      +
      +

      + @Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" }) + + said + +

      +
      +

      @comment.Record.CommentText

      +
      +
    • }
    diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml index 89c56cb3f..640fab31b 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Views/Admin/Index.cshtml @@ -20,7 +20,7 @@

    @T("The search index contains the following fields: {0}.", string.Join(T(", ").Text, Model.IndexEntry.Fields))

    } -

    @T("The search index was last updated {0}.", Html.DateTimeRelative(Model.IndexEntry.LastUpdateUtc.Value, T))

    +

    @T("The search index was last updated {0}.", Display.DateTimeRelative(dateTime: Model.IndexEntry.LastUpdateUtc.Value))

    }

    @T("Update the search index now: ")

    @Html.AntiForgeryTokenOrchard() diff --git a/src/Orchard.Web/Themes/Corporate/Views/ListOfComments.ascx b/src/Orchard.Web/Themes/Corporate/Views/ListOfComments.ascx index ed920dfd1..7678b33a2 100644 --- a/src/Orchard.Web/Themes/Corporate/Views/ListOfComments.ascx +++ b/src/Orchard.Web/Themes/Corporate/Views/ListOfComments.ascx @@ -7,7 +7,7 @@ foreach (var comment in Model) { %>

    <%: comment.Record.CommentText %>

    - <%: Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%> said <%: Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%> + <%: Html.LinkOrDefault(Html.Encode(comment.Record.UserName), Html.Encode(comment.Record.SiteName), new { rel = "nofollow" })%> said <%: Html.Link(Display.DateTimeRelative(dateTime: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%>
  • <% } %> diff --git a/src/Orchard.Web/Themes/Green/Views/ListOfComments.ascx b/src/Orchard.Web/Themes/Green/Views/ListOfComments.ascx index cfc433e7c..218ffd95d 100644 --- a/src/Orchard.Web/Themes/Green/Views/ListOfComments.ascx +++ b/src/Orchard.Web/Themes/Green/Views/ListOfComments.ascx @@ -7,7 +7,7 @@ foreach (var comment in Model) { %>

    <%: comment.Record.CommentText %>

    - <%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%> said <%: Html.Link(Html.DateTimeRelative(comment.Record.CommentDateUtc.GetValueOrDefault(), T).Text, "#")%> + <%: Html.LinkOrDefault(comment.Record.UserName, comment.Record.SiteName, new { rel = "nofollow" })%> said <%: Html.Link(Display.DateTimeRelative(dateTime: comment.Record.CommentDateUtc.GetValueOrDefault()).Text, "#")%>
    <% } %> diff --git a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs index 3cb858bed..3a571f6a3 100644 --- a/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs +++ b/src/Orchard/Mvc/Html/HtmlHelperExtensions.cs @@ -206,27 +206,6 @@ namespace Orchard.Mvc.Html { #region Format Date/Time - public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull, Localizer T) { - return value.HasValue ? htmlHelper.DateTimeRelative(value.Value, T) : defaultIfNull; - } - - public static LocalizedString DateTimeRelative(this HtmlHelper htmlHelper, DateTime value, Localizer T) { - var time = htmlHelper.Resolve().UtcNow - value; - - if (time.TotalDays > 7) - return htmlHelper.DateTime(value, T("'on' MMM d yyyy 'at' h:mm tt")); - if (time.TotalHours > 24) - return T.Plural("1 day ago", "{0} days ago", time.Days); - if (time.TotalMinutes > 60) - return T.Plural("1 hour ago", "{0} hours ago", time.Hours); - if (time.TotalSeconds > 60) - return T.Plural("1 minute ago", "{0} minutes ago", time.Minutes); - if (time.TotalSeconds > 10) - return T.Plural("1 second ago", "{0} seconds ago", time.Seconds); //aware that the singular won't be used - - return T("a moment ago"); - } - public static LocalizedString DateTime(this HtmlHelper htmlHelper, DateTime? value, LocalizedString defaultIfNull) { return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull; } diff --git a/src/Orchard/Mvc/Shapes.cs b/src/Orchard/Mvc/Shapes.cs new file mode 100644 index 000000000..fe6ee1def --- /dev/null +++ b/src/Orchard/Mvc/Shapes.cs @@ -0,0 +1,42 @@ +using System; +using System.Web.Mvc; +using Orchard.DisplayManagement; +using Orchard.Localization; +using Orchard.Mvc.Html; +using Orchard.Services; + +namespace Orchard.Mvc { + public class Shapes { + private readonly IClock _clock; + + public Shapes(IClock clock) { + _clock = clock; + T = NullLocalizer.Instance; + } + + public Localizer T { get; set; } + + [Shape] + public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime? dateTime, LocalizedString defaultIfNull) { + return dateTime.HasValue ? DateTimeRelative(Html, dateTime.Value) : defaultIfNull; + } + + [Shape] + public LocalizedString DateTimeRelative(HtmlHelper Html, DateTime dateTime) { + var time = _clock.UtcNow - dateTime; + + if (time.TotalDays > 7) + return Html.DateTime(dateTime, T("'on' MMM d yyyy 'at' h:mm tt")); + if (time.TotalHours > 24) + return T.Plural("1 day ago", "{0} days ago", time.Days); + if (time.TotalMinutes > 60) + return T.Plural("1 hour ago", "{0} hours ago", time.Hours); + if (time.TotalSeconds > 60) + return T.Plural("1 minute ago", "{0} minutes ago", time.Minutes); + if (time.TotalSeconds > 10) + return T.Plural("1 second ago", "{0} seconds ago", time.Seconds); //aware that the singular won't be used + + return T("a moment ago"); + } + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index c533a8e82..761b08653 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -176,6 +176,7 @@ +