Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/10/2016 12:55:49 PM (4 years ago)
Author:
djpaul
Message:

Fix inaccurate timestamps caused by page caching.

If any template with a timestamp is statically cached, then the timestamps quickly become inaccurate.
The change adds livestamp.js and moment.js to dynamically update timestamps with the real relative time.

A consequence is that the labels surrounding the timestamps, notably in our widgets, have slightly changed.
We're going to keep an eye on this for the remainder of the 2.7 development cycle, and may make further adjustments as testing proves necessary.

Fixes #5757

Props r-a-y, imath, DJPaul

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-template.php

    r10904 r11008  
    685685 *
    686686 * @since 1.0.0
    687  *
    688  * @param object|bool $group Optional. Group object.
    689  *                           Default: current group in loop.
    690  */
    691 function bp_group_last_active( $group = false ) {
    692     echo bp_get_group_last_active( $group );
     687 * @since 2.7.0 Added $args as a parameter.
     688 *
     689 * @param object|bool  $group Optional. Group object. Default: current group in loop.
     690 * @param array|string $args Optional. {@see bp_get_group_last_active()}.
     691 */
     692function bp_group_last_active( $group = false, $args = array() ) {
     693    echo bp_get_group_last_active( $group, $args );
    693694}
    694695    /**
     
    696697     *
    697698     * @since 1.0.0
    698      *
    699      * @param object|bool $group Optional. Group object.
    700      *                           Default: current group in loop.
     699     * @since 2.7.0 Added $args as a parameter.
     700     *
     701     * @param object|bool  $group Optional. Group object. Default: current group in loop.
     702     * @param array|string $args {
     703     *     Array of optional parameters.
     704     *
     705     *     @type bool $relative Optional. If true, returns relative activity date. eg. active 5 months ago.
     706     *                          If false, returns active date value from database. Default: true.
     707     * }
    701708     * @return string
    702709     */
    703     function bp_get_group_last_active( $group = false ) {
     710    function bp_get_group_last_active( $group = false, $args = array() ) {
    704711        global $groups_template;
    705712
     
    708715        }
    709716
     717        $r = wp_parse_args( $args, array(
     718            'relative' => true,
     719        ) );
     720
    710721        $last_active = $group->last_activity;
    711 
    712         if ( !$last_active ) {
     722        if ( ! $last_active ) {
    713723            $last_active = groups_get_groupmeta( $group->id, 'last_activity' );
     724        }
     725
     726        // We do not want relative time, so return now.
     727        // @todo Should the 'bp_get_group_last_active' filter be applied here?
     728        if ( ! $r['relative'] ) {
     729            return esc_attr( $last_active );
    714730        }
    715731
     
    719735
    720736            /**
    721              * Filters the 'last active' string for the current gorup in the loop.
     737             * Filters the 'last active' string for the current group in the loop.
    722738             *
    723739             * @since 1.0.0
     
    10531069 *
    10541070 * @since 1.0.0
    1055  *
    1056  * @param object|bool $group Optional. Group object.
    1057  *                           Default: current group in loop.
    1058  */
    1059 function bp_group_date_created( $group = false ) {
    1060     echo bp_get_group_date_created( $group );
     1071 * @since 2.7.0 Added $args as a parameter.
     1072 *
     1073 * @param object|bool  $group Optional. Group object. Default: current group in loop.
     1074 * @param array|string $args  {@see bp_get_group_date_created()}.
     1075 */
     1076function bp_group_date_created( $group = false, $args = array() ) {
     1077    echo bp_get_group_date_created( $group, $args );
    10611078}
    10621079    /**
     
    10641081     *
    10651082     * @since 1.0.0
    1066      *
    1067      * @param object|bool $group Optional. Group object.
    1068      *                           Default: current group in loop.
     1083     * @since 2.7.0 Added $args as a parameter.
     1084     *
     1085     * @param object|bool  $group Optional. Group object. Default: current group in loop.
     1086     * @param array|string $args {
     1087     *     Array of optional parameters.
     1088     *
     1089     *     @type bool $relative Optional. If true, returns relative created date. eg. active 5 months ago.
     1090     *                          If false, returns created date value from database. Default: true.
     1091     * }
    10691092     * @return string
    10701093     */
    1071     function bp_get_group_date_created( $group = false ) {
     1094    function bp_get_group_date_created( $group = false, $args = array() ) {
    10721095        global $groups_template;
     1096
     1097        $r = wp_parse_args( $args, array(
     1098            'relative' => true,
     1099        ) );
    10731100
    10741101        if ( empty( $group ) ) {
    10751102            $group =& $groups_template->group;
     1103        }
     1104
     1105        // We do not want relative time, so return now.
     1106        // @todo Should the 'bp_get_group_date_created' filter be applied here?
     1107        if ( ! $r['relative'] ) {
     1108            return esc_attr( $group->date_created );
    10761109        }
    10771110
     
    39714004
    39724005/**
    3973  * @since 1.0.0
    3974  */
    3975 function bp_group_member_joined_since() {
    3976     echo bp_get_group_member_joined_since();
    3977 }
    3978 
    3979     /**
     4006 * Output the joined date for the current member in the group member loop.
     4007 *
     4008 * @since 1.0.0
     4009 * @since 2.7.0 Added $args as a parameter.
     4010 *
     4011 * @param array|string $args {@see bp_get_group_member_joined_since()}
     4012 * @return string
     4013 */
     4014function bp_group_member_joined_since( $args = array() ) {
     4015    echo bp_get_group_member_joined_since( $args );
     4016}
     4017    /**
     4018     * Return the joined date for the current member in the group member loop.
     4019     *
    39804020     * @since 1.0.0
    3981      *
    3982      * @return mixed|void
    3983      */
    3984     function bp_get_group_member_joined_since() {
     4021     * @since 2.7.0 Added $args as a parameter.
     4022     *
     4023     * @param array|string $args {
     4024     *     Array of optional parameters.
     4025     *
     4026     *     @type bool $relative Optional. If true, returns relative joined date. eg. joined 5 months ago.
     4027     *                          If false, returns joined date value from database. Default: true.
     4028     * }
     4029     * @return string
     4030     */
     4031    function bp_get_group_member_joined_since( $args = array() ) {
    39854032        global $members_template;
     4033
     4034        $r = wp_parse_args( $args, array(
     4035            'relative' => true,
     4036        ) );
     4037
     4038        // We do not want relative time, so return now.
     4039        // @todo Should the 'bp_get_group_member_joined_since' filter be applied here?
     4040        if ( ! $r['relative'] ) {
     4041            return esc_attr( $members_template->member->date_modified );
     4042        }
    39864043
    39874044        /**
Note: See TracChangeset for help on using the changeset viewer.