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-members/bp-members-template.php

    r10825 r11008  
    934934 * @since 1.2.0
    935935 *
    936  * @param array $args See {@link bp_get_member_last_active()}.
     936 * @param array $args {@see bp_get_member_last_active()}.
    937937 */
    938938function bp_member_last_active( $args = array() ) {
     
    943943     *
    944944     * @since 1.2.0
     945     * @since 2.7.0 Added 'relative' as a parameter to $args.
    945946     *
    946947     * @param array $args {
    947948     *     Array of optional arguments.
    948      *     @type mixed $active_format If true, formatted "active 5 minutes
    949      *                                ago". If false, formatted "5 minutes ago".
    950      *                                If string, should be sprintf'able like
    951      *                                'last seen %s ago'.
     949     *     @type mixed $active_format If true, formatted "active 5 minutes ago". If false, formatted "5 minutes
     950     *                                ago". If string, should be sprintf'able like 'last seen %s ago'.
     951     *     @type bool  $relative      If true, will return relative time "5 minutes ago". If false, will return
     952     *                                date from database. Default: true.
    952953     * }
    953954     * @return string
     
    958959        // Parse the activity format.
    959960        $r = bp_parse_args( $args, array(
    960             'active_format' => true
     961            'active_format' => true,
     962            'relative'      => true,
    961963        ) );
    962964
     
    968970        // Member has logged in at least one time.
    969971        if ( isset( $members_template->member->last_activity ) ) {
     972            // We do not want relative time, so return now.
     973            // @todo Should the 'bp_member_last_active' filter be applied here?
     974            if ( ! $r['relative'] ) {
     975                return esc_attr( $members_template->member->last_activity );
     976            }
    970977
    971978            // Backwards compatibility for pre 1.5 'ago' strings.
     
    974981                : bp_core_time_since( $members_template->member->last_activity );
    975982
    976             // Member has never logged in or been active.
     983        // Member has never logged in or been active.
    977984        } else {
    978985            $last_activity = __( 'Never active', 'buddypress' );
     
    11521159 *
    11531160 * @since 1.2.0
    1154  */
    1155 function bp_member_registered() {
    1156     echo bp_get_member_registered();
     1161 * @since 2.7.0 Added $args as a parameter.
     1162 *
     1163 * @param array $args Optional. {@see bp_get_member_registered()}
     1164 */
     1165function bp_member_registered( $args = array() ) {
     1166    echo bp_get_member_registered( $args );
    11571167}
    11581168    /**
     
    11601170     *
    11611171     * @since 1.2.0
    1162      *
    1163      * @return string
    1164      */
    1165     function bp_get_member_registered() {
     1172     * @since 2.7.0 Added $args as a parameter.
     1173     *
     1174     * @param array $args {
     1175     *     Array of optional parameters.
     1176     *
     1177     *     @type bool $relative Optional. If true, returns relative registered date. eg. registered 5 months ago.
     1178     *                          If false, returns registered date value from database.
     1179     * }
     1180     *
     1181     * @return string
     1182     */
     1183    function bp_get_member_registered( $args = array() ) {
    11661184        global $members_template;
     1185
     1186        $r = wp_parse_args( $args, array(
     1187            'relative' => true,
     1188        ) );
     1189
     1190        // We do not want relative time, so return now.
     1191        // @todo Should the 'bp_member_registered' filter be applied here?
     1192        if ( ! $r['relative'] ) {
     1193            return esc_attr( $members_template->member->user_registered );
     1194        }
    11671195
    11681196        $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, _x( 'registered %s', 'Records the timestamp that the user registered into the activity stream', 'buddypress' ) ) );
Note: See TracChangeset for help on using the changeset viewer.